| | |
| | | package com.zy.asrs.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.BaseRes; |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.SnowflakeIdWorker; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.param.OpenOrderCompleteParam; |
| | | import com.zy.asrs.entity.param.OpenOrderPakinParam; |
| | | import com.zy.asrs.entity.param.OpenOrderPakoutParam; |
| | | import com.zy.asrs.entity.param.PackParam; |
| | | import com.zy.asrs.entity.param.*; |
| | | import com.zy.asrs.entity.result.OpenOrderCompeteResult; |
| | | import com.zy.asrs.entity.result.StockVo; |
| | | import com.zy.asrs.mapper.ReportQueryMapper; |
| | | import com.zy.asrs.mapper.TagMapper; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.utils.MatUtils; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | |
| | | private TagService tagService; |
| | | @Autowired |
| | | private TagMapper tagMapper; |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | @Autowired |
| | | private WaitPakinService waitPakinService; |
| | | @Autowired |
| | | private WrkDetlService wrkDetlService; |
| | | @Autowired |
| | | private ReportQueryMapper reportQueryMapper; |
| | | |
| | | @Override |
| | | @Transactional |
| | |
| | | for (DetlDto detail : orderDetails) { |
| | | DetlDto dto = new DetlDto(detail.getMatnr(), detail.getBatch(), detail.getAnfme()); |
| | | if (DetlDto.has(list, dto)) { |
| | | DetlDto detlDto = DetlDto.find(list, dto.getMatnr(), dto.getBatch()); |
| | | DetlDto detlDto = DetlDto.find(list, dto.getMatnr(), dto.getBatch(),dto.getCsocode(),dto.getIsoseq(),null); |
| | | assert detlDto != null; |
| | | detlDto.setAnfme(detlDto.getAnfme() + detail.getAnfme()); |
| | | } else { |
| | |
| | | orderDetl.setAnfme(detlDto.getAnfme()); |
| | | orderDetl.setOrderId(order.getId()); |
| | | orderDetl.setOrderNo(order.getOrderNo()); |
| | | orderDetl.setSource(docType.getDocId().intValue()); |
| | | orderDetl.setCreateBy(9527L); |
| | | orderDetl.setCreateTime(now); |
| | | orderDetl.setUpdateBy(9527L); |
| | |
| | | throw new CoolException("生成单据明细失败,请联系管理员"); |
| | | } |
| | | } |
| | | // 生成调拨单 |
| | | if (docType.getDocId().intValue() == 32) { |
| | | order = new Order( |
| | | String.valueOf(snowflakeIdWorker.nextId()), // 编号[非空] |
| | | "DB" + param.getOrderNo(), // 订单编号 |
| | | DateUtils.convert(now), // 单据日期 |
| | | 33L, // 单据类型 |
| | | null, // 项目编号 |
| | | null, // |
| | | null, // 调拨项目编号 |
| | | null, // 初始票据号 |
| | | null, // 票据号 |
| | | null, // 客户编号 |
| | | null, // 客户 |
| | | null, // 联系方式 |
| | | null, // 操作人员 |
| | | null, // 合计金额 |
| | | null, // 优惠率 |
| | | null, // 优惠金额 |
| | | null, // 销售或采购费用合计 |
| | | null, // 实付金额 |
| | | null, // 付款类型 |
| | | null, // 业务员 |
| | | null, // 结算天数 |
| | | null, // 邮费支付类型 |
| | | null, // 邮费 |
| | | null, // 付款时间 |
| | | null, // 发货时间 |
| | | null, // 物流名称 |
| | | null, // 物流单号 |
| | | 1L, // 订单状态 |
| | | 1, // 状态 |
| | | 9527L, // 添加人员 |
| | | now, // 添加时间 |
| | | 9527L, // 修改人员 |
| | | now, // 修改时间 |
| | | null // 备注 |
| | | ); |
| | | if (!orderService.insert(order)) { |
| | | throw new CoolException("生成半成品调拨单失败"); |
| | | } |
| | | List<DetlDto> dbList = new ArrayList<>(); |
| | | List<DetlDto> dbOrderDetails = param.getOrderDetails(); |
| | | // 单据明细档 |
| | | for (DetlDto detail : orderDetails) { |
| | | DetlDto dto = new DetlDto(detail.getMatnr(), detail.getBatch(), detail.getAnfme()); |
| | | if (DetlDto.has(dbList, dto)) { |
| | | DetlDto detlDto = DetlDto.find(dbList, dto.getMatnr(), dto.getBatch(),dto.getCsocode(),dto.getIsoseq(),null); |
| | | assert detlDto != null; |
| | | detlDto.setAnfme(detlDto.getAnfme() + detail.getAnfme()); |
| | | } else { |
| | | dbList.add(dto); |
| | | } |
| | | } |
| | | for (DetlDto detlDto : dbList) { |
| | | Mat mat = matService.selectByMatnr(detlDto.getMatnr()); |
| | | if (Cools.isEmpty(mat)) { |
| | | throw new CoolException(detlDto.getMatnr() + "编号商品检索失败,请先添加商品"); |
| | | } |
| | | OrderDetl orderDetl = new OrderDetl(); |
| | | orderDetl.sync(mat); |
| | | orderDetl.setBatch(detlDto.getBatch()); |
| | | orderDetl.setAnfme(detlDto.getAnfme()); |
| | | orderDetl.setOrderId(order.getId()); |
| | | orderDetl.setOrderNo(order.getOrderNo()); |
| | | orderDetl.setSource(docType.getDocId().intValue()); |
| | | orderDetl.setCreateBy(9527L); |
| | | orderDetl.setCreateTime(now); |
| | | orderDetl.setUpdateBy(9527L); |
| | | orderDetl.setUpdateTime(now); |
| | | orderDetl.setStatus(1); |
| | | orderDetl.setQty(0.0D); |
| | | if (!orderDetlService.insert(orderDetl)) { |
| | | throw new CoolException("生成半成品调拨单明细档失败,请联系管理员"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | |
| | | result.setOrderType(order.getDocType$()); |
| | | List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId()); |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | result.getOrderDetails().add(new DetlDto(orderDetl.getOrderNo(), orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getQty())); |
| | | //result.getOrderDetails().add(new DetlDto(orderDetl.getOrderNo(), orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getQty())); |
| | | } |
| | | if (order.getSettle() == 4L) { |
| | | // 修改订单状态 4.完成 ===>> 6.已上报 |
| | |
| | | result.setOrderType(order.getDocType$()); |
| | | List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId()); |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | result.getOrderDetails().add(new DetlDto(orderDetl.getOrderNo(), orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getQty())); |
| | | //result.getOrderDetails().add(new DetlDto(orderDetl.getOrderNo(), orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getQty())); |
| | | } |
| | | // 修改订单状态 4.完成 ===>> 6.已上报 |
| | | if (!orderService.updateSettle(order.getId(), 6L, null)) { |
| | |
| | | for (DetlDto detail : orderDetails) { |
| | | DetlDto dto = new DetlDto(detail.getMatnr(), detail.getBatch(), detail.getAnfme()); |
| | | if (DetlDto.has(list, dto)) { |
| | | DetlDto detlDto = DetlDto.find(list, dto.getMatnr(), dto.getBatch()); |
| | | DetlDto detlDto = DetlDto.find(list, dto.getMatnr(), dto.getBatch(),dto.getCsocode(),dto.getIsoseq(),null); |
| | | assert detlDto != null; |
| | | detlDto.setAnfme(detlDto.getAnfme() + detail.getAnfme()); |
| | | } else { |
| | |
| | | orderDetl.setAnfme(detlDto.getAnfme()); |
| | | orderDetl.setOrderId(order.getId()); |
| | | orderDetl.setOrderNo(order.getOrderNo()); |
| | | orderDetl.setSource(docType.getDocId().intValue()); |
| | | orderDetl.setCreateBy(9527L); |
| | | orderDetl.setCreateTime(now); |
| | | orderDetl.setUpdateBy(9527L); |
| | |
| | | orderDetl.setQty(0.0D); |
| | | if (!orderDetlService.insert(orderDetl)) { |
| | | throw new CoolException("生成单据明细失败,请联系管理员"); |
| | | } |
| | | } |
| | | if (docType.getDocId().intValue() == 32) { |
| | | order = new Order( |
| | | String.valueOf(snowflakeIdWorker.nextId()), // 编号[非空] |
| | | "DB" + param.getOrderNo(), // 订单编号 |
| | | DateUtils.convert(now), // 单据日期 |
| | | 33L, // 单据类型 |
| | | null, // 项目编号 |
| | | null, // |
| | | null, // 调拨项目编号 |
| | | null, // 初始票据号 |
| | | null, // 票据号 |
| | | null, // 客户编号 |
| | | null, // 客户 |
| | | null, // 联系方式 |
| | | null, // 操作人员 |
| | | null, // 合计金额 |
| | | null, // 优惠率 |
| | | null, // 优惠金额 |
| | | null, // 销售或采购费用合计 |
| | | null, // 实付金额 |
| | | null, // 付款类型 |
| | | null, // 业务员 |
| | | null, // 结算天数 |
| | | null, // 邮费支付类型 |
| | | null, // 邮费 |
| | | null, // 付款时间 |
| | | null, // 发货时间 |
| | | null, // 物流名称 |
| | | null, // 物流单号 |
| | | 1L, // 订单状态 |
| | | 1, // 状态 |
| | | 9527L, // 添加人员 |
| | | now, // 添加时间 |
| | | 9527L, // 修改人员 |
| | | now, // 修改时间 |
| | | null // 备注 |
| | | ); |
| | | if (!orderService.insert(order)) { |
| | | throw new CoolException("生成半成品调拨单失败"); |
| | | } |
| | | List<DetlDto> dbList = new ArrayList<>(); |
| | | List<DetlDto> dbOrderDetails = param.getOrderDetails(); |
| | | // 单据明细档 |
| | | for (DetlDto detail : orderDetails) { |
| | | DetlDto dto = new DetlDto(detail.getMatnr(), detail.getBatch(), detail.getAnfme()); |
| | | if (DetlDto.has(dbList, dto)) { |
| | | DetlDto detlDto = DetlDto.find(dbList, dto.getMatnr(), dto.getBatch(),dto.getCsocode(),dto.getIsoseq(),null); |
| | | assert detlDto != null; |
| | | detlDto.setAnfme(detlDto.getAnfme() + detail.getAnfme()); |
| | | } else { |
| | | dbList.add(dto); |
| | | } |
| | | } |
| | | for (DetlDto detlDto : dbList) { |
| | | Mat mat = matService.selectByMatnr(detlDto.getMatnr()); |
| | | if (Cools.isEmpty(mat)) { |
| | | throw new CoolException(detlDto.getMatnr() + "编号商品检索失败,请先添加商品"); |
| | | } |
| | | OrderDetl orderDetl = new OrderDetl(); |
| | | orderDetl.sync(mat); |
| | | orderDetl.setBatch(detlDto.getBatch()); |
| | | orderDetl.setAnfme(detlDto.getAnfme()); |
| | | orderDetl.setOrderId(order.getId()); |
| | | orderDetl.setOrderNo(order.getOrderNo()); |
| | | orderDetl.setSource(docType.getDocId().intValue()); |
| | | orderDetl.setCreateBy(9527L); |
| | | orderDetl.setCreateTime(now); |
| | | orderDetl.setUpdateBy(9527L); |
| | | orderDetl.setUpdateTime(now); |
| | | orderDetl.setStatus(1); |
| | | orderDetl.setQty(0.0D); |
| | | if (!orderDetlService.insert(orderDetl)) { |
| | | throw new CoolException("生成半成品调拨单明细档失败,请联系管理员"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | result.setOrderType(order.getDocType$()); |
| | | List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId()); |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | result.getOrderDetails().add(new DetlDto(orderDetl.getOrderNo(), orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getQty())); |
| | | //result.getOrderDetails().add(new DetlDto(orderDetl.getOrderNo(), orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getQty())); |
| | | } |
| | | if (order.getSettle() == 4L) { |
| | | // 修改订单状态 4.完成 ===>> 6.已上报 |
| | |
| | | result.setOrderType(order.getDocType$()); |
| | | List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId()); |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | result.getOrderDetails().add(new DetlDto(orderDetl.getOrderNo(), orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getQty())); |
| | | //result.getOrderDetails().add(new DetlDto(orderDetl.getOrderNo(), orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getQty())); |
| | | } |
| | | // 修改订单状态 4.完成 ===>> 6.已上报 |
| | | if (!orderService.updateSettle(order.getId(), 6L, null)) { |
| | |
| | | Date now = new Date(); |
| | | pack = new Pack( |
| | | param.getBarcode(), // 条码[非空] |
| | | analyse.getMatnr(), // 单据号 |
| | | analyse.getMatnr(), // 物料号 |
| | | analyse.getBarcode(), // 序列码 |
| | | 1L, // 订单状态 |
| | | 1, // 状态 |
| | |
| | | if (!matService.insert(mat)) { |
| | | throw new CoolException("服务器内部错误,请联系管理员"); |
| | | } else { |
| | | log.info("打包上线添加新物料[单据号:{}]", mat.getMatnr()); |
| | | log.info("打包上线添加新物料[物料号:{}]", mat.getMatnr()); |
| | | } |
| | | } |
| | | } |
| | | @Override |
| | | @Transactional |
| | | public Mat syncMat(MatSyncParam param) { |
| | | if (Cools.isEmpty(param.getCInvCode()) ) { |
| | | throw new CoolException("商品数据为空"); |
| | | } |
| | | Tag tag = tagService.selectByName("全部", 1); |
| | | |
| | | Mat mat = matService.selectByMatnr(param.getCInvCode()); |
| | | if (Cools.isEmpty(mat)) { |
| | | mat = new Mat(); |
| | | mat.setTagId(tag.getId()); |
| | | syncMat(mat,param); |
| | | if (matService.insert(mat)) { |
| | | callApiLogSave(mat, "/open/asrs/mat/v1", "接收ERP下发商品信息成功!添加商品信息成功!", true); |
| | | } else { |
| | | callApiLogSave(mat, "/open/asrs/mat/v1", "添加ERP下发商品信息失败!!!状态异常!!!", false); |
| | | mat.setMemo("添加ERP下发商品信息失败!"); |
| | | } |
| | | |
| | | } else { |
| | | mat.setTagId(tag.getId()); |
| | | syncMat(mat,param); |
| | | if (matService.updateById(mat)) { |
| | | callApiLogSave(mat, "/open/asrs/mat/v1", "接收ERP下发商品信息成功!添加商品信息成功!", true); |
| | | } else { |
| | | callApiLogSave(mat, "/open/asrs/mat/v1", "添加ERP下发商品信息失败!!!状态异常!!!", false); |
| | | mat.setMemo("添加ERP下发商品信息失败!"); |
| | | } |
| | | } |
| | | return mat; |
| | | } |
| | | |
| | | private void syncMat(Mat mat, MatSyncParam param){ |
| | | Date date = new Date(); |
| | | mat.setMatnr(param.getCInvCode());//物料编码 |
| | | mat.setMaktx(param.getCInvName());//物料名称 |
| | | mat.setSpecs(param.getCInvStd());//规格 |
| | | mat.setUnit(param.getCComUnitName()); |
| | | mat.setBeBatch(Cools.eq("true",param.getBInvBatch()) ? 1 : 0); |
| | | mat.setStatus(param.getStates()); |
| | | |
| | | mat.setCreateBy(9999L);//9999表示erp下发 |
| | | mat.setCreateTime(date); |
| | | mat.setUpdateBy(9999L);//9999表示erp下发 |
| | | mat.setUpdateTime(date); |
| | | |
| | | |
| | | } |
| | | |
| | | public void callApiLogSave(Mat mat, String tableName, String response, Boolean bool) { |
| | | apiLogService.save("ERP下发商品信息", tableName, "null", "10.10.10.1", |
| | | "物料编码:" + mat.getMatnr() + "、物料名称:" + mat.getMaktx() + "、规格:" + mat.getSpecs() + "、备注:" + mat.getMemo(), |
| | | response, bool); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void combMes(CombParam param) { |
| | | Long userId=9999l; |
| | | if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) { |
| | | callApiLogSaveMES(null, null, BaseRes.PARAM, false); |
| | | throw new CoolException(BaseRes.PARAM); |
| | | } |
| | | if(param.getBarcode().length()!=8){ |
| | | callApiLogSaveMES(param, null, param.getBarcode() + ":条码长度不是8位", false); |
| | | throw new CoolException("条码长度不是8位===>>" + param.getBarcode()); |
| | | } |
| | | // 判断是否有相同条码的数据 |
| | | if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>(). |
| | | eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) { |
| | | callApiLogSaveMES(param, null, param.getBarcode() + "数据正在进行入库", false); |
| | | throw new CoolException(param.getBarcode() + "数据正在进行入库"); |
| | | } |
| | | |
| | | int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet",param.getBarcode())); |
| | | int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet",param.getBarcode())); |
| | | if (countLoc > 0) { |
| | | callApiLogSaveMES(param, null, param.getBarcode() + ":库存条码数据已存在", false); |
| | | throw new CoolException("库存条码数据已存在===>>" + param.getBarcode()); |
| | | }else if (countWrk > 0){ |
| | | callApiLogSaveMES(param, null, param.getBarcode() + ":工作明细档已存在此数据", false); |
| | | throw new CoolException("工作明细档已存在此数据===>>" + param.getBarcode()); |
| | | } |
| | | |
| | | Date now = new Date(); |
| | | try{ |
| | | // 生成入库通知档 |
| | | List<DetlDto> detlDtos = new ArrayList<>(); |
| | | param.getCombMats().forEach(elem -> { |
| | | DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme()); |
| | | detlDto.setContainerCode(elem.getContainerCode()); |
| | | if (DetlDto.has(detlDtos, detlDto)) { |
| | | DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch(),detlDto.getCsocode(),detlDto.getIsoseq(),detlDto.getContainerCode()); |
| | | assert one != null; |
| | | one.setAnfme(one.getAnfme() + detlDto.getAnfme()); |
| | | } else { |
| | | detlDtos.add(detlDto); |
| | | } |
| | | }); |
| | | |
| | | for (DetlDto detlDto : detlDtos) { |
| | | Mat mat = matService.selectByMatnr(detlDto.getMatnr()); |
| | | if (Cools.isEmpty(mat)) { |
| | | callApiLogSaveMES(param, null,mat.getMatnr()+"商品档案不存在", false); |
| | | throw new CoolException(detlDto.getMatnr() + "商品档案不存在"); |
| | | } |
| | | WaitPakin waitPakin = new WaitPakin(); |
| | | waitPakin.sync(mat); |
| | | waitPakin.setBatch(detlDto.getBatch()); |
| | | waitPakin.setZpallet(param.getBarcode()); // 托盘码 |
| | | waitPakin.setIoStatus("N"); // 入出状态 |
| | | waitPakin.setAnfme(detlDto.getAnfme()); // 数量 |
| | | waitPakin.setStatus("Y"); // 状态 |
| | | waitPakin.setAppeUser(userId); |
| | | waitPakin.setAppeTime(now); |
| | | waitPakin.setModiUser(userId); |
| | | waitPakin.setModiTime(now); |
| | | if (!waitPakinService.insert(waitPakin)) { |
| | | callApiLogSaveMES(param, null,mat.getMatnr()+"保存入库通知档失败", false); |
| | | throw new CoolException("保存入库通知档失败"); |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | callApiLogSaveMES(null, null,""+e, false); |
| | | } |
| | | callApiLogSaveMES(param, param.getCombMats().get(0),"组托成功", true); |
| | | } |
| | | public void callApiLogSaveMES(CombParam combParam,CombParam.CombMat combMat, String response, Boolean bool) { |
| | | if (Cools.isEmpty(combParam)){ |
| | | apiLogService.save("MES下发入库通知单", "/open/asrs/comb/v1", "null", "10.10.10.1", |
| | | "", |
| | | response, bool); |
| | | }else if (Cools.isEmpty(combMat)){ |
| | | apiLogService.save("MES下发入库通知单", "/open/asrs/comb/v1", "null", "10.10.10.1", |
| | | "托盘码:" + combParam.getBarcode(), |
| | | response, bool); |
| | | }else { |
| | | apiLogService.save("MES下发入库通知单", "/open/asrs/comb/v1", "null", "10.10.10.1", |
| | | "托盘码:" + combParam.getBarcode() + "、物料编号:" + combMat.getMatnr() + "、数量:" + combMat.getAnfme(), |
| | | response, bool); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 入库记录获取 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public List<ViewWorkInBean> inlogERP() { |
| | | List<ViewWorkInBean> viewWorkInERP = reportQueryMapper.getViewWorkInERP(); |
| | | ArrayList<ViewWorkInBean> viewWorkInBeans = new ArrayList<>(); |
| | | for (ViewWorkInBean viewWorkInBean:viewWorkInERP){ |
| | | viewWorkInBean.sype(); |
| | | viewWorkInBeans.add(viewWorkInBean); |
| | | } |
| | | return viewWorkInBeans; |
| | | } |
| | | |
| | | /** |
| | | * 出库记录获取 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public List<ViewWorkInBean> outlogERP() { |
| | | List<ViewWorkInBean> viewWorkInERP = reportQueryMapper.getViewWorkOutERP(); |
| | | ArrayList<ViewWorkInBean> viewWorkInBeans = new ArrayList<>(); |
| | | for (ViewWorkInBean viewWorkInBean:viewWorkInERP){ |
| | | viewWorkInBean.sype(); |
| | | viewWorkInBeans.add(viewWorkInBean); |
| | | } |
| | | return viewWorkInBeans; |
| | | } |
| | | |
| | | @Transactional |
| | | public boolean syncMat(MatInfoParam param) { |
| | | Date now = new Date(); |
| | | Mat mat = matService.selectByMatnr(param.getCinvcode()); |
| | | boolean update = true; |
| | | if(Cools.isEmpty(matService.selectByMatnr(param.getCinvcode()))){ |
| | | //物料号 |
| | | mat = new Mat(); |
| | | mat.setMatnr(param.getCinvcode()); |
| | | mat.setCreateTime(now); |
| | | mat.setCreateBy(9999L); |
| | | update = false; |
| | | // callApiLogSave(param, "/open/asrs/mat/v1", "接收ERP下发商品信息失败!!!商品已存在!!!", false); |
| | | // param.setType(false); |
| | | // param.setMemo("商品已存在!"); |
| | | // return false; |
| | | } |
| | | //Mat mat = new Mat(); |
| | | //物料号 |
| | | //mat.setMatnr(param.getCinvcode()); |
| | | //物料名称 |
| | | mat.setMaktx(param.getCinvname()); |
| | | //规格型号 |
| | | mat.setSpecs(param.getCInvStd()); |
| | | //存货分类编码 |
| | | mat.setBrand(param.getCinvccode()); |
| | | //存货分类名称 |
| | | mat.setColor(param.getCInvCName()); |
| | | //计量单位 |
| | | mat.setUnit(param.getCComUnitName()); |
| | | //进项税 |
| | | mat.setPrice(param.getIImpTaxRate()); |
| | | //销项税 |
| | | mat.setUnits(param.getITaxRate()); |
| | | //启用日期 |
| | | mat.setDsDate(param.getDSDate()); |
| | | //建档人 |
| | | mat.setSupp(param.getCCreatePerson()); |
| | | //建档日期 |
| | | mat.setDInvCreateDatetime(param.getDInvCreateDatetime()); |
| | | //通用型号 |
| | | mat.setModel(param.getCinvdefine4()); |
| | | |
| | | //9999表示erp下发 |
| | | |
| | | mat.setUpdateBy(9999L); |
| | | mat.setTagId(1L); |
| | | |
| | | mat.setUpdateTime(now); |
| | | |
| | | if(update){ |
| | | if (matService.updateById(mat)){ |
| | | callApiLogSave(param, "/open/asrs/mat/v1", "接收ERP下发商品信息成功!添加商品信息成功!", true); |
| | | param.setUpdate(true); |
| | | } else { |
| | | callApiLogSave(param, "/open/asrs/mat/v1", "添加ERP下发商品信息失败!!!状态异常!!!", false); |
| | | param.setError(true); |
| | | param.setMemo("添加ERP下发商品信息失败!"); |
| | | } |
| | | }else { |
| | | if (matService.insert(mat)) { |
| | | callApiLogSave(param, "/open/asrs/mat/v1", "接收ERP下发商品信息成功!添加商品信息成功!", true); |
| | | param.setInsert(true); |
| | | } else { |
| | | callApiLogSave(param, "/open/asrs/mat/v1", "添加ERP下发商品信息失败!!!状态异常!!!", false); |
| | | param.setError(true); |
| | | param.setMemo("添加ERP下发商品信息失败!"); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | return true; |
| | | } |
| | | |
| | | @Transactional |
| | | public boolean syncOrder(OrderSyncParam param, boolean pakin, String docName) { |
| | | if(Cools.isEmpty(param) || Cools.isEmpty(param.getChildren())){ |
| | | callApiLogSave(param, "/order/pakout/default/v1", "接受单据失败,单据参数为空或者单据详情为空,无法生成单据信息", false); |
| | | throw new CoolException("单据参数为空或者单据详情为空,无法生成单据信息"); |
| | | } |
| | | |
| | | Order orderOld = null; |
| | | |
| | | if(!Cools.isEmpty(orderService.selectByNo(param.getCPOID()))){ |
| | | |
| | | orderOld = orderService.selectByNo(param.getCPOID()); |
| | | if(orderOld.getSettle() > 1){ |
| | | throw new CoolException("该单据已在作业中,无法更改单据信息"); |
| | | } |
| | | |
| | | // String orderNo = param.getCPOID(); |
| | | // if (orderNo.contains("-")){ |
| | | // int index = Integer.parseInt(orderNo.split("-")[1]) + 1; |
| | | // orderNo = orderNo.split("-")[0] + "-" + index; |
| | | // param.setcPOID(orderNo); |
| | | // }else { |
| | | // orderNo = orderNo + "-1"; |
| | | // param.setcPOID(orderNo); |
| | | // } |
| | | // |
| | | // syncOrder(param,pakin,docName); |
| | | |
| | | //callApiLogSave(param, "/order/pakout/default/v1", "接受单据失败,该单据已存在,无法生成单据信息", false); |
| | | //throw new CoolException("该单据已存在,无法生成单据信息"); |
| | | } |
| | | Date now = new Date(); |
| | | Order order = orderMapping(param,now,pakin,docName); |
| | | orderService.insert(order); |
| | | param.getChildren().forEach(od -> { |
| | | OrderDetl orderDetl = orderDetlMapping(order,od,now); |
| | | orderDetlService.insert(orderDetl); |
| | | }); |
| | | |
| | | if(!Cools.isEmpty(orderOld)){ |
| | | //删除原有单据信息 |
| | | orderService.delete(new EntityWrapper<Order>().eq("id",orderOld.getId())); |
| | | orderDetlService.delete(new EntityWrapper<OrderDetl>().eq("order_id",orderOld.getId())); |
| | | } |
| | | |
| | | callApiLogSave(param, "/order/pakout/default/v1", "接受单据成功", true); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | @Transactional |
| | | public boolean orderDelete(String orderNo) { |
| | | Order order = orderService.selectByNo(orderNo); |
| | | if(Cools.isEmpty(order)){ |
| | | throw new CoolException("单据不存在,无法删除单据"); |
| | | } |
| | | |
| | | if(order.getSettle() != 1){ |
| | | return false; |
| | | } |
| | | |
| | | orderService.deleteById(order); |
| | | orderDetlService.delete(new EntityWrapper<OrderDetl>().eq("order_id",order.getId())); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | private Order orderMapping(OrderSyncParam param, Date now, boolean pakin, String docName){ |
| | | Order order = new Order(); |
| | | //uuid |
| | | order.setUuid(String.valueOf(snowflakeIdWorker.nextId())); |
| | | //单据唯一表示 |
| | | order.setOrderNo(param.getCPOID()); |
| | | //单据类型 |
| | | DocType docType = docTypeService.selectOrAdd(docName, pakin); |
| | | order.setDocType(docType.getDocId()); |
| | | //单据日期 |
| | | order.setOrderTime(param.getDdate()); |
| | | |
| | | order.setMemo(param.getCMemo()); |
| | | //制单人 |
| | | order.setShipCode(param.getCPersonCode()); |
| | | |
| | | order.setDefNumber(param.get操作系统号()); |
| | | |
| | | order.setCreateTime(now); |
| | | order.setUpdateTime(now); |
| | | |
| | | //订单状态 |
| | | order.setSettle(1L); |
| | | //状态 |
| | | order.setStatus(1); |
| | | return order; |
| | | } |
| | | |
| | | private OrderDetl orderDetlMapping(Order order, OrderSyncParam.OrderDetl odParam, Date now){ |
| | | |
| | | Mat mat = matService.selectByMatnr(odParam.getCInvCode()); |
| | | if(Cools.isEmpty(mat)){ |
| | | throw new CoolException("存货编码:" + odParam.getCInvCode() + "不存在,请先同步存货档案"); |
| | | } |
| | | |
| | | OrderDetl od = new OrderDetl(); |
| | | od.setOrderId(order.getId()); |
| | | od.setOrderNo(order.getOrderNo()); |
| | | //采购订单行号 |
| | | od.setItemNum(odParam.getIvouchrowno()); |
| | | //存货编码 |
| | | od.setMatnr(mat.getMatnr()); |
| | | //存货名称 |
| | | od.setMaktx(mat.getMaktx()); |
| | | //规格型号 |
| | | //od.setSpecs(odParam.get("cInvStd").toString()); |
| | | od.setSpecs(mat.getSpecs()); |
| | | //计量单位 |
| | | //od.setUnit(odParam.get("cComUnitName").toString()); |
| | | od.setUnit(mat.getUnit()); |
| | | //数量 |
| | | od.setAnfme(odParam.getIQuantity()); |
| | | //销售订单号 |
| | | od.setThreeCode(odParam.getCDefine22()); |
| | | //自由项 |
| | | od.setDeadTime(odParam.getBFree1()); |
| | | //IDs |
| | | od.setSku(odParam.getId()); |
| | | |
| | | od.setLength(odParam.getINum()); |
| | | |
| | | od.setStatus(1); |
| | | od.setQty(0.0D); |
| | | od.setCreateBy(9999L); |
| | | od.setCreateTime(now); |
| | | od.setUpdateBy(9999L); |
| | | od.setUpdateTime(now); |
| | | |
| | | return od; |
| | | } |
| | | |
| | | private String toString(Object o){ |
| | | if(StringUtils.isEmpty(o)){ |
| | | return null; |
| | | }else{ |
| | | return o.toString(); |
| | | } |
| | | } |
| | | |
| | | |
| | | public void callApiLogSave(MatInfoParam matParam, String tableName, String response, Boolean bool) { |
| | | apiLogService.save("ERP下发商品信息", tableName, "null", "10.10.10.1", |
| | | "物料编码:" + matParam.getCinvcode() + "、物料名称:" + matParam.getCinvname() + "、规格:" + matParam.getCInvStd() + "、备注:" + matParam.getMemo(), |
| | | response, bool); |
| | | } |
| | | |
| | | public void callApiLogSave(OrderSyncParam param, String tableName, String response, Boolean bool) { |
| | | apiLogService.save("ERP订单同步", tableName, "null", "10.10.10.1", |
| | | param.toString(), response, bool); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | Object s = null; |
| | | if(StringUtils.isEmpty(s)){ |
| | | System.out.println("null"); |
| | | }else { |
| | | System.out.println(s.toString()); |
| | | } |
| | | } |
| | | } |