package com.rongwei.bscommon.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rongwei.bscommon.sys.dao.EquEnergyMeterCenterDosageMonthDao;
import com.rongwei.bscommon.sys.service.EquEnergyMeterCenterDosageMonthService;
import com.rongwei.bsentity.domain.EquEnergyMeterCenterDosageMonthDo;
import com.rongwei.bsentity.domain.EquEnergyMeterDosageMonthDo;
import com.rongwei.rwcommon.utils.SecurityUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class EquEnergyMeterCenterDosageMonthServiceImpl  extends ServiceImpl<EquEnergyMeterCenterDosageMonthDao, EquEnergyMeterCenterDosageMonthDo>
        implements EquEnergyMeterCenterDosageMonthService {

    @Autowired
    EquEnergyMeterCenterDosageMonthDao equEnergyMeterCenterDosageMonthDao;


    @Autowired
    EquEnergyMeterCenterDosageMonthService equEnergyMeterCenterDosageMonthService;

    @Override
    public void calRecordDataToCenterDosageMonth() {
        //1.查询月表中已存在的数据
        List<EquEnergyMeterCenterDosageMonthDo> list = equEnergyMeterCenterDosageMonthDao.queryDaySum();

        List<EquEnergyMeterCenterDosageMonthDo> saveList =new ArrayList<>();
        List<EquEnergyMeterCenterDosageMonthDo> updateList =new ArrayList<>();
        final UpdateWrapper<EquEnergyMeterCenterDosageMonthDo>[] updateWrapper = new UpdateWrapper[]{null};

        list.forEach(v->{
            if (StringUtils.isNotBlank(v.getId())){
                updateList.add(v);
                updateWrapper[0] =new UpdateWrapper<>();
               this.setUpdateWrapper( updateWrapper[0],v);
                equEnergyMeterCenterDosageMonthService.update(v, updateWrapper[0]);
            }else {
                v.setId(SecurityUtil.getUUID());

                saveList.add(v);
            }
        });

        if (!saveList.isEmpty()){
            equEnergyMeterCenterDosageMonthService.saveBatch(saveList);
        }

    };


    public void setUpdateWrapper(UpdateWrapper<EquEnergyMeterCenterDosageMonthDo> updateWrapper, EquEnergyMeterCenterDosageMonthDo equEnergyMeterCenterDosageMonthDo){
        updateWrapper.eq("id",equEnergyMeterCenterDosageMonthDo.getId())
                .set("day1",equEnergyMeterCenterDosageMonthDo.getDay1())
                .set("day2",equEnergyMeterCenterDosageMonthDo.getDay2())
                .set("day3",equEnergyMeterCenterDosageMonthDo.getDay3())
                .set("day4",equEnergyMeterCenterDosageMonthDo.getDay4())
                .set("day5",equEnergyMeterCenterDosageMonthDo.getDay5())
                .set("day6",equEnergyMeterCenterDosageMonthDo.getDay6())
                .set("day7",equEnergyMeterCenterDosageMonthDo.getDay7())
                .set("day8",equEnergyMeterCenterDosageMonthDo.getDay8())
                .set("day9",equEnergyMeterCenterDosageMonthDo.getDay9())
                .set("day10",equEnergyMeterCenterDosageMonthDo.getDay10())
                .set("day11",equEnergyMeterCenterDosageMonthDo.getDay11())
                .set("day12",equEnergyMeterCenterDosageMonthDo.getDay12())
                .set("day13",equEnergyMeterCenterDosageMonthDo.getDay13())
                .set("day14",equEnergyMeterCenterDosageMonthDo.getDay14())
                .set("day15",equEnergyMeterCenterDosageMonthDo.getDay15())
                .set("day16",equEnergyMeterCenterDosageMonthDo.getDay16())
                .set("day17",equEnergyMeterCenterDosageMonthDo.getDay17())
                .set("day18",equEnergyMeterCenterDosageMonthDo.getDay18())
                .set("day19",equEnergyMeterCenterDosageMonthDo.getDay19())
                .set("day20",equEnergyMeterCenterDosageMonthDo.getDay20())
                .set("day21",equEnergyMeterCenterDosageMonthDo.getDay21())
                .set("day22",equEnergyMeterCenterDosageMonthDo.getDay22())
                .set("day23",equEnergyMeterCenterDosageMonthDo.getDay23())
                .set("day24",equEnergyMeterCenterDosageMonthDo.getDay24())
                .set("day25",equEnergyMeterCenterDosageMonthDo.getDay25())
                .set("day26",equEnergyMeterCenterDosageMonthDo.getDay26())
                .set("day27",equEnergyMeterCenterDosageMonthDo.getDay27())
                .set("day28",equEnergyMeterCenterDosageMonthDo.getDay28())
                .set("day29",equEnergyMeterCenterDosageMonthDo.getDay29())
                .set("day30",equEnergyMeterCenterDosageMonthDo.getDay30())
                .set("day31",equEnergyMeterCenterDosageMonthDo.getDay31());
    }
}
