zxl
9 小时以前 3b0516a2959e25576e4f3fda697a3b025d06c8c9
ycl-server/src/main/java/com/ycl/platform/service/impl/CheckRuleServiceImpl.java
@@ -1,160 +1,108 @@
package com.ycl.platform.service.impl;
import com.ycl.platform.base.BaseSelect;
import com.ycl.platform.domain.entity.CheckRule;
import com.ycl.platform.domain.entity.YwUnit;
import com.ycl.platform.mapper.CheckRuleMapper;
import com.ycl.platform.service.CheckRuleService;
import com.ycl.system.Result;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycl.platform.domain.form.CheckRuleForm;
import com.ycl.platform.domain.entity.CheckRule;
import com.ycl.platform.domain.vo.CheckRuleVO;
import com.ycl.platform.domain.query.CheckRuleQuery;
import java.util.List;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ycl.system.page.PageUtil;
import com.ycl.utils.DateUtils;
import org.springframework.stereotype.Service;
import org.springframework.security.core.context.SecurityContextHolder;
import com.ycl.platform.mapper.CheckRuleMapper;
import com.ycl.platform.service.ICheckRuleService;
import constant.CheckConstants;
import org.hibernate.annotations.Check;
import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.util.ArrayList;
import java.util.Objects;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import utils.DateUtils;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.util.StringUtils;
/**
 * 考核规则 服务实现类
 *
 * @author xp
 * @since 2024-03-06
 * 考核规则Service业务层处理
 *
 * @author ruoyi
 * @date 2024-04-15
 */
@Service
@RequiredArgsConstructor
public class CheckRuleServiceImpl extends ServiceImpl<CheckRuleMapper, CheckRule> implements CheckRuleService {
    private final CheckRuleMapper checkRuleMapper;
public class CheckRuleServiceImpl extends ServiceImpl<CheckRuleMapper, CheckRule> implements ICheckRuleService
{
    @Autowired
    private CheckRuleMapper checkRuleMapper;
    /**
     * 添加
     * @param form
     * @return
     * 查询考核规则
     * @param id 考核规则主键
     * @return 考核规则
     */
    @Override
    public Result add(CheckRuleForm form) {
        CheckRule entity = CheckRuleForm.getEntityByForm(form, null);
        if(baseMapper.insert(entity) > 0) {
            return Result.ok("添加成功");
        }
        return Result.error("添加失败");
    public CheckRule selectCheckRuleById(Long id)
    {
        return checkRuleMapper.selectCheckRuleById(id);
    }
    /**
     * 修改
     * @param form
     * @return
     * 查询考核规则列表
     *
     * @param checkRule 考核规则
     * @return 考核规则
     */
    @Override
    public Result update(CheckRuleForm form) {
        CheckRule entity = baseMapper.selectById(form.getId());
        // 为空抛IllegalArgumentException,做全局异常处理
        Assert.notNull(entity, "记录不存在");
        BeanUtils.copyProperties(form, entity);
        if (baseMapper.updateById(entity) > 0) {
            return Result.ok("修改成功");
        }
        return Result.error("修改失败");
    public CheckRuleVO selectCheckRuleList(CheckRule checkRule)
    {
        List<CheckRule> checkRules = checkRuleMapper.selectCheckRuleList(checkRule);
        Map<Short, List<CheckRule>> map = checkRules.stream().collect(Collectors.groupingBy(CheckRule::getRuleCategory));
        CheckRuleVO checkRuleVO = new CheckRuleVO()
                .setCarRules(map.get(CheckConstants.Rule_Category_Car))
                .setFaceRules(map.get(CheckConstants.Rule_Category_Face))
                .setVideoRules(map.get(CheckConstants.Rule_Category_Video));
        return checkRuleVO;
    }
    /**
     * 批量删除
     * @param ids
     * @return
     * 新增考核规则
     *
     * @param checkRule 考核规则
     * @return 结果
     */
    @Override
    public Result remove(List<String> ids) {
        if(baseMapper.deleteBatchIds(ids) > 0) {
            return Result.ok("删除成功");
        }
        return Result.error("删除失败");
    public int insertCheckRule(CheckRule checkRule)
    {
        return checkRuleMapper.insertCheckRule(checkRule);
    }
    /**
     * id删除
     * @param id
     * @return
     * 修改考核规则
     * @param checkRule 考核规则
     * @return 结果
     */
    @Override
    public Result removeById(String id) {
        if(baseMapper.deleteById(id) > 0) {
            return Result.ok("删除成功");
        }
        return Result.error("删除失败");
    public int updateCheckRule(CheckRule checkRule)
    {
        return checkRuleMapper.updateCheckRule(checkRule);
    }
    /**
     * 分页查询
     * @param query
     * @return
     * 批量删除考核规则
     *
     * @param ids 需要删除的考核规则主键
     * @return 结果
     */
    @Override
    public Result page(CheckRuleQuery query) {
        IPage<CheckRule> page = new LambdaQueryChainWrapper<>(baseMapper)
                .like(StringUtils.hasText(query.getRuleName()), CheckRule::getRuleName, query.getRuleName())
                .between(Objects.nonNull(query.getStart()) && Objects.nonNull(query.getEnd()),
                        CheckRule::getCreateTime,
                        DateUtils.getDayStart(query.getStart()),
                        DateUtils.getDayEnd(query.getEnd()))
                .orderByDesc(CheckRule::getCreateTime)
                .page(PageUtil.getPage(query, CheckRule.class));
        List<CheckRuleVO> vos = page.getRecords().stream()
                .map(
                        entity -> CheckRuleVO.getVoByEntity(entity, null)
                )
                .collect(Collectors.toList());
        return Result.ok().data(vos).total(page.getTotal());
    public int deleteCheckRuleByIds(Long[] ids)
    {
        return checkRuleMapper.deleteCheckRuleByIds(ids);
    }
    /**
     * 根据id查找
     * @param id
     * @return
     * 删除考核规则信息
     *
     * @param id 考核规则主键
     * @return 结果
     */
    @Override
    public Result detail(String id) {
        CheckRule entity = baseMapper.selectById(id);
        Assert.notNull(entity, "记录不存在");
        CheckRuleVO vo = CheckRuleVO.getVoByEntity(entity, null);
        return Result.ok().data(vo);
    }
    /**
     * 列表
     * @return
     */
    @Override
    public Result all() {
        List<CheckRule> entities = baseMapper.selectList(null);
        List<BaseSelect> vos = entities.stream()
                .map(
                        entity -> {
                            BaseSelect vo = new BaseSelect();
                            vo.setId(entity.getId());
                            vo.setValue(entity.getRuleName());
                            return vo;
                        }
                )
                .collect(Collectors.toList());
        return Result.ok().data(vos);
    public int deleteCheckRuleById(Long id)
    {
        return checkRuleMapper.deleteCheckRuleById(id);
    }
}