| 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.dto.CreateMaterialDTO; | 
| import doumeemes.dao.business.dto.MaterialListDTO; | 
| import doumeemes.dao.business.model.*; | 
| import doumeemes.dao.ext.*; | 
| import doumeemes.dao.ext.bean.EndCheckApBean; | 
| import doumeemes.dao.ext.dto.*; | 
| import doumeemes.dao.ext.vo.*; | 
| import doumeemes.dao.system.model.SystemDictData; | 
| import doumeemes.service.business.WOutboundService; | 
| import doumeemes.service.ext.BarcodeParamExtService; | 
| import doumeemes.service.ext.DepartmentExtService; | 
| import doumeemes.service.ext.WStockRecordExtService; | 
| import doumeemes.service.ext.WorkorderRecordExtService; | 
| 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; | 
|   | 
| /** | 
|  * 工单生产过程记录Service实现 | 
|  * @author 江蹄蹄 | 
|  * @date 2022/04/20 10:56 | 
|  */ | 
| @Service | 
| public class WorkorderRecordExtServiceImpl implements WorkorderRecordExtService { | 
|   | 
|     @Autowired | 
|     private RedisTemplate<String, Object> redisTemplate; | 
|     @Autowired | 
|     public SystemDictDataBiz systemDictDataBiz; | 
|   | 
|     @Autowired | 
|     private BackOrderDetailMapper backOrderDetailMapper; | 
|     @Autowired | 
|     private BackorderMapper backorderMapper; | 
|     @Autowired | 
|     private WOutboundDetailExtMapper wOutboundDetailExtMapper; | 
|     @Autowired | 
|     private WStockRecordExtService wStockRecordExtService; | 
|     @Autowired | 
|     private RouteProcedureExtMapper routeProcedureExtMapper; | 
|     @Autowired | 
|     private WStockExtMapper wStockExtMapper; | 
|     @Autowired | 
|     private WOutboundRecordExtMapper wOutboundRecordExtMapper; | 
|     @Autowired | 
|     private WOutboundService wOutboundService; | 
|     @Autowired | 
|     private WorkorderRecordExtMapper workorderRecordExtMapper; | 
|     @Autowired | 
|     private WorkorderCheckExtMapper workorderCheckExtMapper; | 
|     @Autowired | 
|     private AppliancesExtMapper appliancesExtMapper; | 
|     @Autowired | 
|     private PlansExtMapper plansExtMapper; | 
|   | 
|     @Autowired | 
|     private CompanyUserExtMapper companyUserExtMapper; | 
|     @Autowired | 
|     private DepartmentExtService departmentExtService; | 
|     @Autowired | 
|     private PlanHistoryExtMapper planHistoryExtMapper; | 
|     @Autowired | 
|     private MaterialDistributeExtMapper materialDistributeExtMapper; | 
|     @Autowired | 
|     private WorkorderExtMapper workorderExtMapper; | 
|     @Autowired | 
|     private BomDetailExtMapper bomDetailExtMapper; | 
|     @Autowired | 
|     private BomExtMapper bomExtMapper; | 
|     @Autowired | 
|     private BarcodeParamExtService barcodeParamExtService; | 
|     @Autowired | 
|     private SystemDictDataService systemDictDataService; | 
|     @Autowired | 
|     private WorkorderHistoryExtMapper workorderHistoryExtMapper; | 
|   | 
|     @Override | 
|     public PageData<WorkorderRecordExtListVO> findPage(PageWrap<QueryWorkorderRecordExtDTO> pageWrap) { | 
|         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|         if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){ | 
|             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!"); | 
|         } | 
|         //只能查看当前根组织的数据 | 
|         pageWrap.getModel().setDeleted(Constants.ZERO); | 
|         pageWrap.getModel().setRootDepartId(user.getRootDepartment().getId()); | 
|         PageHelper.startPage(pageWrap.getPage(), pageWrap.getCapacity()); | 
|   | 
|         //数据权限 | 
|         List<Integer> dataPermission = user.getDepartPermissionList(); | 
|         if(dataPermission!=null){ | 
|             pageWrap.getModel().setCreateUser(user.getId()); | 
|             pageWrap.getModel().setDepartIds(dataPermission); | 
|            /*if(dataPermission.size() == 0){ | 
|                 //只能看自己的(生产人员信息) | 
|                 //  pageWrap.getModel().setProUserId(user.getId()); | 
|                 //需求变更 查看数据权限范围内的数据(走创建人或者生产人员为我数据权限范围内); | 
|                 pageWrap.getModel().setCreateUser(user.getId()); | 
|             }else{ | 
|                 //否则走数据权限 | 
|                 pageWrap.getModel().setDepartIds(dataPermission); | 
|             }*/ | 
|         } | 
|         List<WorkorderRecordExtListVO> result = workorderRecordExtMapper.selectListNew(pageWrap.getModel()); | 
|         if(result!=null){ | 
|             List<DepartmentExtListVO> allDepartList = RedisUtil.getObject(redisTemplate,Constants.RedisKeys.COM_DEPART_LIST_KEY+user.getCompany().getId(),ArrayList.class); | 
|             for(WorkorderRecordExtListVO model : result){ | 
|                 //查询生产人员姓名 | 
|                 initProUser(user,model,allDepartList); | 
|             } | 
|         } | 
|         return PageData.from(new PageInfo<>(result)); | 
|     } | 
|     @Override | 
|     public  PageData<SalaryStatisticsListVO> salaryStatistic(PageWrap<QuerySalaryStatisticDTO> pageWrap) { | 
|         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|         if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){ | 
|             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!"); | 
|         } | 
|         //只能查看当前根组织的数据 | 
|         pageWrap.getModel().setRootDepartId(user.getRootDepartment().getId()); | 
|         PageHelper.startPage(pageWrap.getPage(), pageWrap.getCapacity()); | 
|         List<SalaryStatisticsListVO> result = workorderRecordExtMapper.salaryStatistic(pageWrap.getModel()); | 
|         if(result!=null){ | 
|             List<DepartmentExtListVO> allDepartList = RedisUtil.getObject(redisTemplate,Constants.RedisKeys.COM_DEPART_LIST_KEY+user.getCompany().getId(),ArrayList.class); | 
|             for(SalaryStatisticsListVO model : result){ | 
|                 //查询生产人员姓名 | 
| //                model.setUserName(initProUser(user,model.getUserId(),allDepartList)); | 
|                     model.setUserInfo(initProUser(user,model.getUserId(),allDepartList)); | 
|                     model.setJijianSalary(model.getJijianSalary().divide(new BigDecimal("100"),2,BigDecimal.ROUND_HALF_UP)); | 
|                     model.setJishiSalary(model.getJishiSalary().divide(new BigDecimal("100"),2,BigDecimal.ROUND_HALF_UP)); | 
|                     model.setTotalSalary(model.getTotalSalary().divide(new BigDecimal("100"),2,BigDecimal.ROUND_HALF_UP)); | 
|             } | 
|         } | 
|         return PageData.from(new PageInfo<>(result)); | 
|     } | 
|     @Override | 
|     public  PageData<UserSalaryListVO> userSalaryPage(PageWrap<QueryUserSalaryListDTO> pageWrap) { | 
|         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|         if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){ | 
|             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!"); | 
|         } | 
|         //只能查看当前根组织的数据 | 
|         pageWrap.getModel().setRootDepartId(user.getRootDepartment().getId()); | 
|         pageWrap.getModel().setRootDepartId(user.getRootDepartment().getId()); | 
|         PageHelper.startPage(pageWrap.getPage(), pageWrap.getCapacity()); | 
|   | 
|         //数据权限 | 
| //        List<Integer> dataPermission = user.getDepartPermissionList(); | 
|         List<UserSalaryListVO> result = workorderRecordExtMapper.userSalaryPage(pageWrap.getModel()); | 
|         if(result!=null){ | 
|             List<DepartmentExtListVO> allDepartList = RedisUtil.getObject(redisTemplate,Constants.RedisKeys.COM_DEPART_LIST_KEY+user.getCompany().getId(),ArrayList.class); | 
|             for(UserSalaryListVO model : result){ | 
|                 //查询生产人员姓名 | 
|                 model.setUserInfo(initProUser(user,model.getUserId(),allDepartList)); | 
|                 if(Constants.formatBigdecimal4Float(model.getNum()).compareTo(new BigDecimal(0))>0){ | 
|                     model.setRate(Constants.formatBigdecimal4Float(model.getQualifiedNum()).divide(model.getNum(),4).multiply(new BigDecimal(100))); | 
|                 } | 
|             } | 
|         } | 
|         return PageData.from(new PageInfo<>(result)); | 
|     } | 
|   | 
|     private void initProUser(LoginUserInfo user, WorkorderRecordExtListVO data, List<DepartmentExtListVO> allDepartList) { | 
|         if(data.getCreateUser() ==null){ | 
|             return; | 
|         } | 
|         CompanyUser query=new CompanyUser(); | 
|         query.setUserId(data.getCreateUser()); | 
|         query.setRootDepartId(user.getRootDepartment().getId()); | 
|         query.setDeleted(Constants.ZERO); | 
|         CompanyUser comp= companyUserExtMapper.selectOne(new QueryWrapper<>(query).last(" limit 1")); | 
|         if(comp!=null){ | 
|             DepartmentExtListVO d = departmentExtService.getModelById(user.getCompany().getId(),comp.getDepartmentId(),allDepartList); | 
|             String dName =d==null?"":StringUtils.defaultString(d.getName(),""); | 
|             data.setProcedureName(comp.getName()+"-"+dName); | 
|         } | 
|     } | 
|     private UserBaseInfoVO initProUser(LoginUserInfo user, Integer userId, List<DepartmentExtListVO> allDepartList) { | 
|         if(userId ==null){ | 
|             return null; | 
|         } | 
|   | 
|         CompanyUser query=new CompanyUser(); | 
|         query.setUserId(userId); | 
|         query.setRootDepartId(user.getRootDepartment().getId()); | 
|         query.setDeleted(Constants.ZERO); | 
|         CompanyUser comp= companyUserExtMapper.selectOne(new QueryWrapper<>(query).last(" limit 1")); | 
|         if(comp!=null){ | 
|             UserBaseInfoVO userinfo = new UserBaseInfoVO(); | 
|             DepartmentExtListVO d = departmentExtService.getModelById(user.getCompany().getId(),comp.getDepartmentId(),allDepartList); | 
|             String dName =d==null?"":StringUtils.defaultString(d.getName(),""); | 
|             userinfo.setNameAndDepart (comp.getName()+"-"+dName); | 
|             userinfo.setDepartId(d.getId()); | 
|             userinfo.setUserId(userId); | 
|             userinfo.setUserName(comp.getName()); | 
|             userinfo.setDepartName(d.getName()); | 
|             return  userinfo; | 
|         } | 
|         return null; | 
|     } | 
|     @Override | 
|     public List<WorkorderRecordExtListVO> findAll(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<WorkorderRecordExtListVO> result = workorderRecordExtMapper.selectListNew(pageWrap); | 
|   | 
|         List<CategoryExtListVO> clist = RedisUtil.getObject(redisTemplate,Constants.RedisKeys.COM_CATEGORY_KEY+user.getCompany().getId(), ArrayList.class); | 
|   | 
|         for(int i=0;i<result.size();i++){ | 
|             WorkorderRecordExtListVO w=result.get(i); | 
|             for(int j=0;j<clist.size();j++){ | 
|                 CategoryExtListVO categoryExtListVO=clist.get(j); | 
|                 if(StringUtils.isNotEmpty(w.getCumodelCateBigId())){ | 
|                     if(Constants.equalsInteger(Integer.valueOf(w.getCumodelCateBigId()),categoryExtListVO.getId())){ | 
|                         w.setCmodel1BigName(categoryExtListVO.getName()); | 
|                     } | 
|                 } | 
|   | 
|                 if(StringUtils.isNotEmpty(w.getCumodelCateMiddleId())){ | 
|                     if(Constants.equalsInteger(Integer.valueOf(w.getCumodelCateMiddleId()),categoryExtListVO.getId())){ | 
|                         w.setCmodel1MiddleName(categoryExtListVO.getName()); | 
|                     } | 
|                 } | 
|   | 
|                 if(StringUtils.isNotEmpty(w.getCumodelCateSmallId())){ | 
|                     if(Constants.equalsInteger(Integer.valueOf(w.getCumodelCateSmallId()),categoryExtListVO.getId())){ | 
|                         w.setCmodel1SmallName(categoryExtListVO.getName()); | 
|                     } | 
|                 } | 
|   | 
|             } | 
|         } | 
|         return  result; | 
|     } | 
|   | 
|   | 
|   | 
|   | 
|   | 
|   | 
|     /** | 
|      * 工单投料 | 
|      * @param param | 
|      * @return | 
|      */ | 
|     @Transactional(rollbackFor = {BusinessException.class,Exception.class}) | 
|     @Override | 
|     public  Integer createMaterial(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); | 
|         //查询全部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<MaterialListDTO> apList =  initApParamList(param); | 
|         //查询全部投料记录(查询是否有重复投料的篮筐) | 
|         List<WorkorderRecordExtListVO> allRecordList = workorderRecordExtMapper.selectAllList(getAllRecordParam(mp.getId(),Constants.WORKORDER_RECORD_TYPE.materail,apList)); | 
|         if(allRecordList!=null && allRecordList.size()>0){ | 
|             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,相同工装器具不能重复投料该工单!"); | 
|         } | 
|         //根据请求数据,查询全部器具信息 | 
|         List<AppliancesExtListVO> aList = appliancesExtMapper.selectList(initApplianceParam(user,mp.getBackorderId(),apList)); | 
|         if(aList == null || aList.size() ==0){ | 
|             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,当前工装装载物料非本次返工返修关联物料"); | 
|         } | 
|         //带批量插入投料记录集合 | 
|         List<WorkorderRecord> recordList = new ArrayList<>(); | 
|         //待更新数据 | 
|         List<Appliances> appliancesList = new ArrayList<>() ; | 
|         if(Constants.equalsInteger(mp.getType(),Constants.WORKORDER_TYPE.normal)){ | 
|             //如果是正常单 | 
|             List<BomDetailExtListVO> bomDetailList = null; | 
|             //如果有bom配置 | 
|             if(bdparam!=null){ | 
|                 bomDetailList = bomDetailExtMapper.selectList(bdparam); | 
|             } | 
|             for(AppliancesExtListVO amodel : aList){ | 
|                 BigDecimal pNum = getNumFromParam(amodel.getId(),apList); | 
|                 //当前计划有bom不需要判断投料时的下一个工序进行对比,只有无BOM需要加这个校验 | 
|                 if(bdparam==null && !Constants.equalsInteger(amodel.getNextProcedureId(),mp.getProcedureId())){ | 
|                     throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,该工装绑定的下一道工序与当前工单工序不一致,不能进行投料!"); | 
|                 } | 
|                 if(bdparam!=null) { | 
|                     //如果有bom配置,按bom进行投料 | 
|                     //判断器具装载物料数量是否满足提交条件 | 
|                     isValideApplianceNum(pNum,user,amodel,mp,bomDetailList); | 
|                 }else { | 
|                     //如果没有bom配置,投生产物料本身 | 
|                     //判断器具装载物料数量是否满足提交条件 | 
|                     isValideApplianceNum(pNum,user,amodel,mp); | 
|                 } | 
|                 //不更新器具状态和数据 | 
|                 //appliancesList.add(initUpdateAppliance(user,pNum,amodel)); | 
|                 //初始化投料记录对象 | 
|                 recordList.add(getWorkrecordModel(user,amodel,mp,pNum )); | 
|             } | 
|         }else{ | 
|             //如果是返工返修申请 | 
|             if(mp.getBackorderId() == null){ | 
|                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,该工单关联返修申请信息有误,请联系管理员!"); | 
|             } | 
|             for(AppliancesExtListVO amodel : aList){ | 
|                 BigDecimal pNum = getNumFromParam(amodel.getId(),apList); | 
|                 //判断器具装载物料数量是否满足提交条件 | 
|                 isValideApplianceNum(pNum,user,amodel,mp); | 
|                 //初始化投料记录对象 | 
|                 recordList.add(getWorkrecordModel(user,amodel,mp,pNum )); | 
|             } | 
|         } | 
|   | 
|         //批量插入投料记录 | 
|         workorderRecordExtMapper.insertBatch(recordList); | 
|         //单添加历史记录(不更新状态) | 
|         updateOrderInfo(user,mp,Constants.WORKORDER_HISTORY_STATUS.material); | 
|         /*if(appliancesList.size()>0){ | 
|             for(Appliances ta : appliancesList){ | 
|                 //根据id更新器具状态和数量 | 
|                 appliancesExtMapper.updateById(ta); | 
|             } | 
|         }*/ | 
|         return param.getId(); | 
|     } | 
|     /** | 
|      * 工单产出 | 
|      * @param param | 
|      * @return | 
|      */ | 
|     @Transactional(rollbackFor = {BusinessException.class,Exception.class}) | 
|     @Override | 
|     public  Integer createProduce(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); | 
|   | 
|         //合并并坚持提交物料数据的合法性 | 
|         List<MaterialListDTO> apList =  initApParamList(param); | 
|         //查询全部产出记录(查询是否有重复投放的篮筐) | 
|         List<WorkorderRecordExtListVO> allRecordList = workorderRecordExtMapper.selectAllList(getAllRecordParam(mp.getId(),Constants.WORKORDER_RECORD_TYPE.produce,apList)); | 
|         if(allRecordList!=null && allRecordList.size()>0){ | 
|             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,相同工装器具不能重复投放产出物料!"); | 
|         } | 
|         //根据请求数据,查询全部器具信息 | 
|         List<AppliancesExtListVO> aList = appliancesExtMapper.selectList(initApplianceParam(user,null,apList)); | 
|         if(aList == null || aList.size() ==0){ | 
|             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,该工单物料信息配置有误,请联系管理员!"); | 
|         } | 
|         //带批量插入投料记录集合 | 
|         List<WorkorderRecord> recordList = new ArrayList<>(); | 
|         initBomParam(user,mp); | 
|         BomDetail bomDetail = isBomMaterialed(mp); | 
|         for(AppliancesExtListVO amodel : aList){ | 
|             BigDecimal pNum = getNumFromParam(amodel.getId(),apList); | 
|              //判断器具装载物料数量是否满足提交条件,返回产出类型 0合格 1不良 | 
|            Integer doneType =  isValideAppliance(mp,pNum,user,amodel,bomDetail); | 
|             //初始化记录对象 | 
|             recordList.add(getWorkrecordProModel(user,amodel.getId(),mp,pNum ,doneType)); | 
|         } | 
|   | 
|   | 
|         //批量插入投料记录 | 
|         workorderRecordExtMapper.insertBatch(recordList); | 
|         //单添加历史记录(不更新状态) | 
|         updateOrderInfo(user,mp,Constants.WORKORDER_HISTORY_STATUS.produce); | 
|   | 
|         return param.getId(); | 
|     } | 
|   | 
|     /** | 
|      * 产出工装是否满足条件,必须为合格工装 | 
|      * @param user | 
|      * @param amodel | 
|      */ | 
|     private Integer isValideAppliance(Workorder mp,BigDecimal pNum,LoginUserInfo user, AppliancesExtListVO amodel, BomDetail bomDetail ) { | 
|         BarcodeParamExtListVO barCode =  barcodeParamExtService.getByCodeId(user.getCompany().getId(),user.getCurComDepartment().getId(),amodel.getBrcode()); | 
|         String pName =barCode==null? "":barCode.getPrefix(); | 
|         if(pNum.compareTo(BigDecimal.ZERO)==0 ){ | 
|             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,器具【"+/*pName+*/amodel.getCode()+"】提交数据不合法!"); | 
|         } | 
|         if(amodel.getType() == null){ | 
|             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,器具【"+/*pName+*/amodel.getCode()+"】非合格工装,不能投放产出物料!"); | 
|         } | 
|         SystemDictData type = systemDictDataService.findById(amodel.getType()); | 
|        /* if(type == null || !StringUtils.equals(type.getLabel(),Constants.APPLIANCES_TYPE_LABLE.qualified)){ | 
|             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,器具【"+*//*pName+*//*amodel.getCode()+"】非合格工装,不能投放产出物料!"); | 
|         }*/ | 
|         if(type == null){ | 
|             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,器具【"+ amodel.getCode()+"】工作属性有误,不能投放产出物料!"); | 
|         } | 
|         if(!Constants.equalsInteger(mp.getType(),Constants.WORKORDER_TYPE.normal)){ | 
|             //如果是返工工单,返工工单只能产出合格/报废属性的工装 | 
|             if(!(StringUtils.equals(type.getLabel(),Constants.APPLIANCES_TYPE_LABLE.scrap) | 
|                     || StringUtils.equals(type.getLabel(),Constants.APPLIANCES_TYPE_LABLE.qualified))){ | 
|                 throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,工装器具【"+amodel.getCode()+"】质量属性不正确,返工工单只能产出合格/报废属性的工装!"); | 
|             } | 
|         } | 
|         if(isRouteLastProcudureId(mp.getProcedureId(),mp)  && bomDetail ==null){ | 
|             //如果是最后一道工序、并且生产物料不是其他bom的组成,使用混合篮筐 | 
|             if( !(StringUtils.equals(type.getLabel(),Constants.APPLIANCES_TYPE_LABLE.mix)|| | 
|                     StringUtils.equals(type.getLabel(),Constants.APPLIANCES_TYPE_LABLE.scrap)|| | 
|                     StringUtils.equals(type.getLabel(),Constants.APPLIANCES_TYPE_LABLE.rejects))){ | 
|                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,器具【"+pName+amodel.getCode()+"】非混合工装,不能投放产出物料!"); | 
|             } | 
|         } | 
|   | 
|         if( StringUtils.equals(type.getLabel(),Constants.APPLIANCES_TYPE_LABLE.rejects)){ | 
|             //不良 | 
|             return Constants.ONE; | 
|         }else  if( StringUtils.equals(type.getLabel(),Constants.APPLIANCES_TYPE_LABLE.scrap)){ | 
|             //报废 | 
|             return Constants.TWO; | 
|         }else  if( StringUtils.equals(type.getLabel(),Constants.APPLIANCES_TYPE_LABLE.qualified)) { | 
|             //合格 | 
|             return Constants.ZERO; | 
| //        }else  if( StringUtils.equals(type.getLabel(),Constants.APPLIANCES_TYPE_LABLE.mix)){ | 
|         } | 
|         return  null; | 
|     } | 
|   | 
|     private QueryWorkorderRecordExtDTO getAllRecordParam(Integer workorderId,int type,  List<MaterialListDTO> aids) { | 
|         QueryWorkorderRecordExtDTO rParam = new QueryWorkorderRecordExtDTO(); | 
|         rParam.setDeleted(Constants.ZERO); | 
|         rParam.setType(type); | 
|         rParam.setWorkorderId(workorderId); | 
|         rParam.setApplianceIds(aids); | 
|         return rParam; | 
|     } | 
|   | 
|     /** | 
|      * 投料删除 | 
|      * @param id | 
|      * @return | 
|      */ | 
|     @Transactional(rollbackFor = {BusinessException.class,Exception.class}) | 
|     @Override | 
|     public   void deleteById(Integer id) { | 
|         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|         if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){ | 
|             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!"); | 
|         } | 
|         WorkorderRecord model = new WorkorderRecord(); | 
|         model.setRootDepartId(user.getRootDepartment().getId()); | 
|         model.setId(id); | 
|         model.setDeleted(Constants.ZERO); | 
|         //查询投料记录 | 
|         model = workorderRecordExtMapper.selectByModel(model); | 
|         if(model ==null){ | 
|             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "对不起,记录不存在!"); | 
|         } | 
|         if(!Constants.equalsInteger(model.getWorkorderStatus(),Constants.WORKORDER_STATUS.create) | 
|                 && !Constants.equalsInteger(model.getWorkorderStatus(),Constants.WORKORDER_STATUS.material) | 
|                 && !Constants.equalsInteger(model.getWorkorderStatus(),Constants.WORKORDER_STATUS.producing) | 
|                 && !Constants.equalsInteger(model.getWorkorderStatus(),Constants.WORKORDER_STATUS.check) | 
|                 && !Constants.equalsInteger(model.getWorkorderStatus(),Constants.WORKORDER_STATUS.done)){ | 
|             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,该工单状态已流转,不能进行该操作!"); | 
|         } | 
|         WorkorderRecord param = new WorkorderRecord(); | 
|         param.setDeleted(Constants.ONE); | 
|         param.setId(id); | 
|         param.setUpdateTime(DateUtil.getCurrentDate()); | 
|         param.setUpdateUser(user.getId()); | 
|         workorderRecordExtMapper.updateById(param); | 
|     } | 
|     /** | 
|      * 投料修改 | 
|      * @param workorderRecord | 
|      * @return | 
|      */ | 
|     @Transactional(rollbackFor = {BusinessException.class,Exception.class}) | 
|     @Override | 
|     public  void updateById(WorkorderRecord workorderRecord){ | 
|         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|         if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){ | 
|             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!"); | 
|         } | 
|         if(Constants.formatBigdecimal(workorderRecord.getNum()).compareTo(new BigDecimal(0)) != 1){ | 
|             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,产品数量必须大于0!"); | 
|         } | 
|         WorkorderRecord model = new WorkorderRecord(); | 
|         model.setRootDepartId(user.getRootDepartment().getId()); | 
|         model.setId(workorderRecord.getId()); | 
|         model.setDeleted(Constants.ZERO); | 
|         //查询投料记录 | 
|         model = workorderRecordExtMapper.selectByModel(model); | 
|         if(model ==null){ | 
|             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "对不起,记录不存在!"); | 
|         } | 
|         if(!Constants.equalsInteger(model.getWorkorderStatus(),Constants.WORKORDER_STATUS.create) | 
|                 && !Constants.equalsInteger(model.getWorkorderStatus(),Constants.WORKORDER_STATUS.material) | 
|                 && !Constants.equalsInteger(model.getWorkorderStatus(),Constants.WORKORDER_STATUS.producing) | 
|                 && !Constants.equalsInteger(model.getWorkorderStatus(),Constants.WORKORDER_STATUS.check) | 
|                 && !Constants.equalsInteger(model.getWorkorderStatus(),Constants.WORKORDER_STATUS.done)){ | 
|             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,该工单状态已流转,不能进行该操作!"); | 
|         } | 
|         WorkorderRecord param = new WorkorderRecord(); | 
|         param.setNum(workorderRecord.getNum()); | 
|         param.setId(workorderRecord.getId()); | 
|         param.setUpdateTime(DateUtil.getCurrentDate()); | 
|         param.setUpdateUser(user.getId()); | 
|         workorderRecordExtMapper.updateById(param); | 
|     } | 
|   | 
|     @Transactional(rollbackFor = {BusinessException.class,Exception.class}) | 
|     @Override | 
|     public  Integer comfirmDone(Workorder param){ | 
|         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)){ | 
|             //只有已完工状态才能确认报工 | 
|             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)); | 
|         //检查数据信息 | 
| //        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,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); | 
|                 } | 
|   | 
|             } | 
|         } | 
|         return param.getId(); | 
|     } | 
|   | 
|     private QueryWorkorderRecordExtDTO getQueryRecordParam(Workorder param) { | 
|         QueryWorkorderRecordExtDTO mParam = new QueryWorkorderRecordExtDTO(); | 
|         mParam.setWorkorderId(param.getId()); | 
|         mParam.setDeleted(Constants.ZERO); | 
|         return mParam; | 
|     } | 
|     //更新篮筐信息 | 
|     private void updateApplianceList(List<Appliances> updateApplianceList, List<Appliances> updateApplianceProList) { | 
|             if(updateApplianceProList!=null){ | 
|                 for(Appliances a :updateApplianceProList){ | 
|                     //更新产出篮筐信息 | 
|                     dealUpdataeAppliance(a); | 
|                 } | 
|             } | 
|             if(updateApplianceList!=null){ | 
|                 //更新投料篮筐信息 | 
|                 for(Appliances a :updateApplianceList){ | 
|                     if(existsInProlist(a.getId(),updateApplianceProList)){ | 
|                         // 如果既有投料 也有产出的工单,以产出的状态为主进行更新,投料的不管 | 
|                         continue; | 
|                     } | 
|                     dealUpdataeAppliance(a); | 
|                 } | 
|             } | 
|     } | 
|   | 
|     private void dealUpdataeAppliance(Appliances a) { | 
|         LambdaUpdateWrapper<Appliances> updateWrapper = new LambdaUpdateWrapper<>(); | 
|         updateWrapper.eq(Appliances::getId,a.getId()); | 
|         updateWrapper.set(Appliances::getUpdateTime,a.getUpdateTime()); | 
|         updateWrapper.set(Appliances::getUpdateUser,a.getUpdateUser()); | 
|         updateWrapper.set(Appliances::getNum,a.getNum()); | 
|         updateWrapper.set(Appliances::getPositionType,a.getPositionType()); | 
|         updateWrapper.set(Appliances::getStatus,a.getStatus()); | 
|         updateWrapper.set(Appliances::getWorkorderId,a.getWorkorderId()); | 
|         updateWrapper.set(Appliances::getWarehouseId,a.getWarehouseId()); | 
|         updateWrapper.set(Appliances::getMaterialId,a.getMaterialId()); | 
|         updateWrapper.set(Appliances::getCurObjId,a.getCurObjId()); | 
|         updateWrapper.set(Appliances::getCurObjType,a.getCurObjType()); | 
|         updateWrapper.set(Appliances::getLocationId,a.getLocationId()); | 
|         updateWrapper.set(Appliances::getNextProcedureId,a.getNextProcedureId()); | 
|         updateWrapper.set(Appliances::getProcedureId,a.getProcedureId()); | 
|         updateWrapper.set(Appliances::getBatch,a.getBatch()); | 
|         updateWrapper.set(Appliances::getRelobjType,a.getRelobjType()); | 
|         updateWrapper.set(Appliances::getSaleorderId,a.getSaleorderId()); | 
|         updateWrapper.set(Appliances::getBackorderId,a.getBackorderId()); | 
|         updateWrapper.set(Appliances::getQualityType,a.getQualityType()); | 
|         appliancesExtMapper.update(a,updateWrapper); | 
|     } | 
|   | 
|     private boolean existsInProlist(Integer id, List<Appliances> updateApplianceProList) { | 
|         for(Appliances a : updateApplianceProList){ | 
|             if(Constants.equalsInteger(id,a.getId())){ | 
|                 return true; | 
|             } | 
|         } | 
|         return  false; | 
|     } | 
|   | 
|     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 boolean isRouteLastProcudureId(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){ | 
|             if(Constants.equalsInteger(rpList.get(rpList.size()-1).getProcedureId(),proceduresId)){ | 
|                 //检查是否最后一道工序 | 
|                  return true; | 
|             } | 
|         } | 
|         return false; | 
|     } | 
|     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)){ | 
|                 //如果是产出 | 
|                 mp.setHasProduceNum(Constants.formatBigdecimal(tModel.getNum()).intValue()+Constants.formatIntegerNum(mp.getHasProduceNum())); | 
|                 if(tModel.getAmodel() == null){ | 
|                     continue; | 
|                 } | 
|                 if(tModel.getDoneType() == null){ | 
|                     throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,工装器具【"+tModel.getAmodel().getCode()+"】产出质量属性为空,无法报工!"); | 
|                 } | 
|                 if(!Constants.equalsInteger(tModel.getDoneType(),Constants.ZERO)){ | 
|                     //如果不良,累计工单的不良产出 | 
|                     mp.setUnqualifiedNum(Constants.formatIntegerNum(mp.getUnqualifiedNum())+(Constants.formatBigdecimal(tModel.getNum()).intValue())); | 
| //                    mp.setUnqualifiedNum(mp.getUnqualifiedNum().add(tModel.getNum())); | 
|                 }else{ | 
|                     //如果是合格,累计工单的合格数量 | 
|                     mp.setQualifiedNum(Constants.formatIntegerNum(mp.getQualifiedNum())+(Constants.formatBigdecimal(tModel.getNum()).intValue())); | 
| //                    mp.setUnqualifiedNum(mp.getQualifiedNum().add(tModel.getNum())); | 
|                 } | 
|                 //检查篮筐是否被作为产出篮筐,如果是,则需要判断该篮筐是否投料余额为0 | 
|                 Appliances curUpdateModel = getApplianceFromList(tModel.getAppliancesId(),updateApplianceList); | 
|                 if(curUpdateModel!=null){ | 
|                     if(!Constants.equalsInteger(curUpdateModel.getStatus(),Constants.APPLIANCES_STATUS.empty)){ | 
|                         throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,工装器具【"+tModel.getAmodel().getCode()+"】有工单产出记录,必须清空后才可报工!"); | 
|                     } | 
|                 }else{ | 
|                     if(!Constants.equalsInteger(tModel.getAmodel().getStatus(),Constants.APPLIANCES_STATUS.empty)){ | 
|                         throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,工装器具【"+tModel.getAmodel().getCode()+"】有工单产出记录,必须清空后才可报工!"); | 
|                     } | 
|                 } | 
|                 Appliances aModel = new Appliances(); | 
|                 aModel.setId(tModel.getAppliancesId()); | 
|                 aModel.setUpdateUser(user.getId()); | 
|                 aModel.setUpdateTime(DateUtil.getCurrentDate()); | 
|                 aModel.setNum(tModel.getNum()); | 
|                 //产出走仓库 | 
|                 aModel.setPositionType(Constants.APPLIANCES_POSITION.warehouse); | 
|                 //篮筐有东西 | 
|                 aModel.setStatus(Constants.APPLIANCES_STATUS.full); | 
|                 aModel.setWorkorderId(mp.getId()); | 
|                 aModel.setMaterialId(mp.getMaterialId()); | 
|                 aModel.setCurObjId(tModel.getId()); | 
|                 aModel.setCurObjType(Constants.ONE); | 
|                 aModel.setWarehouseId(mp.getFinishWarehouseId()); | 
|                 aModel.setLocationId(mp.getFinishWarehouseLocationId()); | 
|                 aModel.setRelobjType(Constants.RELOBJ_TYPE.workorder); | 
|                 aModel.setQualityType(tModel.getDoneType()); | 
|                 aModel.setBatch(tModel.getBatch()); | 
|                 aModel.setProcedureId(tModel.getProcedureId()); | 
|                 aModel.setBackProcedureId(null); | 
|                 aModel.setBackorderId(null); | 
|                 aModel.setSaleorderId(null); | 
|                 aModel.setNextProcedureId(getNextProcudureId(tModel.getProcedureId(),mp)); | 
|   | 
|                 updateApplianceProList.add(aModel); | 
|   | 
|                 //物料+批次+工序+质量属性去重 | 
|                 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.getMaterialProcedureId()); | 
|                     detail.setMaterialId(tModel.getMaterialId()); | 
|                     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.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.getMaterialDonetype(),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.getMaterialDonetype()); | 
|                     //待更新库存信息 | 
|                     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 WOutboundDetail getWoutbondDetailByList(WorkorderRecordExtListVO tModel, List<WOutboundDetail> detailList) { | 
|         for(WOutboundDetail detail : detailList){ | 
|             if(Constants.equalsInteger(detail.getProcedureId(),tModel.getMaterialProcedureId()) | 
|                 && StringUtils.equals(detail.getBatch(),tModel.getMaterialBatch()) | 
|                 && Constants.equalsInteger(detail.getMaterialId(),tModel.getMaterialId()) | 
|                 && Constants.equalsInteger(detail.getQualityType(),tModel.getMaterialDonetype())){ | 
|                 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; | 
|     } | 
|   | 
|     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){ | 
|                 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; | 
|                         } | 
|                         //更新已经投料数量 | 
|                         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; | 
|                         } | 
|                     } | 
|                 } | 
|             } | 
|         } | 
|     } | 
|   | 
|     private WOutbound getFromOutboundList(Integer warehouseId, List<WOutbound> outboundList) { | 
|         for(WOutbound o : outboundList){ | 
|             if(Constants.equalsInteger(warehouseId,o.getWarehouseId())){ | 
|                 return o; | 
|             } | 
|         } | 
|         return null; | 
|     } | 
|   | 
|     private WStock initMaterialNum(Integer materialId, BigDecimal num) { | 
|         WStock s = new WStock(); | 
|         s.setMaterialId(materialId); | 
|         //1:1投料 | 
|         s.setNum(num); | 
|         return s; | 
|     } | 
|   | 
|     private void   dealApplianceMateial(Workorder mp | 
|             , LoginUserInfo user | 
|             , List<WorkorderRecordExtListVO> allRecordList | 
|             , List<Appliances> updateApplianceList | 
|             , 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.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()))); | 
|                 if(tModel.getAmodel()==null){ | 
|                     continue; | 
|                 } | 
|                 if(!Constants.equalsInteger(tModel.getAmodel().getLocationId(),mp.getProduceWarehouseLocationId())){ | 
|                     throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,器具【"+tModel.getAmodel().getCode()+"】装载物料信息必须来自工单待生产机台货位!"); | 
|                 } | 
|                 //剩余数量 | 
|                 BigDecimal aNum = Constants.formatBigdecimal(tModel.getAmodel().getNum()).subtract(Constants.formatBigdecimal(tModel.getNum())); | 
|                 Appliances aModel = new Appliances(); | 
|                 aModel.setId(tModel.getAppliancesId()); | 
|                 aModel.setUpdateUser(user.getId()); | 
|                 aModel.setUpdateTime(DateUtil.getCurrentDate()); | 
|                 if(aNum.compareTo(new BigDecimal(0)) < 0){ | 
|                     throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,器具【"+tModel.getAmodel().getCode()+"】内数量小于投料数量!"); | 
|                 } | 
|                 aModel.setNum(aNum); | 
|                 //投料走车间 | 
|                 aModel.setPositionType(Constants.APPLIANCES_POSITION.workshop); | 
|                 if(aNum.compareTo(new BigDecimal(0)) == 0){ | 
|                     //如果剩余数量为0,清空篮筐 | 
|                     aModel.setStatus(Constants.APPLIANCES_STATUS.empty); | 
|                     aModel.setWorkorderId(null); | 
|                     aModel.setMaterialId(null); | 
|                     aModel.setProcedureId(null); | 
|                     aModel.setCurObjId(null); | 
|                     aModel.setCurObjType(null); | 
|                     aModel.setWarehouseId(null); | 
|                     aModel.setLocationId(null); | 
|                     aModel.setQualityType(null); | 
|                     aModel.setNextProcedureId(null); | 
|                     aModel.setSaleorderId(null); | 
|                     aModel.setBackorderId(null); | 
|                     aModel.setRelobjType(null); | 
|                     if(Constants.equalsInteger(mp.getType(),Constants.WORKORDER_TYPE.normal)){ | 
|                         //正常工单,清楚批次号 | 
|                         aModel.setBatch(null); | 
|                     } | 
|                 }else{ | 
|                     aModel.setProcedureId(tModel.getAmodel().getProcedureId()); | 
|                     aModel.setStatus(tModel.getAmodel().getStatus()); | 
|                     aModel.setWorkorderId(tModel.getAmodel().getWorkorderId()); | 
|                     aModel.setMaterialId(tModel.getAmodel().getMaterialId()); | 
|                     aModel.setCurObjId(tModel.getAmodel().getCurObjId()); | 
|                     aModel.setCurObjType(tModel.getAmodel().getCurObjType()); | 
|                     aModel.setWarehouseId(tModel.getAmodel().getWarehouseId()); | 
|                     aModel.setLocationId(tModel.getAmodel().getLocationId()); | 
|                     aModel.setQualityType(tModel.getAmodel().getQualityType()); | 
|                     aModel.setNextProcedureId(tModel.getAmodel().getNextProcedureId()); | 
|                     aModel.setBatch(tModel.getAmodel().getBatch()); | 
|                     aModel.setPositionType(tModel.getAmodel().getPositionType()); | 
|                     aModel.setSaleorderId(tModel.getAmodel().getSaleorderId()); | 
|                     aModel.setBackorderId(tModel.getAmodel().getBackorderId()); | 
|                     aModel.setRelobjType(tModel.getAmodel().getRelobjType()); | 
|   | 
|                     //2022年8月19日18:14:14 修改加入 原有生产工序 | 
|                     aModel.setProcedureId(tModel.getAmodel().getProcedureId()); | 
|                 } | 
|                 updateApplianceList.add(aModel); | 
|                 //物料+批次+工序+质量属性去重 | 
|                 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(); | 
|                /* 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.setWarehouseId(outbound.getWarehouseId()); | 
|                 detail.setLocationId(mp.getProduceWarehouseLocationId()); | 
|                 detail.setNum(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()); | 
| //                outboundDetailList.add(detail); | 
|                 wOutboundDetailExtMapper.insert(detail);*/ | 
|                 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); | 
|                 WStock stock = getFromStockList(mp.getProduceWarehouseLocationId(),detail.getWarehouseId(),detail.getMaterialId(),detail.getBatch(),tModel.getAmodel().getProcedureId(),tModel.getAmodel().getQualityType(),stockList); | 
|                 if(stock!=null){ | 
|                     //如果库存对象已存在,直接减少对应的库存量 | 
|                     stock.setNum(Constants.formatBigdecimal(stock.getNum()).subtract(Constants.formatBigdecimal(tModel.getNum()))); | 
|                 }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); | 
|             //记录库存变动记录 | 
|             wStockRecordExtService.saveRecord(Constants.ZERO,detail.getId(),user); | 
|             if(detail.getWOutboundRecordInList()!=null){ | 
|                 for(WOutboundRecord r : detail.getWOutboundRecordInList()){ | 
|                     r.setDetailId(detail.getId()); | 
|                     wOutboundRecordExtMapper.insert(r); | 
|                 } | 
|             } | 
|         } | 
|     } | 
|   | 
|     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 int caculateCheckRecord(LoginUserInfo user | 
|             , Workorder mp | 
|             ,List<WorkorderRecordExtListVO>  allRecordList ) { | 
|         if(Constants.equalsInteger(mp.getIscalculate(),Constants.ONE)){ | 
|             //如果不需要报工计算不合格品,不作任何处理 | 
|             return 0; | 
|         } | 
|         //否则查询检验数据 | 
|         int cNum=0; | 
|         WorkorderCheck cParam = new WorkorderCheck(); | 
|         cParam.setWorkorderId(mp.getId()); | 
|         cParam.setDeleted(Constants.ZERO); | 
|         //查询工单全部检验记录 | 
|         List<WorkorderCheck> checkList = workorderCheckExtMapper.selectGroupList(cParam); | 
|         if(checkList!= null && checkList.size()>0){ | 
|             for(WorkorderCheck wc : checkList){ | 
|                 //不合格数量(包含不良和报废品数量) | 
|                 cNum+= Constants.formatIntegerNum(wc.getUnqualifiedNum()); | 
|                 if(Constants.formatIntegerNum(wc.getUnqualifiedNum())>0){ | 
|                     //如果有报废或者不合格,走工单报工 | 
|                     WorkorderRecord r = getWorkrecordProModel(user,wc.getQualifiedApplianceId(),mp,new BigDecimal(Constants.formatIntegerNum(wc.getUnqualifiedNum())) ,Constants.ONE); | 
| //                    checkRecordList.add(r); | 
|                     //插入产出数据 | 
|                     workorderRecordExtMapper.insert(r); | 
|                     WorkorderRecordExtListVO r1 = new WorkorderRecordExtListVO(); | 
|                     BeanUtils.copyProperties(r,r1); | 
|                     r1.setAmodel(appliancesExtMapper.selectById(r1.getAppliancesId())); | 
|                     if(allRecordList == null){ | 
|                         allRecordList = new ArrayList<>(); | 
|                     } | 
|                     //附加到全部产品记录中 | 
|                     allRecordList.add(r1); | 
|                 } | 
|             } | 
|         } | 
|         return cNum; | 
|     } | 
|   | 
|     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()); | 
|            /* if(order.getHasProduceNum()>=Constants.formatIntegerNum(mp.getTotalPlanNum())){ | 
|                 //如果计划数量已经完成,则更新计划的数据状态 | 
|                 Plans model = new Plans(); | 
|                 model.setId(mp.getPlanId()); | 
|                 //检查数据有效性 | 
|                 model.setUpdateTime(DateUtil.getCurrentDate()); | 
|                 model.setUpdateUser(user.getId()); | 
|                 model.setStatus(Constants.PLAN_STATUS.publish); | 
|                 model.setRootDepartId(mp.getRootDepartId()); | 
|                 model.setDepartId(mp.getDepartId()); | 
|                 //更新计划数据 | 
|                 plansExtMapper.updateById(model); | 
|                 //历史数据,关闭 | 
|                 planHistoryExtMapper.insert(PlansExtServiceImpl.initHistoryByModel(model,user.getId(),Constants.PLANHISTORY_TYPE.done)); | 
|   | 
|             }*/ | 
|         }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.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); | 
|     } | 
|   | 
|     /** | 
|      * 投料批量删除 | 
|      * @param idList | 
|      * @return | 
|      */ | 
|     @Transactional(rollbackFor = {BusinessException.class,Exception.class}) | 
|     @Override | 
|     public  void deleteByIdInBatch(List<Integer> idList){ | 
|          for(Integer id : idList){ | 
|              this.deleteById(id); | 
|          } | 
|     } | 
|   | 
|     /** | 
|      *  如果没有bom配置 直接投自己,只能从工单上设备关联的待生产机台货位投料 | 
|      * @param user | 
|      * @param amodel | 
|      * @param mp | 
|      */ | 
|     private void isValideApplianceNum(BigDecimal pNum,LoginUserInfo user,AppliancesExtListVO amodel, 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(amodel.getNum()))>0){ | 
|             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,器具【"+/*pName+*/amodel.getCode()+"】提交数据不合法!"); | 
|         } | 
|         if(!Constants.equalsInteger(amodel.getMaterialId(),mp.getMaterialId())){ | 
|             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,器具【"+/*pName+*/amodel.getCode()+"】装载物料信息不符合工单投料要求!"); | 
|         } | 
|         if(!Constants.equalsInteger(amodel.getLocationId(),mp.getProduceWarehouseLocationId())){ | 
|             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,器具【"+/*pName+*/amodel.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 BomDetail isBomMaterialed(  Workorder mp)  throws BusinessException{ | 
|         BomDetail  bom = new BomDetail(); | 
|         bom.setDeleted(Constants.ZERO); | 
|         bom.setMaterialId(mp.getMaterialId()); | 
|         return bomDetailExtMapper.selectOne(new QueryWrapper<>(bom).exists(" select c.id from bom_version b left join bom c on b.bom_id=c.id where bom_detail.bom_id=b.id and c.status=1 and c.deleted=0 limit 1").last(" limit 1")); | 
|     } | 
|     private WorkorderRecord getWorkrecordModel(LoginUserInfo user, AppliancesExtListVO amodel, Workorder mp,BigDecimal pNum) { | 
|         WorkorderRecord wrModel = new WorkorderRecord(); | 
|         wrModel.setWorkorderId(mp.getId()); | 
|         wrModel.setDeleted(Constants.ZERO); | 
|         wrModel.setRootDepartId(mp.getRootDepartId()); | 
|         wrModel.setMaterialId(amodel.getMaterialId()); | 
|         wrModel.setDepartId(mp.getDepartId()); | 
|         wrModel.setCreateTime(DateUtil.getCurrentDate()); | 
|         wrModel.setCreateUser(user.getId()); | 
|         wrModel.setAppliancesId(amodel.getId()); | 
|         wrModel.setMaterialBatch(amodel.getBatch()); | 
|         wrModel.setType(Constants.WORKORDER_RECORD_TYPE.materail); | 
|         wrModel.setFactoryId(mp.getFactoryId()); | 
|         wrModel.setProcedureId(mp.getProcedureId()); | 
|         wrModel.setBatch(mp.getBatch()); | 
|         wrModel.setUnitId(amodel.getMdmodel().getUnitId()); | 
|         wrModel.setPlanId(mp.getPlanId()); | 
|         wrModel.setMaterialDonetype(amodel.getQualityType()); | 
|         wrModel.setMaterialProcedureId(amodel.getProcedureId()); | 
|         wrModel.setNum(pNum); | 
|         wrModel.setRelobjType(amodel.getRelobjType()); | 
|         wrModel.setRelobjId(amodel.getWorkorderId()); | 
|         return wrModel; | 
|     } | 
|     private WorkorderRecord getWorkrecordProModel(LoginUserInfo user, Integer applianceId, Workorder mp,BigDecimal pNum,Integer doneType ) { | 
|         WorkorderRecord wrModel = new WorkorderRecord(); | 
|         wrModel.setWorkorderId(mp.getId()); | 
|         wrModel.setDeleted(Constants.ZERO); | 
|         wrModel.setMaterialId(mp.getMaterialId()); | 
|         wrModel.setRootDepartId(mp.getRootDepartId()); | 
|         wrModel.setDepartId(mp.getDepartId()); | 
|         wrModel.setCreateTime(DateUtil.getCurrentDate()); | 
|         wrModel.setCreateUser(user.getId()); | 
|         wrModel.setAppliancesId(applianceId); | 
|         wrModel.setProcedureId(mp.getProcedureId()); | 
|         if(Constants.equalsInteger(mp.getType(),Constants.WORKORDER_TYPE.repair)){ | 
|             //如果是返工返修工单,工序为返工返修申请的产生工序 | 
|             Backorder order  = backorderMapper.selectById(mp.getBackorderId()); | 
|             if(order !=null){ | 
|                 wrModel.setProcedureId(order.getProcedureId()); | 
|             } | 
|         } | 
|         wrModel.setMaterialBatch(mp.getBatch()); | 
|         wrModel.setType(Constants.WORKORDER_RECORD_TYPE.produce); | 
|         wrModel.setFactoryId(mp.getFactoryId()); | 
|         wrModel.setBatch(mp.getBatch()); | 
|         wrModel.setUnitId(mp.getUnitId()); | 
|         wrModel.setPlanId(mp.getPlanId()); | 
|         wrModel.setNum(pNum); | 
|         wrModel.setProDate(mp.getPlanDate()); | 
|         wrModel.setDoneType(doneType); | 
|         wrModel.setMaterialProcedureId(mp.getProcedureId()); | 
|         wrModel.setMaterialDonetype(doneType); | 
|         return wrModel; | 
|     } | 
|   | 
|     private void updateOrderInfo2(LoginUserInfo user, Workorder mp) { | 
|         List<WorkorderHistory> whList = new ArrayList<>(); | 
|         //工单历史数据 | 
|         Workorder order = new Workorder(); | 
|         order.setUpdateTime(DateUtil.getCurrentDate()); | 
|         order.setUpdateUser(user.getId()); | 
|         order.setRootDepartId(mp.getRootDepartId()); | 
|         order.setDepartId(mp.getDepartId()); | 
|         order.setStatus(Constants.WORKORDER_STATUS.material); | 
|         /*if(Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.create)){ | 
|             //如果当前状态为已分配,则更新为已投料 | 
|             workorderExtMapper.updateById(order); | 
|         }*/ | 
|         whList.add(WorkorderExtServiceImpl.initHistoryByModel(order,user.getId(),Constants.WORKORDER_HISTORY_STATUS.material)); | 
|         workorderHistoryExtMapper.insertBatch(whList); | 
|     } | 
|   | 
|     private QueryAppliancesExtDTO initApplianceParam(LoginUserInfo user,Integer backorderId, List<MaterialListDTO> apList) { | 
|         QueryAppliancesExtDTO appliancesExtDTO =   new QueryAppliancesExtDTO(); | 
|         appliancesExtDTO.setDeleted(Constants.ZERO); | 
|         appliancesExtDTO.setRootDepartId(user.getRootDepartment().getId()); | 
|         appliancesExtDTO.setDepartId(user.getComDepartment().getId()); | 
|         appliancesExtDTO.setBackorderId(backorderId); | 
|         appliancesExtDTO.setRecordList(apList); | 
|         return appliancesExtDTO; | 
|   | 
|     } | 
|   | 
|     private Workorder getOrderAndValid(LoginUserInfo user, CreateMaterialDTO param)  throws  BusinessException{ | 
|         if(param.getId()== null||param.getRecordList()==null || param.getRecordList().size()==0){ | 
|             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(), "对不起,该记录不存在!"); | 
|         } | 
|         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 isValideApplianceNum(BigDecimal pNum, LoginUserInfo user, AppliancesExtListVO amodel, Workorder mp, List<BomDetailExtListVO> bomDetailList) throws BusinessException { | 
| //        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(amodel.getNum()))>0){ | 
|             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,器具【"+/*pName+*/amodel.getCode()+"】提交数据不合法!"); | 
|         } | 
|         if(!Constants.equalsInteger(amodel.getLocationId(),mp.getProduceWarehouseLocationId())){ | 
|             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,器具【"+/*pName+*/amodel.getCode()+"】装载物料信息必须来自工单待生产机台货位!"); | 
|         } | 
|         //获取该物料的组成部分 | 
|         BomDetailExtListVO detial =getBomMaterial(amodel.getMaterialId(),bomDetailList); | 
|         if(detial == null){ | 
|             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,器具【"+/*pName+*/amodel.getCode()+"】装载物料非BOM组成物料!"); | 
|         } | 
|   | 
|         /* | 
|         //如果bom需求数量已经满足,不需求再投料 | 
|         if(detial.getNum().compareTo(pNum.add(detial.getWorkorderNum()))<0){ | 
|             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,器具【"+pName+amodel.getCode()+"】装载投料数量已超出需求!"); | 
|         }*/ | 
|     } | 
|   | 
|     private BomDetailExtListVO getBomMaterial(Integer materialId, List<BomDetailExtListVO> bomDetailList) { | 
|         for(BomDetailExtListVO d : bomDetailList){ | 
|             if(Constants.equalsInteger(materialId,d.getMaterialId())){ | 
|                 return d; | 
|             } | 
|         } | 
|         return null; | 
|     } | 
|   | 
|     /** | 
|      * 获取工作器具提交的投料数量 | 
|      * @param id | 
|      * @param apList | 
|      * @return | 
|      */ | 
|     private BigDecimal getNumFromParam(Integer id, List<MaterialListDTO> apList) { | 
|         for(MaterialListDTO l : apList){ | 
|             if(Constants.equalsInteger(id,l.getApplianceId())){ | 
|                 return l.getNum(); | 
|             } | 
|         } | 
|         return BigDecimal.ZERO; | 
|     } | 
|   | 
|     /** | 
|      * 初始化请求数据 | 
|      * @param param | 
|      * @return | 
|      */ | 
|     private List<MaterialListDTO> initApParamList(CreateMaterialDTO param  ) { | 
|         List<MaterialListDTO> list = new ArrayList<>(); | 
|         for(MaterialListDTO l : param.getRecordList()){ | 
|   | 
|             MaterialListDTO temp =    existsInlist(l.getApplianceId(),list); | 
|             if(temp == null){ | 
|                 list.add(l); | 
|             }else{ | 
|                 //如果扫码重复,则累加数量 | 
|                 temp.setNum( temp.getNum().add(l.getNum())); | 
|             } | 
|         } | 
|         return list; | 
|     } | 
|   | 
|     private MaterialListDTO existsInlist(Integer applianceId, List<MaterialListDTO> list) { | 
|         for(MaterialListDTO l : list){ | 
|             if(Constants.equalsInteger(applianceId,l.getApplianceId())){ | 
|                return l; | 
|             } | 
|         } | 
|         return null; | 
|     } | 
|   | 
|   | 
|     @Override | 
|     public EndCheckApBean getWOutboundRecordAp(String workOrderId , String appliancesId ){ | 
|         EndCheckApBean endCheckApBean = wOutboundRecordExtMapper.getWOutboundRecordAp(workOrderId,appliancesId); | 
|         if(Objects.isNull(endCheckApBean)){ | 
|             throw new BusinessException(ResponseStatus.OBJECT_EMP.getCode(), "对不起,未查询到产出记录!"); | 
|         } | 
|        return  endCheckApBean; | 
|     } | 
|   | 
|   | 
|     @Override | 
|     public void exportUserSalary(PageWrap<QueryUserSalaryListDTO> pageWrap, HttpServletResponse response) { | 
|         List<UserSalaryListVO> result=this.userSalaryPage(pageWrap).getRecords(); | 
|         for(UserSalaryListVO model : result) { | 
|             if(model.getUserInfo()!=null){ | 
|                 model.setUserName(model.getUserInfo().getUserName()); | 
|                 model.setDepartName(model.getUserInfo().getDepartName()); | 
|                 model.setNum(Constants.formatBigdecimalFloat(model.getNum(),2)); | 
|                 model.setQualifiedNum(Constants.formatBigdecimalFloat(model.getQualifiedNum(),2)); | 
|                 model.setUnQualifiedNum(Constants.formatBigdecimalFloat(model.getUnQualifiedNum(),2)); | 
|                 model.setRate(Constants.formatBigdecimalFloat(model.getRate(),2)); | 
|             } | 
|         } | 
|         ExcelExporter.build(UserSalaryListVO.class).export(result, "员工绩效明细"+System.currentTimeMillis(), response); | 
|     } | 
|     @Override | 
|     public void exportSalaryStatistics(PageWrap<QuerySalaryStatisticDTO> pageWrap, HttpServletResponse response){ | 
|         List<SalaryStatisticsListVO> result=this.salaryStatistic(pageWrap).getRecords(); | 
|         for(SalaryStatisticsListVO model : result) { | 
|             if(model.getUserInfo()!=null){ | 
|                 model.setUserName(model.getUserInfo().getUserName()); | 
|                 model.setDepartName(model.getUserInfo().getDepartName()); | 
|             } | 
|         } | 
|         ExcelExporter.build(SalaryStatisticsListVO.class).export(result, "工资报表"+System.currentTimeMillis(), response); | 
|   | 
|     } | 
|     @Override | 
|     public void exportExcel(PageWrap<QueryWorkorderRecordExtDTO> pageWrap, HttpServletResponse response) { | 
|         List<WorkorderRecordExtListVO> result=this.findPage(pageWrap).getRecords(); | 
|         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); | 
|         List<WorkorderRecordExportExtListVO> list=new ArrayList<>(); | 
|         for(int i=0;i<result.size();i++) { | 
|             WorkorderRecordExtListVO re = result.get(i); | 
|             WorkorderRecordExportExtListVO wreev = new WorkorderRecordExportExtListVO(); | 
|             if (re.getOmodel() != null) { | 
|                 wreev.setWorkordercode(re.getOmodel().getCode()); | 
|                 if (re.getOmodel().getStatus() != null) { | 
|                     String status = Constants.WORKORDER_STATUS.getTitleByStatus(null, re.getOmodel().getStatus()); | 
|                     wreev.setStatus(status); | 
|                 } | 
|             } | 
|             if (re.getMmodel() != null) { | 
|                 wreev.setMaterialcode(re.getMmodel().getCode()); | 
|                 wreev.setMaterialname(re.getMmodel().getName()); | 
|             } | 
|   | 
|             wreev.setBatch(re.getBatch()); | 
|             if (re.getPromodel() != null) { | 
|                 wreev.setProceduresname(re.getPromodel().getName()); | 
|             } | 
|   | 
|             String unintname = ""; | 
|             if (re.getUmodel() != null) { | 
|                 unintname = re.getUmodel().getName(); | 
|             } | 
|             if (re.getPmodel() != null) { | 
|                 BigDecimal pmodelnum = re.getNum() != null ? re.getNum() : new BigDecimal("0"); | 
|                // wreev.setPlanNum( new BigDecimal(pmodelnum).stripTrailingZeros().toPlainString() + unintname); | 
|                 wreev.setPlanNum( re.getNum().stripTrailingZeros().toPlainString()+unintname); | 
|             } | 
|                 wreev.setProcedureName(re.getProcedureName()); | 
|                 wreev.setUnintname(unintname); | 
|                 if(re.getNum()!=null){ | 
|                     wreev.setAppliancenum(re.getNum().stripTrailingZeros().toPlainString()+unintname ); | 
|                 } | 
|   | 
|   | 
|                 if (re.getAmodel() != null) { | 
|                     wreev.setAppliancecode(re.getAmodel().getCode()); | 
|                 } | 
|   | 
|                 wreev.setDeviceCode(re.getDeviceCode()+"|"+re.getDeviceName()); | 
|                 wreev.setCreateTime(format.format(re.getCreateTime())); | 
|                 wreev.setQualifiedNum(re.getQualifiedNum()+unintname); | 
|                 wreev.setUnqualifiedNum(re.getUnqualifiedNum()+unintname); | 
|                 wreev.setDuration(re.getDuration()); | 
|                 list.add(wreev); | 
|   | 
|         } | 
|         ExcelExporter.build(WorkorderRecordExportExtListVO.class).export(list, "生产产出明细"+System.currentTimeMillis(), response); | 
|   | 
|        // EasyExcelUtil.exportExcel(list, "工单生产过程记录","工单生产过程记录",WorkorderRecordExportExtListVO.class,"工单生产过程记录"+System.currentTimeMillis()+".xls", response); | 
|     } | 
|   | 
|     @Override | 
|     public void exportExcel2(PageWrap<QueryWorkorderRecordExtDTO> pageWrap, HttpServletResponse response) { | 
|   | 
|         List<WorkorderRecordExtListVO> result=this.findPage(pageWrap).getRecords(); | 
|         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); | 
|         List<WorkorderRecordBathExportExtListVO> list=new ArrayList<>(); | 
|         for(int i=0;i<result.size();i++) { | 
|             WorkorderRecordExtListVO re = result.get(i); | 
|             WorkorderRecordBathExportExtListVO wreev = new WorkorderRecordBathExportExtListVO(); | 
|             if (re.getOmodel() != null) { | 
|                 wreev.setWorkordercode(re.getOmodel().getCode()); | 
|                 if (re.getOmodel().getStatus() != null) { | 
|                     String status = Constants.WORKORDER_STATUS.getTitleByStatus(null, re.getOmodel().getStatus()); | 
|                     wreev.setStatus(status); | 
|                 } | 
|             } | 
|             if (re.getMmodel() != null) { | 
|                 wreev.setMaterialcode(re.getMmodel().getCode()); | 
|                 wreev.setMaterialname(re.getMmodel().getName()); | 
|             } | 
|   | 
|             wreev.setBatch(re.getBatch()); | 
|             if (re.getPromodel() != null) { | 
|                 wreev.setProceduresname(re.getPromodel().getName()); | 
|             } | 
|   | 
|             String unintname = ""; | 
|             if (re.getUmodel() != null) { | 
|                 unintname = re.getUmodel().getName(); | 
|             } | 
|             if (re.getNum() != null) { | 
|                 BigDecimal pmodelnum = re.getNum() != null ? re.getNum() : new BigDecimal("0"); | 
|                 // wreev.setPlanNum( new BigDecimal(pmodelnum).stripTrailingZeros().toPlainString() + unintname); | 
|                 wreev.setNum( pmodelnum.stripTrailingZeros().toPlainString()+unintname); | 
|             } | 
|             wreev.setProcedureName(re.getProcedureName()); | 
|             wreev.setUnintname(unintname); | 
|             if(re.getOmodel().getPlanNum() != null){ | 
|                 wreev.setPlanNum(re.getOmodel().getPlanNum()+unintname ); | 
|             } | 
|             wreev.setMaterialDonetype(re.getMaterialDonetype()); | 
|             wreev.setDeviceCode(re.getDeviceCode()+"|"+re.getDeviceName()); | 
|             wreev.setCreateTime(format.format(re.getCreateTime())); | 
|             list.add(wreev); | 
|   | 
|         } | 
|         ExcelExporter.build(WorkorderRecordBathExportExtListVO.class).export(list, "生产投料明细"+System.currentTimeMillis(), response); | 
|   | 
|     } | 
| } |