package doumeemes.service.ext.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageInfo;
|
import doumeemes.biz.system.SystemDictDataBiz;
|
import doumeemes.core.annotation.excel.ExcelExporter;
|
import doumeemes.core.constants.ResponseStatus;
|
import doumeemes.core.exception.BusinessException;
|
import doumeemes.core.model.LoginUserInfo;
|
import doumeemes.core.model.PageData;
|
import doumeemes.core.model.PageWrap;
|
import doumeemes.core.utils.Constants;
|
import doumeemes.core.utils.DateUtil;
|
import doumeemes.core.utils.redis.RedisUtil;
|
import doumeemes.dao.business.BackOrderDetailMapper;
|
import doumeemes.dao.business.BackorderMapper;
|
import doumeemes.dao.business.SalaryParamMapper;
|
import doumeemes.dao.business.UnqualifiedRecordMapper;
|
import doumeemes.dao.business.dto.*;
|
import doumeemes.dao.business.model.*;
|
import doumeemes.dao.ext.*;
|
import doumeemes.dao.ext.bean.EndCheckApBean;
|
import doumeemes.dao.ext.beanDto.QueryWStockDto;
|
import doumeemes.dao.ext.dto.*;
|
import doumeemes.dao.ext.vo.*;
|
import doumeemes.dao.system.model.SystemDictData;
|
import doumeemes.service.business.UnqualifiedRecordService;
|
import doumeemes.service.business.WOutboundService;
|
import doumeemes.service.ext.*;
|
import doumeemes.service.system.SystemDictDataService;
|
import org.apache.commons.lang3.StringUtils;
|
import org.apache.shiro.SecurityUtils;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.math.BigDecimal;
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Objects;
|
import java.util.stream.Collectors;
|
|
/**
|
* 工单生产过程记录Service实现
|
* @author 江蹄蹄
|
* @date 2022/04/20 10:56
|
*/
|
@Service
|
public class WorkorderRecordStandardServiceImpl implements WorkorderRecordStandardService {
|
|
|
@Autowired
|
private WorkorderExtMapper workorderExtMapper;
|
@Autowired
|
private BomExtMapper bomExtMapper;
|
@Autowired
|
private RouteProcedureExtMapper routeProcedureExtMapper;
|
@Autowired
|
private BomDetailExtMapper bomDetailExtMapper;
|
@Autowired
|
private WorkorderRecordExtMapper workorderRecordExtMapper;
|
@Autowired
|
private WorkorderHistoryExtMapper workorderHistoryExtMapper;
|
@Autowired
|
private WStockExtMapper wStockExtMapper;
|
@Autowired
|
private WOutboundDetailExtMapper wOutboundDetailExtMapper;
|
@Autowired
|
private WOutboundService wOutboundService;
|
@Autowired
|
private WStockRecordExtService wStockRecordExtService;
|
@Autowired
|
private WOutboundRecordExtMapper wOutboundRecordExtMapper;
|
@Autowired
|
private MaterialExtMapper materialExtMapper;
|
@Autowired
|
private SalaryParamMapper salaryParamMapper;
|
@Autowired
|
private PlansExtMapper plansExtMapper;
|
@Autowired
|
private DeviceExtMapper deviceExtMapper;
|
@Autowired
|
private UnqualifiedRecordMapper unqualifiedRecordMapper;
|
@Autowired
|
private CompanyUserExtMapper companyUserExtMapper;
|
|
@Autowired
|
private UnqualifiedRecordService unqualifiedRecordService;
|
|
@Transactional(rollbackFor = {BusinessException.class,Exception.class})
|
@Override
|
public Integer createMaterialStandard(CreateMaterialDTO param) {
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!");
|
}
|
//查询并验证工单信息
|
Workorder mp = getOrderAndValid(user,param.getId());
|
//查询全部bom组成数据,如果有BOM配置,按照BOM组成进行投料,如果没有BOM配置,则投料物料为待生产库位的物料本身
|
QueryBomDetailExtDTO bdparam = initBomParam(user,mp);
|
if(mp.getBomModel()!=null&&Constants.equalsInteger(mp.getBomModel().getType(),Constants.BOM_TYPE.pull)){
|
//如果是拉式投料,系统根据BOM自动扣减库存,不需要手动投料
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,该物料投料方式是扣减库存,无需主动投料!");
|
}
|
//带批量插入投料记录集合
|
List<WorkorderRecord> recordList = new ArrayList<>();
|
if(Constants.equalsInteger(mp.getType(),Constants.WORKORDER_TYPE.normal)){
|
//如果是正常单
|
List<BomDetailExtListVO> bomDetailList = null;
|
//如果有bom配置
|
if(bdparam!=null){
|
bomDetailList = bomDetailExtMapper.selectList(bdparam);
|
}
|
for(MaterialListDTO materialListDTO : param.getRecordList()){
|
//查询工单下 是否已存在该库存记录的使用记录
|
if(workorderRecordExtMapper.selectList(new QueryWrapper<WorkorderRecord>().eq("DELETED",Constants.ZERO)
|
.eq("WORKORDER_ID",param.getId()).eq("APPLIANCES_ID",materialListDTO.getWStockId())).size()>Constants.ZERO){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "当前库存已投料,请修改记录数据!");
|
};
|
WStock wStock = wStockExtMapper.selectById(materialListDTO.getWStockId());
|
if(materialListDTO.getNum().compareTo(BigDecimal.ZERO)>Constants.ZERO){
|
if(bdparam!=null) {
|
//如果有bom配置,按bom进行投料
|
//判断器具装载物料数量是否满足提交条件
|
isValideApplianceNum(wStock,materialListDTO.getNum(),mp,bomDetailList);
|
}else {
|
//如果没有bom配置,投生产物料本身
|
//判断器具装载物料数量是否满足提交条件
|
isValideApplianceNum(materialListDTO.getNum(),user,wStock,mp);
|
}
|
}else{
|
if(!wStock.getMaterialId().equals(mp.getMaterialId())){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,提交物料非BOM组成物料!");
|
}
|
}
|
//初始化投料记录对象
|
recordList.add(getWorkrecordModel(user,wStock,mp,materialListDTO.getNum()));
|
}
|
}else{
|
//如果是返工返修申请
|
if(mp.getBackorderId() == null){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,该工单关联返修申请信息有误,请联系管理员!");
|
}
|
for(MaterialListDTO materialListDTO : param.getRecordList()){
|
WStock wStock = wStockExtMapper.selectById(materialListDTO.getWStockId());
|
if(!wStock.getMaterialId().equals(mp.getMaterialId())){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,提交物料非BOM组成物料!");
|
}
|
recordList.add(getWorkrecordModel(user,wStock,mp,materialListDTO.getNum()));
|
}
|
}
|
|
//批量插入投料记录
|
workorderRecordExtMapper.insertBatch(recordList);
|
//单添加历史记录(判断更新为生产中)
|
updateOrderInfo(user,mp,Constants.WORKORDER_HISTORY_STATUS.material);
|
return param.getId();
|
}
|
|
private BigDecimal getNumFromParam(Integer id, List<MaterialListDTO> apList) {
|
for(MaterialListDTO l : apList){
|
if(Constants.equalsInteger(id,l.getApplianceId())){
|
return l.getNum();
|
}
|
}
|
return BigDecimal.ZERO;
|
}
|
|
|
private Workorder getOrderAndValid(LoginUserInfo user, Integer id) throws BusinessException{
|
if(id== null){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,请按要求填写和选择提交数据!");
|
}
|
Workorder mp = new Workorder();
|
mp.setDeleted(Constants.ZERO);
|
mp.setId(id);
|
mp.setRootDepartId(user.getRootDepartment().getId());
|
mp = workorderExtMapper.selectOne(mp);
|
if(mp== null){
|
throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "对不起,该记录不存在!");
|
}
|
if(Constants.equalsInteger(mp.getPaused(),Constants.ONE)){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,工单已暂停!");
|
}
|
if(!Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.create)
|
&& !Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.material)
|
&& !Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.producing)
|
&& !Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.check)
|
&& !Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.done)){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,该工单状态已流转,不能进行该操作!");
|
}
|
return mp;
|
}
|
|
private void getPlansAndValid(LoginUserInfo user, Plans mp) throws BusinessException{
|
if(mp== null){
|
throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "对不起,该记录不存在!");
|
}
|
if(Constants.equalsInteger(mp.getPaused(),Constants.ONE)){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,工单已暂停!");
|
}
|
}
|
|
private QueryBomDetailExtDTO initBomParam(LoginUserInfo user, Workorder mp) throws BusinessException{
|
QueryBomExtDTO bb = new QueryBomExtDTO();
|
bb.setDepartId(mp.getDepartId());
|
bb.setDeleted(Constants.ZERO);
|
bb.setRootDepartId(user.getRootDepartment().getId());
|
bb.setMaterialId(mp.getMaterialId());
|
bb.setProcedureId(mp.getProcedureId());
|
BomExtListVO versionBom = bomExtMapper.selectByModel( bb);
|
if(versionBom == null || StringUtils.isBlank(versionBom.getVersion()) || versionBom.getBomVersionId() == null){
|
return null;
|
// throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "对不起,该工单物料BOM信息配置有误,请联系管理员!");
|
}
|
mp.setBomModel(versionBom);
|
QueryBomDetailExtDTO bom = new QueryBomDetailExtDTO();
|
bom.setDeleted(Constants.ZERO);
|
bom.setBomId(versionBom.getBomVersionId());
|
// bom.setProcedureId(mp.getProcedureId());
|
bom.setWorkorderId(mp.getId());
|
return bom;
|
}
|
|
private QueryBomDetailExtDTO initBomParamForPlans(LoginUserInfo user, Plans plans) throws BusinessException{
|
QueryBomExtDTO bb = new QueryBomExtDTO();
|
bb.setDepartId(plans.getDepartId());
|
bb.setDeleted(Constants.ZERO);
|
bb.setRootDepartId(user.getRootDepartment().getId());
|
bb.setMaterialId(plans.getMaterialId());
|
bb.setProcedureId(plans.getProcedureId());
|
BomExtListVO versionBom = bomExtMapper.selectByModel( bb);
|
if(versionBom == null || StringUtils.isBlank(versionBom.getVersion()) || versionBom.getBomVersionId() == null){
|
return null;
|
// throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "对不起,该工单物料BOM信息配置有误,请联系管理员!");
|
}
|
plans.setBomModel(versionBom);
|
QueryBomDetailExtDTO bom = new QueryBomDetailExtDTO();
|
bom.setDeleted(Constants.ZERO);
|
bom.setBomId(versionBom.getBomVersionId());
|
// bom.setProcedureId(mp.getProcedureId());
|
bom.setPlansId(plans.getId());
|
return bom;
|
}
|
|
private void isValideApplianceNum(WStock wStock ,BigDecimal useNum,Workorder mp, List<BomDetailExtListVO> bomDetailList) throws BusinessException {
|
if(wStock.getNum().compareTo(useNum)<0){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,提交物料大于库存数量!");
|
}
|
//获取该物料的组成部分
|
BomDetailExtListVO detial =getBomMaterial(wStock.getMaterialId(),bomDetailList);
|
if(detial == null){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,提交物料非BOM组成物料!");
|
}
|
if(!Constants.equalsInteger(wStock.getLocationId(),mp.getProduceWarehouseLocationId())){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,物料信息必须来自工单待生产机台货位!");
|
}
|
}
|
|
/**
|
* 如果没有bom配置 直接投自己,只能从工单上设备关联的待生产机台货位投料
|
* @param user
|
* @param wStock
|
* @param mp
|
*/
|
private void isValideApplianceNum(BigDecimal pNum,LoginUserInfo user,WStock wStock, Workorder mp) {
|
// BarcodeParamExtListVO barCode = barcodeParamExtService.getByCodeId(user.getCompany().getId(),user.getCurComDepartment().getId(),amodel.getBrcode());
|
// String pName =barCode==null? "":barCode.getPrefix();
|
if(pNum.compareTo(BigDecimal.ZERO)==0 || pNum.compareTo(Constants.formatBigdecimal(wStock.getNum()))>0){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,提交数据不合法,投料数量大于库存数量!");
|
}
|
if(!Constants.equalsInteger(wStock.getMaterialId(),mp.getMaterialId())){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,投料选择库存记录装载物料信息不符合工单投料要求!");
|
}
|
if(!Constants.equalsInteger(wStock.getLocationId(),mp.getProduceWarehouseLocationId())){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,装载物料信息必须来自工单待生产机台货位!");
|
}
|
}
|
|
|
private BomDetailExtListVO getBomMaterial(Integer materialId, List<BomDetailExtListVO> bomDetailList) {
|
for(BomDetailExtListVO d : bomDetailList){
|
if(Constants.equalsInteger(materialId,d.getMaterialId())){
|
return d;
|
}
|
}
|
return null;
|
}
|
|
private WorkorderRecord getWorkrecordModel(LoginUserInfo user, WStock wStock, Workorder mp,BigDecimal pNum) {
|
WorkorderRecord wrModel = new WorkorderRecord();
|
wrModel.setWorkorderId(mp.getId());
|
wrModel.setDeleted(Constants.ZERO);
|
wrModel.setRootDepartId(mp.getRootDepartId());
|
wrModel.setMaterialId(wStock.getMaterialId());
|
wrModel.setDepartId(mp.getDepartId());
|
wrModel.setCreateTime(DateUtil.getCurrentDate());
|
wrModel.setCreateUser(mp.getCreateUser());
|
wrModel.setMaterialBatch(mp.getBatch());
|
wrModel.setType(Constants.WORKORDER_RECORD_TYPE.materail);
|
wrModel.setFactoryId(mp.getFactoryId());
|
wrModel.setProcedureId(wStock.getProcedureId());
|
wrModel.setBatch(wStock.getBatch());
|
wrModel.setUnitId(wStock.getUnitId());
|
wrModel.setPlanId(mp.getPlanId());
|
//目前使用工装主键存储货位主键
|
wrModel.setAppliancesId(wStock.getId());
|
wrModel.setMaterialDonetype(wStock.getQualityType());
|
wrModel.setMaterialProcedureId(wStock.getProcedureId());
|
wrModel.setNum(pNum);
|
wrModel.setRelobjType(Constants.ZERO);
|
wrModel.setRelobjId(mp.getId());
|
return wrModel;
|
}
|
|
private void updateOrderInfo(LoginUserInfo user, Workorder mp,int status) {
|
List<WorkorderHistory> whList = new ArrayList<>();
|
//工单历史数据
|
Workorder order = new Workorder();
|
order.setId(mp.getId());
|
order.setUpdateTime(DateUtil.getCurrentDate());
|
order.setUpdateUser(user.getId());
|
order.setRootDepartId(mp.getRootDepartId());
|
order.setDepartId(mp.getDepartId());
|
whList.add(WorkorderExtServiceImpl.initHistoryByModel(order,user.getId(),status));
|
if(status == Constants.WORKORDER_HISTORY_STATUS.baogong){
|
order.setStatus(Constants.WORKORDER_STATUS.baogong);
|
order.setQualifiedNum(mp.getQualifiedNum());
|
order.setUnqualifiedNum(mp.getUnqualifiedNum());
|
}else if(status ==Constants.WORKORDER_HISTORY_STATUS.readyMaterial){
|
order.setStatus(Constants.WORKORDER_STATUS.material);
|
}else if(status ==Constants.WORKORDER_HISTORY_STATUS.done){
|
order.setStatus(Constants.WORKORDER_STATUS.done);
|
}else if(status ==Constants.WORKORDER_HISTORY_STATUS.material ||status ==Constants.WORKORDER_HISTORY_STATUS.produce){
|
//投料操作
|
if(Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.create)
|
||Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.material)){
|
//如果是已创建或者已备料状态的工单,修改其状态为【生产中】
|
order.setStatus(Constants.WORKORDER_STATUS.producing);
|
}
|
}
|
workorderExtMapper.updateById(order);
|
workorderHistoryExtMapper.insertBatch(whList);
|
}
|
|
|
|
@Override
|
public List<WStockExtListForWorkorderVO> findAllForStandard(QueryWorkorderRecordExtDTO pageWrap) {
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!");
|
}
|
pageWrap.setDeleted(Constants.ZERO);
|
//只能查看当前根组织的数据
|
pageWrap.setRootDepartId(user.getRootDepartment().getId());
|
List<WStockExtListForWorkorderVO> result = workorderRecordExtMapper.choiceWorkorderRecordUseStockList(pageWrap);
|
return result;
|
}
|
|
@Transactional(rollbackFor = {BusinessException.class,Exception.class})
|
@Override
|
public Integer comfirmDone(Workorder param,Boolean needCheck){
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!");
|
}
|
if(param.getId()== null ){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,请按要求填写和选择提交数据!");
|
}
|
Workorder mp = new Workorder();
|
mp.setDeleted(Constants.ZERO);
|
mp.setId(param.getId());
|
mp.setRootDepartId(user.getRootDepartment().getId());
|
mp = workorderExtMapper.selectOne(mp);
|
if(mp== null){
|
throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "对不起,该记录不存在!");
|
}
|
/*
|
Plans plans = new Plans();
|
plans.setId(mp.getPlanId());
|
//查询计划已报工数量
|
plans = plansExtMapper.selectOne(new QueryWrapper<>(plans).select("(select sum(workorders.plan_num) from workorders where workorders.plan_id=plans.id and workorders.deleted=0 and workorders.status="+Constants.WORKORDER_STATUS.baogong+") as baogongNum").last(" limit 1"));
|
*/
|
|
param.setPlanId(mp.getPlanId());
|
if(Constants.equalsInteger(mp.getPaused(),Constants.ONE)){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,工单已暂停!");
|
}
|
//如果需要完工检才能检验
|
if(Constants.equalsInteger(mp.getNeedcheck(),Constants.ZERO)&&needCheck){
|
//只有已完工状态才能确认报工
|
if(!Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.done)){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,该工单状态已流转,不能进行该操作!");
|
}
|
}
|
// //出入库记录集合
|
// List<WOutbound> outboundList = new ArrayList<>();
|
// //出入库明细记录集合
|
List<WOutboundDetail> outboundDetailList = new ArrayList<>();
|
//待更新工装集合投料
|
List<Appliances> updateApplianceList = new ArrayList<>();
|
//待更新工装集合产出
|
List<Appliances> updateApplianceProList = new ArrayList<>();
|
//待更新库存集合
|
List<WStock> stockList = new ArrayList<>();
|
//查询投料和报工记录列表
|
List<WorkorderRecordExtListVO> allRecordList = workorderRecordExtMapper.selectAllList(getQueryRecordParam(param));
|
if(Objects.isNull(allRecordList)||allRecordList.size()==Constants.ZERO){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未查询投料和报工记录!");
|
}
|
//检查数据信息
|
// caculateCheckRecord(user, mp,allRecordList);
|
QueryBomDetailExtDTO bdparam = initBomParam(user,mp);
|
if(mp.getBomModel()!=null&&Constants.equalsInteger(mp.getBomModel().getType(),Constants.BOM_TYPE.pull)){
|
//如果是拉式投料,系统根据BOM自动扣减库存
|
dealApplianceMateialPull(mp,user,bdparam,updateApplianceList, stockList);
|
}
|
if(allRecordList!=null && allRecordList.size()>0){
|
if(mp.getBomModel()==null||Constants.equalsInteger(mp.getBomModel().getType(),Constants.BOM_TYPE.push)){
|
//如果是推式投料,走正常生产手动投料
|
dealApplianceMateial(mp,user,bdparam,allRecordList,updateApplianceList, outboundDetailList,stockList);
|
}
|
//处理产出数据
|
dealAppliancePro(mp,user,allRecordList,updateApplianceList,updateApplianceProList, outboundDetailList,stockList);
|
}
|
|
|
//如果有没bom配置,检查产出(包含检验的不良和报废品)和投料数量是否相等匹配,不一致提示错误
|
if(bdparam==null){
|
//投料数量 和 产出数量不相等
|
if(Constants.formatBigdecimal(mp.getHasMaterialNum()).intValue() != Constants.formatIntegerNum(mp.getHasProduceNum())){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,该工单投料和产出数量不一致,请确认后重试!");
|
}
|
}
|
//更新工单状态为已报工
|
updateOrderInfo(user,mp,Constants.WORKORDER_HISTORY_STATUS.baogong);
|
/*if(updateApplianceList!=null && updateApplianceList.size()>0){
|
//遍历更新工装器具信息
|
for(Appliances a : updateApplianceList){
|
appliancesExtMapper.updateById(a);
|
}
|
}*/
|
//更新工装本身状态数据,以产出报工的工装状态为主,如果既有投料 也有产出的工单,以产出的状态为主进行更新
|
// updateApplianceList(updateApplianceList,updateApplianceProList);
|
//批量插入出入库明细记录
|
if(outboundDetailList!=null && outboundDetailList.size()>0){
|
wOutboundDetailExtMapper.insertBatch(outboundDetailList);
|
}
|
if(stockList != null && stockList.size()>0){
|
for(WStock s : stockList){
|
WStock s1 = new WStock();
|
s1.setLocationId(s.getLocationId());
|
s1.setWarehouseId(s.getWarehouseId());
|
s1.setDeleted(Constants.ZERO);
|
s1.setMaterialId(s.getMaterialId());
|
s1.setQualityType(s.getQualityType());
|
s1.setProcedureId(s.getProcedureId());
|
if(StringUtils.isBlank(s.getBatch() )){
|
s1 = wStockExtMapper.selectOne(new QueryWrapper<>(s1).isNull("batch").last(" limit 1"));
|
}else{
|
s1.setBatch(s.getBatch());
|
s1 = wStockExtMapper.selectOne(new QueryWrapper<>(s1).last(" limit 1"));
|
}
|
if(s1 ==null){
|
//如果库存记录不存在,插入数据
|
s.setDeleted(Constants.ZERO);
|
s.setCreateTime(DateUtil.getCurrentDate());
|
s.setCreateUser(user.getId());
|
s.setRootDepartId(mp.getRootDepartId());
|
if(Constants.formatBigdecimal(s.getNum()).compareTo(new BigDecimal(0)) == -1){
|
//如果库存不足
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,仓库余料不足,请联系仓库管理员!");
|
}
|
wStockExtMapper.insert(s);
|
}else{
|
//如果库存记录存在,则更新库存量
|
s.setId(s1.getId());
|
s.setUpdateTime(DateUtil.getCurrentDate());
|
s.setUpdateUser(user.getId());
|
s.setNum(Constants.formatBigdecimal(s1.getNum()).add(Constants.formatBigdecimal(s.getNum())));
|
if(Constants.formatBigdecimal(s.getNum()).compareTo(new BigDecimal(0)) == -1){
|
//如果库存不足
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,仓库余料不足,请联系仓库管理员!!");
|
}
|
wStockExtMapper.updateById(s);
|
}
|
|
}
|
}
|
// if(1==1){
|
// throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起!");
|
// }
|
return param.getId();
|
}
|
|
|
@Transactional(rollbackFor = {BusinessException.class,Exception.class})
|
@Override
|
public Workorder comfirmDoneNew(AutoWorkReportDTO autoWorkReportDTO, Boolean needCheck){
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!");
|
}
|
if(Objects.isNull(autoWorkReportDTO)
|
|| Objects.isNull(autoWorkReportDTO.getCreateWorkorderRecordDTO())
|
|| Objects.isNull(autoWorkReportDTO.getCreateWorkorderRecordDTO().getUnQualifiedNum())|| autoWorkReportDTO.getCreateWorkorderRecordDTO().getUnQualifiedNum().compareTo(BigDecimal.ZERO) < Constants.ZERO
|
|| Objects.isNull(autoWorkReportDTO.getCreateWorkorderRecordDTO().getQualifiedNum())|| autoWorkReportDTO.getCreateWorkorderRecordDTO().getQualifiedNum().compareTo(BigDecimal.ZERO) < Constants.ZERO){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST);
|
}
|
if(autoWorkReportDTO.getCreateWorkorderRecordDTO().getWorkorderId()== null ){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,请按要求填写和选择提交数据!");
|
}
|
Workorder mp = new Workorder();
|
mp.setDeleted(Constants.ZERO);
|
mp.setId(autoWorkReportDTO.getCreateWorkorderRecordDTO().getWorkorderId());
|
mp.setRootDepartId(user.getRootDepartment().getId());
|
mp = workorderExtMapper.selectOne(mp);
|
if(mp== null){
|
throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "对不起,该记录不存在!");
|
}
|
Plans plans = plansExtMapper.selectById(mp.getPlanId());
|
if(Objects.isNull(plans)){
|
throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "对不起,工序计划记录不存在!");
|
}
|
//查询工序计划下 所有工单已报工数量
|
QueryWorkorderExtDTO dto = new QueryWorkorderExtDTO();
|
dto.setPlanId(mp.getPlanId());
|
dto.setDeleted(Constants.ZERO);
|
dto.setStatus(Constants.WORKORDER_STATUS.baogong);
|
List<WorkorderExtListVO> workorderList = workorderExtMapper.selectList(dto);
|
Integer plansQualifiedNum = 0 , plansUnQualifiedNum = 0;
|
plansQualifiedNum = workorderList.stream().map( workorderExtListVO -> workorderExtListVO.getQualifiedNum()).reduce(Constants.ZERO, Integer::sum);
|
plansUnQualifiedNum = workorderList.stream().map( workorderExtListVO -> workorderExtListVO.getUnqualifiedNum()).reduce(Constants.ZERO, Integer::sum);
|
if((BigDecimal.valueOf(plansQualifiedNum).add(BigDecimal.valueOf(plansUnQualifiedNum).add(autoWorkReportDTO.getCreateWorkorderRecordDTO().getUnQualifiedNum())
|
.add(autoWorkReportDTO.getCreateWorkorderRecordDTO().getQualifiedNum()))).compareTo(BigDecimal.valueOf(plans.getNum()))>Constants.ZERO){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,报工数量超出工序计划总数!");
|
}
|
Workorder param = new Workorder();
|
|
param.setPlanId(mp.getPlanId());
|
param.setId(autoWorkReportDTO.getCreateWorkorderRecordDTO().getWorkorderId());
|
if(Constants.equalsInteger(mp.getPaused(),Constants.ONE)){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,工单已暂停!");
|
}
|
//如果需要完工检才能检验
|
if(Constants.equalsInteger(mp.getNeedcheck(),Constants.ZERO)&&needCheck){
|
//只有已完工状态才能确认报工
|
if(!Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.done)){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,该工单状态已流转,不能进行该操作!");
|
}
|
}
|
//出入库明细记录集合
|
List<WOutboundDetail> outboundDetailList = new ArrayList<>();
|
//待更新工装集合投料
|
List<Appliances> updateApplianceList = new ArrayList<>();
|
//待更新工装集合产出
|
List<Appliances> updateApplianceProList = new ArrayList<>();
|
//待更新库存集合
|
List<WStock> stockList = new ArrayList<>();
|
//处理产出数据
|
WorkorderRecord workorderRecord = this.createWorkorderRecord(autoWorkReportDTO.getCreateWorkorderRecordDTO(),user,null);
|
//查询投料和报工记录列表
|
List<WorkorderRecordExtListVO> allRecordList = workorderRecordExtMapper.selectAllList(getQueryRecordParam(param));
|
if(Objects.isNull(allRecordList)||allRecordList.size()==Constants.ZERO){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未查询投料和报工记录!");
|
}
|
//检查数据信息
|
// caculateCheckRecord(user, mp,allRecordList);
|
QueryBomDetailExtDTO bdparam = initBomParam(user,mp);
|
if(mp.getBomModel()!=null&&Constants.equalsInteger(mp.getBomModel().getType(),Constants.BOM_TYPE.pull)){
|
//如果是拉式投料,系统根据BOM自动扣减库存
|
dealApplianceMateialPull(mp,user,bdparam,updateApplianceList, stockList);
|
}
|
if(allRecordList!=null && allRecordList.size()>0){
|
if(mp.getBomModel()==null||Constants.equalsInteger(mp.getBomModel().getType(),Constants.BOM_TYPE.push)){
|
//如果是推式投料,走正常生产手动投料
|
dealApplianceMateial(mp,user,bdparam,allRecordList,updateApplianceList, outboundDetailList,stockList);
|
}
|
//处理产出数据
|
dealAppliancePro(mp,user,allRecordList,updateApplianceList,updateApplianceProList, outboundDetailList,stockList);
|
}
|
|
//如果有没bom配置,检查产出(包含检验的不良和报废品)和投料数量是否相等匹配,不一致提示错误
|
if(bdparam==null){
|
//投料数量 和 产出数量不相等
|
if(Constants.formatBigdecimal(mp.getHasMaterialNum()).intValue() != Constants.formatIntegerNum(mp.getHasProduceNum())){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,该工单投料和产出数量不一致,请确认后重试!");
|
}
|
}
|
//更新工单状态为已报工
|
mp.setUnqualifiedNum(autoWorkReportDTO.getCreateWorkorderRecordDTO().getUnQualifiedNum().intValue());
|
mp.setQualifiedNum(autoWorkReportDTO.getCreateWorkorderRecordDTO().getQualifiedNum().intValue());
|
updateOrderInfo(user,mp,Constants.WORKORDER_HISTORY_STATUS.baogong);
|
|
//批量插入出入库明细记录
|
if(outboundDetailList!=null && outboundDetailList.size()>0){
|
wOutboundDetailExtMapper.insertBatch(outboundDetailList);
|
}
|
if(stockList != null && stockList.size()>0){
|
for(WStock s : stockList){
|
WStock s1 = new WStock();
|
s1.setLocationId(s.getLocationId());
|
s1.setWarehouseId(s.getWarehouseId());
|
s1.setDeleted(Constants.ZERO);
|
s1.setMaterialId(s.getMaterialId());
|
s1.setQualityType(s.getQualityType());
|
s1.setProcedureId(s.getProcedureId());
|
if(StringUtils.isBlank(s.getBatch() )){
|
s1 = wStockExtMapper.selectOne(new QueryWrapper<>(s1).isNull("batch").last(" limit 1"));
|
}else{
|
s1.setBatch(s.getBatch());
|
s1 = wStockExtMapper.selectOne(new QueryWrapper<>(s1).last(" limit 1"));
|
}
|
if(s1 ==null){
|
//如果库存记录不存在,插入数据
|
s.setDeleted(Constants.ZERO);
|
s.setCreateTime(DateUtil.getCurrentDate());
|
s.setCreateUser(user.getId());
|
s.setRootDepartId(mp.getRootDepartId());
|
if(Constants.formatBigdecimal(s.getNum()).compareTo(new BigDecimal(0)) == -1){
|
//如果库存不足
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,仓库余料不足,请联系仓库管理员!");
|
}
|
wStockExtMapper.insert(s);
|
}else{
|
//如果库存记录存在,则更新库存量
|
s.setId(s1.getId());
|
s.setUpdateTime(DateUtil.getCurrentDate());
|
s.setUpdateUser(user.getId());
|
s.setNum(Constants.formatBigdecimal(s1.getNum()).add(Constants.formatBigdecimal(s.getNum())));
|
if(Constants.formatBigdecimal(s.getNum()).compareTo(new BigDecimal(0)) == -1){
|
//如果库存不足
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,仓库余料不足,请联系仓库管理员!!");
|
}
|
wStockExtMapper.updateById(s);
|
}
|
|
}
|
}
|
|
//存储报工不良项数据
|
if(autoWorkReportDTO.getCreateWorkorderRecordDTO().getUnQualifiedNum().compareTo(BigDecimal.ZERO)<=Constants.ZERO){
|
if(!Objects.isNull(autoWorkReportDTO.getCreateUnqualifiedDTOList())&&autoWorkReportDTO.getCreateUnqualifiedDTOList().size()>Constants.ZERO){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"不良项错误:请检查不良项数据");
|
}
|
}else{
|
List<CreateUnqualifiedDTO> createUnqualifiedDTOList = autoWorkReportDTO.getCreateUnqualifiedDTOList();
|
BigDecimal unqualified = createUnqualifiedDTOList.stream().map(s -> s.getUnQualifiedNum()).reduce(BigDecimal.ZERO, BigDecimal::add);
|
if(unqualified.compareTo(autoWorkReportDTO.getCreateWorkorderRecordDTO().getUnQualifiedNum())!=Constants.ZERO){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"不良项错误:请检查不良项数据");
|
}
|
for (CreateUnqualifiedDTO createUnqualifiedDTO:createUnqualifiedDTOList) {
|
if(createUnqualifiedDTO.getUnQualifiedNum().compareTo(BigDecimal.ZERO)==Constants.ZERO
|
||Objects.isNull(createUnqualifiedDTO.getCategoryId())){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"不良项错误:请检查不良项数据");
|
}
|
UnqualifiedRecord unqualifiedRecord = new UnqualifiedRecord();
|
unqualifiedRecord.setDeleted(Constants.ZERO);
|
unqualifiedRecord.setCreateUser(user.getId());
|
unqualifiedRecord.setCreateTime(new Date());
|
unqualifiedRecord.setRootDepartId(mp.getRootDepartId());
|
unqualifiedRecord.setDepartId(mp.getDepartId());
|
unqualifiedRecord.setWorkorderId(mp.getId());
|
unqualifiedRecord.setRecordId(workorderRecord.getId());
|
unqualifiedRecord.setCategoryId(createUnqualifiedDTO.getCategoryId());
|
unqualifiedRecord.setUnqualifiedNum(createUnqualifiedDTO.getUnQualifiedNum());
|
unqualifiedRecordMapper.insert(unqualifiedRecord);
|
}
|
}
|
|
return param;
|
}
|
|
|
|
private QueryWorkorderRecordExtDTO getQueryRecordParam(Workorder param) {
|
QueryWorkorderRecordExtDTO mParam = new QueryWorkorderRecordExtDTO();
|
mParam.setWorkorderId(param.getId());
|
mParam.setDeleted(Constants.ZERO);
|
return mParam;
|
}
|
|
|
|
private void dealApplianceMateialPull(Workorder mp
|
, LoginUserInfo user
|
,QueryBomDetailExtDTO bdparam
|
, List<Appliances> updateApplianceList
|
,List<WStock> stockList) {
|
//记录需要投料的物料和数量
|
List<Integer> tempIds = new ArrayList<>();
|
List<WStock> materialList = new ArrayList<>();
|
//如果有bom配置,查询全部bom组成,进行库存投料
|
if(bdparam!=null){
|
List<BomDetailExtListVO> bomDetailList = bomDetailExtMapper.selectList(bdparam);
|
if(bomDetailList == null || bomDetailList.size()==0){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,该生产物料的bom配置有误,请联系管理员!");
|
}
|
for(BomDetailExtListVO d : bomDetailList){
|
//安装物料组成 乘以 生产量,拉式扣减的BOM每行物料数量=产出产品数量×BOM每行物料使用数量;
|
BigDecimal num = Constants.formatBigdecimal(d.getNum()).multiply(new BigDecimal(Constants.formatIntegerNum(mp.getPlanNum())));
|
materialList.add(initMaterialNum(d.getMaterialId(),num));
|
tempIds.add(Constants.formatIntegerNum( d.getMaterialId()));
|
}
|
}else{
|
//投料为自己,1:1投生产物料
|
materialList.add(initMaterialNum(mp.getMaterialId(),new BigDecimal(Constants.formatIntegerNum(mp.getPlanNum()))));
|
tempIds.add(Constants.formatIntegerNum( mp.getMaterialId()));
|
}
|
//根据物料、质量属性(合格)去库存余额,并进行扣减,如果有多条库存余量则按创建时间顺序(正序)扣减;单条余额不够,支持扣多条余额数据;如果存在多仓库扣减,则产生多个出库单;
|
WStock sparam = new WStock();
|
sparam.setDeleted(Constants.ZERO);
|
sparam.setQualityType(Constants.QUALITIY_TYPE.normal);
|
sparam.setRootDepartId(mp.getRootDepartId());
|
//限制只从工单关联设备配置的待生产货位进行投料扣除
|
sparam.setWarehouseId(mp.getProduceWarehouseId());
|
sparam.setLocationId(mp.getProduceWarehouseLocationId());
|
//查询所有合格的符合物料需要的库存记录,按创建时间正序,库存量>0。
|
List<WStock> allList = wStockExtMapper.selectList(new QueryWrapper<>(sparam)
|
.isNull(mp.getProduceWarehouseLocationId()== null,"LOCATION_ID" )
|
.in("MATERIAL_ID",tempIds).gt("NUM",new BigDecimal(0)).orderByAsc("CREATE_TIME"));
|
if(allList!=null && allList.size()>0){
|
List<WOutbound> outboundList = new ArrayList<>();
|
//如果需要投料的物料集合,在库存中寻找投料来源
|
for(WStock model : materialList){
|
List<WStock> useList = allList.stream().filter(wStock -> Constants.equalsInteger(model.getMaterialId(),wStock.getMaterialId())).collect(Collectors.toList());
|
BigDecimal wStockNum = useList.stream().map(s -> s.getNum()).reduce(BigDecimal.ZERO, BigDecimal::add);
|
if(wStockNum.compareTo(Constants.formatBigdecimal(model.getNum()))<Constants.ZERO){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,生产物料不足,无法进行该操作!");
|
}
|
for(WStock ts : allList){
|
if(Constants.equalsInteger(model.getMaterialId(),ts.getMaterialId())){
|
//还需要投料数量
|
BigDecimal actNum = Constants.formatBigdecimal(model.getNum()).subtract(Constants.formatBigdecimal(model.getTNum()));
|
if(actNum.compareTo(new BigDecimal(0))==0){
|
//如果已经投料完全,直接跳出
|
break;
|
}
|
boolean isfull =false;
|
if(actNum.compareTo(Constants.formatBigdecimal(ts.getNum())) ==1 ){
|
//如果当前库存不能满足剩余需求量,有多少投多少
|
actNum = Constants.formatBigdecimal(ts.getNum());
|
}else{
|
//如果已经满足剩余需求量
|
isfull =true;
|
}
|
|
//添加投料记录
|
workorderRecordExtMapper.insert(getWorkrecordModel(user,ts,mp,actNum));
|
|
//更新已经投料数量
|
model.setTNum(Constants.formatBigdecimal(model.getTNum()).add(actNum));
|
WOutbound outbound = getFromOutboundList(ts.getWarehouseId(),outboundList);
|
if(outbound==null){
|
outbound = new WOutbound();
|
outbound.setDeleted(Constants.ZERO);
|
outbound.setCreateTime(DateUtil.getCurrentDate());
|
outbound.setDealDate(outbound.getCreateTime());
|
outbound.setValidDate(outbound.getCreateTime());
|
outbound.setCreateUser(user.getId());
|
outbound.setRootDepartId(mp.getRootDepartId());
|
outbound.setDepartId(mp.getDepartId());
|
outbound.setStatus(Constants.WOUTBOUND_STATUS.dealed);
|
outbound.setType(Constants.WOUTBOUND_TYPE.out);
|
//2022年7月1日14:42:41 加入单据类别
|
outbound.setBillType(Constants.WOUTBOUND_BILLTYPE.workerOrderOut);
|
outbound.setCode(wOutboundService.getNextOutCode(user.getCompany().getId()));
|
outbound.setOrigin(Constants.ONE);
|
outbound.setOriginType(Constants.WOUTBOUND_ORIGIN_TYPE.produce);
|
outbound.setOriginCode(mp.getCode());
|
outbound.setOriginId(mp.getId());
|
outbound.setPlanDate(DateUtil.getCurrentDate());
|
outbound.setUserId(user.getId());
|
outbound.setWarehouseId(ts.getWarehouseId());
|
wOutboundService.create(outbound);
|
outboundList.add(outbound);
|
}
|
|
WOutboundDetail detail = new WOutboundDetail();
|
detail.setDeleted(Constants.ZERO);
|
detail.setCreateTime(DateUtil.getCurrentDate());
|
detail.setCreateUser(user.getId());
|
detail.setRootDepartId(mp.getRootDepartId());
|
detail.setOutboundId(outbound.getId());
|
detail.setBatch(ts.getBatch());
|
detail.setWarehouseId(outbound.getWarehouseId());
|
detail.setLocationId(ts.getLocationId());
|
detail.setMaterialId(ts.getMaterialId());
|
detail.setNum(actNum);
|
detail.setDoneDate(new Date());
|
detail.setDoneNum(actNum);
|
detail.setStatus(Constants.ONE);
|
detail.setUnitId(ts.getUnitId());
|
detail.setProcedureId(ts.getProcedureId());
|
detail.setQualityType(ts.getQualityType());
|
wOutboundDetailExtMapper.insert(detail);
|
|
//记录库存变动记录
|
wStockRecordExtService.saveRecord(Constants.ZERO,detail.getId(),user);
|
|
WStock s = new WStock();
|
s.setId(ts.getId());
|
s.setUpdateTime(DateUtil.getCurrentDate());
|
s.setUpdateUser(user.getId());
|
s.setNum(Constants.formatBigdecimal(ts.getNum()).subtract(Constants.formatBigdecimal(actNum)));
|
if(Constants.formatBigdecimal(s.getNum()).compareTo(new BigDecimal(0)) == -1){
|
//如果库存不足
|
s.setNum(new BigDecimal(0));
|
}
|
wStockExtMapper.updateById(s);
|
|
/*WStock stock = getFromStockList(ts.getLocationId(),ts.getWarehouseId(),ts.getMaterialId(),ts.getBatch(),ts.getProcedureId(),ts.getQualityType(),stockList);
|
if(stock!=null){
|
//如果库存对象已存在,直接减少对应的库存量
|
stock.setNum(Constants.formatBigdecimal(stock.getNum()).subtract(actNum));
|
}else{
|
stock = new WStock();
|
stock.setMaterialId(ts.getMaterialId());
|
stock.setLocationId(ts.getLocationId());
|
stock.setNum(actNum.multiply(new BigDecimal(-1)));
|
stock.setWarehouseId(ts.getWarehouseId());
|
stock.setUnitId(ts.getUnitId());
|
stock.setBatch(ts.getBatch());
|
stock.setProcedureId(ts.getProcedureId());
|
stock.setQualityType(ts.getQualityType());
|
//待更新库存信息
|
stockList.add(stock);
|
}*/
|
if(isfull){
|
//如果已经满足剩余需求量,终止当前需求物料的库存查询
|
break;
|
}
|
}
|
}
|
}
|
}else{
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"生产所需物料库存不足,无法报工");
|
}
|
}
|
|
|
private void dealApplianceMateial(Workorder mp
|
, LoginUserInfo user
|
,QueryBomDetailExtDTO bdparam
|
, List<WorkorderRecordExtListVO> allRecordList
|
, List<Appliances> updateApplianceList
|
, List<WOutboundDetail> outboundDetailList
|
,List<WStock> stockList) {
|
|
if(bdparam!=null) {
|
List<BomDetailExtListVO> bomDetailList = bomDetailExtMapper.selectList(bdparam);
|
if (bomDetailList == null || bomDetailList.size() == 0) {
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,该生产物料的bom配置有误,请联系管理员!");
|
}
|
for (BomDetailExtListVO i :bomDetailList) {
|
//查询是否投料
|
if(workorderRecordExtMapper.selectCount(new QueryWrapper<WorkorderRecord>()
|
.eq("WORKORDER_ID",mp.getId())
|
.eq("DELETED",Constants.ZERO).eq("MATERIAL_ID",i.getMaterialId()).eq("TYPE",Constants.ZERO))<=0){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"存在未投料BOM物料,无法进行报工");
|
}
|
}
|
}
|
|
WOutbound outbound = new WOutbound();
|
outbound.setDeleted(Constants.ZERO);
|
outbound.setCreateTime(DateUtil.getCurrentDate());
|
outbound.setDealDate(outbound.getCreateTime());
|
outbound.setValidDate(outbound.getCreateTime());
|
outbound.setCreateUser(user.getId());
|
outbound.setRootDepartId(mp.getRootDepartId());
|
outbound.setDepartId(mp.getDepartId());
|
outbound.setStatus(Constants.WOUTBOUND_STATUS.dealed);
|
outbound.setType(Constants.WOUTBOUND_TYPE.out);
|
//2022年7月1日14:42:41 加入单据类别
|
outbound.setBillType(Constants.WOUTBOUND_BILLTYPE.workerOrderOut);
|
outbound.setCode(wOutboundService.getNextOutCode(user.getCompany().getId()));
|
outbound.setOrigin(Constants.ONE);
|
outbound.setOriginType(Constants.WOUTBOUND_ORIGIN_TYPE.produce);
|
outbound.setOriginId(mp.getId());
|
outbound.setOriginCode(mp.getCode());
|
outbound.setPlanDate(DateUtil.getCurrentDate());
|
outbound.setProcedureId(mp.getProcedureId());
|
outbound.setUserId(user.getId());
|
outbound.setWarehouseId(mp.getProduceWarehouseId());
|
wOutboundService.create(outbound);
|
List<WOutboundDetail> detailList = new ArrayList<>();
|
for(WorkorderRecordExtListVO tModel :allRecordList){
|
if(Constants.equalsInteger(tModel.getType(),Constants.WORKORDER_RECORD_TYPE.materail)){
|
//如果是投料
|
mp.setHasMaterialNum(Constants.formatBigdecimal(tModel.getNum()).add(Constants.formatBigdecimal(mp.getHasMaterialNum())));
|
WStock stock = wStockExtMapper.selectById(tModel.getAppliancesId());
|
if(Objects.isNull(stock)){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,投料选择库存记录不存在!");
|
}
|
|
if(!Constants.equalsInteger(stock.getLocationId(),mp.getProduceWarehouseLocationId())){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,投料记录物料信息必须来自工单待生产机台货位!");
|
}
|
if(stock.getNum().compareTo(tModel.getNum())<Constants.ZERO){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,投料物料在对应货物库存不足!");
|
}
|
|
//物料+批次+工序+质量属性去重
|
WOutboundDetail detail =getWoutbondDetailByList(tModel,detailList);
|
if(detail!=null){
|
detail.setNum(Constants.formatBigdecimal(detail.getNum()).add(tModel.getNum()));
|
}else{
|
detail = new WOutboundDetail();
|
detail.setDeleted(Constants.ZERO);
|
detail.setCreateTime(DateUtil.getCurrentDate());
|
detail.setCreateUser(user.getId());
|
detail.setRootDepartId(mp.getRootDepartId());
|
detail.setOutboundId(outbound.getId());
|
detail.setWarehouseId(outbound.getWarehouseId());
|
detail.setLocationId(mp.getProduceWarehouseLocationId());
|
detail.setNum(tModel.getNum());
|
detail.setDoneDate(new Date());
|
detail.setDoneNum(tModel.getNum());
|
detail.setStatus(Constants.ONE);
|
detail.setUnitId(tModel.getUnitId());
|
detail.setMaterialId(tModel.getMaterialId());
|
detail.setBatch(tModel.getMaterialBatch());
|
detail.setProcedureId(tModel.getMaterialProcedureId());
|
detail.setQualityType(tModel.getMaterialDonetype());
|
detail.setWOutboundRecordInList(new ArrayList<>());
|
detailList.add(detail);
|
}
|
|
WOutboundRecord record = new WOutboundRecord();
|
record.setDeleted(Constants.ZERO);
|
record.setCreateTime(DateUtil.getCurrentDate());
|
record.setCreateUser(user.getId());
|
record.setAppliancesId(tModel.getAppliancesId());
|
record.setBatch(detail.getBatch());
|
record.setDetailId(detail.getId());
|
record.setRootDepartId(mp.getRootDepartId());
|
record.setNum(tModel.getNum());
|
record.setOutboundId(detail.getOutboundId());
|
record.setUnitId(detail.getUnitId());
|
record.setWarehouseId(detail.getWarehouseId());
|
record.setMaterialId(detail.getMaterialId());
|
record.setProcedureId(detail.getProcedureId());
|
record.setQualityType(detail.getQualityType());
|
record.setLocationId(detail.getLocationId());
|
detail.getWOutboundRecordInList().add(record);
|
// wOutboundRecordExtMapper.insert(record);
|
if(stock!=null){
|
//如果库存对象已存在,直接减少对应的库存量
|
WStockRecord wStockRecord = new WStockRecord();
|
BeanUtils.copyProperties(stock,wStockRecord);
|
wStockRecord.setBeforNum(stock.getNum());
|
stock.setNum(Constants.formatBigdecimal(stock.getNum()).subtract(Constants.formatBigdecimal(tModel.getNum())));
|
wStockRecord.setNum(tModel.getNum());
|
wStockRecord.setAfterNum(stock.getNum());
|
wStockRecord.setWStockId(stock.getId());
|
wStockExtMapper.updateById(stock);
|
wStockRecordExtService.insertWStockRecord(wStockRecord);
|
}else{
|
stock = new WStock();
|
stock.setMaterialId(detail.getMaterialId());
|
stock.setLocationId(mp.getProduceWarehouseLocationId());
|
stock.setNum(Constants.formatBigdecimal(tModel.getNum()).multiply(new BigDecimal(-1)));
|
stock.setWarehouseId(outbound.getWarehouseId());
|
stock.setUnitId(detail.getUnitId());
|
stock.setBatch(detail.getBatch());
|
stock.setProcedureId(tModel.getAmodel().getProcedureId());
|
stock.setQualityType(tModel.getAmodel().getQualityType());
|
//待更新库存信息
|
stockList.add(stock);
|
}
|
}
|
}
|
for(WOutboundDetail detail : detailList){
|
wOutboundDetailExtMapper.insert(detail);
|
}
|
}
|
|
|
|
// private void dealAppliancePro(Workorder mp
|
// , LoginUserInfo user
|
// , List<WorkorderRecordExtListVO> allRecordList
|
// , List<Appliances> updateApplianceList
|
// , List<Appliances> updateApplianceProList
|
// , List<WOutboundDetail> outboundDetailList
|
// , List<WStock> stockList) {
|
// WOutbound outbound = new WOutbound();
|
// outbound.setDeleted(Constants.ZERO);
|
// outbound.setCreateTime(DateUtil.getCurrentDate());
|
// outbound.setDealDate(outbound.getCreateTime());
|
// outbound.setValidDate(outbound.getCreateTime());
|
// outbound.setCreateUser(user.getId());
|
// outbound.setRootDepartId(mp.getRootDepartId());
|
// outbound.setDepartId(mp.getDepartId());
|
// outbound.setStatus(Constants.WOUTBOUND_STATUS.dealed);
|
// outbound.setType(Constants.WOUTBOUND_TYPE.in);
|
// //2022年7月1日14:42:41 加入单据类别
|
// outbound.setBillType(Constants.WOUTBOUND_BILLTYPE.workerOrderIn);
|
// outbound.setCode(wOutboundService.getNextInCode(user.getCompany().getId()));
|
// outbound.setOrigin(Constants.ONE);
|
// outbound.setOriginType(Constants.WOUTBOUND_ORIGIN_TYPE.produce);
|
// outbound.setOriginCode(mp.getCode());
|
// outbound.setOriginId(mp.getId());
|
// outbound.setPlanDate(DateUtil.getCurrentDate());
|
// outbound.setProcedureId(mp.getProcedureId());
|
// outbound.setUserId(user.getId());
|
// outbound.setWarehouseId(mp.getFinishWarehouseId());
|
// wOutboundService.create(outbound);
|
//
|
// List<WOutboundDetail> detailList = new ArrayList<>();
|
// List<WOutboundRecord> recordList = new ArrayList<>();
|
// for(WorkorderRecordExtListVO tModel :allRecordList){
|
// if(Constants.equalsInteger(tModel.getType(),Constants.WORKORDER_RECORD_TYPE.produce)){
|
// if(tModel.getNum().compareTo(BigDecimal.ZERO)<=Constants.ZERO){
|
// continue;
|
// }
|
// //如果是产出
|
// mp.setHasProduceNum(Constants.formatBigdecimal(tModel.getNum()).intValue()+Constants.formatIntegerNum(mp.getHasProduceNum()));
|
//
|
// //物料+批次+工序+质量属性去重
|
// WOutboundDetail detail =getWoutbondDetailByList(tModel,detailList);
|
// if(detail!=null){
|
// detail.setNum(Constants.formatBigdecimal(detail.getNum()).add(tModel.getNum()));
|
// }else{
|
// detail = new WOutboundDetail();
|
// detail.setDeleted(Constants.ZERO);
|
// detail.setCreateTime(DateUtil.getCurrentDate());
|
// detail.setCreateUser(user.getId());
|
// detail.setOutboundId(outbound.getId());
|
// detail.setRootDepartId(outbound.getRootDepartId());
|
// detail.setWarehouseId(outbound.getWarehouseId());
|
// detail.setLocationId(mp.getFinishWarehouseLocationId());
|
// detail.setNum(tModel.getNum());
|
// detail.setStatus(Constants.ONE);
|
// detail.setDoneNum(tModel.getNum());
|
// detail.setDoneDate(new Date());
|
// detail.setUnitId(tModel.getUnitId());
|
// detail.setBatch(tModel.getMaterialBatch());
|
// detail.setProcedureId(tModel.getProcedureId());
|
// detail.setMaterialId(tModel.getMaterialId());
|
// detail.setQualityType(tModel.getDoneType());
|
// detail.setWOutboundRecordInList(new ArrayList<>());
|
// detailList.add(detail);
|
// }
|
//
|
// WOutboundRecord record = new WOutboundRecord();
|
// record.setDeleted(Constants.ZERO);
|
// record.setCreateTime(DateUtil.getCurrentDate());
|
// record.setCreateUser(user.getId());
|
// record.setAppliancesId(tModel.getAppliancesId());
|
// record.setBatch(detail.getBatch());
|
// record.setRootDepartId(mp.getRootDepartId());
|
// record.setNum(tModel.getNum());
|
// record.setOutboundId(detail.getOutboundId());
|
// record.setUnitId(detail.getUnitId());
|
// record.setWarehouseId(detail.getWarehouseId());
|
// record.setMaterialId(detail.getMaterialId());
|
// record.setProcedureId(detail.getProcedureId());
|
// record.setLocationId(detail.getLocationId());
|
// record.setQualityType(detail.getQualityType());
|
// detail.getWOutboundRecordInList().add(record);
|
//
|
// WStock stock = getFromStockList(mp.getFinishWarehouseLocationId(),detail.getWarehouseId(),detail.getMaterialId(),detail.getBatch(),
|
// tModel.getProcedureId(),tModel.getDoneType(),stockList);
|
// if(stock!=null){
|
// //如果库存对象已存在,直接增加对应的库存量
|
// stock.setNum(Constants.formatBigdecimal(stock.getNum()).add(Constants.formatBigdecimal(tModel.getNum())));
|
// }else{
|
// stock = new WStock();
|
// stock.setMaterialId(detail.getMaterialId());
|
// stock.setBatch(detail.getBatch());
|
// stock.setWarehouseId(outbound.getWarehouseId());
|
// stock.setLocationId(mp.getFinishWarehouseLocationId());
|
// stock.setUnitId(detail.getUnitId());
|
// stock.setNum(Constants.formatBigdecimal(tModel.getNum()));
|
// stock.setProcedureId(tModel.getProcedureId());
|
// stock.setQualityType(tModel.getDoneType());
|
// //待更新库存信息
|
// stockList.add(stock);
|
// }
|
// }
|
// }
|
// for(WOutboundDetail detail : detailList){
|
// wOutboundDetailExtMapper.insert(detail);
|
// //记录库存变动记录
|
// wStockRecordExtService.saveRecord(Constants.ONE,detail.getId(),user);
|
// if(detail.getWOutboundRecordInList()!=null){
|
// for(WOutboundRecord r : detail.getWOutboundRecordInList()){
|
// r.setDetailId(detail.getId());
|
// wOutboundRecordExtMapper.insert(r);
|
// }
|
// }
|
// }
|
// if(Constants.formatIntegerNum(mp.getHasProduceNum()) >Constants.formatIntegerNum(mp.getPlanNum())){
|
// throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,该工单的产出数量不能大于工单计划数量!");
|
// }
|
// }
|
|
|
private void dealAppliancePro(Workorder mp
|
, LoginUserInfo user
|
, List<WorkorderRecordExtListVO> allRecordList
|
, List<Appliances> updateApplianceList
|
, List<Appliances> updateApplianceProList
|
, List<WOutboundDetail> outboundDetailList
|
, List<WStock> stockList) {
|
WOutbound outbound = new WOutbound();
|
outbound.setDeleted(Constants.ZERO);
|
outbound.setCreateTime(DateUtil.getCurrentDate());
|
outbound.setDealDate(outbound.getCreateTime());
|
outbound.setValidDate(outbound.getCreateTime());
|
outbound.setCreateUser(user.getId());
|
outbound.setRootDepartId(mp.getRootDepartId());
|
outbound.setDepartId(mp.getDepartId());
|
outbound.setStatus(Constants.WOUTBOUND_STATUS.dealed);
|
outbound.setType(Constants.WOUTBOUND_TYPE.in);
|
//2022年7月1日14:42:41 加入单据类别
|
outbound.setBillType(Constants.WOUTBOUND_BILLTYPE.workerOrderIn);
|
outbound.setCode(wOutboundService.getNextInCode(user.getCompany().getId()));
|
outbound.setOrigin(Constants.ONE);
|
outbound.setOriginType(Constants.WOUTBOUND_ORIGIN_TYPE.produce);
|
outbound.setOriginCode(mp.getCode());
|
outbound.setOriginId(mp.getId());
|
outbound.setPlanDate(DateUtil.getCurrentDate());
|
outbound.setProcedureId(mp.getProcedureId());
|
outbound.setUserId(user.getId());
|
outbound.setWarehouseId(mp.getFinishWarehouseId());
|
wOutboundService.create(outbound);
|
|
List<WOutboundDetail> detailList = new ArrayList<>();
|
List<WOutboundRecord> recordList = new ArrayList<>();
|
for(WorkorderRecordExtListVO tModel :allRecordList){
|
if(Constants.equalsInteger(tModel.getType(),Constants.WORKORDER_RECORD_TYPE.produce)){
|
if(tModel.getNum().compareTo(BigDecimal.ZERO)<=Constants.ZERO){
|
continue;
|
}
|
//如果是产出
|
mp.setHasProduceNum(Constants.formatBigdecimal(tModel.getNum()).intValue()+Constants.formatIntegerNum(mp.getHasProduceNum()));
|
//产出合格
|
this.createOutDetail(user,outbound,mp,tModel,Constants.ZERO,detailList,stockList);
|
//产出不良
|
this.createOutDetail(user,outbound,mp,tModel,Constants.ONE,detailList,stockList);
|
}
|
}
|
for(WOutboundDetail detail : detailList){
|
wOutboundDetailExtMapper.insert(detail);
|
//记录库存变动记录
|
wStockRecordExtService.saveRecord(Constants.ONE,detail.getId(),user);
|
if(detail.getWOutboundRecordInList()!=null){
|
for(WOutboundRecord r : detail.getWOutboundRecordInList()){
|
r.setDetailId(detail.getId());
|
wOutboundRecordExtMapper.insert(r);
|
}
|
}
|
}
|
if(Constants.formatIntegerNum(mp.getHasProduceNum()) >Constants.formatIntegerNum(mp.getPlanNum())){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,该工单的产出数量不能大于工单计划数量!");
|
}
|
}
|
|
|
public void createOutDetail(LoginUserInfo user,WOutbound outbound,Workorder mp,WorkorderRecordExtListVO tModel,Integer doneType
|
,List<WOutboundDetail> detailList,List<WStock> stockList ){
|
//物料+批次+工序+质量属性去重
|
WOutboundDetail detail = new WOutboundDetail();
|
detail.setDeleted(Constants.ZERO);
|
detail.setCreateTime(DateUtil.getCurrentDate());
|
detail.setCreateUser(user.getId());
|
detail.setOutboundId(outbound.getId());
|
detail.setRootDepartId(outbound.getRootDepartId());
|
detail.setWarehouseId(outbound.getWarehouseId());
|
detail.setLocationId(mp.getFinishWarehouseLocationId());
|
detail.setNum(BigDecimal.valueOf(doneType.equals(Constants.ZERO)?tModel.getQualifiedNum():tModel.getUnqualifiedNum()));
|
if(detail.getNum().compareTo(BigDecimal.ZERO)==Constants.ZERO){
|
return;
|
}
|
detail.setStatus(Constants.ONE);
|
detail.setDoneNum(detail.getNum());
|
detail.setDoneDate(new Date());
|
detail.setUnitId(tModel.getUnitId());
|
detail.setBatch(tModel.getMaterialBatch());
|
detail.setProcedureId(tModel.getProcedureId());
|
detail.setMaterialId(tModel.getMaterialId());
|
detail.setQualityType(doneType);
|
detail.setWOutboundRecordInList(new ArrayList<>());
|
detailList.add(detail);
|
|
WOutboundRecord record = new WOutboundRecord();
|
record.setDeleted(Constants.ZERO);
|
record.setCreateTime(DateUtil.getCurrentDate());
|
record.setCreateUser(user.getId());
|
record.setAppliancesId(tModel.getAppliancesId());
|
record.setBatch(detail.getBatch());
|
record.setRootDepartId(mp.getRootDepartId());
|
record.setNum(detail.getNum());
|
record.setOutboundId(detail.getOutboundId());
|
record.setUnitId(detail.getUnitId());
|
record.setWarehouseId(detail.getWarehouseId());
|
record.setMaterialId(detail.getMaterialId());
|
record.setProcedureId(detail.getProcedureId());
|
record.setLocationId(detail.getLocationId());
|
record.setQualityType(detail.getQualityType());
|
detail.getWOutboundRecordInList().add(record);
|
|
WStock stock = getFromStockList(mp.getFinishWarehouseLocationId(),detail.getWarehouseId(),detail.getMaterialId(),detail.getBatch(),
|
tModel.getProcedureId(),doneType,stockList);
|
if(stock!=null){
|
//如果库存对象已存在,直接增加对应的库存量
|
stock.setNum(Constants.formatBigdecimal(stock.getNum()).add(Constants.formatBigdecimal(detail.getNum())));
|
}else{
|
stock = new WStock();
|
stock.setMaterialId(detail.getMaterialId());
|
stock.setBatch(detail.getBatch());
|
stock.setWarehouseId(outbound.getWarehouseId());
|
stock.setLocationId(mp.getFinishWarehouseLocationId());
|
stock.setUnitId(detail.getUnitId());
|
stock.setNum(Constants.formatBigdecimal(detail.getNum()));
|
stock.setProcedureId(tModel.getProcedureId());
|
stock.setQualityType(doneType);
|
//待更新库存信息
|
stockList.add(stock);
|
}
|
}
|
|
|
private WStock initMaterialNum(Integer materialId, BigDecimal num) {
|
WStock s = new WStock();
|
s.setMaterialId(materialId);
|
//1:1投料
|
s.setNum(num);
|
return s;
|
}
|
|
private WOutbound getFromOutboundList(Integer warehouseId, List<WOutbound> outboundList) {
|
for(WOutbound o : outboundList){
|
if(Constants.equalsInteger(warehouseId,o.getWarehouseId())){
|
return o;
|
}
|
}
|
return null;
|
}
|
|
|
private WStock getFromStockList(Integer produceWarehouseLocationId, Integer warehouseId, Integer mId,String batch,Integer procedureId,Integer qtype,List<WStock> stockList) {
|
for(WStock s : stockList){
|
if(Constants.equalsInteger(produceWarehouseLocationId,s.getLocationId())
|
&& Constants.equalsInteger(procedureId,s.getProcedureId())
|
&& Constants.equalsInteger(qtype,s.getQualityType())
|
&& Constants.equalsInteger(warehouseId,s.getWarehouseId())
|
&& StringUtils.equals(batch,s.getBatch())
|
&& Constants.equalsInteger(mId,s.getMaterialId())){
|
return s;
|
}
|
}
|
return null;
|
}
|
private Integer getNextProcudureId(Integer proceduresId, Workorder mp) {
|
List<RouteProcedure> rpList = null;
|
if (mp.getBomModel() != null && mp.getBomModel().getRouteId() != null) {
|
//
|
if (mp.getBomModel().getRouteId() != null) {
|
RouteProcedure rp = new RouteProcedure();
|
rp.setDeleted(Constants.ZERO);
|
rp.setRouteId(mp.getBomModel().getRouteId());
|
rp.setDepartId(mp.getFactoryId());
|
rpList = routeProcedureExtMapper.selectList(new QueryWrapper<>(rp).orderByAsc("SORTNUM"));
|
}
|
} else {
|
//没有bom的情况
|
RouteProcedure rp = new RouteProcedure();
|
rp.setDeleted(Constants.ZERO);
|
rp.setDepartId(mp.getFactoryId());
|
rpList = routeProcedureExtMapper.selectList(new QueryWrapper<>(rp).exists("select bom.id from bom where bom.material_id=" + mp.getMaterialId() + " and bom.route_id =route_procedure.route_id and bom.deleted=0").orderByAsc("SORTNUM"));
|
|
}
|
if(rpList!=null && rpList.size()>0){
|
for(int i=0;i<rpList.size();i++){
|
RouteProcedure r = rpList.get(i);
|
if(Constants.equalsInteger(r.getProcedureId(),proceduresId)){
|
//如果工序相同,找下一工序
|
if(i < rpList.size()-1){
|
return rpList.get(i+1).getProcedureId();
|
}
|
}
|
}
|
}
|
return null;
|
}
|
|
private WOutboundDetail getWoutbondDetailByList(WorkorderRecordExtListVO tModel, List<WOutboundDetail> detailList) {
|
for(WOutboundDetail detail : detailList){
|
if(Constants.equalsInteger(detail.getProcedureId(),tModel.getProcedureId())
|
&& StringUtils.equals(detail.getBatch(),tModel.getMaterialBatch())
|
&& Constants.equalsInteger(detail.getMaterialId(),tModel.getMaterialId())
|
&& Constants.equalsInteger(detail.getQualityType(),tModel.getDoneType())){
|
return detail;
|
}
|
}
|
return null;
|
}
|
|
private Appliances getApplianceFromList(Integer appliancesId, List<Appliances> updateApplianceList) {
|
for(Appliances tModel :updateApplianceList){
|
if(Constants.equalsInteger(appliancesId,tModel.getId())){
|
return tModel;
|
}
|
}
|
return null;
|
}
|
|
|
@Override
|
@Transactional(rollbackFor = {BusinessException.class,Exception.class})
|
public WorkorderRecord dealWorkorderRecord(DealWorkorderRecordDTO dealWorkorderRecordDTO, LoginUserInfo loginUserInfo){
|
Workorder workorder = workorderExtMapper.selectById(dealWorkorderRecordDTO.getWorkorderId());
|
if(Objects.isNull(workorder)){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,该工单信息!");
|
}
|
if(Objects.isNull(dealWorkorderRecordDTO.getDownType())
|
||Objects.isNull(dealWorkorderRecordDTO.getWorkorderId())
|
||Objects.isNull(dealWorkorderRecordDTO.getNum())
|
){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST);
|
}
|
WorkorderRecord workorderRecord = new WorkorderRecord();
|
if(Objects.isNull(dealWorkorderRecordDTO.getRecordId())){
|
//查询工单下是否存在对应记录
|
workorderRecord = workorderRecordExtMapper.selectOne(new QueryWrapper<WorkorderRecord>()
|
.eq("WORKORDER_ID",dealWorkorderRecordDTO.getWorkorderId())
|
.eq("DONE_TYPE",dealWorkorderRecordDTO.getDownType())
|
.eq("TYPE",Constants.ONE)
|
.eq("DELETED",Constants.ZERO)
|
.last(" limit 1 ")
|
);
|
if(!Objects.isNull(workorderRecord)){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,该工单的该类产出记录已存在!");
|
}
|
BigDecimal havaNum = new BigDecimal(Constants.ZERO);
|
List<WorkorderRecord> workorderRecords = workorderRecordExtMapper.selectList(new QueryWrapper<WorkorderRecord>()
|
.eq("WORKORDER_ID",dealWorkorderRecordDTO.getWorkorderId()).eq("TYPE",Constants.ONE).eq("DELETED",Constants.ZERO));
|
if(!Objects.isNull(workorderRecords)&&workorderRecords.size()>Constants.ZERO){
|
havaNum = workorderRecords.stream().map(s -> s.getNum()).reduce(BigDecimal.ZERO, BigDecimal::add);
|
}
|
if((havaNum.add(dealWorkorderRecordDTO.getNum())).compareTo(BigDecimal.valueOf(workorder.getPlanNum()))>Constants.ZERO){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,该工单的产出数量不能大于工单计划数量!");
|
}
|
//数据存储
|
workorderRecord = new WorkorderRecord();
|
workorderRecord.setDeleted(Constants.ZERO);
|
workorderRecord.setCreateUser(loginUserInfo.getId());
|
workorderRecord.setCreateTime(new Date());
|
workorderRecord.setDoneType(dealWorkorderRecordDTO.getDownType());
|
workorderRecord.setNum(dealWorkorderRecordDTO.getNum());
|
workorderRecord.setRootDepartId(loginUserInfo.getRootDepartment().getId());
|
workorderRecord.setDepartId(loginUserInfo.getCurComDepartment().getId());
|
workorderRecord.setPlanId(workorder.getPlanId());
|
workorderRecord.setWorkorderId(dealWorkorderRecordDTO.getWorkorderId());
|
workorderRecord.setBatch(workorder.getBatch());
|
workorderRecord.setFactoryId(workorder.getFactoryId());
|
workorderRecord.setProcedureId(workorder.getProcedureId());
|
workorderRecord.setProDate(new Date());
|
workorderRecord.setType(Constants.ONE);
|
workorderRecord.setMaterialId(workorder.getMaterialId());
|
workorderRecord.setUnitId(workorder.getUnitId());
|
workorderRecord.setMaterialBatch(workorder.getBatch());
|
workorderRecordExtMapper.insert(workorderRecord);
|
|
}else{
|
//查询工单下是否存在对应记录
|
workorderRecord = workorderRecordExtMapper.selectById(dealWorkorderRecordDTO.getRecordId());
|
BigDecimal havaNum = new BigDecimal(Constants.ZERO);
|
List<WorkorderRecord> workorderRecords = workorderRecordExtMapper.selectList(new QueryWrapper<WorkorderRecord>()
|
.eq("WORKORDER_ID",dealWorkorderRecordDTO.getWorkorderId()).eq("TYPE",Constants.ONE).eq("DELETED",Constants.ZERO).ne("id",dealWorkorderRecordDTO.getRecordId()));
|
if(!Objects.isNull(workorderRecords)&&workorderRecords.size()>Constants.ZERO){
|
havaNum = workorderRecords.stream().map(s -> s.getNum()).reduce(BigDecimal.ZERO, BigDecimal::add);
|
}
|
if((havaNum.add(dealWorkorderRecordDTO.getNum())).compareTo(BigDecimal.valueOf(workorder.getPlanNum()))>Constants.ZERO){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,该工单的产出数量不能大于工单计划数量!");
|
}
|
if(dealWorkorderRecordDTO.getNum().compareTo(BigDecimal.ZERO)==Constants.ZERO){
|
workorderRecord.setDeleted(Constants.ONE);
|
}else{
|
workorderRecord.setDeleted(Constants.ZERO);
|
}
|
workorderRecord.setUpdateTime(new Date());
|
workorderRecord.setUpdateUser(loginUserInfo.getId());
|
workorderRecord.setNum(dealWorkorderRecordDTO.getNum());
|
workorderRecordExtMapper.updateById(workorderRecord);
|
|
}
|
return workorderRecord;
|
}
|
|
|
@Override
|
public List<WorkorderRecord> getWorkorderRecordList(Integer workorderId) {
|
List<WorkorderRecord> workorderRecordList = workorderRecordExtMapper.selectList(
|
new QueryWrapper<WorkorderRecord>().eq("WORKORDER_ID",workorderId).eq("TYPE",Constants.ONE).eq("DELETED",Constants.ZERO).orderByAsc(" DONE_TYPE "));
|
if(!Objects.isNull(workorderRecordList)&workorderRecordList.size()>Constants.ZERO){
|
for (WorkorderRecord workorderRecord:workorderRecordList) {
|
//查询不良产出记录详情 产出 且 不良 才存在该数据
|
if(workorderRecord.getType().equals(Constants.ONE)&&workorderRecord.getUnqualifiedNum().compareTo(BigDecimal.ZERO)>Constants.ZERO){
|
List<UnqualifiedRecord> unqualifiedRecordList = unqualifiedRecordService.findJoinList(workorderRecord.getId());
|
workorderRecord.setUnqualifiedRecordList(unqualifiedRecordList);
|
}
|
}
|
}
|
return workorderRecordList;
|
}
|
|
|
@Override
|
public PageData<WStockExtListVO> choiceStockPageForWorkorder(PageWrap<QueryWStockDto> pageWrap,LoginUserInfo userInfo) {
|
Workorder workorder = workorderExtMapper.selectById(pageWrap.getModel().getWorkorderId());
|
if(Objects.isNull(workorder)){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,未查询到工单信息!");
|
}
|
//查询并验证工单信息
|
Workorder mp = getOrderAndValid(userInfo,workorder.getId());
|
//查询全部bom组成数据,如果有BOM配置,按照BOM组成进行投料,如果没有BOM配置,则投料物料为待生产库位的物料本身
|
QueryBomDetailExtDTO bdparam = initBomParam(userInfo,mp);
|
List<BomDetailExtListVO> bomDetailList = null;
|
if(bdparam!=null){
|
bomDetailList = bomDetailExtMapper.selectList(bdparam);
|
List<Integer> materialDistributeId = bomDetailList.stream().map(BomDetailExtListVO::getMaterialId).collect(Collectors.toList());
|
pageWrap.getModel().setMaterialDistributeId(materialDistributeId);
|
}else{
|
//查询物料BOM信息
|
Bom bom = bomExtMapper.selectOne(new QueryWrapper<Bom>().eq("MATERIAL_ID",workorder.getMaterialId()).eq("DELETED",Constants.ZERO).last(" limit 1 "));
|
if(Objects.isNull(bom)){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,未查询到BOM信息!");
|
}
|
RouteProcedure currentRouteProcedure = routeProcedureExtMapper.selectOne(new QueryWrapper<RouteProcedure>()
|
.eq("ROUTE_ID",bom.getRouteId())
|
.eq("PROCEDURE_ID",workorder.getProcedureId())
|
.last(" limit 1 ")
|
);
|
if(currentRouteProcedure!=null){
|
RouteProcedure routeProcedure = routeProcedureExtMapper.selectOne(new QueryWrapper<RouteProcedure>()
|
.eq("ROUTE_ID",currentRouteProcedure.getRouteId()).apply(" SORTNUM < " + currentRouteProcedure.getSortnum() ).eq("STATUS",Constants.ONE).orderByDesc(" SORTNUM ").last(" limit 1 ")
|
);
|
if(Objects.isNull(routeProcedure)){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,未查询到生产物料上一步工序信息!");
|
}
|
pageWrap.getModel().setProcedureId(routeProcedure.getProcedureId());
|
pageWrap.getModel().setMaterialId(workorder.getMaterialId());
|
}
|
}
|
pageWrap.getModel().setLocationId(workorder.getProduceWarehouseLocationId());
|
PageHelper.startPage(pageWrap.getPage(), pageWrap.getCapacity());
|
List<WStockExtListVO> result = wStockExtMapper.choiceStockList(pageWrap.getModel());
|
return PageData.from(new PageInfo<>(result));
|
}
|
|
@Override
|
public PageData<WStockExtListVO> choiceStockPageForPlans(PageWrap<QueryWStockDto> pageWrap,LoginUserInfo userInfo) {
|
Plans plans =plansExtMapper.selectById(pageWrap.getModel().getPlansId());
|
if(Objects.isNull(plans)){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,未查询到工序计划信息!");
|
}
|
Device device = deviceExtMapper.selectById(pageWrap.getModel().getDeviceId());
|
if(Objects.isNull(plans)){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,未查询到设备信息!");
|
}
|
//查询并验证工单信息
|
this.getPlansAndValid(userInfo,plans);
|
//查询全部bom组成数据,如果有BOM配置,按照BOM组成进行投料,如果没有BOM配置,则投料物料为待生产库位的物料本身
|
QueryBomDetailExtDTO bdparam = initBomParamForPlans(userInfo,plans);
|
List<BomDetailExtListVO> bomDetailList = null;
|
if(bdparam!=null){
|
bomDetailList = bomDetailExtMapper.selectList(bdparam);
|
List<Integer> materialDistributeId = bomDetailList.stream().map(BomDetailExtListVO::getMaterialId).collect(Collectors.toList());
|
pageWrap.getModel().setMaterialDistributeId(materialDistributeId);
|
}else{
|
//查询物料BOM信息
|
Bom bom = bomExtMapper.selectOne(new QueryWrapper<Bom>().eq("MATERIAL_ID",plans.getMaterialId()).eq("DELETED",Constants.ZERO).last(" limit 1 "));
|
if(Objects.isNull(bom)){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,未查询到BOM信息!");
|
}
|
RouteProcedure currentRouteProcedure = routeProcedureExtMapper.selectOne(new QueryWrapper<RouteProcedure>()
|
.eq("ROUTE_ID",bom.getRouteId())
|
.eq("PROCEDURE_ID",plans.getProcedureId())
|
.last(" limit 1 ")
|
);
|
if(currentRouteProcedure!=null){
|
RouteProcedure routeProcedure = routeProcedureExtMapper.selectOne(new QueryWrapper<RouteProcedure>()
|
.eq("ROUTE_ID",currentRouteProcedure.getRouteId()).apply(" SORTNUM < " + currentRouteProcedure.getSortnum() ).eq("STATUS",Constants.ONE).orderByDesc(" SORTNUM ").last(" limit 1 ")
|
);
|
if(Objects.isNull(routeProcedure)){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,未查询到生产物料上一步工序信息!");
|
}
|
pageWrap.getModel().setProcedureId(routeProcedure.getProcedureId());
|
pageWrap.getModel().setMaterialId(plans.getMaterialId());
|
}
|
}
|
pageWrap.getModel().setLocationId(device.getProduceWarehouseLocationId());
|
PageHelper.startPage(pageWrap.getPage(), pageWrap.getCapacity());
|
List<WStockExtListVO> result = wStockExtMapper.choiceStockList(pageWrap.getModel());
|
return PageData.from(new PageInfo<>(result));
|
}
|
|
@Override
|
@Transactional(rollbackFor = {BusinessException.class,Exception.class})
|
public WorkorderRecord createWorkorderRecord(CreateWorkorderRecordDTO createWorkorderRecordDTO, LoginUserInfo loginUserInfo ,Integer userId){
|
Workorder workorder = workorderExtMapper.selectById(createWorkorderRecordDTO.getWorkorderId());
|
if(Objects.isNull(workorder)){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,未查询到该工单信息!");
|
}
|
if(Objects.isNull(createWorkorderRecordDTO.getUnQualifiedNum())
|
||Objects.isNull(createWorkorderRecordDTO.getUnQualifiedNum())
|
||Objects.isNull(createWorkorderRecordDTO.getWorkorderId())
|
){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST);
|
}
|
BigDecimal num = createWorkorderRecordDTO.getQualifiedNum().add(createWorkorderRecordDTO.getUnQualifiedNum());
|
WorkorderRecord workorderRecord = new WorkorderRecord();
|
//查询工单下是否存在对应记录
|
workorderRecord = workorderRecordExtMapper.selectOne(new QueryWrapper<WorkorderRecord>()
|
.eq("WORKORDER_ID",createWorkorderRecordDTO.getWorkorderId())
|
.eq("TYPE",Constants.ONE)
|
.eq("DELETED",Constants.ZERO)
|
.last(" limit 1 ")
|
);
|
if(!Objects.isNull(workorderRecord)){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,该工单的该类产出记录已存在!");
|
}
|
if(num.compareTo(BigDecimal.valueOf(workorder.getPlanNum()))>Constants.ZERO){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,该工单的产出数量不能大于工单计划数量!");
|
}
|
//数据存储
|
workorderRecord = new WorkorderRecord();
|
workorderRecord.setDeleted(Constants.ZERO);
|
if(!Objects.isNull(userId)){
|
CompanyUser companyUser = new CompanyUser();
|
companyUser.setUserId(userId);
|
companyUser.setRootDepartId(loginUserInfo.getRootDepartment().getId());
|
companyUser = companyUserExtMapper.selectOne(new QueryWrapper<>(companyUser).last("limit 1"));
|
if(Objects.isNull(companyUser)){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,未查询到生产人员对应企业用户信息!");
|
}
|
workorderRecord.setCreateUser(userId);
|
workorderRecord.setRootDepartId(loginUserInfo.getRootDepartment().getId());
|
workorderRecord.setDepartId(loginUserInfo.getCurComDepartment().getId());
|
}else{
|
workorderRecord.setCreateUser(loginUserInfo.getId());
|
workorderRecord.setRootDepartId(loginUserInfo.getRootDepartment().getId());
|
workorderRecord.setDepartId(loginUserInfo.getCurComDepartment().getId());
|
}
|
workorderRecord.setCreateTime(new Date());
|
workorderRecord.setNum(num);
|
workorderRecord.setPlanId(workorder.getPlanId());
|
workorderRecord.setWorkorderId(createWorkorderRecordDTO.getWorkorderId());
|
workorderRecord.setBatch(workorder.getBatch());
|
workorderRecord.setFactoryId(workorder.getFactoryId());
|
workorderRecord.setProcedureId(workorder.getProcedureId());
|
workorderRecord.setProDate(new Date());
|
workorderRecord.setType(Constants.ONE);
|
workorderRecord.setMaterialId(workorder.getMaterialId());
|
workorderRecord.setUnitId(workorder.getUnitId());
|
workorderRecord.setMaterialBatch(workorder.getBatch());
|
workorderRecord.setUnqualifiedNum(createWorkorderRecordDTO.getUnQualifiedNum());
|
workorderRecord.setQualifiedNum(createWorkorderRecordDTO.getQualifiedNum());
|
//计算工资信息
|
SalaryParam salaryParam = salaryParamMapper.selectOne(new QueryWrapper<SalaryParam>().eq("DELETED",Constants.ZERO).eq("MATERIAL_ID",workorderRecord.getMaterialId())
|
.eq("DEPART_ID",workorderRecord.getFactoryId()).eq("PROCEDURE_ID",workorderRecord.getProcedureId()).eq("TYPE",createWorkorderRecordDTO.getType()).last(" limit 1 "));
|
if(!Objects.isNull(salaryParam)){
|
workorderRecord.setSalaryPrice(salaryParam.getSalary());
|
workorderRecord.setSalaryType(salaryParam.getType());
|
workorderRecord.setSalaryUnqualified(salaryParam.getUnqualified());
|
workorderRecord.setSalaryTimes(salaryParam.getTimes());
|
//计件工资
|
if(salaryParam.getType().equals(Constants.ZERO)){
|
workorderRecord.setSalaryNum(salaryParam.getNum());
|
workorderRecord.setDuration(createWorkorderRecordDTO.getDuration());
|
workorderRecord.setSalary(salaryParam.getSalary().multiply(salaryParam.getUnqualified()==Constants.ONE?num:createWorkorderRecordDTO.getQualifiedNum()));
|
}else{
|
if(!Objects.isNull(createWorkorderRecordDTO.getDuration())&&Constants.formatIntegerNum(createWorkorderRecordDTO.getDuration())>Constants.ZERO){
|
workorderRecord.setSalaryNum(salaryParam.getNum());
|
workorderRecord.setDuration(createWorkorderRecordDTO.getDuration());
|
workorderRecord.setSalary(BigDecimal.valueOf(createWorkorderRecordDTO.getDuration()).multiply(salaryParam.getSalary()).divide(new BigDecimal(3600),BigDecimal.ROUND_HALF_UP));
|
}
|
}
|
}
|
//插入工单操作记录,并且判断是否更改为工单的状态【生产中】
|
updateOrderInfo(loginUserInfo,workorder,Constants.WORKORDER_HISTORY_STATUS.produce);
|
workorderRecordExtMapper.insert(workorderRecord);
|
return workorderRecord;
|
}
|
|
|
|
|
}
|