/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.work.service.report;

import com.jeeplus.common.oss.OSSClientUtil;
import com.jeeplus.common.persistence.Page;
import com.jeeplus.common.service.CrudService;
import com.jeeplus.common.utils.JPushClientUtil;
import com.jeeplus.common.utils.MenuStatusEnum;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.oa.dao.LeaveDao;
import com.jeeplus.modules.oa.entity.Leave;
import com.jeeplus.modules.oa.entity.OaAttendance;
import com.jeeplus.modules.oa.service.LeaveService;
import com.jeeplus.modules.oa.service.OaAttendanceService;
import com.jeeplus.modules.oa_evection.entity.oa_evection.OaEvection;
import com.jeeplus.modules.oa_evection.service.oa_evection.OaEvectionService;
import com.jeeplus.modules.pushinfo.entity.Pushinfo;
import com.jeeplus.modules.pushinfo.service.PushinfoService;
import com.jeeplus.modules.sys.dao.WorkattachmentDao;
import com.jeeplus.modules.sys.entity.User;
import com.jeeplus.modules.sys.entity.Workattachment;
import com.jeeplus.modules.sys.service.WorkattachmentService;
import com.jeeplus.modules.sys.utils.UserUtils;
import com.jeeplus.modules.work.dao.report.WorkReportDao;
import com.jeeplus.modules.work.dao.report.WorkReportRecordDao;
import com.jeeplus.modules.work.entity.report.WorkReport;
import com.jeeplus.modules.work.entity.report.WorkReportRecord;
import com.jeeplus.modules.workcalendar.entity.CalendarCountEntity;
import com.jeeplus.modules.workclientinfo.entity.WorkClientAttachment;
import com.jeeplus.modules.workgoout.entity.GoOut;
import com.jeeplus.modules.workgoout.service.GoOutService;
import com.jeeplus.modules.workoutsignin.entity.WorkOutSignIn;
import com.jeeplus.modules.workoutsignin.service.WorkOutSignInService;
import com.jeeplus.modules.workovertimeform.entity.WorkOvertimeForm;
import com.jeeplus.modules.workovertimeform.service.WorkOvertimeFormService;
import com.jeeplus.modules.workreimbursement.utils.VarStr;
import com.jeeplus.modules.worksealform.entity.WorkSealForm;
import com.jeeplus.modules.worksealform.service.WorkSealFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 工作报告Service
 * @author 许凯
 * @version 2017-04-21
 */
@Service
@Transactional(readOnly = true)
public class WorkReportService extends CrudService<WorkReportDao, WorkReport> {
	@Autowired
	private WorkReportRecordDao workReportRecordDao;
	@Autowired
	private WorkReportDao workReportDao;
	@Autowired
    private PushinfoService pushinfoService;

	@Autowired
	private WorkOutSignInService workOutSignInService;
	@Autowired
	private OaAttendanceService oaAttendanceService;
	@Autowired
	private LeaveService leaveService;
	@Autowired
	private WorkSealFormService workSealFormService;
	@Autowired
	private OaEvectionService oaEvectionService;
	@Autowired
	private WorkOvertimeFormService workOvertimeFormService;
	@Autowired
	private GoOutService goOutService;
	@Autowired
	private WorkattachmentService workattachmentService;
	public WorkReport get(String id) {
		WorkReport workReport = super.get(id);
		workReport.setWorkReportRecordListUser(workReportRecordDao.findList(new WorkReportRecord(workReport)));
		List<Workattachment> attachmentList = workattachmentService.getListByAttachmentIdAndFlag(id,"77");
		workReport.setWorkAttachments(attachmentList);

		return workReport;
	}
	public Page<WorkReport> findPage(Page<WorkReport> page, WorkReport workReport) {
		return super.findPage(page, workReport);
	}
	public  Page<WorkReport> findPageByUser(Page<WorkReport> page , WorkReport workReport){
		workReport.setPage(page);
		page.setList(dao.findListByUser(workReport));
		return page ;
	}
	public List<WorkReport> findList(WorkReport workReport) {
		return super.findList(workReport);
	}

    public List<WorkReport> findGetList(WorkReport workReport) {
        return workReportDao.findGetList(workReport);
    }

    public  List<WorkReport> findListByDate(WorkReport workReport){
        return super.findList(workReport);
    }
	
