|
@@ -0,0 +1,215 @@
|
|
|
|
+package com.fjhx.task.service.impl;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.fjhx.task.mapper.ScheduleTaskMapper;
|
|
|
|
+import com.fjhx.task.service.ScheduleTaskService;
|
|
|
|
+import org.springblade.core.launch.BladeApplication;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
|
+import org.springframework.http.converter.StringHttpMessageConverter;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
+
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+@Service
|
|
|
|
+public class ScheduleTaskServiceImpl implements ScheduleTaskService {
|
|
|
|
+
|
|
|
|
+ private static final RestTemplate restTemplate;
|
|
|
|
+
|
|
|
|
+ private static final String GET_ACCESS_TOKEN_ACTION_URL;
|
|
|
|
+
|
|
|
|
+ private static final String STOCK_ACCEPT_ACTION;
|
|
|
|
+
|
|
|
|
+ private static final String SELECT_PUBLISHED_SQL;
|
|
|
|
+ private static final String UPDATE_PUBLISHED_SQL;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ScheduleTaskMapper scheduleTaskMapper;
|
|
|
|
+
|
|
|
|
+ static {
|
|
|
|
+ restTemplate = new RestTemplate();
|
|
|
|
+ restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
|
|
|
|
+
|
|
|
|
+ if (BladeApplication.isLocalDev()) {
|
|
|
|
+ GET_ACCESS_TOKEN_ACTION_URL = "http://106.14.146.72:8087/portal/getAccessTokenAction.do?AppId=1&AppSecret=a2b1c2d3";
|
|
|
|
+ STOCK_ACCEPT_ACTION = "http://106.14.146.72:8087/SrmWeb/stockAcceptAction.do?action=custom&access_token=";
|
|
|
|
+ SELECT_PUBLISHED_SQL = "select Id,Content from `cap.published_copy1` where handle is null";
|
|
|
|
+ UPDATE_PUBLISHED_SQL = "UPDATE `cap.published_copy1` SET handle=1 WHERE id=";
|
|
|
|
+ } else {
|
|
|
|
+ GET_ACCESS_TOKEN_ACTION_URL = "http://mes.cfmfactory.com:8087/portal/getAccessTokenAction.do?AppId=1&AppSecret=a2b1c2d3";
|
|
|
|
+ STOCK_ACCEPT_ACTION = "http://mes.cfmfactory.com:8087/SrmWeb/stockAcceptAction.do?action=custom&access_token=";
|
|
|
|
+ SELECT_PUBLISHED_SQL = "select Id,Content from `cap.published` where handle is null";
|
|
|
|
+ UPDATE_PUBLISHED_SQL = "UPDATE `cap.published` SET handle=1 WHERE id=";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void stockAcceptActionTask() {
|
|
|
|
+
|
|
|
|
+ List<Map<String, Object>> selectPublishedList = scheduleTaskMapper.selectPublished(SELECT_PUBLISHED_SQL);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ ResponseEntity<String> entity = restTemplate.getForEntity(GET_ACCESS_TOKEN_ACTION_URL, String.class);
|
|
|
|
+ String body = entity.getBody();
|
|
|
|
+ if (ObjectUtil.isEmpty(body)) return;
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(body);
|
|
|
|
+ String token = jsonObject.getString("token");
|
|
|
|
+ if (ObjectUtil.isEmpty(token)) return;
|
|
|
|
+
|
|
|
|
+ for (Map<String, Object> stringStringMap : selectPublishedList) {
|
|
|
|
+ String content = stringStringMap.get("Content").toString();
|
|
|
|
+
|
|
|
|
+ JSONObject contentMap = JSONObject.parseObject(content);
|
|
|
|
+ JSONObject value = contentMap.getJSONObject("Value");
|
|
|
|
+ String userId = value.getString("UserId");
|
|
|
|
+
|
|
|
|
+ Map<String, String> userIdAndJobNo = scheduleTaskMapper.selectUserIdAndJobNo(userId);
|
|
|
|
+
|
|
|
|
+ if (userIdAndJobNo.get("ID").equals(userIdAndJobNo.get("JobNo"))) {
|
|
|
|
+ scheduleTaskMapper.updatePublished(UPDATE_PUBLISHED_SQL + stringStringMap.get("Id"));
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+
|
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ map.put("material", value.getString("MaterialCode"));
|
|
|
|
+ map.put("type", value.getString("Type"));
|
|
|
|
+ map.put("begNum", value.getString("BegNum"));
|
|
|
|
+ map.put("endNum", value.getString("EndNum"));
|
|
|
|
+ map.put("count", value.getString("Qty"));
|
|
|
|
+ map.put("userId", userIdAndJobNo.get("JobNo"));
|
|
|
|
+ map.put("createDate", value.getString("CreateDate"));
|
|
|
|
+
|
|
|
|
+ ResponseEntity<String> stockAcceptActionResult = restTemplate.postForEntity(STOCK_ACCEPT_ACTION + token, map, String.class);
|
|
|
|
+ String stockAcceptActionBody = stockAcceptActionResult.getBody();
|
|
|
|
+
|
|
|
|
+ if (JSONObject.parseObject(stockAcceptActionBody).getBoolean("success")) {
|
|
|
|
+ scheduleTaskMapper.updatePublished(UPDATE_PUBLISHED_SQL + stringStringMap.get("Id"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
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