SupplierService.java 7.9 KB

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