| | |
| | | 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.plugins.Page; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | | import com.core.common.SpringUtils; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.Order; |
| | | import com.zy.asrs.entity.param.OpenOrderPakinParam; |
| | | import com.zy.asrs.entity.result.OrderRsult; |
| | | import com.zy.asrs.mapper.OrderDetlMapper; |
| | | import com.zy.asrs.entity.OrderDetl; |
| | | import com.zy.asrs.service.ApiLogService; |
| | | import com.zy.asrs.service.OrderDetlService; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.zy.asrs.service.OrderService; |
| | | import com.zy.common.model.DetlDto; |
| | | 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.text.Format; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Slf4j |
| | | @Service("orderDetlService") |
| | | public class OrderDetlServiceImpl extends ServiceImpl<OrderDetlMapper, OrderDetl> implements OrderDetlService { |
| | | |
| | | @Autowired |
| | | private OrderService orderService; |
| | | @Autowired |
| | | private OrderDetlService orderDetlService; |
| | | |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | @Value("${erp.switch.ReviewOrderSwitch}") |
| | | private Boolean switchReviewOrderSwitch; |
| | | @Value("${erp.address.URL}") |
| | | private String URL; |
| | | @Value("${erp.address.inaddressSave}") |
| | | private String inaddressSave; |
| | | @Value("${erp.address.outaddressSave}") |
| | | private String outaddressSave; |
| | | |
| | | @Override |
| | | public List<OrderDetl> selectByOrderId(Long orderId) { |
| | | return this.selectList(new EntityWrapper<OrderDetl>().eq("order_id", orderId)); |
| | | } |
| | | |
| | | @Override |
| | | public Page<OrderDetl> getPakoutPage(Page<OrderDetl> page) { |
| | | page.setRecords(baseMapper.getPakoutPage(page.getCondition())); |
| | | page.setTotal(baseMapper.getPakoutPageCount(page.getCondition())); |
| | | return page; |
| | | } |
| | | |
| | | @Override |
| | |
| | | public OrderDetl findByLook(List<OrderDetl> orderDetls, Long orderId, String matnr, String batch) { |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | if (orderDetl.getOrderId().equals(orderId) && orderDetl.getMatnr().equals(matnr)) { |
| | | if (!Cools.isEmpty(batch)) { |
| | | if (orderDetl.getBatch().equals(batch)) { |
| | | return orderDetl; |
| | | } |
| | | } else { |
| | | if (Cools.eq(batch, orderDetl.getBatch())) { |
| | | return orderDetl; |
| | | } |
| | | } |
| | |
| | | public boolean increase(Long orderId, String matnr, String batch, Double qty) { |
| | | return this.baseMapper.increase(orderId, matnr, batch, qty) > 0; |
| | | } |
| | | |
| | | @Override |
| | | public boolean decrease(String orderNo, String matnr, String batch, Double qty) { |
| | | int decrease = this.baseMapper.decrease(orderNo, matnr, batch, qty); |
| | | if (decrease == 0) { |
| | | return this.baseMapper.decrease(orderNo, matnr, null, qty) > 0; |
| | | } else { |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public boolean modifyStatus(Long orderId, Integer status) { |
| | | return this.baseMapper.modifyStatus(orderId, status) > 0; |
| | | } |
| | | |
| | | @Override |
| | | public boolean addToLogTable(OrderDetl orderDetl) { |
| | | return this.baseMapper.addToLogTable(orderDetl) > 0; |
| | | } |
| | | |
| | | @Override |
| | | public boolean increaseQtyByOrderNo(String orderNo, String matnr, String batch, Double qty) { |
| | | return this.baseMapper.increaseQtyByOrderNo(orderNo, matnr, batch, qty) > 0; |
| | | } |
| | | |
| | | /** |
| | | * 入出库任务生成时,更新单据表中作业数量 |
| | | * @param orderId |
| | | * @param matnr |
| | | * @param batch |
| | | * @param workQty |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean increaseWorkQty(Long orderId, String matnr, String batch, Double workQty) { |
| | | return this.baseMapper.increaseWorkQty(orderId, matnr, batch, workQty) > 0; |
| | | } |
| | | |
| | | @Override |
| | | public R U8Reporting(long id, Integer sts) { |
| | | String ERPPath=inaddressSave; |
| | | String ERPName=""; |
| | | OrderDetl orderDetl = orderDetlService.selectById(id); |
| | | Order order = orderService.selectByNo(orderDetl.getOrderNo()); |
| | | if (order==null){ |
| | | return R.error("没有找到改订单 id="+id); |
| | | } |
| | | OrderRsult orderRsult = new OrderRsult(); |
| | | OrderRsult.Login login = new OrderRsult.Login(); |
| | | OrderRsult.HeadTable headTable = new OrderRsult.HeadTable(); |
| | | OrderRsult.BodyTable bodyTable = new OrderRsult.BodyTable(); |
| | | login.setSAccID("999"); //账套号 固定 |
| | | login.setSUserID("sys");//U8登陆账号 固定 |
| | | login.setSPassword("123456");//U8登陆密码 固定 |
| | | login.setSServer("10.1.9.20");//U8服务器地址 固定 |
| | | orderRsult.setLogin(login); |
| | | orderRsult.setVerifier("sys");//单据类型 固定 |
| | | orderRsult.setCommandType(sts.equals(1) ? "新增" : "关闭");//操作类型 固定 |
| | | orderRsult.setVouchName("调拨单");//审核人 填写则自动审核 |
| | | |
| | | headTable.setCtvcode(order.getOrderNo());//调拨单号 默认 |
| | | //时间 |
| | | Date date=new Date(); |
| | | Format formatter = new SimpleDateFormat("yyyy-MM-dd"); |
| | | String format = formatter.format(date); |
| | | headTable.setDtvdate(format);//单据日期 |
| | | headTable.setCmaker("sys");//制单人名称 |
| | | headTable.setVt_id("89");//模板号 默认 |
| | | |
| | | headTable.setCiwhcode("");//转入仓库编码 |
| | | headTable.setCowhcode("");//转出仓库编码 |
| | | headTable.setCordcode("");//出库类别编码 默认 |
| | | headTable.setCirdcode("");//入库类别编码 默认 |
| | | headTable.setCodepcode("");//转出部门编码 |
| | | headTable.setCidepcode("");//转入部门编码 |
| | | |
| | | |
| | | |
| | | bodyTable.setIrowno(orderDetl.getModel());//行号 |
| | | bodyTable.setCinvcode(orderDetl.getMatnr());//存货编码 |
| | | bodyTable.setCtvbatch(Cools.isEmpty(orderDetl.getBatch()) ? "" : orderDetl.getBatch());//批号(特殊说明) |
| | | Double qty = orderDetl.getQty()-(Cools.isEmpty(orderDetl.getUnits())?0:orderDetl.getUnits()); |
| | | bodyTable.setItvquantity(String.valueOf(qty));//完成件数 |
| | | bodyTable.setCinposcode("1-1");//立库源货位 |
| | | bodyTable.setCoutposcode("");//目标货位 |
| | | bodyTable.setItrsid(orderDetl.getMemo());//行主键 |
| | | bodyTable.setEditprop(sts.equals(1) ? "A" : "B");//状态 A 新增 |
| | | |
| | | |
| | | if (order.getDocType()>10L) { |
| | | ERPPath=outaddressSave; |
| | | } |
| | | ERPName=order.getDocType$(); |
| | | String response = ""; |
| | | boolean success = false; |
| | | try { |
| | | |
| | | response = new HttpHandler.Builder() |
| | | // .setHeaders(map) |
| | | .setUri(URL) |
| | | .setPath(ERPPath) |
| | | .setJson(JSON.toJSONString(orderRsult)) |
| | | .build() |
| | | .doPost(); |
| | | System.out.println("response:"+response); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | |
| | | if (jsonObject.getInteger("code").equals(200)) { |
| | | orderDetl.setUnits(qty+orderDetl.getUnits()); |
| | | orderDetl.setStatus(sts); |
| | | orderDetlService.updateById(orderDetl); |
| | | success = true; |
| | | } else { |
| | | log.error("请求接口失败!!!url:{};request:{};response:{}", URL+"/"+ERPPath, JSON.toJSONString(orderRsult), response); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("请求接口失败!!!url:{};request:{};response:{}", URL+"/"+ERPPath, JSON.toJSONString(orderRsult), response); |
| | | } finally { |
| | | try { |
| | | // 保存接口日志 |
| | | ApiLogService apiLogService = SpringUtils.getBean(ApiLogService.class); |
| | | apiLogService.save( |
| | | "上报"+ERPName, |
| | | URL +"/"+ ERPPath, |
| | | null, |
| | | "127.0.0.1", |
| | | JSON.toJSONString(orderRsult), |
| | | response, |
| | | success |
| | | ); |
| | | } catch (Exception e) { |
| | | log.error("", e); |
| | | } |
| | | } |
| | | if (!success) { |
| | | return R.error(); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | } |