SupplierService.java 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. package com.dk.mdm.service.mst;
  2. import com.dk.common.infrastructure.annotaiton.Pagination;
  3. import com.dk.common.infrastructure.constant.Constant;
  4. import com.dk.common.model.pojo.PageList;
  5. import com.dk.common.response.ResponseResultUtil;
  6. import com.dk.common.response.ResponseResultVO;
  7. import com.dk.mdm.infrastructure.convert.mst.SupplierConvert;
  8. import com.dk.mdm.mapper.mac.OtherPayableMapper;
  9. import com.dk.mdm.model.pojo.mst.Supplier;
  10. import com.dk.mdm.mapper.mst.SupplierMapper;
  11. import com.dk.common.service.BaseService;
  12. import com.dk.common.mapper.BaseMapper;
  13. import com.dk.mdm.model.query.mac.MacTransferItemQuery;
  14. import com.dk.mdm.model.query.mac.OtherPayableQuery;
  15. import com.dk.mdm.model.query.mst.SupplierQuery;
  16. import com.dk.mdm.model.response.mac.MacTransferItemResponse;
  17. import com.dk.mdm.model.response.mac.MacTransferResponse;
  18. import com.dk.mdm.model.response.mac.OtherPayableResponse;
  19. import com.dk.mdm.model.response.mst.SpplierResponse;
  20. import com.dk.mdm.model.vo.mac.OtherPayableItemVO;
  21. import com.dk.mdm.model.vo.mac.OtherPayableVO;
  22. import com.dk.mdm.model.vo.mst.SupplierVo;
  23. import com.dk.mdm.service.common.CommonService;
  24. import com.dk.mdm.service.mac.OtherPayableService;
  25. import org.springframework.stereotype.Service;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.transaction.annotation.Transactional;
  28. import org.springframework.transaction.interceptor.TransactionAspectSupport;
  29. import java.math.BigDecimal;
  30. import java.time.LocalDate;
  31. import java.util.ArrayList;
  32. import java.util.List;
  33. import java.util.Map;
  34. @Service
  35. @Transactional
  36. public class SupplierService extends BaseService<Supplier> {
  37. /**
  38. * @desc : 重写主键
  39. * @author : 王英杰
  40. * @date : 2023/1/9 10:39
  41. */
  42. @Override
  43. public String getPrimaryKey() {
  44. return "sup_id";
  45. }
  46. @Override
  47. public BaseMapper<Supplier> getRepository() {
  48. return supplierMapper;
  49. }
  50. @Autowired
  51. private SupplierMapper supplierMapper;
  52. @Autowired
  53. private SupplierConvert supplierConvert;
  54. @Autowired
  55. private CommonService commonService;
  56. @Autowired
  57. private OtherPayableService otherPayableService;
  58. @Autowired
  59. private OtherPayableMapper otherPayableMapper;
  60. /**
  61. * @desc : 条件查询
  62. * @author : 王英杰
  63. * @date : 2023/1/10 17:19
  64. */
  65. @Pagination
  66. public ResponseResultVO<PageList<Supplier>> selectByCond(SupplierQuery supplierQuery) {
  67. List<SpplierResponse> list = new ArrayList<>();
  68. list = supplierMapper.selectByCond(supplierQuery);
  69. for(int i =0;i<list.size();i++){ //显示明细第一条的 内容
  70. list.get(i).getSupId();
  71. // 转账明细
  72. List<OtherPayableResponse> itemList = otherPayableMapper.selectByCond(new OtherPayableQuery().setObjectId(list.get(i).getSupId()).setBusinessType(0));
  73. if(itemList.size()>0){
  74. BigDecimal sumAmtPayableValue = (itemList != null && !itemList.isEmpty() && itemList.get(0).getSumAmtPayable() != null) ?
  75. itemList.get(0).getSumAmtPayable() :
  76. BigDecimal.ZERO;
  77. list.get(i).setSumAmtPayable(sumAmtPayableValue);
  78. }
  79. }
  80. return super.mergeListWithCount(supplierQuery,list ,
  81. supplierMapper.countByCond(supplierQuery));
  82. }
  83. /**
  84. * @desc : 停用 供应商
  85. * @author : 王英杰
  86. * @date : 2023/1/10 17:19
  87. */
  88. public ResponseResultVO<?> deactivateData(SupplierVo supplierVo) {
  89. return super.disable(supplierVo.getSupId());
  90. }
  91. /**
  92. * @desc : 新建供应商
  93. * @author : 王英杰
  94. * @date : 2024/2/27 9:17
  95. */
  96. @Transactional(rollbackFor = {Exception.class})
  97. public ResponseResultVO<?> insert(SupplierVo supplierVo) {
  98. // 转化实体
  99. Supplier supplier = supplierConvert.convertToPo(supplierVo);
  100. Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.SUPPLIER.getName(), true);
  101. supplier.setSupId(codeMap.get("outId").toString());
  102. supplier.setSupCode(codeMap.get("outNote").toString()); //插入供应商表的实体
  103. super.insert(supplier);// 先插入自己的供应商表
  104. if ((supplier.getBrandIds() != null) && (supplier.getBrandIds().size()>0)) { //如果有 商品品牌 一起插入品牌
  105. List<Supplier> Supplierlst = new ArrayList<>();
  106. List<String> BrandIdList = new ArrayList<>();
  107. BrandIdList = supplier.getBrandIds();
  108. Supplier supplier_center = null;
  109. for (int i = 0; i< BrandIdList.size();i++){
  110. supplier_center= new Supplier();
  111. supplier_center.setBrandId(BrandIdList.get(i));
  112. supplier_center.setSupId(supplier.getSupId());
  113. Supplierlst.add(supplier_center);
  114. }
  115. supplierMapper.insertSupplierBrandtBatch(Supplierlst); // 向供应商品牌表插入数据
  116. }
  117. if(supplierVo.getStartAmount()!=null && supplierVo.getStartAmount().compareTo(BigDecimal.ZERO) > 0) { //说明有起始欠款 需要插入其他支出
  118. //先组装明细
  119. List<OtherPayableItemVO> itemList = new ArrayList<>();
  120. OtherPayableItemVO otherPayableItemVO = new OtherPayableItemVO();
  121. otherPayableItemVO.setPayableType("10112024-0415-0000-0000-0000300dd508");
  122. otherPayableItemVO.setAmtPayable(supplierVo.getStartAmount());
  123. itemList.add(otherPayableItemVO);
  124. //调用 新建其他支出
  125. OtherPayableVO otherPayableVO = new OtherPayableVO().setBusinessType(0).setObjectId(supplier.getSupId())
  126. .setSumAmtPayable(supplierVo .getStartAmount()).setStaffId(supplier.getStaffId())
  127. .setOrgId(supplier.getOrgId()).setAccDate(LocalDate.now()).setMakeStaff(supplierVo
  128. .getMakeStaff()).setItemList(itemList).setSumAmtPay(BigDecimal.ZERO);
  129. otherPayableService.insert(otherPayableVO);
  130. }
  131. return ResponseResultUtil.success();
  132. }
  133. /**
  134. * @desc : 编辑方法
  135. * @author : 王英杰
  136. * @date : 2023/1/9 10:49
  137. */
  138. @Transactional(
  139. rollbackFor = {Exception.class}
  140. )
  141. public ResponseResultVO<?> update(SupplierVo supplierVo) {
  142. // 转化实体
  143. Supplier supplier = supplierConvert.convertToPo(supplierVo);
  144. super.updateByUuid(supplier);// 先更新的供应商表
  145. if ((supplier.getBrandIds() != null) && (supplier.getBrandIds().size()>0)) { //如果有 商品品牌 一起插入品牌
  146. supplierMapper.batchDeleteBrand(supplier.getSupId());//批量删除供应商对应的供应商品牌
  147. List<Supplier> Supplierlst = new ArrayList<>();
  148. List<String> BrandIdList = new ArrayList<>();
  149. BrandIdList = supplier.getBrandIds();
  150. Supplier supplier_center = null;
  151. for (int i = 0; i< BrandIdList.size();i++){
  152. supplier_center= new Supplier();
  153. supplier_center.setBrandId(BrandIdList.get(i));
  154. supplier_center.setSupId(supplier.getSupId());
  155. Supplierlst.add(supplier_center);
  156. }
  157. supplierMapper.insertSupplierBrandtBatch(Supplierlst); // 向供应商品牌表插入数据
  158. }
  159. return ResponseResultUtil.success();
  160. }
  161. }