BaseLocationInfoServiceImpl.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. package com.ruoyi.base.service.impl;
  2. import com.ruoyi.base.constant.Constant;
  3. import com.ruoyi.base.domain.BaseLocationInfo;
  4. import com.ruoyi.base.domain.BaseLocationZone;
  5. import com.ruoyi.base.domain.dto.BaseLocationInfoSameColDTO;
  6. import com.ruoyi.base.domain.vo.*;
  7. import com.ruoyi.base.mapper.BaseLocationInfoMapper;
  8. import com.ruoyi.base.mapper.BaseLocationZoneMapper;
  9. import com.ruoyi.base.service.IBaseLocationInfoService;
  10. import com.ruoyi.base.utils.CommonUtils;
  11. import com.ruoyi.common.core.domain.AjaxResult;
  12. import com.ruoyi.common.core.redis.RedisCache;
  13. import com.ruoyi.common.exception.ServiceException;
  14. import com.ruoyi.common.utils.DateUtils;
  15. import com.ruoyi.common.utils.StringUtils;
  16. import lombok.extern.slf4j.Slf4j;
  17. import org.springframework.beans.BeanUtils;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.data.redis.core.RedisTemplate;
  20. import org.springframework.stereotype.Service;
  21. import java.util.ArrayList;
  22. import java.util.Date;
  23. import java.util.List;
  24. import java.util.Map;
  25. import java.util.stream.Collectors;
  26. /**
  27. * 库位信息Service业务层处理
  28. *
  29. * @author andy
  30. * @date 2022-02-18
  31. */
  32. @Slf4j
  33. @Service
  34. public class BaseLocationInfoServiceImpl implements IBaseLocationInfoService {
  35. @Autowired
  36. private BaseLocationInfoMapper baseLocationInfoMapper;
  37. @Autowired
  38. private BaseLocationZoneMapper baseLocationZoneMapper;
  39. @Autowired
  40. private RedisCache redisCache;
  41. /**
  42. * 查询库位信息
  43. *
  44. * @param id 库位信息主键
  45. * @return 库位信息
  46. */
  47. @Override
  48. public BaseLocationInfo selectBaseLocationInfoById(Long id) {
  49. return baseLocationInfoMapper.selectBaseLocationInfoById(id);
  50. }
  51. @Override
  52. public BaseLocationInfo selectBaseLocationInfoByIdOrNo(String idOrNo, Long warehouseId) {
  53. BaseLocationInfo locationInfo = null;
  54. try {
  55. locationInfo = baseLocationInfoMapper.selectBaseLocationInfoById(Long.parseLong(idOrNo));
  56. } catch (Exception e) {
  57. }
  58. if (locationInfo == null) {
  59. return baseLocationInfoMapper.selectBaseLocationInfoByLocationNo(idOrNo, warehouseId);
  60. } else {
  61. return locationInfo;
  62. }
  63. }
  64. /**
  65. * 查询库位信息列表
  66. *
  67. * @param baseLocationInfo 库位信息
  68. * @return 库位信息
  69. */
  70. @Override
  71. public List<BaseLocationInfo> selectBaseLocationInfoList(BaseLocationInfo baseLocationInfo) {
  72. return baseLocationInfoMapper.selectBaseLocationInfoList(baseLocationInfo);
  73. }
  74. @Override
  75. public List<BaseLocationInfo> selectBaseLocationInfoList(long locId) {
  76. BaseLocationInfo baseLocationInfo = new BaseLocationInfo();
  77. baseLocationInfo.setId(locId);
  78. return baseLocationInfoMapper.selectBaseLocationInfoList(baseLocationInfo);
  79. }
  80. /**
  81. * 新增库位信息
  82. *
  83. * @param baseLocationInfo 库位信息
  84. * @return 结果
  85. */
  86. @Override
  87. public int insertBaseLocationInfo(BaseLocationInfo baseLocationInfo) {
  88. baseLocationInfo.setCreateTime(DateUtils.getNowDate());
  89. return baseLocationInfoMapper.insertBaseLocationInfo(baseLocationInfo);
  90. }
  91. /**
  92. * 修改库位信息
  93. *
  94. * @param baseLocationInfo 库位信息
  95. * @return 结果
  96. */
  97. @Override
  98. public int updateBaseLocationInfo(BaseLocationInfo baseLocationInfo) {
  99. baseLocationInfo.setUpdateTime(DateUtils.getNowDate());
  100. return baseLocationInfoMapper.updateBaseLocationInfo(baseLocationInfo);
  101. }
  102. /**
  103. * 批量删除库位信息
  104. *
  105. * @param ids 需要删除的库位信息主键
  106. * @return 结果
  107. */
  108. @Override
  109. public int deleteBaseLocationInfoByIds(Long[] ids) {
  110. return baseLocationInfoMapper.deleteBaseLocationInfoByIds(ids);
  111. }
  112. /**
  113. * 删除库位信息信息
  114. *
  115. * @param id 库位信息主键
  116. * @return 结果
  117. */
  118. @Override
  119. public int deleteBaseLocationInfoById(Long id) {
  120. return baseLocationInfoMapper.deleteBaseLocationInfoById(id);
  121. }
  122. @Override
  123. public List<TreeSelectVO> buildLocationTreeSelect() {
  124. List<BasLocationTreeSelectVO> locationTrees = buildLocationTree(0L);
  125. return locationTrees.stream().map(TreeSelectVO::new).collect(Collectors.toList());
  126. }
  127. @Override
  128. public List<BasLocationTreeSelectVO> buildLocationTree(Long zoneId) {
  129. // 查询区域,库位树把区域也组装进去
  130. BaseLocationZone queryZone = new BaseLocationZone();
  131. queryZone.setStatus("0");
  132. List<BaseLocationZone> zoneList = baseLocationZoneMapper.selectBaseLocationZoneList(queryZone);
  133. List<BasLocationTreeSelectVO> locationTreeSelectVOList = new ArrayList<>();
  134. //循环遍历每个区域的库位
  135. for (BaseLocationZone zone : zoneList) {
  136. BasLocationTreeSelectVO parent = new BasLocationTreeSelectVO();
  137. List<BasLocationTreeSelectVO> children = new ArrayList<>();
  138. BaseLocationInfo query = new BaseLocationInfo();
  139. query.setZoneId(zone.getZoneId());
  140. List<BaseLocationInfo> locationInfoList = baseLocationInfoMapper.selectBaseLocationInfoList(query);
  141. for (BaseLocationInfo b : locationInfoList) {
  142. BasLocationTreeSelectVO child = new BasLocationTreeSelectVO();
  143. child.setId(b.getId());
  144. child.setTreeName(b.getLocationNo());
  145. children.add(child);
  146. }
  147. parent.setId(zone.getZoneId());
  148. parent.setTreeName(zone.getZoneName());
  149. parent.setChildren(children);
  150. locationTreeSelectVOList.add(parent);
  151. }
  152. return locationTreeSelectVOList;
  153. }
  154. @Override
  155. public boolean checkIsLocation(String idOrNo, Long warehouseId) {
  156. BaseLocationInfo baseLocationInfo = this.selectBaseLocationInfoByIdOrNo(idOrNo, warehouseId);
  157. if (baseLocationInfo == null) {
  158. return false;
  159. } else {
  160. return true;
  161. }
  162. }
  163. @Override
  164. public List<BaseLocationInfo> selectSortedLocatinListByZoneId(Long zoneId, Long warehouseId,String orderBy) {
  165. BaseLocationInfo query = new BaseLocationInfo();
  166. query.setWarehouseId(warehouseId);
  167. query.setZoneId(zoneId);
  168. query.setOrderByClause(orderBy);
  169. return baseLocationInfoMapper.selectSortedLocationListByZoneId(query);
  170. }
  171. @Override
  172. public List<BaseLocationLotattListVO> selectSortedLocatinListByZoneId(List<Long> locationId, Long warehouseId, Map<String, String> lotatt, String sku) {
  173. List<BaseLocationLotattListVO> result = new ArrayList<>();
  174. List<BaseLocationLotattVO> locationLotattVOList = baseLocationInfoMapper.selectSortedLocationLotattListByLocationIdList(locationId, warehouseId, lotatt, sku);
  175. BaseLocationLotattListVO current = null;
  176. for (BaseLocationLotattVO vo : locationLotattVOList) {
  177. if (current == null || current.getId().longValue() != vo.getId().longValue()) {
  178. current = new BaseLocationLotattListVO();
  179. BeanUtils.copyProperties(vo, current);
  180. List<LotattInfo> lotattInfoList = new ArrayList<>();
  181. current.setLotattInfoList(lotattInfoList);
  182. result.add(current);
  183. }
  184. LotattInfo lotattObj = new LotattInfo();
  185. lotattObj.setSku(vo.getSku());
  186. lotattObj.setQty(vo.getQty());
  187. lotattObj.setLotattVO(vo.getLotattVO());
  188. current.getLotattInfoList().add(lotattObj);
  189. }
  190. return result;
  191. }
  192. @Override
  193. public int updateLocationStockStatus(Long id, String status) {
  194. return baseLocationInfoMapper.updateLocationStockStatus(id, status);
  195. }
  196. @Override
  197. public List<BaseLocationInfo> selectNeighborLocation(String colNo, Long zoneId) {
  198. List<BaseLocationInfo> colNoList = baseLocationInfoMapper.selectAllColNo();
  199. List<BaseLocationInfo> resultList = new ArrayList<>();
  200. String preColNo = "";
  201. String nextColNo = "";
  202. BaseLocationInfo currentLocation = null;
  203. for (int i = 0; i < colNoList.size(); i++) {
  204. if (!colNoList.get(i).getColNo().equals(colNo) && preColNo.equals("")) {
  205. preColNo = colNoList.get(i).getColNo();
  206. continue;
  207. }
  208. if (colNoList.get(i).getColNo().equals(colNo)) {
  209. currentLocation = colNoList.get(i);
  210. preColNo = colNoList.get(i - 1).getColNo();
  211. if (i + 1 < colNoList.size()) {
  212. nextColNo = colNoList.get(i + 1).getColNo();
  213. }
  214. continue;
  215. }
  216. if (nextColNo.equals(colNoList.get(i).getColNo())) {
  217. continue;
  218. } else {
  219. if (i + 1 < colNoList.size()) {
  220. if (currentLocation != null) {
  221. if (CommonUtils.getString(colNoList.get(i + 1).getBindSku()).equals("") || CommonUtils.getString(colNoList.get(i + 1).getBindSku()).equals(currentLocation.getBindSku())) {
  222. nextColNo = colNoList.get(i + 1).getColNo();
  223. }
  224. }
  225. }
  226. }
  227. }
  228. resultList.addAll(baseLocationInfoMapper.selectLocationByColNo(colNo));
  229. resultList.addAll(baseLocationInfoMapper.selectLocationByColNo(preColNo));
  230. resultList.addAll(baseLocationInfoMapper.selectLocationByColNo(nextColNo));
  231. return resultList;
  232. }
  233. @Override
  234. public Boolean verifyLocationIsIdle(String locationId, Long warehouseId) {
  235. BaseLocationInfo baseLocationInfo = selectBaseLocationInfoByIdOrNo(locationId, warehouseId);
  236. if (!baseLocationInfo.getStockStatus().equals(Constant.STOCK_STATUS.STOCK00.getValue())) {
  237. return false;
  238. }
  239. return true;
  240. }
  241. @Override
  242. public Boolean verifyLocationIsInStock(String locationId, Long warehouseId) {
  243. BaseLocationInfo baseLocationInfo = selectBaseLocationInfoByIdOrNo(locationId, warehouseId);
  244. if (baseLocationInfo.getIsEmpty().equals(Constant.IS_YES.Y.toString())) {
  245. return false;
  246. }
  247. return true;
  248. }
  249. @Override
  250. public boolean lockLocationStockStatus(Long id, Long warehouseId, String updateBy) {
  251. return updateLocationStockStatusAndIsEmpty(id, warehouseId, updateBy
  252. , Constant.STOCK_STATUS.STOCK10, null);
  253. }
  254. @Override
  255. public boolean unLockLocationStockStatus(Long id, Long warehouseId, String updateBy) {
  256. return updateLocationStockStatusAndIsEmpty(id, warehouseId, updateBy
  257. , Constant.STOCK_STATUS.STOCK00, null);
  258. }
  259. @Override
  260. public boolean lockLocationStockStatus(Long locationFromId, Long locationToId, Long warehouseId, String updateBy) {
  261. if (!lockLocationStockStatus(locationFromId, warehouseId, updateBy)) {
  262. return false;
  263. }
  264. return lockLocationStockStatus(locationToId, warehouseId, updateBy);
  265. }
  266. @Override
  267. public boolean unLockLocationStockStatus(Long locationFromId, Long locationToId, Long warehouseId, String updateBy) {
  268. if (!unLockLocationStockStatus(locationFromId, warehouseId, updateBy)) {
  269. return false;
  270. }
  271. return unLockLocationStockStatus(locationToId, warehouseId, updateBy);
  272. }
  273. @Override
  274. public boolean occupyLocation(Long id, Long warehouseId, String updateBy) {
  275. return updateLocationStockStatusAndIsEmpty(id, warehouseId, updateBy
  276. , null, Constant.IS_YES.N);
  277. }
  278. @Override
  279. public boolean unOccupyLocation(Long id, Long warehouseId, String updateBy) {
  280. return updateLocationStockStatusAndIsEmpty(id, warehouseId, updateBy
  281. , null, Constant.IS_YES.Y);
  282. }
  283. @Override
  284. public boolean updateLocationIdleAndEmpty(Long id, Long warehouseId, String updateBy) {
  285. return updateLocationStockStatusAndIsEmpty(id, warehouseId, updateBy
  286. , Constant.STOCK_STATUS.STOCK00, Constant.IS_YES.Y);
  287. }
  288. @Override
  289. public boolean updateLocationIdleAndNoEmpty(Long id, Long warehouseId, String updateBy) {
  290. return updateLocationStockStatusAndIsEmpty(id, warehouseId, updateBy
  291. , Constant.STOCK_STATUS.STOCK00, Constant.IS_YES.N);
  292. }
  293. @Override
  294. public List<BaseLocationInfo> selectBeforeLocationByColNo(String colNo, Long colIndex) {
  295. return baseLocationInfoMapper.selectBeforeLocationByColNo(colNo, colIndex);
  296. }
  297. @Override
  298. public List<BaseLocationInfoSameColDTO> selectSameColCanToLoc(String colNo, Long colIndex) {
  299. return baseLocationInfoMapper.selectSameColCanToLoc(colNo, colIndex);
  300. }
  301. private boolean updateLocationStockStatusAndIsEmpty(Long id, Long warehouseId, String updateBy
  302. , Constant.STOCK_STATUS stockStatus, Constant.IS_YES isYes) {
  303. BaseLocationInfo locationInfo = selectBaseLocationInfoById(id);
  304. if (locationInfo == null) {
  305. return false;
  306. }
  307. BaseLocationInfo locationInfoFromUpdate = new BaseLocationInfo();
  308. locationInfoFromUpdate.setId(locationInfo.getId());
  309. if (stockStatus != null) {
  310. locationInfoFromUpdate.setStockStatus(stockStatus.getValue());
  311. }
  312. if (isYes != null) {
  313. locationInfoFromUpdate.setIsEmpty(isYes.toString());
  314. }
  315. locationInfoFromUpdate.setUpdateBy(updateBy);
  316. locationInfoFromUpdate.setWarehouseId(warehouseId);
  317. return this.updateBaseLocationInfo(locationInfoFromUpdate) > 0;
  318. }
  319. @Override
  320. public AjaxResult importLocation(List<BaseLocationInfo> list, boolean updateSupport, String opname) {
  321. if (StringUtils.isNull(list) || list.size() == 0) {
  322. throw new ServiceException("导入库位基本信息数据不能为空!");
  323. }
  324. int successNum = 0;
  325. int failureNum = 0;
  326. StringBuilder successMsg = new StringBuilder();
  327. StringBuilder failureMsg = new StringBuilder();
  328. for (BaseLocationInfo baseLocationInfo : list) {
  329. try {
  330. if (StringUtils.isEmpty(baseLocationInfo.getLocationNo())) {
  331. baseLocationInfo.setLocationNo(baseLocationInfo.getRowNo() + "-" + StringUtils.addZero(baseLocationInfo.getColNo(), 2) + "-" + StringUtils.addZero(baseLocationInfo.getShiftNo(), 2));
  332. }
  333. BaseLocationInfo b = baseLocationInfoMapper.selectBaseLocationInfoByLocationNo(baseLocationInfo.getLocationNo(), Constant.WAREHOUSE_ID);
  334. if (b == null) {
  335. //BeanValidators.validateWithException(validator, stu);
  336. baseLocationInfo.setCreateBy(opname);
  337. baseLocationInfo.setCreateTime(new Date());
  338. baseLocationInfo.setStockStatus("00");
  339. baseLocationInfo.setWarehouseId(Constant.WAREHOUSE_ID);
  340. baseLocationInfo.setColNo(baseLocationInfo.getRowNo() + baseLocationInfo.getColNo());
  341. this.insertBaseLocationInfo(baseLocationInfo);
  342. successNum++;
  343. successMsg.append("<br/>" + successNum + "、库位 " + baseLocationInfo.getLocationNo() + " 导入成功");
  344. } else if (updateSupport) {
  345. //BeanValidators.validateWithException(validator, stu);
  346. b.setUpdateBy(opname);
  347. b.setUpdateTime(new Date());
  348. this.updateBaseLocationInfo(b);
  349. successNum++;
  350. successMsg.append("<br/>" + successNum + "、库位 " + b.getLocationNo() + " 更新成功");
  351. } else {
  352. failureNum++;
  353. failureMsg.append("<br/>" + failureNum + "、库位 " + b.getLocationNo() + " 已存在");
  354. }
  355. } catch (Exception e) {
  356. failureNum++;
  357. String msg = "<br/>" + failureNum + "、库位 " + baseLocationInfo.getLocationNo() + " 导入失败:";
  358. failureMsg.append(msg + e.getMessage());
  359. log.error(msg, e);
  360. }
  361. }
  362. if (failureNum > 0) {
  363. failureMsg.insert(0, "导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
  364. throw new ServiceException(failureMsg.toString());
  365. } else {
  366. successMsg.insert(0, "数据已全部导入成功!共 " + successNum + " 条,数据如下:");
  367. }
  368. return AjaxResult.success(successMsg);
  369. }
  370. }