生产模块
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package com.gear.mes.production.controller;
|
||||
|
||||
import com.gear.common.core.controller.BaseController;
|
||||
import com.gear.common.core.domain.AjaxResult;
|
||||
import com.gear.common.core.domain.R;
|
||||
import com.gear.common.core.page.TableDataInfo;
|
||||
import com.gear.mes.production.domain.GearProductionTask;
|
||||
import com.gear.mes.production.domain.vo.GearProductionTaskListVo;
|
||||
import com.gear.mes.production.domain.vo.GearProductionTaskWithDetailVo;
|
||||
import com.gear.mes.production.service.IGearProductionTaskService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/mes/production/task")
|
||||
public class GearProductionTaskController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private IGearProductionTaskService productionTaskService;
|
||||
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<GearProductionTaskListVo> list(GearProductionTask query) {
|
||||
startPage();
|
||||
List<GearProductionTaskListVo> list = productionTaskService.selectTaskList(query);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@GetMapping("/{taskId}")
|
||||
public AjaxResult getInfo(@PathVariable("taskId") Long taskId) {
|
||||
return AjaxResult.success(productionTaskService.selectTaskWithDetail(taskId));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public R<Long> add(@RequestBody GearProductionTaskWithDetailVo bo) {
|
||||
Long taskId = productionTaskService.insertTaskWithDetail(bo);
|
||||
if (taskId == null) {
|
||||
return R.fail("新增失败");
|
||||
}
|
||||
return R.ok(taskId);
|
||||
}
|
||||
|
||||
@PostMapping("/{taskId}/complete")
|
||||
public R<Void> complete(@PathVariable("taskId") Long taskId) {
|
||||
boolean ok = productionTaskService.completeTask(taskId);
|
||||
if (!ok) {
|
||||
return R.fail("完成失败");
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.gear.mes.production.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.gear.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class GearProductionTask extends BaseEntity {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long taskId;
|
||||
|
||||
private String taskCode;
|
||||
|
||||
private String taskName;
|
||||
|
||||
private String status;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date planStartTime;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date planEndTime;
|
||||
|
||||
private String remark;
|
||||
|
||||
private String delFlag;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date beginTime;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date endTime;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.gear.mes.production.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class GearProductionTaskMaterial {
|
||||
private Long lineId;
|
||||
|
||||
private Long taskId;
|
||||
|
||||
private Long materialId;
|
||||
|
||||
private String materialRole;
|
||||
|
||||
private BigDecimal planQty;
|
||||
|
||||
private BigDecimal usedQty;
|
||||
|
||||
private String unit;
|
||||
|
||||
private String remark;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.gear.mes.production.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class GearProductionTaskProduct {
|
||||
private Long lineId;
|
||||
|
||||
private Long taskId;
|
||||
|
||||
private Long productId;
|
||||
|
||||
private BigDecimal planQty;
|
||||
|
||||
private BigDecimal finishedQty;
|
||||
|
||||
private BigDecimal badQty;
|
||||
|
||||
private String unit;
|
||||
|
||||
private String remark;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.gear.mes.production.domain.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class GearProductionTaskListVo {
|
||||
private Long taskId;
|
||||
|
||||
private String taskCode;
|
||||
|
||||
private String taskName;
|
||||
|
||||
private String status;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date planStartTime;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date planEndTime;
|
||||
|
||||
private String remark;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date updateTime;
|
||||
|
||||
private BigDecimal planQty;
|
||||
|
||||
private BigDecimal finishedQty;
|
||||
|
||||
private BigDecimal badQty;
|
||||
|
||||
private BigDecimal unfinishedQty;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.gear.mes.production.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class GearProductionTaskMaterialVo {
|
||||
private Long lineId;
|
||||
|
||||
private Long taskId;
|
||||
|
||||
private Long materialId;
|
||||
|
||||
private String materialRole;
|
||||
|
||||
private BigDecimal planQty;
|
||||
|
||||
private BigDecimal usedQty;
|
||||
|
||||
private String unit;
|
||||
|
||||
private String remark;
|
||||
|
||||
private String materialName;
|
||||
|
||||
private Integer materialType;
|
||||
|
||||
private String spec;
|
||||
|
||||
private String model;
|
||||
|
||||
private String factory;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.gear.mes.production.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class GearProductionTaskProductVo {
|
||||
private Long lineId;
|
||||
|
||||
private Long taskId;
|
||||
|
||||
private Long productId;
|
||||
|
||||
private BigDecimal planQty;
|
||||
|
||||
private BigDecimal finishedQty;
|
||||
|
||||
private BigDecimal badQty;
|
||||
|
||||
private String unit;
|
||||
|
||||
private String remark;
|
||||
|
||||
private String productName;
|
||||
|
||||
private String productCode;
|
||||
|
||||
private String productType;
|
||||
|
||||
private String spec;
|
||||
|
||||
private String model;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.gear.mes.production.domain.vo;
|
||||
|
||||
import com.gear.mes.production.domain.GearProductionTask;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class GearProductionTaskWithDetailVo {
|
||||
private GearProductionTask task;
|
||||
|
||||
private List<GearProductionTaskProductVo> products;
|
||||
|
||||
private List<GearProductionTaskMaterialVo> materials;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.gear.mes.production.mapper;
|
||||
|
||||
import com.gear.mes.production.domain.GearProductionTask;
|
||||
import com.gear.mes.production.domain.vo.GearProductionTaskListVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public interface GearProductionTaskMapper {
|
||||
List<GearProductionTaskListVo> selectTaskList(GearProductionTask query);
|
||||
|
||||
GearProductionTask selectTaskById(@Param("taskId") Long taskId);
|
||||
|
||||
int insertTask(GearProductionTask task);
|
||||
|
||||
int updateTask(GearProductionTask task);
|
||||
|
||||
int updateTaskStatus(@Param("taskId") Long taskId,
|
||||
@Param("status") String status,
|
||||
@Param("updateBy") String updateBy,
|
||||
@Param("updateTime") Date updateTime);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.gear.mes.production.mapper;
|
||||
|
||||
import com.gear.mes.production.domain.GearProductionTaskMaterial;
|
||||
import com.gear.mes.production.domain.vo.GearProductionTaskMaterialVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface GearProductionTaskMaterialMapper {
|
||||
List<GearProductionTaskMaterialVo> selectByTaskId(@Param("taskId") Long taskId);
|
||||
|
||||
List<GearProductionTaskMaterial> selectRequirementByTaskId(@Param("taskId") Long taskId);
|
||||
|
||||
int insertBatch(@Param("list") List<GearProductionTaskMaterial> list);
|
||||
|
||||
int deleteByTaskId(@Param("taskId") Long taskId);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.gear.mes.production.mapper;
|
||||
|
||||
import com.gear.mes.production.domain.vo.GearProductionTaskProductVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface GearProductionTaskProductMapper {
|
||||
List<GearProductionTaskProductVo> selectByTaskId(@Param("taskId") Long taskId);
|
||||
|
||||
int insertBatch(@Param("list") List<com.gear.mes.production.domain.GearProductionTaskProduct> list);
|
||||
|
||||
int deleteByTaskId(@Param("taskId") Long taskId);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.gear.mes.production.service;
|
||||
|
||||
import com.gear.mes.production.domain.GearProductionTask;
|
||||
import com.gear.mes.production.domain.vo.GearProductionTaskListVo;
|
||||
import com.gear.mes.production.domain.vo.GearProductionTaskWithDetailVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IGearProductionTaskService {
|
||||
List<GearProductionTaskListVo> selectTaskList(GearProductionTask query);
|
||||
|
||||
GearProductionTaskWithDetailVo selectTaskWithDetail(Long taskId);
|
||||
|
||||
Long insertTaskWithDetail(GearProductionTaskWithDetailVo bo);
|
||||
|
||||
boolean completeTask(Long taskId);
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package com.gear.mes.production.service.impl;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.gear.mes.production.domain.GearProductionTask;
|
||||
import com.gear.mes.production.domain.GearProductionTaskMaterial;
|
||||
import com.gear.mes.production.domain.GearProductionTaskProduct;
|
||||
import com.gear.mes.production.domain.vo.GearProductionTaskListVo;
|
||||
import com.gear.mes.production.domain.vo.GearProductionTaskMaterialVo;
|
||||
import com.gear.mes.production.domain.vo.GearProductionTaskWithDetailVo;
|
||||
import com.gear.common.utils.DateUtils;
|
||||
import com.gear.mes.production.mapper.GearProductionTaskMapper;
|
||||
import com.gear.mes.production.mapper.GearProductionTaskMaterialMapper;
|
||||
import com.gear.mes.production.mapper.GearProductionTaskProductMapper;
|
||||
import com.gear.mes.production.service.IGearProductionTaskService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class GearProductionTaskServiceImpl implements IGearProductionTaskService {
|
||||
|
||||
@Autowired
|
||||
private GearProductionTaskMapper taskMapper;
|
||||
|
||||
@Autowired
|
||||
private GearProductionTaskProductMapper productMapper;
|
||||
|
||||
@Autowired
|
||||
private GearProductionTaskMaterialMapper materialMapper;
|
||||
|
||||
@Override
|
||||
public List<GearProductionTaskListVo> selectTaskList(GearProductionTask query) {
|
||||
return taskMapper.selectTaskList(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GearProductionTaskWithDetailVo selectTaskWithDetail(Long taskId) {
|
||||
GearProductionTask task = taskMapper.selectTaskById(taskId);
|
||||
GearProductionTaskWithDetailVo vo = new GearProductionTaskWithDetailVo();
|
||||
vo.setTask(task);
|
||||
if (taskId == null) {
|
||||
vo.setProducts(null);
|
||||
vo.setMaterials(null);
|
||||
return vo;
|
||||
}
|
||||
vo.setProducts(productMapper.selectByTaskId(taskId));
|
||||
List<GearProductionTaskMaterialVo> materials = materialMapper.selectByTaskId(taskId);
|
||||
if (task != null && "2".equals(String.valueOf(task.getStatus())) && (materials == null || materials.isEmpty())) {
|
||||
regenerateReceiptMaterials(taskId);
|
||||
materials = materialMapper.selectByTaskId(taskId);
|
||||
}
|
||||
vo.setMaterials(materials);
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long insertTaskWithDetail(GearProductionTaskWithDetailVo bo) {
|
||||
if (bo == null || bo.getTask() == null) {
|
||||
return null;
|
||||
}
|
||||
GearProductionTask task = bo.getTask();
|
||||
Long taskId = task.getTaskId() != null ? task.getTaskId() : IdUtil.getSnowflakeNextId();
|
||||
task.setTaskId(taskId);
|
||||
if (task.getDelFlag() == null) {
|
||||
task.setDelFlag("0");
|
||||
}
|
||||
if (task.getStatus() == null || String.valueOf(task.getStatus()).trim().isEmpty()) {
|
||||
task.setStatus("1");
|
||||
}
|
||||
task.setCreateTime(DateUtils.getNowDate());
|
||||
task.setUpdateTime(DateUtils.getNowDate());
|
||||
taskMapper.insertTask(task);
|
||||
|
||||
List<GearProductionTaskProduct> products = new ArrayList<>();
|
||||
if (bo.getProducts() != null) {
|
||||
bo.getProducts().forEach(p -> {
|
||||
if (p == null || p.getProductId() == null) return;
|
||||
GearProductionTaskProduct row = new GearProductionTaskProduct();
|
||||
row.setLineId(IdUtil.getSnowflakeNextId());
|
||||
row.setTaskId(taskId);
|
||||
row.setProductId(p.getProductId());
|
||||
row.setPlanQty(p.getPlanQty() == null ? BigDecimal.ZERO : p.getPlanQty());
|
||||
row.setFinishedQty(p.getFinishedQty() == null ? BigDecimal.ZERO : p.getFinishedQty());
|
||||
row.setBadQty(p.getBadQty() == null ? BigDecimal.ZERO : p.getBadQty());
|
||||
row.setUnit(p.getUnit());
|
||||
row.setRemark(p.getRemark());
|
||||
products.add(row);
|
||||
});
|
||||
}
|
||||
if (!products.isEmpty()) {
|
||||
productMapper.insertBatch(products);
|
||||
}
|
||||
|
||||
return taskId;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean completeTask(Long taskId) {
|
||||
if (taskId == null) {
|
||||
return false;
|
||||
}
|
||||
GearProductionTask task = taskMapper.selectTaskById(taskId);
|
||||
if (task == null) {
|
||||
return false;
|
||||
}
|
||||
int updated = taskMapper.updateTaskStatus(taskId, "2", task.getUpdateBy(), DateUtils.getNowDate());
|
||||
if (updated <= 0) {
|
||||
return false;
|
||||
}
|
||||
regenerateReceiptMaterials(taskId);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void regenerateReceiptMaterials(Long taskId) {
|
||||
materialMapper.deleteByTaskId(taskId);
|
||||
List<GearProductionTaskMaterial> required = materialMapper.selectRequirementByTaskId(taskId);
|
||||
if (required == null || required.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
List<GearProductionTaskMaterial> rows = new ArrayList<>();
|
||||
required.forEach(r -> {
|
||||
if (r == null || r.getMaterialId() == null) return;
|
||||
GearProductionTaskMaterial row = new GearProductionTaskMaterial();
|
||||
row.setLineId(IdUtil.getSnowflakeNextId());
|
||||
row.setTaskId(taskId);
|
||||
row.setMaterialId(r.getMaterialId());
|
||||
row.setMaterialRole(r.getMaterialRole());
|
||||
BigDecimal planQty = r.getPlanQty() == null ? BigDecimal.ZERO : r.getPlanQty();
|
||||
row.setPlanQty(planQty);
|
||||
row.setUsedQty(planQty);
|
||||
row.setUnit(r.getUnit());
|
||||
row.setRemark(null);
|
||||
rows.add(row);
|
||||
});
|
||||
if (!rows.isEmpty()) {
|
||||
materialMapper.insertBatch(rows);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.gear.mes.production.mapper.GearProductionTaskMapper">
|
||||
|
||||
<select id="selectTaskList" parameterType="com.gear.mes.production.domain.GearProductionTask" resultType="com.gear.mes.production.domain.vo.GearProductionTaskListVo">
|
||||
SELECT
|
||||
t.task_id AS taskId,
|
||||
t.task_code AS taskCode,
|
||||
t.task_name AS taskName,
|
||||
t.status AS status,
|
||||
t.plan_start_time AS planStartTime,
|
||||
t.plan_end_time AS planEndTime,
|
||||
t.remark AS remark,
|
||||
t.create_time AS createTime,
|
||||
t.update_time AS updateTime,
|
||||
IFNULL(SUM(p.plan_qty), 0) AS planQty,
|
||||
IFNULL(SUM(p.finished_qty), 0) AS finishedQty,
|
||||
IFNULL(SUM(p.bad_qty), 0) AS badQty,
|
||||
GREATEST(IFNULL(SUM(p.plan_qty), 0) - IFNULL(SUM(p.finished_qty), 0), 0) AS unfinishedQty
|
||||
FROM gear_production_task t
|
||||
LEFT JOIN gear_production_task_product p ON t.task_id = p.task_id
|
||||
<where>
|
||||
t.del_flag = '0'
|
||||
<if test="status != null and status != ''"> AND t.status = #{status}</if>
|
||||
<if test="taskCode != null and taskCode != ''"> AND t.task_code LIKE CONCAT('%', #{taskCode}, '%')</if>
|
||||
<if test="taskName != null and taskName != ''"> AND t.task_name LIKE CONCAT('%', #{taskName}, '%')</if>
|
||||
<if test="beginTime != null"> AND t.plan_start_time <![CDATA[>=]]> #{beginTime}</if>
|
||||
<if test="endTime != null"> AND t.plan_start_time <![CDATA[<=]]> #{endTime}</if>
|
||||
</where>
|
||||
GROUP BY t.task_id
|
||||
ORDER BY t.update_time DESC, t.create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="selectTaskById" resultType="com.gear.mes.production.domain.GearProductionTask">
|
||||
SELECT
|
||||
task_id AS taskId,
|
||||
task_code AS taskCode,
|
||||
task_name AS taskName,
|
||||
status AS status,
|
||||
plan_start_time AS planStartTime,
|
||||
plan_end_time AS planEndTime,
|
||||
remark AS remark,
|
||||
create_by AS createBy,
|
||||
create_time AS createTime,
|
||||
update_by AS updateBy,
|
||||
update_time AS updateTime
|
||||
FROM gear_production_task
|
||||
WHERE task_id = #{taskId}
|
||||
AND del_flag = '0'
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<insert id="insertTask" parameterType="com.gear.mes.production.domain.GearProductionTask">
|
||||
INSERT INTO gear_production_task (
|
||||
task_id,
|
||||
task_code,
|
||||
task_name,
|
||||
status,
|
||||
plan_start_time,
|
||||
plan_end_time,
|
||||
remark,
|
||||
del_flag,
|
||||
create_by,
|
||||
create_time,
|
||||
update_by,
|
||||
update_time
|
||||
) VALUES (
|
||||
#{taskId},
|
||||
#{taskCode},
|
||||
#{taskName},
|
||||
#{status},
|
||||
#{planStartTime},
|
||||
#{planEndTime},
|
||||
#{remark},
|
||||
#{delFlag},
|
||||
#{createBy},
|
||||
#{createTime},
|
||||
#{updateBy},
|
||||
#{updateTime}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="updateTask" parameterType="com.gear.mes.production.domain.GearProductionTask">
|
||||
UPDATE gear_production_task
|
||||
SET
|
||||
task_code = #{taskCode},
|
||||
task_name = #{taskName},
|
||||
status = #{status},
|
||||
plan_start_time = #{planStartTime},
|
||||
plan_end_time = #{planEndTime},
|
||||
remark = #{remark},
|
||||
update_by = #{updateBy},
|
||||
update_time = #{updateTime}
|
||||
WHERE task_id = #{taskId}
|
||||
AND del_flag = '0'
|
||||
</update>
|
||||
|
||||
<update id="updateTaskStatus">
|
||||
UPDATE gear_production_task
|
||||
SET
|
||||
status = #{status},
|
||||
update_by = #{updateBy},
|
||||
update_time = #{updateTime}
|
||||
WHERE task_id = #{taskId}
|
||||
AND del_flag = '0'
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.gear.mes.production.mapper.GearProductionTaskMaterialMapper">
|
||||
|
||||
<select id="selectByTaskId" resultType="com.gear.mes.production.domain.vo.GearProductionTaskMaterialVo">
|
||||
SELECT
|
||||
m.line_id AS lineId,
|
||||
m.task_id AS taskId,
|
||||
m.material_id AS materialId,
|
||||
m.material_role AS materialRole,
|
||||
m.plan_qty AS planQty,
|
||||
m.used_qty AS usedQty,
|
||||
m.unit AS unit,
|
||||
m.remark AS remark,
|
||||
mm.material_name AS materialName,
|
||||
mm.material_type AS materialType,
|
||||
mm.spec AS spec,
|
||||
mm.model AS model,
|
||||
mm.factory AS factory
|
||||
FROM gear_production_task_material m
|
||||
LEFT JOIN mat_material mm ON m.material_id = mm.material_id
|
||||
WHERE m.task_id = #{taskId}
|
||||
ORDER BY m.material_role, m.line_id
|
||||
</select>
|
||||
|
||||
<select id="selectRequirementByTaskId" resultType="com.gear.mes.production.domain.GearProductionTaskMaterial">
|
||||
SELECT
|
||||
r.material_id AS materialId,
|
||||
CASE WHEN mm.material_type = 2 THEN 'main' ELSE 'aux' END AS materialRole,
|
||||
SUM(
|
||||
(
|
||||
CASE
|
||||
WHEN p.finished_qty IS NOT NULL AND p.finished_qty > 0 THEN p.finished_qty
|
||||
ELSE IFNULL(p.plan_qty, 0)
|
||||
END
|
||||
) * IFNULL(r.material_num, 0)
|
||||
) AS planQty,
|
||||
mm.unit AS unit
|
||||
FROM gear_production_task_product p
|
||||
JOIN mat_product_material_relation r ON p.product_id = r.product_id AND r.del_flag = 0
|
||||
LEFT JOIN mat_material mm ON r.material_id = mm.material_id
|
||||
WHERE p.task_id = #{taskId}
|
||||
GROUP BY r.material_id, mm.material_type, mm.unit
|
||||
ORDER BY mm.material_type DESC, MIN(IFNULL(r.sort, 0)), r.material_id
|
||||
</select>
|
||||
|
||||
<insert id="insertBatch">
|
||||
INSERT INTO gear_production_task_material (
|
||||
line_id,
|
||||
task_id,
|
||||
material_id,
|
||||
material_role,
|
||||
plan_qty,
|
||||
used_qty,
|
||||
unit,
|
||||
remark
|
||||
)
|
||||
VALUES
|
||||
<foreach collection="list" item="i" separator=",">
|
||||
(
|
||||
#{i.lineId},
|
||||
#{i.taskId},
|
||||
#{i.materialId},
|
||||
#{i.materialRole},
|
||||
#{i.planQty},
|
||||
#{i.usedQty},
|
||||
#{i.unit},
|
||||
#{i.remark}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<delete id="deleteByTaskId">
|
||||
DELETE FROM gear_production_task_material WHERE task_id = #{taskId}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.gear.mes.production.mapper.GearProductionTaskProductMapper">
|
||||
|
||||
<select id="selectByTaskId" resultType="com.gear.mes.production.domain.vo.GearProductionTaskProductVo">
|
||||
SELECT
|
||||
p.line_id AS lineId,
|
||||
p.task_id AS taskId,
|
||||
p.product_id AS productId,
|
||||
p.plan_qty AS planQty,
|
||||
p.finished_qty AS finishedQty,
|
||||
p.bad_qty AS badQty,
|
||||
p.unit AS unit,
|
||||
p.remark AS remark,
|
||||
COALESCE(gp.product_name, mp.product_name) AS productName,
|
||||
COALESCE(gp.product_code, CAST(mp.product_id AS CHAR)) AS productCode,
|
||||
COALESCE(gp.type, mp.product_type) AS productType,
|
||||
mp.spec AS spec,
|
||||
mp.model AS model
|
||||
FROM gear_production_task_product p
|
||||
LEFT JOIN gear_product gp ON p.product_id = gp.product_id
|
||||
LEFT JOIN mat_product mp ON p.product_id = mp.product_id
|
||||
WHERE p.task_id = #{taskId}
|
||||
ORDER BY p.line_id
|
||||
</select>
|
||||
|
||||
<insert id="insertBatch">
|
||||
INSERT INTO gear_production_task_product (
|
||||
line_id,
|
||||
task_id,
|
||||
product_id,
|
||||
plan_qty,
|
||||
finished_qty,
|
||||
bad_qty,
|
||||
unit,
|
||||
remark
|
||||
)
|
||||
VALUES
|
||||
<foreach collection="list" item="i" separator=",">
|
||||
(
|
||||
#{i.lineId},
|
||||
#{i.taskId},
|
||||
#{i.productId},
|
||||
#{i.planQty},
|
||||
#{i.finishedQty},
|
||||
#{i.badQty},
|
||||
#{i.unit},
|
||||
#{i.remark}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<delete id="deleteByTaskId">
|
||||
DELETE FROM gear_production_task_product WHERE task_id = #{taskId}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user