SaleChannelService.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package com.dk.mdm.service.mst;
  2. import com.dk.common.exception.BaseBusinessException;
  3. import com.dk.common.infrastructure.annotaiton.Pagination;
  4. import com.dk.common.infrastructure.constant.Constant;
  5. import com.dk.common.infrastructure.enums.ErrorCodeEnum;
  6. import com.dk.common.model.pojo.PageList;
  7. import com.dk.common.response.ResponseCodeEnum;
  8. import com.dk.common.response.ResponseResultUtil;
  9. import com.dk.common.response.ResponseResultVO;
  10. import com.dk.mdm.infrastructure.convert.mst.SaleChannelConvert;
  11. import com.dk.mdm.model.pojo.mst.SaleChannel;
  12. import com.dk.mdm.mapper.mst.SaleChannelMapper;
  13. import com.dk.common.service.BaseService;
  14. import com.dk.common.mapper.BaseMapper;
  15. import com.dk.mdm.model.query.mst.SaleChannelQuery;
  16. import com.dk.mdm.model.response.mst.SaleChannelResponse;
  17. import com.dk.mdm.model.vo.mst.SaleChannelVO;
  18. import com.dk.mdm.service.common.CommonService;
  19. import org.springframework.stereotype.Service;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.transaction.annotation.Transactional;
  22. import java.util.Map;
  23. @Service
  24. @Transactional
  25. public class SaleChannelService extends BaseService<SaleChannel> {
  26. @Override
  27. public BaseMapper<SaleChannel> getRepository() {
  28. return saleChannelMapper;
  29. }
  30. @Autowired
  31. private SaleChannelMapper saleChannelMapper;
  32. @Autowired
  33. private CommonService commonService;
  34. @Autowired
  35. private SaleChannelConvert saleChannelConvert;
  36. /**
  37. * @desc : 重写主键
  38. * @author : 于继渤
  39. * @date : 2024/2/29 20:29
  40. */
  41. @Override
  42. public String getPrimaryKey() {
  43. return "channel_id";
  44. }
  45. /**
  46. * @desc : 查询
  47. * @author : 于继渤
  48. * @date : 2023/1/5 9:39
  49. */
  50. @Pagination
  51. public ResponseResultVO<PageList<SaleChannelResponse>> selectByCond(SaleChannelQuery saleChannelQuery) {
  52. return super.mergeListWithCount(saleChannelQuery, saleChannelMapper.selectByCond(saleChannelQuery),
  53. saleChannelMapper.countByCond(saleChannelQuery));
  54. }
  55. /**
  56. * @desc : 新建
  57. * @author : 于继渤
  58. * @date : 2023/1/5 9:39
  59. */
  60. @Transactional(
  61. rollbackFor = {Exception.class}
  62. )
  63. public ResponseResultVO<?> insert(SaleChannelVO saleChannelVO) {
  64. //实体转换
  65. SaleChannel saleChannel = saleChannelConvert.convertToPo(saleChannelVO);
  66. //设置序号
  67. saleChannel.setDisplayNo(commonService.getMaxDisplayNo(Constant.DisplayNoTable.SALECHANNEL));
  68. //设置编码
  69. Map<String, Object> uniqueNoteCode = commonService.getUniqueNoteCode(Constant.docNameConstant.SALECHANNEL.getName(), true);
  70. saleChannel.setChannelId(uniqueNoteCode.get("outId").toString());
  71. saleChannel.setChannelCode(uniqueNoteCode.get("outNote").toString());
  72. //新建如果是默认取消其他默认
  73. if(saleChannelVO.getFlgDefault() != null && saleChannelVO.getFlgDefault() ){
  74. //默认 把其他置为非默认
  75. saleChannelMapper.updateFlgDefault(0);
  76. }
  77. //新建
  78. saleChannelMapper.insert(saleChannel);
  79. return ResponseResultUtil.success();
  80. }
  81. /**
  82. * @desc : 编辑
  83. * @author : 于继渤
  84. * @date : 2023/1/5 9:39
  85. */
  86. @Transactional(
  87. rollbackFor = {Exception.class}
  88. )
  89. public ResponseResultVO<?> update(SaleChannelVO saleChannelVO) {
  90. SaleChannel saleChannel1 = saleChannelMapper.selectById(saleChannelVO.getChannelId());
  91. Long a = saleChannelMapper.selectFlagDefult(new SaleChannelQuery());
  92. if ((saleChannel1.getFlgDefault() == null || !saleChannel1.getFlgDefault()) && saleChannelVO.getFlgDefault() != null && saleChannelVO.getFlgDefault()) {
  93. //默认 把其他置为非默认
  94. saleChannelMapper.updateFlgDefault(saleChannelVO.getCpId());
  95. }
  96. if( a == 1 && saleChannelVO.getFlgDefault()){
  97. SaleChannel saleChannel = saleChannelConvert.convertToPo(saleChannelVO);
  98. super.updateByUuid(saleChannel);
  99. }else{
  100. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.SALE_CHANNEL_DEFULT_IS_NOT_ONLY.getMessage());
  101. }
  102. return ResponseResultUtil.success();
  103. }
  104. /**
  105. * @desc : 批量编辑序号
  106. * @author : 于继渤
  107. * @date : 2023/1/4 9:39
  108. */
  109. @Transactional(
  110. rollbackFor = {Exception.class}
  111. )
  112. public ResponseResultVO<?> updateBatchSaleChannelDisplayNo(SaleChannelVO saleChannelVO) {
  113. saleChannelMapper.updateBatchSaleChannelDisplayNo(saleChannelVO.getDataIds());
  114. return ResponseResultUtil.success();
  115. }
  116. }