BusinessDictServiceImpl.java 1.87 KB
package com.laowu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.laowu.common.exception.HttpException;
import com.laowu.mapper.BusinessDictMapper;
import com.laowu.model.BusinessDictDO;
import com.laowu.service.BusinessDictService;
import com.laowu.util.ConstantUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 经营范围 服务实现类
 * </p>
 *
 * @author Tuyp
 * @since 2023-02-20
 */
@Service
public class BusinessDictServiceImpl extends ServiceImpl<BusinessDictMapper, BusinessDictDO> implements BusinessDictService {

    public String addBusiness(BusinessDictDO businessDictDO) {

        int count = this.baseMapper.selectCount(new QueryWrapper<BusinessDictDO>()
                .lambda()
                .eq(BusinessDictDO::getBusiness, businessDictDO.getBusiness()));
        if (count > 0) {
            throw new HttpException(60001);
        }

        this.baseMapper.insert(businessDictDO);
        return ConstantUtils.ADD_SUCCESS;
    }

    public String updateBusiness(BusinessDictDO businessDictDO) {
        int count = this.baseMapper.selectCount(new QueryWrapper<BusinessDictDO>()
                .lambda()
                .eq(BusinessDictDO::getBusiness, businessDictDO.getBusiness())
                .ne(BusinessDictDO::getBusiness, businessDictDO.getBusiness()));
        if (count > 0) {
            throw new HttpException(60001);
        }
        this.baseMapper.updateById(businessDictDO);
        return ConstantUtils.ADD_SUCCESS;
    }

    public String deleteBusiness(BusinessDictDO businessDictDO) {
        this.baseMapper.deleteById(businessDictDO.getId());
        return ConstantUtils.DELETE_SUCCESS;
    }

    public List<BusinessDictDO> queryBusiness() {
        return this.baseMapper.selectList(null);
    }
}