package com.mzl.flower.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzl.flower.config.exception.ValidationException;
import com.mzl.flower.config.security.SecurityUtils;
import com.mzl.flower.dto.request.configParam.ParamGroupDTO;
import com.mzl.flower.dto.request.configParam.QueryConfigParamDTO;
import com.mzl.flower.dto.request.configParam.QueryConfigParamGroupDTO;
import com.mzl.flower.dto.response.configParam.ConfigParamGroupVO;
import com.mzl.flower.dto.response.configParam.ConfigParamVO;
import com.mzl.flower.entity.configParam.ConfigParamDO;
import com.mzl.flower.entity.configParam.ConfigParamGroupDO;
import com.mzl.flower.mapper.configParam.ConfigParamGroupMapper;
import com.mzl.flower.mapper.configParam.ConfigParamGroupMapperCustom;
import com.mzl.flower.mapper.configParam.ConfigParamMapper;
import com.mzl.flower.service.ConfigParamGroupService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.List;
/**
*
* 服务实现类
*
*
* @author @TaoJie
* @since 2024-12-02
*/
@Service
public class ConfigParamGroupServiceImpl extends ServiceImpl implements ConfigParamGroupService {
@Autowired
private ConfigParamGroupMapperCustom configParamGroupMapperCustom;
@Autowired
private ConfigParamGroupMapper configParamGroupMapper;
@Autowired
ConfigParamMapper configParamMapper;
@Override
public List getList(QueryConfigParamDTO dto) {
QueryWrapper wrapper = new QueryWrapper<>();
wrapper.lambda().eq(ConfigParamGroupDO::getDeleted,false)
.orderByAsc(ConfigParamGroupDO::getParamOrder);
return list(wrapper);
}
@Override
public void saveConfigParamGroup(ParamGroupDTO dto) {
ConfigParamGroupDO c1 = configParamMapper.getByParamGroup(dto.getParamGroup());
if (!ObjectUtils.isEmpty(c1)) {
throw new ValidationException("变量分组重复");
}
ConfigParamGroupDO c2 = configParamMapper.getByParamGroupName(dto.getParamGroupName());
if (!ObjectUtils.isEmpty(c2)) {
throw new ValidationException("变量分组名重复");
}
ConfigParamGroupDO configParamGroupDO = new ConfigParamGroupDO();
BeanUtils.copyProperties(dto, configParamGroupDO);
configParamGroupDO.create(SecurityUtils.getUserId());
configParamGroupMapper.insert(configParamGroupDO);
}
@Override
public void updateConfigParamGroup(ParamGroupDTO dto) {
ConfigParamGroupDO c1 = configParamMapper.getByParamGroup(dto.getParamGroup());
if (!ObjectUtils.isEmpty(c1)) {
if (c1.getId() != dto.getId()) {
throw new ValidationException("已存在变量分组,无法修改");
}
}
ConfigParamGroupDO c2 = configParamMapper.getByParamGroupName(dto.getParamGroupName());
if (!ObjectUtils.isEmpty(c2)) {
if (c2.getId() != dto.getId()) {
throw new ValidationException("已存在变量分组名,无法修改");
}
}
ConfigParamGroupDO configParamGroupDO = configParamGroupMapper.selectById(dto.getId());
BeanUtils.copyProperties(dto, configParamGroupDO);
configParamGroupDO.update(SecurityUtils.getUserId());
configParamGroupMapper.updateById(configParamGroupDO);
}
@Override
public void deleteConfigParamGroup(Long id) {
configParamGroupMapper.deleteById(id);
}
@Override
public Page queryPage(QueryConfigParamGroupDTO dto, Page page) {
List list = configParamGroupMapper.queryPage(dto, page);
page.setRecords(list);
return page;
}
}