package com.yx.face.service.impl;

import com.yx.face.boot.restful.ServiceException;
import com.yx.face.dao.AdminTagDao;
import com.yx.face.model.entity.AdminTag;
import com.yx.face.model.vo.AdminTagVO;
import com.yx.face.model.vo.AdminVO;
import com.yx.face.service.AdminService;
import com.yx.face.service.AdminTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description:
 * @ClassName TagServiceImpl
 * @Author WXG
 * @Date 2021/11/9 11:48
 */
@Service
public class AdminTagServiceImpl implements AdminTagService {

    @Resource
    private AdminTagDao adminTagDao;
    @Resource
    private AdminService adminService;

    @Override
    public Integer insert(AdminTag adminTag) {
        AdminVO info = adminService.getInfo();
        Integer type = info.getType().intValue();
        if (type == 1) {
            if (adminTag.getProvinceId() == null) {
                throw new ServiceException("管理员添加标签需要省份Id");
            }
        } else if (type == 2) {
            adminTag.setProvinceId(info.getProvinceId());
        }
        return adminTagDao.insertSelective(adminTag);
    }

    @Override
    public Integer update(AdminTag adminTag) {
        if (adminTag.getId() == null) {
            throw new ServiceException("标签id不能为空");
        }
        return adminTagDao.updateByPrimaryKeySelective(adminTag);
    }

    @Override
    public Integer delete(Integer id) {
        return adminTagDao.deleteByPrimaryKey(id);
    }

    @Override
    public List<AdminTagVO> getList(Integer provinceId) {
        AdminVO info = adminService.getInfo();
        AdminTag adminTag = new AdminTag();
        if (info.getType().intValue() != 1) {
            adminTag.setProvinceId(info.getProvinceId());
        } else {
            if (provinceId != null) {
                adminTag.setProvinceId(provinceId);
            }
        }
        return adminTagDao.getlist(adminTag);
    }

}
