RtnOdrService.java 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. package com.oqpo.api.service.rtnmng;
  2. import com.oqpo.api.entity.oper.UserMngEntity;
  3. import com.oqpo.api.entity.rtnmng.RtnOdrBaseInfoEntity;
  4. import com.oqpo.api.entity.rtnmng.RtnOdrDtlPtclEntity;
  5. import com.oqpo.api.entity.rtnmng.RtnReqBaseInfoEntity;
  6. import com.oqpo.api.entity.rtnmng.RtnReqDtlPtclEntity;
  7. import com.oqpo.api.enums.SystemMessageCode;
  8. import com.oqpo.api.exception.GlobalException;
  9. import com.oqpo.api.mapper.inoutmng.ColOdrMapper;
  10. import com.oqpo.api.mapper.loanmng.LoanStateMapper;
  11. import com.oqpo.api.mapper.oper.UserMngMapper;
  12. import com.oqpo.api.mapper.rtnmng.RtnOdrMapper;
  13. import com.oqpo.api.mapper.rtnmng.RtnReqMapper;
  14. import com.oqpo.api.mapper.stinfo.StoreBaseInfoMapper;
  15. import com.oqpo.api.mapper.stockmng.StockMngMapper;
  16. import com.oqpo.api.service.CommonService;
  17. import com.oqpo.api.web.dto.request.GridRequest;
  18. import com.oqpo.api.web.dto.request.rtnmng.CancelRtnOrdDtlRequest;
  19. import com.oqpo.api.web.dto.request.rtnmng.RtnReqOrdInitRequest;
  20. import com.oqpo.api.web.dto.request.rtnmng.SaveRtnOdrRequest;
  21. import com.oqpo.api.web.dto.response.GridResponse;
  22. import com.oqpo.api.web.dto.response.rtnmng.rtnOrd.*;
  23. import lombok.extern.slf4j.Slf4j;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.stereotype.Service;
  26. import org.springframework.transaction.annotation.Transactional;
  27. import java.util.ArrayList;
  28. import java.util.List;
  29. import java.util.stream.Collectors;
  30. @Service
  31. @Slf4j
  32. public class RtnOdrService extends CommonService {
  33. @Autowired
  34. private RtnOdrMapper rtnOdrMapper;
  35. @Autowired
  36. private UserMngMapper userMngMapper;
  37. @Autowired
  38. private StockMngMapper stockMngMapper;
  39. @Autowired
  40. private RtnReqMapper rtnReqMapper;
  41. @Autowired
  42. private ColOdrMapper colOdrMapper;
  43. @Autowired
  44. private StoreBaseInfoMapper storeBaseInfoMapper;
  45. @Autowired
  46. private LoanStateMapper loanStateMapper;
  47. @Autowired
  48. private RtnReqService rtnReqService;
  49. /* 반품요청건 발주 가능 여부 체크 */
  50. public String chkRtnReqUseOrd(String userId, RtnReqOrdInitRequest rtnReqOrdInitRequest ) throws Exception {
  51. String usePassPoYn = "Y";
  52. // 초기 발주 head 정보 가져오기
  53. List<RtnOdrBaseInfoEntity> headList = null;
  54. List<RtnOdrDtlPtclEntity> itemList = null;
  55. // 품목 데이타 확인 필요
  56. List<RtnOdrDtlPtclEntity> gridUpdateData = rtnReqOrdInitRequest.toCodeEntities(rtnReqOrdInitRequest.getGridUpdateData());
  57. if (gridUpdateData.size() > 0) {
  58. headList = rtnOdrMapper.selectRecRtnInitInfo(rtnReqOrdInitRequest.getBrandId(),gridUpdateData);
  59. itemList = rtnOdrMapper.selectRecRtnDtlInitInfo(rtnReqOrdInitRequest.getBrandId(),gridUpdateData);
  60. }
  61. if (headList.size() > 1) {
  62. // 서로다른 수거장소로 인한 처리 불가 오류 메세지 출력 본사출력이면 매장수거장소,, 공급사수거면 본사수거장소
  63. usePassPoYn = "N";
  64. throw new GlobalException(SystemMessageCode.ERR_NEQRTNWHSID);
  65. }
  66. RtnOdrBaseInfoEntity headData = headList.get(0);
  67. String colReqDt = ""; // 수거요청일
  68. String spplyId = ""; // 공급업체
  69. //col_dvsn 본사수거 C001 , 공급사 수거 C002
  70. if ("C001".equals(headData.getColDvsn())) {
  71. // 본사수거
  72. if ("".equals(headData.getStoreId())) {
  73. usePassPoYn = "N";
  74. throw new GlobalException(SystemMessageCode.ERR_NONRTNSTORE);
  75. }
  76. } else if ("C002".equals(headData.getColDvsn())) {
  77. // 공급사 수거는 본사 창고입니다.
  78. for (int i = 0; i < itemList.size(); i++) {
  79. RtnOdrDtlPtclEntity itemInfo = itemList.get(i);
  80. if ("".equals(spplyId)) {
  81. spplyId = itemInfo.getSpplyId();
  82. } else {
  83. if (!spplyId.equals(itemInfo.getSpplyId())) {
  84. usePassPoYn = "N";
  85. throw new GlobalException(SystemMessageCode.ERR_NEQRTNSPPLY);
  86. }
  87. }
  88. if ("".equals(spplyId)) {
  89. usePassPoYn = "N";
  90. throw new GlobalException(SystemMessageCode.ERR_NONSPPLY);
  91. }
  92. }
  93. }
  94. return usePassPoYn;
  95. }
  96. /* 반품요청 발주 초기 정보
  97. *
  98. *
  99. * */
  100. public RtnOrdInitInfoResponse selectRecRtnInitInfo(String userId, RtnReqOrdInitRequest rtnReqOrdInitRequest ) throws Exception {
  101. // 로그인 정보 가져오기
  102. UserMngEntity uEntity = userMngMapper.selectGroupUserInfo(userId);
  103. // 초기 발주 head 정보 가져오기
  104. List<RtnOdrBaseInfoEntity> headList = null;
  105. List<RtnOdrDtlPtclEntity> itemList = null;
  106. // 품목 데이타 확인 필요
  107. List<RtnOdrDtlPtclEntity> gridUpdateData = rtnReqOrdInitRequest.toCodeEntities(rtnReqOrdInitRequest.getGridUpdateData());
  108. if (gridUpdateData.size() > 0) {
  109. headList = rtnOdrMapper.selectRecRtnInitInfo(rtnReqOrdInitRequest.getBrandId(),gridUpdateData);
  110. itemList = rtnOdrMapper.selectRecRtnDtlInitInfo(rtnReqOrdInitRequest.getBrandId(),gridUpdateData);
  111. }
  112. if (headList.size() > 1) {
  113. // 서로다른 수거장소로 인한 처리 불가 오류 메세지 출력 본사출력이면 매장수거장소,, 공급사수거면 본사수거장소
  114. throw new GlobalException(SystemMessageCode.ERR_NEQRTNWHSID);
  115. }
  116. RtnOdrBaseInfoEntity headData = headList.get(0);
  117. long rtnTotalAmt = 0 ; // 총 반품금액
  118. String colReqDt = ""; // 수거요청일
  119. String spplyId = ""; // 공급업체
  120. String spplyNm = ""; //공급업체명
  121. //col_dvsn 본사수거 C001 , 공급사 수거 C002
  122. if ("C001".equals(headData.getColDvsn())) {
  123. if ("".equals(headData.getStoreId())) {
  124. throw new GlobalException(SystemMessageCode.ERR_NONRTNSTORE);
  125. }
  126. for (int j = 0 ; j < itemList.size() ; j++) {
  127. RtnOdrDtlPtclEntity itemInfo = itemList.get(j);
  128. rtnTotalAmt = rtnTotalAmt + (itemInfo.getUnitAmt() * itemInfo.getRtnQty());
  129. colReqDt = itemInfo.getColReqDt() ;
  130. }
  131. } else if ("C002".equals(headData.getColDvsn())) {
  132. // 공급사 수거는 본사 창고입니다.
  133. for (int i = 0; i < itemList.size(); i++) {
  134. RtnOdrDtlPtclEntity itemInfo = itemList.get(i);
  135. rtnTotalAmt = rtnTotalAmt + (itemInfo.getUnitAmt() * itemInfo.getRtnQty());
  136. colReqDt = itemInfo.getColReqDt() ;
  137. if ("".equals(spplyId)) {
  138. spplyId = itemInfo.getSpplyId();
  139. spplyNm = itemInfo.getSpplyNm();
  140. } else {
  141. if (!spplyId.equals(itemInfo.getSpplyId())) {
  142. throw new GlobalException(SystemMessageCode.ERR_NEQRTNSPPLY);
  143. }
  144. }
  145. if ("".equals(spplyId)) {
  146. throw new GlobalException(SystemMessageCode.ERR_NONSPPLY);
  147. }
  148. }
  149. }
  150. // System.out.println(" last==dlvReqDt===================>" + dlvReqDt);
  151. headData.setSpplyId(spplyId);
  152. headData.setSpplyNm(spplyNm);
  153. headData.setRtnDodrTotalAmt(rtnTotalAmt);
  154. headData.setRtnDodrItemQty(itemList.size());
  155. headData.setColReqDt(colReqDt);
  156. return RtnOrdInitInfoResponse.toDTO(uEntity, headData, itemList);
  157. }
  158. /*
  159. 반품 발주 신규생성 RtnOrdNInitInfoResponse
  160. */
  161. public RtnOrdNInitInfoResponse selectRtnInitInfo(String userId, String brandId) throws Exception {
  162. // 로그인 정보 가져오기
  163. UserMngEntity uEntity = userMngMapper.selectGroupUserInfo(userId);
  164. // 초기 발주 head 정보 가져오기
  165. RtnOdrBaseInfoEntity headData = rtnOdrMapper.selectRtnInitInfo(brandId);
  166. return RtnOrdNInitInfoResponse.toDTO(uEntity, headData);
  167. }
  168. /*
  169. 발주 정보 저장
  170. */
  171. @Transactional
  172. public void saveRtnOdrInfo(String userId, SaveRtnOdrRequest saveRtnOdrRequest) throws Exception {
  173. try {
  174. // 로그인 정보 가져오기
  175. UserMngEntity uEntity = userMngMapper.selectGroupUserInfo(userId);
  176. uEntity.setTelNo(uEntity.getTelNo().replaceAll("-",""));
  177. // 전달받은 데이타와 전송발 데이타 세팅 후 저장
  178. String rtnPodrUnqNo = fnGetDealNo(19,"");
  179. RtnOdrBaseInfoEntity rtnOrdEntity = new RtnOdrBaseInfoEntity();
  180. rtnOrdEntity.setRtnPodrUnqNo(rtnPodrUnqNo);
  181. rtnOrdEntity.setBrandId(saveRtnOdrRequest.getBrandId());
  182. rtnOrdEntity.setRtnReqDvsn(saveRtnOdrRequest.getRtnReqDvsn());
  183. rtnOrdEntity.setRtnMgrNm(uEntity.getUserNm());
  184. rtnOrdEntity.setRtnMgrId(userId);
  185. rtnOrdEntity.setRtnMgrTelNo(uEntity.getTelNo());
  186. rtnOrdEntity.setSpplyId(saveRtnOdrRequest.getSpplyId());
  187. rtnOrdEntity.setWhsId(saveRtnOdrRequest.getWhsId());
  188. rtnOrdEntity.setLocation(saveRtnOdrRequest.getLocation());
  189. rtnOrdEntity.setColDvsn(saveRtnOdrRequest.getColDvsn());
  190. rtnOrdEntity.setColReqDt(saveRtnOdrRequest.getColReqDt().replaceAll("\\.",""));
  191. rtnOrdEntity.setStoreId(saveRtnOdrRequest.getStoreId());
  192. rtnOrdEntity.setRtnWhsId(saveRtnOdrRequest.getRtnWhsId());
  193. rtnOrdEntity.setRtnLocation(saveRtnOdrRequest.getRtnLocation());
  194. Integer dtlRow = 0 ;
  195. List<RtnOdrDtlPtclEntity> rtnOrdDtlList = new ArrayList<RtnOdrDtlPtclEntity>();
  196. List<RtnOdrDtlPtclEntity> gridUpdateData = saveRtnOdrRequest.toCodeEntities(saveRtnOdrRequest.getGridInsertData());
  197. // 헤더데이타 체크
  198. if (gridUpdateData.size() < 1) {
  199. throw new GlobalException(SystemMessageCode.ERR_NOTITEM);
  200. }
  201. List<RtnOdrBaseInfoEntity> headList = rtnOdrMapper.selectRecRtnInitInfo(saveRtnOdrRequest.getBrandId(),gridUpdateData);
  202. if (headList.size() > 1) {
  203. // 서로다른 수거장소로 인한 처리 불가 오류 메세지 출력 본사출력이면 매장수거장소,, 공급사수거면 본사수거장소
  204. throw new GlobalException(SystemMessageCode.ERR_NEQRTNWHSID);
  205. }
  206. //List<RtnReqBaseInfoEntity> rtnReqList = new ArrayList<RtnReqBaseInfoEntity>();
  207. List<RtnReqDtlPtclEntity> rtnReqDtlList = new ArrayList<RtnReqDtlPtclEntity>();
  208. if (gridUpdateData.size() > 0) {
  209. long rtnTotAmt = 0 ;
  210. int rtnItemCnt = 0 ;
  211. String diffSpplyYn = "N" ;
  212. //String diffStoreYn = "N";
  213. for (int i = 0 ; i < gridUpdateData.size() ;i++ ) {
  214. RtnOdrDtlPtclEntity rtnDtlEntity = gridUpdateData.get(i); // 전달받은값
  215. RtnOdrDtlPtclEntity rtnSaveDtlEntity = new RtnOdrDtlPtclEntity(); // 저장할 메인
  216. //RtnReqBaseInfoEntity rtnReqEntity = new RtnReqBaseInfoEntity(); // 반품요청상태
  217. RtnReqDtlPtclEntity rtnReqDtlEntity = new RtnReqDtlPtclEntity(); // 반품요청상세상태
  218. // 반품요청건에 대한 데이타 가져옴
  219. if ("R".equals(saveRtnOdrRequest.getJobCd())) { // 반품요청건
  220. // 구매요청번호와 항번으로 데이타 가져놈
  221. rtnSaveDtlEntity = rtnOdrMapper.selectPoRtnDtlSaveInfo(rtnDtlEntity.getRtnReqUnqNo(), rtnDtlEntity.getRtnReqDtlNo());
  222. //rtnReqEntity.setRtnReqUnqNo(rtnDtlEntity.getRtnReqUnqNo());
  223. //rtnReqEntity.setRtnReqStCd("RR30");
  224. rtnReqDtlEntity.setRtnReqUnqNo(rtnDtlEntity.getRtnReqUnqNo());
  225. rtnReqDtlEntity.setRtnReqDtlNo(rtnDtlEntity.getRtnReqDtlNo());
  226. rtnReqDtlEntity.setRtnReqDtlStCd("RRD30");
  227. //rtnReqList.add(rtnReqEntity);
  228. rtnReqDtlList.add(rtnReqDtlEntity);
  229. } else if ("P".equals(saveRtnOdrRequest.getJobCd())) { // 신규발주건
  230. // item id 로 데이타 가져옴 == 단가는 브랜드 단가로 처리함
  231. rtnSaveDtlEntity = rtnOdrMapper.selectRtnItemDtlSaveInfo(saveRtnOdrRequest.getBrandId(), rtnDtlEntity.getItemId(), rtnDtlEntity.getBrandUnitUnqNo());
  232. }
  233. if (!rtnOrdEntity.getSpplyId().equals(rtnSaveDtlEntity.getSpplyId())) {
  234. diffSpplyYn = "Y"; // 수거 공급사는 하나여야 합니다.
  235. }
  236. dtlRow = dtlRow + 10;
  237. rtnSaveDtlEntity.setRtnPodrUnqNo(rtnPodrUnqNo);
  238. String dtlNo = Integer.toString(dtlRow);
  239. rtnSaveDtlEntity.setRtnPodrDtlNo(dtlNo);
  240. rtnSaveDtlEntity.setRtnReqUnqNo(rtnDtlEntity.getRtnReqUnqNo());
  241. rtnSaveDtlEntity.setRtnReqDtlNo(rtnDtlEntity.getRtnReqDtlNo());
  242. rtnSaveDtlEntity.setRtnQty(rtnSaveDtlEntity.getRtnReqQty());
  243. //System.out.println("==========================================");
  244. //System.out.println(rtnDtlEntity.getRtnQty() + "===" + rtnSaveDtlEntity.getUnitAmt());
  245. //System.out.println("==========================================");
  246. rtnSaveDtlEntity.setRtnAmt(Long.valueOf(rtnDtlEntity.getRtnQty()) * rtnSaveDtlEntity.getUnitAmt() );
  247. rtnSaveDtlEntity.setBrandUnitUnqNo(rtnDtlEntity.getBrandUnitUnqNo());
  248. rtnSaveDtlEntity.setStoreUnitUnqNo(rtnDtlEntity.getStoreUnitUnqNo());
  249. rtnSaveDtlEntity.setRtnDvsn(rtnDtlEntity.getRtnDvsn());
  250. rtnSaveDtlEntity.setRtnRsn(rtnDtlEntity.getRtnRsn());
  251. rtnSaveDtlEntity.setRtnRsnDvsn(rtnDtlEntity.getRtnRsnDvsn());
  252. rtnSaveDtlEntity.setRtnOdrQty(rtnDtlEntity.getRtnQty());
  253. rtnSaveDtlEntity.setRtnReqQty(rtnDtlEntity.getRtnReqQty());
  254. rtnSaveDtlEntity.setRtnOdrAmt(Long.valueOf(rtnDtlEntity.getRtnQty()) * rtnSaveDtlEntity.getUnitAmt());
  255. rtnSaveDtlEntity.setRodrDtlStCd("ROD0");
  256. rtnTotAmt = rtnTotAmt + rtnSaveDtlEntity.getRtnOdrAmt();
  257. rtnItemCnt = rtnItemCnt + 1;
  258. rtnOrdDtlList.add(rtnSaveDtlEntity);
  259. }
  260. // 체크로직필요
  261. if ("C002".equals(rtnOrdEntity.getColDvsn())) {
  262. // 공급사 수거일경우
  263. // 공급사는 하나여야 함
  264. if("".equals(saveRtnOdrRequest.getSpplyId())) {
  265. throw new GlobalException(SystemMessageCode.ERR_NOTSPPLY);
  266. }
  267. if ("Y".equals(diffSpplyYn)) {
  268. // 공급사는 하나여야 합니다.
  269. throw new GlobalException(SystemMessageCode.ERR_NEQSPPLY);
  270. }
  271. } else {
  272. // 브랜드 수거 - 매장
  273. if ("".equals(rtnOrdEntity.getStoreId())) {
  274. // 매장정보가 없습니다.
  275. throw new GlobalException(SystemMessageCode.ERR_NONSTOREID);
  276. }
  277. //입고창고정보 존재여부 파악
  278. if ("".equals(rtnOrdEntity.getWhsId()) || "".equals(rtnOrdEntity.getLocation())) {
  279. throw new GlobalException(SystemMessageCode.ERR_INWHS);
  280. }
  281. }
  282. rtnOrdEntity.setRtnDodrTotalAmt(rtnTotAmt);
  283. rtnOrdEntity.setRtnDodrItemQty(rtnItemCnt);
  284. rtnOdrMapper.insertRtnOdrBaseInfo(userId, rtnOrdEntity);
  285. rtnOdrMapper.insertRtnOdrDtlPtcl(userId, rtnOrdDtlList);
  286. // 반품요청건에 대한 상태에 대한 처리상태 변경
  287. if ("R".equals(saveRtnOdrRequest.getJobCd())) { // 반품요청건
  288. rtnReqMapper.updateSelRtnReqDtlStCd(userId,rtnReqDtlList);
  289. String rtnReqUnqNo = "";
  290. List<RtnReqBaseInfoEntity> rtnReqList = new ArrayList<RtnReqBaseInfoEntity>();
  291. for (int k = 0; k < rtnReqDtlList.size(); k++) {
  292. if (!rtnReqUnqNo.equals(rtnReqDtlList.get(k).getRtnReqUnqNo())) {
  293. rtnReqUnqNo = rtnReqDtlList.get(k).getRtnReqUnqNo();
  294. String rtnReqStCd = rtnReqService.selectRtnReqDtlStatusList(rtnReqUnqNo);
  295. RtnReqBaseInfoEntity rtnReqEntity = new RtnReqBaseInfoEntity(); // 반품요청상태
  296. rtnReqEntity.setRtnReqUnqNo(rtnReqUnqNo);
  297. rtnReqEntity.setRtnReqStCd(rtnReqStCd);
  298. rtnReqList.add(rtnReqEntity);
  299. }
  300. }
  301. rtnReqMapper.updateRtnReqStCd(userId, rtnReqList);
  302. }
  303. }
  304. } catch (GlobalException e) {
  305. //e.getStackTrace();
  306. e.printStackTrace();
  307. throw new GlobalException(e.getSystemMessageCode());
  308. } catch (Exception e) {
  309. e.printStackTrace();
  310. throw new RuntimeException();
  311. }
  312. }
  313. /*
  314. 반품발주 그리드 리스트 조회
  315. */
  316. public GridResponse selectRtnOdrGridList(String sBrandId, String fromDt, String toDt, String sRtnOdrStCd, String sRtnWhsId, String sColDvsn, String sWhsId, String sSpplyId, String sItemNm, GridRequest gridRequest) throws Exception {
  317. int gridPage = gridRequest.getGridPage();
  318. int gridSize = gridRequest.getGridSize();
  319. //System.out.println(sBrandId + "==" + fromDt + "==" + toDt + "==" + srtnOdrStCd + "==" + sSpplyId + "==" + sWhsId + "==" + sItemNm);
  320. fromDt = fromDt == null ? null : fromDt.replace(".", "");
  321. toDt = toDt == null ? null : toDt.replace(".", "");
  322. int gridRecords = rtnOdrMapper.selectRtnOdrGridCnt(sBrandId, fromDt, toDt, sRtnOdrStCd,sRtnWhsId, sColDvsn, sWhsId, sSpplyId, sItemNm );
  323. int gridTotal = fnCalculateGridTotal(gridSize, gridRecords);
  324. List<RtnOdrBaseInfoEntity> entities = rtnOdrMapper.selectRtnOdrGridList(sBrandId, fromDt, toDt, sRtnOdrStCd,sRtnWhsId, sColDvsn, sWhsId, sSpplyId, sItemNm, gridRequest);
  325. List<Object> gridRows = entities.stream()
  326. .map(m -> RtnOdrSearchListResponse.builder()
  327. .viewCd("R")
  328. .rtnPodrUnqNo(m.getRtnPodrUnqNo() == null ? "" : m.getRtnPodrUnqNo())
  329. .brandId(m.getBrandId() == null ? "" : m.getBrandId())
  330. .brandNm(m.getBrandNm() == null ? "" : m.getBrandNm())
  331. .rtnOdrStCd(m.getRtnOdrStCd() == null ? "" : m.getRtnOdrStCd())
  332. .rtnOdrStNm(m.getRtnOdrStNm() == null ? "" : m.getRtnOdrStNm())
  333. .rtnOdrRegDt(m.getRtnOdrRegDt() == null ? "" : m.getRtnOdrRegDt())
  334. .rtnWhsId(m.getRtnWhsId() == null ? "" : m.getRtnWhsId())
  335. .rtnLocation(m.getRtnLocation() == null ? "" : m.getRtnLocation())
  336. .rtnWhsNm(m.getRtnWhsNm() == null ? "" : m.getRtnWhsNm())
  337. .rtnLocationNm(m.getRtnLocationNm() == null ? "" : m.getRtnLocationNm())
  338. .spplyId(m.getSpplyId() == null ? "" : m.getSpplyId())
  339. .spplyNm(m.getSpplyNm() == null ? "" : m.getSpplyNm())
  340. .whsId(m.getWhsId() == null ? "" : m.getWhsId())
  341. .location(m.getLocation() == null ? "" : m.getLocation())
  342. .whsNm(m.getWhsNm() == null ? "" : m.getWhsNm())
  343. .locationNm(m.getLocationNm() == null ? "" : m.getLocationNm())
  344. .rtnDodrTotalAmt(m.getRtnDodrTotalAmt() == null ? 0 : m.getRtnDodrTotalAmt())
  345. .rtnDodrItemQty(m.getRtnDodrItemQty() == null ? 0 : m.getRtnDodrItemQty())
  346. .colReqDt(m.getColReqDt() == null ? "" : m.getColReqDt())
  347. .colDvsn(m.getColDvsn() == null ? "" : m.getColDvsn())
  348. .colDvsnNm(m.getColDvsnNm() == null ? "" : m.getColDvsnNm())
  349. .build())
  350. .collect(Collectors.toList());
  351. return GridResponse.toDTO(gridPage, gridTotal, gridRecords, gridRows);
  352. }
  353. /* 반품발주 정보 */
  354. public RtnOdrInfoResponse selectrtnOdrInfo(String rtnPodrUnqNo) throws Exception {
  355. RtnOdrBaseInfoEntity entity = rtnOdrMapper.selectRtnOdrInfo(rtnPodrUnqNo);
  356. List<RtnOdrDtlPtclEntity> dtlEntity = rtnOdrMapper.selectROdrDtlList( rtnPodrUnqNo);
  357. return RtnOdrInfoResponse.toDTO(entity,dtlEntity);
  358. }
  359. /*
  360. 반품 발주 취소처리
  361. */
  362. @Transactional
  363. public void cancelRtnOrdDtl(String userId, CancelRtnOrdDtlRequest cancelRtnOrdDtlRequest) throws Exception {
  364. try {
  365. // 수거서 생성 여부 파악 (이미생성시 반품 취소 불가)
  366. int ingCnt = colOdrMapper.selectColRtnIngCnt(cancelRtnOrdDtlRequest.getBrandId(), cancelRtnOrdDtlRequest.getRtnPodrUnqNo());
  367. if (ingCnt > 0) {
  368. throw new GlobalException(SystemMessageCode.ERR_INGCOLCNT);
  369. }
  370. //반품요청 취소처리
  371. rtnOdrMapper.updateChgRodrStCd(userId, cancelRtnOrdDtlRequest.getRtnPodrUnqNo(),"RO99");
  372. rtnOdrMapper.updateChangeRodrDtlStCd(userId, cancelRtnOrdDtlRequest.getRtnPodrUnqNo(),"ROD4");
  373. RtnOdrBaseInfoEntity rtnOdrInfo = rtnOdrMapper.selectRtnOdrInfo(cancelRtnOrdDtlRequest.getRtnPodrUnqNo());
  374. // 반품요청건에 대한 상태에 대한 처리상태 변경 RR01
  375. if ("RR01".equals(rtnOdrInfo.getRtnReqDvsn())) { // 요청반품건은 반품요청건 상태 변경처리함
  376. List<RtnOdrDtlPtclEntity> rtnOrdList = rtnOdrMapper.selectROdrDtlList(cancelRtnOrdDtlRequest.getRtnPodrUnqNo());
  377. List<RtnReqDtlPtclEntity> rtnReqDtlList = new ArrayList<RtnReqDtlPtclEntity>();
  378. List<RtnReqBaseInfoEntity> rtnReqBaseList = new ArrayList<RtnReqBaseInfoEntity>();
  379. String rtnReqUnqNo = "";
  380. for (int i = 0 ; i < rtnOrdList.size() ;i++) {
  381. RtnOdrDtlPtclEntity rtnOdrEntity = rtnOrdList.get(i);
  382. RtnReqDtlPtclEntity rtnReqDtlEntity = new RtnReqDtlPtclEntity();
  383. RtnReqBaseInfoEntity rtnReqBaseEntity = new RtnReqBaseInfoEntity();
  384. rtnReqDtlEntity.setRtnReqUnqNo(rtnOdrEntity.getRtnReqUnqNo());
  385. rtnReqDtlEntity.setRtnReqDtlNo(rtnOdrEntity.getRtnReqDtlNo());
  386. rtnReqDtlEntity.setRtnReqDtlStCd("RRD99");
  387. rtnReqDtlList.add(rtnReqDtlEntity);
  388. if (!rtnReqUnqNo.equals(rtnOdrEntity.getRtnReqUnqNo())) {
  389. rtnReqUnqNo = rtnOdrEntity.getRtnReqUnqNo();
  390. rtnReqBaseEntity.setRtnReqUnqNo(rtnReqUnqNo);
  391. String rtnReqStcd = rtnReqService.selectRtnReqDtlStatusList(rtnReqUnqNo);
  392. rtnReqBaseEntity.setRtnReqStCd(rtnReqStcd);
  393. rtnReqBaseList.add(rtnReqBaseEntity);
  394. }
  395. }
  396. rtnReqMapper.updateRtnReqStCd(userId,rtnReqBaseList);
  397. }
  398. } catch (GlobalException e) {
  399. //e.getStackTrace();
  400. e.printStackTrace();
  401. throw new GlobalException(e.getSystemMessageCode());
  402. } catch (Exception e) {
  403. e.printStackTrace();
  404. throw new RuntimeException();
  405. }
  406. }
  407. public String selectRtnOdrDtlStatusList(String rtnPodrUnqNo) throws Exception {
  408. //PCH_ODR_ST_CD
  409. String rtnOdrStCd = "";
  410. List<RtnOdrDtlPtclEntity> dtlEntity = rtnOdrMapper.selectRtnOdrDtlStatusList( rtnPodrUnqNo);
  411. int rod0 = 0 ;
  412. int rod1 = 0 ;
  413. int rod2 = 0 ;
  414. int rod3 = 0 ;
  415. int rod4 = 0 ;
  416. for (int i = 0 ; i < dtlEntity.size() ; i++ ) {
  417. RtnOdrDtlPtclEntity entity = dtlEntity.get(i);
  418. if ( "ROD0".equals(entity.getRodrDtlStCd())) { // 임시저장
  419. rod0 = rod0 + entity.getRtnStatusCnt() ;
  420. } else if ( "ROD1".equals(entity.getRodrDtlStCd())) { // 요청
  421. rod1 = rod1 + entity.getRtnStatusCnt() ;
  422. } else if ( "ROD3".equals(entity.getRodrDtlStCd())) { //접수
  423. rod3 = rod3 + entity.getRtnStatusCnt() ;
  424. } else if ( "ROD4".equals(entity.getRodrDtlStCd())) { //취소
  425. rod4 = rod4 + entity.getRtnStatusCnt() ;
  426. }
  427. }
  428. if (rod0 > 0 ) {
  429. rtnOdrStCd = "RO00"; //임시저장
  430. } else if ( rod0 == 0 && rod1 > 0 ) {
  431. rtnOdrStCd = "RO20"; // 접수
  432. } else if ( rod0 == 0 && rod1 == 0 && rod3 > 0 ) {
  433. rtnOdrStCd = "RO30"; // 취소
  434. } else {
  435. rtnOdrStCd = "RO99"; // 취소
  436. }
  437. return rtnOdrStCd;
  438. }
  439. /*
  440. 공급사 수주현황 리스트
  441. */
  442. public GridResponse selectSpplyRtnGridList(String sBrandId, String fromDt, String toDt, String sSpplyId, String sRtnWhsId, String sRtnOdrStCd, String sItemNm, GridRequest gridRequest) throws Exception {
  443. int gridPage = gridRequest.getGridPage();
  444. int gridSize = gridRequest.getGridSize();
  445. fromDt = fromDt == null ? null : fromDt.replace(".", "");
  446. toDt = toDt == null ? null : toDt.replace(".", "");
  447. int gridRecords = rtnOdrMapper.selectSpplyRtnOdrGridCnt(sBrandId,sSpplyId, fromDt, toDt, sRtnOdrStCd, sRtnWhsId, sItemNm);
  448. int gridTotal = fnCalculateGridTotal(gridSize, gridRecords);
  449. List<RtnOdrBaseInfoEntity> entities = rtnOdrMapper.selectSpplyRtnOdrGridList(sBrandId,sSpplyId, fromDt, toDt, sRtnOdrStCd, sRtnWhsId, sItemNm, gridRequest);
  450. List<Object> gridRows = entities.stream()
  451. .map(m -> SpplyRtnOdrSearchListResponse.builder()
  452. .viewCd("R")
  453. .brandId(m.getBrandId() == null ? "" : m.getBrandId())
  454. .brandNm(m.getBrandNm() == null ? "" : m.getBrandNm())
  455. .rtnPodrUnqNo(m.getRtnPodrUnqNo() == null ? "" : m.getRtnPodrUnqNo())
  456. .rtnOdrStCd(m.getRtnOdrStCd() == null ? "" : m.getRtnOdrStCd())
  457. .rtnOdrStNm(m.getRtnOdrStNm() == null ? "" : m.getRtnOdrStNm())
  458. .rtnOdrRegDt(m.getRtnOdrRegDt() == null ? "" : m.getRtnOdrRegDt())
  459. .colReqDt(m.getColReqDt() == null ? "" : m.getColReqDt())
  460. .rtnWhsNm(m.getRtnWhsNm() == null ? "" : m.getRtnWhsNm() + "-" + m.getRtnLocationNm())
  461. .rtnDodrTotalAmt(m.getRtnDodrTotalAmt() == null ? 0 : m.getRtnDodrTotalAmt())
  462. .rtnDodrItemQty(m.getRtnDodrItemQty() == null ? 0 : m.getRtnDodrItemQty())
  463. .rtnMgrNm(m.getRtnMgrNm() == null ? "" : m.getRtnMgrNm())
  464. .build())
  465. .collect(Collectors.toList());
  466. return GridResponse.toDTO(gridPage, gridTotal, gridRecords, gridRows);
  467. }
  468. /* 구매발주 정보
  469. public SpplyrtnOdrInfoResponse selectSpplyrtnOdrInfo(String brandId, String pchReqUnqNo, String spplyId) throws Exception {
  470. rtnOdrBaseInfoEntity entity = pchOrdMapper.selectSpplyrtnOdrInfo(brandId, pchReqUnqNo, spplyId);
  471. List<rtnOdrDtlPtclEntity> dtlEntity = pchOrdMapper.selectSpplyOdrDtlList(brandId, pchReqUnqNo, spplyId);
  472. return SpplyrtnOdrInfoResponse.toDTO(entity,dtlEntity);
  473. }
  474. */
  475. /* 구매발주에 대한 출고가능수량 정보
  476. public PchOrdWhsQtyResponse selectWhsPassQty(PchReqOrdPassQtyRequest pchReqOrdPassQtyRequest ) throws Exception {
  477. List<StckMgntBaseInfoEntity> gridItemData = pchReqOrdPassQtyRequest.toCodeEntities(pchReqOrdPassQtyRequest.getGridUpdateData());
  478. List<StckMgntBaseInfoEntity> stokList = stockMngMapper.selectWhsLocOutPassQty(pchReqOrdPassQtyRequest.getBrandId(), pchReqOrdPassQtyRequest.getWhsId(), pchReqOrdPassQtyRequest.getLocation(), gridItemData);
  479. return PchOrdWhsQtyResponse.toDTO(stokList);
  480. }
  481. */
  482. }