ShmtOdrService.java 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. package com.oqpo.api.service.inoutmng;
  2. import com.oqpo.api.entity.inoutmng.DeliDtlMgntEntity;
  3. import com.oqpo.api.entity.inoutmng.DeliInfoMgntEntity;
  4. import com.oqpo.api.entity.inoutmng.ShmtOdrBaseEntity;
  5. import com.oqpo.api.entity.inoutmng.ShmtOdrDtlEntity;
  6. import com.oqpo.api.entity.oper.FileEntity;
  7. import com.oqpo.api.entity.pomng.PchOdrBaseInfoEntity;
  8. import com.oqpo.api.entity.pomng.PchOdrDtlPtclEntity;
  9. import com.oqpo.api.entity.stinfo.BrandEntity;
  10. import com.oqpo.api.entity.stinfo.SpplyEntity;
  11. import com.oqpo.api.entity.stinfo.StoreBaseInfoEntity;
  12. import com.oqpo.api.entity.stockmng.StckMgntBaseInfoEntity;
  13. import com.oqpo.api.entity.stockmng.StckMgntDtlHistEntity;
  14. import com.oqpo.api.enums.ChgDvsn;
  15. import com.oqpo.api.enums.InOutCd;
  16. import com.oqpo.api.enums.SystemMessageCode;
  17. import com.oqpo.api.exception.GlobalException;
  18. import com.oqpo.api.mapper.FileMapper;
  19. import com.oqpo.api.mapper.inoutmng.ShmtOdrMapper;
  20. import com.oqpo.api.mapper.pomng.PchOrdMapper;
  21. import com.oqpo.api.mapper.stinfo.BrandMapper;
  22. import com.oqpo.api.mapper.stinfo.StoreBaseInfoMapper;
  23. import com.oqpo.api.mapper.stinfo.SupplyMapper;
  24. import com.oqpo.api.mapper.stockmng.StockMngMapper;
  25. import com.oqpo.api.service.CommonService;
  26. import com.oqpo.api.service.pomng.PchOrdService;
  27. import com.oqpo.api.web.dto.request.GridRequest;
  28. import com.oqpo.api.web.dto.request.inoutmng.InstShmtOdrRequest;
  29. import com.oqpo.api.web.dto.request.inoutmng.SaveSpplyDlvRequest;
  30. import com.oqpo.api.web.dto.response.GridResponse;
  31. import com.oqpo.api.web.dto.response.inoutmng.*;
  32. import com.oqpo.api.web.dto.response.pomng.pchOrd.SpplyPoOdrSearchListResponse;
  33. import lombok.extern.slf4j.Slf4j;
  34. import org.springframework.beans.factory.annotation.Autowired;
  35. import org.springframework.stereotype.Service;
  36. import org.springframework.transaction.annotation.Transactional;
  37. import java.util.ArrayList;
  38. import java.util.List;
  39. import java.util.stream.Collectors;
  40. @Service
  41. @Slf4j
  42. public class ShmtOdrService extends CommonService {
  43. @Autowired
  44. private ShmtOdrMapper shmtOdrMapper;
  45. @Autowired
  46. private StockMngMapper stockMngMapper;
  47. @Autowired
  48. private PchOrdMapper pchOrdMapper;
  49. @Autowired
  50. private PchOrdService pchOrdService;
  51. @Autowired
  52. private BrandMapper brandMapper;
  53. @Autowired
  54. private SupplyMapper supplyMapper;
  55. @Autowired
  56. private StoreBaseInfoMapper storeBaseInfoMapper;
  57. @Autowired
  58. private FileMapper fileMapper;
  59. /*
  60. 출하 대상 그리드 리스트 조회
  61. */
  62. public GridResponse selectShmtTargetOdrGridList(String sBrandId, String fromDt, String toDt, String sShmtWhsId, String sWhsId, String sItemNm, GridRequest gridRequest) throws Exception {
  63. int gridPage = gridRequest.getGridPage();
  64. int gridSize = gridRequest.getGridSize();
  65. fromDt = fromDt == null ? null : fromDt.replace(".", "");
  66. toDt = toDt == null ? null : toDt.replace(".", "");
  67. int gridRecords = shmtOdrMapper.selectShmtTargetOdrGridCnt(sBrandId, fromDt, toDt, sShmtWhsId, sWhsId, sItemNm);
  68. int gridTotal = fnCalculateGridTotal(gridSize, gridRecords);
  69. List<PchOdrBaseInfoEntity> entities = shmtOdrMapper.selectShmtTargetOdrGridList(sBrandId, fromDt, toDt, sShmtWhsId, sWhsId, sItemNm, gridRequest);
  70. List<Object> gridRows = entities.stream()
  71. .map(m -> ShmtOdrSearchListResponse.builder()
  72. .viewCd("R")
  73. .brandId(m.getBrandId() == null ? "" : m.getBrandId())
  74. .brandNm(m.getBrandNm() == null ? "" : m.getBrandNm())
  75. .pchPodrUnqNo(m.getPchPodrUnqNo() == null ? "" : m.getPchPodrUnqNo())
  76. .pchPodrDtlNo(m.getPchOdrDtlInfo() == null ? "" : m.getPchOdrDtlInfo().getPchPodrDtlNo() == null ? "" : m.getPchOdrDtlInfo().getPchPodrDtlNo())
  77. .itemId(m.getPchOdrDtlInfo() == null ? "" : m.getPchOdrDtlInfo().getItemId() == null ? "" : m.getPchOdrDtlInfo().getItemId())
  78. .itemNm(m.getPchOdrDtlInfo() == null ? "" : m.getPchOdrDtlInfo().getItemNm() == null ? "" : m.getPchOdrDtlInfo().getItemNm())
  79. .whsId(m.getWhsId() == null ? "" : m.getWhsId())
  80. .whsNm(m.getWhsNm() == null ? "" : m.getWhsNm() + " - " + m.getLocationNm())
  81. .location(m.getLocation() == null ? "" : m.getLocation())
  82. .unitAmt(m.getPchOdrDtlInfo() == null ? 0 : m.getPchOdrDtlInfo().getUnitAmt() == null ? 0 : m.getPchOdrDtlInfo().getUnitAmt())
  83. .podrQty(m.getPchOdrDtlInfo() == null ? 0 : m.getPchOdrDtlInfo().getPodrQty() == null ? 0 : m.getPchOdrDtlInfo().getPodrQty())
  84. .shmtQty(m.getPchOdrDtlInfo() == null ? 0 : m.getPchOdrDtlInfo().getShmtQty() == null ? 0 : m.getPchOdrDtlInfo().getShmtQty())
  85. .stckQty(m.getPchOdrDtlInfo() == null ? 0 : m.getPchOdrDtlInfo().getStckQty() == null ? 0 : m.getPchOdrDtlInfo().getStckQty())
  86. .expryYn(m.getPchOdrDtlInfo() == null ? "" : m.getPchOdrDtlInfo().getExpryYn() == null ? "" : m.getPchOdrDtlInfo().getExpryYn())
  87. .expryPeriod(m.getPchOdrDtlInfo() == null ? 0 : m.getPchOdrDtlInfo().getExpryPeriod() == null ? 0 : m.getPchOdrDtlInfo().getExpryPeriod())
  88. .expryDate(m.getPchOdrDtlInfo() == null ? "" : m.getPchOdrDtlInfo().getExpryDate() == null ? "" : m.getPchOdrDtlInfo().getExpryDate())
  89. .podrAmt(m.getPchOdrDtlInfo() == null ? 0 : m.getPchOdrDtlInfo().getPodrAmt() == null ? 0 : m.getPchOdrDtlInfo().getPodrAmt())
  90. .dlvReqDt(m.getDlvReqDt() == null ? "" : m.getDlvReqDt())
  91. .shmtWhsId(m.getShmtWhsId() == null ? "" : m.getShmtWhsId())
  92. .shmtLocation(m.getShmtLocation() == null ? "" : m.getShmtLocation())
  93. .shmtWhsNm(m.getShmtWhsNm() == null ? "" : m.getShmtWhsNm() + " - " + m.getShmtLocationNm())
  94. .build())
  95. .collect(Collectors.toList());
  96. return GridResponse.toDTO(gridPage, gridTotal, gridRecords, gridRows);
  97. }
  98. /*
  99. 출하지시 저장
  100. */
  101. @Transactional
  102. public void instShmtOdr(String userId, InstShmtOdrRequest instShmtOdrRequest) throws Exception {
  103. try {
  104. // 출하창고 + 납품장소 동일여부 체크
  105. // 출하창고의 재고 와 출하수량 비교처리
  106. // 발주수량은 출하수량보다 크거나 같아야함
  107. // 유통기한 품목에 대해서는 유통기한일자 기입 필수
  108. // 출하 헤더 생성
  109. // 출하 상세 생성
  110. // 납품서 헤더 생성
  111. // 납품서 상세 생성성
  112. List<PchOdrDtlPtclEntity> gridInsertData = instShmtOdrRequest.toCodeEntities(instShmtOdrRequest.getGridInsertData());
  113. List<PchOdrBaseInfoEntity> jobList = shmtOdrMapper.selectShmtJobDataList(instShmtOdrRequest.getBrandId(), gridInsertData);
  114. List<StckMgntBaseInfoEntity> stockList = new ArrayList<StckMgntBaseInfoEntity>();
  115. String whsId = "";
  116. String location = "";
  117. String shmtWhsId = "";
  118. String shmtLocation = "";
  119. int itemQty = 0;
  120. int shmtTotalAmt = 0;
  121. String expryDate = "";
  122. int shmtQty = 0;
  123. String shmtReqUnqNo = "";
  124. String dlvSttmtUnqNo = "";
  125. ShmtOdrBaseEntity shmtBaseEntity = new ShmtOdrBaseEntity();
  126. List<ShmtOdrDtlEntity> shmtDtlList = new ArrayList<ShmtOdrDtlEntity>();
  127. DeliInfoMgntEntity deliBaseEntity = new DeliInfoMgntEntity();
  128. List<DeliDtlMgntEntity> deliDtlList = new ArrayList<DeliDtlMgntEntity>();
  129. for (int i = 0; i < jobList.size(); i++) {
  130. PchOdrBaseInfoEntity entity = jobList.get(i);
  131. for (int j = 0; j < gridInsertData.size(); j++) {
  132. PchOdrDtlPtclEntity reqEntity = gridInsertData.get(j);
  133. if (entity.getPchPodrUnqNo().equals(reqEntity.getPchPodrUnqNo()) && entity.getPchOdrDtlInfo().getPchPodrDtlNo().equals(reqEntity.getPchPodrDtlNo())) {
  134. if (reqEntity.getShmtQty() > entity.getPchOdrDtlInfo().getPodrQty()) {
  135. // 발주수량보다 출고수량이 많을수 없습니다.
  136. throw new GlobalException(SystemMessageCode.ERR_POSHNONQTY);
  137. }
  138. if ("Y".equals(entity.getPchOdrDtlInfo().getExpryYn())) {
  139. if (reqEntity.getExpryDate() == null || "".equals(reqEntity.getExpryDate())) {
  140. // 유통기한을 입력해주세요!
  141. throw new GlobalException(SystemMessageCode.ERR_NONEXPRY);
  142. }
  143. }
  144. expryDate = reqEntity.getExpryDate().replaceAll("\\.", "");
  145. shmtQty = reqEntity.getShmtQty();
  146. break;
  147. }
  148. }
  149. if (shmtWhsId.equals(entity.getShmtWhsId()) && shmtLocation.equals(entity.getShmtLocation()) && whsId.equals(entity.getWhsId()) && location.equals(entity.getLocation())) {
  150. // 추가 작업
  151. itemQty = itemQty + 1;
  152. shmtTotalAmt = shmtTotalAmt + (entity.getPchOdrDtlInfo().getUnitAmt() * shmtQty);
  153. shmtBaseEntity.setItemQty(itemQty);
  154. shmtBaseEntity.setShmtTotalAmt(shmtTotalAmt);
  155. deliBaseEntity.setDlvAmt(shmtTotalAmt);
  156. ShmtOdrDtlEntity inaddDtlEntity = new ShmtOdrDtlEntity();
  157. inaddDtlEntity.setShmtReqUnqNo(shmtReqUnqNo);
  158. int dtlNo = itemQty * 10;
  159. inaddDtlEntity.setShmtReqDtlNo(Integer.toString(dtlNo));
  160. inaddDtlEntity.setItemId(entity.getPchOdrDtlInfo().getItemId());
  161. inaddDtlEntity.setItemNm(entity.getPchOdrDtlInfo().getItemNm());
  162. inaddDtlEntity.setUnitAmt(entity.getPchOdrDtlInfo().getUnitAmt());
  163. inaddDtlEntity.setUnit(entity.getPchOdrDtlInfo().getUnit());
  164. inaddDtlEntity.setPodrQty(entity.getPchOdrDtlInfo().getPodrQty());
  165. inaddDtlEntity.setPodrAmt(entity.getPchOdrDtlInfo().getPodrAmt());
  166. inaddDtlEntity.setShmtQty(shmtQty);
  167. inaddDtlEntity.setShmtAmt(shmtQty * entity.getPchOdrDtlInfo().getUnitAmt());
  168. inaddDtlEntity.setExpryDate(expryDate);
  169. inaddDtlEntity.setPchPodrUnqNo(entity.getPchPodrUnqNo());
  170. inaddDtlEntity.setPchPodrDtlNo(entity.getPchOdrDtlInfo().getPchPodrDtlNo());
  171. inaddDtlEntity.setPchReqUnqNo(entity.getPchOdrDtlInfo().getPchReqUnqNo());
  172. inaddDtlEntity.setPchReqDtlNo(entity.getPchOdrDtlInfo().getPchReqDtlNo());
  173. shmtDtlList.add(inaddDtlEntity);
  174. //재고 수량정보 기입
  175. StckMgntBaseInfoEntity stckEntity = new StckMgntBaseInfoEntity();
  176. /*
  177. String dupYn = "N";
  178. for (int ski = 0 ; ski < stockList.size() ; ski++) {
  179. StckMgntBaseInfoEntity tmpEntity = stockList.get(ski);
  180. if (entity.getBrandId().equals(tmpEntity.getBrandId()) && entity.getShmtWhsId().equals(tmpEntity.getWhsId())
  181. && entity.getShmtLocation().equals(tmpEntity.getLocation()) && entity.getPchOdrDtlInfo().getItemId().equals(tmpEntity.getItemId())) {
  182. int tmpStckQty = tmpEntity.getStckQty() ;
  183. stockList.get(ski).setStckQty(tmpStckQty + shmtQty);
  184. dupYn = "Y";
  185. System.out.println("for============================" + Integer.toString(ski) + stockList.get(ski).getStckQty());
  186. break;
  187. }
  188. }
  189. if ("N".equals(dupYn)) {
  190. */
  191. stckEntity.setBrandId(entity.getBrandId());
  192. stckEntity.setWhsId(entity.getShmtWhsId());
  193. stckEntity.setLocation(entity.getShmtLocation());
  194. stckEntity.setItemId(entity.getPchOdrDtlInfo().getItemId());
  195. stckEntity.setStckQty(shmtQty);
  196. stckEntity.setRelationNo(shmtReqUnqNo);
  197. stockList.add(stckEntity);
  198. // }
  199. //납품서 상세 생성
  200. DeliDtlMgntEntity inaddDeliDtlEntity = new DeliDtlMgntEntity();
  201. inaddDeliDtlEntity.setDlvSttmtUnqNo(dlvSttmtUnqNo);
  202. inaddDeliDtlEntity.setDlvSttmtDtlNo(Integer.toString(dtlNo));
  203. inaddDeliDtlEntity.setPchPodrUnqNo(entity.getPchPodrUnqNo());
  204. inaddDeliDtlEntity.setPchPodrDtlNo(entity.getPchOdrDtlInfo().getPchPodrDtlNo());
  205. inaddDeliDtlEntity.setPchReqUnqNo(entity.getPchOdrDtlInfo().getPchReqUnqNo());
  206. inaddDeliDtlEntity.setPchReqDtlNo(entity.getPchOdrDtlInfo().getPchReqDtlNo());
  207. inaddDeliDtlEntity.setItemId(entity.getPchOdrDtlInfo().getItemId());
  208. inaddDeliDtlEntity.setItemNm(entity.getPchOdrDtlInfo().getItemNm());
  209. inaddDeliDtlEntity.setUnit(entity.getPchOdrDtlInfo().getUnit());
  210. inaddDeliDtlEntity.setUnitAmt(entity.getPchOdrDtlInfo().getUnitAmt());
  211. inaddDeliDtlEntity.setPodrQty(entity.getPchOdrDtlInfo().getPodrQty());
  212. inaddDeliDtlEntity.setDlvQty(shmtQty);
  213. inaddDeliDtlEntity.setPodrAmt(entity.getPchOdrDtlInfo().getPodrAmt());
  214. inaddDeliDtlEntity.setDlvAmt(shmtQty * entity.getPchOdrDtlInfo().getUnitAmt());
  215. inaddDeliDtlEntity.setExpryDate(expryDate);
  216. deliDtlList.add(inaddDeliDtlEntity);
  217. } else {
  218. // 신규로 출하건 생성함 //select fn_get_dealno(16, '') as col_cmd_unq_no
  219. if (shmtDtlList.size() > 0) {
  220. shmtOdrMapper.insertShmtOdrBase(userId, shmtBaseEntity);
  221. shmtOdrMapper.insertShmtOdrDtl(userId, shmtDtlList);
  222. shmtOdrMapper.insertDeliInfoMngt(userId, deliBaseEntity);
  223. shmtOdrMapper.insertDeliDtlPtcl(userId, deliDtlList);
  224. itemQty = 0;
  225. shmtTotalAmt = 0;
  226. }
  227. itemQty = 1;
  228. shmtTotalAmt = entity.getPchOdrDtlInfo().getUnitAmt() * shmtQty;
  229. whsId = entity.getWhsId();
  230. location = entity.getLocation();
  231. shmtWhsId = entity.getShmtWhsId();
  232. shmtLocation = entity.getShmtLocation();
  233. shmtReqUnqNo = fnGetDealNo(16, ""); // 출하지시번호
  234. dlvSttmtUnqNo = fnGetDealNo(15, ""); // 납품서번호
  235. // 출하지시
  236. shmtBaseEntity = new ShmtOdrBaseEntity();
  237. shmtDtlList = new ArrayList<ShmtOdrDtlEntity>();
  238. ShmtOdrDtlEntity inDtlEntity = new ShmtOdrDtlEntity();
  239. //납품서정보
  240. deliBaseEntity = new DeliInfoMgntEntity();
  241. deliDtlList = new ArrayList<DeliDtlMgntEntity>();
  242. DeliDtlMgntEntity deliDtlEntity = new DeliDtlMgntEntity();
  243. shmtBaseEntity.setShmtReqUnqNo(shmtReqUnqNo);
  244. shmtBaseEntity.setShmtReqStCd("SHM1");
  245. shmtBaseEntity.setShmtWhsId(entity.getShmtWhsId());
  246. shmtBaseEntity.setShmtLocation(entity.getShmtLocation());
  247. shmtBaseEntity.setWhsDvsn("W01");
  248. shmtBaseEntity.setBrandId(entity.getBrandId());
  249. shmtBaseEntity.setStoreId(entity.getStoreId());
  250. shmtBaseEntity.setPodrDvsn("OD01");
  251. shmtBaseEntity.setItemQty(itemQty);
  252. shmtBaseEntity.setShmtTotalAmt(shmtTotalAmt);
  253. shmtBaseEntity.setPodrMgrNm(entity.getPodrMgrNm());
  254. shmtBaseEntity.setDlvReqDt(entity.getDlvReqDt().replaceAll("\\.", ""));
  255. shmtBaseEntity.setWhsId(entity.getWhsId());
  256. shmtBaseEntity.setLocation(entity.getLocation());
  257. //납품서 데이타 생성
  258. deliBaseEntity.setDlvSttmtUnqNo(dlvSttmtUnqNo);
  259. deliBaseEntity.setSpplyId(null);
  260. deliBaseEntity.setSpplyNm(null);
  261. deliBaseEntity.setStoreId(entity.getStoreId());
  262. deliBaseEntity.setDlvAmt(shmtTotalAmt);
  263. deliBaseEntity.setDlvMgrNm(instShmtOdrRequest.getDlvMgrNm());
  264. deliBaseEntity.setDlvMgrTelNo(instShmtOdrRequest.getDlvMgrTelNo().replaceAll("-", ""));
  265. deliBaseEntity.setDlvMgrEmal(null);
  266. deliBaseEntity.setDlvMgrMblNo(null);
  267. deliBaseEntity.setVndrTelNo(entity.getDeliTelNo().replaceAll("-", ""));
  268. deliBaseEntity.setDlvStCd("DLV0");
  269. deliBaseEntity.setPodrRegDt(entity.getPodrDt());
  270. deliBaseEntity.setDlvReqDt(entity.getDlvReqDt().replaceAll("\\.", ""));
  271. deliBaseEntity.setDlvSchDt(instShmtOdrRequest.getDlvSchDt().replaceAll("\\.", ""));
  272. deliBaseEntity.setDlvCmpltDt(null);
  273. deliBaseEntity.setWhsId(entity.getWhsId());
  274. deliBaseEntity.setLocation(entity.getLocation());
  275. deliBaseEntity.setWhsDvsn("W01");
  276. deliBaseEntity.setBrandId(instShmtOdrRequest.getBrandId());
  277. //출하지시 상세 생성
  278. ShmtOdrDtlEntity inaddDtlEntity = new ShmtOdrDtlEntity();
  279. inaddDtlEntity.setShmtReqUnqNo(shmtReqUnqNo);
  280. inaddDtlEntity.setShmtReqDtlNo("10");
  281. inaddDtlEntity.setItemId(entity.getPchOdrDtlInfo().getItemId());
  282. inaddDtlEntity.setItemNm(entity.getPchOdrDtlInfo().getItemNm());
  283. inaddDtlEntity.setUnitAmt(entity.getPchOdrDtlInfo().getUnitAmt());
  284. inaddDtlEntity.setUnit(entity.getPchOdrDtlInfo().getUnit());
  285. inaddDtlEntity.setPodrQty(entity.getPchOdrDtlInfo().getPodrQty());
  286. inaddDtlEntity.setPodrAmt(entity.getPchOdrDtlInfo().getPodrAmt());
  287. inaddDtlEntity.setShmtQty(shmtQty);
  288. inaddDtlEntity.setShmtAmt(shmtQty * entity.getPchOdrDtlInfo().getUnitAmt());
  289. inaddDtlEntity.setExpryDate(expryDate);
  290. inaddDtlEntity.setPchPodrUnqNo(entity.getPchPodrUnqNo());
  291. inaddDtlEntity.setPchPodrDtlNo(entity.getPchOdrDtlInfo().getPchPodrDtlNo());
  292. inaddDtlEntity.setPchReqUnqNo(entity.getPchOdrDtlInfo().getPchReqUnqNo());
  293. inaddDtlEntity.setPchReqDtlNo(entity.getPchOdrDtlInfo().getPchReqDtlNo());
  294. shmtDtlList.add(inaddDtlEntity);
  295. StckMgntBaseInfoEntity stckEntity = new StckMgntBaseInfoEntity();
  296. stckEntity.setBrandId(entity.getBrandId());
  297. stckEntity.setWhsId(entity.getShmtWhsId());
  298. stckEntity.setLocation(entity.getShmtLocation());
  299. stckEntity.setItemId(entity.getPchOdrDtlInfo().getItemId());
  300. stckEntity.setStckQty(shmtQty);
  301. stckEntity.setRelationNo(shmtReqUnqNo);
  302. stockList.add(stckEntity);
  303. //납품서 상세 생성
  304. DeliDtlMgntEntity inaddDeliDtlEntity = new DeliDtlMgntEntity();
  305. inaddDeliDtlEntity.setDlvSttmtUnqNo(dlvSttmtUnqNo);
  306. inaddDeliDtlEntity.setDlvSttmtDtlNo("10");
  307. inaddDeliDtlEntity.setPchPodrUnqNo(entity.getPchPodrUnqNo());
  308. inaddDeliDtlEntity.setPchPodrDtlNo(entity.getPchOdrDtlInfo().getPchPodrDtlNo());
  309. inaddDeliDtlEntity.setPchReqUnqNo(entity.getPchOdrDtlInfo().getPchReqUnqNo());
  310. inaddDeliDtlEntity.setPchReqDtlNo(entity.getPchOdrDtlInfo().getPchReqDtlNo());
  311. inaddDeliDtlEntity.setItemId(entity.getPchOdrDtlInfo().getItemId());
  312. inaddDeliDtlEntity.setItemNm(entity.getPchOdrDtlInfo().getItemNm());
  313. inaddDeliDtlEntity.setUnit(entity.getPchOdrDtlInfo().getUnit());
  314. inaddDeliDtlEntity.setUnitAmt(entity.getPchOdrDtlInfo().getUnitAmt());
  315. inaddDeliDtlEntity.setPodrQty(entity.getPchOdrDtlInfo().getPodrQty());
  316. inaddDeliDtlEntity.setDlvQty(shmtQty);
  317. inaddDeliDtlEntity.setPodrAmt(entity.getPchOdrDtlInfo().getPodrAmt());
  318. inaddDeliDtlEntity.setDlvAmt(shmtQty * entity.getPchOdrDtlInfo().getUnitAmt());
  319. inaddDeliDtlEntity.setExpryDate(expryDate);
  320. deliDtlList.add(inaddDeliDtlEntity);
  321. }
  322. // 마지막 부분일 경우
  323. if (i == jobList.size() - 1) {
  324. if (shmtDtlList.size() > 0) {
  325. shmtOdrMapper.insertShmtOdrBase(userId, shmtBaseEntity);
  326. shmtOdrMapper.insertShmtOdrDtl(userId, shmtDtlList);
  327. shmtOdrMapper.insertDeliInfoMngt(userId, deliBaseEntity);
  328. shmtOdrMapper.insertDeliDtlPtcl(userId, deliDtlList);
  329. }
  330. }
  331. System.out.println("============================" + stockList.size());
  332. System.out.println("============================" + "end");
  333. // 재고수량 변동 및 안전비율계산(없애기로함) 처리후 저장함함
  334. stockMngMapper.updateMinStockQty(userId, stockList);
  335. //재고 이력 테이블에 데이타 생성 insertMultiStckMgntDtlHist
  336. List<StckMgntDtlHistEntity> stockHistList = new ArrayList<StckMgntDtlHistEntity>();
  337. for (int m = 0; m < stockList.size(); m++) {
  338. StckMgntBaseInfoEntity baseEntity = stockList.get(m);
  339. StckMgntDtlHistEntity sourceHist = new StckMgntDtlHistEntity();
  340. //String stckMgntDtlNo = fnGetDealNo(32,"");
  341. //String stckMgntDtlNo = commonMapper.selectDealNo(32, "");
  342. //String stckMgntDtlNo1 = commonMapper.selectDealNo(33, "");
  343. sourceHist.setStckMgntDtlNo(fnGetDealNo(32, "")); // 재고관리상세번호
  344. //System.out.println("seqno =========>" +sourceHist.getStckMgntDtlNo() + "===" + stckMgntDtlNo );
  345. sourceHist.setBrandId(baseEntity.getBrandId());
  346. sourceHist.setWhsId(baseEntity.getWhsId());
  347. sourceHist.setLocation(baseEntity.getLocation());
  348. sourceHist.setItemId(baseEntity.getItemId());
  349. sourceHist.setItemNm(baseEntity.getItemNm());
  350. sourceHist.setInoutCd(InOutCd.OUT.getCd()); // 출고
  351. sourceHist.setInoutQty(baseEntity.getStckQty());
  352. sourceHist.setChgDvsn(ChgDvsn.PURCHASE_OUT.getCd()); // 구매출고
  353. sourceHist.setRelationNo(baseEntity.getRelationNo());
  354. stockHistList.add(sourceHist);
  355. }
  356. stockMngMapper.insertMultiStckMgntDtlHist(userId, stockHistList);
  357. // 발주상태 변경처리
  358. // 1. 발주상세정보 상태 없데이트 한후 pchOrdMapper
  359. for (int poi = 0; poi < gridInsertData.size(); poi++) {
  360. gridInsertData.get(poi).setPodrDtlStCd("POD3");
  361. }
  362. pchOrdMapper.updateChangeStPodrDtl(userId, gridInsertData);
  363. // 발주 헤더 상태 처리 updateChgMultiPodrStCd
  364. String pchPodrUnqNo = "";
  365. for (int k = 0; k < gridInsertData.size(); k++) {
  366. if (!pchPodrUnqNo.equals(gridInsertData.get(k).getPchPodrUnqNo())) {
  367. pchPodrUnqNo = gridInsertData.get(k).getPchPodrUnqNo();
  368. String pchOdrStCd = pchOrdService.selectOdrDtlStatusList(pchPodrUnqNo);
  369. pchOrdMapper.updateChgPodrStCd(userId, pchOdrStCd, pchPodrUnqNo);
  370. }
  371. }
  372. }
  373. } catch (GlobalException e) {
  374. //e.getStackTrace();
  375. e.printStackTrace();
  376. throw new GlobalException(e.getSystemMessageCode());
  377. } catch (Exception e) {
  378. e.printStackTrace();
  379. throw new RuntimeException();
  380. }
  381. }
  382. /* 출하현황 */
  383. public GridResponse selectShmtSearchGridList(String sBrandId, String fromDt, String toDt, String sShmtWhsId, String sShmtReqStCd, String sWhsId, String sItemNm, GridRequest gridRequest) throws Exception {
  384. int gridPage = gridRequest.getGridPage();
  385. int gridSize = gridRequest.getGridSize();
  386. fromDt = fromDt == null ? null : fromDt.replace(".", "");
  387. toDt = toDt == null ? null : toDt.replace(".", "");
  388. int gridRecords = shmtOdrMapper.selectShmtSearchGridCnt(sBrandId, fromDt, toDt, sShmtWhsId, sShmtReqStCd, sWhsId, sItemNm);
  389. int gridTotal = fnCalculateGridTotal(gridSize, gridRecords);
  390. List<ShmtOdrBaseEntity> entities = shmtOdrMapper.selectShmtSearchGridList(sBrandId, fromDt, toDt, sShmtWhsId, sShmtReqStCd, sWhsId, sItemNm, gridRequest);
  391. List<Object> gridRows = entities.stream()
  392. .map(m -> ShmtOutSearchListResponse.builder()
  393. .viewCd("R")
  394. .shmtReqUnqNo(m.getShmtReqUnqNo() == null ? "" : m.getShmtReqUnqNo())
  395. .shmtReqDtlNo(m.getShmtOdrDtlInfo() == null ? "" : m.getShmtOdrDtlInfo().getShmtReqDtlNo() == null ? "" : m.getShmtOdrDtlInfo().getShmtReqDtlNo())
  396. .brandId(m.getBrandId() == null ? "" : m.getBrandId())
  397. .brandNm(m.getBrandNm() == null ? "" : m.getBrandNm())
  398. .pchPodrUnqNo(m.getShmtOdrDtlInfo() == null ? "" : m.getShmtOdrDtlInfo().getPchPodrUnqNo() == null ? "" : m.getShmtOdrDtlInfo().getPchPodrUnqNo())
  399. .pchPodrDtlNo(m.getShmtOdrDtlInfo() == null ? "" : m.getShmtOdrDtlInfo().getPchPodrDtlNo() == null ? "" : m.getShmtOdrDtlInfo().getPchPodrDtlNo())
  400. .shmtReqStCd(m.getShmtReqStCd() == null ? "" : m.getShmtReqStCd())
  401. .shmtReqStNm(m.getShmtReqStNm() == null ? "" : m.getShmtReqStNm())
  402. .itemId(m.getShmtOdrDtlInfo() == null ? "" : m.getShmtOdrDtlInfo().getItemId() == null ? "" : m.getShmtOdrDtlInfo().getItemId())
  403. .itemNm(m.getShmtOdrDtlInfo() == null ? "" : m.getShmtOdrDtlInfo().getItemNm() == null ? "" : m.getShmtOdrDtlInfo().getItemNm())
  404. .whsId(m.getWhsId() == null ? "" : m.getWhsId())
  405. .whsNm(m.getWhsNm() == null ? "" : m.getWhsNm() + " - " + m.getLocationNm())
  406. .location(m.getLocation() == null ? "" : m.getLocation())
  407. .shmtQty(m.getShmtOdrDtlInfo() == null ? 0 : m.getShmtOdrDtlInfo().getShmtQty() == null ? 0 : m.getShmtOdrDtlInfo().getShmtQty())
  408. .shmtAmt(m.getShmtOdrDtlInfo() == null ? 0 : m.getShmtOdrDtlInfo().getShmtAmt() == null ? 0 : m.getShmtOdrDtlInfo().getShmtAmt())
  409. .whsQty(m.getWhsProcInfo() == null ? 0 : m.getWhsProcInfo().getWhsQty() == null ? 0 : m.getWhsProcInfo().getWhsQty())
  410. .whsAmt(m.getWhsProcInfo() == null ? 0 : m.getWhsProcInfo().getWhsAmt() == null ? 0 : m.getWhsProcInfo().getWhsAmt())
  411. .whsDt(m.getWhsProcInfo() == null ? "" : m.getWhsProcInfo().getWhsDt() == null ? "" : m.getWhsProcInfo().getWhsDt())
  412. .whsCnfmNm(m.getWhsProcInfo() == null ? "" : m.getWhsProcInfo().getWhsCnfmNm() == null ? "" : m.getWhsProcInfo().getWhsCnfmNm())
  413. .dlvSttmtUnqNo(m.getDlvSttmtUnqNo() == null ? "" : m.getDlvSttmtUnqNo())
  414. .build())
  415. .collect(Collectors.toList());
  416. return GridResponse.toDTO(gridPage, gridTotal, gridRecords, gridRows);
  417. }
  418. /* 납품서 정보 */
  419. public InvInfoResponse selectInvInfo(String brandId, String dlvSttmtUnqNo) throws Exception {
  420. DeliInfoMgntEntity entity = shmtOdrMapper.selectInvInfo(brandId, dlvSttmtUnqNo);
  421. List<DeliDtlMgntEntity> dtlEntity = shmtOdrMapper.selectInvDtlList(brandId, dlvSttmtUnqNo);
  422. // 공급사
  423. // 배송처 정보
  424. BrandEntity brandEntity = brandMapper.selectBrandInfo(brandId);
  425. if ("DL01".equals(entity.getDeliDvsn())) {
  426. //브랜드정보 배송
  427. entity.setDlvBsnsRegno(brandEntity.getBsnsRegNo());
  428. entity.setDlvNm(brandEntity.getBrandNm());
  429. entity.setDlvOwnerNm(brandEntity.getOwnerNm());
  430. entity.setDlvAddr(brandEntity.getAddr1() + " " + brandEntity.getAddr2());
  431. } else {
  432. //공급사 배송
  433. SpplyEntity dlv_spplyEntity = supplyMapper.selectSpplyInfo(brandId, entity.getSpplyId());
  434. entity.setDlvBsnsRegno(dlv_spplyEntity.getBsnsRegNo());
  435. entity.setDlvNm(dlv_spplyEntity.getSpplyNm());
  436. entity.setDlvOwnerNm(dlv_spplyEntity.getOwnerNm());
  437. entity.setDlvAddr(dlv_spplyEntity.getAddr1() + " " + dlv_spplyEntity.getAddr2());
  438. }
  439. //발주처 정보
  440. if ("W01".equals(entity.getWhsDvsn())) {
  441. //납품창고 본사
  442. entity.setPoBsnsRegno(brandEntity.getBsnsRegNo());
  443. entity.setPoNm(brandEntity.getBrandNm());
  444. entity.setPoOwnerNm(brandEntity.getOwnerNm());
  445. entity.setPoAddr(brandEntity.getAddr1() + " " + brandEntity.getAddr2());
  446. } else {
  447. //납품창고 매장
  448. StoreBaseInfoEntity whs_storeBaseInfoEntity = storeBaseInfoMapper.selectStoreInfo(brandId, entity.getStoreId());
  449. entity.setPoBsnsRegno(whs_storeBaseInfoEntity.getBsnsRegNo());
  450. entity.setPoNm(whs_storeBaseInfoEntity.getStoreNm());
  451. entity.setPoOwnerNm(whs_storeBaseInfoEntity.getOwnerNm());
  452. entity.setPoAddr(whs_storeBaseInfoEntity.getAddr1() + " " + whs_storeBaseInfoEntity.getAddr2());
  453. }
  454. // 브랜드 로고 brand_logo_file_no
  455. List<FileEntity> logFileList = null;
  456. if (!"".equals(brandEntity.getBrandLogoFileNo())) {
  457. logFileList = fileMapper.selectFileList(brandEntity.getBrandLogoFileNo());
  458. } else {
  459. logFileList = new ArrayList<FileEntity>();
  460. }
  461. return InvInfoResponse.toDTO(entity, dtlEntity, logFileList);
  462. }
  463. /*
  464. 출하 대상 그리드 리스트 조회
  465. */
  466. public GridResponse selectSpplyTargetOdrGridList(String sBrandId, String fromDt, String toDt, String sSpplyId, String sWhsId, String sItemNm, GridRequest gridRequest) throws Exception {
  467. int gridPage = gridRequest.getGridPage();
  468. int gridSize = gridRequest.getGridSize();
  469. fromDt = fromDt == null ? null : fromDt.replace(".", "");
  470. toDt = toDt == null ? null : toDt.replace(".", "");
  471. int gridRecords = shmtOdrMapper.selectSpplyTargetOdrGridCnt(sBrandId, fromDt, toDt, sSpplyId, sWhsId, sItemNm);
  472. int gridTotal = fnCalculateGridTotal(gridSize, gridRecords);
  473. List<PchOdrBaseInfoEntity> entities = shmtOdrMapper.selectSpplyTargetOdrGridList(sBrandId, fromDt, toDt, sSpplyId, sWhsId, sItemNm, gridRequest);
  474. List<Object> gridRows = entities.stream()
  475. .map(m -> SpplyTargerOdrSearchListResponse.builder()
  476. .viewCd("R")
  477. .brandId(m.getBrandId() == null ? "" : m.getBrandId())
  478. .brandNm(m.getBrandNm() == null ? "" : m.getBrandNm())
  479. .pchPodrUnqNo(m.getPchPodrUnqNo() == null ? "" : m.getPchPodrUnqNo())
  480. .pchPodrDtlNo(m.getPchOdrDtlInfo() == null ? "" : m.getPchOdrDtlInfo().getPchPodrDtlNo() == null ? "" : m.getPchOdrDtlInfo().getPchPodrDtlNo())
  481. .itemId(m.getPchOdrDtlInfo() == null ? "" : m.getPchOdrDtlInfo().getItemId() == null ? "" : m.getPchOdrDtlInfo().getItemId())
  482. .itemNm(m.getPchOdrDtlInfo() == null ? "" : m.getPchOdrDtlInfo().getItemNm() == null ? "" : m.getPchOdrDtlInfo().getItemNm())
  483. .whsId(m.getWhsId() == null ? "" : m.getWhsId())
  484. .whsNm(m.getWhsNm() == null ? "" : m.getWhsNm() + " - " + m.getLocationNm())
  485. .location(m.getLocation() == null ? "" : m.getLocation())
  486. .unitAmt(m.getPchOdrDtlInfo() == null ? 0 : m.getPchOdrDtlInfo().getUnitAmt() == null ? 0 : m.getPchOdrDtlInfo().getUnitAmt())
  487. .podrQty(m.getPchOdrDtlInfo() == null ? 0 : m.getPchOdrDtlInfo().getPodrQty() == null ? 0 : m.getPchOdrDtlInfo().getPodrQty())
  488. .podrAmt(m.getPchOdrDtlInfo() == null ? 0 : m.getPchOdrDtlInfo().getPodrAmt() == null ? 0 : m.getPchOdrDtlInfo().getPodrAmt())
  489. .dlvReqDt(m.getDlvReqDt() == null ? "" : m.getDlvReqDt())
  490. .build())
  491. .collect(Collectors.toList());
  492. return GridResponse.toDTO(gridPage, gridTotal, gridRecords, gridRows);
  493. }
  494. /* 공급사 납품서 생성 최기 정보 */
  495. public SpplyInvInitResponse selectSpplyShmtOdrInfo(String brandId, String spplyId, String pchPodrUnqNo) throws Exception {
  496. PchOdrBaseInfoEntity entity = shmtOdrMapper.selectSpplyShmtOdrInfo(brandId, spplyId, pchPodrUnqNo);
  497. List<PchOdrDtlPtclEntity> dtlEntity = shmtOdrMapper.selectSpplyShmtOdrList(pchPodrUnqNo);
  498. return SpplyInvInitResponse.toDTO(entity, dtlEntity);
  499. }
  500. /* 공급사 납품서 생성 저장 */
  501. @Transactional
  502. public void saveSpplyInv(String userId, SaveSpplyDlvRequest saveSpplyDlvRequest) throws Exception {
  503. try {
  504. List<PchOdrDtlPtclEntity> gridInsertData = saveSpplyDlvRequest.toCodeEntities(saveSpplyDlvRequest.getGridInsertData());
  505. List<PchOdrBaseInfoEntity> jobList = shmtOdrMapper.selectShmtJobDataList(saveSpplyDlvRequest.getBrandId(), gridInsertData);
  506. int shmtTotalAmt = 0;
  507. String expryDate = "";
  508. int shmtQty = 0;
  509. String dlvSttmtUnqNo = "";
  510. DeliInfoMgntEntity deliBaseEntity = new DeliInfoMgntEntity();
  511. List<DeliDtlMgntEntity> deliDtlList = new ArrayList<DeliDtlMgntEntity>();
  512. for (int i = 0; i < jobList.size(); i++) {
  513. PchOdrBaseInfoEntity entity = jobList.get(i);
  514. for (int j = 0; j < gridInsertData.size(); j++) {
  515. PchOdrDtlPtclEntity reqEntity = gridInsertData.get(j);
  516. if (entity.getPchPodrUnqNo().equals(reqEntity.getPchPodrUnqNo()) && entity.getPchOdrDtlInfo().getPchPodrDtlNo().equals(reqEntity.getPchPodrDtlNo())) {
  517. if (reqEntity.getShmtQty() > entity.getPchOdrDtlInfo().getPodrQty()) {
  518. // 발주수량보다 출고수량이 많을수 없습니다.
  519. throw new GlobalException(SystemMessageCode.ERR_POSHNONQTY);
  520. }
  521. if ("Y".equals(entity.getPchOdrDtlInfo().getExpryYn())) {
  522. if (reqEntity.getExpryDate() == null || "".equals(reqEntity.getExpryDate())) {
  523. // 유통기한을 입력해주세요!
  524. throw new GlobalException(SystemMessageCode.ERR_NONEXPRY);
  525. }
  526. }
  527. expryDate = reqEntity.getExpryDate().replaceAll("\\.", "");
  528. shmtQty = reqEntity.getShmtQty();
  529. break;
  530. }
  531. }
  532. shmtTotalAmt = shmtTotalAmt + (entity.getPchOdrDtlInfo().getUnitAmt() * shmtQty);
  533. if (i == 0 ) {
  534. dlvSttmtUnqNo = fnGetDealNo(15, ""); // 납품서번호
  535. deliBaseEntity.setDlvSttmtUnqNo(dlvSttmtUnqNo);
  536. deliBaseEntity.setDlvSttmtUnqNo(dlvSttmtUnqNo);
  537. deliBaseEntity.setSpplyId(entity.getSpplyId());
  538. deliBaseEntity.setSpplyNm(entity.getSpplyNm());
  539. deliBaseEntity.setStoreId(entity.getStoreId());
  540. //deliBaseEntity.setDlvAmt(shmtTotalAmt);
  541. deliBaseEntity.setDlvMgrNm(saveSpplyDlvRequest.getDlvMgrNm());
  542. deliBaseEntity.setDlvMgrTelNo(saveSpplyDlvRequest.getDlvMgrTelNo().replaceAll("-", ""));
  543. deliBaseEntity.setDlvMgrEmal(null);
  544. deliBaseEntity.setDlvMgrMblNo(null);
  545. deliBaseEntity.setVndrTelNo(entity.getDeliTelNo().replaceAll("-", ""));
  546. deliBaseEntity.setDlvStCd("DLV0");
  547. deliBaseEntity.setPodrRegDt(entity.getPodrDt());
  548. deliBaseEntity.setDlvReqDt(entity.getDlvReqDt().replaceAll("\\.", ""));
  549. deliBaseEntity.setDlvSchDt(saveSpplyDlvRequest.getDlvSchDt().replaceAll("\\.", ""));
  550. deliBaseEntity.setDlvCmpltDt(null);
  551. deliBaseEntity.setWhsId(entity.getWhsId());
  552. deliBaseEntity.setLocation(entity.getLocation());
  553. if ("".equals(entity.getStoreId()) || entity.getStoreId() == null) {
  554. deliBaseEntity.setWhsDvsn("W01");
  555. } else {
  556. deliBaseEntity.setWhsDvsn("W02");
  557. }
  558. deliBaseEntity.setBrandId(saveSpplyDlvRequest.getBrandId());
  559. }
  560. int dtlNo = (i+1) * 10;
  561. DeliDtlMgntEntity inaddDeliDtlEntity = new DeliDtlMgntEntity();
  562. inaddDeliDtlEntity.setDlvSttmtUnqNo(dlvSttmtUnqNo);
  563. inaddDeliDtlEntity.setDlvSttmtDtlNo(Integer.toString(dtlNo));
  564. inaddDeliDtlEntity.setPchPodrUnqNo(entity.getPchPodrUnqNo());
  565. inaddDeliDtlEntity.setPchPodrDtlNo(entity.getPchOdrDtlInfo().getPchPodrDtlNo());
  566. inaddDeliDtlEntity.setPchReqUnqNo(entity.getPchOdrDtlInfo().getPchReqUnqNo());
  567. inaddDeliDtlEntity.setPchReqDtlNo(entity.getPchOdrDtlInfo().getPchReqDtlNo());
  568. inaddDeliDtlEntity.setItemId(entity.getPchOdrDtlInfo().getItemId());
  569. inaddDeliDtlEntity.setItemNm(entity.getPchOdrDtlInfo().getItemNm());
  570. inaddDeliDtlEntity.setUnit(entity.getPchOdrDtlInfo().getUnit());
  571. inaddDeliDtlEntity.setUnitAmt(entity.getPchOdrDtlInfo().getUnitAmt());
  572. inaddDeliDtlEntity.setPodrQty(entity.getPchOdrDtlInfo().getPodrQty());
  573. inaddDeliDtlEntity.setDlvQty(shmtQty);
  574. inaddDeliDtlEntity.setPodrAmt(entity.getPchOdrDtlInfo().getPodrAmt());
  575. inaddDeliDtlEntity.setDlvAmt(shmtQty * entity.getPchOdrDtlInfo().getUnitAmt());
  576. inaddDeliDtlEntity.setExpryDate(expryDate);
  577. deliDtlList.add(inaddDeliDtlEntity);
  578. }
  579. deliBaseEntity.setDlvAmt(shmtTotalAmt);
  580. shmtOdrMapper.insertDeliInfoMngt(userId, deliBaseEntity);
  581. shmtOdrMapper.insertDeliDtlPtcl(userId, deliDtlList);
  582. for (int poi = 0; poi < gridInsertData.size(); poi++) {
  583. gridInsertData.get(poi).setPodrDtlStCd("POD3");
  584. }
  585. pchOrdMapper.updateChangeStPodrDtl(userId, gridInsertData);
  586. // 발주 헤더 상태 처리 updateChgMultiPodrStCd
  587. String pchPodrUnqNo = "";
  588. for (int k = 0; k < gridInsertData.size(); k++) {
  589. if (!pchPodrUnqNo.equals(gridInsertData.get(k).getPchPodrUnqNo())) {
  590. pchPodrUnqNo = gridInsertData.get(k).getPchPodrUnqNo();
  591. String pchOdrStCd = pchOrdService.selectOdrDtlStatusList(pchPodrUnqNo);
  592. pchOrdMapper.updateChgPodrStCd(userId, pchOdrStCd, pchPodrUnqNo);
  593. }
  594. }
  595. } catch (GlobalException e) {
  596. //e.getStackTrace();
  597. e.printStackTrace();
  598. throw new GlobalException(e.getSystemMessageCode());
  599. } catch (Exception e) {
  600. e.printStackTrace();
  601. throw new RuntimeException();
  602. }
  603. }
  604. /*
  605. 납품서 현황 그리드 리스트 조회
  606. */
  607. public GridResponse selectDeliGridList(String sBrandId, String dtGubun, String fromDt, String toDt, String sDlvStCd, String sSpplyId, String sWhsId, String sItemNm, GridRequest gridRequest) throws Exception {
  608. int gridPage = gridRequest.getGridPage();
  609. int gridSize = gridRequest.getGridSize();
  610. fromDt = fromDt == null ? null : fromDt.replace(".", "");
  611. toDt = toDt == null ? null : toDt.replace(".", "");
  612. int gridRecords = shmtOdrMapper.selectDeliGridCnt(sBrandId, dtGubun, fromDt, toDt, sDlvStCd, sSpplyId, sWhsId, sItemNm);
  613. int gridTotal = fnCalculateGridTotal(gridSize, gridRecords);
  614. List<DeliInfoMgntEntity> entities = shmtOdrMapper.selectDeliGridList(sBrandId, dtGubun, fromDt, toDt, sDlvStCd, sSpplyId, sWhsId, sItemNm, gridRequest);
  615. List<Object> gridRows = entities.stream()
  616. .map(m -> DeliDtlSearchListResponse.builder()
  617. .viewCd("R")
  618. .brandId(m.getBrandId() == null ? "" : m.getBrandId())
  619. .brandNm(m.getBrandNm() == null ? "" : m.getBrandNm())
  620. .dlvSttmtUnqNo(m.getDlvSttmtUnqNo() == null ? "" : m.getDlvSttmtUnqNo())
  621. .spplyId(m.getSpplyId() == null ? "" : m.getSpplyId())
  622. .spplyNm(m.getSpplyNm() == null ? "" : m.getSpplyNm())
  623. .dlvStCd(m.getDlvStCd() == null ? "" : m.getDlvStCd())
  624. .dlvStNm(m.getDlvStNm() == null ? "" : m.getDlvStNm())
  625. .whsId(m.getWhsId() == null ? "" :m.getWhsId())
  626. .location(m.getLocation() == null ? "" : m.getLocation())
  627. .whsNm(m.getWhsNm() == null ? "" : m.getWhsNm() + " - " + m.getLocationNm())
  628. .podrRegDt(m.getPodrRegDt() == null ? "" : m.getPodrRegDt())
  629. .dlvRegDt(m.getDlvRegDt() == null ? "" : m.getDlvRegDt())
  630. .dlvReqDt(m.getDlvReqDt() == null ? "" : m.getDlvReqDt())
  631. .dlvSchDt(m.getDlvSchDt() == null ? "" : m.getDlvSchDt())
  632. .itemId(m.getDeliDtlMgntInfo() == null ? "" : m.getDeliDtlMgntInfo().getItemId() == null ? "" : m.getDeliDtlMgntInfo().getItemId())
  633. .itemNm(m.getDeliDtlMgntInfo() == null ? "" : m.getDeliDtlMgntInfo().getItemNm() == null ? "" : m.getDeliDtlMgntInfo().getItemNm())
  634. .podrQty(m.getDeliDtlMgntInfo() == null ? 0 : m.getDeliDtlMgntInfo().getPodrQty() == null ? 0 : m.getDeliDtlMgntInfo().getPodrQty())
  635. .dlvQty(m.getDeliDtlMgntInfo() == null ? 0 : m.getDeliDtlMgntInfo().getDlvQty() == null ? 0 : m.getDeliDtlMgntInfo().getDlvQty())
  636. .unit(m.getDeliDtlMgntInfo() == null ? "" : m.getDeliDtlMgntInfo().getUnit() == null ? "" : m.getDeliDtlMgntInfo().getUnit())
  637. .unitAmt(m.getDeliDtlMgntInfo() == null ? 0 : m.getDeliDtlMgntInfo().getUnitAmt() == null ? 0 : m.getDeliDtlMgntInfo().getUnitAmt())
  638. .dlvMgrNm(m.getDlvMgrNm() == null ? "" : m.getDlvMgrNm())
  639. .dlvMgrMblNo(m.getDlvMgrMblNo() == null ? "" : m.getDlvMgrMblNo())
  640. .build())
  641. .collect(Collectors.toList());
  642. return GridResponse.toDTO(gridPage, gridTotal, gridRecords, gridRows);
  643. }
  644. }