Blame view

SubjectRuleServiceImpl.java 2.43 KB
涂亚平 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
package com.meishu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.meishu.dto.rule.GetAllRulesDTO;
import com.meishu.mapper.SubjectTestDictMapper;
import com.meishu.model.SubjectRuleDO;
import com.meishu.mapper.SubjectRuleMapper;
import com.meishu.model.SubjectTestDictDO;
import com.meishu.service.SubjectRuleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meishu.util.ConstantUtils;
import com.meishu.vo.rule.GetAllRulesVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 规则字典表 服务实现类
 * </p>
 *
 * @author Tuyp
 * @since 2021-05-08
 */
@Service
public class SubjectRuleServiceImpl extends ServiceImpl<SubjectRuleMapper, SubjectRuleDO> implements SubjectRuleService {

    @Autowired
    private SubjectTestDictMapper subjectTestDictMapper;

    public IPage<GetAllRulesVO> getAllRules(GetAllRulesDTO getAllRulesDTO) {
        Page pager = new Page(getAllRulesDTO.getPageNum(), getAllRulesDTO.getPageSize());
        return this.baseMapper.getAllRules(pager);
    }

    public  List<GetAllRulesVO> getRules(){
        return this.baseMapper.getRules();
    }

    public String addRule(SubjectRuleDO subjectRuleDO) {
        subjectRuleDO.setStatus("1");
        this.baseMapper.insert(subjectRuleDO);
        return ConstantUtils.ADD_SUCCESS;
    }

    @Transactional(rollbackFor = Exception.class)
    public String updateRule(SubjectRuleDO subjectRuleDO) {
        this.baseMapper.updateById(subjectRuleDO);
        List<SubjectTestDictDO> subjectTestDictDOS = subjectTestDictMapper.selectList(new QueryWrapper<SubjectTestDictDO>()
                .lambda()
                .eq(SubjectTestDictDO::getRuleId,subjectRuleDO.getId()));
            for (SubjectTestDictDO subjectTestDictDO : subjectTestDictDOS){
                subjectTestDictDO.setStatus(subjectRuleDO.getStatus());
                subjectTestDictMapper.updateById(subjectTestDictDO);
            }
        return ConstantUtils.SUCCESS_UPDATE;
    }

    public String deleteRule(SubjectRuleDO subjectRuleDO){
        this.baseMapper.deleteById(subjectRuleDO.getId());
        return ConstantUtils.DELETE_SUCCESS;
    }

}