出货检验单后台代码

This commit is contained in:
JinLu.Yin 2022-09-01 22:07:13 +08:00
parent 975ea3aba8
commit 6a5196d039
11 changed files with 151 additions and 16 deletions

View File

@ -53,6 +53,11 @@ public class QcDefectRecordController extends BaseController
@Autowired
private IQcIpqcService qcIpqcService;
@Autowired
private IQcOqcService qcOqcService;
@Autowired
private IQcOqcLineService qcOqcLineService;
/**
@ -138,9 +143,9 @@ public class QcDefectRecordController extends BaseController
qcIpqcService.updateCrMajMinQuaAndRate(qcId);
}else {
//更新出货检验单行上的cr,maj,min数量
qcOqcLineService.updateCrMajMinQuantity(qcId,lineId);
//更新出货检验单头上的cr,maj,min数量和比例
qcOqcService.updateCrMajMinQuaAndRate(qcId);
}
}

View File

@ -125,19 +125,8 @@ public class QcIqcController extends BaseController
if(UserConstants.NOT_UNIQUE.equals(qcIqcService.checkIqcCodeUnique(qcIqc))){
return AjaxResult.error("单据编号已存在!");
}
QcTemplateProduct param = new QcTemplateProduct();
param.setItemId(qcIqc.getItemId());
List<QcTemplateProduct> templates = qcTemplateProductService.selectQcTemplateProductList(param);
if(CollUtil.isNotEmpty(templates)){
qcIqc.setTemplateId(templates.get(0).getTemplateId());
}else{
return AjaxResult.error("当前产品未配置检测模板!");
}
int ret = qcIqcService.updateQcIqc(qcIqc);
generateLine(qcIqc);
return toAjax(ret);
return toAjax(qcIqcService.updateQcIqc(qcIqc));
}
/**

View File

@ -1,10 +1,15 @@
package com.ktg.mes.qc.controller;
import java.math.BigDecimal;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import cn.hutool.core.collection.CollUtil;
import com.ktg.common.constant.UserConstants;
import com.ktg.mes.qc.domain.*;
import com.ktg.mes.qc.service.IQcOqcLineService;
import com.ktg.mes.qc.service.IQcTemplateIndexService;
import com.ktg.mes.qc.service.IQcTemplateProductService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
@ -20,7 +25,6 @@ import com.ktg.common.annotation.Log;
import com.ktg.common.core.controller.BaseController;
import com.ktg.common.core.domain.AjaxResult;
import com.ktg.common.enums.BusinessType;
import com.ktg.mes.qc.domain.QcOqc;
import com.ktg.mes.qc.service.IQcOqcService;
import com.ktg.common.utils.poi.ExcelUtil;
import com.ktg.common.core.page.TableDataInfo;
@ -41,6 +45,12 @@ public class QcOqcController extends BaseController
@Autowired
private IQcOqcLineService qcOqcLineService;
@Autowired
private IQcTemplateProductService qcTemplateProductService;
@Autowired
private IQcTemplateIndexService qcTemplateIndexService;
/**
* 查询出货检验单列表
*/
@ -87,7 +97,24 @@ public class QcOqcController extends BaseController
if(UserConstants.NOT_UNIQUE.equals(qcOqcService.checkOqcCodeUnique(qcOqc))){
return AjaxResult.error("出货单编号已存在!");
}
return toAjax(qcOqcService.insertQcOqc(qcOqc));
//自动获取对应的检测模板
QcTemplateProduct param = new QcTemplateProduct();
param.setItemId(qcOqc.getItemId());
List<QcTemplateProduct> templates = qcTemplateProductService.selectQcTemplateProductList(param);
if(CollUtil.isNotEmpty(templates)){
qcOqc.setTemplateId(templates.get(0).getTemplateId());
}else{
return AjaxResult.error("当前产品未配置检测模板!");
}
//设置检测人
qcOqc.setInspector(getUsername());
//先保存单据
qcOqcService.insertQcOqc(qcOqc);
//生成行信息
generateLine(qcOqc);
Long oqcId = qcOqc.getOqcId();
return AjaxResult.success(oqcId);
}
/**
@ -124,4 +151,35 @@ public class QcOqcController extends BaseController
return toAjax(qcOqcService.deleteQcOqcByOqcIds(oqcIds));
}
/**
* 根据头信息生成行信息
* @param oqc
*/
private void generateLine(QcOqc oqc){
QcTemplateIndex param = new QcTemplateIndex();
param.setTemplateId(oqc.getTemplateId());
List<QcTemplateIndex> indexs = qcTemplateIndexService.selectQcTemplateIndexList(param);
if(CollUtil.isNotEmpty(indexs)){
for (QcTemplateIndex index:indexs
) {
QcOqcLine line = new QcOqcLine();
line.setOqcId(oqc.getOqcId());
line.setIndexId(index.getIndexId());
line.setIndexCode(index.getIndexCode());
line.setIndexName(index.getIndexName());
line.setIndexType(index.getIndexType());
line.setQcTool(index.getQcTool());
line.setCheckMethod(index.getCheckMethod());
line.setStanderVal(index.getStanderVal());
line.setUnitOfMeasure(index.getUnitOfMeasure());
line.setThresholdMax(index.getThresholdMax());
line.setThresholdMin(index.getThresholdMin());
line.setCrQuantity(new BigDecimal(0L));
line.setMajQuantity(new BigDecimal(0L));
line.setMajQuantity(new BigDecimal(0L));
qcOqcLineService.insertQcOqcLine(line);
}
}
}
}

