package com.chinaweal.aiccs.aiceps.annual.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.chinaweal.aiccs.aiccs.abnormal.entity.TREntBaseInfo;
import com.chinaweal.aiccs.aiccs.abnormal.entity.Toincludeabn;
import com.chinaweal.aiccs.aiccs.abnormal.mapper.ToincludeabnMapper;
import com.chinaweal.aiccs.aiceps.annual.entity.AccountPwdLogon;
import com.chinaweal.aiccs.aiceps.annual.mapper.NoAnnualMapper;
import com.chinaweal.aiccs.aiceps.annual.service.NoAnnualService;
import com.chinaweal.youfool.framework.springboot.mybatis.plus.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * <p>
 * 未年报数据 服务实现类
 * </p>
 *
 * @author lwd
 * @since 2021-07-20
 */
@Service
public class NoAnnualServiceImpl extends BaseServiceImpl<NoAnnualMapper,AccountPwdLogon> implements NoAnnualService {

    @Autowired
    private NoAnnualMapper noAnnualMapper;
    @Autowired
    private  ToincludeabnMapper toincludeabnMapper;


    @Override
    public Map<String, Object> insertNoAnnualData(String year) {
        Map<String,Object> resultMap = new HashMap<>();
        Map<String,Object> pram = new HashMap<>();
        pram.put("reporYear",year);
        pram.put("EstDate",(Integer.valueOf(year)+1)+"-01-01");

        //查询企业为未年报数据
        List<TREntBaseInfo> qyList = noAnnualMapper.selectQynoAnnual(pram);
        List<TREntBaseInfo> wgczList = noAnnualMapper.selectWgczAnnual(pram);

        try {
            if (qyList.size()>0){
                for (int i = 0; i < qyList.size(); i++) {
                    Toincludeabn toincludeabn = new Toincludeabn();
                    toincludeabn.setToIncludeId(UUID.randomUUID().toString());
                    //toincludeabn.setUniscid(qyList.get(i).getUscc());
                    toincludeabn.setRegno(qyList.get(i).getRegistno());
                    toincludeabn.setPripid(qyList.get(i).getEntityno());
                    toincludeabn.setIncludeType("1");
                    toincludeabn.setState("0");
                    toincludeabn.setReportYear(year);
                    toincludeabn.setInsertTime(LocalDateTime.now());
                    toincludeabn.setUpdateTime(LocalDateTime.now());
                    toincludeabn.setDataState("0");

                    toincludeabnMapper.insert(toincludeabn);

                }
            }

            if (wgczList.size()>0){
                for (int i = 0; i < wgczList.size(); i++) {
                    Toincludeabn toincludeabn = new Toincludeabn();
                    toincludeabn.setToIncludeId(UUID.randomUUID().toString());
                    //toincludeabn.setUniscid(wgczList.get(i).getUscc());
                    toincludeabn.setRegno(wgczList.get(i).getRegistno());
                    toincludeabn.setInsertTime(LocalDateTime.now());
                    toincludeabn.setUpdateTime(LocalDateTime.now());
                    toincludeabn.setPripid(wgczList.get(i).getEntityno());
                    toincludeabn.setIncludeType("1");
                    toincludeabn.setState("0");
                    toincludeabn.setReportYear(year);

                    toincludeabnMapper.insert(toincludeabn);

                }
            }
        }catch (Exception e){
            e.printStackTrace();
            System.out.println(e);
            resultMap.put("flag","error");
        }

        resultMap.put("flag","sussess");
        return resultMap;
    }

    @Override
    public List<AccountPwdLogon> selectAnnualAccountByPripid(String spripid) {
        return noAnnualMapper.selectAnnualAccountByPripid(spripid);
    }
}
