package com.cirle.scientific.service.impl;/*
 *24901
 *2023/1/4
 *10:01
 */

import com.cirle.scientific.dao.QkjSuperviseAppDao;
import com.cirle.scientific.dao.QkjSuperviseResultDao;
import com.cirle.scientific.po.QkjSuperviseApp;
import com.cirle.scientific.po.QkjSuperviseResultApp;
import com.cirle.scientific.service.SuperviseAppService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;

/**
 * @author 24901
 */
@Service
@Slf4j
public class SuperviseAppServiceImpl implements SuperviseAppService {

    private QkjSuperviseAppDao qkjSuperviseAppDao;

    private QkjSuperviseResultDao qkjSuperviseResultDao;

    @Autowired
    public void setQkjSuperviseResultDao(QkjSuperviseResultDao qkjSuperviseResultDao) {
        this.qkjSuperviseResultDao = qkjSuperviseResultDao;
    }

    @Autowired
    public void setQkjSuperviseAppDao(QkjSuperviseAppDao qkjSuperviseAppDao) {
        this.qkjSuperviseAppDao = qkjSuperviseAppDao;
    }

    @Override
    public LinkedList<Map<String,Object>> findSuperviseResult(String memCard, Integer type) {
        LinkedList<Map<String,Object>> data = new LinkedList<>();
        try {
            Calendar instance = Calendar.getInstance();
            //获取当前的年
            int year = instance.get(Calendar.YEAR);
            LinkedList<QkjSuperviseApp> resultFile = qkjSuperviseAppDao.findResultFileByYearAndTypeAndMemCard(memCard, year, type);
            for (QkjSuperviseApp qkjSuperviseApp : resultFile) {
                Map<String,Object> map = new HashMap<>();
                //如果是线下督导
                if(type == 1){
                    if(qkjSuperviseApp.getMonth() <= 3){
                        map.put("month", 1);
                    }else if(qkjSuperviseApp.getMonth() > 3 && qkjSuperviseApp.getMonth() <= 6){
                        map.put("month", 2);
                    }else if(qkjSuperviseApp.getMonth() > 6 && qkjSuperviseApp.getMonth() <= 9){
                        map.put("month", 3);
                    }else if(qkjSuperviseApp.getMonth() > 9 && qkjSuperviseApp.getMonth() <= 12){
                        map.put("month", 4);
                    }
                }else{
                    map.put("month", qkjSuperviseApp.getMonth());
                }
                List<QkjSuperviseResultApp> qkjSuperviseResultApps = qkjSuperviseResultDao.selectAllByObjId(qkjSuperviseApp.getId().intValue());
                List<String> list = new ArrayList<>();
                for (QkjSuperviseResultApp qkjSuperviseResultApp : qkjSuperviseResultApps) {
                    String criteria = null;
                    if(null != qkjSuperviseResultApp.getIsPass() && qkjSuperviseResultApp.getIsPass() == 1){
                        criteria = qkjSuperviseResultApp.getCriteria()+": "+"是";
                    }else if(null == qkjSuperviseResultApp.getIsPass() || qkjSuperviseResultApp.getIsPass() == 0){
                        criteria = qkjSuperviseResultApp.getCriteria()+": "+"否";
                    }
                    list.add(criteria);
                }
                map.put("result", list);
                data.add(map);
            }
        }catch (Exception e){
            log.info("接口/app/Supervise/findSupervise出错 e->{e}", e);
        }
        return data;
    }
}
