Kaynağa Gözat

智能仓房远程同步基础数据

hanqingsong 3 yıl önce
ebeveyn
işleme
79ff91ff9d

+ 43 - 118
src/main/java/com/chinaitop/depot/intelligent/basicdata/controller/WareHouseBasicInfoController.java

@@ -3,8 +3,10 @@ package com.chinaitop.depot.intelligent.basicdata.controller;
3 3
 import com.chinaitop.depot.intelligent.basicdata.model.BasicStorehouse;
4 4
 import com.chinaitop.depot.intelligent.basicdata.model.OrgInfo;
5 5
 import com.chinaitop.depot.intelligent.basicdata.service.WareHouseBasicInfoService;
6
+import com.chinaitop.depot.intelligent.grainsituation.service.TemperatureRecordService;
6 7
 import com.chinaitop.depot.intelligent.utils.DateUtils;
7 8
 import com.chinaitop.depot.intelligent.utils.JsonToObjectUtils;
9
+import com.chinaitop.depot.intelligent.utils.RemoteControlUtil;
8 10
 import com.chinaitop.depot.intelligent.wsClient.WebServiceSer;
9 11
 import com.chinaitop.depot.intelligent.wsClient.WebServiceSerSoap;
10 12
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -16,12 +18,17 @@ import io.swagger.annotations.ApiImplicitParams;
16 18
 import io.swagger.annotations.ApiOperation;
17 19
 import org.apache.commons.lang.StringUtils;
18 20
 import org.assertj.core.util.Lists;
21
+import org.springframework.beans.factory.annotation.Autowired;
19 22
 import org.springframework.http.MediaType;
23
+import org.springframework.util.LinkedMultiValueMap;
24
+import org.springframework.util.MultiValueMap;
20 25
 import org.springframework.web.bind.annotation.RequestMapping;
21 26
 import org.springframework.web.bind.annotation.RequestMethod;
27
+import org.springframework.web.bind.annotation.RequestParam;
22 28
 import org.springframework.web.bind.annotation.RestController;
23 29
 
24 30
 import javax.annotation.Resource;
31
+import javax.validation.constraints.NotNull;
25 32
 import java.util.ArrayList;
26 33
 import java.util.Date;
27 34
 import java.util.HashMap;