View File

@ -43,6 +43,13 @@ public interface QcOqcLineMapper
*/
public int updateQcOqcLine(QcOqcLine qcOqcLine);
/**
* 根据缺陷记录更新行上的缺陷数量
* @param qcOqcLine
* @return
*/
public int updateCrMajMinQuantity(QcOqcLine qcOqcLine);
/**
* 删除出货检验单行
*

View File

@ -50,6 +50,13 @@ public interface QcOqcMapper
*/
public int updateQcOqc(QcOqc qcOqc);
/**
* 根据缺陷记录更新头上的缺陷数量和缺陷比率
* @param oqc
* @return
*/
public int updateCrMajMinQuaAndRate(Long oqc);
/**
* 删除出货检验单
*

View File

@ -43,6 +43,14 @@ public interface IQcOqcLineService
*/
public int updateQcOqcLine(QcOqcLine qcOqcLine);
/**
* 计算并更新当前行的Cr,Maj,Min的总数量
* @param qcId
* @param lineId
* @return
*/
public int updateCrMajMinQuantity(Long qcId,Long lineId);
/**
* 批量删除出货检验单行
*

View File

@ -51,6 +51,13 @@ public interface IQcOqcService
*/
public int updateQcOqc(QcOqc qcOqc);
/**
* 根据缺陷记录更新头上的缺陷数量和缺陷比率
* @param oqcId
* @return
*/
public int updateCrMajMinQuaAndRate(Long oqcId);
/**
* 批量删除出货检验单
*

View File

@ -70,6 +70,14 @@ public class QcOqcLineServiceImpl implements IQcOqcLineService
return qcOqcLineMapper.updateQcOqcLine(qcOqcLine);
}
@Override
public int updateCrMajMinQuantity(Long qcId, Long lineId) {
QcOqcLine line = new QcOqcLine();
line.setLineId(lineId);
line.setOqcId(qcId);
return qcOqcLineMapper.updateCrMajMinQuantity(line);
}
/**
* 批量删除出货检验单行
*

View File

@ -83,6 +83,11 @@ public class QcOqcServiceImpl implements IQcOqcService
return qcOqcMapper.updateQcOqc(qcOqc);
}
@Override
public int updateCrMajMinQuaAndRate(Long oqcId) {
return qcOqcMapper.updateCrMajMinQuaAndRate(oqcId);
}
/**
* 批量删除出货检验单
*

View File

@ -144,6 +144,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where line_id = #{lineId}
</update>
<update id="updateCrMajMinQuantity" parameterType="QcOqcLine">
UPDATE qc_oqc_line a
INNER JOIN (
SELECT SUM(CASE WHEN defect_level = 'CR' THEN defect_quantity ELSE 0 END ) AS cr_quantity,
SUM(CASE WHEN defect_level = 'MAJ' THEN defect_quantity ELSE 0 END) AS maj_quantity,
SUM(CASE WHEN defect_level = 'MIN' THEN defect_quantity ELSE 0 END) AS min_quantity,
qid.`qc_id` as 'oqc_id',
qid.`line_id`
FROM qc_defect_record qid
WHERE qid.qc_id = #{oqcId}
AND qid.line_id = #{lineId}
AND qid.qc_type = 'OQC'
GROUP BY qid.qc_id,qid.line_id
)b
ON a.oqc_id = b.oqc_id AND a.line_id = b.line_id
SET a.cr_quantity=b.cr_quantity,a.maj_quantity=b.maj_quantity,a.min_quantity=b.min_quantity
WHERE a.oqc_id = #{oqcId}
AND a.line_id = #{lineId}
</update>
<delete id="deleteQcOqcLineByLineId" parameterType="Long">
delete from qc_oqc_line where line_id = #{lineId}
</delete>

View File

@ -224,6 +224,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where oqc_id = #{oqcId}
</update>
<update id="updateCrMajMinQuaAndRate" parameterType="Long">
UPDATE qc_oqc a
INNER JOIN (
SELECT SUM(CASE WHEN defect_level = 'CR' THEN defect_quantity ELSE 0 END ) AS cr_quantity,
SUM(CASE WHEN defect_level = 'MAJ' THEN defect_quantity ELSE 0 END) AS maj_quantity,
SUM(CASE WHEN defect_level = 'MIN' THEN defect_quantity ELSE 0 END) AS min_quantity,
qid.`qc_id` as 'oqc_id'
FROM qc_defect_record qid
WHERE qid.qc_id = #{oqcId}
and qc_type = 'OQC'
GROUP BY qid.qc_id
) b
ON a.`oqc_id` = b.oqc_id
SET a.cr_quantity=b.cr_quantity,a.maj_quantity=b.maj_quantity,a.min_quantity=b.min_quantity,
a.`cr_rate`= ROUND(b.cr_quantity/a.`quantity_check`*100,2),
a.`maj_rate`= ROUND(b.maj_quantity/a.`quantity_check`*100,2),
a.`min_rate`= ROUND(b.min_quantity/a.`quantity_check`*100,2)
WHERE a.oqc_id = #{oqcId}
</update>
<delete id="deleteQcOqcByOqcId" parameterType="Long">
delete from qc_oqc where oqc_id = #{oqcId}
</delete>