| | |
| | | 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.service.impl.ServiceImpl; |
| | | import com.core.common.Cools; |
| | |
| | | import com.zy.common.model.OrderDto; |
| | | import com.zy.common.model.OrderMergeVo; |
| | | import com.zy.common.service.erp.ErpService; |
| | | import com.zy.common.utils.HttpHandler; |
| | | 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 java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | @Slf4j |
| | | @Service("orderService") |
| | |
| | | @Autowired |
| | | private WrkDetlService wrkDetlService; |
| | | @Autowired |
| | | private AgvWrkDetlService agvWrkDetlService; |
| | | @Autowired |
| | | private MatService matService; |
| | | @Autowired |
| | | private ErpService erpService; |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | @Autowired |
| | | private WaitPakinService waitPakinService; |
| | | @Autowired |
| | | private AgvWaitPakinService agvWaitPakinService; |
| | | @Autowired |
| | | private ManPakOutService manPakOutService; |
| | | |
| | | @Value("${u8.url}") |
| | | private String url; |
| | | |
| | | @Value("${u8.orderReportPath}") |
| | | private String orderReportPath; |
| | | |
| | | @Override |
| | | public Order selectByNo(String orderNo) { |
| | |
| | | @Override |
| | | public void checkComplete(String orderNo) { |
| | | Order order = this.selectByNo(orderNo); |
| | | if(Cools.isEmpty(order)){ |
| | | return; |
| | | } |
| | | if (order.getSettle() >= 4L) { |
| | | return; |
| | | } |
| | | List<OrderDetl> orderDetls = orderDetlMapper.selectList(new EntityWrapper<OrderDetl>().eq("order_id", order.getId())); |
| | | // 作业数量是否等于数量 |
| | | boolean complete = true; |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | if (orderDetl.getAnfme() > orderDetl.getQty()) { |
| | |
| | | break; |
| | | } |
| | | } |
| | | if (complete && wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().like("order_no", orderNo)) == 0) { |
| | | // 出库订单重新整理明细 |
| | | DocType docType = docTypeService.selectById(order.getDocType()); |
| | | if (null != docType && docType.getPakout() == 1) { |
| | | // 重组明细 |
| | | if (!orderDetlService.delete(new EntityWrapper<OrderDetl>().eq("order_id", order.getId()))) { |
| | | throw new CoolException("重整出库订单【orderNo = " + order.getOrderNo() + "】明细失败"); |
| | | } |
| | | List<WrkDetl> wrkDetls = wrkDetlService.selectAndLogByOrderNo(orderNo); |
| | | for (WrkDetl wrkDetl : wrkDetls) { |
| | | OrderDetl orderDetl = new OrderDetl(); |
| | | orderDetl.sync(wrkDetl); |
| | | orderDetl.setQty(orderDetl.getAnfme()); |
| | | orderDetl.setOrderId(order.getId()); |
| | | orderDetl.setOrderNo(orderNo); |
| | | orderDetl.setStatus(1); |
| | | orderDetl.setCreateTime(order.getCreateTime()); |
| | | orderDetl.setCreateBy(order.getCreateBy()); |
| | | orderDetl.setUpdateTime(order.getUpdateTime()); |
| | | orderDetl.setUpdateBy(order.getUpdateBy()); |
| | | if (!orderDetlService.insert(orderDetl)) { |
| | | throw new CoolException("重整出库订单【orderNo = " + order.getOrderNo() + "】明细失败"); |
| | | } |
| | | } |
| | | } |
| | | // 如果 作业数量等于单据总数量 && 工作明细档中无该单据的数据 && AGV工作明细档中无该单据的数据 |
| | | int count = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("order_no", orderNo)); |
| | | boolean wrkDeltExist = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().like("order_no", orderNo)) < 1; |
| | | boolean agvWrkDetlExist = agvWrkDetlService.selectCount(new EntityWrapper<AgvWrkDetl>().like("order_no",orderNo)) < 1; |
| | | boolean waitPakinExist = agvWaitPakinService.selectCount(new EntityWrapper<AgvWaitPakin>().like("order_no",orderNo)) < 1; |
| | | |
| | | ManPakOut manPakOut = manPakOutService.selectByOrderWithName(orderNo); |
| | | |
| | | boolean manPakoutExist = Cools.isEmpty(manPakOut) || (manPakOut.getPayment() != null && manPakOut.getPayment() == 1); |
| | | if (complete && wrkDeltExist && agvWrkDetlExist && waitPakinExist && manPakoutExist) { |
| | | if (!this.updateSettle(order.getId(), 4L, null)) { |
| | | throw new CoolException("修改订单【orderNo = " + order.getOrderNo() + "】状态为已完成失败"); |
| | | } |
| | |
| | | } |
| | | for (DetlDto detlDto : detlDtos) { |
| | | // 修改订单明细数量 |
| | | if (!orderDetlService.increase(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getAnfme())) { |
| | | if (!orderDetlService.increase(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getAnfme(),detlDto.getCsocode(),detlDto.getIsoseq())) { |
| | | throw new CoolException("修改单据明细数量失败"); |
| | | } |
| | | } |
| | |
| | | throw new CoolException("删除单据失败"); |
| | | } |
| | | orderDetlService.delete(new EntityWrapper<OrderDetl>().eq("order_id", orderId)); |
| | | } |
| | | |
| | | public void report(Long orderId, String username) { |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | Order order = this.selectById(orderId); |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("id",order.getOrderNo()); |
| | | param.put("dDate",sdf.format(new Date())); |
| | | param.put("cHandler",username); |
| | | |
| | | List<Map<String,Object>> orderDetlsParam = new ArrayList<>(); |
| | | param.put("orderDetails",orderDetlsParam); |
| | | |
| | | List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(orderId); |
| | | |
| | | for (OrderDetl orderDetl : orderDetls){ |
| | | Map<String, Object> odMap = new HashMap<>(); |
| | | odMap.put("autoid",orderDetl.getItemNum()); |
| | | odMap.put("iQuantity",orderDetl.getQty()); |
| | | orderDetlsParam.add(odMap); |
| | | } |
| | | |
| | | int code = doHttpRequest(param, "单据审核", url, orderReportPath, null, "127.0.0.1"); |
| | | //int code = doHttpRequest(param, "单据审核", "localhost:8080", "/test/report", null, "127.0.0.1"); |
| | | if(code == 0){ |
| | | order.setSettle(6L); |
| | | this.updateById(order); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | return this.baseMapper.selectorderNoL(orderNo); |
| | | } |
| | | |
| | | @Override |
| | | public List<Order> selectToBeHistoryOrder() { |
| | | return this.selectList(new EntityWrapper<Order>().eq("status",1).ge("settle",6)); |
| | | |
| | | //return this.baseMapper.selectToBeHistoryOrder(); |
| | | } |
| | | |
| | | private int doHttpRequest(Object requestParam, String namespace, String url, String path, String appkey, String ip){ |
| | | String response = ""; |
| | | boolean success = false; |
| | | |
| | | try { |
| | | response = new HttpHandler.Builder() |
| | | .setUri(url) |
| | | .setPath(path) |
| | | .setJson(JSONObject.toJSONString(requestParam)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | |
| | | if(Cools.isEmpty(jsonObject.get("errCode"))){ |
| | | throw new CoolException(jsonObject.get("Message").toString()); |
| | | } |
| | | |
| | | int code = (int) jsonObject.get("errCode"); |
| | | if(code != 0){ |
| | | throw new CoolException(jsonObject.get("errMsg").toString()); |
| | | } |
| | | success = true; |
| | | return code; |
| | | }catch (Exception e){ |
| | | log.error(e.getMessage()); |
| | | throw new CoolException("调用接口响应错误"); |
| | | }finally { |
| | | apiLogService.save( |
| | | namespace, |
| | | url + path, |
| | | appkey, |
| | | ip, |
| | | JSON.toJSONString(JSONObject.toJSONString(requestParam)), |
| | | response, |
| | | success |
| | | ); |
| | | } |
| | | |
| | | } |
| | | } |