SupplierService.java 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. list.get(i).setSumAmtPayable(itemList.get(0).getSumAmtPayable());
  75. }
  76. }
  77. return super.mergeListWithCount(supplierQuery,list ,
  78. supplierMapper.countByCond(supplierQuery));
  79. }
  80. /**
  81. * @desc : 停用 供应商
  82. * @author : 王英杰
  83. * @date : 2023/1/10 17:19
  84. */
  85. public ResponseResultVO<?> deactivateData(SupplierVo supplierVo) {
  86. return super.disable(supplierVo.getSupId());
  87. }
  88. /**
  89. * @desc : 新建供应商
  90. * @author : 王英杰
  91. * @date : 2024/2/27 9:17
  92. */
  93. @Transactional(rollbackFor = {Exception.class})
  94. public ResponseResultVO<?> insert(SupplierVo supplierVo) {
  95. // 转化实体
  96. Supplier supplier = supplierConvert.convertToPo(supplierVo);
  97. Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.SUPPLIER.getName(), true);
  98. supplier.setSupId(codeMap.get("outId").toString());
  99. supplier.setSupCode(codeMap.get("outNote").toString()); //插入供应商表的实体
  100. super.insert(supplier);// 先插入自己的供应商表
  101. if ((supplier.getBrandIds() != null) && (supplier.getBrandIds().size()>0)) { //如果有 商品品牌 一起插入品牌
  102. List<Supplier> Supplierlst = new ArrayList<>();
  103. List<String> BrandIdList = new ArrayList<>();
  104. BrandIdList = supplier.getBrandIds();
  105. Supplier supplier_center = null;
  106. for (int i = 0; i< BrandIdList.size();i++){
  107. supplier_center= new Supplier();
  108. supplier_center.setBrandId(BrandIdList.get(i));
  109. supplier_center.setSupId(supplier.getSupId());
  110. Supplierlst.add(supplier_center);
  111. }
  112. supplierMapper.insertSupplierBrandtBatch(Supplierlst); // 向供应商品牌表插入数据
  113. }
  114. if(supplierVo.getStartAmount()!=null && supplierVo.getStartAmount().compareTo(BigDecimal.ZERO) > 0) { //说明有起始欠款 需要插入其他支出
  115. //先组装明细
  116. List<OtherPayableItemVO> itemList = new ArrayList<>();
  117. OtherPayableItemVO otherPayableItemVO = new OtherPayableItemVO();
  118. otherPayableItemVO.setPayableType("10112024-0415-0000-0000-0000300dd508");
  119. otherPayableItemVO.setAmtPayable(supplierVo.getStartAmount());
  120. itemList.add(otherPayableItemVO);
  121. //调用 新建其他支出
  122. OtherPayableVO otherPayableVO = new OtherPayableVO().setBusinessType(0).setObjectId(supplier.getSupId())
  123. .setSumAmtPayable(supplierVo .getStartAmount()).setStaffId(supplier.getStaffId())
  124. .setOrgId(supplier.getOrgId()).setAccDate(LocalDate.now()).setMakeStaff(supplierVo
  125. .getMakeStaff()).setItemList(itemList).setSumAmtPay(BigDecimal.ZERO);
  126. otherPayableService.insert(otherPayableVO);
  127. }
  128. return ResponseResultUtil.success();
  129. }
  130. /**
  131. * @desc : 编辑方法
  132. * @author : 王英杰
  133. * @date : 2023/1/9 10:49
  134. */
  135. @Transactional(
  136. rollbackFor = {Exception.class}
  137. )
  138. public ResponseResultVO<?> update(SupplierVo supplierVo) {
  139. // 转化实体
  140. Supplier supplier = supplierConvert.convertToPo(supplierVo);
  141. try {
  142. super.updateByUuid(supplier);// 先更新的供应商表
  143. if ((supplier.getBrandIds() != null) && (supplier.getBrandIds().size()>0)) { //如果有 商品品牌 一起插入品牌
  144. supplierMapper.batchDeleteBrand(supplier.getBrandIds());//批量删除供应商对应的供应商品牌
  145. List<Supplier> Supplierlst = new ArrayList<>();
  146. List<String> BrandIdList = new ArrayList<>();
  147. BrandIdList = supplier.getBrandIds();
  148. Supplier supplier_center = null;
  149. for (int i = 0; i< BrandIdList.size();i++){
  150. supplier_center= new Supplier();
  151. supplier_center.setBrandId(BrandIdList.get(i));
  152. supplier_center.setSupId(supplier.getSupId());
  153. Supplierlst.add(supplier_center);
  154. }
  155. supplierMapper.insertSupplierBrandtBatch(Supplierlst); // 向供应商品牌表插入数据
  156. }
  157. return ResponseResultUtil.success();
  158. } catch (Exception e) {
  159. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); // 手动回滚事务
  160. return ResponseResultUtil.error("更新失败");
  161. }
  162. }
  163. }