From 59e91a4e9ddaf23cebb12993c774aa899ab22d16 Mon Sep 17 00:00:00 2001
From: 郑永安 <zyazyz250@sina.com>
Date: Mon, 19 Jun 2023 14:22:45 +0800
Subject: [PATCH] 描述
---
src/main/java/com/gk/firework/Scheduls/DL/ReportOrderTask.java | 382 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 382 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/gk/firework/Scheduls/DL/ReportOrderTask.java b/src/main/java/com/gk/firework/Scheduls/DL/ReportOrderTask.java
new file mode 100644
index 0000000..6d00523
--- /dev/null
+++ b/src/main/java/com/gk/firework/Scheduls/DL/ReportOrderTask.java
@@ -0,0 +1,382 @@
+package com.gk.firework.Scheduls.DL;
+
+import com.alibaba.fastjson.JSONObject;
+import com.gk.firework.Domain.CustomerInfo;
+import com.gk.firework.Domain.Enterprise;
+import com.gk.firework.Domain.SaleOrderDetailInfo;
+import com.gk.firework.Domain.SaleOrderInfo;
+import com.gk.firework.Domain.Utils.BeanUtils;
+import com.gk.firework.Domain.Utils.HttpUtils;
+import com.gk.firework.Domain.Utils.StringUtils;
+import com.gk.firework.Service.*;
+import org.apache.axis.client.Call;
+import org.apache.axis.client.Service;
+import org.apache.axis.encoding.XMLType;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+import org.joda.time.DateTime;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import sun.misc.BASE64Decoder;
+import sun.misc.BASE64Encoder;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * @author : jingjy
+ * @date : 2022/1/26 17:15
+ */
+@Configuration
+@EnableScheduling
+//@ConditionalOnProperty(prefix = "scheduling",name = "enabled",havingValue = "true")
+public class ReportOrderTask {
+ private Logger logger = LogManager.getLogger(com.gk.firework.Scheduls.WarningTask.StockWarnTask.class);
+ private static final String url = "http://118.190.117.180:8888";
+ @Value("${com.gk.firework.schedules.single.switch}")
+ private Boolean switchBtn;
+ @Autowired
+ EnterpriseService enterpriseService;
+ @Autowired
+ SaleOrderService saleOrderService;
+ @Autowired
+ SaleOrderDetailService saleOrderDetailService;
+ @Autowired
+ StockService stockService;
+ @Autowired
+ CustomerService customerService;
+
+ //@Scheduled(cron = "0 0 2 * * ?") //每天凌晨两点执行一次
+ @Scheduled(cron = "0/10 * * * * ?") //每隔10秒执行一次
+ private void reportOrder() {
+ if (!switchBtn) return;
+ //1.获取需要上传的企业信息
+ List<Enterprise>enterprises = enterpriseService.selectSaleEnterpriseForUpload();
+ for (Enterprise enterprise : enterprises){
+ if (StringUtils.isBlank(enterprise.getDlcompanycode()) || StringUtils.isBlank(enterprise.getDeviceid())){
+ continue;
+ }
+
+ //2.获取握手密码
+ DlResult result = getHandshake(enterprise);
+ if (result == null || StringUtils.isBlank(result.getFwdz()) || StringUtils.isBlank(result.getWsmm())){
+ continue;
+ }
+ //获取企业未上传销售数据
+ List<SaleOrderInfo> orderInfos = saleOrderService.getWaitUploadOrderByEnterprise(enterprise);
+ if (orderInfos == null || orderInfos.size() == 0){
+ continue;
+ }
+
+ uploadOrders(orderInfos,result,enterprise);
+ }
+
+ //3.上传数据
+ //4.处理上传结果
+
+ }
+
+ private DlResult getHandshake(Enterprise enterprise){
+ String respnse = null;
+ DlResult result = new DlResult();
+ Map params = new HashMap();//请求参数
+ params.put("sbid", enterprise.getDeviceid());//
+ params.put("dwdm", enterprise.getDlcompanycode());//
+
+ try {
+ respnse = HttpUtils.net(url+"/lsjk/Sbrz", params, "GET");
+ JSONObject jsonResult = JSONObject.parseObject(respnse);
+ String wsmm = jsonResult.getString("wsmm");
+ String fwdz = jsonResult.getString("fwdz");
+ result.setFwdz(fwdz);
+ result.setWsmm(wsmm);
+ return result;
+ }catch (Exception e){
+ return result;
+ }
+ }
+
+ public void uploadOrders(List<SaleOrderInfo>orderInfos, DlResult result, Enterprise enterprise){
+
+ String servicesUrl = url+result.getFwdz();
+ for (SaleOrderInfo orderInfo : orderInfos){
+ Service service = new Service();
+ Call call = null;
+ /**
+ * <?xml version="1.0" encoding="GBK"?>
+ * <sb>
+ * <sjbs>YH</sjbs><!--数据标注 -->
+ * <jylx>XX</jylx><!-- 交易类型(03-运输入库、09-退货、10-零散销售) -->
+ * <sjscsj>20100630151617</sjscsj><!--数据生成时间(精确到秒) -->
+ * <dwdm>XXXX</dwdm><!--单位代码(和烟花系统确定对应关系) -->
+ * <cjsbid>XXXX</cjsbid ><!--条码采集设备ID(定长32,不足补0) -->
+ * <zjlx>1</zjlx><!--证件类型(1-身份证、2-其他) -->
+ * <zjhm>XXXX</zjhm><!--证件号码,定长18 -->
+ * <tms>
+ * <bh>XXX</bh><!--条码编号-->
+ * <sj>20100630151617</sj><!--采集时间(精确到秒)-->
+ * </tms>
+ * </sb>
+ */
+ try {
+ List<SaleOrderDetailInfo> detailInfos = saleOrderDetailService.selectByOrderCode(orderInfo.getCode());
+ CustomerInfo customerInfo = customerService.getById(orderInfo.getCustomer());
+ String date = new DateTime(orderInfo.getCreatedat()).toString("yyyyMMddHHmmss");
+ ReportEntity reportEntity = new ReportEntity();
+ reportEntity.setSjbs("YH");
+ reportEntity.setJylx("10");
+ reportEntity.setSjscsj(date);
+ reportEntity.setDwdm(enterprise.getDlcompanycode());
+ reportEntity.setCjsbid(enterprise.getDeviceid());
+ reportEntity.setZjlx("1");
+ reportEntity.setZjhm(customerInfo.getIdcardnum());
+
+ List<TmsEntity>tmsEntities = new ArrayList<>();
+ for (SaleOrderDetailInfo detailInfo : detailInfos){
+ TmsEntity tmsEntity = new TmsEntity(detailInfo.getDirectioncode(),date);
+ tmsEntities.add(tmsEntity);
+ }
+ reportEntity.setTms(tmsEntities);
+ String xml = BeanUtils.beanToXml(reportEntity,ReportEntity.class);
+ //String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><sb><sjbs>YH</sjbs><jylx>03</jylx><sjscsj>20160203221055</sjscsj><dwdm>ADW000000008422</dwdm><cjsbid>ADW000000008422652722194006466</cjsbid><zjlx>1</zjlx><zjhm>220283198201021916</zjhm><tms><bh>11230I4WY0F62203824</bh><sj>20160114195153</sj></tms><tms><bh>11230I4WY0F62203819</bh><sj>20160114195153</sj></tms><tms><bh>11230I4WY0F62203822</bh><sj>20160114195153</sj></tms><tms><bh>11230I4WY0F62203826</bh><sj>20160114195153</sj></tms><tms><bh>11230I4WY0F62203820</bh><sj>20160114195153</sj></tms><tms><bh>11230I4WY0F62203823</bh><sj>20160114195153</sj></tms><tms><bh>11230I4WY0F62203818</bh><sj>20160114195153</sj></tms><tms><bh>11230I4WY0F62203817</bh><sj>20160114195153</sj></tms><tms><bh>11230I4WY0F62203821</bh><sj>20160114195153</sj></tms></sb>";
+ BASE64Encoder encoder = new BASE64Encoder();
+ //String str = encoder.encode(sb.toString().trim().getBytes("utf-8"));
+ String str = encoder.encode(xml.getBytes("UTF-8"));
+ String cjsbid = enterprise.getDeviceid();//设备ID
+ String dwdm = enterprise.getDlcompanycode();//单位代码
+ String wsmm = result.getWsmm();//握手密码
+ call = (Call) service.createCall();
+ call.setTargetEndpointAddress(servicesUrl);
+ call.setTimeout(5 * 60 * 1000);// 超时设定5分钟抛出异常
+ call.setOperationName("lssjsb");// 调用方法
+ call.setReturnType(XMLType.XSD_STRING);// 指定返回类型
+ call.addParameter("str", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);// 接口的参数
+ call.addParameter("sbid", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);// 接口的参数
+ call.addParameter("dwdm", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);// 接口的参数
+ call.addParameter("wsmm", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);// 接口的参数
+ String callResult = (String) call.invoke(new Object[] { str,cjsbid, dwdm,wsmm });// 调用服务并返回存在的对应数据
+ BASE64Decoder decoder = new BASE64Decoder();
+ String xmlCode = null;
+ try {
+ xmlCode = new String(decoder.decodeBuffer(callResult));
+ DlReportResult reportResult = (DlReportResult) BeanUtils.xmlToBean(xmlCode,DlReportResult.class);
+ DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyyMMddHHmmss");
+ DateTime dateTime = dateTimeFormatter.parseDateTime(reportResult.getSjscsj());
+ Date uploadAt = dateTime.toDate();
+ orderInfo.setIsupload((byte)1);
+ orderInfo.setUploadat(uploadAt);
+ orderInfo.setReturncode(reportResult.getFhlx());
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ orderInfo.setReturncode("999");
+ orderInfo.setIsupload((byte)2);
+ }
+ } catch (Exception e) {
+ System.out.println("调用webservice失败!" + e.getMessage());
+ orderInfo.setReturncode("998");
+ orderInfo.setIsupload((byte)2);
+ }
+ saleOrderService.updateById(orderInfo);
+ }
+
+
+ }
+}
+
+class DlResult{
+ private String wsmm;
+ private String fwdz;
+
+ DlResult() {
+ }
+
+ public DlResult(String wsmm, String fwdz) {
+ this.wsmm = wsmm;
+ this.fwdz = fwdz;
+ }
+
+ public String getWsmm() {
+ return wsmm;
+ }
+
+ public void setWsmm(String wsmm) {
+ this.wsmm = wsmm;
+ }
+
+ public String getFwdz() {
+ return fwdz;
+ }
+
+ public void setFwdz(String fwdz) {
+ this.fwdz = fwdz;
+ }
+
+}
+
+@XmlRootElement(name="fh")
+class ReportEntity{
+ private String sjbs;
+ private String jylx;
+ private String sjscsj;
+ private String dwdm;
+ private String cjsbid;
+ private String zjlx;
+ private String zjhm;
+ private List<TmsEntity> tms;
+
+ public String getSjbs() {
+ return sjbs;
+ }
+
+ public void setSjbs(String sjbs) {
+ this.sjbs = sjbs;
+ }
+
+ public String getJylx() {
+ return jylx;
+ }
+
+ public void setJylx(String jylx) {
+ this.jylx = jylx;
+ }
+
+ public String getSjscsj() {
+ return sjscsj;
+ }
+
+ public void setSjscsj(String sjscsj) {
+ this.sjscsj = sjscsj;
+ }
+
+ public String getDwdm() {
+ return dwdm;
+ }
+
+ public void setDwdm(String dwdm) {
+ this.dwdm = dwdm;
+ }
+
+ public String getCjsbid() {
+ return cjsbid;
+ }
+
+ public void setCjsbid(String cjsbid) {
+ this.cjsbid = cjsbid;
+ }
+
+ public String getZjlx() {
+ return zjlx;
+ }
+
+ public void setZjlx(String zjlx) {
+ this.zjlx = zjlx;
+ }
+
+ public String getZjhm() {
+ return zjhm;
+ }
+
+ public void setZjhm(String zjhm) {
+ this.zjhm = zjhm;
+ }
+
+ @XmlElement(name="tms")
+ public List<TmsEntity> getTms() {
+ return tms;
+ }
+
+ public void setTms(List<TmsEntity> tms) {
+ this.tms = tms;
+ }
+}
+
+@XmlRootElement(name="tms")
+class TmsEntity{
+ private String bh;
+
+ private String sj;
+
+ public String getBh() {
+ return bh;
+ }
+
+ public void setBh(String bh) {
+ this.bh = bh;
+ }
+
+ public TmsEntity() {
+ }
+
+ public TmsEntity(String bh, String sj) {
+ this.bh = bh;
+ this.sj = sj;
+ }
+
+ public String getSj() {
+ return sj;
+ }
+
+ public void setSj(String sj) {
+ this.sj = sj;
+ }
+}
+
+@XmlRootElement(name="fh")
+class DlReportResult{
+ private String sjbs;
+
+ private String cjsbid;
+
+ private String sjscsj;
+
+ private String fhlx;
+
+ private String fhsj;
+
+ public String getSjbs() {
+ return sjbs;
+ }
+
+ public void setSjbs(String sjbs) {
+ this.sjbs = sjbs;
+ }
+
+ public String getCjsbid() {
+ return cjsbid;
+ }
+
+ public void setCjsbid(String cjsbid) {
+ this.cjsbid = cjsbid;
+ }
+
+ public String getSjscsj() {
+ return sjscsj;
+ }
+
+ public void setSjscsj(String sjscsj) {
+ this.sjscsj = sjscsj;
+ }
+
+ public String getFhlx() {
+ return fhlx;
+ }
+
+ public void setFhlx(String fhlx) {
+ this.fhlx = fhlx;
+ }
+
+ public String getFhsj() {
+ return fhsj;
+ }
+
+ public void setFhsj(String fhsj) {
+ this.fhsj = fhsj;
+ }
+}
--
Gitblit v1.9.2