Browse Source

新增方式,检测ERP发货提醒取消状态对应B2B单据的情况

hejq 7 years ago
parent
commit
af1c475ca6

+ 19 - 0
src/main/java/com/uas/platform/b2b/erp/controller/PurchaseNotifyController.java

@@ -6,6 +6,7 @@ import com.uas.platform.b2b.erp.model.AcceptNotify;
 import com.uas.platform.b2b.erp.model.AcceptNotifyConfirm;
 import com.uas.platform.b2b.erp.model.AcceptNotifyVerify;
 import com.uas.platform.b2b.erp.model.PurchaseNotify;
+import com.uas.platform.b2b.erp.service.NoticeRecordService;
 import com.uas.platform.b2b.erp.service.PurchaseNotifyService;
 import com.uas.platform.b2b.erp.support.ErpBufferedLogger;
 import com.uas.platform.b2b.model.PurchaseNotice;
@@ -44,6 +45,9 @@ public class PurchaseNotifyController {
 	@Autowired
 	private PurchaseNoticeService purchaseNoticeService;
 
+	@Autowired
+    private NoticeRecordService noticeRecordService;
+
 	private final static ErpBufferedLogger logger = BufferedLoggerManager.getLogger(ErpBufferedLogger.class);
 
 	/**
@@ -207,6 +211,21 @@ public class PurchaseNotifyController {
 		return strings;
 	}
 
+    /**
+     * 每天定时观察校验送货提醒
+     *
+     * @return
+     * @throws UnsupportedEncodingException
+     */
+    @RequestMapping(value = "/endCheck", method = RequestMethod.POST)
+    @ResponseBody
+    public void endCheck(@RequestParam("data") String data) throws UnsupportedEncodingException {
+        String jsonStr = URLDecoder.decode(data, "UTF-8");
+        List<PurchaseNotify> notifyList = FlexJsonUtils.fromJsonArray(jsonStr, PurchaseNotify.class);
+        noticeRecordService.check(notifyList);
+        logger.log("送货提醒", "送货提醒校验", notifyList.size());
+    }
+
 	/**
 	 * 买家修改收料通知的数量后,写回到平台(UAS点全部拒收)
 	 * 

+ 15 - 0
src/main/java/com/uas/platform/b2b/erp/dao/NoticeRecordDao.java

@@ -0,0 +1,15 @@
+package com.uas.platform.b2b.erp.dao;
+
+import com.uas.platform.b2b.erp.model.NoticeRecord;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+/**
+ * ERP提醒校验记录,方便查询两边数据
+ *
+ * @author hejq
+ * @date 2018-08-24 11:35
+ */
+@Repository
+public interface NoticeRecordDao extends JpaRepository<NoticeRecord, Long> {
+}

+ 131 - 0
src/main/java/com/uas/platform/b2b/erp/model/NoticeRecord.java

@@ -0,0 +1,131 @@
+package com.uas.platform.b2b.erp.model;
+
+import javax.persistence.*;
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * ERP提醒校验记录,方便查询两边数据
+ *
+ * @author hejq
+ * @date 2018-08-24 11:05
+ */
+@Entity
+@Table(name = "purc$notice$record", indexes = {
+        @Index(name = "purc$notice$record_enuu_IDX", columnList = "no_enuu")
+})
+public class NoticeRecord implements Serializable {
+
+    /**
+     * 序列号
+     */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * id
+     */
+    @Id
+    @Column(name = "no_id")
+    @GeneratedValue(strategy = GenerationType.AUTO)
+    private Long id;
+
+    /**
+     * 企业UU
+     */
+    @Column(name = "no_enuu")
+    @NotNull
+    private Long enUU;
+
+    /**
+     * 企业名称
+     */
+    @Column(name = "no_enname")
+    private String enName = "";
+
+    /**
+     * 录入时间
+     */
+    @Column(name = "no_date")
+    private Date date = new Date(System.currentTimeMillis());
+
+    /**
+     * 描述
+     */
+    @Column(name = "no_describe")
+    private String describe = "";
+
+    /**
+     * 单据类型
+     *  <pre>
+     *      结案、发货
+     *  </pre>
+     */
+    @Column(name = "no_kind")
+    private String kind = "";
+
+    /**
+     * 对应的采购单详情List
+     */
+    @OneToMany(mappedBy = "record", cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH}, fetch = FetchType.EAGER)
+    private List<NoticeRecordDetail> details;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getEnUU() {
+        return enUU;
+    }
+
+    public void setEnUU(Long enUU) {
+        this.enUU = enUU;
+    }
+
+    public String getEnName() {
+        return enName;
+    }
+
+    public void setEnName(String enName) {
+        this.enName = enName;
+    }
+
+    public Date getDate() {
+        return date;
+    }
+
+    public void setDate(Date date) {
+        this.date = date;
+    }
+
+    public String getDescribe() {
+        return describe;
+    }
+
+    public void setDescribe(String describe) {
+        this.describe = describe;
+    }
+
+    public String getKind() {
+        return kind;
+    }
+
+    public void setKind(String kind) {
+        this.kind = kind;
+    }
+
+    public List<NoticeRecordDetail> getDetails() {
+        return details;
+    }
+
+    public void setDetails(List<NoticeRecordDetail> details) {
+        // 级联保存这里重新赋值保证明细外键不为空
+        details.forEach(detail -> detail.setRecord(this));
+        this.details = details;
+    }
+}

