WmsInboundResultController.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. package com.steerinfo.dil.controller;
  2. import com.steerinfo.dil.feign.ESFeign;
  3. import com.steerinfo.dil.mapper.WmspGridMaterialMapper;
  4. import com.steerinfo.dil.model.*;
  5. import com.steerinfo.dil.service.ICommonService;
  6. import com.steerinfo.dil.service.IWmspInboundDistributeService;
  7. import com.steerinfo.dil.service.impl.*;
  8. import com.steerinfo.dil.util.*;
  9. import com.steerinfo.framework.controller.RESTfulResult;
  10. import com.steerinfo.framework.service.pagehelper.PageHelper;
  11. import io.swagger.annotations.Api;
  12. import io.swagger.annotations.ApiImplicitParam;
  13. import io.swagger.annotations.ApiImplicitParams;
  14. import io.swagger.annotations.ApiOperation;
  15. import io.swagger.models.auth.In;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.transaction.annotation.Transactional;
  18. import org.springframework.web.bind.annotation.*;
  19. import java.math.BigDecimal;
  20. import java.util.*;
  21. //import java.util.*;
  22. /**
  23. * @author luobang
  24. * @create 2021-09-06 18:13
  25. */
  26. @Api("入库实绩")
  27. @RestController
  28. @RequestMapping("${api.version}/inboundResult")
  29. public class WmsInboundResultController extends BaseRESTfulController {
  30. @Autowired
  31. ColumnDataUtil columnDataUtil;
  32. @Autowired
  33. ESFeign esFeign;
  34. @Autowired
  35. WmsInboundResultServiceImpl wmsInboundResultServiceImpl;
  36. @Autowired
  37. WmsInboundScanResultServiceImpl wmsInboundScanResultServiceImpl;
  38. @Autowired
  39. WmsInboundDrivingResultServiceImpl wmsInboundDrivingResultServiceImpl;
  40. @Autowired
  41. RmsStackingServiceImpl rmsStackingService;
  42. @Autowired
  43. RmsPwarehouseGridServiceImpl rmsPwarehouseGridService;
  44. @Autowired
  45. WmspGridMaterialServiceImpl wmspGridMaterialService;
  46. @Autowired
  47. WmspGridMaterialMapper wmspGridMaterialMapper;
  48. @Autowired
  49. WmsInboundStackResultServiceImpl wmsInboundStackResultServiceImpl;
  50. @Autowired
  51. WmspInboundDistributeServiceImpl wmspInboundDistributeService;
  52. @Autowired
  53. ICommonService commonService;
  54. /**
  55. * 展示入库实绩
  56. * @param mapValue
  57. * @param apiId
  58. * @param pageNum
  59. * @param pageSize
  60. * @return
  61. */
  62. @PostMapping("/getWmsInboundResult2")
  63. @ApiOperation(value = "展示入库实绩信息")
  64. @ApiImplicitParams({
  65. @ApiImplicitParam(name = "apiId", value = "90", required = false, dataType = "BigDecimal"),
  66. })
  67. public RESTfulResult getWmsInboundResult(@RequestBody(required = false) Map<String, Object> mapValue,
  68. Integer apiId,
  69. Integer pageNum,
  70. Integer pageSize,
  71. String con) {
  72. if(con != null){
  73. if(!"undefined".equals(con)){
  74. String index = "get_wms_inboundresult";
  75. return success(esFeign.getConResult(mapValue,index,apiId,pageNum,pageSize,con));
  76. }
  77. }
  78. List<Map<String,Object>>inboundResultList = null;
  79. if(mapValue.size() == 0){
  80. //将查询结果存入索引中
  81. inboundResultList = wmsInboundResultServiceImpl.getInboundResult(mapValue);
  82. Map<String, Object> inboundResultMap = new HashMap<>();
  83. //添加索引
  84. inboundResultMap.put("index","get_wms_inboundresultse");
  85. //添加ID
  86. inboundResultMap.put("indexId","inboundresultId");
  87. inboundResultList.add(inboundResultMap);
  88. //新建索引
  89. esFeign.insertIndex(inboundResultList);
  90. //删除
  91. inboundResultList.remove(inboundResultList.size() -1);
  92. }
  93. if(inboundResultList == null) {
  94. inboundResultList = wmsInboundResultServiceImpl.getInboundResult(mapValue);
  95. }
  96. /*分页*/
  97. PageHelper.startPage(pageNum, pageSize);
  98. List<Map<String,Object>> columnList = wmsInboundResultServiceImpl.getInboundResult(mapValue);
  99. PageListAdd pageList = columnDataUtil.tableColumnData(apiId,inboundResultList,columnList);
  100. return success(pageList);
  101. }
  102. /**
  103. * 新增入库实绩
  104. *
  105. * @param
  106. * @return
  107. */
  108. @ApiOperation("新增入库实绩")
  109. @PostMapping("/insertInboundResult2")
  110. @Transactional
  111. public RESTfulResult addInvoice(@RequestParam("userName") String userName,@RequestParam("groupId") BigDecimal groupId,@RequestParam("personnelWorkshopid") BigDecimal personnelWorkshopid, @RequestBody(required = false) List<Map<String, Object>> mapList) {
  112. //首先做的判断处理
  113. //由于钢材是分批次、一批四件的(有特殊情况不是一批四件)
  114. //所有需要设置他们批次不能跨越一个应该是相连的,如果批次跨过两个说明有一个多按了一次,或者是有了一个人少按了一次,所以需要少下发的和多下发的对其。
  115. //使两个人批次相同
  116. //查询当前分组下次最新的一次下发、
  117. // 第一、判断库状态是否是下发中的
  118. // 第二、判断自己上一组是否完成,如果上一组已经完成则开始下一组、没有完成给一点提示
  119. //遗留 查询批次、以及状态
  120. //一、创建一个批次信息
  121. WmspInboundDistribute wmspInboundDistribute=new WmspInboundDistribute();
  122. //初始化下发批次信息
  123. //主键
  124. wmspInboundDistribute.setDistributeId(IDUtils.createIDYMDHMS(commonService.getSeqCount("seq_WMSP_INBOUND_DISTRIBUTE")));
  125. //分组
  126. wmspInboundDistribute.setInboundGroupId(groupId);
  127. //入库状态 1、下发中、2、已完成、3、已接受、4、已结束
  128. //如果两个都已经下发改变状态为已下发、只有一个下发改变状态为下发中
  129. //2、并且当前改变当前用户的,未下发状态为已经下发(给扫码实绩赋值入库实绩id)
  130. wmspInboundDistribute.setResultStatus(new BigDecimal(1));
  131. //当前用户批次
  132. wmspInboundDistribute.setBatch(new BigDecimal(1));
  133. //行车工 没有接收是没有这个字段的
  134. //wmspInboundDistribute.setDistributeId();
  135. //创建用户
  136. wmspInboundDistribute.setInsertUsername(userName);
  137. for (int i=0;i<mapList.size();i++){
  138. Map<String,Object> item=mapList.get(i);
  139. //二、智能的设置好这批钢材的位置、网格图
  140. //二、创建一个默认的网格 解释:目前还没有设计出来网格的结构 没有做默认为 第一库、第一月台、第一垛位、第一行、第一列
  141. //遗留 批次、网格
  142. //三、创建一个入库作业实绩
  143. WmspInboundResult wmspInboundResult=new WmspInboundResult();
  144. //1、给实绩属性赋值
  145. int orderNumber = wmsInboundResultServiceImpl.count();
  146. // 主键ID
  147. wmspInboundResult.setInboundId(IDUtils.createIDYMD(String.valueOf(orderNumber)));
  148. //批次ID
  149. wmspInboundResult.setInboundDistributeId(wmspInboundDistribute.getDistributeId());
  150. //入库类型
  151. wmspInboundResult.setInboundType(new BigDecimal(0));
  152. //入库单/退库单/倒库单编号(WRKD-年月日-8位数的顺序号)
  153. String number=Liushuih.generateNextNumber("WRKD-", "yyyyMMdd-", 8, orderNumber);
  154. wmspInboundResult.setInboundNumber(number);
  155. //仓储网格
  156. //wmspInboundResult.setGridId(new BigDecimal(1));
  157. //入库单是否下发:0:未下发;1:已下发; 2:已接收
  158. wmspInboundResult.setResultStatus(new BigDecimal(0));
  159. //物资ID
  160. wmspInboundResult.setMaterialId(new BigDecimal(item.get("materialId").toString()));
  161. //入库是否完成(0:未完成,1:已完成)
  162. wmspInboundResult.setInboundIscomplete(new BigDecimal(0));
  163. //逻辑删除:1:删除;0:未删除
  164. wmspInboundResult.setResultDeleted(new BigDecimal(0));
  165. //入库日期
  166. wmspInboundResult.setInboundTime(new Date());
  167. //记录创建人
  168. wmspInboundResult.setInsertUsername(userName);
  169. //记录创建时间
  170. wmspInboundResult.setInsertTime(new Date());
  171. }
  172. //四、推送信息给行车工、让他们抢单
  173. return success(null);
  174. }
  175. /**
  176. * 新增入库实绩
  177. *
  178. * @param
  179. * @return
  180. */
  181. @ApiOperation("新增入库实绩")
  182. @PostMapping("/insertInboundResult")
  183. @Transactional
  184. public RESTfulResult addInvoice( @RequestBody(required = false) List<Map<String, Object>> mapList) {
  185. //获取前方传来的仓库ID进行入库
  186. BigDecimal warehouseId = new BigDecimal((Integer)mapList.get(0).get("personnelWorkshopid"));
  187. String inboundValue = null;
  188. BigDecimal ST = null;
  189. if(warehouseId.intValue() == 3){
  190. inboundValue = wmsInboundResultServiceImpl.selectWarehouseName(new BigDecimal(3));
  191. }
  192. //!!!默认该仓库的所有行车工都能看到
  193. //!!!待添加,查询该仓库所有在班的行车工
  194. String personnelJobNumber = "000417";
  195. if(warehouseId.intValue() != 3){
  196. //查询入库垛位信息
  197. Map<String,Object> stackingMap = rmsStackingService.getStackingToUpdate(mapList.size(),warehouseId,personnelJobNumber);
  198. //获取入库垛位ID
  199. ST = (BigDecimal) stackingMap.get("stackingId");
  200. inboundValue = stackingMap.get("stackingNo").toString();
  201. }
  202. for (Map<String,Object> map:mapList
  203. ) {
  204. WmspInboundResult wmspInboundResult = new WmspInboundResult();
  205. wmspInboundResult.setId(new BigDecimal(wmsInboundResultServiceImpl.count() + 1));
  206. /*
  207. 设置入库类型为生产入库
  208. */
  209. wmspInboundResult.setInboundType(new BigDecimal(0));
  210. /*
  211. 设置入库单编号
  212. */
  213. String number=Liushuih.generateNextNumber("WRKD-", "yyyyMMdd-", 8, 12);
  214. wmspInboundResult.setInboundNumber(number);
  215. /*
  216. 设置逻辑删除字段
  217. */
  218. wmspInboundResult.setResultDeleted(new BigDecimal(0));
  219. /*
  220. 设置常规字段
  221. */
  222. wmspInboundResult.setInsertUsername("admin");
  223. wmspInboundResult.setInsertTime(new Date());
  224. wmspInboundResult.setUpdateUsername("admin");
  225. wmspInboundResult.setUpdateTime(new Date());
  226. wmspInboundResult.setInsertUpdateRemark("无");
  227. /*
  228. 设置入库日期
  229. */
  230. wmspInboundResult.setInboundTime(new Date());
  231. /*
  232. 设置入库单状态为已下发
  233. */
  234. wmspInboundResult.setResultStatus(new BigDecimal(1));
  235. /*
  236. 设置入库状态,当异常值为0时,入库状态设为未完成;当异常值为1时,入库状态设为完成
  237. */
  238. Integer K = 1;
  239. if(warehouseId.intValue() != 3){
  240. System.out.println(map.containsKey("abnormalis"));
  241. System.out.println(map.get("abnormalis"));
  242. K = (map.containsKey("abnormalis")&&map.get("abnormalis").toString().isEmpty())?Integer.valueOf(map.get("abnormalis").toString()):0;
  243. }
  244. if (K==0){
  245. wmspInboundResult.setResultStatus(new BigDecimal(0));
  246. wmspInboundResult.setInboundIscomplete(new BigDecimal(0));
  247. }
  248. else{
  249. wmspInboundResult.setResultStatus(new BigDecimal(1));
  250. wmspInboundResult.setInboundIscomplete(new BigDecimal(1));
  251. }
  252. Integer MN = null ;
  253. Integer CC = null ;
  254. Integer CX = null ;
  255. if(warehouseId.intValue() != 3){
  256. //根据垛位ID查询物资数,确定层次层序,即网格ID
  257. HashMap<String, Object> map1 = new HashMap<>();
  258. map1.put("stackingId",ST);
  259. //获取物资数
  260. MN=rmsStackingService.selectMaterialNumber(map1);
  261. //计算层次号
  262. CC=(MN+1)/24+1;
  263. //计算层序号
  264. CX=(MN+1)%24;
  265. //更新垛位表
  266. rmsStackingService.updateStack(ST);
  267. }
  268. //根据仓库id、垛位ID,层次号,层序号查找仓储网格
  269. HashMap<String, Object> map3 = new HashMap<>();
  270. map3.put("warehouseId",warehouseId);
  271. map3.put("stackingID",ST);
  272. map3.put("gradationNumber",CC);
  273. map3.put("sequenceNumber",CX);
  274. BigDecimal gridId=rmsPwarehouseGridService.getGridId(map3);
  275. //设置入库实绩里面的网格ID
  276. wmspInboundResult.setGridId(gridId);
  277. /*
  278. 插入一条网格物资中间表
  279. */
  280. WmspGridMaterial wmspGridMaterial = new WmspGridMaterial();
  281. //设置主键ID
  282. wmspGridMaterial.setGmId(wmspGridMaterialMapper.getCount());
  283. wmspGridMaterial.setGridId(gridId);
  284. wmspGridMaterial.setGmNumber(new BigDecimal(1));
  285. wmspGridMaterial.setStandardDataId(new BigDecimal(1));
  286. //设置网格物资表里面的物资ID
  287. BigDecimal materialId= DataChange.dataToBigDecimal(map.get("materialId"));
  288. wmspInboundResult.setMaterialId(materialId);
  289. wmspGridMaterial.setMaterialId(materialId);
  290. //设置逻辑删除字段
  291. wmspGridMaterial.setDeleted(new BigDecimal(0));
  292. //设置常规字段
  293. wmspGridMaterial.setInsertUsername("admin");
  294. wmspGridMaterial.setInsertTime(new Date());
  295. wmspGridMaterial.setUpdateUsername("admin");
  296. wmspGridMaterial.setUpdateTime(new Date());
  297. wmspGridMaterial.setInsertUpdateRemark("无");
  298. wmspGridMaterial.setStatus(new BigDecimal(2));
  299. wmspGridMaterialService.insertWmspGridMaterial(wmspGridMaterial);
  300. /*
  301. 新增入库实绩主表
  302. */
  303. wmsInboundResultServiceImpl.insertWmsInboundResult(wmspInboundResult);
  304. /*
  305. 新增天车司机接收实绩
  306. */
  307. WmspInboundDrivingResult wmspInboundDrivingResult = new WmspInboundDrivingResult();
  308. wmspInboundDrivingResult.setDrivingId(new BigDecimal(wmsInboundDrivingResultServiceImpl.count()+1));
  309. wmspInboundDrivingResult.setDriverId(new BigDecimal(9));
  310. wmspInboundDrivingResult.setDrivingReceiveTime(new Date());
  311. wmspInboundDrivingResult.setInboundResultId(wmspInboundResult.getInboundId());
  312. wmspInboundDrivingResult.setInsertUsername("admin");
  313. wmspInboundDrivingResult.setInsertTime(new Date());
  314. wmspInboundDrivingResult.setUpdateUsername("admin");
  315. wmspInboundDrivingResult.setResultDeleted(new BigDecimal(1));
  316. wmsInboundDrivingResultServiceImpl.insertWmspInboundDrivingResult(wmspInboundDrivingResult);
  317. /*
  318. 新增选择垛位实绩
  319. */
  320. WmspInboundStackResult wmspInboundStackResult = new WmspInboundStackResult();
  321. wmspInboundStackResult.setResultId(new BigDecimal(wmsInboundStackResultServiceImpl.count()+1));
  322. wmspInboundStackResult.setInboundResultId(wmspInboundResult.getInboundId());
  323. wmspInboundStackResult.setStackingId(ST);
  324. wmspInboundStackResult.setResultDeleted(new BigDecimal(1));
  325. //设置常规字段
  326. wmspInboundStackResult.setInsertUsername("admin");
  327. wmspInboundStackResult.setInsertTime(new Date());
  328. wmspInboundStackResult.setUpdateUsername("admin");
  329. wmspInboundStackResult.setUpdateTime(new Date());
  330. wmspInboundStackResult.setInsertUpdateRemark("无");
  331. wmspInboundStackResult.setStackingStatus(new BigDecimal(0));
  332. wmsInboundStackResultServiceImpl.insertWmsInboundStackResult(wmspInboundStackResult);
  333. System.out.println(map.get("LOADA"));
  334. System.out.println(map.get("LOADB"));
  335. //判断物资是否为线材
  336. BigDecimal count = wmsInboundScanResultServiceImpl.selectMaterialTypeByMaterialId(materialId);
  337. BigDecimal resultId= new BigDecimal((Integer)map.get("resultId")) ;
  338. // BigDecimal RESULTBID= new BigDecimal((Integer)map.get("RESULTBID")) ;
  339. BigDecimal InbounId=wmspInboundResult.getInboundId();
  340. if(count!=null){
  341. /*
  342. 编辑扫描实绩-根据前台返回的扫描实绩ID修改扫描实绩
  343. */
  344. HashMap<String, Object> map5 = new HashMap<>();
  345. Map<String,Object> otherLoadMap = new HashMap<>();
  346. otherLoadMap.put("personnelWorkshopid",map.get("personnelWorkshopid"));
  347. otherLoadMap.put("personnelShifts",map.get("personnelShifts"));
  348. otherLoadMap.put("personnelTeam",map.get("personnelTeam"));
  349. otherLoadMap.put("resultId",resultId);
  350. //获取同一班次班组车间扫描次数扫描实绩
  351. List<Map<String,Object>> otherResultIds = wmsInboundScanResultServiceImpl.getOntherLoadId(otherLoadMap);
  352. //根据物资id查询是否该物资为线材
  353. //设置另一个扫描实绩id为空
  354. BigDecimal otherResultId = null;
  355. //遍历查询出的同一班次班组车间扫描次数所有扫描实绩
  356. for (Map<String,Object> otherMap : otherResultIds) {
  357. //判断,查询出来的扫描实绩id是否于点击下发的扫描实绩的id相同
  358. //如果不同,将获取到的扫描实绩主键id赋予otherResultId
  359. if (((BigDecimal) otherMap.get("resultId")).intValue() != resultId.intValue()) {
  360. otherResultId = (BigDecimal) otherMap.get("resultId");
  361. }
  362. }
  363. //更新扫描实绩
  364. map5.put("resultId",resultId);
  365. map5.put("InbounId",InbounId);
  366. wmsInboundScanResultServiceImpl.updateWmsInboundScanById(map5);
  367. map5.remove("resultId");
  368. map5.put("resultId",otherResultId);
  369. wmsInboundScanResultServiceImpl.updateWmsInboundScanById(map5);
  370. }
  371. //更新扫描实绩状态
  372. Map<String,Object> map7=new HashMap<>();
  373. map7.put("resultId",resultId);
  374. map7.put("InbounId",InbounId);
  375. wmsInboundScanResultServiceImpl.updateWmsInboundScanById(map7);
  376. }
  377. return success(inboundValue);
  378. }
  379. //根据入库实绩id查找扫描实绩
  380. @PostMapping("/selectScanResultByIboundResultId")
  381. @ApiOperation(value = "根据入库实绩id获得扫描实绩数据")
  382. @ApiImplicitParams({
  383. @ApiImplicitParam(name = "apiId", value = "", required = false, dataType = "BigDecimal"),
  384. })
  385. public RESTfulResult selectScanResultByIboundResultId(@RequestBody(required = false) Map<String, Object> mapValue,
  386. Integer apiId,
  387. Integer pageNum,
  388. Integer pageSize,
  389. String con
  390. ) {
  391. if(con != null){
  392. if(!"undefined".equals(con)){
  393. String index = "get_wms_inboundScanResult";
  394. return success(esFeign.getConResult(mapValue,index,apiId,pageNum,pageSize,con));
  395. }
  396. }
  397. List<Map<String,Object>>inboundScanResultList = null;
  398. if(mapValue.size() == 0){
  399. //将查询结果存入索引中
  400. inboundScanResultList = wmsInboundResultServiceImpl.selectScanResultByIboundResultId(mapValue);
  401. Map<String, Object> inboundScanResultMap = new HashMap<>();
  402. //添加索引
  403. inboundScanResultMap.put("index","get_wms_inboundScanResult");
  404. //添加ID
  405. inboundScanResultMap.put("indexId","inboundScanResultId");
  406. inboundScanResultList.add(inboundScanResultMap);
  407. //新建索引
  408. esFeign.insertIndex(inboundScanResultList);
  409. //删除
  410. inboundScanResultList.remove(inboundScanResultList.size() -1);
  411. }
  412. if(inboundScanResultList == null) {
  413. inboundScanResultList = wmsInboundResultServiceImpl.selectScanResultByIboundResultId(mapValue);
  414. }
  415. /*分页*/
  416. PageHelper.startPage(pageNum, pageSize);
  417. List<Map<String,Object>> columnList = wmsInboundResultServiceImpl.selectScanResultByIboundResultId(mapValue);
  418. PageListAdd pageList = columnDataUtil.tableColumnData(apiId,inboundScanResultList,columnList);
  419. return success(pageList);
  420. }
  421. }