自动化立体仓库 - WMS系统
LSH
2023-01-04 6021df21a6eaca3cf48db8f3ec38db6793d1fb97
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package com.zy.ints.task.scheduler;
 
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.SnowflakeIdWorker;
import com.core.exception.CoolException;
import com.zy.asrs.entity.DocType;
import com.zy.asrs.entity.Mat;
import com.zy.asrs.entity.Order;
import com.zy.asrs.entity.OrderDetl;
import com.zy.asrs.service.DocTypeService;
import com.zy.asrs.service.MatService;
import com.zy.asrs.service.OrderDetlService;
import com.zy.asrs.service.OrderService;
import com.zy.ints.entity.ErpDetTb;
import com.zy.ints.entity.ErpDetTbBak;
import com.zy.ints.erp.ErpSqlServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
 
/**
 * erp任务控制器
 * Created by vincent on 2020/11/27
 */
@Slf4j
@Component
public class ErpDetTbScheduler {
    /**
     * ERP接口是否启用
     */
    @Value("${erp.enabled}")
    private Boolean erpEnabled;
    @Autowired
    private ErpSqlServer erpSqlServer;
    @Autowired
    private MatService matService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private OrderDetlService orderDetlService;
    @Autowired
    private SnowflakeIdWorker snowflakeIdWorker;
    @Autowired
    private DocTypeService docTypeService;
 
    /**
     * 获取入出库订单信息
     */
    @Scheduled(cron = "${erp.refreshtime}")
    public void InOrOutOrder() {
        if (!erpEnabled) return;
        String sqlSelectErpDetTb = "select bill_no as billNo,prd_no as prdNo,iokindid,add_id as addId,qty,prd_mark as prdMark,wh,billdate,status,temp1,temp2,temp3 from erp_det_tb where 1=1";
        String sqlUpDateErpDetTbOne = "update erp_det_tb set status=1 where 1=1 and prd_no=";
        String sqlUpDateErpDetTbTwo = "update erp_det_tb set status=2 ";
 
        try {
            List<ErpDetTb> erpDetTbs = erpSqlServer.select(sqlSelectErpDetTb, ErpDetTb.class);
            if (erpDetTbs.size() > 0) {
                for (ErpDetTb erpDetTb : erpDetTbs) {
                    Date now = new Date();
                    Integer status = erpDetTb.getStatus();
                    if (status == 0) {
                        Mat mat = matService.selectByMatnr(erpDetTb.getPrdNo());
                        if (Cools.isEmpty(mat)) {
                            erpSqlServer.update(sqlUpDateErpDetTbTwo + ",temp1='品号信息在立库不存在,请先添加商品!!!'" + "where 1=1 and prd_no=" + "'" + erpDetTb.getPrdNo() + "'");
                        } else {
                            Order order = orderService.selectByNo(erpDetTb.getBillNo());
                            if (Cools.isEmpty(order)) {
                                order = new Order(
                                        String.valueOf(snowflakeIdWorker.nextId()),    // 编号[非空]
                                        erpDetTb.getBillNo(),    // 订单编号
                                        DateUtils.convert(now),    // 单据日期
                                        null,    // 单据类型
                                        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,    // 状态
                                        9999L,    // 添加人员
                                        now,    // 添加时间
                                        9999L,    // 修改人员
                                        now,    // 修改时间
                                        null    // 备注
                                );
                                String InAndOut = erpDetTb.getAddId().equals("2") ? "(出库)" : "(入库)";
                                DocType docType = docTypeService.selectOrAdd(erpDetTb.getIokindid$() + InAndOut, erpDetTb.getAddId().equals("1"));
                                if (!Cools.isEmpty(docType)) {
                                    order.setDocType(docType.getDocId());
                                    if (!orderService.insert(order)) {
                                        throw new CoolException("添加订单主档信息失败!!!");
                                    }
                                }
                            }
                            Order order1 = orderService.selectByNo(erpDetTb.getBillNo());
                            if (!Cools.isEmpty(order1)) {
                                OrderDetl orderDetl = orderDetlService.selectItem(order1.getId(), erpDetTb.getBillNo(), erpDetTb.getPrdMark());
                                if (Cools.isEmpty(orderDetl)) {
                                    orderDetl = new OrderDetl();
                                    orderDetl.setOrderId(order1.getId());
                                    orderDetl.setOrderNo(erpDetTb.getBillNo());
                                    orderDetl.setAnfme(erpDetTb.getQty());
                                    orderDetl.setQty(0.0D);
                                    orderDetl.setMatnr(erpDetTb.getPrdNo());
                                    orderDetl.setMaktx(mat.getMaktx());
                                    orderDetl.setBatch(erpDetTb.getPrdMark());
                                    orderDetl.setSpecs(mat.getSpecs());
                                    orderDetl.setUnit(mat.getUnit());
 
                                    orderDetl.setStatus(1);
                                    orderDetl.setCreateBy(9999L);
                                    orderDetl.setCreateTime(now);
                                    orderDetl.setUpdateBy(9999L);
                                    orderDetl.setUpdateTime(now);
                                    if (orderDetlService.insert(orderDetl)){
                                        erpSqlServer.update(sqlUpDateErpDetTbOne + "'" + erpDetTb.getPrdNo() + "'");
                                    }else {
                                        erpSqlServer.update(sqlUpDateErpDetTbTwo + ",temp1='添加订单明细档失败!!!'" + "where 1=1 and prd_no=" + "'" + erpDetTb.getPrdNo() + "'");
                                    }
                                }
                            }
                        }
                    } else if (status == 1) {
                        String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(now);
                        HashMap<String, Object> condition = new HashMap<>();
                        condition.put("bill_no", "'" + erpDetTb.getBillNo() + "'");
                        condition.put("prd_no", "'" + erpDetTb.getPrdNo() + "'");
                        condition.put("iokindid", "'" + erpDetTb.getIokindid() + "'");
                        condition.put("add_id", "'" + erpDetTb.getAddId() + "'");
                        condition.put("qty", "'" + erpDetTb.getQty() + "'");
                        condition.put("prd_mark", "'" + erpDetTb.getPrdMark() + "'");
                        condition.put("wh", "'" + erpDetTb.getWh() + "'");
                        condition.put("billdate", "'" + format + "'");
                        condition.put("status", "'" + erpDetTb.getStatus() + "'");
                        condition.put("temp1", "'" + erpDetTb.getTemp1() + "'");
                        condition.put("temp2", "'" + erpDetTb.getTemp2() + "'");
                        condition.put("temp3", "'" + erpDetTb.getTemp3() + "'");
                        erpSqlServer.insert(ErpDetTbBak.class, condition);
 
                        HashMap<String, String> condition2 = new HashMap<>();
                        condition2.put("bill_no", "'" + erpDetTb.getBillNo() + "'");
                        condition2.put("prd_no", "'" + erpDetTb.getPrdNo() + "'");
                        condition2.put("prd_mark", "'" + erpDetTb.getPrdMark() + "'");
                        erpSqlServer.delete(ErpDetTb.class, condition2);
                    } else if (status == 2) {
 
                    } else {
 
                    }
                }
            }
        } catch (Exception e) {
            Date date = new Date();
            log.error(date + ": 表名:erp_det_tb :" + e);
        }
    }
}