fanxw 1 jaar geleden
bovenliggende
commit
f28f514cd9

+ 11 - 2
src/main/java/com/chinaitop/depot/business/service/FeignBasicService.java

@@ -15,8 +15,17 @@ public interface FeignBasicService {
15 15
 
16 16
     @RequestMapping(value = "/Warehouse/getWareDataByHwbm", method = RequestMethod.GET)
17 17
     Map<String, Object> getWareDataByHwbm(@RequestParam(value = "hwbm") String hwbm);
18
-    
19
-    
18
+
19
+    /**
20
+     * 获取字典树类型
21
+     * @param parentId
22
+     * @param notParentId
23
+     * @param notEnumId
24
+     * @return
25
+     */
26
+    @RequestMapping(value = "/Enum/findConditionEnum", method = RequestMethod.GET)
27
+    Map<String, Object> findConditionEnum(@RequestParam(value = "parentId") Integer parentId, @RequestParam(value = "notParentId") Integer notParentId, @RequestParam(value = "notEnumId") Integer notEnumId);
28
+
20 29
     @RequestMapping(value = "/Enum/getIdByNameAndParentId", method = RequestMethod.GET)
21 30
     Map<String, Object> getIdByNameAndParentId(@RequestParam(value = "parentId") Integer parentId,@RequestParam(value = "enumName") String enumName, @RequestParam(value = "gbCode") String gbCode);
22 31
 

+ 39 - 17
src/main/java/com/chinaitop/depot/business/service/impl/BusinessContractReceiveServiceImpl.java

@@ -15,6 +15,8 @@ import org.slf4j.LoggerFactory;
15 15
 import org.springframework.stereotype.Service;
16 16
 import org.springframework.transaction.annotation.Transactional;
17 17
 
18
+import com.alibaba.fastjson.JSON;
19
+import com.alibaba.fastjson.JSONArray;
18 20
 import com.alibaba.fastjson.JSONObject;
19 21
 import com.chinaitop.depot.business.controller.BusinessContractController;
20 22
 import com.chinaitop.depot.business.mapper.BusinessContractReceiveMapper;
@@ -114,11 +116,11 @@ public class BusinessContractReceiveServiceImpl implements BusinessContractRecei
114 116
 		String pz = obj.getString("pz");
115 117
 		if (StringUtils.isNotBlank(pz)) {
116 118
 			Map<String, Object> basicMap = feignBasicService.getIdByNameAndParentId(1061, null, pz);
117
-			logger.info("获取到的品种数据如下:");
119
+			logger.info("根据"+pz+"获取到的品种数据如下:");
118 120
 			logger.info(basicMap.toString());
119
-			String lspz = basicMap.get("enumId")+"";
120
-			if (StringUtils.isNotBlank(lspz)) {
121
-				dataobj.setLypz(Integer.parseInt(lspz));
121
+			String lypz = basicMap.get("enumId")+"";
122
+			if (StringUtils.isNotBlank(lypz)) {
123
+				dataobj.setLypz(Integer.parseInt(lypz));
122 124
 			} else {
123 125
 				sbf.append("粮食品种的值"+pz+"有误或不合理,");
124 126
 			}
@@ -128,13 +130,10 @@ public class BusinessContractReceiveServiceImpl implements BusinessContractRecei
128 130
 		String mxpz = obj.getString("mxpz");
129 131
 		if (StringUtils.isNotBlank(mxpz)) {
130 132
 			if (null != dataobj.getLypz()) {
131
-				mxpz = mxpz.replace(" ", "");
132
-				Map<String, Object> basicMap = feignBasicService.getIdByNameAndParentId(dataobj.getLypz(), null, mxpz);
133
-				logger.info("获取到的明细品种数据如下:");
134
-				logger.info(basicMap.toString());
135
-				String lsmxpz = basicMap.get("enumId")+"";
136
-				if (StringUtils.isNotBlank(lsmxpz)) {
137
-					dataobj.setMxpz(Integer.parseInt(lsmxpz));
133
+				Integer enumid = getEnumId(dataobj.getLypz(), mxpz);
134
+				logger.info("根据"+mxpz+"获取到的明细品种数据是:"+enumid);
135
+				if (null != enumid) {
136
+					dataobj.setMxpz(enumid);
138 137
 				} else {
139 138
 					sbf.append("粮食明细品种的值"+mxpz+"有误或不合理,");
140 139
 				}
@@ -157,12 +156,10 @@ public class BusinessContractReceiveServiceImpl implements BusinessContractRecei
157 156
 		}
158 157
 		String lyxz = obj.getString("lsxz");
159 158
 		if (StringUtils.isNotBlank(lyxz)) {
160
-			Map<String, Object> basicMap = feignBasicService.getIdByNameAndParentId(1032, null, lyxz);
161
-			logger.info("获取到的粮食性质数据如下:");
162
-			logger.info(basicMap.toString());
163
-			String lsxz = basicMap.get("enumId")+"";
164
-			if (StringUtils.isNotBlank(lsxz)) {
165
-				dataobj.setLyxz(Integer.parseInt(lsxz));
159
+			Integer enumid = getEnumId(1032, lyxz);
160
+			logger.info("根据"+lyxz+"获取到的粮食性质数据如下:"+enumid);
161
+			if (null != enumid) {
162
+				dataobj.setLyxz(enumid);
166 163
 			} else {
167 164
 				sbf.append("粮食性质的值"+lyxz+"有误,");
168 165
 			}
@@ -219,6 +216,31 @@ public class BusinessContractReceiveServiceImpl implements BusinessContractRecei
219 216
 		return resultMap;
220 217
 	}
221 218
 
219
+	/**
220
+	 * 根据字典父级ID和国标编码获取下面的一个字典ID
221
+	 * @param parentId
222
+	 * @param gbCode
223
+	 * @return
224
+	 */
225
+	private Integer getEnumId(int parentId, String gbCode) {
226
+		Integer enumId = null;
227
+		Map<String, Object> map = feignBasicService.findConditionEnum(parentId, null, null);
228
+		if (null != map) {
229
+			String json_str = JSON.toJSONString(map);
230
+			JSONObject json_obj = JSONObject.parseObject(json_str);
231
+			JSONArray array = JSONArray.parseArray(json_obj.getString("enumList"));
232
+			for (int i = 0; i < array.size(); i++) {
233
+				JSONObject object = JSONObject.parseObject(array.get(i).toString());
234
+				String code = object.getString("gbcode");
235
+				if (code.equals(gbCode)) {
236
+					enumId = Integer.parseInt(object.getString("id"));
237
+					break;
238
+				}
239
+			}
240
+		}
241
+		return enumId;
242
+	}
243
+
222 244
 	@Override
223 245
 	public List<BusinessContractReceive> queryByExample(String htbh, Integer orgId, Integer houseId, Integer warehouseId, String htlx)
224 246
 			throws Exception {

+ 6 - 0
src/main/java/com/chinaitop/depot/utils/HelloServiceHystrix.java

@@ -113,4 +113,10 @@ public class HelloServiceHystrix implements FeignAgileService,FeignBasicService,
113 113
 		return null;
114 114
 	}
115 115
 
116
+	@Override
117
+	public Map<String, Object> findConditionEnum(Integer parentId, Integer notParentId, Integer notEnumId) {
118
+		logger.info("获取"+parentId+"下的字典树接口调用失败!");
119
+		return null;
120
+	}
121
+
116 122
 }