WhsMngService.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. package com.oqpo.api.service.stockmng;
  2. import com.oqpo.api.entity.CodeEntity;
  3. import com.oqpo.api.entity.stockmng.*;
  4. import com.oqpo.api.enums.SystemMessageCode;
  5. import com.oqpo.api.enums.WhsDvsn;
  6. import com.oqpo.api.exception.GlobalException;
  7. import com.oqpo.api.mapper.stockmng.WhsMngMapper;
  8. import com.oqpo.api.service.CommonService;
  9. import com.oqpo.api.util.StringUtil;
  10. import com.oqpo.api.web.dto.request.GridRequest;
  11. import com.oqpo.api.web.dto.request.stockmng.SaveWhsInfoRequest;
  12. import com.oqpo.api.web.dto.response.GridResponse;
  13. import com.oqpo.api.web.dto.response.code.CodeSearchListResponse;
  14. import com.oqpo.api.web.dto.response.stinfo.item.ItemPopSearchResponse;
  15. import com.oqpo.api.web.dto.response.stockmng.*;
  16. import lombok.extern.slf4j.Slf4j;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.stereotype.Service;
  19. import org.springframework.transaction.annotation.Transactional;
  20. import java.math.BigDecimal;
  21. import java.util.List;
  22. import java.util.stream.Collectors;
  23. @Service
  24. @Slf4j
  25. public class WhsMngService extends CommonService {
  26. @Autowired
  27. private WhsMngMapper whsMngMapper;
  28. /*
  29. 창고관리 그리드 리스트 조회
  30. */
  31. public GridResponse selectWhsMngGridList(String sBrandId, String sStoreId, String sWhsDvsn, String sWhsStCd,
  32. String sWhsNm, GridRequest gridRequest) throws Exception {
  33. int gridPage = gridRequest.getGridPage();
  34. int gridSize = gridRequest.getGridSize();
  35. int gridRecords = whsMngMapper.selectWhsMngGridCnt(sBrandId, sStoreId, sWhsDvsn, sWhsStCd, sWhsNm);
  36. int gridTotal = fnCalculateGridTotal(gridSize, gridRecords);
  37. List<WhsMgntBaseInfoEntity> entities = whsMngMapper.selectWhsMngGridList(sBrandId, sStoreId, sWhsDvsn, sWhsStCd, sWhsNm, gridRequest);
  38. List<Object> gridRows = entities.stream()
  39. .map(m -> WhsMngListResponse.builder()
  40. .viewCd("R")
  41. .brandId(m.getBrandId())
  42. .brandNm(m.getBrandNm())
  43. .whsId(m.getWhsId())
  44. .whsNm(m.getWhsNm())
  45. .whsDvsn(m.getWhsDvsn())
  46. .whsDvsnNm(m.getWhsDvsnNm())
  47. .mgrNm(m.getMgrNm())
  48. .mgrTelNo(m.getMgrTelNo())
  49. .whsStCd(m.getWhsStCd())
  50. .whsStNm(m.getWhsStNm())
  51. .storeId(m.getStoreId())
  52. .storeNm(m.getStoreNm())
  53. .build())
  54. .collect(Collectors.toList());
  55. return GridResponse.toDTO(gridPage, gridTotal, gridRecords, gridRows);
  56. }
  57. /* 창고관리 정보 조회 */
  58. public WhsMngInfoResponse selectWhsMngInfo(String brandId, String storeId, String whsId) throws Exception {
  59. WhsMgntBaseInfoEntity entity = whsMngMapper.selectWhsMgntBaseInfo(brandId, storeId, whsId);
  60. return WhsMngInfoResponse.toDTO(entity);
  61. }
  62. /*
  63. Location 그리드 리스트 조회
  64. */
  65. public GridResponse selectWhsLocGridList(String brandId, String whsId, GridRequest gridRequest) throws Exception {
  66. int gridPage = gridRequest.getGridPage();
  67. int gridSize = gridRequest.getGridSize();
  68. int gridRecords = whsMngMapper.selectWhsLocGridCnt(brandId, whsId);
  69. int gridTotal = fnCalculateGridTotal(gridSize, gridRecords);
  70. List<WhsMgntBaseLocEntity> entities = whsMngMapper.selectWhsLocGridList(brandId, whsId, gridRequest);
  71. List<Object> gridRows = entities.stream()
  72. .map(m -> LocInfoListResponse.builder()
  73. .viewCd("R")
  74. .location(m.getLocation())
  75. .locationNm(m.getLocationNm())
  76. .stckDvsn(m.getStckDvsn())
  77. .stckDvsnNm(m.getStckDvsnNm())
  78. .locStCd(m.getLocStCd())
  79. .locStNm(m.getLocStNm())
  80. .build())
  81. .collect(Collectors.toList());
  82. return GridResponse.toDTO(gridPage, gridTotal, gridRecords, gridRows);
  83. }
  84. /* 창고정보 등록 */
  85. @Transactional
  86. public void addWhsInfo(String userId, SaveWhsInfoRequest saveWhsInfoRequest) throws Exception {
  87. try {
  88. // 창고관리기본정보
  89. WhsMgntBaseInfoEntity entity = new WhsMgntBaseInfoEntity();
  90. entity.setBrandId(saveWhsInfoRequest.getBrandId());
  91. entity.setWhsId(fnGetDealNo(28, "")); // 창고아이디 채번
  92. entity.setWhsNm(saveWhsInfoRequest.getWhsNm());
  93. entity.setWhsDvsn(saveWhsInfoRequest.getWhsDvsn());
  94. entity.setMgrNm(saveWhsInfoRequest.getMgrNm());
  95. entity.setMgrTelNo(saveWhsInfoRequest.getMgrTelNo());
  96. entity.setZipNo(saveWhsInfoRequest.getZipNo());
  97. entity.setAddr1(saveWhsInfoRequest.getAddr1());
  98. entity.setAddr2(saveWhsInfoRequest.getAddr2());
  99. entity.setWhsStCd(saveWhsInfoRequest.getWhsStCd());
  100. entity.setStoreId(saveWhsInfoRequest.getStoreId());
  101. entity.setWhsDvsn(StringUtil.isEmpty(entity.getStoreId()) ? WhsDvsn.BRAND.getCd() : WhsDvsn.STORE.getCd());
  102. whsMngMapper.insertWhsMgntBaseInfo(userId, entity);
  103. // 창고로케이션정보
  104. saveWhsInfoRequest.setWhsId(entity.getWhsId()); // 창고번호 지정
  105. List<WhsMgntBaseLocEntity> locEntities = saveWhsInfoRequest.toEntities(saveWhsInfoRequest.getGridInsertData());
  106. for (WhsMgntBaseLocEntity locEntity : locEntities) {
  107. // LOCATION 채번
  108. locEntity.setLocation(whsMngMapper.selectNextLocation4Whs(locEntity.getBrandId(), locEntity.getWhsId()));
  109. whsMngMapper.insertWhsMgntBaseLoc(userId, locEntity);
  110. }
  111. } catch (GlobalException e) {
  112. e.getStackTrace();
  113. throw new GlobalException(e.getSystemMessageCode());
  114. } catch (Exception e) {
  115. e.getStackTrace();
  116. throw new RuntimeException();
  117. }
  118. }
  119. /* 창고정보 수정 */
  120. @Transactional
  121. public void modifyWhsInfo(String userId, SaveWhsInfoRequest saveWhsInfoRequest) throws Exception {
  122. try {
  123. // 창고관리기본정보
  124. WhsMgntBaseInfoEntity entity = new WhsMgntBaseInfoEntity();
  125. entity.setBrandId(saveWhsInfoRequest.getBrandId());
  126. entity.setWhsId(saveWhsInfoRequest.getWhsId());
  127. entity.setWhsNm(saveWhsInfoRequest.getWhsNm());
  128. entity.setWhsDvsn(saveWhsInfoRequest.getWhsDvsn());
  129. entity.setMgrNm(saveWhsInfoRequest.getMgrNm());
  130. entity.setMgrTelNo(saveWhsInfoRequest.getMgrTelNo());
  131. entity.setZipNo(saveWhsInfoRequest.getZipNo());
  132. entity.setAddr1(saveWhsInfoRequest.getAddr1());
  133. entity.setAddr2(saveWhsInfoRequest.getAddr2());
  134. entity.setWhsStCd(saveWhsInfoRequest.getWhsStCd());
  135. entity.setStoreId(saveWhsInfoRequest.getStoreId());
  136. entity.setWhsDvsn(StringUtil.isEmpty(entity.getStoreId()) ? WhsDvsn.BRAND.getCd() : WhsDvsn.STORE.getCd());
  137. whsMngMapper.updateWhsMgntBaseInfo(userId, entity);
  138. // 창고로케이션정보
  139. // 삭제
  140. List<WhsMgntBaseLocEntity> locEntities = saveWhsInfoRequest.toEntities(saveWhsInfoRequest.getGridDeleteData());
  141. for (WhsMgntBaseLocEntity locEntity : locEntities) {
  142. whsMngMapper.deleteWhsMgntBaseLoc(userId, locEntity);
  143. }
  144. // 수정
  145. locEntities = saveWhsInfoRequest.toEntities(saveWhsInfoRequest.getGridUpdateData());
  146. for (WhsMgntBaseLocEntity locEntity : locEntities) {
  147. whsMngMapper.updateWhsMgntBaseLoc(userId, locEntity);
  148. }
  149. // 등록
  150. locEntities = saveWhsInfoRequest.toEntities(saveWhsInfoRequest.getGridInsertData());
  151. for (WhsMgntBaseLocEntity locEntity : locEntities) {
  152. // LOCATION 채번
  153. locEntity.setLocation(whsMngMapper.selectNextLocation4Whs(locEntity.getBrandId(), locEntity.getWhsId()));
  154. whsMngMapper.insertWhsMgntBaseLoc(userId, locEntity);
  155. }
  156. } catch (GlobalException e) {
  157. e.getStackTrace();
  158. throw new GlobalException(e.getSystemMessageCode());
  159. } catch (Exception e) {
  160. e.getStackTrace();
  161. throw new RuntimeException();
  162. }
  163. }
  164. /* 창고정보 삭제 */
  165. @Transactional
  166. public void removeWhsInfo(String userId, SaveWhsInfoRequest saveWhsInfoRequest) throws Exception {
  167. try {
  168. // 창고관리기본정보
  169. WhsMgntBaseInfoEntity entity = new WhsMgntBaseInfoEntity();
  170. entity.setBrandId(saveWhsInfoRequest.getBrandId());
  171. entity.setWhsId(saveWhsInfoRequest.getWhsId());
  172. whsMngMapper.deleteWhsMgntBaseInfo(userId, entity);
  173. // 창고로케이션정보
  174. whsMngMapper.deleteWhsMgntBaseLoc4Info(userId, entity);
  175. } catch (GlobalException e) {
  176. e.getStackTrace();
  177. throw new GlobalException(e.getSystemMessageCode());
  178. } catch (Exception e) {
  179. e.getStackTrace();
  180. throw new RuntimeException();
  181. }
  182. }
  183. /* 매장등록시 창고 자동 등록 */
  184. @Transactional
  185. public void addStoreWhsInfo(String userId, WhsMgntBaseInfoEntity saveWhsInfo, WhsMgntBaseLocEntity saveLocInfo) throws Exception {
  186. try {
  187. // 창고관리기본정보
  188. WhsMgntBaseInfoEntity entity = new WhsMgntBaseInfoEntity();
  189. entity.setBrandId(saveWhsInfo.getBrandId());
  190. entity.setWhsId(fnGetDealNo(28, "")); // 창고아이디 채번
  191. entity.setWhsNm(saveWhsInfo.getWhsNm());
  192. entity.setWhsDvsn(saveWhsInfo.getWhsDvsn());
  193. entity.setMgrNm(saveWhsInfo.getMgrNm());
  194. entity.setMgrTelNo(saveWhsInfo.getMgrTelNo());
  195. entity.setZipNo(saveWhsInfo.getZipNo());
  196. entity.setAddr1(saveWhsInfo.getAddr1());
  197. entity.setAddr2(saveWhsInfo.getAddr2());
  198. entity.setWhsStCd(saveWhsInfo.getWhsStCd());
  199. entity.setStoreId(saveWhsInfo.getStoreId());
  200. whsMngMapper.insertWhsMgntBaseInfo(userId, entity);
  201. // 창고로케이션정보
  202. saveLocInfo.setWhsId(entity.getWhsId());
  203. whsMngMapper.insertWhsMgntBaseLoc(userId, saveLocInfo);
  204. } catch (GlobalException e) {
  205. e.getStackTrace();
  206. throw new GlobalException(e.getSystemMessageCode());
  207. } catch (Exception e) {
  208. e.getStackTrace();
  209. throw new RuntimeException();
  210. }
  211. }
  212. /* 매장창고 상태 값 변경처리 */
  213. @Transactional
  214. public void chgStatusStoreWhsInfo(String userId, String brandId, String storeId, String whsStCd, String locStCd) throws Exception {
  215. try {
  216. whsMngMapper.updateStoreWhsStatus(userId, brandId, storeId, whsStCd);
  217. whsMngMapper.updateWhsLocStatus(userId, brandId, storeId, locStCd);
  218. } catch (GlobalException e) {
  219. e.getStackTrace();
  220. throw new GlobalException(e.getSystemMessageCode());
  221. } catch (Exception e) {
  222. e.getStackTrace();
  223. throw new RuntimeException();
  224. }
  225. }
  226. /*
  227. 창고 팝업 검색
  228. */
  229. public GridResponse searchPopWhsLocationList(String sBrandId, String sStoreId, String sWhsNm, String sWhsDvsn, GridRequest gridRequest) throws Exception {
  230. int gridPage = gridRequest.getGridPage();
  231. int gridSize = gridRequest.getGridSize();
  232. int gridRecords = 0;
  233. int gridTotal = 0;
  234. //창고구분(브랜드 W01/매장 W02)
  235. /*
  236. String sWhsDvsn = "W01";
  237. if (!"".equals(sStoreId) && sStoreId != null) {
  238. sWhsDvsn = "W02";
  239. }
  240. */
  241. List<WhsMgntBaseInfoEntity> entities = whsMngMapper.selectPopWhsLocList(sBrandId, sWhsDvsn, sStoreId, sWhsNm);
  242. List<Object> gridRows = entities.stream()
  243. .map(m -> WhsLocationPopListResponse.builder()
  244. .brandId(m.getBrandId())
  245. .brandNm(m.getBrandNm())
  246. .whsId(m.getWhsId())
  247. .whsNm(m.getWhsNm())
  248. .location(m.getLocationInfo() == null ? "" : m.getLocationInfo().getLocation() == null ? "" : m.getLocationInfo().getLocation())
  249. .locationNm(m.getLocationInfo() == null ? "" : m.getLocationInfo().getLocationNm() == null ? "" : m.getLocationInfo().getLocationNm())
  250. .stckDvsn(m.getLocationInfo() == null ? "" : m.getLocationInfo().getStckDvsn() == null ? "" : m.getLocationInfo().getStckDvsn())
  251. .stckDvsnNm(m.getLocationInfo() == null ? "" : m.getLocationInfo().getStckDvsnNm() == null ? "" : m.getLocationInfo().getStckDvsnNm())
  252. .build())
  253. .collect(Collectors.toList());
  254. return GridResponse.toDTO(gridPage, gridTotal, gridRecords, gridRows);
  255. }
  256. }