| | |
| | | package com.xcong.farmer.cms.modules.system.service.Impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.xcong.farmer.cms.common.exception.GlobalException; |
| | | import com.xcong.farmer.cms.modules.system.conversion.CmsGroupInfoConversion; |
| | | import com.xcong.farmer.cms.modules.system.dto.AddGroupInfoDto; |
| | | import com.xcong.farmer.cms.modules.system.dto.ModifyGroupInfoDto; |
| | | import com.xcong.farmer.cms.modules.system.entity.CmsGroupInfoEntity; |
| | | import com.xcong.farmer.cms.modules.system.entity.UserEntity; |
| | | import com.xcong.farmer.cms.modules.system.mapper.CmsGroupInfoMapper; |
| | | import com.xcong.farmer.cms.modules.system.service.ICmsGroupInfoService; |
| | | import com.xcong.farmer.cms.modules.system.util.LoginUserUtil; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * @author wzy |
| | |
| | | **/ |
| | | @Slf4j |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class CmsGroupInfoServiceImpl extends ServiceImpl<CmsGroupInfoMapper, CmsGroupInfoEntity> implements ICmsGroupInfoService { |
| | | |
| | | |
| | | @Override |
| | | public void add(AddGroupInfoDto addGroupInfoDto) { |
| | | UserEntity user = LoginUserUtil.getLoginUser(); |
| | | |
| | | CmsGroupInfoEntity hasExist = this.baseMapper.selectByCode(addGroupInfoDto.getCode(), user.getCompanyId()); |
| | | if (hasExist != null) { |
| | | throw new GlobalException("分组编码已存在"); |
| | | } |
| | | |
| | | CmsGroupInfoEntity groupInfo = CmsGroupInfoConversion.INSTANCE.addDtoToEntity(addGroupInfoDto); |
| | | groupInfo.setCreateBy(user.getNickname()); |
| | | groupInfo.setUpdateBy(user.getNickname()); |
| | | groupInfo.setCompanyId(user.getCompanyId()); |
| | | this.baseMapper.insert(groupInfo); |
| | | } |
| | | |
| | | @Override |
| | | public void modify(ModifyGroupInfoDto modifyGroupInfoDto) { |
| | | UserEntity user = LoginUserUtil.getLoginUser(); |
| | | |
| | | CmsGroupInfoEntity hasExist = this.baseMapper.selectByCode(modifyGroupInfoDto.getCode(), user.getCompanyId()); |
| | | if (hasExist != null && !Objects.equals(hasExist.getId(), modifyGroupInfoDto.getId())) { |
| | | throw new GlobalException("分组编码已存在"); |
| | | } |
| | | |
| | | CmsGroupInfoEntity groupInfo = CmsGroupInfoConversion.INSTANCE.modifyDtoToEntity(modifyGroupInfoDto); |
| | | groupInfo.setUpdateBy(user.getNickname()); |
| | | this.baseMapper.updateById(groupInfo); |
| | | } |
| | | } |