明细批量修改接口,待测试

This commit is contained in:
hy2250089 2020-03-26 19:55:20 +08:00
parent fb085cdeba
commit 16f70ba4a4
17 changed files with 257 additions and 37 deletions

View File

@ -28,20 +28,10 @@ public class ProduceManagePublicMethod {
* 自动生成唯一的批次明细条码规则PCMX+八位日期+批次加工单id+批次号+卷号
* @return
*/
public static String creatBatchDetCode(Date createDate, Integer productProcessId, String batchCode, Integer piNum, String volumeNum) {
public static String creatBatchDetCode(Date createDate, Integer productProcessId, String batchCode, String volumeNum) {
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");
String timePartStr = sdf1.format(createDate);
int count=0; //位数计数
while(piNum>=1) {
piNum/=10;
count++;
}
for (int i = 0; i < count-1 ; i++) {
volumeNum = 0+volumeNum;//如果是一位数卷号为1如果是两位数卷号为01如果是三位数卷号为001以此类推
}
String batchDetCode = "PCMX"+timePartStr+productProcessId+batchCode+volumeNum;
return batchDetCode;
@ -49,7 +39,7 @@ public class ProduceManagePublicMethod {
public static void main(String[] args){
String code = creatBatchDetCode(new Date(), 10, "1", 100, "1");
String code = creatBatchDetCode(new Date(), 10, "1", "1");
System.out.println("----------"+code);
}
}

View File

@ -12,4 +12,6 @@ public interface ProductBatchDetectDetMapper extends Mapper<ProductBatchDetectDe
List<ProductBatchDetectDet> findList(ProductBatchDetectDetParams params);
List<ProductBatchDetectDetVo> findDetectDetVoListByBatchDetAndProcess(ProductBatchDetectParams params);
void deleteByBatchDet(ProductBatchDetectParams batchDetectParams);
}

View File

@ -10,4 +10,6 @@ public interface ProductBatchDetectMapper extends Mapper<ProductBatchDetect> {
List<ProductBatchDetect> findList(ProductBatchDetectParams params);
ProductBatchDetect findDetectByBatchDetAndProcess(ProductBatchDetectParams params);
void deleteByBatchDet(ProductBatchDetectParams batchDetectParams);
}

View File

@ -11,9 +11,13 @@ import java.util.List;
public interface ProductProcessBatchDetMapper extends Mapper<ProductProcessBatchDet> {
List<ProductProcessBatchDet> findList(ProductProcessBatchDetParams params);
//List<String> volumeStepListByProdprocid(ProductProcessParams params);
List<ProductProcessBatchDetVo> findListByProductProcess(ProductProcessParams params);
ProductProcessBatchDet findBatchDetById(ProductProcessBatchDetParams batchDetParams);
Integer findMaxVolumeNumByProductProcess(ProductProcessParams productProcessId);
void deleteByIdsList(List<Integer> deleteIdsDB);
void updateList(List<ProductProcessBatchDet> updateList);
}

View File

@ -51,4 +51,14 @@
</if>
</where> ORDER BY detectdet.position
</select>
<delete id="deleteByBatchDet" parameterType="com.deer.wms.produce.manage.model.ProductBatchDetectParams">
DELETE FROM mt_alone_product_batch_detect_det WHERE 1>2 OR ( batch_det_id IN
<foreach collection="params.batchDetIdList" item="item" open="(" separator="," close=")">
#{params.batchDetIdList[${item}]}
</foreach>
<if test="companyId != null">
AND company_id = #{params.companyId}
</if> )
</delete>
</mapper>

View File

@ -36,4 +36,14 @@
</where>
</select>
<delete id="deleteByBatchDet" parameterType="com.deer.wms.produce.manage.model.ProductBatchDetectParams">
DELETE FROM mt_alone_product_batch_detect WHERE 1>2 OR ( batch_det_id IN
<foreach collection="params.batchDetIdList" item="item" open="(" separator="," close=")">
#{params.batchDetIdList[${item}]}
</foreach>
<if test="companyId != null">
AND company_id = #{params.companyId}
</if> )
</delete>
</mapper>

View File

@ -99,5 +99,39 @@
</where>
</select>
<select id="findMaxVolumeNumByProductProcess" parameterType="com.deer.wms.produce.manage.model.ProductProcessParams">
SELECT MAX(CAST(det.volume_num AS DECIMAL)) FROM mt_alone_product_process_batch_det det
<where>
<if test="productProcessId != null">
AND det.product_process_id = #{productProcessId}
</if>
<if test="companyId != null">
AND det.company_id = #{companyId}
</if>
</where>
</select>
<update id="updateList" parameterType="java.util.List">
<foreach collection="list" index="index" item="item" open="" separator=";" close="">
UPDATE mt_alone_product_process_batch_det
<set>
update_time = #{item.updateTime},
len = #{item.len},
delivery_len = #{item.deliveryLen},
detection_len = #{item.detectionLen},
shrinkage = #{item.shrinkage}
</set>
WHERE id = #{item.id}
</foreach>
</update>
<delete id="deleteByIdsList" parameterType="java.util.List">
DELETE FROM mt_alone_product_process_batch_det WHERE 1>2 OR id IN
<foreach collection="list" item="item" open="(" separator="," close=")" >
#{item}
</foreach>
</delete>
</mapper>

View File

@ -0,0 +1,31 @@
package com.deer.wms.produce.manage.model;
import java.util.List;
/**批量修改明细时传入的参数
* @Author: hy
* @Date: 2020/3/26 15:13
* @Version 1.0
*/
public class BatchDetListAndProductProcess {
private Integer productProcessId;
private List<ProductProcessBatchDet> productProcessBatchDetList;
public Integer getProductProcessId() {
return productProcessId;
}
public void setProductProcessId(Integer productProcessId) {
this.productProcessId = productProcessId;
}
public List<ProductProcessBatchDet> getProductProcessBatchDetList() {
return productProcessBatchDetList;
}
public void setProductProcessBatchDetList(List<ProductProcessBatchDet> productProcessBatchDetList) {
this.productProcessBatchDetList = productProcessBatchDetList;
}
}

View File

@ -2,6 +2,8 @@ package com.deer.wms.produce.manage.model;
import com.deer.wms.project.seed.core.service.QueryParams;
import java.util.List;
/**
* Created by on 2019/09/09.
*/
@ -13,6 +15,8 @@ public class ProductBatchDetectParams extends QueryParams {
private Integer processId;//工序id
private List<Integer> batchDetIdList;//批次明细id的list
public Integer getProductBatchDetectId() {
return productBatchDetectId;
}
@ -36,4 +40,12 @@ public class ProductBatchDetectParams extends QueryParams {
public void setProcessId(Integer processId) {
this.processId = processId;
}
public List<Integer> getBatchDetIdList() {
return batchDetIdList;
}
public void setBatchDetIdList(List<Integer> batchDetIdList) {
this.batchDetIdList = batchDetIdList;
}
}

View File

@ -17,4 +17,6 @@ public interface ProductBatchDetectDetService extends Service<ProductBatchDetect
List<ProductBatchDetectDet> findList(ProductBatchDetectDetParams params) ;
List<ProductBatchDetectDetVo> findDetectDetVoListByBatchDetAndProcess(ProductBatchDetectParams params);
void deleteByBatchDet(ProductBatchDetectParams batchDetectParams);
}

View File

@ -20,4 +20,6 @@ public interface ProductBatchDetectService extends Service<ProductBatchDetect, I
void saveDetectRusult(ProductBatchDetectInfo productBatchDetectInfo, CurrentUser currentUser);
ProductBatchDetectResult findDetectResultByBatchDetAndProcess(ProductBatchDetectParams params);
void deleteByBatchDet(ProductBatchDetectParams batchDetectParams);
}

View File

@ -1,10 +1,8 @@
package com.deer.wms.produce.manage.service;
import com.deer.wms.produce.manage.model.ProductProcessBatchDet;
import com.deer.wms.produce.manage.model.ProductProcessBatchDetParams;
import com.deer.wms.intercept.common.data.CurrentUser;
import com.deer.wms.produce.manage.model.*;
import com.deer.wms.produce.manage.model.ProductProcessBatchDetVo;
import com.deer.wms.produce.manage.model.ProductProcessParams;
import com.deer.wms.project.seed.core.service.Service;
import java.util.List;
@ -16,11 +14,13 @@ public interface ProductProcessBatchDetService extends Service<ProductProcessBat
List<ProductProcessBatchDet> findList(ProductProcessBatchDetParams params) ;
//List<String> volumeStepListByProdprocid(ProductProcessParams params);
List<ProductProcessBatchDetVo> findListByProductProcess(ProductProcessParams params);
ProductProcessBatchDet findBatchDetById(ProductProcessBatchDetParams batchDetParams);
void batchUpdate(List<ProductProcessBatchDet> productProcessBatchDetList);
void batchModify(BatchDetListAndProductProcess batchDetListAndProductProcess, CurrentUser currentUser);
void deleteByIdsList(List<Integer> deleteIdsDB);
void updateList(List<ProductProcessBatchDet> updateList);
}

