| | |
| | | package com.zy.asrs.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.core.common.BaseRes; |
| | |
| | | import com.zy.asrs.mapper.TagMapper; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.task.AbstractHandler; |
| | | import com.zy.asrs.task.core.ReturnT; |
| | | import com.zy.asrs.utils.MatUtils; |
| | | import com.zy.common.constant.MesConstant; |
| | | import com.zy.asrs.utils.PostMesDataUtils; |
| | | import com.zy.common.model.DetlDto; |
| | | import com.zy.common.model.enums.WorkNoType; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import com.zy.common.utils.NodeUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | @Autowired |
| | | private CommonService commonService; |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | |
| | | @Value("${mes.url}") |
| | | private String mesUrl; |
| | | |
| | | @Value("${mes.inPath}") |
| | | private String inpath; |
| | | @Value("${mes.url}") |
| | | private String mesUrl; |
| | | |
| | | @Override |
| | | @Transactional |
| | |
| | | @Override |
| | | @Transactional |
| | | public void combPACK(CombParam param) { |
| | | if (Cools.isEmpty(param.getPackNo())){ |
| | | throw new CoolException("缺少参数:packNo"); |
| | | }else if (Cools.isEmpty(param.getPackName())){ |
| | | throw new CoolException("缺少参数:packName"); |
| | | }else if (Cools.isEmpty(param.getRequestTime())){ |
| | | throw new CoolException("缺少参数:requestTime");//此参数填入生产日期一栏 不用可关闭 |
| | | } |
| | | if (Cools.isEmpty(param.getPackNo())) { |
| | | throw new CoolException(BaseRes.PARAM); |
| | | } |
| | | // 判断是否有相同Pack码的数据 |
| | | if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>(). |
| | | eq("zpallet", param.getPackNo()).eq("io_status", "N")) > 0) { |
| | | throw new CoolException(param.getPackNo() + "数据正在进行入库"); |
| | | } |
| | | |
| | | int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet",param.getPackNo())); |
| | | int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet",param.getPackNo())); |
| | | if (countLoc > 0 || countWrk > 0) { |
| | | throw new CoolException("工作档/库存条码数据已存在===>>" + param.getPackNo()); |
| | | } |
| | | |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | java.util.Date date1=null; |
| | | try { |
| | | date1= sdf.parse(param.getRequestTime()); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | java.sql.Date requestTime = new java.sql.Date(date1.getTime()); |
| | | |
| | | // 生成入库通知档 |
| | | // Mat mat = matService.selectByMatnr(param.getPackName()); |
| | | // if (Cools.isEmpty(mat)) { |
| | | // throw new CoolException(param.getPackName() + "商品档案不存在"); |
| | | // // 判断是否有相同Pack码的数据 |
| | | // if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>(). |
| | | // eq("zpallet", param.getPackNo()).eq("io_status", "N")) > 0) { |
| | | // throw new CoolException(param.getPackNo() + "数据正在进行入库"); |
| | | // } |
| | | WaitPakin waitPakin = new WaitPakin(); |
| | | // waitPakin.sync(mat); |
| | | waitPakin.setMatnr(param.getPackName()); |
| | | waitPakin.setMaktx(param.getPackName()); |
| | | waitPakin.setZpallet(param.getPackNo()); // Pack码 |
| | | waitPakin.setIoStatus("N"); // 入出状态 |
| | | waitPakin.setAnfme(1.0); // 数量 |
| | | waitPakin.setStatus("Y"); // 状态 |
| | | waitPakin.setManuDate(requestTime.toString()); |
| | | waitPakin.setAppeUser(null); |
| | | waitPakin.setAppeTime(new Date()); |
| | | waitPakin.setModiUser(null); |
| | | waitPakin.setModiTime(new Date()); |
| | | waitPakin.setDeadWarn(param.getSettingTimes()); |
| | | if (!waitPakinService.insert(waitPakin)) { |
| | | throw new CoolException("保存入库通知档失败"); |
| | | |
| | | // int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet",param.getPackNo())); |
| | | // int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet",param.getPackNo())); |
| | | // int countPakin = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet",param.getPackNo())); |
| | | // if (countLoc > 0 || countWrk > 0) { |
| | | // throw new CoolException("工作档/库存条码数据已存在===>>" + param.getPackNo()); |
| | | // }else if (countPakin>0){ |
| | | // throw new CoolException("重复申请" + param.getPackNo()); |
| | | // } |
| | | |
| | | // 生成入库通知档 |
| | | Mat mat = matService.selectByMatnr(param.getPackNo()); |
| | | Date now = new Date(); |
| | | if (Cools.isEmpty(mat)) { |
| | | Tag tag = tagService.selectByName("全部", 1); |
| | | Mat matNew = new Mat(); |
| | | matNew.setTagId(tag.getId()); |
| | | matNew.setMatnr(param.getPackNo()); |
| | | matNew.setMaktx(param.getPackName()); |
| | | matNew.setManuDate(param.getRequestTime()); |
| | | matNew.setDeadWarn(360);//6小时 360分钟 |
| | | matNew.setCreateBy(9999L);//9999表示erp下发 |
| | | matNew.setCreateTime(now); |
| | | matNew.setUpdateBy(9999L);//9999表示erp下发 |
| | | matNew.setUpdateTime(now); |
| | | if (!matService.insert(matNew)){ |
| | | throw new CoolException(param.getPackName() + "商品档案自动生成失败"); |
| | | } |
| | | // mat=matNew; |
| | | // throw new CoolException(param.getPackName() + "商品档案不存在"); |
| | | } |
| | | // WaitPakin waitPakin = new WaitPakin(); |
| | | //// waitPakin.sync(mat); |
| | | // waitPakin.setMatnr(param.getPackName()); |
| | | // waitPakin.setMaktx(param.getPackName()); |
| | | // waitPakin.setZpallet(param.getPackNo()); // Pack码 |
| | | // waitPakin.setIoStatus("N"); // 入出状态 |
| | | // waitPakin.setAnfme(1.0); // 数量 |
| | | // waitPakin.setStatus("Y"); // 状态 |
| | | // waitPakin.setManuDate(param.getRequestTime()); |
| | | // waitPakin.setAppeUser(null); |
| | | // waitPakin.setAppeTime(new Date()); |
| | | // waitPakin.setModiUser(null); |
| | | // waitPakin.setModiTime(new Date()); |
| | | // waitPakin.setDeadWarn(mat.getDeadWarn()); |
| | | // if (!waitPakinService.insert(waitPakin)) { |
| | | // throw new CoolException("保存入库通知档失败"); |
| | | // } |
| | | } |
| | | @Override |
| | | @Transactional |
| | | public void combPackOut(CombParam param) { |
| | | if (Cools.isEmpty(param.getPackNo())){ |
| | | throw new CoolException("缺少参数:packNo"); |
| | | }else if (Cools.isEmpty(param.getPackName())){ |
| | | throw new CoolException("缺少参数:packName"); |
| | | }else if (Cools.isEmpty(param.getSettingTimes())){ |
| | | throw new CoolException("缺少参数:settingTimes"); |
| | | }else if (Cools.isEmpty(param.getRequestTime())){ |
| | | throw new CoolException("缺少参数:requestTime"); |
| | | } |
| | | if (Cools.isEmpty(param.getPackNo())) { |
| | | throw new CoolException(BaseRes.PARAM); |
| | | } |
| | |
| | | .eq("barcode", param.getPackNo())); |
| | | if (Cools.isEmpty(locMast)){ |
| | | throw new CoolException("未查询到PACK码为:"+param.getPackNo()+"的货物"); |
| | | }else if (locMast.getLocSts().equals("F")){ |
| | | }else if (!locMast.getLocSts().equals("F")){ |
| | | throw new CoolException("PACK码为:"+param.getPackNo()+"的货物库位状态不是“F”"); |
| | | }else if (locMast.getFireStatus()!=0){ |
| | | throw new CoolException("警告!!!PACK码为:"+param.getPackNo()+"的库位:"+locMast.getLocNo()+"消防状态异常!!!"); |
| | | // }else if (locMast.getFireStatus()!=0){ |
| | | // throw new CoolException("警告!!!PACK码为:"+param.getPackNo()+"的库位:"+locMast.getLocNo()+"消防状态异常!!!"); |
| | | // }else if (locMast.getFireStatus()!=0){ |
| | | // throw new CoolException("警告!!!PACK码为:"+param.getPackNo()+"的库位:"+locMast.getLocNo()+"消防状态异常!!!"); |
| | | // }else if (locMast.getFireStatus()!=0){ |
| | | // throw new CoolException("警告!!!PACK码为:"+param.getPackNo()+"的库位:"+locMast.getLocNo()+"消防状态异常!!!"); |
| | | }else { |
| | | Date now = new Date(); |
| | | Integer ioType = 101; //入出库类型 |
| | |
| | | if (locMast.getLocSts().equals("F")) { |
| | | locMast.setLocSts("R"); |
| | | locMast.setModiTime(now); |
| | | locMast.setPackStatus(5); //5:静置完成 |
| | | locMast.setPackStatus(6); //6:静置完成 |
| | | CombParam combParam = new CombParam(); |
| | | combParam.setPackNo(locMast.getBarcode()); |
| | | combParam.setLocNo(locMast.getLocNo()); |
| | | combParam.setPackSts(6); |
| | | combParam.setPackSts(7); |
| | | combParam.setRequestTime(DateUtils.convert(new Date())); |
| | | postMesData(inpath,combParam); |
| | | new PostMesDataUtils().postMesData("MES系统",mesUrl,inpath,combParam); |
| | | |
| | | if (!locMastService.updateById(locMast)) { |
| | | throw new CoolException("预约库位状态失败,库位号:"+locMast.getLocNo()); |
| | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void infoReview(Review review) { |
| | | public TestMast infoReview(Review review) { |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", review.getLocNo())); |
| | | if (!review.getBarcode().equals(locMast.getBarcode())){ |
| | | throw new CoolException("pack码不同"); |
| | |
| | | .eq("loc_no", review.getLocNo()) |
| | | .eq("barcode", review.getBarcode()) |
| | | .eq("user_Id", review.getUserId()); |
| | | if (null == locMast ||locMast.getPackStatus()!=1) { |
| | | throw new CoolException("产品状态不是 1:待测试"); |
| | | } |
| | | TestMast testMast = testMastService.selectOne(wrapper); |
| | | if (null == locMast) { |
| | | throw new CoolException("产品状态为空"); |
| | | }else if (locMast.getPackStatus()==2){ |
| | | if (!Cools.isEmpty(testMast)){ |
| | | if (testMast.getStatus()==2 || testMast.getStatus()==3){ |
| | | return testMast; |
| | | } |
| | | } |
| | | }else if (locMast.getPackStatus()!=1){ |
| | | throw new CoolException("产品状态不是1待测试"); |
| | | } |
| | | |
| | | if(null != testMast){ |
| | | if (testMast.getStatus()==1){ |
| | | testMast.setStatus(3); |
| | | testMast.setStatus(2); |
| | | testMast.setModiTime(new Date()); |
| | | if (!testMastService.update(testMast,wrapper)){ |
| | | throw new CoolException("更新测试状态失败"); |
| | | } |
| | | locMast.setPackStatus(2); |
| | | CombParam combParam = new CombParam(); |
| | | combParam.setPackNo(locMast.getBarcode()); |
| | | combParam.setLocNo(locMast.getLocNo()); |
| | | combParam.setPackSts(2); |
| | | combParam.setRequestTime(DateUtils.convert(new Date())); |
| | | postMesData(inpath,combParam); |
| | | if (!locMastService.update(locMast,new EntityWrapper<LocMast>().eq("loc_no", review.getLocNo()))){ |
| | | |
| | | |
| | | throw new CoolException("更新产品状态失败"); |
| | | } |
| | | }else if (Cools.isEmpty(testMast.getStatus())){ |
| | | } else if (Cools.isEmpty(testMast.getStatus())){ |
| | | throw new CoolException("状态异常"); |
| | | }else { |
| | | throw new CoolException("状态不是 1:申请中"); |
| | |
| | | } else { |
| | | throw new CoolException("测试申请复核失败"); |
| | | } |
| | | return testMast; |
| | | } |
| | | |
| | | |
| | |
| | | if(null != testMast){ |
| | | if (testMast.getStatus()==3){ |
| | | Date date = new Date(); |
| | | testMast.setStatus(4); |
| | | testMast.setModiTime(date); |
| | | if (!testMastService.update(testMast,wrapper)){ |
| | | throw new CoolException("更改测试状态失败"); |
| | | } |
| | | locMast.setPackStatus(3); |
| | | testMast.setModiTime(date); |
| | | CombParam combParam = new CombParam(); |
| | | combParam.setPackNo(locMast.getBarcode()); |
| | | combParam.setLocNo(locMast.getLocNo()); |
| | | combParam.setPackSts(3); |
| | | combParam.setRequestTime(DateUtils.convert(new Date())); |
| | | postMesData(inpath,combParam); |
| | | locMast.setModiTime(date); |
| | | // CombParam combParam = new CombParam(); |
| | | // combParam.setPackNo(locMast.getBarcode()); |
| | | // combParam.setLocNo(locMast.getLocNo()); |
| | | // combParam.setPackSts(3); |
| | | // combParam.setRequestTime(DateUtils.convert(new Date())); |
| | | // new PostMesDataUtils().postMesData("MES系统",mesUrl,inpath,combParam); |
| | | |
| | | if (!locMastService.update(locMast, new EntityWrapper<LocMast>().eq("loc_no", review.getLocNo()))){ |
| | | throw new CoolException("更改产品状态失败"); |
| | | } |
| | | }else if (Cools.isEmpty(testMast.getStatus())){ |
| | | throw new CoolException("状态异常"); |
| | | }else { |
| | | throw new CoolException("测试状态不是 3:测试中"); |
| | | } |
| | | } else { |
| | | throw new CoolException("状态异常"); |
| | | } |
| | | return success; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Boolean testNG(Review review) { |
| | | Boolean success=true; |
| | | Wrapper wrapper = new EntityWrapper<TestMast>() |
| | | .eq("loc_no", review.getLocNo()) |
| | | .eq("barcode", review.getBarcode()) |
| | | .eq("user_Id", review.getUserId()); |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", review.getLocNo())); |
| | | if (null == locMast ||locMast.getPackStatus()!=2){ |
| | | throw new CoolException("产品状态不是 2:测试中"); |
| | | }else if (!review.getBarcode().equals(locMast.getBarcode())){ |
| | | throw new CoolException("pack码不同"); |
| | | } |
| | | TestMast testMast = testMastService.selectOne(wrapper); |
| | | if(null != testMast){ |
| | | if (testMast.getStatus()==3){ |
| | | Date date = new Date(); |
| | | locMast.setPackStatus(4); |
| | | locMast.setModiTime(date); |
| | | // CombParam combParam = new CombParam(); |
| | | // combParam.setPackNo(locMast.getBarcode()); |
| | | // combParam.setLocNo(locMast.getLocNo()); |
| | | // combParam.setPackSts(4); |
| | | // combParam.setRequestTime(DateUtils.convert(new Date())); |
| | | // new PostMesDataUtils().postMesData("MES系统",mesUrl,inpath,combParam); |
| | | |
| | | if (!locMastService.update(locMast, new EntityWrapper<LocMast>().eq("loc_no", review.getLocNo()))){ |
| | | throw new CoolException("更改产品状态失败"); |
| | | } |
| | |
| | | throw new CoolException("状态异常"); |
| | | } |
| | | return success; |
| | | } |
| | | |
| | | private ReturnT<String> postMesData(String mesPath, Object combParam){ |
| | | if(combParam != null){ |
| | | String response = ""; |
| | | boolean success = false; |
| | | try { |
| | | // Map<String, Object> map = new HashMap<>(); |
| | | // map.put("appkey","ea1f0459efc02a79f046f982767939ae"); |
| | | response = new HttpHandler.Builder() |
| | | // .setHeaders(map) |
| | | .setUri(mesUrl) |
| | | .setPath(mesPath) |
| | | .setJson(JSON.toJSONString(combParam)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (jsonObject.getInteger("code").equals(200)) { |
| | | if (jsonObject.getDate("isComplete").equals(true)){ |
| | | success = true; |
| | | }else if (jsonObject.getDate("isComplete").equals(false)){ |
| | | success = false; |
| | | }else { |
| | | log.error("返回值出错!!!url:{};request:{};response:{}", mesUrl+mesPath, JSON.toJSONString(combParam), response); |
| | | throw new CoolException("返回值出错"); |
| | | } |
| | | } else { |
| | | log.error("请求接口失败!!!url:{};request:{};response:{}", mesUrl+mesPath, JSON.toJSONString(combParam), response); |
| | | throw new CoolException("上报mes系统失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("fail", e); |
| | | // TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | return FAIL.setMsg(e.getMessage()); |
| | | } finally { |
| | | try { |
| | | // 保存接口日志 |
| | | apiLogService.save( |
| | | "成品库入库上报", |
| | | mesUrl + mesPath, |
| | | null, |
| | | "127.0.0.1", |
| | | JSON.toJSONString(combParam), |
| | | response, |
| | | success |
| | | ); |
| | | } catch (Exception e) { log.error("", e); } |
| | | } |
| | | } |
| | | return SUCCESS; |
| | | } |
| | | /*...........................赣州新增..............以上.............赣州新增...........................*/ |
| | | |