package com.nantian.cloud.jljc.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nantian.cloud.jljc.entity.TNotice;
import com.nantian.cloud.jljc.mapper.TNoticeMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nantian.cloud.jljc.service.TNoticeService;
import com.nantian.sc.cloud.common.data.datascope.DataScope;
import com.nantian.sc.cloud.common.security.util.SecurityUtils;
import org.springframework.stereotype.Service;

/**
 * 通知表 服务实现类
 *
 * @since 2020-10-23
 */
@Service("tNoticeService")
public class TNoticeServiceImpl extends ServiceImpl<TNoticeMapper, TNotice> implements TNoticeService {


    @Override
    public IPage<TNotice> pageManager(Page page, TNotice tNotice) {
        String userDept = SecurityUtils.getUser().getUserDept();
        if(userDept.contains("0") || userDept.contains("1") || userDept.contains("2")){
            userDept = ""; //超管、节能、计量 可以看所有通知
        }
        return baseMapper.pageManager(page,tNotice,userDept,new DataScope());
    }

    @Override
    public IPage<TNotice> pageCmp(Page page, TNotice tNotice, String epc) {
        return baseMapper.pageCmp(page, tNotice, epc);
    }

    @Override
    public IPage<TNotice> pageGov(Page page, TNotice tNotice, Integer userid, Integer deptId) {
        //return baseMapper.pageGov(page, tNotice, new DataScope());
        String userDept = SecurityUtils.getUser().getUserDept();
        return baseMapper.pageGov(page, tNotice, userid, userDept, deptId);
    }

    @Override
    public TNotice getByIdCmp(Integer id, String epc) {
        return baseMapper.getByIdCmp(id, epc);
    }

    @Override
    public int noCount(String epc) {
        return baseMapper.noCount(epc);
    }

    @Override
    public int noCountGov(Integer userid, Integer deptId) {
        String userDept = SecurityUtils.getUser().getUserDept();
        return baseMapper.noCountGov(userid, userDept, deptId);
    }

    @Override
    public TNotice getByIdGov(Integer id, Integer userid, Integer deptId) {
        String userDept = SecurityUtils.getUser().getUserDept();
        return baseMapper.getByIdGov(id, userid, userDept, deptId);
    }
}