View File

@ -33,4 +33,9 @@ public class ProductBatchDetectDetServiceImpl extends AbstractService<ProductBat
public List<ProductBatchDetectDetVo> findDetectDetVoListByBatchDetAndProcess(ProductBatchDetectParams params) {
return productBatchDetectDetMapper.findDetectDetVoListByBatchDetAndProcess(params);
}
@Override
public void deleteByBatchDet(ProductBatchDetectParams batchDetectParams) {
productBatchDetectDetMapper.deleteByBatchDet(batchDetectParams);
}
}

View File

@ -77,4 +77,10 @@ public class ProductBatchDetectServiceImpl extends AbstractService<ProductBatchD
productBatchDetectResult.setProductBatchDetectDetVoList(productBatchDetectDetVoList);
return productBatchDetectResult;
}
@Override
public void deleteByBatchDet(ProductBatchDetectParams batchDetectParams) {
productBatchDetectMapper.deleteByBatchDet(batchDetectParams);
productBatchDetectDetService.deleteByBatchDet(batchDetectParams);
}
}

View File

@ -1,17 +1,23 @@
package com.deer.wms.produce.manage.service.impl;
import com.deer.wms.intercept.common.data.CurrentUser;
import com.deer.wms.produce.manage.constant.ProduceManagePublicMethod;
import com.deer.wms.produce.manage.dao.ProductProcessBatchDetMapper;
import com.deer.wms.produce.manage.model.ProductProcessBatchDet;
import com.deer.wms.produce.manage.model.ProductProcessBatchDetParams;
import com.deer.wms.produce.manage.model.ProductProcessBatchDetVo;
import com.deer.wms.produce.manage.model.ProductProcessParams;
import com.deer.wms.produce.manage.model.*;
import com.deer.wms.produce.manage.service.ProductBatchDetectService;
import com.deer.wms.produce.manage.service.ProductProcessBatchDetService;
import com.deer.wms.produce.manage.service.ProductProcessService;
import com.deer.wms.project.seed.core.service.AbstractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* Created by on 2019/09/09.
@ -23,17 +29,21 @@ public class ProductProcessBatchDetServiceImpl extends AbstractService<ProductPr
@Autowired
private ProductProcessBatchDetMapper productProcessBatchDetMapper;
@Autowired
private ProductProcessBatchDetService productProcessBatchDetService;
@Autowired
private ProductProcessService productProcessService;
@Autowired
private ProductBatchDetectService productBatchDetectService;
@Override
public List<ProductProcessBatchDet> findList(ProductProcessBatchDetParams params) {
return productProcessBatchDetMapper.findList(params);
}
//@Override
//public List<String> volumeStepListByProdprocid(ProductProcessParams params) {
// return productProcessBatchDetMapper.volumeStepListByProdprocid(params);
//}
@Override
public List<ProductProcessBatchDetVo> findListByProductProcess(ProductProcessParams params) {
return productProcessBatchDetMapper.findListByProductProcess(params);
@ -45,7 +55,99 @@ public class ProductProcessBatchDetServiceImpl extends AbstractService<ProductPr
}
@Override
public void batchUpdate(List<ProductProcessBatchDet> productProcessBatchDetList) {
public void batchModify(BatchDetListAndProductProcess batchDetListAndProductProcess, CurrentUser currentUser) {
//前端获取的所有明细
List<ProductProcessBatchDet> batchDetListFront = batchDetListAndProductProcess.getProductProcessBatchDetList();
ProductProcessParams productProcessParams = new ProductProcessParams();
productProcessParams.setProductProcessId(batchDetListAndProductProcess.getProductProcessId());
productProcessParams.setCompanyId(currentUser.getCompanyId());
ProductProcess currentProductProcess = productProcessService.findById(batchDetListAndProductProcess.getProductProcessId());
//获取当前加工单下库表中所有的明细
List<ProductProcessBatchDetVo> batchDetVoListDB = productProcessBatchDetService.findListByProductProcess(productProcessParams);
//设置加工单的总卷数与前端明细个数相同,并更新加工单信息
currentProductProcess.setPiNum(null==batchDetListFront?0:batchDetListFront.size());
productProcessService.update(currentProductProcess);
Date date = new Date();
//获取库表中该加工单下所有明细中最大的卷号,默认为0
Integer maxVolumeNumDB = productProcessBatchDetMapper.findMaxVolumeNumByProductProcess(productProcessParams);
if(null == maxVolumeNumDB)
maxVolumeNumDB = 0;
/**原则从前端的明细list中判断先拿出有id的明细更新再插入没id的明细最后删除前端已移除的明细即库表中在前端找不到对应id的明细**/
if(null!=batchDetListFront && batchDetListFront.size()!=0){//如果前端有明细
//将已有非新增明细放入一个list
List<ProductProcessBatchDet> updateList = new ArrayList<ProductProcessBatchDet>();
//将新增明细放入一个list
List<ProductProcessBatchDet> addList = new ArrayList<ProductProcessBatchDet>();
for (ProductProcessBatchDet productProcessBatchDet : batchDetListFront){
if(null!=productProcessBatchDet.getId()){//已有的明细非新增明细有id
productProcessBatchDet.setUpdateTime(date);
productProcessBatchDet.setShrinkage(productProcessBatchDet.getLen()/productProcessBatchDet.getDetectionLen()+"");
updateList.add(productProcessBatchDet);
}else{//新增明细没有id
productProcessBatchDet.setCreateTime(date);
productProcessBatchDet.setUpdateTime(date);
productProcessBatchDet.setOperatorId(currentUser.getUserId());
productProcessBatchDet.setVersion("1.1");
productProcessBatchDet.setStatus(0);
productProcessBatchDet.setBatchCode(currentProductProcess.getBatchCode());
productProcessBatchDet.setDeliveryCode(currentProductProcess.getDeliveryCode());
productProcessBatchDet.setProductProcessId(currentProductProcess.getId());
productProcessBatchDet.setVolumeNum((maxVolumeNumDB++)+"");
productProcessBatchDet.setBatchCode(ProduceManagePublicMethod.creatBatchDetCode(date, currentProductProcess.getId(), currentProductProcess.getBatchCode(), productProcessBatchDet.getVolumeNum()));
productProcessBatchDet.setShrinkage(productProcessBatchDet.getLen()/productProcessBatchDet.getDetectionLen()+"");
productProcessBatchDet.setCompanyId(currentUser.getCompanyId());
addList.add(productProcessBatchDet);
}
}
//批量删除前端已移除的明细及其瑕疵
if(null!=batchDetVoListDB && batchDetVoListDB.size()!=0){
//获取所有前端明细的id
List<Integer> idsFront = batchDetListFront.stream().map(ProductProcessBatchDet::getId).collect(Collectors.toList());
//获取该加工单下所有库表明细的id
List<Integer> idsDB = batchDetVoListDB.stream().map(ProductProcessBatchDetVo::getId).collect(Collectors.toList());
if(null!=idsDB && idsDB.size()!=0) {
List<Integer> deleteIdsDB = new ArrayList<Integer>(idsDB);
deleteIdsDB.removeAll(idsFront);
productProcessBatchDetService.deleteByIdsList(deleteIdsDB);
ProductBatchDetectParams batchDetectParams = new ProductBatchDetectParams();
batchDetectParams.setBatchDetIdList(deleteIdsDB);
batchDetectParams.setCompanyId(currentProductProcess.getCompanyId());
productBatchDetectService.deleteByBatchDet(batchDetectParams);
}
}
if(updateList.size()!=0)//批量更新对应的明细
productProcessBatchDetService.updateList(updateList);
if(addList.size()!=0)//批量插入前端新增的明细
productProcessBatchDetService.save(addList);
}else{//如果前端无明细则批量删除库表中的明细及其瑕疵
if(null!=batchDetVoListDB && batchDetVoListDB.size()!=0){
//获取该加工单下所有库表明细的id
List<Integer> idsDB = batchDetVoListDB.stream().map(ProductProcessBatchDetVo::getId).collect(Collectors.toList());
if(null!=idsDB && idsDB.size()!=0) {
productProcessBatchDetService.deleteByIdsList(idsDB);
ProductBatchDetectParams batchDetectParams = new ProductBatchDetectParams();
batchDetectParams.setBatchDetIdList(idsDB);
batchDetectParams.setCompanyId(currentProductProcess.getCompanyId());
productBatchDetectService.deleteByBatchDet(batchDetectParams);
}
}
}
}
@Override
public void deleteByIdsList(List<Integer> deleteIdsDB) {
productProcessBatchDetMapper.deleteByIdsList(deleteIdsDB);
}
@Override
public void updateList(List<ProductProcessBatchDet> updateList) {
productProcessBatchDetMapper.updateList(updateList);
}
}
}

