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.

352 lines
13 KiB

1 year ago
1 year ago
  1. package com.spring.ifs.bean;
  2. import com.alibaba.fastjson.JSON;
  3. import com.spring.ifs.api.BaseSearchApi;
  4. import com.spring.ifs.api.BaseSearchApiTest;
  5. import com.spring.ifs.api.IfsServer;
  6. import com.spring.ifs.api.TechnicalClassApi;
  7. import com.spring.ifs.data.*;
  8. import com.spring.modules.base.entity.WorkCenterCost;
  9. import com.spring.modules.base.vo.PersonnelLevelVo;
  10. import com.spring.modules.part.entity.APIEntity.PartIfsInventory;
  11. import com.spring.modules.part.entity.PartInformationEntity;
  12. import com.spring.modules.part.vo.InventoryPartUnitCostSumVo;
  13. import ifs.fnd.ap.APException;
  14. import ifs.fnd.ap.Server;
  15. import org.slf4j.Logger;
  16. import org.slf4j.LoggerFactory;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.stereotype.Component;
  19. import java.util.ArrayList;
  20. import java.util.HashMap;
  21. import java.util.List;
  22. import java.util.Map;
  23. /**
  24. * @description: 基础查询的实现类
  25. * @author LR
  26. * @date 2024/12/9 11:49
  27. * @version 1.0
  28. */
  29. @Component
  30. public class BaseSearchBeanTest {
  31. @Autowired
  32. private IfsServer ifsServer;
  33. private static final Logger logger = LoggerFactory.getLogger(BaseSearchBean.class);
  34. /**
  35. * @description: 查询加工中心
  36. * @author LR
  37. * @date 2024/12/12 13:23
  38. * @version 1.0
  39. */
  40. public List<WorkCenter> getWorkCenterNos(BaseSearchData inData) throws APException {
  41. //查询的参数
  42. String username = inData.getIfsUsername();
  43. String password = inData.getIfsPassword();
  44. String siteCon = inData.getSiteCon();
  45. String ifsRowVersion = inData.getIfsRowVersion();
  46. logger.info("请求参数:"+siteCon);
  47. //获取连接
  48. Server srv = ifsServer.getIfsServer(username, password);
  49. List<WorkCenter> resultList = BaseSearchApiTest.getWorkCenterNos(srv, siteCon, ifsRowVersion);;
  50. logger.info("返回集合大小:"+resultList.size());
  51. return resultList;
  52. }
  53. /**
  54. * @description: 查询
  55. * @author LR
  56. * @date 2024/12/12 13:24
  57. * @version 1.0
  58. */
  59. public List<WarehouseLocation> getWarehouseLocations(BaseSearchData inData) throws APException {
  60. //查询的参数
  61. String username = inData.getIfsUsername();
  62. String password = inData.getIfsPassword();
  63. String siteCon = inData.getSiteCon();
  64. String ifsRowVersion = inData.getIfsRowVersion();
  65. logger.info("请求参数:"+siteCon);
  66. //获取连接
  67. Server srv = ifsServer.getIfsServer(username, password);
  68. List<WarehouseLocation> resultList = new ArrayList<>();
  69. int pageSize = 200;
  70. //迭代查询
  71. for(int i = 0; i < 150; i++){
  72. int startIndex = i * pageSize;
  73. List<WarehouseLocation> tempList = BaseSearchApiTest.getWarehouseLocations(srv, siteCon, startIndex, pageSize);
  74. //判断查询是否结束
  75. if(tempList.size() > 0) {
  76. resultList.addAll(tempList);
  77. }else {
  78. break;
  79. }
  80. }
  81. logger.info("返回集合大小:"+resultList.size());
  82. return resultList;
  83. }
  84. /**
  85. * @description: 获取人员等级的信息
  86. * @author LR
  87. * @date 2024/12/12 13:29
  88. * @version 1.0
  89. */
  90. public List<LaborClass> getIfsLaborClasss(BaseSearchData inData) throws APException {
  91. //查询的参数
  92. String username = inData.getIfsUsername();
  93. String password = inData.getIfsPassword();
  94. String siteCon = inData.getSiteCon();
  95. String ifsRowVersion = inData.getIfsRowVersion();
  96. //获取连接
  97. Server srv = ifsServer.getIfsServer(username, password);
  98. return BaseSearchApiTest.getIfsLaborClasss(srv, siteCon, ifsRowVersion);
  99. }
  100. /**
  101. * @description: 查询物料件的信息
  102. * @author LR
  103. * @date 2024/12/9 13:28
  104. * @version 1.0
  105. */
  106. public List<PartCatalog> getMasterParts(BaseSearchData inData) throws APException {
  107. //公共参数
  108. String username = inData.getIfsUsername();
  109. String password = inData.getIfsPassword();
  110. String ifsRowVersion = inData.getIfsRowVersion();
  111. //获取连接
  112. Server srv = ifsServer.getIfsServer(username, password);
  113. List<PartCatalog> resultList = new ArrayList<>();
  114. int pageSize = 200;
  115. //迭代查询
  116. for(int i = 0; i < 10; i++){
  117. int startIndex = i * pageSize;
  118. List<PartCatalog> tempList = BaseSearchApiTest.getPartCatalogs(srv, ifsRowVersion, startIndex, pageSize);
  119. //判断查询是否结束
  120. if(tempList.size() > 0) {
  121. resultList.addAll(tempList);
  122. }else {
  123. break;
  124. }
  125. }
  126. logger.info("返回集合大小:"+resultList.size());
  127. return resultList;
  128. }
  129. /**
  130. * @description: 查询库存件的属性值
  131. * @author LR
  132. * @date 2024/12/12 13:33
  133. * @version 1.0
  134. */
  135. public List<InventoryValue> getInventoryValues(BaseSearchData inData) throws APException {
  136. //查询的参数
  137. String username = inData.getIfsUsername();
  138. String password = inData.getIfsPassword();
  139. String siteCon = inData.getSiteCon();
  140. String ifsRowVersion = inData.getIfsRowVersion();
  141. logger.info("库存件cost value请求参数:"+siteCon);
  142. //获取连接
  143. Server srv = ifsServer.getIfsServer(username, password);
  144. List<InventoryValue> resultList = new ArrayList<>();
  145. int pageSize = 200;
  146. //迭代查询
  147. for(int i = 0; i < 10; i++){
  148. int startIndex = i * pageSize;
  149. List<InventoryValue> tempList = BaseSearchApiTest.getInventoryValues(srv, siteCon, ifsRowVersion, startIndex, pageSize);
  150. //判断查询是否结束
  151. if(tempList.size() > 0) {
  152. resultList.addAll(tempList);
  153. }else {
  154. break;
  155. }
  156. }
  157. logger.info("返回集合大小:"+resultList.size());
  158. return resultList;
  159. }
  160. /**
  161. * @description: 获取库存件的预估成本
  162. * @author HP
  163. * @date 2025-12-19 16:25
  164. * @version 1.0
  165. */
  166. public InventoryPartUnitCostSumVo getInventoryEstimatedMaterialCostByPartNo(BaseSearchData inData) throws APException{
  167. //查询的参数
  168. //查询的参数
  169. String username = inData.getIfsUsername();
  170. String password = inData.getIfsPassword();
  171. String site = inData.getSite();
  172. String partNo = inData.getPartNo();
  173. logger.info("库存件cost value请求参数 域:"+site+",物料编码:"+partNo);
  174. //获取连接
  175. Server srv = ifsServer.getIfsServer(username, password);
  176. InventoryPartUnitCostSumVo resultRow = BaseSearchApi.getInventoryEstimatedMaterialCostByPartNo(srv, site, partNo);
  177. //判断null
  178. if(resultRow == null) {
  179. throw new APException("库存件按成本不存在!");
  180. }
  181. logger.info("返回集合大小:"+resultRow.toString());
  182. return resultRow;
  183. }
  184. /**
  185. * @description: 按照条件查询库存件的成本
  186. * @author LR
  187. * @date 2025/1/17 11:40
  188. * @version 1.0
  189. */
  190. public InventoryValue getInventoryValueByPartNo(BaseSearchData inData) throws APException {
  191. //查询的参数
  192. String site = inData.getSite();
  193. String partNo = inData.getPartNo();
  194. String username = inData.getIfsUsername();
  195. String password = inData.getIfsPassword();
  196. logger.info("库存件cost value请求参数 域:"+site+",物料编码:"+partNo);
  197. //获取连接
  198. Server srv = ifsServer.getIfsServer(username, password);
  199. InventoryValue resultRow = BaseSearchApiTest.getInventoryValueByPartNo(srv, site, partNo);
  200. //判断null
  201. if(resultRow == null) {
  202. throw new APException("库存件按成本不存在!");
  203. }
  204. logger.info("返回集合大小:"+resultRow.toString());
  205. return resultRow;
  206. }
  207. /**
  208. * @description: 按照条件查询技术等级的数据
  209. * @author LR
  210. * @date 2025/1/17 13:20
  211. * @version 1.0
  212. */
  213. public List<TechnicalAttribute> getTechnicalAttributesByCon(BaseSearchData inData) throws APException {
  214. String username = inData.getIfsUsername();
  215. String password = inData.getIfsPassword();
  216. String keyRef = inData.getKeyRef();
  217. String luName = inData.getLuName() ;
  218. //获取连接
  219. Server srv = ifsServer.getIfsServer(username, password);
  220. //查询主表对应的信息
  221. Map<String, String> resultMap = TechnicalClassApi.getTechnicalClass(srv, luName, keyRef);
  222. //获取关联键
  223. String technicalSpecNo = resultMap.get("TECHNICAL_SPEC_NO");
  224. //查询技术等级属性的列表数据
  225. List<TechnicalAttribute> resultList = BaseSearchApi.getTechnicalAttributesByCon(srv, technicalSpecNo);
  226. return resultList;
  227. }
  228. /**
  229. * @description: 查询加工中心成本
  230. * @author LR
  231. * @date 2025/1/17 13:20
  232. * @version 1.0
  233. */
  234. public List<WorkCenterCost> getWorkCenterCosts(BaseSearchData inData) throws APException {
  235. //查询的参数
  236. String username = inData.getIfsUsername();
  237. String password = inData.getIfsPassword();
  238. String siteCon = inData.getSiteCon();
  239. String ifsRowVersion = inData.getIfsRowVersion();
  240. logger.info("加工中心成本的请求参数:"+siteCon);
  241. List<WorkCenterCost> resultList = new ArrayList<>();
  242. int pageSize = 200;
  243. //获取连接
  244. Server srv = ifsServer.getIfsServer(username, password);
  245. //迭代查询
  246. for(int i = 0; i < 20; i++){
  247. int startIndex = i * pageSize;
  248. List<WorkCenterCost> tempList = BaseSearchApi.getWorkCenterCosts(srv, siteCon, ifsRowVersion, startIndex, pageSize);
  249. //判断查询是否结束
  250. if(tempList.size() > 0) {
  251. resultList.addAll(tempList);
  252. }else {
  253. break;
  254. }
  255. }
  256. logger.info("返回集合大小:"+resultList.size());
  257. return resultList;
  258. }
  259. /**
  260. * @description: 按照时间获取所有域下的库存件信息
  261. * @author LR
  262. * @date 2025/3/7 11:01
  263. * @version 1.0
  264. */
  265. public List<PartIfsInventory> getInventoryParts(BaseSearchData inData) throws APException {
  266. //查询的参数
  267. String ifsRowVersion = inData.getIfsRowVersion();
  268. String username = inData.getIfsUsername();
  269. String password = inData.getIfsPassword();
  270. logger.info("库存件查询的请求参数:"+ifsRowVersion);
  271. List<PartIfsInventory> resultList = new ArrayList<>();
  272. int pageSize = 200;
  273. //获取连接
  274. Server srv = ifsServer.getIfsServer(username, password);
  275. //迭代查询
  276. for(int i = 0; i < 10; i++){
  277. int startIndex = i * pageSize;
  278. List<PartIfsInventory> tempList = BaseSearchApi.getInventoryParts(srv, ifsRowVersion, startIndex, pageSize);
  279. //判断查询是否结束
  280. if(tempList.size() > 0) {
  281. resultList.addAll(tempList);
  282. }else {
  283. break;
  284. }
  285. }
  286. //过滤重复的数据
  287. List<PartIfsInventory> returnList = new ArrayList<>();
  288. Map<String, Integer> checkMap = new HashMap<>();
  289. for (PartIfsInventory partIfsInventory : resultList){
  290. String key = partIfsInventory.getContract() +"-"+partIfsInventory.getPartNo();
  291. if (checkMap.containsKey(key)){
  292. int index = checkMap.get(key);
  293. returnList.set(index, partIfsInventory);
  294. }else {
  295. returnList.add(partIfsInventory);
  296. checkMap.put(key, returnList.size() - 1);
  297. }
  298. }
  299. logger.info("返回集合大小:"+returnList.size());
  300. return returnList;
  301. }
  302. /**
  303. * @description: 查询人员等级成本
  304. * @author LR
  305. * @date 2025/5/6 11:55
  306. * @version 1.0
  307. */
  308. public List<PersonnelLevelVo> getLaborClassCosts(BaseSearchData inData) throws APException {
  309. //查询的参数
  310. logger.info("人员等级成本开始查询!");
  311. String username = inData.getIfsUsername();
  312. String password = inData.getIfsPassword();
  313. String siteCon = inData.getSiteCon();
  314. List<PersonnelLevelVo> resultList = new ArrayList<>();
  315. int pageSize = 200;
  316. try {
  317. Server srv = ifsServer.getIfsServer(username, password);
  318. //迭代查询
  319. for(int i = 0; i < 150; i++){
  320. int startIndex = i * pageSize;
  321. List<PersonnelLevelVo> tempList = BaseSearchApi.getLaborClassCosts(srv, siteCon, startIndex, pageSize);
  322. //判断查询是否结束
  323. if(tempList.size() > 0) {
  324. resultList.addAll(tempList);
  325. }else {
  326. break;
  327. }
  328. }
  329. } catch (APException e){
  330. throw new APException("异常信息:"+e.getMessage());
  331. }
  332. logger.info("人员等级成本结束查询,返回集合大小:"+resultList.size());
  333. return resultList;
  334. }
  335. }