SysSwitchConfigServiceImpl.java 5.0 KB

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