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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nantian.cloud.jly.entity.Memorandum;
import com.nantian.cloud.jly.mapper.EnterpriseInfoMapper;
import com.nantian.cloud.jly.mapper.MemorandumMapper;
import com.nantian.cloud.jly.service.MemorandumService;
import com.nantian.cloud.jly.vo.MemorandumVo;
import com.nantian.cloud.jly.vo.util.Pages;
import com.nantian.sc.cloud.common.data.datascope.DataScope;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service;

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

/**
 * @Description: MemorandumServiceImpl类的描述
 * @Author: wuyuanhao
 * @CreateDate: 2021/5/6 13:49
 * @UpdateUser: wuyuanhao
 * @UpdateDate: 2021/5/6 13:49
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Service("MemorandumService")
public class MemorandumServiceImpl extends ServiceImpl<MemorandumMapper, Memorandum> implements MemorandumService {
    @Resource
    MemorandumMapper memorandumMapper;

    @Override
    public List<MemorandumVo> selectPageAll(Pages page, MemorandumVo memorandum) {
        String code = "";
        if (memorandum.getRegionCode().equals("530000")){
            code = "53";
        } else if (memorandum.getRegionCode().substring(4).equals("00") ){
            code = memorandum.getRegionCode().substring(0,4);
        }else {
            code = memorandum.getRegionCode();
        }
        return baseMapper.selectPageAll(page,memorandum,code,new DataScope());
    }

    @Override
    public List<Integer> count(MemorandumVo memorandum) {
        String code = "";
        if (memorandum.getRegionCode().equals("530000")){
            code = "53";
        } else if (memorandum.getRegionCode().substring(4).equals("00") ){
            code = memorandum.getRegionCode().substring(0,4);
        }else {
            code = memorandum.getRegionCode();
        }
        return baseMapper.count(memorandum,code,new DataScope());
    }

    @Override
    public boolean saveFile(Memorandum memorandum) {
        Memorandum memorandum1=memorandumMapper.selectByEpc(memorandum);
        try {
            if(memorandum1.getId()!=null){
                memorandum.setId(memorandum1.getId());
                return retBool(baseMapper.updateById(memorandum));
            }
        }catch (Exception e){

        }
        return retBool(baseMapper.insert(memorandum));
    }
}