	public Page<WorkReport> findGetPage(Page<WorkReport> page, WorkReport workReport) {
		workReport.setPage(page);
		page.setList(workReportDao.findGetList(workReport));
		return page;
	}
	//优化版，供PC端使用
	public List<WorkReport> findByCompany2(WorkReport workReport,String date){
    	return workReportDao.findByCompany2(workReport,date);
	}
	public List getCreateDateList(String companyId,String date) {
		Map<String,String> map = new HashMap<String,String>();
		map.put("companyId",companyId);
		map.put("date",date);
		return workReportDao.getCreateDateList(map);
	}
	public List getCreateDateList1(String time) {
		Map<String,String> map = new HashMap<String,String>();
		map.put("userId",UserUtils.getUser().getId());
		map.put("time",time);
		return workReportDao.getCreateDateList1(map);
	}
	public List<WorkReport> findByCompany1(String time){
		Map<String,String> map = new HashMap<String,String>();
		map.put("userId",UserUtils.getUser().getId());
		map.put("time",time);
		return workReportDao.findByCompany1(map);
	}

	public List getCreateDateListAll(String time) {
		WorkReport w=new WorkReport();
		Map<String,String> map = new HashMap<String,String>();
		map.put("sqlStr",dataScopeFilter(w.getCurrentUser(), "o", "u", "s", MenuStatusEnum.WORK_REPORT.getValue()));
		map.put("time",time);
		return workReportDao.getCreateDateListAll(map);
	}
	public List<WorkReport> findByCompanyAll(String time){
		Map<String,String> map = new HashMap<String,String>();
		WorkReport w=new WorkReport();
		map.put("sqlStr",dataScopeFilter(w.getCurrentUser(), "o", "u", "s", MenuStatusEnum.WORK_REPORT.getValue()));
		map.put("time",time);
		return workReportDao.findByCompanyAll(map);
	}
    public List<WorkReport> findByCompany(WorkReport workReport) {
        return workReportDao.findByCompany(workReport);
    }

    public List<WorkReport> findReportUserByCompany(WorkReport workReport) {
        return workReportDao.findReportUserByCompany(workReport);
    }
	
	public Page<WorkReport> findOutPage(Page<WorkReport> page, WorkReport workReport) {
		workReport.setPage(page);
		page.setList(workReportDao.findOutList(workReport));
		return page;
	}

    public WorkReport findNewId() {
        WorkReport workReport = workReportDao.findNewId();
        workReport.setWorkReportRecordListUser(workReportRecordDao.findList(new WorkReportRecord(workReport)));
        return workReport;
    }
	
