SysSwitchConfigServiceImpl.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package com.ydtech.modules.admin.service.impl;
  2. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  3. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  4. import com.github.pagehelper.util.StringUtil;
  5. import com.ydtech.modules.admin.constants.ManagementSource;
  6. import com.ydtech.modules.admin.constants.SwitchConfig;
  7. import com.ydtech.modules.admin.dao.SysSwitchConfigMapper;
  8. import com.ydtech.modules.admin.model.SysDept;
  9. import com.ydtech.modules.admin.model.dto.FeeLookSwitchesDTO;
  10. import com.ydtech.modules.admin.model.po.SysSwitchConfig;
  11. import com.ydtech.modules.admin.model.vo.SysSwitchConfigQueryVo;
  12. import com.ydtech.modules.admin.model.vo.SysSwitchConfigVo;
  13. import com.ydtech.modules.admin.service.SysDeptService;
  14. import com.ydtech.modules.admin.service.SysSwitchConfigService;
  15. import com.ydtech.modules.base.controller.BaseController;
  16. import com.ydtech.modules.fee.constants.CostAllocation;
  17. import com.ydtech.modules.fee.dto.po.InsFeeOrderConfig;
  18. import com.ydtech.modules.fee.service.InsFeeOrderConfigService;
  19. import com.ydtech.modules.order.entity.BasePageResult;
  20. import com.ydtech.modules.order.entity.vo.OrderVo;
  21. import com.ydtech.modules.protocol.utils.AssertionUtils;
  22. import lombok.RequiredArgsConstructor;
  23. import org.apache.commons.lang3.ObjectUtils;
  24. import org.springframework.beans.BeanUtils;
  25. import org.springframework.stereotype.Service;
  26. import org.springframework.transaction.annotation.Transactional;
  27. import java.math.BigDecimal;
  28. import java.util.Date;
  29. /**
  30. * @author Administrator
  31. * @description 针对表【sys_switch_config(系统开关配置表)】的数据库操作Service实现
  32. * @createDate 2024-08-07 18:04:47
  33. */
  34. @Service
  35. @RequiredArgsConstructor
  36. public class SysSwitchConfigServiceImpl extends ServiceImpl<SysSwitchConfigMapper, SysSwitchConfig> implements SysSwitchConfigService {
  37. private final SysDeptService sysDeptService;
  38. private final InsFeeOrderConfigService insFeeOrderConfigService;
  39. @Override
  40. public BigDecimal getEnterProportion(String deptId, Integer entryStatus) {
  41. if (entryStatus != 2) {
  42. return BigDecimal.ZERO;
  43. }
  44. SysDept dept = sysDeptService.getById(deptId);
  45. SysSwitchConfig config;
  46. CostAllocation costAllocation;
  47. SwitchConfig switchConfig;
  48. // 渠道
  49. if (ManagementSource.MS_01.getCode().equals(dept.getManagementSource())) {
  50. costAllocation = CostAllocation.CA_05;
  51. switchConfig = SwitchConfig.SC_02;
  52. // 代理人
  53. } else {
  54. costAllocation = CostAllocation.CA_04;
  55. switchConfig = SwitchConfig.SC_01;
  56. }
  57. config = lambdaQuery().eq(SysSwitchConfig::getKeyword, switchConfig.getCode()).one();
  58. if (config.getEnabled() == 1) {
  59. InsFeeOrderConfig insFeeOrderConfig = insFeeOrderConfigService.lambdaQuery()
  60. .eq(InsFeeOrderConfig::getKeyword, costAllocation.getCode())
  61. .one();
  62. return insFeeOrderConfig.getVal();
  63. }
  64. return BigDecimal.ZERO;
  65. }
  66. @Override
  67. public void add(SysSwitchConfigVo sysSwitchConfigVo) {
  68. SysSwitchConfig sysSwitchConfig = new SysSwitchConfig();
  69. BeanUtils.copyProperties(sysSwitchConfigVo, sysSwitchConfig);
  70. String userId = BaseController.getUserId();
  71. sysSwitchConfig.setCreateBy(userId);
  72. sysSwitchConfig.setCreateTime(new Date());
  73. boolean save = save(sysSwitchConfig);
  74. AssertionUtils.isSucceed(save, "增加失败");
  75. }
  76. @Override
  77. @Transactional
  78. public void revise(String id, SysSwitchConfigVo sysSwitchConfigVo) {
  79. SysSwitchConfig sysSwitchConfig = getByIdExist(id, "未查询到你所配置的开关");
  80. BeanUtils.copyProperties(sysSwitchConfigVo, sysSwitchConfig);
  81. String userId = BaseController.getUserId();
  82. sysSwitchConfig.setUpdateBy(userId);
  83. sysSwitchConfig.setUpdateTime(new Date());
  84. boolean b = updateById(sysSwitchConfig);
  85. AssertionUtils.isSucceed(b, "修改失败");
  86. }
  87. @Override
  88. public BasePageResult<SysSwitchConfig> queryPage(SysSwitchConfigQueryVo sysSwitchConfigQueryVo) {
  89. Page<SysSwitchConfig> page = new Page<>(sysSwitchConfigQueryVo.getPageNum(), sysSwitchConfigQueryVo.getPageSize());
  90. Page<SysSwitchConfig> sysSwitchConfigPage = lambdaQuery()
  91. .eq(!ObjectUtils.isEmpty(sysSwitchConfigQueryVo.getEnabled()), SysSwitchConfig::getEnabled, sysSwitchConfigQueryVo.getEnabled())
  92. .like(StringUtil.isNotEmpty(sysSwitchConfigQueryVo.getKeyword()), SysSwitchConfig::getKeyword, sysSwitchConfigQueryVo.getKeyword())
  93. .like(StringUtil.isNotEmpty(sysSwitchConfigQueryVo.getProject()), SysSwitchConfig::getProject, sysSwitchConfigQueryVo.getProject())
  94. .like(StringUtil.isNotEmpty(sysSwitchConfigQueryVo.getFunctionName()), SysSwitchConfig::getFunctionName, sysSwitchConfigQueryVo.getFunctionName())
  95. .page(page);
  96. return new BasePageResult<>(sysSwitchConfigQueryVo.getPageNum(), sysSwitchConfigQueryVo.getPageSize(),
  97. sysSwitchConfigPage.getTotal(), sysSwitchConfigPage.getPages(), sysSwitchConfigPage.getRecords());
  98. }
  99. @Override
  100. public FeeLookSwitchesDTO feeLookSwitches() {
  101. String deptId = BaseController.getDeptId();
  102. FeeLookSwitchesDTO feeLookSwitchesDTO = new FeeLookSwitchesDTO();
  103. SysDept dept = sysDeptService.getById(deptId);
  104. // 渠道
  105. if (ManagementSource.MS_01.getCode().equals(dept.getManagementSource())) {
  106. feeLookSwitchesDTO.setFeeView(isEnabled(SwitchConfig.FEE_02.getCode()));
  107. feeLookSwitchesDTO.setFeeDisplay(isEnabled(SwitchConfig.FDA_02.getCode()));
  108. // 代理人
  109. } else if (ManagementSource.MS_02.getCode().equals(dept.getManagementSource())) {
  110. feeLookSwitchesDTO.setFeeView(isEnabled(SwitchConfig.FEE_01.getCode()));
  111. feeLookSwitchesDTO.setFeeDisplay(isEnabled(SwitchConfig.FDA_01.getCode()));
  112. }else {
  113. feeLookSwitchesDTO.setFeeView(true);
  114. feeLookSwitchesDTO.setFeeDisplay(true);
  115. }
  116. return feeLookSwitchesDTO;
  117. }
  118. @Override
  119. public boolean feeDisplaySwitches() {
  120. String deptId = BaseController.getDeptId();
  121. SysDept dept = sysDeptService.getById(deptId);
  122. if (ManagementSource.MS_01.getCode().equals(dept.getManagementSource())) {
  123. return isEnabled(SwitchConfig.FEE_02.getCode());
  124. // 代理人
  125. } else if (ManagementSource.MS_02.getCode().equals(dept.getManagementSource())) {
  126. return isEnabled(SwitchConfig.FEE_01.getCode());
  127. }
  128. return true;
  129. }
  130. }