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

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rongwe.scentity.domian.AspAnnouncementBoardLargeScreenDo;
import com.rongwe.scentity.domian.AspBoardLargeManualMaintenanceDo;
import com.rongwe.scentity.vo.BaoAnShiDaPingDataVo;
import com.rongwei.rwcommon.utils.SecurityUtil;
import com.rongwei.sfcommon.sys.dao.AspAnnouncementBoardLargeScreenDao;
import com.rongwei.sfcommon.sys.dao.AspBoardLargeManualMaintenanceDao;
import com.rongwei.sfcommon.sys.service.AspAnnouncementBoardLargeScreenService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class AspAnnouncementBoardLargeScreenServiceImpl extends ServiceImpl<AspAnnouncementBoardLargeScreenDao, AspAnnouncementBoardLargeScreenDo> implements AspAnnouncementBoardLargeScreenService {
    private static final Logger logger = LoggerFactory.getLogger(CheckTemplateServiceImpl.class);

    @Autowired
    private AspBoardLargeManualMaintenanceDao aspBoardLargeManualMaintenanceDao;

    @Override
    public void announcement() {
        logger.info("开始定时生成公告栏数据.....");
        //获取表asp_board_large_manual_maintenance数据
        List<AspBoardLargeManualMaintenanceDo> list = aspBoardLargeManualMaintenanceDao.getLastest();
        if(list.size() > 0){
            //遍历 list  根据其中字段tenantid 去asp_announcement_board_large_screen 表中保存数据
            for(AspBoardLargeManualMaintenanceDo item : list){
                AspAnnouncementBoardLargeScreenDo boardLargeScreenDo = new AspAnnouncementBoardLargeScreenDo();
                boardLargeScreenDo.setId(SecurityUtil.getUUID());
                boardLargeScreenDo.setTenantid(item.getTenantid());
                //修改时间 date 类型
                boardLargeScreenDo.setModifydate(new Date());
                //创建时间
                boardLargeScreenDo.setCreatedate(new Date());
                //创建人
                boardLargeScreenDo.setCreateuserid("系统生产");
                //修改人
                boardLargeScreenDo.setModifyuserid("系统生产");
                //手动维护数据
                boardLargeScreenDo.setShengchanzhuangzhi(item.getShengchanzhuangzhi());
                boardLargeScreenDo.setYunxingzhong(item.getYunxingzhong());
                boardLargeScreenDo.setTingchan(item.getTingchan());
                boardLargeScreenDo.setJianxiu(item.getJianxiu());
                boardLargeScreenDo.setGongshishenming(item.getGongshishenming());

                boardLargeScreenDo.setShifoupanshichishengchan(item.getShifoupanshichishengchan());
                boardLargeScreenDo.setShifoupankaidingtingche(item.getShifoupankaidingtingche());
                boardLargeScreenDo.setGuanqucangkudazhongweixianyuanshifouanquan(item.getGuanqucangkudazhongweixianyuanshifouanquan());

                //计算数据
                BaoAnShiDaPingDataVo dataVo = aspBoardLargeManualMaintenanceDao.getDaPingData(item.getTenantid());
                boardLargeScreenDo.setDonghuozuoye(dataVo.getDhzyCount());
                boardLargeScreenDo.setDonghuozuoyeshengqiteshuzuoyeshu(dataVo.getTjdhzyCount());
                boardLargeScreenDo.setDonghuozuoyeyijishu(dataVo.getYjdhzyCount());
                boardLargeScreenDo.setDonghuozuoyeerjishu(dataVo.getEjdhzyCount());
                boardLargeScreenDo.setShuxiankongjianzuoye(dataVo.getSxkjzyCount());
                boardLargeScreenDo.setLinshiyongdianzuoye(dataVo.getLsydzyCount());
                boardLargeScreenDo.setGaochuzuoye(dataVo.getGczyCount());
                boardLargeScreenDo.setDiaozhuangzuoye(dataVo.getDzzyCount());
                boardLargeScreenDo.setMangbanchouduzuoye(dataVo.getMbcdzyCount());
                boardLargeScreenDo.setDongtuzuoye(dataVo.getDtzyCount());
                boardLargeScreenDo.setDuanluzuoye(dataVo.getDlzzCount());
                //生成数据插入到表中
                this.save(boardLargeScreenDo);
            }
        }
    }


    public void announcementByTenantId(String tenantId) {
        logger.info("开始定时生成公告栏数据.....");
        //获取表asp_board_large_manual_maintenance数据
        List<AspBoardLargeManualMaintenanceDo> listByTenantId = aspBoardLargeManualMaintenanceDao.getLastestByTenantId(tenantId);
        if(listByTenantId.size() > 0){
            //遍历 list  根据其中字段tenantid 去asp_announcement_board_large_screen 表中保存数据
            for(AspBoardLargeManualMaintenanceDo item : listByTenantId){
                AspAnnouncementBoardLargeScreenDo boardLargeScreenDo = new AspAnnouncementBoardLargeScreenDo();
                boardLargeScreenDo.setId(SecurityUtil.getUUID());
                boardLargeScreenDo.setTenantid(item.getTenantid());
                //修改时间 date 类型
                boardLargeScreenDo.setModifydate(new Date());
                //创建时间
                boardLargeScreenDo.setCreatedate(new Date());
                //创建人
                boardLargeScreenDo.setCreateuserid("系统生产");
                //修改人
                boardLargeScreenDo.setModifyuserid("系统生产");
                //手动维护数据
                boardLargeScreenDo.setShengchanzhuangzhi(item.getShengchanzhuangzhi());
                boardLargeScreenDo.setYunxingzhong(item.getYunxingzhong());
                boardLargeScreenDo.setTingchan(item.getTingchan());
                boardLargeScreenDo.setJianxiu(item.getJianxiu());
                boardLargeScreenDo.setGongshishenming(item.getGongshishenming());

                boardLargeScreenDo.setShifoupanshichishengchan(item.getShifoupanshichishengchan());
                boardLargeScreenDo.setShifoupankaidingtingche(item.getShifoupankaidingtingche());
                boardLargeScreenDo.setGuanqucangkudazhongweixianyuanshifouanquan(item.getGuanqucangkudazhongweixianyuanshifouanquan());

                //计算数据
                BaoAnShiDaPingDataVo dataVo = aspBoardLargeManualMaintenanceDao.getDaPingData(item.getTenantid());
                boardLargeScreenDo.setDonghuozuoye(dataVo.getDhzyCount());
                boardLargeScreenDo.setDonghuozuoyeshengqiteshuzuoyeshu(dataVo.getTjdhzyCount());
                boardLargeScreenDo.setDonghuozuoyeyijishu(dataVo.getYjdhzyCount());
                boardLargeScreenDo.setDonghuozuoyeerjishu(dataVo.getEjdhzyCount());
                boardLargeScreenDo.setShuxiankongjianzuoye(dataVo.getSxkjzyCount());
                boardLargeScreenDo.setLinshiyongdianzuoye(dataVo.getLsydzyCount());
                boardLargeScreenDo.setGaochuzuoye(dataVo.getGczyCount());
                boardLargeScreenDo.setDiaozhuangzuoye(dataVo.getDzzyCount());
                boardLargeScreenDo.setMangbanchouduzuoye(dataVo.getMbcdzyCount());
                boardLargeScreenDo.setDongtuzuoye(dataVo.getDtzyCount());
                boardLargeScreenDo.setDuanluzuoye(dataVo.getDlzzCount());
                //生成数据插入到表中
                this.save(boardLargeScreenDo);
            }
        }
    }
}
