工单添加BOM组成信息

This commit is contained in:
JinLu.Yin 2022-05-10 00:47:53 +08:00
parent 39f67f504e
commit 5f7d10e476
10 changed files with 109 additions and 33 deletions

View File

@ -28,7 +28,7 @@ import com.ktg.common.core.page.TableDataInfo;
* @date 2022-05-09
*/
@RestController
@RequestMapping("/pro/workorderbom")
@RequestMapping("/mes/pro/workorderbom")
public class ProWorkorderBomController extends BaseController
{
@Autowired
@ -37,7 +37,7 @@ public class ProWorkorderBomController extends BaseController
/**
* 查询生产工单BOM组成列表
*/
@PreAuthorize("@ss.hasPermi('pro:workorderbom:list')")
@PreAuthorize("@ss.hasPermi('mes:pro:workorderbom:list')")
@GetMapping("/list")
public TableDataInfo list(ProWorkorderBom proWorkorderBom)
{
@ -49,7 +49,7 @@ public class ProWorkorderBomController extends BaseController
/**
* 导出生产工单BOM组成列表
*/
@PreAuthorize("@ss.hasPermi('pro:workorderbom:export')")
@PreAuthorize("@ss.hasPermi('mes:pro:workorderbom:export')")
@Log(title = "生产工单BOM组成", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, ProWorkorderBom proWorkorderBom)
@ -62,7 +62,7 @@ public class ProWorkorderBomController extends BaseController
/**
* 获取生产工单BOM组成详细信息
*/
@PreAuthorize("@ss.hasPermi('pro:workorderbom:query')")
@PreAuthorize("@ss.hasPermi('mes:pro:workorderbom:query')")
@GetMapping(value = "/{lineId}")
public AjaxResult getInfo(@PathVariable("lineId") Long lineId)
{
@ -72,7 +72,7 @@ public class ProWorkorderBomController extends BaseController
/**
* 新增生产工单BOM组成
*/
@PreAuthorize("@ss.hasPermi('pro:workorderbom:add')")
@PreAuthorize("@ss.hasPermi('mes:pro:workorderbom:add')")
@Log(title = "生产工单BOM组成", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody ProWorkorderBom proWorkorderBom)
@ -83,7 +83,7 @@ public class ProWorkorderBomController extends BaseController
/**
* 修改生产工单BOM组成
*/
@PreAuthorize("@ss.hasPermi('pro:workorderbom:edit')")
@PreAuthorize("@ss.hasPermi('mes:pro:workorderbom:edit')")
@Log(title = "生产工单BOM组成", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody ProWorkorderBom proWorkorderBom)
@ -94,7 +94,7 @@ public class ProWorkorderBomController extends BaseController
/**
* 删除生产工单BOM组成
*/
@PreAuthorize("@ss.hasPermi('pro:workorderbom:remove')")
@PreAuthorize("@ss.hasPermi('mes:pro:workorderbom:remove')")
@Log(title = "生产工单BOM组成", businessType = BusinessType.DELETE)
@DeleteMapping("/{lineIds}")
public AjaxResult remove(@PathVariable Long[] lineIds)

View File

@ -1,5 +1,6 @@
package com.ktg.mes.pro.controller;
import java.math.BigDecimal;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
@ -26,7 +27,6 @@ import com.ktg.common.enums.BusinessType;
import com.ktg.mes.pro.domain.ProWorkorder;
import com.ktg.mes.pro.service.IProWorkorderService;
import com.ktg.common.utils.poi.ExcelUtil;
import com.ktg.common.core.page.TableDataInfo;
/**
* 生产工单Controller
@ -52,11 +52,10 @@ public class ProWorkorderController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('mes:pro:workorder:list')")
@GetMapping("/list")
public TableDataInfo list(ProWorkorder proWorkorder)
public AjaxResult list(ProWorkorder proWorkorder)
{
startPage();
List<ProWorkorder> list = proWorkorderService.selectProWorkorderList(proWorkorder);
return getDataTable(list);
return AjaxResult.success(list);
}
/**
@ -90,7 +89,15 @@ public class ProWorkorderController extends BaseController
@PostMapping
public AjaxResult add(@RequestBody ProWorkorder proWorkorder)
{
return toAjax(proWorkorderService.insertProWorkorder(proWorkorder));
if(proWorkorder.getParentId()==null || proWorkorder.getParentId()==0){
proWorkorder.setAncestors("0");
}
proWorkorderService.insertProWorkorder(proWorkorder);
Long workorderId = proWorkorder.getWorkorderId();
generateBomLine(workorderId);
return AjaxResult.success(workorderId);
}
/**
@ -101,7 +108,17 @@ public class ProWorkorderController extends BaseController
@PutMapping
public AjaxResult edit(@RequestBody ProWorkorder proWorkorder)
{
return toAjax(proWorkorderService.updateProWorkorder(proWorkorder));
ProWorkorder workorder = proWorkorderService.selectProWorkorderByWorkorderId(proWorkorder.getWorkorderId());
int ret =proWorkorderService.updateProWorkorder(proWorkorder);
//如果是产品和数量发生变化则需要重新生成BOM组成
if(ret >0){
if(workorder.getProductId().longValue() != proWorkorder.getProductId().longValue() ||
workorder.getQuantity().compareTo(proWorkorder.getQuantity())!=0){
removeBomLine(proWorkorder.getWorkorderId());
generateBomLine(proWorkorder.getWorkorderId());
}
}
return toAjax(ret);
}
/**
@ -112,36 +129,53 @@ public class ProWorkorderController extends BaseController
@DeleteMapping("/{workorderIds}")
public AjaxResult remove(@PathVariable Long[] workorderIds)
{
for (Long id:workorderIds
) {
removeBomLine(id);
}
return toAjax(proWorkorderService.deleteProWorkorderByWorkorderIds(workorderIds));
}
/**
* 根据生产工单中的产品生成对应的BOM组成物料清单
* @param workOrderId
* 根据生产工单中的产品生成BOM物料行
* @param workorderId
*/
private void generateBomLine(Long workOrderId){
ProWorkorder workorder = proWorkorderService.selectProWorkorderByWorkorderId(workOrderId);
Long itemId = workorder.getProductId(); //得到当前工单生产的物料/产品ID
private void generateBomLine(Long workorderId){
//先根据ID找到对应的产品
ProWorkorder workorder = proWorkorderService.selectProWorkorderByWorkorderId(workorderId);
//根据产品找到BOM组成
MdProductBom param = new MdProductBom();
param.setItemId(itemId);
param.setItemId(workorder.getProductId());
List<MdProductBom> boms = mdProductBomService.selectMdProductBomList(param);
ProWorkorderBom proWorkorderBom = new ProWorkorderBom();
if(!CollUtil.isEmpty(boms)){
//生成BOM数据
BigDecimal orderQuantitiy = workorder.getQuantity();
ProWorkorderBom workorderBom = new ProWorkorderBom();
if(CollUtil.isNotEmpty(boms)){
for (MdProductBom bom:boms
) {
proWorkorderBom.setWorkorderId(workOrderId);
proWorkorderBom.setItemId(bom.getBomItemId());
proWorkorderBom.setItemCode(bom.getBomItemCode());
proWorkorderBom.setItemName(bom.getBomItemName());
proWorkorderBom.setItemSpc(bom.getBomItemSpec());
proWorkorderBom.setUnitOfMeasure(bom.getUnitOfMeasure());
proWorkorderBom.setItemOrProduct(""); //TODO
workorderBom.setWorkorderId(workorderId);
workorderBom.setItemId(bom.getBomItemId());
workorderBom.setItemCode(bom.getBomItemCode());
workorderBom.setItemName(bom.getBomItemName());
workorderBom.setItemSpc(bom.getBomItemSpec());
workorderBom.setItemOrProduct(bom.getItemOrProduct());
workorderBom.setUnitOfMeasure(bom.getUnitOfMeasure());
workorderBom.setQuantity(orderQuantitiy.multiply(bom.getQuantity()));
proWorkorderBomService.insertProWorkorderBom(workorderBom);
}
}
}
/**
* 删除当前工单下所有BOM组成
* @param workorderId
*/
private void removeBomLine(Long workorderId){
ProWorkorderBom param = new ProWorkorderBom();
param.setWorkorderId(workorderId);
proWorkorderBomService.deleteProWorkorderBomByWorkorderId(workorderId);
}
}

View File

@ -6,7 +6,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ktg.common.annotation.Excel;
import com.ktg.common.core.domain.BaseEntity;
import com.ktg.common.core.domain.TreeEntity;
/**
* 生产工单对象 pro_workorder
@ -14,7 +14,7 @@ import com.ktg.common.core.domain.BaseEntity;
* @author yinjinlu
* @date 2022-05-09
*/
public class ProWorkorder extends BaseEntity
public class ProWorkorder extends TreeEntity
{
private static final long serialVersionUID = 1L;
@ -293,6 +293,8 @@ public class ProWorkorder extends BaseEntity
.append("clientCode", getClientCode())
.append("clientName", getClientName())
.append("requestDate", getRequestDate())
.append("parentId", getParentId())
.append("ancestors", getAncestors())
.append("status", getStatus())
.append("remark", getRemark())
.append("attr1", getAttr1())

View File

@ -58,4 +58,6 @@ public interface ProWorkorderBomMapper
* @return 结果
*/
public int deleteProWorkorderBomByLineIds(Long[] lineIds);
public int deleteProWorkorderBomByWorkorderId(Long workorderId);
}

View File

@ -58,4 +58,13 @@ public interface IProWorkorderBomService
* @return 结果
*/
public int deleteProWorkorderBomByLineId(Long lineId);
/**
* 批量删除工单下所有的BOM组成数据
* @param workorderId
* @return
*/
public int deleteProWorkorderBomByWorkorderId(Long workorderId);
}

View File

@ -60,4 +60,5 @@ public interface IProWorkorderService
public int deleteProWorkorderByWorkorderId(Long workorderId);
}

View File

@ -93,4 +93,9 @@ public class ProWorkorderBomServiceImpl implements IProWorkorderBomService
{
return proWorkorderBomMapper.deleteProWorkorderBomByLineId(lineId);
}
@Override
public int deleteProWorkorderBomByWorkorderId(Long workorderId) {
return proWorkorderBomMapper.deleteProWorkorderBomByWorkorderId(workorderId);
}
}

View File

@ -2,6 +2,8 @@ package com.ktg.mes.pro.service.impl;
import java.util.List;
import com.ktg.common.utils.DateUtils;
import com.ktg.common.utils.StringUtils;
import com.ktg.mes.dv.domain.DvMachineryType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktg.mes.pro.mapper.ProWorkorderMapper;
@ -53,6 +55,13 @@ public class ProWorkorderServiceImpl implements IProWorkorderService
@Override
public int insertProWorkorder(ProWorkorder proWorkorder)
{
if(proWorkorder.getParentId()!= null){
ProWorkorder parent = proWorkorderMapper.selectProWorkorderByWorkorderId(proWorkorder.getParentId());
if(StringUtils.isNotNull(parent)){
proWorkorder.setAncestors(parent.getAncestors()+","+parent.getParentId());
}
}
proWorkorder.setCreateTime(DateUtils.getNowDate());
return proWorkorderMapper.insertProWorkorder(proWorkorder);
}

View File

@ -124,4 +124,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{lineId}
</foreach>
</delete>
<delete id="deleteProWorkorderBomByWorkorderId" parameterType="Long">
delete from pro_workorder_bom where workorder_id = #{workorderId}
</delete>
</mapper>

View File

@ -20,6 +20,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="clientCode" column="client_code" />
<result property="clientName" column="client_name" />
<result property="requestDate" column="request_date" />
<result property="parentId" column="parent_id" />
<result property="ancestors" column="ancestors" />
<result property="status" column="status" />
<result property="remark" column="remark" />
<result property="attr1" column="attr1" />
@ -33,7 +35,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectProWorkorderVo">
select workorder_id, workorder_code, workorder_name, order_source, source_code, product_id, product_code, product_name, product_spc, unit_of_measure, quantity, client_id, client_code, client_name, request_date, status, remark, attr1, attr2, attr3, attr4, create_by, create_time, update_by, update_time from pro_workorder
select workorder_id, workorder_code, workorder_name, order_source, source_code, product_id, product_code, product_name, product_spc, unit_of_measure, quantity, client_id, client_code, client_name, request_date, parent_id, ancestors, status, remark, attr1, attr2, attr3, attr4, create_by, create_time, update_by, update_time from pro_workorder
</sql>
<select id="selectProWorkorderList" parameterType="ProWorkorder" resultMap="ProWorkorderResult">
@ -53,6 +55,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="clientCode != null and clientCode != ''"> and client_code = #{clientCode}</if>
<if test="clientName != null and clientName != ''"> and client_name like concat('%', #{clientName}, '%')</if>
<if test="requestDate != null "> and request_date = #{requestDate}</if>
<if test="parentId != null "> and parent_id = #{parentId}</if>
<if test="ancestors != null and ancestors != ''"> and ancestors = #{ancestors}</if>
<if test="status != null and status != ''"> and status = #{status}</if>
</where>
</select>
@ -79,6 +83,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="clientCode != null">client_code,</if>
<if test="clientName != null">client_name,</if>
<if test="requestDate != null">request_date,</if>
<if test="parentId != null">parent_id,</if>
<if test="ancestors != null and ancestors != ''">ancestors,</if>
<if test="status != null">status,</if>
<if test="remark != null">remark,</if>
<if test="attr1 != null">attr1,</if>
@ -105,6 +111,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="clientCode != null">#{clientCode},</if>
<if test="clientName != null">#{clientName},</if>
<if test="requestDate != null">#{requestDate},</if>
<if test="parentId != null">#{parentId},</if>
<if test="ancestors != null and ancestors != ''">#{ancestors},</if>
<if test="status != null">#{status},</if>
<if test="remark != null">#{remark},</if>
<if test="attr1 != null">#{attr1},</if>
@ -135,6 +143,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="clientCode != null">client_code = #{clientCode},</if>
<if test="clientName != null">client_name = #{clientName},</if>
<if test="requestDate != null">request_date = #{requestDate},</if>
<if test="parentId != null">parent_id = #{parentId},</if>
<if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
<if test="status != null">status = #{status},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="attr1 != null">attr1 = #{attr1},</if>