package doumeemes.service.ext.impl; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import doumeemes.biz.system.impl.SystemDictDataBizImpl; import doumeemes.core.exception.BusinessException; import doumeemes.core.model.ApiResponse; import doumeemes.core.model.LoginUserInfo; import doumeemes.core.model.PageData; import doumeemes.core.model.PageWrap; import doumeemes.core.utils.Constants; import doumeemes.core.utils.excel.EasyExcelUtil; import doumeemes.core.utils.redis.RedisUtil; import doumeemes.dao.business.model.*; import doumeemes.dao.ext.AppliancesExtMapper; import doumeemes.dao.ext.dto.QueryAppliancesByManualDTO; import doumeemes.dao.ext.dto.QueryAppliancesExtDTO; import doumeemes.dao.ext.vo.AppliancesExtListVO; import doumeemes.dao.ext.vo.CategoryExtListVO; import doumeemes.dao.system.model.SystemDictData; import doumeemes.service.business.AppliancesService; import doumeemes.service.business.BarcodeParamService; import doumeemes.service.business.impl.*; import doumeemes.service.ext.AppliancesExtService; import doumeemes.service.system.impl.SystemDictDataServiceImpl; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.SecurityUtils; 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 org.springframework.web.multipart.MultipartFile; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.stream.Collectors; /** * 工装器具信息Service实现 * @author 江蹄蹄 * @date 2022/04/20 11:01 */ @Service public class AppliancesExtServiceImpl implements AppliancesExtService { @Autowired private RedisTemplate redisTemplate; @Autowired private AppliancesExtMapper appliancesExtMapper; @Autowired private AppliancesService appliancesService; @Autowired private BarcodeParamService barcodeParamService; @Autowired private SystemDictDataBizImpl systemDictDataBizimpl; @Autowired private AppliancesServiceImpl appliancesServiceimpl; @Autowired private WorkorderServiceImpl workorderServiceimpl; @Autowired private WorkorderRecordServiceImpl workorderRecordServiceimpl; @Autowired private SystemDictDataServiceImpl systemDictDataServiceimpl; @Autowired private ApplianceChangeServiceImpl applianceChangeServiceimpl; @Autowired private ApplianceChangeDetialServiceImpl applianceChangeDetialServiceimpl; @Override public PageData findPage(PageWrap pageWrap) { LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); pageWrap.getModel().setDeleted(Constants.ZERO); pageWrap.getModel().setRootDepartId(user.getRootDepartment().getRootId()); pageWrap.getModel().setDepartId(user.getCurComDepartment().getId()); PageHelper.startPage(pageWrap.getPage(), pageWrap.getCapacity()); List result = appliancesExtMapper.selectListByCondition(pageWrap.getModel()); List clist = RedisUtil.getObject(redisTemplate,Constants.RedisKeys.COM_CATEGORY_KEY+user.getCompany().getId(), ArrayList.class); for(int i=0;i(result)); } @Override public AppliancesExtListVO findMaxSerial(QueryAppliancesExtDTO pageWrap) { AppliancesExtListVO result = appliancesExtMapper.findMaxSerial(pageWrap); return result; } @Override @Transactional(rollbackFor = {BusinessException.class,Exception.class}) public ApiResponse importExcel(MultipartFile file, String categoryId) { LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); //获取二维码规则 BarcodeParam queryparam=new BarcodeParam(); queryparam.setDepartId(user.getCurComDepartment().getId()); queryparam.setRootDepartId(user.getRootDepartment().getId()); queryparam.setType(Constants.BARCODEPARAM_TYPE.appliance); BarcodeParam barcodeParam =barcodeParamService.findOne(queryparam); if(barcodeParam==null){ return ApiResponse.failed("请先完善二维码篮筐配置"); } List alllist = EasyExcelUtil.importExcel(file, 1, 1, Appliances.class); // List alllist = ExcelExporter.build(Appliances.class).readExcel(null, Appliances.class, file); if(StringUtils.isEmpty(categoryId)){ return ApiResponse.failed("工装类型不能为空"); } //查询编码是否存在 try{ for(int i=0;i dicList= systemDictDataBizimpl.queryDataByCode("SYSTEM_APPLIANCE_TYPE",chriApp.getTypeName()); if(dicList==null||dicList.size()<=0){ throw new RuntimeException("工装属性不存在"); } Appliances query1=new Appliances(); query1.setDeleted(Constants.ZERO); // query1.setCategoryId(Integer.valueOf(categoryId)); query1.setDepartId(user.getCurComDepartment().getId()); query1.setRootDepartId(user.getRootDepartment().getId()); query1.setCode(chriApp.getCode()); List queryData1= appliancesService.findList(query1); if(queryData1.size()>0){ throw new RuntimeException(chriApp.getCode()+"编码已存在,不允许插入"); } //获取工装属性 Appliances appliances=new Appliances(); appliances.setBrcode(barcodeParam.getId()); appliances.setDeleted(Constants.ZERO); appliances.setDepartId(user.getCurComDepartment().getId()); appliances.setRootDepartId(user.getRootDepartment().getId()); appliances.setCreateUser(user.getId()); appliances.setCreateTime(new Date()); appliances.setStatus(Constants.APPLIANCES_STATUS.empty); appliances.setCategoryId(Integer.valueOf(categoryId)); appliances.setType(dicList.get(0).getId()); appliances.setCode(chriApp.getCode()); // appliances.setCategoryId(Integer.valueOf(categoryId)); appliancesService.insertDate(appliances); } }catch (Exception e){ e.printStackTrace(); return ApiResponse.failed(e.getMessage()); } return ApiResponse.success(null); } @Override public List selectListByCondition(QueryAppliancesExtDTO pageWrap) { LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); pageWrap.setDeleted(Constants.ZERO); pageWrap.setRootDepartId(user.getRootDepartment().getRootId()); pageWrap.setDepartId(user.getCurComDepartment().getId()); List result = appliancesExtMapper.selectListByCondition(pageWrap); List clist = RedisUtil.getObject(redisTemplate,Constants.RedisKeys.COM_CATEGORY_KEY+user.getCompany().getId(), ArrayList.class); for(int i=0;i> getApplianceListByCondition(QueryAppliancesExtDTO pageWrap) { LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); pageWrap.setDeleted(Constants.ZERO); pageWrap.setRootDepartId(user.getRootDepartment().getRootId()); pageWrap.setDepartId(user.getCurComDepartment().getId()); List result = appliancesExtMapper.selectListByCondition(pageWrap);//第一个旧篮筐 List clist = RedisUtil.getObject(redisTemplate,Constants.RedisKeys.COM_CATEGORY_KEY+user.getCompany().getId(), ArrayList.class); for(int i=0;i0){ for(int i=0;i0){ for(int j=0;j newappliancelist=new ArrayList<>(); List oldappliancelist=new ArrayList<>(); //查询新篮筐中的数据是否重复 Boolean newappliancerepeat=checkRepeatNewApplianceOrNo(query.getNewList()); if(newappliancerepeat){ return ApiResponse.failed("新工装重复扫描,更换失败!"); } for(int z=0;z0){ for(int newi=0;newi0){ for(int n=0;n0){ for(int n=0;n workrecordList= workorderRecordServiceimpl.findList(workorderRecord); Workorder workorder= workorderServiceimpl.findById(workorderId); if(workorder!=null&&(Constants.equalsInteger(workorder.getStatus(),Constants.WORKORDER_STATUS.create) ||Constants.equalsInteger(workorder.getStatus(),Constants.WORKORDER_STATUS.material) ||Constants.equalsInteger(workorder.getStatus(),Constants.WORKORDER_STATUS.done) ||Constants.equalsInteger(workorder.getStatus(),Constants.WORKORDER_STATUS.check))){ if(workrecordList!=null&&workrecordList.size()>0){ return false; } }else{ return true ;//工单不存在直接跳过判断逻辑 } */ //根据appliance id 查询当前声生产记录里面包含的工单workorderid 的状态是否包含已创建、已备料、已检验、已完工 WorkorderRecord wr=new WorkorderRecord(); wr.setDeleted(Constants.ZERO); wr.setAppliancesId(appliancesId); wr.setRootDepartId(user.getRootDepartment().getId()); wr.setDepartId(user.getCurComDepartment().getId()); // wr.setType(1);//产出 List worList= workorderRecordServiceimpl.findList(wr); if(worList!=null&&worList.size()>0){ for(int i=0;i oldlist){ if(oldlist!=null&&oldlist.size()>0) { Integer materialId=null; Integer nextProcedureId=null; String batch=""; Integer warehouseId=null; Integer locationId=null; for (int i = 0; i < oldlist.size(); i++) { Appliances data = oldlist.get(i); Appliances app = appliancesService.findById(data.getId()); if(i==0){ materialId= app.getMaterialId(); nextProcedureId=app.getNextProcedureId(); batch=app.getBatch(); warehouseId=app.getWarehouseId(); locationId=app.getLocationId(); }else{ if(Constants.equalsInteger(app.getMaterialId(),materialId) &&Constants.equalsInteger(app.getNextProcedureId(),nextProcedureId) &&StringUtils.equals(app.getBatch(),batch) &&Constants.equalsInteger(app.getWarehouseId(),warehouseId) &&Constants.equalsInteger(app.getLocationId(),locationId)){ }else{ return false; } } } } return true; } /** * 如果旧篮筐属性非报废,更换时,需要旧篮筐的物料编码、批次号、质量属性、最近加工工序、返工返修工序、申请单编号(返工返修/报废申请)、客返单号、仓库、库位都相同,才能一起更换; * @param oldlist * @return */ public boolean oldlkFBF(List oldlist){ if(oldlist!=null&&oldlist.size()>0) { Integer materialId=null; String batch=""; Integer qualityType=null; Integer nextProcedureId=null; Integer backProcedureId=null; Integer backorderId=null; Integer saleOrderId=null; Integer warehouseId=null; Integer locationId=null; for (int i = 0; i < oldlist.size(); i++) { Appliances data = oldlist.get(i); Appliances app = appliancesService.findById(data.getId()); if(i==0){ materialId= app.getMaterialId(); nextProcedureId=app.getNextProcedureId(); batch=app.getBatch(); warehouseId=app.getWarehouseId(); locationId=app.getLocationId(); qualityType=app.getQualityType(); backProcedureId= app.getBackProcedureId(); backorderId=app.getBackorderId(); saleOrderId=app.getSaleorderId(); }else{ if(Constants.equalsInteger(app.getMaterialId(),materialId) &&Constants.equalsInteger(app.getNextProcedureId(),nextProcedureId) &&StringUtils.equals(app.getBatch(),batch) &&Constants.equalsInteger(app.getWarehouseId(),warehouseId) &&Constants.equalsInteger(app.getLocationId(),locationId) &&Constants.equalsInteger(app.getQualityType(),qualityType) &&Constants.equalsInteger(app.getBackProcedureId(),backProcedureId) &&Constants.equalsInteger(app.getBackorderId(),backorderId) &&Constants.equalsInteger(app.getSaleorderId(),saleOrderId)){ }else{ return false; } } } } return true; } //查詢新籃筐中的数据是否重复 private Boolean checkRepeatNewApplianceOrNo(List list ) { if(list!=null&&list.size()>1){ List collect1 = list.stream().map(Appliances::getId).distinct().collect(Collectors.toList()); if(collect1.size()!=list.size()){ return true; }else{ return false; } }else { return false; } } /** * 新增更换单记录 * @param olddata * @param user * @return */ public Integer insertApplianceChange(Appliances olddata,LoginUserInfo user){ ApplianceChange applianceChange=new ApplianceChange(); applianceChange.setDeleted(Constants.ZERO); applianceChange.setCreateTime(new Date()); applianceChange.setCreateUser(user.getId()); applianceChange.setRootDepartId(user.getRootDepartment().getId()); applianceChange.setDepartId(user.getCurComDepartment().getId()); applianceChange.setType(olddata.getType()); applianceChange.setWarehouseId(olddata.getWarehouseId()); applianceChange.setLocationId(olddata.getLocationId()); applianceChange.setProcedureId(olddata.getProcedureId()); applianceChange.setSaleorderId(olddata.getSaleorderId()); applianceChange.setBackProcedureId(olddata.getBackProcedureId()); applianceChange.setMaterialId(olddata.getMaterialId()+""); applianceChange.setBatch(olddata.getBatch()); String code=applianceChangeServiceimpl.getNextCode(user.getCompany().getId()); applianceChange.setCode(code); return applianceChangeServiceimpl.create(applianceChange); } /** * 工单记录详情添加 * mark 标记新篮筐1,0旧篮筐 * @param appliances * @param user * @param mark * @return */ public Integer insertApplianceChangedetail(Appliances appliances,LoginUserInfo user,Integer mark,Integer changeid ){ ApplianceChangeDetial applianceChangedetail=new ApplianceChangeDetial(); applianceChangedetail.setDeleted(Constants.ZERO); applianceChangedetail.setCreateTime(new Date()); applianceChangedetail.setCreateUser(user.getId()); applianceChangedetail.setRootDepartId(user.getRootDepartment().getId()); applianceChangedetail.setDepartId(user.getCurComDepartment().getId()); applianceChangedetail.setApplianceId(appliances.getId()); applianceChangedetail.setType(mark); applianceChangedetail.setMaterialId(appliances.getMaterialId()+""); applianceChangedetail.setBatch(appliances.getBatch()); applianceChangedetail.setNum(appliances.getNum().intValue()); applianceChangedetail.setWorkorderId(appliances.getWorkorderId()); applianceChangedetail.setRelobjType(appliances.getRelobjType()); applianceChangedetail.setChaneId(changeid); return applianceChangeDetialServiceimpl.create(applianceChangedetail); } @Override public PageData findListPageForManual(PageWrap pageWrap) { LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); pageWrap.getModel().setRootDepartId(user.getRootDepartment().getRootId()); pageWrap.getModel().setDepartId(user.getCurComDepartment().getId()); PageHelper.startPage(pageWrap.getPage(), pageWrap.getCapacity()); List result = appliancesExtMapper.findListPageForManual(pageWrap.getModel()); return PageData.from(new PageInfo<>(result)); } }