YearDictServiceImpl.java 1.48 KB
package com.zhongzhi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhongzhi.common.exception.HttpException;
import com.zhongzhi.model.YearDictDO;
import com.zhongzhi.dao.YearDictDAO;
import com.zhongzhi.service.YearDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 年份字典表 服务实现类
 * </p>
 *
 * @author DengMin
 * @since 2023-04-11
 */
@Service
public class YearDictServiceImpl extends ServiceImpl<YearDictDAO, YearDictDO> implements YearDictService {


    public List<YearDictDO> queryYears() {
        return this.baseMapper.selectList(null);
    }

    public void updateYear(YearDictDO yearDictDO) {

        int count = this.baseMapper.selectCount(new QueryWrapper<YearDictDO>()
        .lambda()
        .eq(YearDictDO::getYear,yearDictDO.getYear())
        .ne(YearDictDO::getId,yearDictDO.getId()));

        if (count > 0 ){
            throw new HttpException(90001);
        }

        this.baseMapper.updateById(yearDictDO);
    }

    public void addYear(YearDictDO yearDictDO) {
        int count = this.baseMapper.selectCount(new QueryWrapper<YearDictDO>()
                .lambda()
                .eq(YearDictDO::getYear,yearDictDO.getYear()));

        if (count > 0 ){
            throw new HttpException(90001);
        }
        yearDictDO.setStatus("1");
        this.baseMapper.insert(yearDictDO);
    }

}