| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | |
| | | import com.core.common.*; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.param.InFormIdParam; |
| | | import com.zy.asrs.entity.param.OrderDomainParam; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.task.core.ReturnT; |
| | | import com.zy.asrs.task.kingdee.handler.LoginAuthenticationHandler; |
| | | import com.zy.common.model.DetlDto; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import com.zy.common.web.BaseController; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | |
| | | @Slf4j |
| | | @RestController |
| | | public class OrderController extends BaseController { |
| | | |
| | |
| | | private WaitPakinService waitPakinService; |
| | | @Autowired |
| | | private LocDetlService locDetlService; |
| | | @Value("${erp.address.URL}") |
| | | //端口 |
| | | private String URL; |
| | | |
| | | @Value("${erp.address.inaddress}") |
| | | //单据,商品档案地址 |
| | | private String inaddress; |
| | | |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | |
| | | @Autowired |
| | | private LoginAuthenticationHandler loginAuthenticationHandler; |
| | | |
| | | @Autowired |
| | | private MatService matService; |
| | | |
| | | @Autowired |
| | | private TagService tagService; |
| | | |
| | | |
| | | @RequestMapping(value = "/order/nav/list/auth") |
| | | @ManagerAuth |
| | |
| | | return R.ok("订单添加成功"); |
| | | } |
| | | |
| | | @RequestMapping(value = "/order/form/KingDeeadd/authtest") |
| | | @ManagerAuth(memo = "根据订单类型和订单码添加") |
| | | @Transactional |
| | | public R KingDeeformAddTest(@RequestBody OrderDomainParam param){ |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | //登录金蝶 |
| | | ReturnT<String> start = loginAuthenticationHandler.start(); |
| | | InFormIdParam inFormIdParam = new InFormIdParam(); |
| | | //数量字段ncompatible types. Found: 'java.lang.Long', required: 'char, byte, short, int, Character, Byte, Short, Integer, String, or an enum' |
| | | String anfme =null; |
| | | int i=Long.valueOf(param.getDocType()).intValue(); |
| | | switch (i){ |
| | | //采购入库 |
| | | case 13 : inFormIdParam.setFormId("STK_InStock");anfme ="FRealQty"; break; |
| | | //采购退料 |
| | | case 21 : inFormIdParam.setFormId("PUR_MRB");anfme ="FRMREALQTY"; break; |
| | | //生产领料 |
| | | case 22 : inFormIdParam.setFormId("PRD_PickMtrl");anfme ="FActualQty"; break; |
| | | //生产退料 |
| | | case 24 : inFormIdParam.setFormId("PRD_ReturnMtrl");anfme ="FQty"; break; |
| | | //生产补料 |
| | | case 25 : inFormIdParam.setFormId("PRD_FeedMtrl");anfme ="FActualQty"; break; |
| | | //直接调拨单 |
| | | case 26 : inFormIdParam.setFormId("STK_TransferDirect");anfme ="FQty"; break; |
| | | //盘盈单 |
| | | case 28 : inFormIdParam.setFormId("STK_StockCountGain");anfme ="FGainQty"; break; |
| | | //盘亏单 |
| | | case 29 : inFormIdParam.setFormId("STK_StockCountLoss");anfme ="FLossQty"; break; |
| | | //其他出库 |
| | | case 30 : inFormIdParam.setFormId("STK_MisDelivery");anfme ="FQty"; break; |
| | | //简单生产领料 |
| | | case 31 : inFormIdParam.setFormId("SP_PickMtrl");anfme ="FActualQty"; break; |
| | | //简单生产退料 |
| | | case 32 : inFormIdParam.setFormId("SP_ReturnMtrl");anfme ="FQty"; break; |
| | | //销售出库 |
| | | case 14 : inFormIdParam.setFormId("SAL_OUTSTOCK");anfme ="FRealQty"; break; |
| | | //销售退货 |
| | | case 33 : inFormIdParam.setFormId("SAL_RETURNSTOCK");anfme ="FRealQty"; break; |
| | | } |
| | | inFormIdParam.setLimit(100); |
| | | inFormIdParam.setStartRow("0"); |
| | | String FDocumentStatus = "B"; |
| | | |
| | | //条件和需要获得的结果拼接 |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("FormId", inFormIdParam.getFormId()); |
| | | jsonObject.put("Limit", inFormIdParam.getLimit()); |
| | | jsonObject.put("StartRow", inFormIdParam.getStartRow()); |
| | | //单据状态 |
| | | FDocumentStatus="B"; |
| | | //订单码 |
| | | String orderNo= param.getOrderNo(); |
| | | jsonObject.put("FilterString", "FBillNo='"+orderNo+"'and FStockId.Fname='立库'"+" and FDocumentStatus='"+FDocumentStatus+"'"); |
| | | jsonObject.put("FieldKeys", "FBillNo,FCreateDate,FMaterialId.FNumber,FMaterialId.FName,FMaterialId.FSpecification,"+anfme+",FDocumentStatus"); |
| | | // FBillNo :单据编号; |
| | | // FCreateDate :单据创建时间; |
| | | // FMaterialId.FNumber : 物料编码; |
| | | // FMaterialName :物料名称; |
| | | // FMaterialId.FSpecification:物料规格 |
| | | // anfme : 物料数量 |
| | | // FDocumentStatus :单据状态; |
| | | JSONObject jsonObject1 = new JSONObject(); |
| | | jsonObject1.put("data", jsonObject); |
| | | String add = jsonObject1.toJSONString(); |
| | | |
| | | //上报 |
| | | String response = ""; |
| | | boolean success = false; |
| | | try { |
| | | //获取Cookie值 |
| | | HashMap<String, Object> headers = new HashMap<>(); |
| | | headers.put("Cookie", start.getContent()); |
| | | response = new HttpHandler.Builder() |
| | | .setHeaders(headers) |
| | | .setUri(URL) |
| | | .setPath(inaddress) |
| | | .setJson(add) |
| | | .build() |
| | | .doPost(); |
| | | JSONArray data = JSON.parseArray(response); |
| | | if(data.getJSONArray(0).get(0).toString().length()<20){ |
| | | success = true; |
| | | for (int j = 0; j < data.size(); j++) { |
| | | JSONArray jsonArray = data.getJSONArray(j); |
| | | Order order = orderService.selectByNo(jsonArray.get(0).toString()); |
| | | if (Cools.isEmpty(order)) { |
| | | DocType docType = docTypeService.selectById(param.getDocType()); |
| | | Date now = new Date(); |
| | | // 单据主档 |
| | | order = new Order( |
| | | String.valueOf(snowflakeIdWorker.nextId()), // 编号[非空] |
| | | jsonArray.get(0).toString(), // 订单编号 |
| | | DateUtils.convert(now), // 单据日期 |
| | | docType.getDocId(), // 单据类型 |
| | | 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 // 备注 |
| | | ); |
| | | //对美国时间进行转换 |
| | | DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME; |
| | | LocalDateTime dateTime = LocalDateTime.parse(jsonArray.get(1).toString(), formatter); |
| | | String format = dateFormat.format(dateTime); |
| | | Date date = sdf.parse(format); |
| | | //最新抓取时间 |
| | | docType.setCreateTime(date); |
| | | docTypeService.update(docType, new EntityWrapper<DocType>().eq("doc_id", param.getDocType())); |
| | | if (!orderService.insert(order)) { |
| | | throw new CoolException("生成单据主档失败,请联系管理员"); |
| | | } |
| | | } |
| | | //物料编码 |
| | | Mat mat = matService.selectByMatnr(jsonArray.get(2).toString()); |
| | | if (Cools.isEmpty(mat)) { |
| | | throw new CoolException(jsonArray.get(2).toString() + "编号商品检索失败,请先添加商品"); |
| | | } |
| | | OrderDetl orderDetl1 = orderDetlService.selectOne(new EntityWrapper<OrderDetl>().eq("order_no", jsonArray.get(0).toString()).eq("matnr", jsonArray.get(2).toString())); |
| | | if (!Cools.isEmpty(orderDetl1)) { |
| | | continue; |
| | | } |
| | | DocType docType = docTypeService.selectById(param.getDocType()); |
| | | OrderDetl orderDetl = new OrderDetl(); |
| | | orderDetl.sync(mat); |
| | | orderDetl.setBatch(null); |
| | | orderDetl.setAnfme(Double.parseDouble(jsonArray.get(5).toString())); |
| | | orderDetl.setOrderId(order.getId()); |
| | | orderDetl.setOrderNo(order.getOrderNo()); |
| | | orderDetl.setCreateBy(9527L); |
| | | orderDetl.setCreateTime(new Date()); |
| | | orderDetl.setUpdateBy(9527L); |
| | | orderDetl.setUpdateTime(new Date()); |
| | | orderDetl.setStatus(1); |
| | | orderDetl.setQty(0.0D); |
| | | DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME; |
| | | LocalDateTime dateTime = LocalDateTime.parse(jsonArray.get(1).toString(), formatter); |
| | | String format = dateFormat.format(dateTime); |
| | | Date date = sdf.parse(format); |
| | | //最新抓取时间 |
| | | docType.setCreateTime(date); |
| | | if (!orderDetlService.insert(orderDetl)) { |
| | | throw new CoolException("生成单据明细失败,请联系管理员"); |
| | | } |
| | | } |
| | | }else{ |
| | | throw new CoolException("没有找到指定订单,请联系管理员"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("fail", e); |
| | | // TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | } finally { |
| | | try { |
| | | // 保存接口日志 |
| | | apiLogService.save( |
| | | "轮询数据", |
| | | URL + inaddress, |
| | | null, |
| | | "127.0.0.1", |
| | | add, |
| | | response, |
| | | success |
| | | ); |
| | | } catch (Exception e) { |
| | | log.error("", e); |
| | | } |
| | | } |
| | | return R.ok("订单添加成功"); |
| | | } |
| | | |
| | | |
| | | |
| | | |