#
luxiaotao1123
2021-03-01 0497edd108397506301b181d7e934d546c092834
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
package zy.cloud.wms.common.service.erp;
 
import com.alibaba.fastjson.JSON;
import com.core.common.Cools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import zy.cloud.wms.common.service.MainService;
import zy.cloud.wms.common.service.erp.entity.GetDataResult;
import zy.cloud.wms.manager.entity.Mat;
import zy.cloud.wms.manager.service.MatService;
import zy.cloud.wms.manager.utils.HttpHandler;
 
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * erp任务控制器
 * Created by vincent on 2020/11/27
 */
@Slf4j
@Component
public class ErpScheduler {
 
    public static final String URI = "http://8.133.182.21:8080/api/";
    public static final String GET_ORDERS = "cM/basis/getOrders";
 
    @Autowired
    private MatService matService;
    @Autowired
    private MainService mainService;
 
    /**
     * 原材料
     */
//    @Scheduled(cron = "0/3 * * * * ? ")
    public void getOrdersExecute(){
        try {
            Map<String, Object> json = new HashMap<>();
            json.put("vchType", 41);
            String response = new HttpHandler.Builder()
                    .setUri(URI)
                    .setPath(GET_ORDERS)
                    .setJson(JSON.toJSONString(json))
                    .build()
                    .doPost();
            if (Cools.isEmpty(response)) {
                log.error("请求:{}\nError,响应结果为空!", URI + GET_ORDERS);
            } else {
                log.info(response);
                Result result = JSON.parseObject(response, Result.class);
                List<GetDataResult> datas = JSON.parseArray(result.getData(), GetDataResult.class);
                if (!Cools.isEmpty(datas)) {
                    for (GetDataResult data : datas) {
                        // 生成出库单
                        Mat mat = matService.selectByMatnr(data.getUserCode());
                        mainService.stockOutProcess();
 
 
                    }
                }
 
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
 
    }
 
}