MainChartService.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. package com.oqpo.api.service.oper;
  2. import com.oqpo.api.entity.oper.MainChartEntity;
  3. import com.oqpo.api.mapper.oper.MainChartMapper;
  4. import com.oqpo.api.service.CommonService;
  5. import com.oqpo.api.util.StringUtil;
  6. import com.oqpo.api.web.dto.response.oper.mainchart.ChartResponse;
  7. import lombok.extern.slf4j.Slf4j;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Service;
  10. import java.util.List;
  11. @Service
  12. @Slf4j
  13. public class MainChartService extends CommonService {
  14. @Autowired
  15. private MainChartMapper mainChartMapper;
  16. public ChartResponse selectMainCount(String brandId, String storeId, String spplyId) throws Exception {
  17. MainChartEntity entity = null;
  18. if (!StringUtil.isEmpty(spplyId)) {
  19. entity = mainChartMapper.selectSpplyMainCount(spplyId);
  20. } else if (!StringUtil.isEmpty(storeId)) {
  21. entity = mainChartMapper.selectStoreMainCount(storeId);
  22. } else if (!StringUtil.isEmpty(brandId)) {
  23. entity = mainChartMapper.selectBrandMainCount(brandId);
  24. }
  25. ChartResponse result = new ChartResponse();
  26. result.setPr20Count( entity == null ? 0 : entity.getPr20Val() == null ? 0 : entity.getPr20Val() ); // 구매요청 건수 : 당일 구매요청 대기 건수
  27. result.setDp02Amt(entity == null ? 0 : entity.getDp02Val() == null ? 0 : entity.getDp02Val()); // 입금승인금액
  28. result.setUnpaidAmt(entity == null ? 0 : entity.getUnpaidAmt() == null ? 0 : entity.getUnpaidAmt()); // 미납금액
  29. result.setPo30Count(entity == null ? 0 : entity.getPo30Val() == null ? 0 : entity.getPo30Val()); // 발주진행
  30. result.setPoEndCount(entity == null ? 0 : entity.getDlvVal() == null ? 0 : entity.getDlvVal()); // 발주완료
  31. result.setPoPsblAmt(entity == null ? 0 : entity.getPoPsblAmt() == null ? 0 : entity.getPoPsblAmt()); // 구매가능금액
  32. result.setOrdersCount(entity == null ? 0 : entity.getOrdersCount() == null ? 0 : entity.getOrdersCount()); // 수주건수
  33. result.setOrdersAmt(entity == null ? 0 : entity.getOrdersAmt() == null ? 0 : entity.getOrdersAmt()); // 수주금액
  34. result.setSttlReqAmt(entity == null ? 0 : entity.getSttlReqAmt() == null ? 0 : entity.getSttlReqAmt()); // 정산요청금액
  35. return result;
  36. }
  37. public ChartResponse selectPchReqChart(String brandId, String storeId, String prType) throws Exception {
  38. MainChartEntity entity = mainChartMapper.selectPchReqChart(brandId, storeId, prType);
  39. String chartData = "[ [' ', '요청', '접수', '반려'], [' ', " + entity.getPr20Val() + " , " + entity.getPr30Val() + " , " + entity.getPr40Val() + "] ]";
  40. ChartResponse result = new ChartResponse();
  41. result.setChartData(chartData);
  42. return result;
  43. }
  44. public ChartResponse selectPchOdrChart(String brandId, String storeId, String spplyId, String poType) throws Exception {
  45. String chartData = null;
  46. if (StringUtil.isEmpty(spplyId)) {
  47. // 브랜드/매장
  48. MainChartEntity entity = mainChartMapper.selectPchOdrChart(brandId, storeId, spplyId, poType);
  49. chartData = "[ [' ', '요청', '접수', '취소'], [' ', " + entity.getPo20Val() + " , " + entity.getPo30Val() + " , " + entity.getPo99Val() + "] ]";
  50. } else {
  51. // 공급사
  52. MainChartEntity entity = mainChartMapper.selectPchOdrChart(brandId, storeId, spplyId, poType); // 수주대상
  53. chartData = "[ [' ', '요청', '접수', '취소'], [' ', " + entity.getPo20Val() + " , " + entity.getPo30Val() + " , " + entity.getPo99Val() + "] ]";
  54. // MainChartEntity deliEntity = mainChartMapper.selectDeliChart(brandId, storeId, spplyId, poType, "DLV0", "dlv_reg_dt"); // 납품서생성 (납품서생성/납품생성일자 비교)
  55. // chartData = "[ [' ', '수주대상', '납품서생성'], [' ', " + entity.getPo20Val() + " , " + deliEntity.getDlvVal() + "] ]";
  56. }
  57. ChartResponse result = new ChartResponse();
  58. result.setChartData(chartData);
  59. return result;
  60. }
  61. public ChartResponse selectPrRankChart(String brandId, String storeId, String spplyId, String prType) throws Exception {
  62. List<MainChartEntity> entityList = null;
  63. if (!StringUtil.isEmpty(spplyId)) {
  64. entityList = mainChartMapper.selectPoRankChart4Spply(spplyId, prType);
  65. } else {
  66. entityList = mainChartMapper.selectPrRankChart(brandId, storeId, prType);
  67. }
  68. StringBuffer retVal = new StringBuffer();
  69. if (entityList == null || entityList.size() < 1) {
  70. retVal.append("[ [' ', '품목없음'], [' ', 0] ]");
  71. } else {
  72. retVal.append("[ [' '");
  73. for (MainChartEntity entity : entityList) {
  74. retVal.append(", '" + entity.getItemNm() + "'");
  75. }
  76. retVal.append("], [' '");
  77. for (MainChartEntity entity : entityList) {
  78. retVal.append(", " + entity.getItemCnt());
  79. }
  80. retVal.append("] ]");
  81. }
  82. ChartResponse result = new ChartResponse();
  83. result.setChartData(retVal.toString());
  84. return result;
  85. }
  86. public ChartResponse selectStlChart(String brandId, String storeId, String spplyId) throws Exception {
  87. MainChartEntity entity = null;
  88. if (!StringUtil.isEmpty(spplyId)) {
  89. entity = mainChartMapper.selectStlChart(null, null, spplyId);
  90. } else if (!StringUtil.isEmpty(storeId)) {
  91. entity = mainChartMapper.selectStlChart(null, storeId, null);
  92. } else if (!StringUtil.isEmpty(brandId)) {
  93. entity = mainChartMapper.selectStlChart(brandId, null, null);
  94. }
  95. // String chartData = "[ [' ', '요청', '확인', '반려'], [' ', " + entity.getSt10Val() + " , " + entity.getSt20Val() + " , " + entity.getSt30Val() + "] ]";
  96. String chartData = "[ [' ', ' '], ['요청', " + entity.getSt10Val() + "], ['확정', " + entity.getSt20Val() + "], ['반려', " + entity.getSt30Val() + "] ]";
  97. ChartResponse result = new ChartResponse();
  98. result.setChartData(chartData);
  99. return result;
  100. }
  101. public ChartResponse selectSftStckChart(String brandId, String storeId) throws Exception {
  102. List<MainChartEntity> entityList = mainChartMapper.selectSftStckChart(brandId, storeId);
  103. StringBuffer charVal = new StringBuffer();
  104. // String chartData = "[ [' ', '안전재고수량', '현재재고수량'], ['품목1', 1000, 400], ['품목2', 1170, 460], ]";
  105. if (entityList == null || entityList.size() < 1) {
  106. charVal.append("['품목없음', 0, 0], ");
  107. } else {
  108. for (MainChartEntity entity : entityList) {
  109. charVal.append("['" + entity.getItemNm() + "', " + entity.getSftStckQty() + ", " + entity.getStckQty() + "], ");
  110. }
  111. }
  112. ChartResponse result = new ChartResponse();
  113. result.setChartData("[ [' ', '안전재고수량', '현재재고수량'], " + charVal.toString() + " ]");
  114. return result;
  115. }
  116. public ChartResponse selectDeliChart(String brandId, String storeId, String spplyId, String deliType) throws Exception {
  117. String chartData = null;
  118. if (!StringUtil.isEmpty(storeId)) {
  119. // 매장 입고
  120. MainChartEntity entity1 = mainChartMapper.selectDeliChart(brandId, storeId, spplyId, deliType, "DLV0", "dlv_reg_dt"); // 대기 (납품서생성/납품등록일자 비교)
  121. MainChartEntity entity2 = mainChartMapper.selectDeliChart(brandId, storeId, spplyId, deliType, "DLV1", "dlv_cmplt_dt"); // 확인 (납품서완료/납품완료일자 비교)
  122. chartData = "[ [' ', '대기', '확인'], [' ', " + entity1.getDlvVal() + " , " + entity2.getDlvVal() + "] ]";
  123. } else if (!StringUtil.isEmpty(spplyId)) {
  124. // 공급사 출고
  125. // 출고 대상 : 납품서생성, 납품예정일자 비교
  126. // 출고 확인 : 납품서완료, 납품완료일자 비교
  127. MainChartEntity entity1 = mainChartMapper.selectDeliChart(brandId, storeId, spplyId, deliType, "DLV0", "dlv_reg_dt"); // 대기 (납품서생성/납품등록일자 비교)
  128. MainChartEntity entity2 = mainChartMapper.selectDeliChart(brandId, storeId, spplyId, deliType, "DLV1", "dlv_cmplt_dt"); // 확인 (납품서완료/납품완료일자 비교)
  129. chartData = "[ [' ', '대기', '완료'], [' ', " + entity1.getDlvVal() + " , " + entity2.getDlvVal() + "] ]";
  130. }
  131. ChartResponse result = new ChartResponse();
  132. result.setChartData(chartData);
  133. return result;
  134. }
  135. }