skyouc
18 小时以前 299cd2a4b79f32f9e1b55997e48bbe7e598c2d3f
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
package com.vincent.rsf.openApi.service.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.cfg.CoercionAction;
import com.fasterxml.jackson.databind.cfg.CoercionInputShape;
import com.vincent.rsf.framework.common.R;
import com.vincent.rsf.framework.exception.CoolException;
import com.vincent.rsf.openApi.entity.CommonResponse;
import com.vincent.rsf.openApi.entity.constant.RcsConstant;
import com.vincent.rsf.openApi.entity.params.RcsPubTaskParams;
import com.vincent.rsf.openApi.service.WmsRcsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;
 
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
 
@Slf4j
@Service("wmsRcsServiceImpl")
public class WmsRcsServiceImpl implements WmsRcsService {
 
//    @Autowired
//    private RemotesInfoProperties.RcsApi rcsApi;
 
    @Autowired
    private RestTemplate restTemplate;
 
    /**RCS基础配置链接*/
//    private final String rcsUrl =  rcsApi.getHost() + rcsApi.getPort();
 
    /**
     * @author Ryan
     * @date 2025/8/27
     * @description: 任务下发
     * @version 1.0
     */
    @Override
    @Transactional(timeout = 60, rollbackFor = Exception.class)
    public R pubTasks(RcsPubTaskParams params)  {
        log.info("任务下发,请求地址: {}, 请求参数: {}", "" + RcsConstant.pubTask, JSONObject.toJSONString(params));
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/json");
        headers.add("api-version", "v2.0");
        HttpEntity httpEntity = new HttpEntity(params, headers);
        ResponseEntity<String> exchange = restTemplate.exchange("rcsUrl" + RcsConstant.pubTask, HttpMethod.POST, httpEntity, String.class);
        log.info("任务下发后,响应结果: {}", exchange);
        if (Objects.isNull(exchange.getBody())) {
            throw new CoolException("任务下发失败!!");
        } else {
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.coercionConfigDefaults()
                    .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
            try {
                CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
                if (result.getCode() == 200) {
                    return R.ok(result);
                } else {
                    throw new CoolException("任务下发失败!!");
                }
            } catch (JsonProcessingException e) {
                throw new CoolException(e.getMessage());
            }
        }
    }
 
    /**
     * @author Ryan
     * @date 2025/8/27
     * @description: 取消任务
     * @version 1.0
     */
    @Override
    public R cancelTasks(Map<String, Object> params) {
        return null;
    }
 
    /**
     * @author Ryan
     * @date 2025/8/27
     * @description: RCS状态回写
     * @version 1.0
     */
    @Override
    public R callBackEvent(Map<String, Object> params) {
        return null;
    }
 
    /**
     * @author Ryan
     * @date 2025/8/27
     * @description: 库位信息同步
     * @version 1.0
     */
    @Override
    public void syncLocs() {
        ScheduledExecutorService scheduled = Executors.newScheduledThreadPool(1);
        scheduled.scheduleWithFixedDelay(new Runnable() {
            int current = 1;
            @Override
            public void run() {
                log.info("<UNK>{}<UNK>", current);
                current ++;
                log.info("{}", current);
            }
        }, 3, 3, TimeUnit.SECONDS);
    }
}