package org.jeecg.modules.fbsQualityQualificationRate.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.modules.fbsQualityQualificationRate.entity.FbsQualityQualificationRate;
import org.jeecg.modules.fbsQualityQualificationRate.mapper.FbsQualityQualificationRateMapper;
import org.jeecg.modules.fbsQualityQualificationRate.service.IFbsQualityQualificationRateService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 品质看板合格率统计表格数据
 * @author： jeecg-boot
 * @date：   2020-11-03
 * @version： V1.0
 */
@Service
public class FbsQualityQualificationRateServiceImpl extends ServiceImpl<FbsQualityQualificationRateMapper, FbsQualityQualificationRate> implements IFbsQualityQualificationRateService {

    @Resource
    IFbsQualityQualificationRateService iFbsQualityQualificationRateService;

    @Resource
    FbsQualityQualificationRateMapper fbsQualityQualificationRateMapper;

    @Override
    public int addData(FbsQualityQualificationRate fbsQualityQualificationRate) {
        //查询未删除的
        LambdaQueryWrapper<FbsQualityQualificationRate> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(FbsQualityQualificationRate::getDelFlag,"0");
        //删除状态
        FbsQualityQualificationRate fbsQualityQualificationRateUpdate=new FbsQualityQualificationRate();
        fbsQualityQualificationRateUpdate.setDelFlag("1");
        //修改
        iFbsQualityQualificationRateService.update(fbsQualityQualificationRateUpdate,lambdaQueryWrapper);
        //保存新记录
        fbsQualityQualificationRate.setId(null);
        int result=fbsQualityQualificationRateMapper.insert(fbsQualityQualificationRate);
        return result;
    }

    @Override
    public List<Map<String, Object>> getLastSixMonthQualityTargetCompareWeb() {
        List<Map<String,Object>> mapList=new ArrayList<>();

        LambdaQueryWrapper<FbsQualityQualificationRate> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(FbsQualityQualificationRate::getDelFlag,'0');
        List<FbsQualityQualificationRate> list=fbsQualityQualificationRateMapper.selectList(lambdaQueryWrapper);
        if(list!=null&&list.size()>0){
            FbsQualityQualificationRate fbsQualityQualificationRate=list.get(0);
            Map<String,Object> map=new HashMap<>();
            map.put("month",fbsQualityQualificationRate.getOneMonthName());
            map.put("real",fbsQualityQualificationRate.getOneMonth());
            map.put("target",fbsQualityQualificationRate.getScaleMark());
            mapList.add(map);
            Map<String,Object> map2=new HashMap<>();
            map2.put("month",fbsQualityQualificationRate.getTwoMonthName());
            map2.put("real",fbsQualityQualificationRate.getTwoMonth());
            map2.put("target",fbsQualityQualificationRate.getScaleMark());
            mapList.add(map2);
            Map<String,Object> map3=new HashMap<>();
            map3.put("month",fbsQualityQualificationRate.getThreeMonthName());
            map3.put("real",fbsQualityQualificationRate.getThreeMonth());
            map3.put("target",fbsQualityQualificationRate.getScaleMark());
            mapList.add(map3);
            Map<String,Object> map4=new HashMap<>();
            map4.put("month",fbsQualityQualificationRate.getFourMonthName());
            map4.put("real",fbsQualityQualificationRate.getFourMonth());
            map4.put("target",fbsQualityQualificationRate.getScaleMark());
            mapList.add(map4);
            Map<String,Object> map5=new HashMap<>();
            map5.put("month",fbsQualityQualificationRate.getFiveMonthName());
            map5.put("real",fbsQualityQualificationRate.getFiveMonth());
            map5.put("target",fbsQualityQualificationRate.getScaleMark());
            mapList.add(map5);
            Map<String,Object> map6=new HashMap<>();
            map6.put("month",fbsQualityQualificationRate.getSixMonthName());
            map6.put("real",fbsQualityQualificationRate.getSixMonth());
            map6.put("target",fbsQualityQualificationRate.getScaleMark());
            mapList.add(map6);
            Map<String,Object> map7=new HashMap<>();
            map7.put("month",fbsQualityQualificationRate.getSevenMonthName());
            map7.put("real",fbsQualityQualificationRate.getSevenMonth());
            map7.put("target",fbsQualityQualificationRate.getScaleMark());
            mapList.add(map7);
            Map<String,Object> map8=new HashMap<>();
            map8.put("month",fbsQualityQualificationRate.getEightMonthName());
            map8.put("real",fbsQualityQualificationRate.getEightMonth());
            map8.put("target",fbsQualityQualificationRate.getScaleMark());
            mapList.add(map8);
            Map<String,Object> map9=new HashMap<>();
            map9.put("month",fbsQualityQualificationRate.getNineMonthName());
            map9.put("real",fbsQualityQualificationRate.getNineMonth());
            map9.put("target",fbsQualityQualificationRate.getScaleMark());
            mapList.add(map9);
            Map<String,Object> map10=new HashMap<>();
            map10.put("month",fbsQualityQualificationRate.getTenMonthName());
            map10.put("real",fbsQualityQualificationRate.getTenMonth());
            map10.put("target",fbsQualityQualificationRate.getScaleMark());
            mapList.add(map10);
            Map<String,Object> map11=new HashMap<>();
            map11.put("month",fbsQualityQualificationRate.getElevenMonthName());
            map11.put("real",fbsQualityQualificationRate.getElevenMonth());
            map11.put("target",fbsQualityQualificationRate.getScaleMark());
            mapList.add(map11);
            Map<String,Object> map12=new HashMap<>();
            map12.put("month",fbsQualityQualificationRate.getTwelveMonthName());
            map12.put("real",fbsQualityQualificationRate.getTwelveMonth());
            map12.put("target",fbsQualityQualificationRate.getScaleMark());
            mapList.add(map12);

        }
        return mapList;
    }
}