+ 194 - 0
src/main/java/com/uas/platform/b2b/erp/model/NoticeRecordDetail.java

@@ -0,0 +1,194 @@
+package com.uas.platform.b2b.erp.model;
+
+
+import com.uas.platform.core.model.Constant;
+
+import javax.persistence.*;
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * ERP操作发货提醒记录明细
+ *
+ * @author hejq
+ * @date 2018-08-24 11:19
+ */
+@Entity
+@Table(name = "purc$notice$record$detail", indexes = {
+        @Index(name = "purc$notice$record$detail_noid_IDX", columnList = "nod_noid"),
+        @Index(name = "purc$notice$record$detail_b2bid_IDX", columnList = "nod_b2bid"),
+        @Index(name = "purc$notice$record$detail_okstatus_IDX", columnList = "nod_okstatus")
+})
+public class NoticeRecordDetail implements Serializable {
+
+    /**
+     * 序列号
+     */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * id
+     */
+    @Id
+    @Column(name = "nod_id")
+    @GeneratedValue(strategy = GenerationType.AUTO)
+    private Long id;
+
+    /**
+     * 主记录
+     */
+    @ManyToOne(cascade = { CascadeType.REFRESH, CascadeType.PERSIST })
+    @JoinColumn(name = "nod_noid")
+    private NoticeRecord record;
+
+    /**
+     * erpID
+     */
+    @Column(name = "nod_erpid")
+    @NotNull
+    private Long erpId;
+
+    /**
+     * b2bID
+     * <pre>
+     *     -1标识B2B未找到相应的ID,为异常数据
+     * </pre>
+     */
+    @Column(name = "nod_b2bid")
+    private Long b2bId = -1L;
+
+    /**
+     * 结案状态
+     */
+    @Column(name = "nod_status")
+    private Short status = 0;
+
+    /**
+     * 需求数量
+     */
+    @Column(name = "nod_needqty")
+    private Double needQty = 0.00;
+
+    /**
+     * 已发货数量
+     */
+    @Column(name = "nod_sendqty")
+    private Double sendQty = 0.00;
+
+    /**
+     * 记录日期
+     */
+    @Column(name = "nod_date")
+    private Date date = new Date(System.currentTimeMillis());
+
+    /**
+     * 状态,是否正常
+     *  <pre>
+     *      1. YES
+     *      0. NO
+     *  </pre>
+     */
+    @Column(name = "nod_okstatus")
+    private Short okStatus = Constant.YES;
+
+    /**
+     * 发货提醒单录入时间
+     */
+    @Column(name = "nod_nodate")
+    private Date noDate;
+
+    /**
+     * 单据操作备注
+     */
+    @Column(name = "nod_remark")
+    private String  remark;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public NoticeRecord getRecord() {
+        return record;
+    }
+
+    public void setRecord(NoticeRecord record) {
+        this.record = record;
+    }
+
+    public Long getErpId() {
+        return erpId;
+    }
+
+    public void setErpId(Long erpId) {
+        this.erpId = erpId;
+    }
+
+    public Long getB2bId() {
+        return b2bId;
+    }
+
+    public void setB2bId(Long b2bId) {
+        this.b2bId = b2bId;
+    }
+
+    public Short getStatus() {
+        return status;
+    }
+
+    public void setStatus(Short status) {
+        this.status = status;
+    }
+
+    public Double getNeedQty() {
+        return needQty;
+    }
+
+    public void setNeedQty(Double needQty) {
+        this.needQty = needQty;
+    }
+
+    public Double getSendQty() {
+        return sendQty;
+    }
+
+    public void setSendQty(Double sendQty) {
+        this.sendQty = sendQty;
+    }
+
+    public Date getDate() {
+        return date;
+    }
+
+    public void setDate(Date date) {
+        this.date = date;
+    }
+
+    public Short getOkStatus() {
+        return okStatus;
+    }
+
+    public void setOkStatus(Short okStatus) {
+        this.okStatus = okStatus;
+    }
+
+    public Date getNoDate() {
+        return noDate;
+    }
+
+    public void setNoDate(Date noDate) {
+        this.noDate = noDate;
+    }
+
+    public String getRemark() {
+        return remark;
+    }
+
+    public void setRemark(String remark) {
+        this.remark = remark;
+    }
+}