View File

@ -255,7 +255,7 @@ public class ProductProcessServiceImpl extends AbstractService<ProductProcess, I
productProcessBatchDet.setDeliveryCode(productProcess.getDeliveryCode());
productProcessBatchDet.setProductProcessId(productProcess.getId());
productProcessBatchDet.setVolumeNum(i+1+"");
productProcessBatchDet.setBatchDetCode(ProduceManagePublicMethod.creatBatchDetCode(productProcessBatchDet.getCreateTime(), productProcessBatchDet.getProductProcessId(), productProcessBatchDet.getBatchCode(), productProcess.getPiNum(), productProcessBatchDet.getVolumeNum()));
productProcessBatchDet.setBatchDetCode(ProduceManagePublicMethod.creatBatchDetCode(productProcessBatchDet.getCreateTime(), productProcessBatchDet.getProductProcessId(), productProcessBatchDet.getBatchCode(), productProcessBatchDet.getVolumeNum()));
productProcessBatchDet.setCompanyId(currentUser.getCompanyId());
productProcessBatchDetList.add(productProcessBatchDet);

View File

@ -103,12 +103,20 @@ public class ProductProcessBatchDetController {
return ResultGenerator.genSuccessResult(pageInfo);
}
/**
* 批量修改明细包括修改删除新增
* @param batchDetListAndProductProcess
* @param currentUser
* @return
*/
@ApiImplicitParams({
@ApiImplicitParam(name = "batchDetListAndProductProcess", value = "批次加工单Id及明细list", paramType = "body", dataType = "BatchDetListAndProductProcess", required = true)
})
@OperateLog(description = "批量修改明细", type = "更新")
@ApiOperation(value = "批量修改明细", notes = "批量修改明细")
@PostMapping("/batchUpdate")
public Result batchUpdate(@RequestBody List<ProductProcessBatchDet> productProcessBatchDetList) {
productProcessBatchDetService.batchUpdate(productProcessBatchDetList);
@PostMapping("/batchModify")
public Result batchModify(@RequestBody BatchDetListAndProductProcess batchDetListAndProductProcess, @ApiIgnore @User CurrentUser currentUser) {
productProcessBatchDetService.batchModify(batchDetListAndProductProcess, currentUser);
return ResultGenerator.genSuccessResult();
}