|
@@ -1,11 +1,75 @@
|
|
|
package com.sqx.modules.lovers.service.impl;
|
|
package com.sqx.modules.lovers.service.impl;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.sqx.common.exception.SqxException;
|
|
|
|
|
+import com.sqx.common.utils.PageUtils;
|
|
|
import com.sqx.modules.lovers.dao.LoversSetRuleDao;
|
|
import com.sqx.modules.lovers.dao.LoversSetRuleDao;
|
|
|
|
|
+import com.sqx.modules.lovers.dto.LoversSetRuleDTO;
|
|
|
|
|
+import com.sqx.modules.lovers.dto.LoversSetRuleQueryDTO;
|
|
|
import com.sqx.modules.lovers.entity.LoversSetRule;
|
|
import com.sqx.modules.lovers.entity.LoversSetRule;
|
|
|
import com.sqx.modules.lovers.service.LoversSetRuleService;
|
|
import com.sqx.modules.lovers.service.LoversSetRuleService;
|
|
|
|
|
+import com.sqx.modules.lovers.vo.LoversSetRuleVO;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
@Service
|
|
@Service
|
|
|
public class LoversSetRuleServiceImpl extends ServiceImpl<LoversSetRuleDao, LoversSetRule> implements LoversSetRuleService {
|
|
public class LoversSetRuleServiceImpl extends ServiceImpl<LoversSetRuleDao, LoversSetRule> implements LoversSetRuleService {
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public PageUtils page(LoversSetRuleQueryDTO queryDTO) {
|
|
|
|
|
+ Page<LoversSetRule> pages = new Page<>(queryDTO.getPage(), queryDTO.getLimit());
|
|
|
|
|
+ LambdaQueryWrapper<LoversSetRule> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ queryWrapper.eq(StrUtil.isNotBlank(queryDTO.getName()), LoversSetRule::getName, queryDTO.getName());
|
|
|
|
|
+
|
|
|
|
|
+ IPage<LoversSetRule> page = this.page(pages, queryWrapper);
|
|
|
|
|
+ PageUtils pageUtils = new PageUtils(page);
|
|
|
|
|
+
|
|
|
|
|
+ List<LoversSetRuleVO> vos = pageUtils.getList().stream().map(e -> {
|
|
|
|
|
+ LoversSetRuleVO vo = new LoversSetRuleVO();
|
|
|
|
|
+ BeanUtil.copyProperties(e, vo);
|
|
|
|
|
+ return vo;
|
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ pageUtils.setList(vos);
|
|
|
|
|
+
|
|
|
|
|
+ return pageUtils;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void add(LoversSetRuleDTO loversSetRule) {
|
|
|
|
|
+ // 检测名称是否重复
|
|
|
|
|
+ checkNameUnique(null, loversSetRule.getName());
|
|
|
|
|
+
|
|
|
|
|
+ LoversSetRule entity = new LoversSetRule();
|
|
|
|
|
+ BeanUtil.copyProperties(loversSetRule, entity);
|
|
|
|
|
+ entity.setDelFlag("0");
|
|
|
|
|
+
|
|
|
|
|
+ this.save(entity);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void update(LoversSetRuleDTO loversSetRule) {
|
|
|
|
|
+ checkNameUnique(loversSetRule.getId(), loversSetRule.getName());
|
|
|
|
|
+
|
|
|
|
|
+ LoversSetRule entity = new LoversSetRule();
|
|
|
|
|
+ BeanUtil.copyProperties(loversSetRule, entity);
|
|
|
|
|
+ this.updateById(entity);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void checkNameUnique(Long id, String name) {
|
|
|
|
|
+ LambdaQueryWrapper<LoversSetRule> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ queryWrapper.ne(ObjectUtil.isNotNull(id), LoversSetRule::getId, id);
|
|
|
|
|
+ queryWrapper.eq(LoversSetRule::getName, name);
|
|
|
|
|
+ if (this.count(queryWrapper) > 0) {
|
|
|
|
|
+ throw new SqxException("规则名称重复");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|