WmsInboundResultController.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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("/insertInboundResult")
  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. Map<String,Object> conditionMap=wmsInboundResultServiceImpl.selectInboundResultByGroupId(groupId);
  121. //如果最新的一条是自己的并且
  122. //遗留 查询批次、以及状态
  123. int batch=0;
  124. //此条件成了说明他提交之后、另外一个还没提交交
  125. if ((conditionMap!=null&&conditionMap.get("userName").toString().equals(userName)&&conditionMap.get("resultStatus").toString().equals("1"))){
  126. return success("请勿重复提交");
  127. }
  128. //此条件成了说明第二个人开始提交了
  129. if (conditionMap!=null&&!conditionMap.get("userName").toString().equals(userName)&&conditionMap.get("resultStatus").toString().equals("1")){
  130. //获得第一个人的批次
  131. //将下面的订单都录入这个批次里面
  132. for (int i=0;i<mapList.size();i++){
  133. Map<String,Object> item=mapList.get(i);
  134. //二、获得同一批的第i个的网格 解释:目前还没有设计出来网格的结构 没有做默认为 第一库、第一月台、第一垛位、第一行、第一列 \推送信息给行车工、让他们抢单代码备注了
  135. BigDecimal houseGrid = wmsInboundResultServiceImpl.getGrid(conditionMap.get("distributeId").toString(), i+1);
  136. //如果差不多、说明上一个人少扫了一次
  137. if (houseGrid==null){
  138. houseGrid = rmsPwarehouseGridService.selectGrid(mapList.size()-1, personnelWorkshopid);
  139. //创建实时库存
  140. wmspGridMaterialService.initInsertWmspGridMaterial(item,houseGrid);
  141. }
  142. //遗留 批次、网格
  143. //三、创建一个入库作业实绩
  144. WmspInboundResult wmspInboundResult = wmsInboundResultServiceImpl.initAndWmspInboundResult(i+1,personnelWorkshopid,groupId,userName,new BigDecimal(conditionMap.get("distributeId").toString()),houseGrid,item);
  145. //改变扫码实绩里面的状态
  146. int status= wmsInboundScanResultServiceImpl.updateInboundScanStatus(new BigDecimal(item.get("resultId").toString()),wmspInboundResult.getInboundId());
  147. //当都完成的时候就要去改变这一批的状态改为下发状态
  148. if(mapList.size()==i+1){
  149. int status2= wmsInboundResultServiceImpl.updateInboundStatus(new BigDecimal(conditionMap.get("distributeId").toString()));
  150. }
  151. }
  152. return success();
  153. //第n批第一次提交
  154. }else{
  155. //需要判断是否已经提交过了 通过resultId判断物质是否已经下发过了跳出、多次下发的结果
  156. Integer resultStatus= wmsInboundScanResultServiceImpl.getResultStatusByResultId(mapList.get(0).get("resultId").toString());
  157. if(resultStatus==1){
  158. return success("请勿重复下发");
  159. }
  160. //第一、创建批次
  161. WmspInboundDistribute wmspInboundDistribute=wmspInboundDistributeService.initAndCreateInboundDistribute(personnelWorkshopid,groupId,userName,batch);
  162. //将下面的订单都录入这个批次里面
  163. for (int i=0;i<mapList.size();i++){
  164. Map<String,Object> item=mapList.get(i);
  165. //二、智能的设置好这批钢材的位置、网格图
  166. //二、查询一个默认的网格 解释:目前还没有设计出来网格的结构 没有做默认为 第一库、第一月台、第一垛位、第一行、第一列 \推送信息给行车工、让他们抢单代码备注了
  167. BigDecimal houseGrid = rmsPwarehouseGridService.selectGrid(mapList.size()-1, personnelWorkshopid);
  168. //遗留 批次、网格
  169. //三、创建一个入库作业实绩
  170. WmspInboundResult wmspInboundResult = wmsInboundResultServiceImpl.initAndWmspInboundResult(i+1,personnelWorkshopid,groupId,userName,wmspInboundDistribute.getDistributeId(),houseGrid,item);
  171. //改变扫码实绩里面的状态
  172. int status= wmsInboundScanResultServiceImpl.updateInboundScanStatus(new BigDecimal(item.get("resultId").toString()),wmspInboundResult.getInboundId());
  173. //创建实时库存
  174. wmspGridMaterialService.initInsertWmspGridMaterial(item,houseGrid);
  175. }
  176. return success(null);
  177. }
  178. }
  179. /**
  180. * 新增入库实绩
  181. *
  182. * @param
  183. * @return
  184. */
  185. @ApiOperation("新增入库实绩")
  186. @PostMapping("/insertInboundResult2")
  187. @Transactional
  188. public RESTfulResult addInvoice( @RequestBody(required = false) List<Map<String, Object>> mapList) {
  189. //获取前方传来的仓库ID进行入库
  190. BigDecimal warehouseId = new BigDecimal((Integer)mapList.get(0).get("personnelWorkshopid"));
  191. String inboundValue = null;
  192. BigDecimal ST = null;
  193. if(warehouseId.intValue() == 3){
  194. inboundValue = wmsInboundResultServiceImpl.selectWarehouseName(new BigDecimal(3));
  195. }
  196. //!!!默认该仓库的所有行车工都能看到
  197. //!!!待添加,查询该仓库所有在班的行车工
  198. String personnelJobNumber = "000417";
  199. if(warehouseId.intValue() != 3){
  200. //查询入库垛位信息
  201. Map<String,Object> stackingMap = rmsStackingService.getStackingToUpdate(mapList.size(),warehouseId,personnelJobNumber);
  202. //获取入库垛位ID
  203. ST = (BigDecimal) stackingMap.get("stackingId");
  204. inboundValue = stackingMap.get("stackingNo").toString();
  205. }
  206. for (Map<String,Object> map:mapList
  207. ) {
  208. WmspInboundResult wmspInboundResult = new WmspInboundResult();
  209. wmspInboundResult.setInboundId(new BigDecimal(wmsInboundResultServiceImpl.count() + 1));
  210. /*
  211. 设置入库类型为生产入库
  212. */
  213. wmspInboundResult.setInboundType(new BigDecimal(0));
  214. /*
  215. 设置入库单编号
  216. */
  217. String number=Liushuih.generateNextNumber("WRKD-", "yyyyMMdd-", 8, 12);
  218. wmspInboundResult.setInboundNumber(number);
  219. /*
  220. 设置逻辑删除字段
  221. */
  222. wmspInboundResult.setResultDeleted(new BigDecimal(0));
  223. /*
  224. 设置常规字段
  225. */
  226. wmspInboundResult.setInsertUsername("admin");
  227. wmspInboundResult.setInsertTime(new Date());
  228. wmspInboundResult.setUpdateUsername("admin");
  229. wmspInboundResult.setUpdateTime(new Date());
  230. wmspInboundResult.setInsertUpdateRemark("无");
  231. /*
  232. 设置入库日期
  233. */
  234. wmspInboundResult.setInboundTime(new Date());
  235. /*
  236. 设置入库单状态为已下发
  237. */
  238. wmspInboundResult.setResultStatus(new BigDecimal(1));
  239. /*
  240. 设置入库状态,当异常值为0时,入库状态设为未完成;当异常值为1时,入库状态设为完成
  241. */
  242. Integer K = 1;
  243. if(warehouseId.intValue() != 3){
  244. System.out.println(map.containsKey("abnormalis"));
  245. System.out.println(map.get("abnormalis"));
  246. K = (map.containsKey("abnormalis")&&map.get("abnormalis").toString().isEmpty())?Integer.valueOf(map.get("abnormalis").toString()):0;
  247. }
  248. if (K==0){
  249. wmspInboundResult.setResultStatus(new BigDecimal(0));
  250. wmspInboundResult.setInboundIscomplete(new BigDecimal(0));
  251. }
  252. else{
  253. wmspInboundResult.setResultStatus(new BigDecimal(1));
  254. wmspInboundResult.setInboundIscomplete(new BigDecimal(1));
  255. }
  256. Integer MN = null ;
  257. Integer CC = null ;
  258. Integer CX = null ;
  259. if(warehouseId.intValue() != 3){
  260. //根据垛位ID查询物资数,确定层次层序,即网格ID
  261. HashMap<String, Object> map1 = new HashMap<>();
  262. map1.put("stackingId",ST);
  263. //获取物资数
  264. MN=rmsStackingService.selectMaterialNumber(map1);
  265. //计算层次号
  266. CC=(MN)/24+1;
  267. //计算层序号
  268. CX=(MN)%24+1;
  269. //更新垛位表
  270. rmsStackingService.updateStack(ST);
  271. }
  272. //根据仓库id、垛位ID,层次号,层序号查找仓储网格
  273. HashMap<String, Object> map3 = new HashMap<>();
  274. map3.put("warehouseId",warehouseId);
  275. map3.put("stackingID",ST);
  276. map3.put("gradationNumber",CC);
  277. map3.put("sequenceNumber",CX);
  278. BigDecimal gridId=rmsPwarehouseGridService.getGridId(map3);
  279. //设置入库实绩里面的网格ID
  280. wmspInboundResult.setGridId(gridId);
  281. /*
  282. 插入一条网格物资中间表
  283. */
  284. WmspGridMaterial wmspGridMaterial = new WmspGridMaterial();
  285. //设置主键ID
  286. wmspGridMaterial.setGmId(wmspGridMaterialMapper.getCount());
  287. wmspGridMaterial.setGridId(gridId);
  288. wmspGridMaterial.setGmNumber(new BigDecimal(1));
  289. wmspGridMaterial.setStandardDataId(new BigDecimal(1));
  290. //设置网格物资表里面的物资ID
  291. BigDecimal materialId= DataChange.dataToBigDecimal(map.get("materialId"));
  292. wmspInboundResult.setMaterialId(materialId);
  293. wmspGridMaterial.setMaterialId(materialId);
  294. //设置逻辑删除字段
  295. wmspGridMaterial.setDeleted(new BigDecimal(0));
  296. //设置常规字段
  297. wmspGridMaterial.setInsertUsername("admin");
  298. wmspGridMaterial.setInsertTime(new Date());
  299. wmspGridMaterial.setUpdateUsername("admin");
  300. wmspGridMaterial.setUpdateTime(new Date());
  301. wmspGridMaterial.setInsertUpdateRemark("无");
  302. wmspGridMaterial.setStatus(new BigDecimal(2));
  303. wmspGridMaterialService.insertWmspGridMaterial(wmspGridMaterial);
  304. /*
  305. 新增入库实绩主表
  306. */
  307. wmsInboundResultServiceImpl.insertWmsInboundResult(wmspInboundResult);
  308. /*
  309. 新增天车司机接收实绩
  310. */
  311. WmspInboundDrivingResult wmspInboundDrivingResult = new WmspInboundDrivingResult();
  312. wmspInboundDrivingResult.setDrivingId(new BigDecimal(wmsInboundDrivingResultServiceImpl.count()+1));
  313. wmspInboundDrivingResult.setDriverId(new BigDecimal(9));
  314. wmspInboundDrivingResult.setDrivingReceiveTime(new Date());
  315. wmspInboundDrivingResult.setInboundResultId(wmspInboundResult.getInboundId());
  316. wmspInboundDrivingResult.setInsertUsername("admin");
  317. wmspInboundDrivingResult.setInsertTime(new Date());
  318. wmspInboundDrivingResult.setUpdateUsername("admin");
  319. wmspInboundDrivingResult.setResultDeleted(new BigDecimal(1));
  320. wmsInboundDrivingResultServiceImpl.insertWmspInboundDrivingResult(wmspInboundDrivingResult);
  321. /*
  322. 新增选择垛位实绩
  323. */
  324. WmspInboundStackResult wmspInboundStackResult = new WmspInboundStackResult();
  325. wmspInboundStackResult.setResultId(new BigDecimal(wmsInboundStackResultServiceImpl.count()+1));
  326. wmspInboundStackResult.setInboundResultId(wmspInboundResult.getInboundId());
  327. wmspInboundStackResult.setStackingId(ST);
  328. wmspInboundStackResult.setResultDeleted(new BigDecimal(1));
  329. //设置常规字段
  330. wmspInboundStackResult.setInsertUsername("admin");
  331. wmspInboundStackResult.setInsertTime(new Date());
  332. wmspInboundStackResult.setUpdateUsername("admin");
  333. wmspInboundStackResult.setUpdateTime(new Date());
  334. wmspInboundStackResult.setInsertUpdateRemark("无");
  335. wmspInboundStackResult.setStackingStatus(new BigDecimal(0));
  336. wmsInboundStackResultServiceImpl.insertWmsInboundStackResult(wmspInboundStackResult);
  337. System.out.println(map.get("LOADA"));
  338. System.out.println(map.get("LOADB"));
  339. //判断物资是否为线材
  340. BigDecimal count = wmsInboundScanResultServiceImpl.selectMaterialTypeByMaterialId(materialId);
  341. BigDecimal resultId= new BigDecimal((Integer)map.get("resultId")) ;
  342. // BigDecimal RESULTBID= new BigDecimal((Integer)map.get("RESULTBID")) ;
  343. BigDecimal InbounId=wmspInboundResult.getInboundId();
  344. if(count!=null){
  345. /*
  346. 编辑扫描实绩-根据前台返回的扫描实绩ID修改扫描实绩
  347. */
  348. HashMap<String, Object> map5 = new HashMap<>();
  349. Map<String,Object> otherLoadMap = new HashMap<>();
  350. otherLoadMap.put("personnelWorkshopid",map.get("personnelWorkshopid"));
  351. otherLoadMap.put("personnelShifts",map.get("personnelShifts"));
  352. otherLoadMap.put("personnelTeam",map.get("personnelTeam"));
  353. otherLoadMap.put("resultId",resultId);
  354. //获取同一班次班组车间扫描次数扫描实绩
  355. List<Map<String,Object>> otherResultIds = wmsInboundScanResultServiceImpl.getOntherLoadId(otherLoadMap);
  356. //根据物资id查询是否该物资为线材
  357. //设置另一个扫描实绩id为空
  358. BigDecimal otherResultId = null;
  359. //遍历查询出的同一班次班组车间扫描次数所有扫描实绩
  360. for (Map<String,Object> otherMap : otherResultIds) {
  361. //判断,查询出来的扫描实绩id是否于点击下发的扫描实绩的id相同
  362. //如果不同,将获取到的扫描实绩主键id赋予otherResultId
  363. if (((BigDecimal) otherMap.get("resultId")).intValue() != resultId.intValue()) {
  364. otherResultId = (BigDecimal) otherMap.get("resultId");
  365. }
  366. }
  367. //更新扫描实绩
  368. map5.put("resultId",resultId);
  369. map5.put("InbounId",InbounId);
  370. wmsInboundScanResultServiceImpl.updateWmsInboundScanById(map5);
  371. map5.remove("resultId");
  372. map5.put("resultId",otherResultId);
  373. wmsInboundScanResultServiceImpl.updateWmsInboundScanById(map5);
  374. }
  375. //更新扫描实绩状态
  376. Map<String,Object> map7=new HashMap<>();
  377. map7.put("resultId",resultId);
  378. map7.put("InbounId",InbounId);
  379. wmsInboundScanResultServiceImpl.updateWmsInboundScanById(map7);
  380. }
  381. return success(inboundValue);
  382. }
  383. //根据入库实绩id查找扫描实绩
  384. @PostMapping("/selectScanResultByIboundResultId")
  385. @ApiOperation(value = "根据入库实绩id获得扫描实绩数据")
  386. @ApiImplicitParams({
  387. @ApiImplicitParam(name = "apiId", value = "", required = false, dataType = "BigDecimal"),
  388. })
  389. public RESTfulResult selectScanResultByIboundResultId(@RequestBody(required = false) Map<String, Object> mapValue,
  390. Integer apiId,
  391. Integer pageNum,
  392. Integer pageSize,
  393. String con
  394. ) {
  395. if(con != null){
  396. if(!"undefined".equals(con)){
  397. String index = "get_wms_inboundScanResult";
  398. return success(esFeign.getConResult(mapValue,index,apiId,pageNum,pageSize,con));
  399. }
  400. }
  401. List<Map<String,Object>>inboundScanResultList = null;
  402. if(mapValue.size() == 0){
  403. //将查询结果存入索引中
  404. inboundScanResultList = wmsInboundResultServiceImpl.selectScanResultByIboundResultId(mapValue);
  405. Map<String, Object> inboundScanResultMap = new HashMap<>();
  406. //添加索引
  407. inboundScanResultMap.put("index","get_wms_inboundScanResult");
  408. //添加ID
  409. inboundScanResultMap.put("indexId","inboundScanResultId");
  410. inboundScanResultList.add(inboundScanResultMap);
  411. //新建索引
  412. esFeign.insertIndex(inboundScanResultList);
  413. //删除
  414. inboundScanResultList.remove(inboundScanResultList.size() -1);
  415. }
  416. if(inboundScanResultList == null) {
  417. inboundScanResultList = wmsInboundResultServiceImpl.selectScanResultByIboundResultId(mapValue);
  418. }
  419. /*分页*/
  420. PageHelper.startPage(pageNum, pageSize);
  421. List<Map<String,Object>> columnList = wmsInboundResultServiceImpl.selectScanResultByIboundResultId(mapValue);
  422. PageListAdd pageList = columnDataUtil.tableColumnData(apiId,inboundScanResultList,columnList);
  423. return success(pageList);
  424. }
  425. }