@@ -41,6 +48,10 @@ public class WareHouseBasicInfoController {
41 48
 
42 49
     @Resource
43 50
     private WareHouseBasicInfoService wareHouseBasicInfoService;
51
+    @Autowired
52
+    private TemperatureRecordService temperatureRecordService;
53
+    @Resource
54
+    private RemoteControlUtil remoteControlUtil;
44 55
 
45 56
     /**
46 57
      * 根据单位查找单位下的所有仓房信息(统一对外接口)
@@ -72,61 +83,21 @@ public class WareHouseBasicInfoController {
72 83
             @ApiImplicitParam(name = "orgInfoJson", value = "库点数据", paramType = "form"),
73 84
             @ApiImplicitParam(name = "CUD", value = "库点数据:新增(I),删除(D),修改(U)", paramType = "query")
74 85
     })
75
-    public ResponseEntity saveGrainpoint(String orgInfoJson, String CUD) {
76
-        // 非空判断
77
-        if (StringUtils.isNotBlank(orgInfoJson)) {
78
-            if (StringUtils.isNotBlank(CUD)) {
79
-                // json转对象
80
-                OrgInfo orgInfo = (OrgInfo) JsonToObjectUtils.jsonToObject(orgInfoJson, OrgInfo.class);
81
-                // 封装推送数据
82
-                Map<String, Object> orgInfoMap = new HashMap<>();
83
-                orgInfoMap.put("vKdCode", orgInfo.getOrgId()); // 库点编码
84
-                orgInfoMap.put("vKdName", orgInfo.getOrgName()); // 库点名称
85
-                orgInfoMap.put("vKdShort", orgInfo.getShortName()); // 库点简称
86
-                orgInfoMap.put("vKdQyxz", orgInfo.getCompanyNature()); // 企业性质
87
-                orgInfoMap.put("vKdType", orgInfo.getBusiType()); // 企业类型
88
-                orgInfoMap.put("vBuildDate", DateUtils.formatDate(orgInfo.getCompleteDate() == null ? new Date() : orgInfo.getCompleteDate())); // 建造日期
89
-                orgInfoMap.put("fcapacity", orgInfo.getEffectiveCapacity()); // 容量
90
-                orgInfoMap.put("vTelephone", orgInfo.getContact()); // 电话
91
-                orgInfoMap.put("vFax", orgInfo.getFax()); // 传真
92
-                orgInfoMap.put("vKdaddress", orgInfo.getAddress()); // 地址
93
-                orgInfoMap.put("vPostCode", orgInfo.getPost()); // 邮件代码
94
-                orgInfoMap.put("vPerson", orgInfo.getLegalPerson());// 法人
95
-                orgInfoMap.put("fKdArea", orgInfo.getDepotArea()); // 库点面积
96
-                orgInfoMap.put("province", orgInfo.getProvince()); // 省
97
-                orgInfoMap.put("city", orgInfo.getCity()); // 市
98
-                orgInfoMap.put("province2", null); // 省2
99
-                // 封装推送数据为数组格式
100
-                ArrayList<SendEntity> tGrainpoints = null;
101
-                // 判断推送数据操作insert,delete,update
102
-                if ("I".equals(CUD)) { // 新增(I)
103
-                    tGrainpoints = Lists.newArrayList(SendEntity.insertConvert(orgInfoMap));
104
-                } else if ("D".equals(CUD)) { // 删除
105
-                    tGrainpoints = Lists.newArrayList(SendEntity.deleteConvert(orgInfoMap));
106
-                } else if ("U".equals(CUD)) { // 更新
107
-                    tGrainpoints = Lists.newArrayList(SendEntity.updateConvert(orgInfoMap));
108
-                }
109
-                try {
110
-                    // 创建json转换对象
111
-                    ObjectMapper objectMapper = new ObjectMapper();
112
-                    // 对象转json字符串
113
-                    String jsonStr = objectMapper.writeValueAsString(tGrainpoints);
114
-                    // webService对象
115
-                    WebServiceSer webs = new WebServiceSer();
116
-                    // 获取cxf代理
117
-                    WebServiceSerSoap factor = webs.getWebServiceSerSoap();
118
-                    // 推送数据并返回结果
119
-                    String s = factor.saveGrainPointData(jsonStr);
120
-                    // 返回结果给调用接口
121
-                    return ResponseEntity.ok(s);
122
-                } catch (Exception e) {
123
-                    e.printStackTrace();
124
-                    return ResponseEntity.failed("推送失败");
125
-                }
126
-            }
127
-        }
128
-        return null;
129
-
86
+    public ResponseEntity saveGrainpoint(@RequestParam @NotNull String orgInfoJson,
87
+                                         @RequestParam @NotNull String CUD,
88
+                                         @RequestParam @NotNull String orgId) {
89
+        // 1.获取库端url
90
+        String url = temperatureRecordService.getRemoteUrl(orgId);
91
+        if (StringUtils.isBlank(url))
92
+            return ResponseEntity.failed("库端硬件地址未配置!");
93
+        // 2.封装请求数据
94
+        MultiValueMap<String, String> requestEntity = new LinkedMultiValueMap<>();
95
+        requestEntity.add("orgInfoJson", orgInfoJson);
96
+        requestEntity.add("CUD", CUD);
97
+        return remoteControlUtil.remoteScan(
98
+                String.format("%s%s", url, RemoteControlUtil.saveGrainPoint),
99
+                requestEntity
100
+        );
130 101
     }
131 102
 
132 103
     /**
@@ -142,67 +113,21 @@ public class WareHouseBasicInfoController {
142 113
             @ApiImplicitParam(name = "basicStorehouseJson", value = "仓房信息数据", paramType = "form"),
143 114
             @ApiImplicitParam(name = "del", defaultValue = "D", value = "删除标识", paramType = "query")
144 115
     })
145
-    public ResponseEntity synchronizationStoreHouse(String basicStorehouseJson, String del) {
146
-        // 非空判断
147
-        if (StringUtils.isNotBlank(basicStorehouseJson)) {
148
-            // json转对象
149
-            BasicStorehouse storehouse = (BasicStorehouse) JsonToObjectUtils.jsonToObject(basicStorehouseJson, BasicStorehouse.class);
150
-            // 封装推送数据
151
-            Map<String, Object> wareHouseData = new HashMap<>();
152
-            wareHouseData.put("vKdCode", storehouse.getOrgId()); // 库点id
153
-            wareHouseData.put("vCfCode", storehouse.getStorehouseCode()); // 仓房编码
154
-            wareHouseData.put("vCfName", storehouse.getStorehouseName()); // 仓房名称
155
-            wareHouseData.put("vCfType", storehouse.getStorehouseType()); // 仓房类型编号
156
-            wareHouseData.put("vCfStruct", null); // 仓房结构
157
-            wareHouseData.put("vBuildType", storehouse.getArchitectureType()); // 建筑类型编号
158
-            wareHouseData.put("vCfLong", storehouse.getLength()); // 仓内长
159
-            wareHouseData.put("vCfWide", storehouse.getWidth()); // 仓内宽
160
-            wareHouseData.put("vCfHigh", storehouse.getHeigth()); // 仓内高
161
-            wareHouseData.put("fDesignCap", storehouse.getDesignCapacity()); // 设计仓容
162
-            wareHouseData.put("fActCap", null); //
163
-            wareHouseData.put("vWorkDate", DateUtils.formatDate(storehouse.getUsedate() == null ? new Date() : storehouse.getUsedate())); // 启用日期
164
-            wareHouseData.put("vCfStatus", null);
165
-            wareHouseData.put("vRemark", storehouse.getStorehouseState());
166
-            wareHouseData.put("vKeeperId", storehouse.getDutystoreman()); // 保管员
167
-            wareHouseData.put("duiliangH", storehouse.getGrainLineHeigth()); // 装粮线高
168
-            wareHouseData.put("isshuliangjiace", null); // 是否启用数量检测功能 1 启用
169
-            wareHouseData.put("isInCheck", null); // 是否在检查 1代表是 0或null代表不是
170
-            wareHouseData.put("checkMode", null); // 检查模式 标准或者快速
171
-            wareHouseData.put("isWzc", null);
172
-            wareHouseData.put("type", null);
173
-            wareHouseData.put("id", null);
174
-            // 封装推送数据为数组格式
175
-            ArrayList<SendEntity> wareHouses = null;
176
-            // 判断推送数据操作insert,delete,update
177
-            if (storehouse.getStorehouseId() == null) {
178
-                // 插入
179
-                wareHouses = Lists.newArrayList(SendEntity.insertConvert(wareHouseData));
180
-            } else if (StringUtils.isNotBlank(del) && "D".equals(del)) {
181
-                // 删除
182
-                wareHouses = Lists.newArrayList(SendEntity.deleteConvert(wareHouseData));
183
-            } else {
184
-                // 更新
185
-                wareHouses = Lists.newArrayList(SendEntity.updateConvert(wareHouseData));
186
-            }
187
-            try {
188
-                // 创建json转换对象
189
-                ObjectMapper objectMapper = new ObjectMapper();
190
-                // 对象转json字符串
191
-                String jsonStr = objectMapper.writeValueAsString(wareHouses);
192
-                // webService对象
193
-                WebServiceSer webs = new WebServiceSer();
194
-                // 获取cxf代理
195
-                WebServiceSerSoap factor = webs.getWebServiceSerSoap();
196
-                // 推送数据并返回结果
197
-                String s = factor.saveWareHouseData(jsonStr);
198
-                // 返回结果给调用接口
199
-                return ResponseEntity.ok(s);
200
-            } catch (Exception e) {
201
-                e.printStackTrace();
202
-                return ResponseEntity.failed("推送失败");
203
-            }
204
-        }
205
-        return null;
116
+    public ResponseEntity synchronizationStoreHouse(@RequestParam @NotNull String basicStorehouseJson,
117
+                                                    @RequestParam @NotNull String del,
118
+                                                    @RequestParam @NotNull String orgId) {
119
+        // 1.获取库端url
120
+        String url = temperatureRecordService.getRemoteUrl(orgId);
121
+        if (StringUtils.isBlank(url))
122
+            return ResponseEntity.failed("库端硬件地址未配置!");
123
+        // 2.封装请求数据
124
+        MultiValueMap<String, String> requestEntity = new LinkedMultiValueMap<>();
125
+        requestEntity.add("basicStorehouseJson", basicStorehouseJson);
126
+        requestEntity.add("del", del);
127
+        return remoteControlUtil.remoteScan(
128
+                String.format("%s%s", url, RemoteControlUtil.syncStoreHouse),
129
+                requestEntity
130
+        );
206 131
     }
207 132
 
208 133
     @RequestMapping(value = "/getStorehouse", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
@@ -212,10 +137,10 @@ public class WareHouseBasicInfoController {
212 137
             @ApiImplicitParam(name = "cfCode", value = "仓房code", paramType = "query"),
213 138
             @ApiImplicitParam(name = "libraryType", value = "仓房性质(主粮库或代储点)", paramType = "query")
214 139
     })
215
-    public ResponseEntity getStorehouse(Integer orgId, String libraryType,String cfCode) {
140
+    public ResponseEntity getStorehouse(Integer orgId, String libraryType, String cfCode) {
216 141
         Map<String, Object> map = null;
217 142
         try {
218
-            map = wareHouseBasicInfoService.getStorehouse(orgId, libraryType,cfCode);
143
+            map = wareHouseBasicInfoService.getStorehouse(orgId, libraryType, cfCode);
219 144
         } catch (Exception e) {
220 145
             e.printStackTrace();
221 146
             return ResponseEntity.failed("查询仓房信息失败");

+ 5 - 0
src/main/java/com/chinaitop/depot/intelligent/utils/RemoteControlUtil.java

@@ -106,6 +106,11 @@ public class RemoteControlUtil {
106 106
     // 与智远同步气调设置基础数据
107 107
     public static final String gasSYN  = "/intelligents/gas/synchronizationAll";
108 108
 
109
+    // orgInfo CRUD到硬件方 POST(String orgInfoJson, String CUD)
110
+    public static final String saveGrainPoint = "/intelligents/wareHouseBasicInfo/saveGrainpoint";
111
+    // storeHouse CRUD到硬件方 POST(String basicStorehouseJson,String del)
112
+    public static final String syncStoreHouse = "/intelligents/wareHouseBasicInfo/synchronizationStoreHouse";
113
+
109 114
     /**
110 115
      * 远程库端请求方法
111 116
      *