| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- package com.ydtech.modules.admin.service.impl;
- import cn.hutool.core.collection.CollUtil;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.ydtech.modules.admin.constants.UserConstants;
- import com.ydtech.modules.admin.dao.SysChannelGradeMapper;
- import com.ydtech.modules.admin.model.po.*;
- import com.ydtech.modules.admin.model.vo.AuthSysChannelGradeVo;
- import com.ydtech.modules.admin.model.vo.SysChannelGradePageVo;
- import com.ydtech.modules.admin.model.vo.SysChannelVo;
- import com.ydtech.modules.admin.service.SysChannelAreaRelationService;
- import com.ydtech.modules.admin.service.SysChannelGradeService;
- import com.ydtech.modules.admin.service.SysChannelGroupInfoService;
- import com.ydtech.modules.protocol.utils.AssertionUtils;
- import org.apache.commons.lang3.ObjectUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Objects;
- import java.util.stream.Collectors;
- /**
- * @author dongxin
- * @description 针对表【sys_channel_grade(渠道分组级别表)】的数据库操作Service实现
- * @createDate 2024-09-10 17:41:31
- */
- @Service
- public class SysChannelGradeServiceImpl extends ServiceImpl<SysChannelGradeMapper, SysChannelGrade>
- implements SysChannelGradeService {
- @Autowired
- private SysChannelAreaRelationService sysChannelAreaRelationService;
- @Autowired
- private SysChannelGradeService sysChannelGradeService;
- @Autowired
- private SysChannelGroupInfoService sysChannelGroupInfoService;
- @Override
- public List<SysChannelGrade> queryList() {
- return list();
- }
- @Override
- public String checkNameUnique(SysChannelGrade sysChannelGrade) {
- Long groupId = ObjectUtils.isEmpty(sysChannelGrade.getId()) ? -1L: sysChannelGrade.getId();
- QueryWrapper<SysChannelGrade> qw = new QueryWrapper<>();
- qw.eq("name", sysChannelGrade.getName());
- SysChannelGrade info = this.baseMapper.selectOne(qw);
- if (!Objects.isNull(info) && info.getId() != groupId) {
- return UserConstants.NOT_UNIQUE;
- }
- return UserConstants.UNIQUE;
- }
- @Override
- @Transactional
- public void authArea(AuthSysChannelGradeVo authSysChannelGradeVo) {
- // 删除所有已经授权机构
- LambdaQueryWrapper<SysChannelAreaRelation> lqw = new LambdaQueryWrapper<>();
- lqw.eq(SysChannelAreaRelation::getGradeId, authSysChannelGradeVo.getId());
- sysChannelAreaRelationService.remove(lqw);
- List<String> areaIdList = authSysChannelGradeVo.getAreaIdList();
- List<SysChannelAreaRelation> relations = new ArrayList<>();
- if (CollUtil.isNotEmpty(areaIdList)) {
- for (String areaId : areaIdList) {
- SysChannelAreaRelation sysChannelAreaRelation = new SysChannelAreaRelation();
- sysChannelAreaRelation.setGradeId(authSysChannelGradeVo.getId());
- sysChannelAreaRelation.setAreaId(areaId);
- relations.add(sysChannelAreaRelation);
- }
- sysChannelAreaRelationService.saveBatch(relations);
- }
- }
- @Override
- @Transactional
- public void delete(Long id) {
- // 判断是否有费用设置
- LambdaQueryWrapper<SysChannelGroupInfo> infoWapper = new LambdaQueryWrapper<>();
- infoWapper.eq(SysChannelGroupInfo::getGradeId, id);
- long count = sysChannelGroupInfoService.count(infoWapper);
- AssertionUtils.isFail(count > 0,"该分组已经设置费用,请先删除费用分组");
- // 删除所有授权机构
- LambdaQueryWrapper<SysChannelAreaRelation> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(SysChannelAreaRelation::getGradeId, id);
- sysChannelAreaRelationService.remove(wrapper);
- // 删除渠道分组级别
- sysChannelGradeService.removeById(id);
- }
- @Override
- public Page<SysChannelGrade> queryPage(Page page, SysChannelGradePageVo sysChannelGradePageVo) {
- LambdaQueryWrapper<SysChannelGrade> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(!ObjectUtils.isEmpty(sysChannelGradePageVo.getName()), SysChannelGrade::getName,
- sysChannelGradePageVo.getName());
- Page<SysChannelGrade> channelGradePage = page(page, wrapper);
- return channelGradePage;
- }
- @Override
- public List<SysChannelAreaRelation> queryRelation(SysChannelVo sysChannelVo) {
- List<SysChannelAreaRelation> relationList = sysChannelAreaRelationService.queryRelationList(sysChannelVo);
- if(CollUtil.isEmpty(relationList)){
- return relationList;
- }else{
- for (SysChannelAreaRelation sysChannelAreaRelation : relationList) {
- sysChannelAreaRelation.setName(sysChannelAreaRelation.getName() + "--" + sysChannelAreaRelation.getAreaId());
- }
- return relationList;
- }
- }
- }
|