You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

404 lines
18 KiB

  1. package com.spring.ifs.bean;
  2. import com.alibaba.fastjson.JSON;
  3. import com.spring.ifs.api.IfsServer;
  4. import com.spring.ifs.api.TechnicalClassApi;
  5. import com.spring.modules.part.entity.APIEntity.PartIfsCatalogModel;
  6. import com.spring.modules.part.entity.APIEntity.PartIfsCatalogProperty;
  7. import ifs.fnd.ap.APException;
  8. import ifs.fnd.ap.Server;
  9. import org.apache.poi.ss.formula.functions.T;
  10. import org.slf4j.Logger;
  11. import org.slf4j.LoggerFactory;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.stereotype.Component;
  14. import java.math.BigDecimal;
  15. import java.util.ArrayList;
  16. import java.util.HashMap;
  17. import java.util.List;
  18. import java.util.Map;
  19. /**
  20. * @description: 技术等级实现类
  21. * @author LR
  22. * @date 2024/12/9 11:49
  23. * @version 1.0
  24. */
  25. @Component
  26. public class TechnicalClassBean {
  27. @Autowired
  28. private IfsServer ifsServer;
  29. private static final Logger logger = LoggerFactory.getLogger(TechnicalClassBean.class);
  30. /**
  31. * @description: 查询技术等级
  32. * @author LR
  33. * @date 2024/12/16 13:15
  34. * @version 1.0
  35. */
  36. public Map<String, String> getTechnicalClass(Server srv, PartIfsCatalogModel inData) {
  37. logger.info("Technical Class 查询开始:"+ JSON.toJSONString(inData));
  38. //公共参数
  39. Map<String, String> returnMap = new HashMap<>();
  40. String luName = inData.getLuName(); //
  41. String keyRef = inData.getKeyRef(); //
  42. try{
  43. //查询对象
  44. Map<String, String> resultMap = TechnicalClassApi.getTechnicalClass(srv, luName, keyRef);
  45. //判断查询导数据
  46. if(resultMap == null) {
  47. throw new APException("查无此技术等级的信息!");
  48. }
  49. //设置ifs 信息
  50. inData.setIfsRowId(resultMap.get("IFSROWID"));
  51. inData.setIfsRowVersion(resultMap.get("IFSROWVERSION"));
  52. returnMap.put("resultCode", "200");
  53. returnMap.put("obj", JSON.toJSONString(inData));
  54. } catch(APException e){
  55. returnMap.put("resultCode", "400");
  56. returnMap.put("resultMsg", e.getMessage());
  57. logger.info("异常信息:"+e.getMessage());
  58. }
  59. //打印日志
  60. logger.info("Technical Class 查询结束:"+JSON.toJSONString(inData));
  61. //返回结果集
  62. return returnMap;
  63. }
  64. /**
  65. * @description: 新增
  66. * @author LR
  67. * @date 2024/12/16 13:37
  68. * @version 1.0
  69. */
  70. public Map<String, String> syncTechnicalClass(Server srv, PartIfsCatalogModel inData) {
  71. logger.info("Technical Class 新增开始:"+JSON.toJSONString(inData));
  72. //公共参数
  73. Map<String, String> returnMap = new HashMap<>();
  74. try{
  75. //调用api同步信息
  76. Map<String, String> resultMap = TechnicalClassApi.insertTechnicalClass(srv, inData);
  77. //设置唯一键和版本
  78. inData.setIfsRowVersion(resultMap.get("OBJVERSION"));
  79. returnMap.put("resultCode", "200");
  80. returnMap.put("obj", JSON.toJSONString(inData));
  81. } catch(APException e){
  82. returnMap.put("resultCode", "400");
  83. returnMap.put("resultMsg", e.getMessage());
  84. logger.info("异常信息:"+e.getMessage());
  85. }
  86. //插入查询的记录数据
  87. logger.info("Technical Class 新增结束:"+JSON.toJSONString(inData));
  88. //返回结果集
  89. return returnMap;
  90. }
  91. /**
  92. * @description: 修改技术等级的数据
  93. * @author LR
  94. * @date 2024/12/16 13:45
  95. * @version 1.0
  96. */
  97. public Map<String, String> modifyTechnicalClass(Server srv, PartIfsCatalogModel inData) {
  98. logger.info("Technical Class 修改开始:"+JSON.toJSONString(inData));
  99. //公共参数
  100. Map<String, String> returnMap = new HashMap<>();
  101. String luName = inData.getLuName(); //
  102. String keyRef = inData.getKeyRef();
  103. try{
  104. //查询对象
  105. Map<String, String> technicalMap = TechnicalClassApi.getTechnicalClass(srv, luName, keyRef);
  106. //判断查询导数据
  107. if(technicalMap == null || technicalMap.isEmpty()) {
  108. throw new APException("不存在此技术等级的信息!");
  109. }
  110. //设置IFS的信息
  111. inData.setIfsRowId(technicalMap.get("IFSROWID"));
  112. inData.setIfsRowVersion(technicalMap.get("IFSROWVERSION"));
  113. //调用api同步信息
  114. Map<String, String> resultMap = TechnicalClassApi.modifyTechnicalClass(srv, inData);
  115. //设置唯一键和版本
  116. inData.setIfsRowVersion(resultMap.get("OBJVERSION"));
  117. returnMap.put("resultCode", "200");
  118. returnMap.put("obj", JSON.toJSONString(inData));
  119. } catch(APException e){
  120. returnMap.put("resultCode", "400");
  121. returnMap.put("resultMsg", e.getMessage());
  122. logger.info("异常信息:"+e.getMessage());
  123. }
  124. //插入查询的记录数据
  125. logger.info("Technical Class 修改结束:"+JSON.toJSONString(inData));
  126. //返回结果集
  127. return returnMap;
  128. }
  129. /**
  130. * @description: 刪除技术等级的信息
  131. * @author LR
  132. * @date 2024/12/16 13:46
  133. * @version 1.0
  134. */
  135. public Map<String, String> removeTechnicalClass(Server srv, PartIfsCatalogModel inData) {
  136. logger.info("Technical Class 删除开始:"+JSON.toJSONString(inData));
  137. //公共参数
  138. Map<String, String> returnMap = new HashMap<>();
  139. String luName = inData.getLuName(); //
  140. String keyRef = inData.getKeyRef(); //
  141. try{
  142. //查询对象
  143. Map<String, String> technicalMap = TechnicalClassApi.getTechnicalClass(srv, luName, keyRef);
  144. //判断查询导数据
  145. if(technicalMap == null || technicalMap.isEmpty()) {
  146. throw new APException("不存在此技术等级的信息!");
  147. }
  148. //设置IFS的信息
  149. inData.setIfsRowId(technicalMap.get("IFSROWID"));
  150. inData.setIfsRowVersion(technicalMap.get("IFSROWVERSION"));
  151. //调用api同步信息
  152. TechnicalClassApi.removeTechnicalClass(srv, inData);
  153. returnMap.put("resultCode", "200");
  154. returnMap.put("obj", JSON.toJSONString(inData));
  155. } catch(APException e){
  156. returnMap.put("resultCode", "400");
  157. returnMap.put("resultMsg", e.getMessage());
  158. logger.info("异常信息:"+e.getMessage());
  159. }
  160. //插入查询的记录数据
  161. logger.info("Technical Class 删除结束:"+JSON.toJSONString(inData));
  162. //返回结果集
  163. return returnMap;
  164. }
  165. /**
  166. * @description: 批量同步技术等级属性数据
  167. * @author LR
  168. * @date 2024/12/19 15:02
  169. * @version 1.0
  170. */
  171. public Map<String, String> modifyTechnicalClassAttributes(Server srv, List<PartIfsCatalogProperty> inDatas) {
  172. logger.info("Technical Class Attributes 批量修改开始:"+JSON.toJSONString(inDatas));
  173. Map<String, String> returnMap = new HashMap<>();
  174. PartIfsCatalogProperty inData = inDatas.get(0);
  175. // 公共参数
  176. String luName = inData.getLuName(); //
  177. String keyRef = inData.getKeyRef(); //
  178. try{
  179. //查询技术等级
  180. Map<String, String> technicalMap = TechnicalClassApi.getTechnicalClass(srv, luName, keyRef);
  181. //判断查询导数据
  182. //判断查询导数据
  183. if(technicalMap == null || technicalMap.isEmpty()) {
  184. throw new APException("不存在此技术等级的信息!");
  185. }
  186. //设置唯一键和版本
  187. String technicalSpecNo = technicalMap.get("TECHNICAL_SPEC_NO");
  188. String technicalClass = inData.getTechnicalClass();
  189. //打印日志
  190. //查询当前技术等级下的所有属性的数据
  191. List<Map<String, String>> resultList = TechnicalClassApi.getTechnicalAttributesMap(srv, technicalSpecNo, technicalClass);
  192. //调用方法 获取需要修改的数据
  193. List<PartIfsCatalogProperty> paramList = this.getAndCheckNeedUpdateList(resultList, inDatas);
  194. //打印日志
  195. logger.info("Technical Class Attributes 最终批量修改:"+JSON.toJSONString(paramList));
  196. logger.info("Technical Class Attributes 最终批量数量:"+JSON.toJSONString(paramList.size()));
  197. //循环设置参数
  198. for(PartIfsCatalogProperty tempData : paramList) {
  199. //设置替代的ifs的key
  200. tempData.setTechnicalSpecNo(technicalSpecNo);
  201. logger.info("属性编码:"+tempData.getAttribute());
  202. //api修改参数
  203. Map<String, String> resultMap = TechnicalClassApi.modifyTechnicalAttribute(srv, tempData);
  204. //设置记录的版本
  205. tempData.setIfsRowVersion(resultMap.get("OBJVERSION"));
  206. }
  207. returnMap.put("resultCode", "200");
  208. returnMap.put("obj", JSON.toJSONString(inDatas));
  209. } catch(APException e){
  210. returnMap.put("resultCode", "400");
  211. returnMap.put("resultMsg", e.getMessage());
  212. logger.info("异常信息:"+e.getMessage());
  213. }
  214. //插入查询的记录数据
  215. logger.info("Technical Class Attributes 批量修改结束:"+JSON.toJSONString(inDatas));
  216. //返回结果集
  217. return returnMap;
  218. }
  219. /**
  220. * @description: 获取需要修改的数据 不需要修改的数据不再放入循环操作中
  221. * @author LR
  222. * @date 2025/4/28 09:45
  223. * @version 1.0
  224. */
  225. public List<PartIfsCatalogProperty> getAndCheckNeedUpdateList(List<Map<String, String>> resultList, List<PartIfsCatalogProperty> inDatas) {
  226. //数据转Map 键为属性名称
  227. Map<String, PartIfsCatalogProperty> newMap = new HashMap<>();
  228. List<PartIfsCatalogProperty> updateList = new ArrayList<>();
  229. //循环转换
  230. for(PartIfsCatalogProperty bean : inDatas) {
  231. newMap.put(bean.getAttribute(), bean);
  232. }
  233. //循环比较数据是否一直
  234. for (Map<String, String> resultMap : resultList){
  235. String attribute = resultMap.get("ATTRIBUTE"); // 属性编码
  236. String attributeType = resultMap.get("ATTRIBUTETYPE"); // 属性类型
  237. String valueText = resultMap.get("VALUE_TEXT"); // 文本值
  238. String valueNo = resultMap.get("VALUE_NO"); // 数字值
  239. //接口路传过来的新值
  240. if (!newMap.containsKey(attribute)){
  241. continue;
  242. }
  243. PartIfsCatalogProperty tempBean = newMap.get(attribute);
  244. //针对文本和数据使用不同的比较方式
  245. if(attributeType.equals("Alpha")) {
  246. String newValueText = tempBean.getValueText();
  247. //如果都是空字符串 或者都是null 跳过修改
  248. if ((null == newValueText || "NULL".equalsIgnoreCase(newValueText) || newValueText.trim().isEmpty())
  249. && (null == valueText || "NULL".equalsIgnoreCase(valueText) || valueText.trim().isEmpty())){
  250. continue;
  251. }else if (newValueText.equals(valueText)){
  252. continue;
  253. }
  254. } else if (attributeType.equals("Numeric")) {
  255. String newValueNo = tempBean.getValueNo();
  256. //如果都是空字符串 或者都是null 跳过修改
  257. if ((null == newValueNo || "NULL".equalsIgnoreCase(newValueNo) || newValueNo.trim().isEmpty())
  258. && (null == valueNo || "NULL".equalsIgnoreCase(valueNo) || valueNo.trim().isEmpty())){
  259. continue;
  260. }else if (!newValueNo.equals(valueNo)){
  261. if ((newValueNo != null && "".equals(newValueNo.trim())) || (valueNo != null && "".equals(valueNo.trim()))){
  262. //添加ifsRowId ifsRowVersion
  263. logger.info("可以放到修改中: 原始值:"+valueNo+",新值:"+newValueNo);
  264. }else {
  265. //判断是否是相同大小的数字
  266. BigDecimal oriValue = new BigDecimal(valueNo);
  267. oriValue = oriValue.setScale(6, BigDecimal.ROUND_HALF_UP);
  268. logger.info("原始值:"+oriValue+",新值:"+newValueNo);
  269. BigDecimal newValue = new BigDecimal(newValueNo);
  270. if(oriValue.compareTo(newValue) == 0) {
  271. continue;
  272. }
  273. }
  274. }
  275. }
  276. //添加ifsRowId ifsRowVersion
  277. String ifsRowId = resultMap.get("IFSROWID");
  278. String ifsRowVersion = resultMap.get("IFSROWVERSION");
  279. tempBean.setIfsRowId(ifsRowId);
  280. tempBean.setIfsRowVersion(ifsRowVersion);
  281. updateList.add(tempBean);
  282. }
  283. //返回需要处理的数据
  284. return updateList;
  285. }
  286. /**
  287. * @description: 批量删除技术等级属性数据
  288. * @author LR
  289. * @date 2024/12/19 15:02
  290. * @version 1.0
  291. */
  292. public Map<String, String> removeTechnicalClassAttributes(Server srv, List<PartIfsCatalogProperty> inDatas) {
  293. logger.info("Technical Class Attributes 批量删除开始:"+JSON.toJSONString(inDatas));
  294. Map<String, String> returnMap = new HashMap<>();
  295. PartIfsCatalogProperty inData = inDatas.get(0);
  296. // 公共参数
  297. String luName = inData.getLuName(); //
  298. String keyRef = inData.getKeyRef(); //
  299. try{
  300. //查询技术等级
  301. Map<String, String> technicalMap = TechnicalClassApi.getTechnicalClass(srv, luName, keyRef);
  302. logger.info("技术等级查询");
  303. //判断查询导数据
  304. if(technicalMap == null || technicalMap.isEmpty()) {
  305. throw new APException("不存在此技术等级的信息!");
  306. }
  307. //设置唯一键和版本
  308. String technicalSpecNo = technicalMap.get("TECHNICAL_SPEC_NO");
  309. String technicalClass = inData.getTechnicalClass();
  310. //循环设置参数
  311. for(PartIfsCatalogProperty tempData : inDatas) {
  312. String attribute = tempData.getAttribute();
  313. //查询属性信息
  314. Map<String, String> attributeMap = TechnicalClassApi.getTechnicalAttribute(srv, technicalSpecNo, technicalClass, attribute);
  315. if(attributeMap == null || attributeMap.isEmpty()) {
  316. throw new APException("不存在此技术等级的属性信息!");
  317. }
  318. logger.info("技术等级属性查询");
  319. //设置替代的ifs的key
  320. tempData.setIfsRowId(attributeMap.get("IFSROWID"));
  321. tempData.setIfsRowVersion(attributeMap.get("IFSROWVERSION"));
  322. tempData.setAttributeType(attributeMap.get("ATTRIBUTETYPE"));
  323. tempData.setTechnicalSpecNo(technicalSpecNo);
  324. logger.info("技术等级属性删除开始");
  325. //api修改参数
  326. TechnicalClassApi.removeTechnicalAttribute(srv, tempData);
  327. logger.info("技术等级属性删除结束");
  328. }
  329. returnMap.put("resultCode", "200");
  330. returnMap.put("obj", JSON.toJSONString(inDatas));
  331. } catch(APException e){
  332. returnMap.put("resultCode", "400");
  333. returnMap.put("resultMsg", e.getMessage());
  334. logger.info("异常信息:"+e.getMessage());
  335. }
  336. //插入查询的记录数据
  337. logger.info("Technical Class Attributes 批量删除结束:"+JSON.toJSONString(inDatas));
  338. //返回结果集
  339. return returnMap;
  340. }
  341. /**
  342. * @description: 批量删除技术等级的集合数据
  343. * @author DouDou
  344. * @date 2025/9/10 13:28
  345. * @version 1.0
  346. */
  347. public Map<String, String> removeTechnicalClassAttributesByTechnicalClass(Server srv, PartIfsCatalogModel inData) {
  348. logger.info("Technical Class Attributes 批量删除开始:"+JSON.toJSONString(inData));
  349. Map<String, String> returnMap = new HashMap<>();
  350. // 公共参数
  351. String luName = inData.getLuName(); //
  352. String keyRef = inData.getKeyRef(); //
  353. try{
  354. //查询技术等级
  355. Map<String, String> technicalMap = TechnicalClassApi.getTechnicalClass(srv, luName, keyRef);
  356. //判断查询导数据
  357. if(technicalMap == null || technicalMap.isEmpty()) {
  358. throw new APException("不存在此技术等级的信息!");
  359. }
  360. //设置唯一键和版本
  361. String technicalSpecNo = technicalMap.get("TECHNICAL_SPEC_NO");
  362. String technicalClass = technicalMap.get("TECHNICAL_CLASS");
  363. logger.info("技术等级模版信息:"+JSON.toJSONString(technicalMap));
  364. //查询属性集合批量删除
  365. List<PartIfsCatalogProperty> resultList = TechnicalClassApi.getTechnicalAttributeList(srv, technicalSpecNo, technicalClass);
  366. logger.info("技术等级属性集合信息:"+JSON.toJSONString(resultList));
  367. //循环删除 只删除有数据的对象 ---没有对象的数据 不处理
  368. for(PartIfsCatalogProperty tempData : resultList) {
  369. logger.info("技术等级属性删除开始:"+JSON.toJSONString(tempData));
  370. //api修改参数
  371. TechnicalClassApi.removeTechnicalAttribute(srv, tempData);
  372. logger.info("技术等级属性删除结束:"+JSON.toJSONString(tempData));
  373. }
  374. returnMap.put("resultCode", "200");
  375. returnMap.put("obj", JSON.toJSONString(resultList));
  376. } catch(APException e){
  377. returnMap.put("resultCode", "400");
  378. returnMap.put("resultMsg", e.getMessage());
  379. logger.info("异常信息:"+e.getMessage());
  380. }
  381. //插入查询的记录数据
  382. logger.info("Technical Class Attributes 批量删除结束:"+JSON.toJSONString(inData));
  383. //返回结果集
  384. return returnMap;
  385. }
  386. }