+ 21 - 0
src/main/java/com/uas/platform/b2b/erp/service/NoticeRecordService.java

@@ -0,0 +1,21 @@
+package com.uas.platform.b2b.erp.service;
+
+import com.uas.platform.b2b.erp.model.PurchaseNotify;
+
+import java.util.List;
+
+/**
+ * 发货提醒校验记录
+ *
+ * @author hejq
+ * @date 2018-08-24 11:38
+ */
+public interface NoticeRecordService {
+
+    /**
+     * 送货提醒数据校验
+     *
+     * @param notifyList 送货提醒
+     */
+    void check(List<PurchaseNotify> notifyList);
+}

+ 84 - 0
src/main/java/com/uas/platform/b2b/erp/service/impl/NoticeRecordServiceImpl.java

@@ -0,0 +1,84 @@
+package com.uas.platform.b2b.erp.service.impl;
+
+import com.uas.platform.b2b.dao.PurchaseNoticeDao;
+import com.uas.platform.b2b.erp.dao.NoticeRecordDao;
+import com.uas.platform.b2b.erp.model.NoticeRecord;
+import com.uas.platform.b2b.erp.model.NoticeRecordDetail;
+import com.uas.platform.b2b.erp.model.PurchaseNotify;
+import com.uas.platform.b2b.erp.service.NoticeRecordService;
+import com.uas.platform.b2b.model.Enterprise;
+import com.uas.platform.b2b.model.PurchaseNotice;
+import com.uas.platform.b2b.support.SystemSession;
+import com.uas.platform.core.model.Constant;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 发货提醒校验记录
+ *
+ * @author hejq
+ * @date 2018-08-24 11:38
+ */
+@Service
+public class NoticeRecordServiceImpl implements NoticeRecordService {
+
+    @Autowired
+    private PurchaseNoticeDao noticeDao;
+
+    @Autowired
+    private NoticeRecordDao recordDao;
+
+    /**
+     * 送货提醒数据校验
+     *
+     * @param notifyList 送货提醒
+     */
+    @Override
+    public void check(List<PurchaseNotify> notifyList) {
+        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+        Long time = System.currentTimeMillis() - 2 * 60 * 60 * 1000;
+        final String describe = dateFormat.format(new Date(System.currentTimeMillis()))
+                + "~" + dateFormat.format(new Date(time)) + " 送货提醒取消记录";
+        final Enterprise enterprise = SystemSession.getUser().getEnterprise();
+        NoticeRecord record = new NoticeRecord();
+        record.setDescribe(describe);
+        record.setEnName(enterprise.getEnName());
+        record.setEnUU(enterprise.getUu());
+        record.setKind("end");
+        List<NoticeRecordDetail> details = new ArrayList<>();
+        notifyList.forEach(notify -> details.add(covert(notify)));
+        record.setDetails(details);
+        recordDao.save(record);
+    }
+
+    /**
+     * 将ERP发货提醒明细转成B2B记录明细
+     *
+     * @param notify ERP发货提醒明细
+     * @return NoticeRecordDetail
+     */
+    private NoticeRecordDetail covert(PurchaseNotify notify) {
+        NoticeRecordDetail detail = new NoticeRecordDetail();
+        PurchaseNotice notice = noticeDao.findOne(notify.getPn_b2bid());
+        detail.setErpId(notify.getPn_id());
+        detail.setOkStatus(Constant.NO);
+        detail.setRemark(notify.getPn_remark());
+        if (null != notice) {
+            detail.setB2bId(notice.getId());
+            detail.setNeedQty(notice.getQty());
+            detail.setSendQty(notice.getEndQty());
+            detail.setStatus(notice.getEnd());
+            detail.setNoDate(notice.getDate());
+            if (detail.getSendQty() == 0) {
+                detail.setOkStatus(Constant.YES);
+            }
+        }
+        return detail;
+    }
+
+}