	@Transactional(readOnly = false)
	public void save(WorkReport workReport) {
		if (StringUtils.isBlank(workReport.getOfficeId())) {
			workReport.setOfficeId(UserUtils.getSelectOffice().getId());
		}
		super.save(workReport);
		if ( workReport.getWorkAttachments()!=null && workReport.getWorkAttachments().size()!=0){
			//附件信息
			for (Workattachment workattachment : workReport.getWorkAttachments()) {
				if (workattachment.getId() == null) {
					continue;
				}
				if (WorkClientAttachment.DEL_FLAG_NORMAL.equals(workattachment.getDelFlag())) {
					workattachment.setAttachmentFlag("77");
					workattachment.setAttachmentId(workReport.getId());
					workattachment.setAttachmentUser(UserUtils.getUser().getId());
					if (StringUtils.isBlank(workattachment.getId()) || "null".equals(workattachment.getId())) {
						workattachment.preInsert();
						workattachmentService.insert(workattachment);
					} else {
						workattachment.preUpdate();
						workattachmentService.update(workattachment);
					}
				} else {
					workattachmentService.delete(workattachment);
				}
			}
		}

		/*if(workReport!=null && StringUtils.isNotBlank(workReport.getId()) &&files!=null){
			if(files.length>0){
				OSSClientUtil ossClientUtil = new OSSClientUtil();
				for (int i = 0; i < files.length; i++) {
					MultipartFile file = files[i];
					if(!file.isEmpty()&&file.getSize()>0){
						String fileName = file.getOriginalFilename();
						String fileType = fileName.substring(fileName.lastIndexOf("."));
						String url = ossClientUtil.uploadFile2OSS(file,"report");
						Workattachment workattachment = new Workattachment();
						workattachment.setUrl(url);
						workattachment.setType(fileType);
						workattachment.setAttachmentName(fileName);
						workattachment.setAttachmentUser(UserUtils.getUser().getId());
						workattachment.setAttachmentId(workReport.getId());
						workattachment.setCompanyId(UserUtils.getSelectCompany().getId());
						workattachment.setAttachmentFlag("77");
						workattachmentService.save(workattachment);
					}
				}
			}
		}*/

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String date = sdf.format(new Date());
		String content = workReport.getThisContent();

		// 更新发送接受人记录
		workReportRecordDao.deleteByReportId(workReport.getId());
		if (workReport.getWorkReportRecordListUser().size()>0){
			workReportRecordDao.insertAllUser(workReport.getWorkReportRecordListUser());
		}
		if (workReport.getWorkReportRecordListGroup().size()>0){
			workReportRecordDao.insertAllGroup(workReport.getWorkReportRecordListGroup());
		}

		String state = "1";
        String ids = workReport.getWorkReportRecordIdsUser();
        Map extras = new HashMap();
        extras.put("type","3003");
        extras.put("id",workReport.getId());


        List aliases = new ArrayList();
        if(ids != null && ids.length()!=0){
            String[] aliase = ids.split(",");
            for(String a : aliase){
                aliases.add(a);
            }
        }

        if(StringUtils.isNotBlank(workReport.getStatus()) && "1".equals(workReport.getStatus())){

			Pushinfo pushinfo = new Pushinfo();
			pushinfo.setCompanyId(workReport.getCompanyId());
			pushinfo.setMobile("ios,android");
			pushinfo.setCurrentUser(UserUtils.getUser());
			pushinfo.setRemarks(content);
			pushinfo.setUserId(UserUtils.getUser().getId());
			pushinfo.setType("3003");
			pushinfo.setPushId(workReport.getId());
			pushinfo.setTitle("工作报告");
			String status = workReport.getUpdateBy().getName() +"  "+date;
			pushinfo.setStatus(status);
			pushinfo.setContent(workReport.getThisContent());
			pushinfo.setPushUserId(ids);
			pushinfo.setParentType("singleWorkReport");
			if (workReport.getThisFiles()!=null &&workReport.getThisFiles().length()>0){
				pushinfo.setStatus(workReport.getThisFiles());
			}
			pushinfoService.save(pushinfo);

			JPushClientUtil.sendNotificationToAliases(workReport.getThisFiles(), content, extras, aliases);
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(WorkReport workReport) {
		super.delete(workReport);
		workReportRecordDao.delete(new WorkReportRecord(workReport));
	}

    /**
     * 更新阅读状态
     */
    @Transactional(readOnly = false)
    public void updateReadFlag(WorkReport workReport) {
        WorkReportRecord workReportRecord = new WorkReportRecord(workReport);
        workReportRecord.setUser(workReportRecord.getCurrentUser());
        workReportRecord.setReadDate(new Date());
        workReportRecord.setReadFlag("1");
        workReportRecordDao.update(workReportRecord);
    }

    //APP端使用，一次上传一个
	@Transactional(readOnly = false)
	public String uploadFile(OSSClientUtil ossClientUtil, MultipartFile file, WorkReport workReport, String flag) {
		String fileName = file.getOriginalFilename();
		String fileType = fileName.substring(fileName.lastIndexOf("."));
		String url = ossClientUtil.uploadFile2OSS(file,"report");
		Workattachment workattachment = new Workattachment();
		workattachment.setUrl(url);
		workattachment.setType(fileType);
		workattachment.setAttachmentName(fileName);
		workattachment.setAttachmentUser(UserUtils.getUser().getId());
		workattachment.setAttachmentId(workReport.getId());
		workattachment.setCompanyId(UserUtils.getSelectCompany().getId());
		workattachment.setAttachmentFlag(flag);
		workattachmentService.save(workattachment);
		return url;
	}

	//删除附件
	@Transactional(readOnly = false)
	public void delFile(String attaId, String attachmentUrl) {
		try {
			Workattachment workattachment = new Workattachment();
			if(StringUtils.isNotBlank(attaId)){
				workattachment.setId(attaId);
				workattachmentService.delete(workattachment);
			}
			if(StringUtils.isNotBlank(attachmentUrl)){
				workattachment.setUrl(attachmentUrl);
				workattachmentService.deleteFileFromAliyun(workattachment,workattachment==null?attachmentUrl:workattachment.getUrl());
			}
		}catch (Exception e){
			e.printStackTrace();
		}
	}
	public List<WorkReport> findByManage(Map<String,Object> map) {
		return workReportDao.findByManage(map);
	}
	public List<WorkReport> findByCompanySelf(Map<String,Object> map) {
		return workReportDao.findByCompanySelf(map);
	}
	/**
	 *
	 */
/*	@Transactional(readOnly = false)
	public List<WorkReport> reportlist(String start) {
		Map<String,Object> map=new HashMap<>();
		map.put("time",start);
		map.put("userId",UserUtils.getUser().getId());
		List<WorkReport> reportlist= workReportDao.reportlist(map);
		return reportlist;
	}*/
	public Map<String,Object> getManageCalendarByDateAll(String dateStr,CalendarCountEntity c) {
		Map<String,Object> map=new HashMap<>();
		CalendarCountEntity cc=new CalendarCountEntity();
		map.put("time",dateStr);
		map.put("sqlStr",dataScopeFilter(cc.getCurrentUser(), "o", "u", "s", MenuStatusEnum.WORK_REPORT.getValue()));
		map.put("startDate",c.getStartDate());
		map.put("endDate",c.getEndDate());
		List<WorkReport> workReportList=new ArrayList<>();
		List<WorkOutSignIn> workOutList=new ArrayList<>();
		List<OaAttendance> oaAttenList=new ArrayList<>();
		List<WorkSealForm> workSealList=new ArrayList<>();
		List<Leave> leaveList =new ArrayList<>();
		List<OaEvection> oaEvectionList=new ArrayList<>();
		List<WorkOvertimeForm> workOvertimeFormList=new ArrayList<>();
		List<GoOut> goOutList=new ArrayList<>();
		if(c.getType()!=null&&!"".equals(c.getType())){
			if("1".equals(c.getType())){
				workReportList = this.findByManage(map);
			}else if("2".equals(c.getType())){
				leaveList = leaveService.findByManage(map);
			}
		}else{
			 workReportList = this.findByManage(map);
			 workOutList = workOutSignInService.findByManage(map);
			 oaAttenList = oaAttendanceService.findByManage(map);
			 workSealList = workSealFormService.findByManage(map);
			 leaveList = leaveService.findByManage(map);
			 oaEvectionList = oaEvectionService.findByManage(map);
			 workOvertimeFormList = workOvertimeFormService.findByManage(map);
			 goOutList = goOutService.findByManage(map);
		}

		Map<String,Object> map1 = new HashMap<String,Object>();
		map1.put("workReportList",workReportList);
		map1.put("workOutList",workOutList);
		map1.put("oaAttenList",oaAttenList);
		map1.put("workSealList",workSealList);
		map1.put("leaveList",leaveList);
		map1.put("oaEvectionList",oaEvectionList);
		map1.put("workOvertimeFormList",workOvertimeFormList);
		map1.put("goOutList",goOutList);
		return  map1;
	}

	public Map<String,Object> getManageCalendarByDate(String dateStr,CalendarCountEntity c) {
		Map<String,Object> map=new HashMap<>();
		map.put("time",dateStr);
		map.put("userId",UserUtils.getUser().getId());
		map.put("startDate",c.getStartDate());
		map.put("endDate",c.getEndDate());
		List<WorkReport> workReportList=new ArrayList<>();
		List<WorkOutSignIn> workOutList=new ArrayList<>();
		List<OaAttendance> oaAttenList=new ArrayList<>();
		List<WorkSealForm> workSealList=new ArrayList<>();
		List<Leave> leaveList =new ArrayList<>();
		List<OaEvection> oaEvectionList=new ArrayList<>();
		List<WorkOvertimeForm> workOvertimeFormList=new ArrayList<>();
		List<GoOut> goOutList=new ArrayList<>();

		if(c.getType()!=null&&!"".equals(c.getType())){
			if("1".equals(c.getType())){
				workReportList = this.findByCompanySelf(map);
			}else if("2".equals(c.getType())){
				leaveList = leaveService.findByCompanySelf(map);
			}
		}else{
			workReportList = this.findByCompanySelf(map);
			workOutList = workOutSignInService.findByCompanySelf(map);
			oaAttenList = oaAttendanceService.findByCompanySelf(map);
			workSealList = workSealFormService.findByCompanySelf(map);
			leaveList = leaveService.findByCompanySelf(map);
			oaEvectionList = oaEvectionService.findByCompanySelf(map);
			workOvertimeFormList = workOvertimeFormService.findByCompanySelf(map);
			goOutList = goOutService.findByCompanySelf(map);
		}
		Map<String,Object> map1 = new HashMap<String,Object>();
		map1.put("workReportList",workReportList);
		map1.put("workOutList",workOutList);
		map1.put("oaAttenList",oaAttenList);
		map1.put("workSealList",workSealList);
		map1.put("leaveList",leaveList);
		map1.put("oaEvectionList",oaEvectionList);
		map1.put("workOvertimeFormList",workOvertimeFormList);
		map1.put("goOutList",goOutList);
		return  map1;
	}
	/**
	 *
	 */
/*	@Transactional(readOnly = false)
	public List<WorkReport> reportlistAll(String start) {
		Map<String,Object> map=new HashMap<>();
		map.put("time",start);
		map.put("sqlStr",dataScopeFilter(UserUtils.getUser(), "o", "u", "s"));
		List<WorkReport> reportlist= workReportDao.reportlistAll(map);
		return reportlist;
	}*/

	public List getReportUserList(String dateStr,CalendarCountEntity c){
		Map<String,Object> maps = getManageCalendarByDate(dateStr,c);
		List reportList =new ArrayList();
		List<WorkReport> workReportList = (List<WorkReport>)maps.get("workReportList");
		List<WorkOutSignIn> workOutList = (List<WorkOutSignIn>)maps.get("workOutList");
		List<OaAttendance> oaAttenList = (List<OaAttendance>)maps.get("oaAttenList");
		List<WorkSealForm> workSealList = (List<WorkSealForm>)maps.get("workSealList");
		List<Leave> leaveList = (List<Leave>)maps.get("leaveList");
		List<OaEvection> oaEvectionList = (List<OaEvection>)maps.get("oaEvectionList");
		List<WorkOvertimeForm> workOvertimeFormList = (List<WorkOvertimeForm>)maps.get("workOvertimeFormList");
		List<GoOut> goOutList = (List<GoOut>)maps.get("goOutList");

		List<Map> mapList1 = new ArrayList<>();
		List<Map> mapList2 = new ArrayList<>();
		List<Map> mapList3 = new ArrayList<>();
		List<Map> mapList4 = new ArrayList<>();
		List<Map> mapList5 = new ArrayList<>();
		List<Map> mapList6 = new ArrayList<>();
		List<Map> mapList7 = new ArrayList<>();
		List<Map> mapList8 = new ArrayList<>();
		List<Map> mapList9 = new ArrayList<>();
		List<Map> mapList10 = new ArrayList<>();
		List<Map> mapList11 = new ArrayList<>();
		Map<String,Object> totalMap1 = new HashMap<String,Object>();
		Map<String,Object> totalMap2 = new HashMap<String,Object>();
		Map<String,Object> totalMap3 = new HashMap<String,Object>();
		Map<String,Object> totalMap4 = new HashMap<String,Object>();

		Map<String,Object> map3 = new HashMap<String,Object>();
		Map<String,Object> map4 = new HashMap<String,Object>();
		if(workReportList!=null && workReportList.size()!=0) {
			for (WorkReport w : workReportList) {
				Map map = new HashMap();
				User u = UserUtils.get(w.getCreateBy().getId());
				if (u!=null) {
					map.put("userId", u.getId());
					map.put("createDate",w.getCreateDate());
					map.put("workReportBean",w);
					mapList1.add(map);
				}
			}
			map3.put("workReport",mapList1);
		}
		totalMap1.put("workReports",map3);
		if(workOutList!=null && workOutList.size()!=0) {
			for (WorkOutSignIn w : workOutList) {
				Map map = new HashMap();
				User u = UserUtils.get(w.getCreateBy().getId());
				if (u!=null) {
					map.put("userId", u.getId());
					map.put("createDate",w.getCreateDate());
					map.put("workOutSignInBean",w);
					mapList2.add(map);
				}
			}
			map4.put("workOutSignIn", mapList2);
		}
		totalMap2.put("workOutSignIns",map4);

		Map<String,Object> map1 = new HashMap<String,Object>();
		if(oaAttenList!=null && oaAttenList.size()!=0) {
			SimpleDateFormat sdf3 = new SimpleDateFormat("HHmmss");
			for (OaAttendance o : oaAttenList) {
				Map map = new HashMap();
				User u = UserUtils.get(o.getCreateBy().getId());
				if (u!=null){
					if (o.getStartTime() != null && !"".equals(o.getStartTime())) {
						String ruleStart = o.getRule().getStartTime().replaceAll(":","")+"00";
						Integer start = Integer.parseInt(sdf3.format(o.getStartTime()));
						int morning = Integer.parseInt(ruleStart);
						if (start > morning) {
							map.put("userId", u.getId());
							map.put("createDate",o.getCreateDate());
							map.put("oaAttendanceBean",o);
							mapList3.add(map);
						} else {
							map.put("userId", u.getId());
							map.put("createDate",o.getCreateDate());
							map.put("oaAttendanceBean",o);
							mapList4.add(map);
						}
					}
					if (o.getEndTime() != null && !"".equals(o.getEndTime())) {
						String ruleEnd = o.getRule().getEndTime().replaceAll(":","")+"00";
						Integer end = Integer.parseInt(sdf3.format(o.getEndTime()));
						int night = Integer.parseInt(ruleEnd);
						if (end >= night) {
							map.put("userId", u.getId());
							map.put("createDate",o.getCreateDate());
							map.put("oaAttendanceBean",o);
							mapList5.add(map);
						} else {
							map.put("userId", u.getId());
							map.put("createDate",o.getCreateDate());
							map.put("oaAttendanceBean",o);
							mapList6.add(map);
						}
					}
				}
			}
			if(mapList3!=null && mapList3.size()!=0){ map1.put("late",mapList3); }

			if(mapList4!=null && mapList4.size()!=0){ map1.put("onDuty",mapList4);}
			if(mapList5!=null && mapList5.size()!=0){  map1.put("offDut",mapList5);}
			if(mapList6!=null && mapList6.size()!=0){ map1.put("leaveEarly",mapList6);}

		}
		totalMap3.put("attendances",map1);


		Map<String,Object> map2 = new HashMap<String,Object>();
		if(workSealList!=null && workSealList.size()!=0) {
			for (WorkSealForm w : workSealList) {
				Map map = new HashMap();
				User u = UserUtils.get(w.getCreateBy().getId());
				if (u!=null) {
					map.put("userId", u.getId());
					map.put("createDate",w.getCreateDate());
					map.put("workSealFormBean",w);
					mapList7.add(map);
				}
			}
			map2.put("workSealFrom",mapList7);
		}
		if(leaveList!=null && leaveList.size()!=0) {
			for (Leave w : leaveList) {
				Map map = new HashMap();
				User u = UserUtils.get(w.getCreateBy().getId());
				if (u!=null) {
					map.put("userId", u.getId());
					map.put("createDate",w.getCreateDate());
					map.put("leaveBean",w);
					mapList8.add(map);
				}
			}
			map2.put("leave",mapList8);
		}
		if(oaEvectionList!=null && oaEvectionList.size()!=0) {
			for (OaEvection w : oaEvectionList) {
				Map map = new HashMap();
				User u = UserUtils.get(w.getCreateBy().getId());
				if (u!=null) {
					map.put("userId", u.getId());
					map.put("createDate",w.getCreateDate());
					map.put("oaEvectionBean",w);
					mapList9.add(map);
				}
			}
			map2.put("oaEvection",mapList9);
		}
		if(workOvertimeFormList!=null && workOvertimeFormList.size()!=0) {
			for (WorkOvertimeForm w : workOvertimeFormList) {
				Map map = new HashMap();
				User u = UserUtils.get(w.getCreateBy().getId());
				if (u!=null) {
					map.put("userId", u.getId());
					map.put("createDate",w.getCreateDate());
					map.put("workOvertimeFormBean",w);
					mapList10.add(map);
				}
			}
			map2.put("workOvertimeForm",mapList10);
		}
		if(goOutList!=null && goOutList.size()!=0) {
			for (GoOut goOut : goOutList) {
				Map map = new HashMap();
				User u = UserUtils.get(goOut.getCreateBy().getId());
				if (u!=null) {
					map.put("userId", u.getId());
					map.put("createDate",goOut.getCreateDate());
					map.put("goOutBean",goOut);
					mapList11.add(map);
				}
			}
			map2.put("workGoOut",mapList11);
		}
		totalMap4.put("audits",map2);
		reportList.add(totalMap1);
		reportList.add(totalMap2);
		reportList.add(totalMap3);
		reportList.add(totalMap4);
		return reportList;
	}

	public List getReportUserListAll(String dateStr,CalendarCountEntity c){
		Map<String,Object> maps = getManageCalendarByDateAll(dateStr,c);
		List reportList =new ArrayList();

		List<WorkReport> workReportList = (List<WorkReport>)maps.get("workReportList");
		List<WorkOutSignIn> workOutList = (List<WorkOutSignIn>)maps.get("workOutList");
		List<OaAttendance> oaAttenList = (List<OaAttendance>)maps.get("oaAttenList");
		List<WorkSealForm> workSealList = (List<WorkSealForm>)maps.get("workSealList");
		List<Leave> leaveList = (List<Leave>)maps.get("leaveList");
		List<OaEvection> oaEvectionList = (List<OaEvection>)maps.get("oaEvectionList");
		List<WorkOvertimeForm> workOvertimeFormList = (List<WorkOvertimeForm>)maps.get("workOvertimeFormList");
		List<GoOut> goOutList = (List<GoOut>)maps.get("goOutList");

		List<Map> mapList1 = new ArrayList<>();
		List<Map> mapList2 = new ArrayList<>();
		List<Map> mapList3 = new ArrayList<>();
		List<Map> mapList4 = new ArrayList<>();
		List<Map> mapList5 = new ArrayList<>();
		List<Map> mapList6 = new ArrayList<>();
		List<Map> mapList7 = new ArrayList<>();
		List<Map> mapList8 = new ArrayList<>();
		List<Map> mapList9 = new ArrayList<>();
		List<Map> mapList10 = new ArrayList<>();
		List<Map> mapList11 = new ArrayList<>();
		Map<String,Object> totalMap1 = new HashMap<String,Object>();
		Map<String,Object> totalMap2 = new HashMap<String,Object>();
		Map<String,Object> totalMap3 = new HashMap<String,Object>();
		Map<String,Object> totalMap4 = new HashMap<String,Object>();

		Map<String,Object> map3 = new HashMap<String,Object>();
		Map<String,Object> map4 = new HashMap<String,Object>();
		if(workReportList!=null && workReportList.size()!=0) {
			for (WorkReport w : workReportList) {
				Map map = new HashMap();
				User u = UserUtils.get(w.getCreateBy().getId());
				if (u!=null) {
					map.put("userId", u.getId());
					map.put("photo", u.getPhoto());
					map.put("no",u.getNo());
					map.put("officeName",u.getOfficeName());
					map.put("userName", u.getName());
					map.put("createDate",w.getCreateDate());
					map.put("updateDate",w.getUpdateDate());
					map.put("workReportBean",w);
					mapList1.add(map);
				}
			}
			map3.put("workReport",mapList1);
		}
		totalMap1.put("workReports",map3);
		if(workOutList!=null && workOutList.size()!=0) {
			for (WorkOutSignIn w : workOutList) {
				Map map = new HashMap();
				User u = UserUtils.get(w.getCreateBy().getId());
				if (u!=null) {
					map.put("userId", u.getId());
					map.put("photo", u.getPhoto());
					map.put("no",u.getNo());
					map.put("officeName",u.getOfficeName());
					map.put("userName", u.getName());
					map.put("createDate",w.getCreateDate());
					map.put("updateDate",w.getUpdateDate());
					map.put("workOutSignInBean",w);
					mapList2.add(map);
				}
			}
			map4.put("workOutSignIn", mapList2);
		}
		totalMap2.put("workOutSignIns",map4);

		Map<String,Object> map1 = new HashMap<String,Object>();
		if(oaAttenList!=null && oaAttenList.size()!=0) {
			SimpleDateFormat sdf3 = new SimpleDateFormat("HHmmss");
			for (OaAttendance o : oaAttenList) {
				Map map = new HashMap();
				User u = UserUtils.get(o.getCreateBy().getId());
				if (u!=null){
					if (o.getStartTime() != null && !"".equals(o.getStartTime())) {
						String ruleStart = o.getRule().getStartTime().replaceAll(":","")+"00";
						Integer start = Integer.parseInt(sdf3.format(o.getStartTime()));
						int morning = Integer.parseInt(ruleStart);
						if (start > morning) {
							map.put("userId", u.getId());
							map.put("photo", u.getPhoto());
							map.put("no",u.getNo());
							map.put("officeName",u.getOfficeName());
							map.put("userName", u.getName());
							map.put("createDate",o.getCreateDate());
							map.put("updateDate",o.getUpdateDate());
							map.put("oaAttendanceBean",o);
							mapList3.add(map);
						} else {
							map.put("userId", u.getId());
							map.put("photo", u.getPhoto());
							map.put("no",u.getNo());
							map.put("officeName",u.getOfficeName());
							map.put("userName", u.getName());
							map.put("createDate",o.getCreateDate());
							map.put("updateDate",o.getUpdateDate());
							map.put("oaAttendanceBean",o);
							mapList4.add(map);
						}
					}
					if (o.getEndTime() != null && !"".equals(o.getEndTime())) {
						String ruleEnd = o.getRule().getEndTime().replaceAll(":","")+"00";
						Integer end = Integer.parseInt(sdf3.format(o.getEndTime()));
						int night = Integer.parseInt(ruleEnd);
						if (end >= night) {
							map.put("userId", u.getId());
							map.put("photo", u.getPhoto());
							map.put("no",u.getNo());
							map.put("officeName",u.getOfficeName());
							map.put("userName", u.getName());
							map.put("createDate",o.getCreateDate());
							map.put("updateDate",o.getUpdateDate());
							map.put("oaAttendanceBean",o);
							mapList5.add(map);
						} else {
							map.put("userId", u.getId());
							map.put("photo", u.getPhoto());
							map.put("no",u.getNo());
							map.put("officeName",u.getOfficeName());
							map.put("userName", u.getName());
							map.put("createDate",o.getCreateDate());
							map.put("updateDate",o.getUpdateDate());
							map.put("oaAttendanceBean",o);
							mapList6.add(map);
						}
					}
				}
			}
			if(mapList3!=null && mapList3.size()!=0){ map1.put("late",mapList3); }
			if(mapList4!=null && mapList4.size()!=0){ map1.put("onDuty",mapList4);}
			if(mapList5!=null && mapList5.size()!=0){  map1.put("offDut",mapList5);}
			if(mapList6!=null && mapList6.size()!=0){ map1.put("leaveEarly",mapList6);}

		}
		totalMap3.put("attendances",map1);


		Map<String,Object> map2 = new HashMap<String,Object>();
		if(workSealList!=null && workSealList.size()!=0) {
			for (WorkSealForm w : workSealList) {
				Map map = new HashMap();
				User u = UserUtils.get(w.getCreateBy().getId());
				if (u!=null) {
					map.put("userId", u.getId());
					map.put("photo", u.getPhoto());
					map.put("no",u.getNo());
					map.put("officeName",u.getOfficeName());
					map.put("userName", u.getName());
					map.put("createDate",w.getCreateDate());
					map.put("updateDate",w.getUpdateDate());
					map.put("workSealFormBean",w);
					mapList7.add(map);
				}
			}
			map2.put("workSealFrom",mapList7);
		}
		if(leaveList!=null && leaveList.size()!=0) {
			for (Leave w : leaveList) {
				Map map = new HashMap();
				User u = UserUtils.get(w.getCreateBy().getId());
				if (u!=null) {
					map.put("userId", u.getId());
					map.put("photo", u.getPhoto());
					map.put("no",u.getNo());
					map.put("officeName",u.getOfficeName());
					map.put("userName", u.getName());
					map.put("createDate",w.getCreateDate());
					map.put("updateDate",w.getUpdateDate());
					map.put("leaveBean",w);
					mapList8.add(map);
				}
			}
			map2.put("leave",mapList8);
		}
		if(oaEvectionList!=null && oaEvectionList.size()!=0) {
			for (OaEvection w : oaEvectionList) {
				Map map = new HashMap();
				User u = UserUtils.get(w.getCreateBy().getId());
				if (u!=null) {
					map.put("userId", u.getId());
					map.put("photo", u.getPhoto());
					map.put("no",u.getNo());
					map.put("officeName",u.getOfficeName());
					map.put("userName", u.getName());
					map.put("createDate",w.getCreateDate());
					map.put("updateDate",w.getUpdateDate());
					map.put("oaEvectionBean",w);
					mapList9.add(map);
				}
			}
			map2.put("oaEvection",mapList9);
		}
		if(workOvertimeFormList!=null && workOvertimeFormList.size()!=0) {
			for (WorkOvertimeForm w : workOvertimeFormList) {
				Map map = new HashMap();
				User u = UserUtils.get(w.getCreateBy().getId());
				if (u!=null) {
					map.put("userId", u.getId());
					map.put("photo", u.getPhoto());
					map.put("no",u.getNo());
					map.put("officeName",u.getOfficeName());
					map.put("userName", u.getName());
					map.put("createDate",w.getCreateDate());
					map.put("updateDate",w.getUpdateDate());
					map.put("workOvertimeFormBean",w);
					mapList10.add(map);
				}
			}
			map2.put("workOvertimeForm",mapList10);
		}
		if(goOutList!=null && goOutList.size()!=0) {
			for (GoOut goOut : goOutList) {
				Map map = new HashMap();
				User u = UserUtils.get(goOut.getCreateBy().getId());
				if (u!=null) {
					map.put("userId", u.getId());
					map.put("photo", u.getPhoto());
					map.put("no",u.getNo());
					map.put("officeName",u.getOfficeName());
					map.put("userName", u.getName());
					map.put("createDate",goOut.getCreateDate());
					map.put("updateDate",goOut.getUpdateDate());
					map.put("goOutBean",goOut);
					mapList11.add(map);
				}
			}
			map2.put("workGoOut",mapList11);
		}
		totalMap4.put("audits",map2);
		reportList.add(totalMap1);
		reportList.add(totalMap2);
		reportList.add(totalMap3);
		reportList.add(totalMap4);
		return reportList;
	}
}