| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | @Autowired |
| | | private ManLocDetlMapper manLocDetlMapper; |
| | | @Resource |
| | | private InventoryCheckOrderDetlService inventoryCheckOrderDetlService; |
| | | private InventoryCheckOrderService checkOrderService; |
| | | @Resource |
| | | private InventoryCheckOrderDetlService checkOrderDetlService; |
| | | |
| | | @Resource |
| | | private BasDevpMapper basDevpMapper; |
| | |
| | | throw new CoolException("盘点列表参数为空"); |
| | | } |
| | | for (InventoryCheckOrderDetl orderDetl: param.getParam()){ |
| | | InventoryCheckOrderDetl inventoryCheckOrderDetl = inventoryCheckOrderDetlService.selectOne(new EntityWrapper<InventoryCheckOrderDetl>() |
| | | InventoryCheckOrderDetl inventoryCheckOrderDetl = checkOrderDetlService.selectOne(new EntityWrapper<InventoryCheckOrderDetl>() |
| | | .eq("order_no", orderDetl.getOrderNo()) |
| | | .eq("matnr", orderDetl.getMatnr()) |
| | | .eq("batch", orderDetl.getBatch())); |
| | |
| | | } |
| | | inventoryCheckOrderDetl.setCheckAnfme(orderDetl.getCheckAnfme()); |
| | | inventoryCheckOrderDetl.setStatus("2"); |
| | | if (!inventoryCheckOrderDetlService.updateById(inventoryCheckOrderDetl)){ |
| | | if (!checkOrderDetlService.updateById(inventoryCheckOrderDetl)){ |
| | | throw new CoolException("保存盘点信息失败!"); |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void inventoryUpload(String orderId) { |
| | | if (Cools.isEmpty(orderId)){ |
| | | throw new CoolException("盘点单id为空"); |
| | | } |
| | | InventoryCheckOrder inventoryCheckOrder = checkOrderService.selectById(orderId); |
| | | if (Cools.isEmpty(inventoryCheckOrder)){ |
| | | throw new CoolException("未找到盘点单"); |
| | | } |
| | | if (inventoryCheckOrder.getStatus().equals("2")){ |
| | | throw new CoolException("盘点单已提交"); |
| | | } |
| | | int count = checkOrderDetlService.selectCount(new EntityWrapper<InventoryCheckOrderDetl>() |
| | | .eq("order_no", inventoryCheckOrder.getOrderNo()).isNull("check_anfme")); |
| | | if (count>0){ |
| | | throw new CoolException("有未完成的盘点任务"); |
| | | } |
| | | |
| | | List<InventoryCheckOrderDetl> checkOrderProfitDetls = checkOrderDetlService.selectList(new EntityWrapper<InventoryCheckOrderDetl>() |
| | | .eq("order_no", inventoryCheckOrder.getOrderNo()) |
| | | .addFilter("anfme < check_anfme")); |
| | | if (!checkOrderProfitDetls.isEmpty()){ |
| | | //获取盘盈单param |
| | | InventoryErpParam erpProfitParam = getErpProfitParam(inventoryCheckOrder, checkOrderProfitDetls); |
| | | uploadErp(erpProfitParam); |
| | | } |
| | | |
| | | List<InventoryCheckOrderDetl> checkOrderDeficitDetls = checkOrderDetlService.selectList(new EntityWrapper<InventoryCheckOrderDetl>() |
| | | .eq("order_no", inventoryCheckOrder.getOrderNo()) |
| | | .addFilter("anfme > check_anfme")); |
| | | |
| | | if (!checkOrderDeficitDetls.isEmpty()){ |
| | | //获取盘亏单param |
| | | InventoryErpParam erpDeficitParam = getErpDeficitParam(inventoryCheckOrder, checkOrderDeficitDetls); |
| | | uploadErp(erpDeficitParam); |
| | | } |
| | | |
| | | inventoryCheckOrder.setStatus("2"); |
| | | if (!checkOrderService.updateById(inventoryCheckOrder)){ |
| | | throw new CoolException("状态更新失败"); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | public void uploadErp(InventoryErpParam param){ |
| | | String response = ""; |
| | | boolean success = false; |
| | | try { |
| | | HashMap<String, Object> headers = new HashMap<>(); |
| | | headers.put("Content-Type", "application/json"); |
| | | response = new HttpHandler.Builder() |
| | | .setHeaders(headers) |
| | | .setUri("10.0.100.160:30108") |
| | | .setPath("web/apps/gongqi.df.dataTrans/DTInterFace/doJobWithupdateBody") |
| | | .setJson(JSON.toJSONString(param)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (jsonObject.getInteger("errcode").equals(0)) { |
| | | success = true; |
| | | } else if (jsonObject.getInteger("errcode").equals(1)) { |
| | | log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL+MesConstant.PACK_DOWN_URL, JSON.toJSONString(param), response); |
| | | throw new CoolException(jsonObject.getString("msg")); |
| | | } else { |
| | | log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL+MesConstant.PACK_DOWN_URL, JSON.toJSONString(param), response); |
| | | throw new CoolException("上报mes系统失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("fail", e); |
| | | throw new CoolException(e.getMessage()); |
| | | } finally { |
| | | try { |
| | | // 保存接口日志 |
| | | apiLogService.save( |
| | | "盘点单上报", |
| | | MesConstant.URL + MesConstant.PACK_DOWN_URL, |
| | | null, |
| | | "127.0.0.1", |
| | | JSON.toJSONString(param), |
| | | response, |
| | | success |
| | | ); |
| | | } catch (Exception e) { log.error("", e); } |
| | | } |
| | | } |
| | | |
| | | public InventoryErpParam getErpProfitParam(InventoryCheckOrder inventoryCheckOrder,List<InventoryCheckOrderDetl> checkOrderProfitDetls) { |
| | | Date date = new Date(); |
| | | InventoryErpParam erpProfitParam = new InventoryErpParam(); |
| | | InventoryErpParam.DataJson dataJson = new InventoryErpParam.DataJson(); |
| | | dataJson.setFlowCode("LIKUwms12GOTmes"); |
| | | dataJson.setTableCode("DTInventInTable_pdd"); |
| | | dataJson.setLogName("盘盈单-入库单"); |
| | | erpProfitParam.setDataJson(dataJson); |
| | | List<InventoryErpParam.UpdateJson> updateJsonList = new ArrayList<>(); |
| | | InventoryErpParam.UpdateJson updateJson = new InventoryErpParam.UpdateJson(); |
| | | updateJson.setOrderNo(inventoryCheckOrder.getOrderNo()); |
| | | updateJson.setDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date)); |
| | | List<InventoryErpParam.MatDetails> matDetails = new ArrayList<>(); |
| | | for (InventoryCheckOrderDetl checkOrderProfitDetl: checkOrderProfitDetls){ |
| | | InventoryErpParam.MatDetails matDetail = new InventoryErpParam.MatDetails(); |
| | | |
| | | Mat mat = matService.selectByMatnr(checkOrderProfitDetl.getMatnr()); |
| | | |
| | | matDetail.setMatnr(checkOrderProfitDetl.getMatnr()); |
| | | matDetail.setBatch(checkOrderProfitDetl.getBatch()); |
| | | matDetail.setSpecs(mat.getSpecs()); |
| | | Double anfme = new BigDecimal(checkOrderProfitDetl.getCheckAnfme()).subtract(new BigDecimal(checkOrderProfitDetl.getAnfme())).doubleValue(); |
| | | matDetail.setAnfme(anfme); |
| | | matDetail.setLocNo(checkOrderProfitDetl.getLocNo()); |
| | | matDetail.setWarehouse(checkOrderProfitDetl.getArea()); |
| | | matDetail.setSeq(updateJson.getMatDetails() == null?1:updateJson.getMatDetails().size()+1); |
| | | matDetails.add(matDetail); |
| | | } |
| | | updateJson.setMatDetails(matDetails); |
| | | updateJsonList.add(updateJson); |
| | | erpProfitParam.setUpdateJson(updateJsonList); |
| | | return erpProfitParam; |
| | | } |
| | | |
| | | public InventoryErpParam getErpDeficitParam(InventoryCheckOrder inventoryCheckOrder,List<InventoryCheckOrderDetl> checkOrderDeficitDetls) { |
| | | Date date = new Date(); |
| | | InventoryErpParam erpDeficitParam = new InventoryErpParam(); |
| | | InventoryErpParam.DataJson dataJson = new InventoryErpParam.DataJson(); |
| | | dataJson.setFlowCode("LIKUwms12GOTmes"); |
| | | dataJson.setTableCode("DTInventOutTable_pdd"); |
| | | dataJson.setLogName("盘亏单-出库单"); |
| | | erpDeficitParam.setDataJson(dataJson); |
| | | List<InventoryErpParam.UpdateJson> updateJsonList2 = new ArrayList<>(); |
| | | InventoryErpParam.UpdateJson updateJson2 = new InventoryErpParam.UpdateJson(); |
| | | updateJson2.setOrderNo(inventoryCheckOrder.getOrderNo()); |
| | | updateJson2.setDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date)); |
| | | List<InventoryErpParam.MatDetails> matDetails = new ArrayList<>(); |
| | | for (InventoryCheckOrderDetl checkOrderDeficitDetl: checkOrderDeficitDetls){ |
| | | InventoryErpParam.MatDetails matDetail = new InventoryErpParam.MatDetails(); |
| | | |
| | | Mat mat = matService.selectByMatnr(checkOrderDeficitDetl.getMatnr()); |
| | | |
| | | matDetail.setMatnr(checkOrderDeficitDetl.getMatnr()); |
| | | matDetail.setBatch(checkOrderDeficitDetl.getBatch()); |
| | | matDetail.setSpecs(mat.getSpecs()); |
| | | Double anfme = new BigDecimal(checkOrderDeficitDetl.getAnfme()).subtract(new BigDecimal(checkOrderDeficitDetl.getCheckAnfme())).doubleValue(); |
| | | matDetail.setAnfme(anfme); |
| | | matDetail.setLocNo(checkOrderDeficitDetl.getLocNo()); |
| | | matDetail.setWarehouse(checkOrderDeficitDetl.getArea()); |
| | | matDetail.setSeq(updateJson2.getMatDetails() == null?1:updateJson2.getMatDetails().size()+1); |
| | | matDetails.add(matDetail); |
| | | } |
| | | updateJson2.setMatDetails(matDetails); |
| | | updateJsonList2.add(updateJson2); |
| | | erpDeficitParam.setUpdateJson(updateJsonList2); |
| | | return erpDeficitParam; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void stockOut(OrderDetl orderDetl, BasDevp staNo, LocDetl locDetl, |
| | | Double curOutQty, Integer ioType, Long userId, Date now) { |
| | | // 获取库位 |