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

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.persistence.Page;
import com.jeeplus.common.utils.JPushClientUtil;
import com.jeeplus.common.web.BaseController;
import com.jeeplus.modules.act.entity.Act;
import com.jeeplus.modules.act.service.ActTaskService;
import com.jeeplus.modules.oa.entity.Leave;
import com.jeeplus.modules.oa.entity.OaNotify;
import com.jeeplus.modules.oa.service.LeaveService;
import com.jeeplus.modules.oa.service.OaNotifyService;
import com.jeeplus.modules.oa_evection.entity.oa_evection.OaEvection;
import com.jeeplus.modules.oa_evection.service.oa_evection.OaEvectionService;
import com.jeeplus.modules.oaall.entity.OaAll;
import com.jeeplus.modules.oaall.service.OaAllService;
import com.jeeplus.modules.oabuy.entity.OaBuy;
import com.jeeplus.modules.oabuy.service.OaBuyService;
import com.jeeplus.modules.oaperformance.entity.OaPerformance;
import com.jeeplus.modules.oaperformance.service.OaPerformanceService;
import com.jeeplus.modules.pushinfo.entity.Pushinfo;
import com.jeeplus.modules.pushinfo.service.PushinfoService;
import com.jeeplus.modules.sys.dao.UserDao;
import com.jeeplus.modules.sys.entity.Office;
import com.jeeplus.modules.sys.entity.Role;
import com.jeeplus.modules.sys.entity.User;
import com.jeeplus.modules.sys.entity.Workattachment;
import com.jeeplus.modules.sys.service.SystemService;
import com.jeeplus.modules.sys.service.WorkattachmentService;
import com.jeeplus.modules.sys.utils.UserUtils;
import com.jeeplus.modules.sysuseroffice.entity.Useroffice;
import com.jeeplus.modules.utils.ErrorCode;
import com.jeeplus.modules.work.entity.report.WorkReport;
import com.jeeplus.modules.work.service.report.WorkReportService;
import com.jeeplus.modules.workapprovalcopy.entity.ApprovalCopy;
import com.jeeplus.modules.workapprovalcopy.service.ApprovalCopyService;
import com.jeeplus.modules.workcompanyinfo.service.CompanyinfoService;
import com.jeeplus.modules.workgoout.entity.GoOut;
import com.jeeplus.modules.workgoout.service.GoOutService;
import com.jeeplus.modules.workovertimeform.entity.WorkOvertimeForm;
import com.jeeplus.modules.workovertimeform.service.WorkOvertimeFormService;
import com.jeeplus.modules.workpayment.entity.WorkPayment;
import com.jeeplus.modules.workpayment.service.WorkPaymentService;
import com.jeeplus.modules.workpettycash.entity.WorkPettyCash;
import com.jeeplus.modules.workpettycash.service.WorkPettyCashService;
import com.jeeplus.modules.workprojectnotify.entity.WorkProjectNotify;
import com.jeeplus.modules.workprojectnotify.service.WorkProjectNotifyService;
import com.jeeplus.modules.workreimbur.dao.WorkReimburDao;
import com.jeeplus.modules.workreimbur.entity.WorkReimbur;
import com.jeeplus.modules.workreimbur.entity.WorkReimburDetails;
import com.jeeplus.modules.workreimbur.service.WorkReimburService;
import com.jeeplus.modules.worksealform.entity.WorkSealForm;
import com.jeeplus.modules.worksealform.service.WorkSealFormService;
import org.activiti.engine.history.HistoricTaskInstance;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 流程个人任务相关Controller
 * @author jeeplus
 * @version 2013-11-03
 */
@SuppressWarnings("all")
@Controller
@RequestMapping(value = "${frontPath}/task")
public class ActTaskMoblieController extends BaseController {

    @Autowired
    private ActTaskService actTaskService;
    @Autowired
    private LeaveService leaveService;
    @Autowired
    private GoOutService goOutService;
    @Autowired
    private WorkSealFormService workSealFormService;
    @Autowired
    private OaPerformanceService oaPerformanceService;
    @Autowired
    private OaBuyService oaBuyService;

    @Autowired
    private OaEvectionService oaEvectionService;
    @Autowired
    private WorkOvertimeFormService workOvertimeFormService;
    @Autowired
    private ApprovalCopyService approvalCopyService;
    @Autowired
    private CompanyinfoService companyinfoService;
    @Autowired
    private PushinfoService pushinfoService;
    @Autowired
    private OaAllService oaAllService;

    @Autowired
    private WorkReportService workReportService;
    @Autowired
    private OaNotifyService oaNotifyService;
    @Autowired
    private UserDao userDao;
    @Autowired
    private SystemService systemService;
    @Autowired
    private WorkPettyCashService workPettyCashService;
    @Autowired
    private WorkPaymentService workPaymentService;
    @Autowired
    private WorkReimburService workReimburService;
    @Autowired
    private WorkReimburDao workReimburDao;
    @Autowired
    private WorkattachmentService workattachmentService;
    @Autowired
    private WorkProjectNotifyService workProjectNotifyService;

    @RequestMapping(value={"todoList"}, method={RequestMethod.GET})
    @ResponseBody
    public AjaxJson todoList(HttpServletRequest request, HttpServletResponse response, Model model)
            throws Exception
    {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        HashMap requestMap = findRequestMap(request);
        AjaxJson j = new AjaxJson();
        try {
            String procDefKey = (String)requestMap.get("procDefKey");
            int pageNo = Integer.parseInt(request.getParameter("pageNo"));
            int pageSize = Integer.parseInt(request.getParameter("pageSize"));
            Office company = UserUtils.getSelectCompany();
            Act act = new Act();
            if (StringUtils.isNotBlank(procDefKey)) {
                act.setProcDefKey(procDefKey);
            }
            Page<Act> page = actTaskService.todoList(new Page<Act>(request, response), act);
            List<Act> list = page.getList();
            List list1 = new ArrayList();
            if(list==null){
                j.setSuccess(false);
                j.setErrorCode(ErrorCode.code_2005);
                j.setMsg("获取列表失败");
                j.put("data", list1);
            }else {
                j.put("maxNum", page.getCount());
                if (pageNo <= page.getTotalPage()) {
                    for (int i=0;i< list.size();i++) {
                        Act act1 = list.get(i);
                        String procDef =act1.getProcDef().toString();
                        String processInstanceId =act1.getTask().getProcessInstanceId();
                        if(processInstanceId!=null && !procDef.equals("")){
                            if (procDef.contains("leave")){
                                Leave leave = leaveService.getByProcessInstanceId(processInstanceId);
                                if(leave!=null && leave.getId()!=null && leave.getCompanyId().equals(company.getId())){
                                    Map<String,Object> map = new HashMap<String,Object>();
                                    String startTime = leave.getStartTime();
                                    String endTime = leave.getEndTime();
                                    String createTime = sdf.format(leave.getCreateDate());
                                    String status = leave.getStatus();
                                    String approvalId = leave.getId();
                                    String leaveType =leave.getLeaveType();
                                    User u = leave.getCreateBy();
                                    User user = UserUtils.get(u.getId());
                                    String userName = user.getName();
                                    String photo = user.getPhoto();
                                    map.put("userName",userName);
                                    map.put("photo",photo);
                                    map.put("procDefKey", "leave");
                                    map.put("approvalId",approvalId);
                                    map.put("startTime",startTime);
                                    map.put("endTime",endTime);
                                    map.put("createTime",createTime);
                                    map.put("status",status);
                                    if (leaveType.equals("1")){
                                        leaveType = "事假";
                                    }else if(leaveType.equals("2")){
                                        leaveType = "病假";
                                    }else if(leaveType.equals("3")){
                                        leaveType = "调休";
                                    }else if(leaveType.equals("4")){
                                        leaveType = "年假";
                                    }else if(leaveType.equals("5")){
                                        leaveType = "婚假";
                                    }else if(leaveType.equals("6")){
                                        leaveType = "产假";
                                    }else if(leaveType.equals("7")){
                                        leaveType = "其他";
                                    }
                                    map.put("leaveType", leaveType);
                                    if (!status.equals("5")) {
                                        list1.add(map);
                                    }
                                }
                            }else if (procDef.contains("overtime")){
                                WorkOvertimeForm overtimeform  =  workOvertimeFormService.getByProcessInstanceId(processInstanceId);
                                if(overtimeform!=null  && overtimeform.getId()!=null && overtimeform.getCompanyId().equals(company.getId())){
                                    Map<String,Object> map = new HashMap<String,Object>();
                                    String startTime = overtimeform.getStartTime();
                                    String endTime = overtimeform.getEndTime();
                                    String createTime = sdf.format(overtimeform.getCreateDate());
                                    String status = overtimeform.getStatus();
                                    String approvalId = overtimeform.getId();
                                    String isHolidays = overtimeform.getIsHolidays();
                                    User u = overtimeform.getCreateBy();
                                    User user = UserUtils.get(u.getId());
                                    String userName = user.getName();
                                    String photo = user.getPhoto();
                                    map.put("userName",userName);
                                    map.put("photo",photo);
                                    map.put("procDefKey", "overtime");
                                    map.put("approvalId",approvalId);
                                    map.put("startTime",startTime);
                                    map.put("endTime",endTime);
                                    map.put("createTime",createTime);
                                    map.put("status", status);
                                    if (isHolidays.equals("1")){
                                        isHolidays = "是";
                                    }else if (isHolidays.equals("2")){
                                        isHolidays = "不是";
                                    }
                                    map.put("isHolidays", isHolidays);
                                    if (!status.equals("5")) {
                                        list1.add(map);
                                    }
                                }
                            }else if (procDef.contains("goout")){
                                GoOut goout = goOutService.getByProcessInstanceId(processInstanceId);
                                if(goout!=null  && goout.getId()!=null && goout.getCompanyId().equals(company.getId())) {
                                    Map<String,Object> map = new HashMap<String,Object>();
                                    String startTime = goout.getStartTime();
                                    String endTime = goout.getEndTime();
                                    String createTime = sdf.format(goout.getCreateDate());
                                    String status = goout.getStatus();
                                    String approvalId = goout.getId();
                                    String gooutDay =goout.getGooutDay();
                                    User u = goout.getCreateBy();
                                    User user = UserUtils.get(u.getId());
                                    String userName = user.getName();
                                    String photo = user.getPhoto();
                                    map.put("userName",userName);
                                    map.put("photo",photo);
                                    map.put("procDefKey", "goout");
                                    map.put("approvalId",approvalId);
                                    map.put("startTime",startTime);
                                    map.put("endTime",endTime);
                                    map.put("createTime",createTime);
                                    map.put("status", status);
                                    map.put("gooutDay", gooutDay);
                                    if (!status.equals("5")) {
                                        list1.add(map);
                                    }
                                }
                            }else if (procDef.contains("sealform")){
                                WorkSealForm sealform = workSealFormService.getByProcessInstanceId(processInstanceId);
                                if(sealform!=null && sealform.getId()!=null && sealform.getCompanyId().equals(company.getId())) {
                                    Map<String,Object> map = new HashMap<String,Object>();
                                    String documentName = sealform.getDocumentName();
                                    String documentCount = sealform.getDocumentCount();
                                    String createTime = sdf.format(sealform.getCreateDate());
                                    String status = sealform.getStatus();
                                    String approvalId = sealform.getId();
                                    String sealType = sealform.getSealType();
                                    User u = sealform.getCreateBy();
                                    User user = UserUtils.get(u.getId());
                                    String userName = user.getName();
                                    String photo = user.getPhoto();
                                    map.put("userName",userName);
                                    map.put("photo",photo);
                                    map.put("procDefKey", "sealform");
                                    map.put("approvalId", approvalId);
                                    map.put("createTime",createTime);
                                    map.put("status",status);
                                    map.put("documentName",documentName);
                                    map.put("documentCount",documentCount);
                                    if (sealType.equals("1")){
                                        sealType = "公章";
                                    }else if (sealType.equals("2")){
                                        sealType = "合同章";
                                    }else if (sealType.equals("3")){
                                        sealType = "法人章";
                                    }else if (sealType.equals("4")){
                                        sealType = "其他";
                                    }
                                    map.put("sealType", sealType);
                                    if (!status.equals("5")) {
                                        list1.add(map);
                                    }
                                }
                            }else if (procDef.contains("evection")){
                                OaEvection evection = oaEvectionService.getByProcessInstanceId(processInstanceId);
                                if(evection!=null  && evection.getId()!=null && evection.getCompanyId().equals(company.getId())) {
                                    Map<String,Object> map = new HashMap<String,Object>();
                                    String startTime = evection.getStartTime();
                                    String endTime = evection.getEndTime();
                                    String createTime = sdf.format(evection.getCreateDate());
                                    String status = evection.getStatus();
                                    String approvalId = evection.getId();
                                    User u = evection.getCreateBy();
                                    User user = UserUtils.get(u.getId());
                                    String userName = user.getName();
                                    String photo = user.getPhoto();
                                    map.put("userName",userName);
                                    map.put("photo",photo);
                                    map.put("procDefKey", "evection");
                                    map.put("approvalId",approvalId);
                                    map.put("startTime",startTime);
                                    map.put("endTime",endTime);
                                    map.put("createTime",createTime);
                                    map.put("status", status);
                                    if (!status.equals("5")) {
                                        list1.add(map);
                                    }
                                }
                            }else if(procDef.contains("pettyCash")){
                                WorkPettyCash workPettyCash = workPettyCashService.getByProcessInstanceId(processInstanceId);
                                if(workPettyCash!=null && workPettyCash.getId()!=null && workPettyCash.getCompanyId().equals(company.getId())) {
                                    Map<String,Object> map = new HashMap<String,Object>();
                                    User user = UserUtils.getByUserId(workPettyCash.getCreateBy().getId());
                                    String userId = user.getId();
                                    String userName = user.getName();
                                    String applicantName = workPettyCash.getApplicantName();
                                    String applicantOfficeName = workPettyCash.getApplicantOfficeName();
                                    Office office = workPettyCash.getOffice();
                                    String officeId = office.getId();
                                    String officeName = office.getName();
                                    String createTime = sdf.format(workPettyCash.getCreateDate());
                                    String reason = workPettyCash.getReason();
                                    String amount = workPettyCash.getAmount();
                                    String amountCN = workPettyCash.getAmountCN();
                                    Date   useDate = workPettyCash.getUseDate();
                                    String useDateStr = useDate==null?"":sdf.format(useDate);
                                    Date  returnDate = workPettyCash.getReturnDate();
                                    String returnDateStr = returnDate==null?"":sdf.format(returnDate);
                                    String remarks = workPettyCash.getRemarks();
                                    String status = workPettyCash.getStatus();
                                    String approvalId = workPettyCash.getId();
                                    String photo = user.getPhoto();
                                    map.put("photo",photo);
                                    map.put("procDefKey", "pettyCash");
                                    map.put("approvalId", approvalId);
                                    map.put("userName",userName);
                                    map.put("officeName",officeName);
                                    map.put("applicantName",applicantName);
                                    map.put("applicantOfficeName",applicantOfficeName);
                                    map.put("createTime",createTime);
                                    map.put("status",status);
                                    map.put("reason",reason);
                                    map.put("amount",amount);
                                    map.put("amountCN",amountCN);
                                    map.put("useDateStr",useDateStr);
                                    map.put("returnDateStr",returnDateStr);
                                    map.put("remarks",remarks);
                                    if (!status.equals("5")) {
                                        list1.add(map);
                                    }
                                }
                            }else if(procDef.contains("payment")){
                                WorkPayment workPayment = workPaymentService.getByProcessInstanceId(processInstanceId);
                                if(workPayment!=null && workPayment.getId()!=null && workPayment.getCompanyId().equals(company.getId())) {
                                    Map<String,Object> map = new HashMap<String,Object>();
                                    User user = UserUtils.getByUserId(workPayment.getCreateBy().getId());
                                    String userId = user.getId();
                                    String userName = user.getName();
                                    Office office = workPayment.getOffice();
                                    String officeId = office.getId();
                                    String officeName = office.getName();
                                    String createTime = sdf.format(workPayment.getCreateDate());
                                    String reason = workPayment.getReason();
                                    String amount = workPayment.getAmount();
                                    Date   payDate = workPayment.getPayDate();
                                    String payDateStr = payDate==null?"":sdf.format(payDate);
                                    String payType = workPayment.getPayType();
                                    String payObject = workPayment.getPayObject();
                                    String payBank = workPayment.getPayBank();
                                    String payBankAccount = workPayment.getPayBankAccount();
                                    String status = workPayment.getStatus();
                                    String approvalId = workPayment.getId();
                                    String remarks = workPayment.getRemarks();
                                    String photo = user.getPhoto();
                                    map.put("photo",photo);
                                    map.put("procDefKey", "payment");
                                    map.put("userName",userName);
                                    map.put("approvalId", approvalId);
                                    map.put("officeName",officeName);
                                    map.put("createTime",createTime);
                                    map.put("status",status);
                                    map.put("reason",reason);
                                    map.put("amount",amount);
                                    map.put("payDateStr",payDateStr);
                                    map.put("payObject",payObject);
                                    map.put("payBank",payBank);
                                    map.put("payBankAccount",payBankAccount);
                                    map.put("remarks",remarks);
                                    if (payType.equals("1")){
                                        payType = "支票";
                                    }else if (payType.equals("2")){
                                        payType = "贷记";
                                    }else if (payType.equals("3")){
                                        payType = "电汇";
                                    }else if (payType.equals("4")){
                                        payType = "汇票";
                                    }else if (payType.equals("5")){
                                        payType = "现金";
                                    }else if (payType.equals("6")){
                                        payType = "银行卡";
                                    }else if (payType.equals("7")){
                                        payType = "其他";
                                    }
                                    map.put("payType", payType);
                                    if (!status.equals("5")) {
                                        list1.add(map);
                                    }
                                }
                            }else if(procDef.contains("reimbur")){
                                WorkReimbur workReimbur = workReimburService.getByProcessInstanceId(processInstanceId);
                                if(workReimbur!=null && workReimbur.getId()!=null && workReimbur.getCompanyId().equals(company.getId())) {
                                    Map<String,Object> map = new HashMap<String,Object>();
                                    User user = UserUtils.getByUserId(workReimbur.getCreateBy().getId());
                                    String userId = user.getId();
                                    String userName = user.getName();
                                    Office office = workReimbur.getOffice();
                                    String officeId = office.getId();
                                    String officeName = office.getName();
                                    String createTime = sdf.format(workReimbur.getCreateDate());
                                    String status = workReimbur.getStatus();
                                    String approvalId = workReimbur.getId();
                                    String remarks = workReimbur.getRemarks();
                                    List<WorkReimburDetails> detailsList = workReimburDao.getDetailsList(workReimbur);
                                    List<Workattachment> attachmentList = workattachmentService.getListByAttachmentIdAndFlag(workReimbur.getId(),"70");
                                    String photo = user.getPhoto();
                                    map.put("photo",photo);
                                    map.put("procDefKey", "reimbur");
                                    map.put("userName",userName);
                                    map.put("approvalId", approvalId);
                                    map.put("officeName",officeName);
                                    map.put("createTime",createTime);
                                    map.put("status",status);
                                    map.put("remarks",remarks);
                                    map.put("detailsList",detailsList);
                                    String totalAmount = "";
                                    if(detailsList!=null && detailsList.size()>0){
                                        BigDecimal bd = new BigDecimal("0.00");
                                        for (int z = 0; z < detailsList.size(); z++) {
                                            WorkReimburDetails details = detailsList.get(z);
                                            if(com.jeeplus.common.utils.StringUtils.isNotBlank(details.getReimburAmount())){
                                                bd = bd.add(new BigDecimal(details.getReimburAmount()));
                                            }
                                        }
                                        totalAmount = bd.toString();
                                    }
                                    map.put("totalAmount",totalAmount);
                                    //map.put("attachmentList",attachmentList);
                                    String filePath = "";
                                    if(attachmentList!=null && attachmentList.size()>0){
                                        for (int a = 0; a < attachmentList.size(); a++) {
                                            if(com.jeeplus.common.utils.StringUtils.isNotBlank(attachmentList.get(a).getUrl())){
                                                filePath += ","+attachmentList.get(a).getUrl();
                                            }
                                        }
                                    }
                                    if(filePath.startsWith(",")&&filePath.length()>2){
                                        filePath = filePath.substring(1);
                                    }
                                    map.put("files",filePath);
                                    if (!status.equals("5")) {
                                        list1.add(map);
                                    }
                                }
                            }
                            else if (procDef.contains("oaPerformance")){
                                OaPerformance evection = oaPerformanceService.getByProcessInstanceId(processInstanceId);
                                if(evection!=null  && evection.getId()!=null && evection.getCompanyId().equals(company.getId())) {
                                    Map<String,Object> map = new HashMap<String,Object>();
                                    User u = evection.getCreateBy();
                                    User user = UserUtils.get(u.getId());
                                    String userName = user.getName();
                                    String photo = user.getPhoto();
                                    String lastWork = evection.getLastWork();
                                    String finishWork = evection.getFinishWork();
                                    String finishRate = evection.getFinishRate();
                                    String lastPerformance = evection.getLastPerformance();
                                    String nowWork = evection.getNowWork();
                                    String nowPlan = evection.getNowPlan();

                                    String createTime = sdf.format(evection.getCreateDate());
                                    String status = evection.getStatus();
                                    String approvalId = evection.getId();
                                    map.put("userName",userName);
                                    map.put("photo",photo);
                                    map.put("procDefKey", "oaPerformance");
                                    map.put("approvalId",approvalId);
                                    map.put("createTime",createTime);
                                    map.put("status", status);
                                    map.put("lastWork",lastWork);
                                    map.put("finishWork",finishWork);
                                    map.put("finishRate",finishRate);
                                    map.put("lastPerformance",lastPerformance);
                                    map.put("nowWork",nowWork);
                                    map.put("nowPlan",nowPlan);
                                    if (!status.equals("5")) {
                                        list1.add(map);
                                    }
                                }
                            }
                            else if (procDef.contains("allApprove")){
                                OaAll evection = oaAllService.getByProcessInstanceId(processInstanceId);
                                if(evection!=null  && evection.getId()!=null && evection.getCompanyId().equals(company.getId())) {
                                    Map<String,Object> map = new HashMap<String,Object>();
                                    User u = evection.getCreateBy();
                                    User user = UserUtils.get(u.getId());
                                    String userName = user.getName();
                                    String photo = user.getPhoto();
                                    String applyContent = evection.getApplyContent();
                                    String approveDetail = evection.getApproveDetail();

                                    String createTime = sdf.format(evection.getCreateDate());
                                    String status = evection.getStatus();
                                    String approvalId = evection.getId();
                                    map.put("userName",userName);
                                    map.put("photo",photo);
                                    map.put("procDefKey", "allApprove");
                                    map.put("approvalId",approvalId);
                                    map.put("createTime",createTime);
                                    map.put("status", status);
                                    map.put("applyContent",applyContent);
                                    map.put("approveDetail",approveDetail);
                                    if (!status.equals("5")) {
                                        list1.add(map);
                                    }
                                }
                            }
                            else if (procDef.contains("oaBuy")){
                                OaBuy evection = oaBuyService.getByProcessInstanceId(processInstanceId);
                                if(evection!=null  && evection.getId()!=null && evection.getCompanyId().equals(company.getId())) {
                                    Map<String,Object> map = new HashMap<String,Object>();
                                    User u = evection.getCreateBy();
                                    User user = UserUtils.get(u.getId());
                                    String userName = user.getName();
                                    String photo = user.getPhoto();
                                    String applyContent = evection.getApplyContent();
                                    String buySort = evection.getBuySort();
                                    Date d = evection.getDeliverDate();
                                    String deliverDate = null;
                                    if(d!=null){
                                        deliverDate = sdf.format(d);
                                    }
                                    String payStyle = evection.getPayStyle();

                                    String createTime = sdf.format(evection.getCreateDate());
                                    String status = evection.getStatus();
                                    String approvalId = evection.getId();
                                    map.put("userName",userName);
                                    map.put("photo",photo);

                                    map.put("procDefKey", "oaBuy");
                                    map.put("approvalId",approvalId);
                                    map.put("createTime",createTime);
                                    map.put("status", status);
                                    map.put("applyContent",applyContent);
                                    map.put("deliverDate",deliverDate);
                                    if (buySort.equals("1")){
                                        buySort = "办公用品";
                                    }else if (buySort.equals("2")){
                                        buySort = "生产原料";
                                    }else if (buySort.equals("3")){
                                        buySort = "其它";
                                    }
                                    map.put("buySort", buySort);
                                    if (payStyle.equals("1")){
                                        payStyle = "现金";
                                    }else if (payStyle.equals("2")){
                                        payStyle = "汇款";
                                    }else if (payStyle.equals("3")){
                                        payStyle = "第三方支付软件";
                                    }
                                    map.put("payStyle", payStyle);
                                    if (!status.equals("5")) {
                                        list1.add(map);
                                    }
                                }
                            }

                        }
                    }
                    j.put("data", list1);
                }else {
                    j.put("data", new ArrayList<>());
                }
                j.setErrorCode(ErrorCode.code_1004);
                j.setMsg("获取待办任务成功");
                j.put("maxNum", page.getCount());

            }
        } catch (Exception e) {
            j.setErrorCode(ErrorCode.code_2004);
            j.setMsg("获取待办任务失败");
            j.put("maxNum", 0);
            j.put("data", "");
            logger.info("---------e:"+e.getMessage());
        }
        return j;
    }

    /**
     * 获取已办任务
     * @param
     * @return
     */
    @RequestMapping(value = "historic", method = RequestMethod.GET)
    @ResponseBody
    public AjaxJson historicList(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
        HashMap<String, String> requestMap = findRequestMap(request);
        String pageNo  = requestMap.get("pageNo");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        AjaxJson j = new AjaxJson();
        try {
            String procDefKey = requestMap.get("procDefKey");
            Act act = new Act();
            if (StringUtils.isNotBlank(procDefKey)) {
                act.setProcDefKey(procDefKey);
            }
            Office company = UserUtils.getSelectCompany();
            Page<Act> page = actTaskService.historicList(new Page<Act>(request, response), act);
            List<Act> list = page.getList();
            List list1 = new ArrayList();
            if(list==null){
                j.setSuccess(false);
                j.setErrorCode(ErrorCode.code_2005);
                j.setMsg("获取列表失败");
                j.put("data", list1);
            }else {
                j.put("maxNum", page.getCount());
                if(Integer.parseInt(pageNo)<=page.getTotalPage()) {
                    for (int i=0;i< list.size();i++) {
                        Act act1 = list.get(i);
                        HistoricTaskInstance historicTaskInstance = act1.getHistTask();
                        String procInsId = historicTaskInstance.getProcessInstanceId();
                        String procDef =act1.getProcDef().toString();
                        String processInstanceId =act1.getHistTask().getProcessInstanceId();
                        if(processInstanceId!=null && !procDef.equals("")){
                            if (procDef.contains("leave")){
                                Leave leave = leaveService.getByProcessInstanceId(processInstanceId);
                                if(leave!=null && leave.getId()!=null && leave.getCompanyId().equals(company.getId())){
                                    Map<String,Object> map = new HashMap<String,Object>();
                                    String startTime = leave.getStartTime();
                                    String endTime = leave.getEndTime();
                                    String createTime = sdf.format(leave.getCreateDate());
                                    String status = leave.getStatus();
                                    String approvalId = leave.getId();
                                    String leaveType =leave.getLeaveType();
                                    User u = leave.getCreateBy();
                                    User user = UserUtils.get(u.getId());
                                    String userName = user.getName();
                                    String photo = user.getPhoto();
                                    map.put("photo",photo);
                                    map.put("userName",userName);
                                    map.put("procDefKey", "leave");
                                    map.put("approvalId",approvalId);
                                    map.put("startTime",startTime);
                                    map.put("endTime",endTime);
                                    map.put("createTime",createTime);
                                    map.put("status",status);
                                    if (leaveType.equals("1")){
                                        leaveType = "事假";
                                    }else if(leaveType.equals("2")){
                                        leaveType = "病假";
                                    }else if(leaveType.equals("3")){
                                        leaveType = "调休";
                                    }else if(leaveType.equals("4")){
                                        leaveType = "年假";
                                    }else if(leaveType.equals("5")){
                                        leaveType = "婚假";
                                    }else if(leaveType.equals("6")){
                                        leaveType = "产假";
                                    }else if(leaveType.equals("7")){
                                        leaveType = "其他";
                                    }
                                    map.put("leaveType", leaveType);
                                    if (!status.equals("5")) {
                                        list1.add(map);
                                    }
                                }
                            }else if (procDef.contains("overtime")){
                                WorkOvertimeForm overtimeform  =  workOvertimeFormService.getByProcessInstanceId(processInstanceId);
                                if(overtimeform!=null  && overtimeform.getId()!=null && overtimeform.getCompanyId().equals(company.getId())){
                                    Map<String,Object> map = new HashMap<String,Object>();
                                    String startTime = overtimeform.getStartTime();
                                    String endTime = overtimeform.getEndTime();
                                    String createTime = sdf.format(overtimeform.getCreateDate());
                                    String status = overtimeform.getStatus();
                                    String approvalId = overtimeform.getId();
                                    String isHolidays = overtimeform.getIsHolidays();
                                    User u = overtimeform.getCreateBy();
                                    User user = UserUtils.get(u.getId());
                                    String userName = user.getName();
                                    String photo = user.getPhoto();
                                    map.put("photo",photo);
                                    map.put("userName",userName);
                                    map.put("procDefKey", "overtime");
                                    map.put("approvalId",approvalId);
                                    map.put("startTime",startTime);
                                    map.put("endTime",endTime);
                                    map.put("createTime",createTime);
                                    map.put("status", status);
                                    if (isHolidays.equals("1")){
                                        isHolidays = "是";
                                    }else if (isHolidays.equals("2")){
                                        isHolidays = "不是";
                                    }
                                    map.put("isHolidays", isHolidays);
                                    if (!status.equals("5")) {
                                        list1.add(map);
                                    }
                                }
                            }else if (procDef.contains("goout")){
                                GoOut goout = goOutService.getByProcessInstanceId(processInstanceId);
                                if(goout!=null  && goout.getId()!=null && goout.getCompanyId().equals(company.getId())) {
                                    Map<String,Object> map = new HashMap<String,Object>();
                                    String startTime = goout.getStartTime();
                                    String endTime = goout.getEndTime();
                                    String createTime = sdf.format(goout.getCreateDate());
                                    String status = goout.getStatus();
                                    String approvalId = goout.getId();
                                    String gooutDay =goout.getGooutDay();
                                    User u = goout.getCreateBy();
                                    User user = UserUtils.get(u.getId());
                                    String userName = user.getName();
                                    String photo = user.getPhoto();
                                    map.put("photo",photo);
                                    map.put("userName",userName);
                                    map.put("procDefKey", "goout");
                                    map.put("approvalId",approvalId);
                                    map.put("startTime",startTime);
                                    map.put("endTime",endTime);
                                    map.put("createTime",createTime);
                                    map.put("status", status);
                                    map.put("gooutDay", gooutDay);
                                    if (!status.equals("5")) {
                                        list1.add(map);
                                    }
                                }
                            }else if (procDef.contains("sealform")){
                                WorkSealForm sealform = workSealFormService.getByProcessInstanceId(processInstanceId);
                                if(sealform!=null && sealform.getId()!=null && sealform.getCompanyId().equals(company.getId())) {
                                    Map<String,Object> map = new HashMap<String,Object>();
                                    String documentName = sealform.getDocumentName();
                                    String documentCount = sealform.getDocumentCount();
                                    String createTime = sdf.format(sealform.getCreateDate());
                                    String status = sealform.getStatus();
                                    String approvalId = sealform.getId();
                                    String sealType = sealform.getSealType();
                                    User u = sealform.getCreateBy();
                                    User user = UserUtils.get(u.getId());
                                    String userName = user.getName();
                                    String photo = user.getPhoto();
                                    map.put("photo",photo);
                                    map.put("userName",userName);
                                    map.put("procDefKey", "sealform");
                                    map.put("approvalId", approvalId);
                                    map.put("createTime",createTime);
                                    map.put("status",status);
                                    map.put("documentName",documentName);
                                    map.put("documentCount",documentCount);
                                    if (sealType.equals("1")){
                                        sealType = "公章";
                                    }else if (sealType.equals("2")){
                                        sealType = "合同章";
                                    }else if (sealType.equals("3")){
                                        sealType = "法人章";
                                    }else if (sealType.equals("4")){
                                        sealType = "其他";
                                    }
                                    map.put("sealType", sealType);
                                    if (!status.equals("5")) {
                                        list1.add(map);
                                    }
                                }
                            }else if (procDef.contains("evection")){
                                OaEvection evection = oaEvectionService.getByProcessInstanceId(processInstanceId);
                                if(evection!=null  && evection.getId()!=null && evection.getCompanyId().equals(company.getId())) {
                                    Map<String,Object> map = new HashMap<String,Object>();
                                    String startTime = evection.getStartTime();
                                    String endTime = evection.getEndTime();
                                    String createTime = sdf.format(evection.getCreateDate());
                                    String status = evection.getStatus();
                                    String approvalId = evection.getId();
                                    User u = evection.getCreateBy();
                                    User user = UserUtils.get(u.getId());
                                    String userName = user.getName();
                                    String photo = user.getPhoto();
                                    map.put("photo",photo);
                                    map.put("userName",userName);
                                    map.put("procDefKey", "evection");
                                    map.put("approvalId",approvalId);
                                    map.put("startTime",startTime);
                                    map.put("endTime",endTime);
                                    map.put("createTime",createTime);
                                    map.put("status", status);
                                    if (!status.equals("5")) {
                                        list1.add(map);
                                    }
                                }
                            }else if(procDef.contains("pettyCash")){
                                WorkPettyCash workPettyCash = workPettyCashService.getByProcessInstanceId(processInstanceId);
                                if(workPettyCash!=null && workPettyCash.getId()!=null && workPettyCash.getCompanyId().equals(company.getId())) {
                                    Map<String,Object> map = new HashMap<String,Object>();
                                    User user = UserUtils.getByUserId(workPettyCash.getCreateBy().getId());
                                    String userId = user.getId();
                                    String userName = user.getName();
                                    String applicantName = workPettyCash.getApplicantName();
                                    String applicantOfficeName = workPettyCash.getApplicantOfficeName();
                                    Office office = workPettyCash.getOffice();
                                    String officeId = office.getId();
                                    String officeName = office.getName();
                                    String createTime = sdf.format(workPettyCash.getCreateDate());
                                    String reason = workPettyCash.getReason();
                                    String amount = workPettyCash.getAmount();
                                    Date   useDate = workPettyCash.getUseDate();
                                    String useDateStr = useDate==null?"":sdf.format(useDate);
                                    Date  returnDate = workPettyCash.getReturnDate();
                                    String returnDateStr = returnDate==null?"":sdf.format(returnDate);
                                    String status = workPettyCash.getStatus();
                                    String approvalId = workPettyCash.getId();
                                    String remarks = workPettyCash.getRemarks();
                                    String photo = user.getPhoto();
                                    map.put("photo",photo);
                                    map.put("procDefKey", "pettyCash");
                                    map.put("approvalId", approvalId);
                                    map.put("applicantName",applicantName);
                                    map.put("applicantOfficeName",applicantOfficeName);
                                    map.put("userName",userName);
                                    map.put("officeName",officeName);
                                    map.put("createTime",createTime);
                                    map.put("status",status);
                                    map.put("reason",reason);
                                    map.put("amount",amount);
                                    map.put("useDateStr",useDateStr);
                                    map.put("returnDateStr",returnDateStr);
                                    map.put("remarks",remarks);
                                    if (!status.equals("5")) {
                                        list1.add(map);
                                    }
                                }
                            }else if(procDef.contains("payment")){
                                WorkPayment workPayment = workPaymentService.getByProcessInstanceId(processInstanceId);
                                if(workPayment!=null && workPayment.getId()!=null && workPayment.getCompanyId().equals(company.getId())) {
                                    Map<String,Object> map = new HashMap<String,Object>();
                                    User user = UserUtils.getByUserId(workPayment.getCreateBy().getId());
                                    String userId = user.getId();
                                    String userName = user.getName();
                                    Office office = workPayment.getOffice();
                                    String officeId = office.getId();
                                    String officeName = office.getName();
                                    String createTime = sdf.format(workPayment.getCreateDate());
                                    String reason = workPayment.getReason();
                                    String amount = workPayment.getAmount();
                                    Date   payDate = workPayment.getPayDate();
                                    String payDateStr = payDate==null?"":sdf.format(payDate);
                                    String payType = workPayment.getPayType();
                                    String payObject = workPayment.getPayObject();
                                    String payBank = workPayment.getPayBank();
                                    String payBankAccount = workPayment.getPayBankAccount();
                                    String status = workPayment.getStatus();
                                    String approvalId = workPayment.getId();
                                    String remarks = workPayment.getRemarks();
                                    String photo = user.getPhoto();
                                    map.put("photo",photo);
                                    map.put("procDefKey", "payment");
                                    map.put("approvalId", approvalId);
                                    map.put("userName",userName);
                                    map.put("officeName",officeName);
                                    map.put("createTime",createTime);
                                    map.put("status",status);
                                    map.put("reason",reason);
                                    map.put("amount",amount);
                                    map.put("payDateStr",payDateStr);
                                    map.put("payObject",payObject);
                                    map.put("payBank",payBank);
                                    map.put("payBankAccount",payBankAccount);
                                    map.put("remarks",remarks);
                                    if (payType.equals("1")){
                                        payType = "支票";
                                    }else if (payType.equals("2")){
                                        payType = "贷记";
                                    }else if (payType.equals("3")){
                                        payType = "电汇";
                                    }else if (payType.equals("4")){
                                        payType = "汇票";
                                    }else if (payType.equals("5")){
                                        payType = "现金";
                                    }else if (payType.equals("6")){
                                        payType = "银行卡";
                                    }else if (payType.equals("7")){
                                        payType = "其他";
                                    }
                                    map.put("payType", payType);
                                    if (!status.equals("5")) {
                                        list1.add(map);
                                    }
                                }
                            }else if(procDef.contains("reimbur")){
                                WorkReimbur workReimbur = workReimburService.getByProcessInstanceId(processInstanceId);
                                if(workReimbur!=null && workReimbur.getId()!=null && workReimbur.getCompanyId().equals(company.getId())) {
                                    Map<String,Object> map = new HashMap<String,Object>();
                                    User user = UserUtils.getByUserId(workReimbur.getCreateBy().getId());
                                    String userId = user.getId();
                                    String userName = user.getName();
                                    Office office = workReimbur.getOffice();
                                    String officeId = office.getId();
                                    String officeName = office.getName();
                                    String createTime = sdf.format(workReimbur.getCreateDate());
                                    String status = workReimbur.getStatus();
                                    String approvalId = workReimbur.getId();
                                    String remarks = workReimbur.getRemarks();
                                    List<WorkReimburDetails> detailsList = workReimburDao.getDetailsList(workReimbur);
                                    List<Workattachment> attachmentList = workattachmentService.getListByAttachmentIdAndFlag(workReimbur.getId(),"70");
                                    map.put("procDefKey", "reimbur");
                                    String photo = user.getPhoto();
                                    map.put("photo",photo);
                                    map.put("approvalId", approvalId);
                                    map.put("userName",userName);
                                    map.put("officeName",officeName);
                                    map.put("createTime",createTime);
                                    map.put("status",status);
                                    map.put("remarks",remarks);
                                    map.put("detailsList",detailsList);
                                    String totalAmount = "";
                                    if(detailsList!=null && detailsList.size()>0){
                                        BigDecimal bd = new BigDecimal("0.00");
                                        for (int z = 0; z < detailsList.size(); z++) {
                                            WorkReimburDetails details = detailsList.get(z);
                                            if(com.jeeplus.common.utils.StringUtils.isNotBlank(details.getReimburAmount())){
                                                bd = bd.add(new BigDecimal(details.getReimburAmount()));
                                            }
                                        }
                                        totalAmount = bd.toString();
                                    }
                                    map.put("totalAmount",totalAmount);
                                    //map.put("attachmentList",attachmentList);
                                    String filePath = "";
                                    if(attachmentList!=null && attachmentList.size()>0){
                                        for (int a = 0; a < attachmentList.size(); a++) {
                                            if(com.jeeplus.common.utils.StringUtils.isNotBlank(attachmentList.get(a).getUrl())){
                                                filePath += ","+attachmentList.get(a).getUrl();
                                            }
                                        }
                                    }
                                    if(filePath.startsWith(",")&&filePath.length()>2){
                                        filePath = filePath.substring(1);
                                    }
                                    map.put("files",filePath);
                                    if (!status.equals("5")) {
                                        list1.add(map);
                                    }
                                }
                            }
                            else if (procDef.contains("oaPerformance")) {
                                OaPerformance evection = oaPerformanceService.getByProcessInstanceId(processInstanceId);
                                if (evection != null && evection.getId() != null && evection.getCompanyId().equals(company.getId())) {
                                    Map<String, Object> map = new HashMap<String, Object>();
                                    User u = evection.getCreateBy();
                                    User user = UserUtils.get(u.getId());
                                    String userName = user.getName();
                                    String photo = user.getPhoto();
                                    String lastWork = evection.getLastWork();
                                    String finishWork = evection.getFinishWork();
                                    String finishRate = evection.getFinishRate();
                                    String lastPerformance = evection.getLastPerformance();
                                    String nowWork = evection.getNowWork();
                                    String nowPlan = evection.getNowPlan();

                                    String createTime = sdf.format(evection.getCreateDate());
                                    String status = evection.getStatus();
                                    String approvalId = evection.getId();
                                    map.put("userName",userName);
                                    map.put("photo",photo);
                                    map.put("procDefKey", "oaPerformance");
                                    map.put("approvalId", approvalId);
                                    map.put("createTime", createTime);
                                    map.put("status", status);
                                    map.put("lastWork", lastWork);
                                    map.put("finishWork", finishWork);
                                    map.put("finishRate", finishRate);
                                    map.put("lastPerformance", lastPerformance);
                                    map.put("nowWork", nowWork);
                                    map.put("nowPlan", nowPlan);
                                    if (!status.equals("5")) {
                                        list1.add(map);
                                    }
                                }
                            }
                            else if (procDef.contains("allApprove")){
                                OaAll evection = oaAllService.getByProcessInstanceId(processInstanceId);
                                if(evection!=null  && evection.getId()!=null && evection.getCompanyId().equals(company.getId())) {
                                    Map<String,Object> map = new HashMap<String,Object>();
                                    User u = evection.getCreateBy();
                                    User user = UserUtils.get(u.getId());
                                    String userName = user.getName();
                                    String photo = user.getPhoto();
                                    String applyContent = evection.getApplyContent();
                                    String approveDetail = evection.getApproveDetail();

                                    String createTime = sdf.format(evection.getCreateDate());
                                    String status = evection.getStatus();
                                    String approvalId = evection.getId();
                                    map.put("userName",userName);
                                    map.put("photo",photo);
                                    map.put("procDefKey", "allApprove");
                                    map.put("approvalId",approvalId);
                                    map.put("createTime",createTime);
                                    map.put("status", status);
                                    map.put("applyContent",applyContent);
                                    map.put("approveDetail",approveDetail);
                                    if (!status.equals("5")) {
                                        list1.add(map);
                                    }
                                }
                            }
                            else if (procDef.contains("oaBuy")){
                                OaBuy evection = oaBuyService.getByProcessInstanceId(processInstanceId);
                                if(evection!=null  && evection.getId()!=null && evection.getCompanyId().equals(company.getId())) {
                                    Map<String,Object> map = new HashMap<String,Object>();
                                    User u = evection.getCreateBy();
                                    User user = UserUtils.get(u.getId());
                                    String userName = user.getName();
                                    String photo = user.getPhoto();
                                    String applyContent = evection.getApplyContent();
                                    String buySort = evection.getBuySort();
                                    Date d = evection.getDeliverDate();
                                    String deliverDate = null;
                                    if(d!=null){
                                        deliverDate = sdf.format(d);
                                    }
                                    String payStyle = evection.getPayStyle();

                                    String createTime = sdf.format(evection.getCreateDate());
                                    String status = evection.getStatus();
                                    String approvalId = evection.getId();
                                    map.put("userName",userName);
                                    map.put("photo",photo);
                                    map.put("procDefKey", "oaBuy");
                                    map.put("approvalId",approvalId);
                                    map.put("createTime",createTime);
                                    map.put("status", status);
                                    map.put("applyContent",applyContent);
                                    map.put("deliverDate",deliverDate);
                                    if (buySort.equals("1")){
                                        buySort = "办公用品";
                                    }else if (buySort.equals("2")){
                                        buySort = "生产原料";
                                    }else if (buySort.equals("3")){
                                        buySort = "其它";
                                    }
                                    map.put("buySort", buySort);
                                    if (payStyle.equals("1")){
                                        payStyle = "现金";
                                    }else if (payStyle.equals("2")){
                                        payStyle = "汇款";
                                    }else if (payStyle.equals("3")){
                                        payStyle = "第三方支付软件";
                                    }
                                    map.put("payStyle", payStyle);
                                    if (!status.equals("5")) {
                                        list1.add(map);
                                    }
                                }
                            }
                        }
                    }
                    j.put("data",list1);
                }else{
                    j.put("data",new ArrayList<>());
                }
                j.setErrorCode(ErrorCode.code_1004);
                j.setMsg("获取已办任务成功");
                j.put("maxNum",page.getCount());
            }
        }catch (Exception e){
            j.setErrorCode(ErrorCode.code_2004);
            j.setMsg("获取已办任务失败");
            j.put("maxNum",0);
            j.put("data",new ArrayList());
            logger.info("---------e:"+e.getMessage());
        }

        return j;
    }

    /**
     * 查看用户发起的审批信息
     * @param
     * @return json数据
     */
    @RequestMapping(value = "getMyStartedList", method=RequestMethod.GET)
    @ResponseBody
    public AjaxJson getMyStartedList(HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
        AjaxJson j = new AjaxJson();
        try{
            Office company = UserUtils.getSelectCompany();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String userId = request.getParameter("userId");
            String procDefKey = request.getParameter("procDefKey");
            String pageNo = request.getParameter("pageNo");
            ApprovalCopy approvalCopy = new ApprovalCopy();
            approvalCopy.setUserId(userId);
            approvalCopy.setDelFlag("0");
            if (StringUtils.isNotBlank(procDefKey)){
                approvalCopy.setType(procDefKey);
            }
            Page<ApprovalCopy> page = approvalCopyService.find(new Page<ApprovalCopy>(request, response), approvalCopy);
            List<ApprovalCopy> list=page.getList();
            List lists = new ArrayList();
            if(list==null){
                j.setSuccess(false);
                j.setErrorCode(ErrorCode.code_2005);
                j.setMsg("获取列表失败");
                j.put("data", lists);
            }else{
                j.put("maxNum",page.getCount());
                if(Integer.parseInt(pageNo)<=page.getTotalPage()){
                    for (ApprovalCopy a :list){
                        Map<String,Object> map = new HashMap<String,Object>();
                        String type = a.getType();
                        String aUserId = a.getUserId();
                        String approvalId = a.getApprovalId();
                        String reason = a.getRemarks()==null?"":a.getRemarks();
                        map.put("type",type);
                        map.put("userId",aUserId);
                        map.put("approvalId",approvalId);
                        map.put("reason",reason);
                        if(type.equals("leave")){
                            Leave leave = leaveService.getById(approvalId);
                            if(leave!=null && company.getId().equals(leave.getCompanyId())){
                                String startTime = leave.getStartTime();
                                String endTime = leave.getEndTime();
                                String createTime = sdf.format(leave.getCreateDate());
                                String status = leave.getStatus();
                                String processInstanceId = leave.getProcessInstanceId();
                                User u = leave.getCreateBy();
                                User user = UserUtils.get(u.getId());
                                String userName = user.getName();
                                String photo = user.getPhoto();
                                map.put("photo",photo);
                                map.put("userName",userName);
                                map.put("processInstanceId",processInstanceId);
                                map.put("createTime",createTime);
                                map.put("startTime",startTime);
                                map.put("endTime", endTime);
                                map.put("status",status);
                                String leaveType =leave.getLeaveType();
                                if (leaveType.equals("1")){
                                    leaveType = "事假";
                                }else if(leaveType.equals("2")){
                                    leaveType = "病假";
                                }else if(leaveType.equals("3")){
                                    leaveType = "调休";
                                }else if(leaveType.equals("4")){
                                    leaveType = "年假";
                                }else if(leaveType.equals("5")){
                                    leaveType = "婚假";
                                }else if(leaveType.equals("6")){
                                    leaveType = "产假";
                                }else if(leaveType.equals("7")){
                                    leaveType = "其他";
                                }
                                map.put("leaveType",leaveType);
                                lists.add(map);
                            }
                        }
                        else if(type.equals("goout")){
                            GoOut goOut = goOutService.getById(approvalId);
                            if(goOut!=null && company.getId().equals(goOut.getCompanyId())){
                                String startTime = goOut.getStartTime();
                                String endTime = goOut.getEndTime();
                                String createTime = sdf.format(goOut.getCreateDate());
                                String status = goOut.getStatus();
                                String processInstanceId = goOut.getProcessInstanceId();
                                User u = goOut.getCreateBy();
                                User user = UserUtils.get(u.getId());
                                String userName = user.getName();
                                String photo = user.getPhoto();
                                map.put("photo",photo);
                                map.put("userName",userName);
                                map.put("processInstanceId",processInstanceId);
                                map.put("createTime",createTime);
                                map.put("startTime",startTime);
                                map.put("endTime",endTime);
                                map.put("status",status);
                                lists.add(map);
                            }
                        }
                        else if(type.equals("evection")){
                            OaEvection evection = oaEvectionService.getById(approvalId);
                            if(evection!=null && company.getId().equals(evection.getCompanyId())){
                                String startTime = evection.getStartTime();
                                String endTime = evection.getEndTime();
                                String createTime = sdf.format(evection.getCreateDate());
                                String status = evection.getStatus();
                                String processInstanceId = evection.getProcessInstanceId();
                                User u = evection.getCreateBy();
                                User user = UserUtils.get(u.getId());
                                String userName = user.getName();
                                String photo = user.getPhoto();
                                map.put("photo",photo);
                                map.put("userName",userName);
                                map.put("processInstanceId",processInstanceId);
                                map.put("createTime",createTime);
                                map.put("startTime",startTime);
                                map.put("endTime",endTime);
                                map.put("status",status);
                                lists.add(map);
                            }
                        }
                        else if(type.equals("sealform")){
                            WorkSealForm useseal = workSealFormService.getById(approvalId);
                            if(useseal!=null && company.getId().equals(useseal.getCompanyId())){
                                String createTime = sdf.format(useseal.getCreateDate());
                                String documentName = useseal.getDocumentName();
                                String documentCount = useseal.getDocumentCount();
                                String status = useseal.getStatus();
                                String processInstanceId = useseal.getProcessInstanceId();
                                User u = useseal.getCreateBy();
                                User user = UserUtils.get(u.getId());
                                String userName = user.getName();
                                String photo = user.getPhoto();
                                map.put("photo",photo);
                                map.put("userName",userName);
                                map.put("processInstanceId",processInstanceId);
                                map.put("createTime",createTime);
                                map.put("status",status);
                                map.put("documentName",documentName);
                                map.put("documentCount",documentCount);
                                String sealType = useseal.getSealType();
                                if (sealType.equals("1")){
                                    sealType = "公章";
                                }else if (sealType.equals("2")){
                                    sealType = "合同章";
                                }else if (sealType.equals("3")){
                                    sealType = "法人章";
                                }else if (sealType.equals("4")){
                                    sealType = "其他";
                                }
                                map.put("sealType",sealType);
                                lists.add(map);
                            }
                        }
                        else if(type.equals("overtime")){
                            WorkOvertimeForm overtime = workOvertimeFormService.getById(approvalId);
                            if(overtime!=null && company.getId().equals(overtime.getCompanyId())){
                                String startTime = overtime.getStartTime();
                                String endTime = overtime.getEndTime();
                                String createTime = sdf.format(overtime.getCreateDate());
                                String status = overtime.getStatus();
                                String processInstanceId = overtime.getProcessInstanceId();
                                User u = overtime.getCreateBy();
                                User user = UserUtils.get(u.getId());
                                String userName = user.getName();
                                String photo = user.getPhoto();
                                map.put("photo",photo);
                                map.put("userName",userName);
                                map.put("processInstanceId",processInstanceId);
                                map.put("createTime",createTime);
                                map.put("startTime",startTime);
                                map.put("endTime",endTime);
                                map.put("status",status);
                                String isHolidays = overtime.getIsHolidays();
                                if (isHolidays.equals("1")){
                                    isHolidays = "是";
                                }else if (isHolidays.equals("2")){
                                    isHolidays = "不是";
                                }
                                map.put("isHolidays",isHolidays);
                                lists.add(map);
                            }
                        }
                        else if(type.equals("pettyCash")){
                            WorkPettyCash workPettyCash = workPettyCashService.getById(approvalId);
                            if(workPettyCash!=null && company.getId().equals(workPettyCash.getCompanyId())){
                                String processInstanceId = workPettyCash.getProcessInstanceId();
                                User user = UserUtils.getByUserId(workPettyCash.getCreateBy().getId());
                                String userName = user.getName();
                                String applicantName = workPettyCash.getApplicantName();
                                String applicantOfficeName = workPettyCash.getApplicantOfficeName();
                                Office office = workPettyCash.getOffice();
                                String officeId = office.getId();
                                String officeName = office.getName();
                                String createTime = sdf.format(workPettyCash.getCreateDate());
                                String reason2 = workPettyCash.getReason();
                                String amount = workPettyCash.getAmount();
                                Date   useDate = workPettyCash.getUseDate();
                                String useDateStr = useDate==null?"":sdf.format(useDate);
                                Date  returnDate = workPettyCash.getReturnDate();
                                String returnDateStr = returnDate==null?"":sdf.format(returnDate);
                                String status = workPettyCash.getStatus();
                                String remarks = workPettyCash.getRemarks();
                                String photo = user.getPhoto();
                                map.put("photo",photo);
                                map.put("processInstanceId",processInstanceId);
                                map.put("userName",userName);
                                map.put("applicantName",applicantName);
                                map.put("applicantOfficeName",applicantOfficeName);
                                map.put("officeName",officeName);
                                map.put("createTime",createTime);
                                map.put("status",status);
                                map.put("reason",reason2);
                                map.put("amount",amount);
                                map.put("useDateStr",useDateStr);
                                map.put("returnDateStr",returnDateStr);
                                map.put("remarks",remarks);
                                lists.add(map);
                            }
                        }
                        else if(type.equals("payment")){
                            WorkPayment workPayment = workPaymentService.getById(approvalId);
                            if(workPayment!=null && company.getId().equals(workPayment.getCompanyId())){
                                String processInstanceId = workPayment.getProcessInstanceId();
                                User user = UserUtils.getByUserId(workPayment.getCreateBy().getId());
                                String userName = user.getName();
                                Office office = workPayment.getOffice();
                                String officeId = office.getId();
                                String officeName = office.getName();
                                String createTime = sdf.format(workPayment.getCreateDate());
                                String reason2 = workPayment.getReason();
                                String amount = workPayment.getAmount();
                                Date   payDate = workPayment.getPayDate();
                                String payDateStr = payDate==null?"":sdf.format(payDate);
                                String payType = workPayment.getPayType();
                                String payObject = workPayment.getPayObject();
                                String payBank = workPayment.getPayBank();
                                String payBankAccount = workPayment.getPayBankAccount();
                                String status = workPayment.getStatus();
                                String remarks = workPayment.getRemarks();
                                String photo = user.getPhoto();
                                map.put("photo",photo);
                                map.put("processInstanceId",processInstanceId);
                                map.put("userName",userName);
                                map.put("officeName",officeName);
                                map.put("createTime",createTime);
                                map.put("status",status);
                                map.put("reason",reason);
                                map.put("amount",amount);
                                map.put("payDateStr",payDateStr);
                                map.put("payObject",payObject);
                                map.put("payBank",payBank);
                                map.put("payBankAccount",payBankAccount);
                                map.put("remarks",remarks);
                                if (payType.equals("1")){
                                    payType = "支票";
                                }else if (payType.equals("2")){
                                    payType = "贷记";
                                }else if (payType.equals("3")){
                                    payType = "电汇";
                                }else if (payType.equals("4")){
                                    payType = "汇票";
                                }else if (payType.equals("5")){
                                    payType = "现金";
                                }else if (payType.equals("6")){
                                    payType = "银行卡";
                                }else if (payType.equals("7")){
                                    payType = "其他";
                                }
                                map.put("payType", payType);
                                lists.add(map);
                            }
                        }
                        else if(type.equals("reimbur")){
                            WorkReimbur workReimbur = workReimburService.getById(approvalId);
                            if(workReimbur!=null && company.getId().equals(workReimbur.getCompanyId())){
                                String processInstanceId = workReimbur.getProcessInstanceId();
                                User user = UserUtils.getByUserId(workReimbur.getCreateBy().getId());
                                String userName = user.getName();
                                Office office = workReimbur.getOffice();
                                String officeId = office.getId();
                                String officeName = office.getName();
                                String createTime = sdf.format(workReimbur.getCreateDate());
                                String status = workReimbur.getStatus();
                                String remarks = workReimbur.getRemarks();
                                List<WorkReimburDetails> detailsList = workReimburDao.getDetailsList(workReimbur);
                                String totalAmount = "";
                                if(detailsList!=null && detailsList.size()>0){
                                    BigDecimal bd = new BigDecimal("0.00");
                                    for (int i = 0; i < detailsList.size(); i++) {
                                        WorkReimburDetails details = detailsList.get(i);
                                        if(com.jeeplus.common.utils.StringUtils.isNotBlank(details.getReimburAmount())){
                                            bd = bd.add(new BigDecimal(details.getReimburAmount()));
                                        }
                                    }
                                    totalAmount = bd.toString();
                                }
                                List<Workattachment> attachmentList = workattachmentService.getListByAttachmentIdAndFlag(workReimbur.getId(),"70");
                                map.put("processInstanceId",processInstanceId);
                                String photo = user.getPhoto();
                                map.put("photo",photo);
                                map.put("userName",userName);
                                map.put("officeName",officeName);
                                map.put("createTime",createTime);
                                map.put("status",status);
                                map.put("reason",reason);
                                map.put("remarks",remarks);
                                map.put("detailsList",detailsList);
                                map.put("totalAmount",totalAmount);
                                //map.put("attachmentList",attachmentList);
                                String filePath = "";
                                if(attachmentList!=null && attachmentList.size()>0){
                                    for (int k = 0; k < attachmentList.size(); k++) {
                                        if(com.jeeplus.common.utils.StringUtils.isNotBlank(attachmentList.get(k).getUrl())){
                                            filePath += ","+attachmentList.get(k).getUrl();
                                        }
                                    }
                                }
                                if(filePath.startsWith(",")&&filePath.length()>2){
                                    filePath = filePath.substring(1);
                                }
                                map.put("files",filePath);
                                lists.add(map);
                            }
                        }
                        else if (type.contains("oaPerformance")) {
                            OaPerformance evection = oaPerformanceService.getById(approvalId);
                            if (evection != null && evection.getId() != null && evection.getCompanyId().equals(company.getId())) {
                                User u = evection.getCreateBy();
                                User user = UserUtils.get(u.getId());
                                String userName = user.getName();
                                String photo = user.getPhoto();
                                String lastWork = evection.getLastWork();
                                String finishWork = evection.getFinishWork();
                                String finishRate = evection.getFinishRate();
                                String lastPerformance = evection.getLastPerformance();
                                String nowWork = evection.getNowWork();
                                String nowPlan = evection.getNowPlan();

                                String createTime = sdf.format(evection.getCreateDate());
                                String status = evection.getStatus();
                                String processInstanceId = evection.getProcessInstanceId();
                                map.put("userName",userName);
                                map.put("photo",photo);
                                map.put("procDefKey", "oaPerformance");
                                map.put("processInstanceId", processInstanceId);
                                map.put("createTime", createTime);
                                map.put("status", status);
                                map.put("lastWork", lastWork);
                                map.put("finishWork", finishWork);
                                map.put("finishRate", finishRate);
                                map.put("lastPerformance", lastPerformance);
                                map.put("nowWork", nowWork);
                                map.put("nowPlan", nowPlan);
                                lists.add(map);
                            }
                        }
                        else if (type.contains("allApprove")){
                            OaAll evection = oaAllService.getById(approvalId);
                            if(evection!=null  && evection.getId()!=null && evection.getCompanyId().equals(company.getId())) {
                                User u = evection.getCreateBy();
                                User user = UserUtils.get(u.getId());
                                String userName = user.getName();
                                String photo = user.getPhoto();
                                String applyContent = evection.getApplyContent();
                                String approveDetail = evection.getApproveDetail();

                                String createTime = sdf.format(evection.getCreateDate());
                                String status = evection.getStatus();
                                String processInstanceId = evection.getProcessInstanceId();
                                map.put("userName",userName);
                                map.put("photo",photo);
                                map.put("procDefKey", "allApprove");
                                map.put("processInstanceId",processInstanceId);
                                map.put("createTime",createTime);
                                map.put("status", status);
                                map.put("applyContent",applyContent);
                                map.put("approveDetail",approveDetail);
                                lists.add(map);
                            }
                        }
                        else if (type.contains("oaBuy")){
                            OaBuy evection = oaBuyService.getById(approvalId);
                            if(evection!=null  && evection.getId()!=null && evection.getCompanyId().equals(company.getId())) {
                                User u = evection.getCreateBy();
                                User user = UserUtils.get(u.getId());
                                String userName = user.getName();
                                String photo = user.getPhoto();
                                String applyContent = evection.getApplyContent();
                                String buySort = evection.getBuySort();
                                Date d = evection.getDeliverDate();
                                String deliverDate = null;
                                if(d!=null){
                                    deliverDate = sdf.format(d);
                                }
                                String payStyle = evection.getPayStyle();

                                String createTime = sdf.format(evection.getCreateDate());
                                String status = evection.getStatus();
                                String processInstanceId = evection.getProcessInstanceId();
                                map.put("userName",userName);
                                map.put("photo",photo);
                                map.put("procDefKey", "oaBuy");
                                map.put("processInstanceId", processInstanceId);
                                map.put("createTime",createTime);
                                map.put("status", status);
                                map.put("applyContent",applyContent);
                                map.put("deliverDate",deliverDate);
                                if (buySort.equals("1")){
                                    buySort = "办公用品";
                                }else if (buySort.equals("2")){
                                    buySort = "生产原料";
                                }else if (buySort.equals("3")){
                                    buySort = "其它";
                                }
                                map.put("buySort", buySort);
                                if (payStyle.equals("1")){
                                    payStyle = "现金";
                                }else if (payStyle.equals("2")){
                                    payStyle = "汇款";
                                }else if (payStyle.equals("3")){
                                    payStyle = "第三方支付软件";
                                }
                                map.put("payStyle", payStyle);
                                lists.add(map);
                            }
                        }

                    }
                    j.put("data",lists);
                    j.setMsg("获取列表成功");
                    j.setErrorCode(ErrorCode.code_1004);
                }else{
                    j.put("data", Lists.newArrayList());
                    j.setErrorCode(ErrorCode.code_1004);
                    j.setMsg("获取列表成功");
                }
            }
        }catch (Exception e){
            j.setErrorCode(ErrorCode.code_2004);
            j.setMsg("获取已办任务失败");
            j.put("maxNum",0);
            j.put("data","");
        }

        return j;
    }

    /**
     * 查看用户收到的抄送信息
     * @param
     * @param
     * @return json数据
     */
    @RequestMapping(value = "getCopyMeList", method=RequestMethod.GET)
    @ResponseBody
    public AjaxJson getCopyMeList(HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
        AjaxJson j = new AjaxJson();
        try{
            Office company = UserUtils.getSelectCompany();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String userId = request.getParameter("userId");
            String pageNo = request.getParameter("pageNo");
            String procDefKey = request.getParameter("procDefKey");
            ApprovalCopy approvalCopy = new ApprovalCopy();
            approvalCopy.setCCId(userId);
            approvalCopy.setDelFlag("0");
            if (procDefKey!=null && !procDefKey.equals("")){
                approvalCopy.setType(procDefKey);
            }
            Page<ApprovalCopy> page = approvalCopyService.find(new Page<ApprovalCopy>(request, response), approvalCopy);
            List<ApprovalCopy> list=page.getList();
            List lists = new ArrayList();
            if(list==null){
                j.setSuccess(false);
                j.setErrorCode(ErrorCode.code_2005);
                j.setMsg("获取列表失败");
                j.put("data", lists);
            }else{
                j.put("maxNum",page.getCount());
                if(Integer.parseInt(pageNo)<=page.getTotalPage()){
                    for (ApprovalCopy a :list){
                        Map<String,Object> map = new HashMap<String,Object>();
                        String type = a.getType();
                        String aUserId = a.getUserId();
                        String approvalId = a.getApprovalId();
                        String reason = a.getRemarks()==null?"":a.getRemarks();
                        String readFlag = a.getReadFlag();
                        map.put("type",type);
                        map.put("userId",aUserId);
                        map.put("approvalId",approvalId);
                        map.put("reason",reason);
                        map.put("readFlag",readFlag);
                        if(type.equals("leave")){
                            Leave leave = leaveService.getById(approvalId);
                            if(leave!=null && company.getId().equals(leave.getCompanyId())){
                                String startTime = leave.getStartTime();
                                String endTime = leave.getEndTime();
                                String createTime = sdf.format(leave.getCreateDate());
                                String status = leave.getStatus();
                                User u = leave.getCreateBy();
                                User user = UserUtils.get(u.getId());
                                String userName = user.getName();
                                String photo = user.getPhoto();
                                map.put("photo",photo);
                                map.put("userName",userName);
                                map.put("startTime",startTime);
                                map.put("endTime",endTime);
                                map.put("createTime",createTime);
                                map.put("status",status);
                                String leaveType =leave.getLeaveType();
                                if (leaveType.equals("1")){
                                    leaveType = "事假";
                                }else if(leaveType.equals("2")){
                                    leaveType = "病假";
                                }else if(leaveType.equals("3")){
                                    leaveType = "调休";
                                }else if(leaveType.equals("4")){
                                    leaveType = "年假";
                                }else if(leaveType.equals("5")){
                                    leaveType = "婚假";
                                }else if(leaveType.equals("6")){
                                    leaveType = "产假";
                                }else if(leaveType.equals("7")){
                                    leaveType = "其他";
                                }
                                map.put("leaveType",leaveType);
                                lists.add(map);
                            }
                        }
                        else if(type.equals("goout")){
                            GoOut goOut = goOutService.getById(approvalId);
                            if(goOut!=null && company.getId().equals(goOut.getCompanyId())){
                                String startTime = goOut.getStartTime();
                                String endTime = goOut.getEndTime();
                                String createTime = sdf.format(goOut.getCreateDate());
                                String status = goOut.getStatus();
                                User u = goOut.getCreateBy();
                                User user = UserUtils.get(u.getId());
                                String userName = user.getName();
                                String photo = user.getPhoto();
                                map.put("photo",photo);
                                map.put("userName",userName);
                                map.put("startTime",startTime);
                                map.put("endTime",endTime);
                                map.put("createTime",createTime);
                                map.put("status",status);
                                lists.add(map);
                            }
                        }
                        else if(type.equals("evection")){
                            OaEvection evection = oaEvectionService.getById(approvalId);
                            if(evection!=null && company.getId().equals(evection.getCompanyId())){
                                String startTime = evection.getStartTime();
                                String endTime = evection.getEndTime();
                                String createTime = sdf.format(evection.getCreateDate());
                                String status = evection.getStatus();
                                User u = evection.getCreateBy();
                                User user = UserUtils.get(u.getId());
                                String userName = user.getName();
                                String photo = user.getPhoto();
                                map.put("photo",photo);
                                map.put("userName",userName);
                                map.put("startTime",startTime);
                                map.put("endTime",endTime);
                                map.put("createTime",createTime);
                                map.put("status",status);
                                lists.add(map);
                            }
                        }
                        else if(type.equals("sealform")){
                            WorkSealForm useseal = workSealFormService.getById(approvalId);
                            if(useseal!=null && company.getId().equals(useseal.getCompanyId())){
                                String createTime = sdf.format(useseal.getCreateDate());
                                String documentName = useseal.getDocumentName();
                                String documentCount = useseal.getDocumentCount();
                                String status = useseal.getStatus();
                                User u = useseal.getCreateBy();
                                User user = UserUtils.get(u.getId());
                                String userName = user.getName();
                                String photo = user.getPhoto();
                                map.put("photo",photo);
                                map.put("userName",userName);
                                map.put("createTime",createTime);
                                map.put("status",status);
                                map.put("documentName",documentName);
                                map.put("documentCount",documentCount);
                                String sealType = useseal.getSealType();
                                if (sealType.equals("1")){
                                    sealType = "公章";
                                }else if (sealType.equals("2")){
                                    sealType = "合同章";
                                }else if (sealType.equals("3")){
                                    sealType = "法人章";
                                }else if (sealType.equals("4")){
                                    sealType = "其他";
                                }
                                map.put("sealType",sealType);
                                lists.add(map);
                            }
                        }
                        else if(type.equals("overtime")){
                            WorkOvertimeForm overtime = workOvertimeFormService.getById(approvalId);
                            if(overtime!=null && company.getId().equals(overtime.getCompanyId())){
                                String startTime = overtime.getStartTime();
                                String endTime = overtime.getEndTime();
                                String createTime = sdf.format(overtime.getCreateDate());
                                String status = overtime.getStatus();
                                User u = overtime.getCreateBy();
                                User user = UserUtils.get(u.getId());
                                String userName = user.getName();
                                String photo = user.getPhoto();
                                map.put("photo",photo);
                                map.put("userName",userName);
                                map.put("startTime",startTime);
                                map.put("endTime",endTime);
                                map.put("createTime",createTime);
                                map.put("status",status);
                                String isHolidays = overtime.getIsHolidays();
                                if (isHolidays.equals("1")){
                                    isHolidays = "是";
                                }else if (isHolidays.equals("2")){
                                    isHolidays = "不是";
                                }
                                map.put("isHolidays",isHolidays);
                                lists.add(map);
                            }
                        }
                        else if(type.equals("pettyCash")){
                            WorkPettyCash workPettyCash = workPettyCashService.getById(approvalId);
                            if(workPettyCash!=null && company.getId().equals(workPettyCash.getCompanyId())){
                                String processInstanceId = workPettyCash.getProcessInstanceId();
                                User user = UserUtils.getByUserId(workPettyCash.getCreateBy().getId());
                                String userName = user.getName();
                                String applicantName = workPettyCash.getApplicantName();
                                String applicantOfficeName = workPettyCash.getApplicantOfficeName();
                                Office office = workPettyCash.getOffice();
                                String officeId = office.getId();
                                String officeName = office.getName();
                                String createTime = sdf.format(workPettyCash.getCreateDate());
                                String reason2 = workPettyCash.getReason();
                                String amount = workPettyCash.getAmount();
                                Date   useDate = workPettyCash.getUseDate();
                                String useDateStr = useDate==null?"":sdf.format(useDate);
                                Date  returnDate = workPettyCash.getReturnDate();
                                String returnDateStr = returnDate==null?"":sdf.format(returnDate);
                                String status = workPettyCash.getStatus();
                                String remarks = workPettyCash.getRemarks();
                                String photo = user.getPhoto();
                                map.put("photo",photo);
                                map.put("userName",userName);
                                map.put("applicantName",applicantName);
                                map.put("applicantOfficeName",applicantOfficeName);
                                map.put("officeName",officeName);
                                map.put("createTime",createTime);
                                map.put("status",status);
                                map.put("reason",reason2);
                                map.put("amount",amount);
                                map.put("useDateStr",useDateStr);
                                map.put("returnDateStr",returnDateStr);
                                map.put("remarks",remarks);
                                lists.add(map);
                            }
                        }
                        else if(type.equals("payment")){
                            WorkPayment workPayment = workPaymentService.getById(approvalId);
                            if(workPayment!=null && company.getId().equals(workPayment.getCompanyId())){
                                User user = UserUtils.getByUserId(workPayment.getCreateBy().getId());
                                String userName = user.getName();
                                Office office = workPayment.getOffice();
                                String officeId = office.getId();
                                String officeName = office.getName();
                                String createTime = sdf.format(workPayment.getCreateDate());
                                String reason2 = workPayment.getReason();
                                String amount = workPayment.getAmount();
                                Date   payDate = workPayment.getPayDate();
                                String payDateStr = payDate==null?"":sdf.format(payDate);
                                String payType = workPayment.getPayType();
                                String payObject = workPayment.getPayObject();
                                String payBank = workPayment.getPayBank();
                                String payBankAccount = workPayment.getPayBankAccount();
                                String status = workPayment.getStatus();
                                String remarks = workPayment.getRemarks();
                                String photo = user.getPhoto();
                                map.put("photo",photo);
                                map.put("userName",userName);
                                map.put("officeName",officeName);
                                map.put("createTime",createTime);
                                map.put("status",status);
                                map.put("reason",reason2);
                                map.put("amount",amount);
                                map.put("payDateStr",payDateStr);
                                map.put("payObject",payObject);
                                map.put("payBank",payBank);
                                map.put("payBankAccount",payBankAccount);
                                map.put("remarks",remarks);
                                if (payType.equals("1")){
                                    payType = "支票";
                                }else if (payType.equals("2")){
                                    payType = "贷记";
                                }else if (payType.equals("3")){
                                    payType = "电汇";
                                }else if (payType.equals("4")){
                                    payType = "汇票";
                                }else if (payType.equals("5")){
                                    payType = "现金";
                                }else if (payType.equals("6")){
                                    payType = "银行卡";
                                }else if (payType.equals("7")){
                                    payType = "其他";
                                }
                                map.put("payType", payType);
                                lists.add(map);
                            }
                        }
                        else if(type.equals("reimbur")){
                            WorkReimbur workReimbur = workReimburService.getById(approvalId);
                            if(workReimbur!=null && company.getId().equals(workReimbur.getCompanyId())){
                                User user = UserUtils.getByUserId(workReimbur.getCreateBy().getId());
                                String userName = user.getName();
                                Office office = workReimbur.getOffice();
                                String officeId = office.getId();
                                String officeName = office.getName();
                                String createTime = sdf.format(workReimbur.getCreateDate());
                                String status = workReimbur.getStatus();
                                String remarks = workReimbur.getRemarks();
                                List<WorkReimburDetails> detailsList = workReimburDao.getDetailsList(workReimbur);
                                List<Workattachment> attachmentList = workattachmentService.getListByAttachmentIdAndFlag(workReimbur.getId(),"70");
                                map.put("userName",userName);
                                String photo = user.getPhoto();
                                map.put("photo",photo);
                                map.put("officeName",officeName);
                                map.put("createTime",createTime);
                                map.put("status",status);
                                map.put("detailsList",detailsList);
                                //map.put("attachmentList",attachmentList);
                                String filePath = "";
                                if(attachmentList!=null && attachmentList.size()>0){
                                    for (int k = 0; k < attachmentList.size(); k++) {
                                        if(com.jeeplus.common.utils.StringUtils.isNotBlank(attachmentList.get(k).getUrl())){
                                            filePath += ","+attachmentList.get(k).getUrl();
                                        }
                                    }
                                }
                                if(filePath.startsWith(",")&&filePath.length()>2){
                                    filePath = filePath.substring(1);
                                }
                                map.put("files",filePath);
                                lists.add(map);
                            }
                        }
                        else if (type.contains("oaPerformance")) {
                            OaPerformance evection = oaPerformanceService.getById(approvalId);
                            if (evection != null && evection.getId() != null && evection.getCompanyId().equals(company.getId())) {
                                User u = evection.getCreateBy();
                                User user = UserUtils.get(u.getId());
                                String userName = user.getName();
                                String photo = user.getPhoto();
                                String lastWork = evection.getLastWork();
                                String finishWork = evection.getFinishWork();
                                String finishRate = evection.getFinishRate();
                                String lastPerformance = evection.getLastPerformance();
                                String nowWork = evection.getNowWork();
                                String nowPlan = evection.getNowPlan();

                                String createTime = sdf.format(evection.getCreateDate());
                                String status = evection.getStatus();
                                String processInstanceId = evection.getProcessInstanceId();
                                map.put("userName",userName);
                                map.put("photo",photo);
                                map.put("procDefKey", "oaPerformance");
                                map.put("processInstanceId", processInstanceId);
                                map.put("createTime", createTime);
                                map.put("status", status);
                                map.put("lastWork", lastWork);
                                map.put("finishWork", finishWork);
                                map.put("finishRate", finishRate);
                                map.put("lastPerformance", lastPerformance);
                                map.put("nowWork", nowWork);
                                map.put("nowPlan", nowPlan);
                                lists.add(map);
                            }
                        }
                        else if (type.contains("allApprove")){
                            OaAll evection = oaAllService.getById(approvalId);
                            if(evection!=null  && evection.getId()!=null && evection.getCompanyId().equals(company.getId())) {
                                User u = evection.getCreateBy();
                                User user = UserUtils.get(u.getId());
                                String userName = user.getName();
                                String photo = user.getPhoto();
                                String applyContent = evection.getApplyContent();
                                String approveDetail = evection.getApproveDetail();

                                String createTime = sdf.format(evection.getCreateDate());
                                String status = evection.getStatus();
                                String processInstanceId = evection.getProcessInstanceId();
                                map.put("userName",userName);
                                map.put("photo",photo);
                                map.put("procDefKey", "allApprove");
                                map.put("processInstanceId",processInstanceId);
                                map.put("createTime",createTime);
                                map.put("status", status);
                                map.put("applyContent",applyContent);
                                map.put("approveDetail",approveDetail);
                                lists.add(map);
                            }
                        }
                        else if (type.contains("oaBuy")){
                            OaBuy evection = oaBuyService.getById(approvalId);
                            if(evection!=null  && evection.getId()!=null && evection.getCompanyId().equals(company.getId())) {
                                User u = evection.getCreateBy();
                                User user = UserUtils.get(u.getId());
                                String userName = user.getName();
                                String photo = user.getPhoto();
                                String applyContent = evection.getApplyContent();
                                String buySort = evection.getBuySort();
                                Date d = evection.getDeliverDate();
                                String deliverDate = null;
                                if(d!=null){
                                    deliverDate = sdf.format(d);
                                }
                                String payStyle = evection.getPayStyle();

                                String createTime = sdf.format(evection.getCreateDate());
                                String status = evection.getStatus();
                                String processInstanceId = evection.getProcessInstanceId();
                                map.put("userName",userName);
                                map.put("photo",photo);
                                map.put("procDefKey", "oaBuy");
                                map.put("processInstanceId", processInstanceId);
                                map.put("createTime",createTime);
                                map.put("status", status);
                                map.put("applyContent",applyContent);
                                map.put("deliverDate",deliverDate);
                                if (buySort.equals("1")){
                                    buySort = "办公用品";
                                }else if (buySort.equals("2")){
                                    buySort = "生产原料";
                                }else if (buySort.equals("3")){
                                    buySort = "其它";
                                }
                                map.put("buySort", buySort);
                                if (payStyle.equals("1")){
                                    payStyle = "现金";
                                }else if (payStyle.equals("2")){
                                    payStyle = "汇款";
                                }else if (payStyle.equals("3")){
                                    payStyle = "第三方支付软件";
                                }
                                map.put("payStyle", payStyle);
                                lists.add(map);
                            }
                        }
                    }
                    j.put("data",lists);
                    j.setMsg("获取列表成功");
                    j.setErrorCode(ErrorCode.code_1004);
                }else{
                    j.put("data", Lists.newArrayList());
                    j.setMsg("获取列表成功");
                    j.setErrorCode(ErrorCode.code_1004);
                }
            }
        }catch (Exception e){
            j.setErrorCode(ErrorCode.code_2004);
            j.setMsg("获取已办任务失败");
            j.put("maxNum",0);
            j.put("data",Lists.newArrayList());
        }

        return j;
    }

    /**
     * 审核同意/失败
     * @param
     * @return
     */
    @Transactional
    @RequestMapping(value = "saveAudit", method=RequestMethod.POST)
    @ResponseBody
    public AjaxJson saveAudit(HttpServletRequest request, HttpServletResponse response) {
        HashMap<String, String> requestMap = findRequestMap(request);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String taskId = requestMap.get("taskId");
        String taskName = requestMap.get("taskName");
        String taskDefKey = requestMap.get("taskDefKey");
        String procInsId = requestMap.get("procInsId");
        String procDefId = requestMap.get("procDefId");
        String procDefKey = requestMap.get("procDefKey");
        String flag = requestMap.get("flag");
        String CCId = requestMap.get("CCId");
        //String actStatus = requestMap.get("actStatus");
        String comment = requestMap.get("comment");
        String approvalId = requestMap.get("approvalId");
        Act act = new Act();
        act.setTaskId(taskId);
        act.setTaskName(taskName);
        act.setTaskDefKey(taskDefKey);
        act.setProcInsId(procInsId);
        act.setProcDefId(procDefId);
        act.setFlag(flag);
        act.setComment(comment);
        String type = "2";
        AjaxJson j = new AjaxJson();
        j.setMsg("流程审核成功");
        j.setSuccess(true);
        j.setErrorCode(ErrorCode.code_1004);
        try {
            Map map = new HashMap();
            String name = "";
            String title="审批";
            String content="";
            String remarks="";
            String aliase = "";
            String pushStatus="";
            if(procDefKey.equals("leave")){
                name = "请假";
                Leave leave = leaveService.getById(approvalId);
                leave.setAct(act);
                leave.setComment(comment);
                leaveService.auditSave(leave);
                map = leaveService.getLeaveById(approvalId,type);
                String leaveType = map.get("leaveType").toString();
                String startTime = map.get("startTime").toString();
                String endTime = map.get("endTime").toString();
                if (leaveType.equals("1")){
                    //1:事假、2:病假、3:调休、4:年假、5:婚假、6:产假、7:其他
                    leaveType = "事假";
                }else if (leaveType.equals("2")){
                    leaveType = "病假";
                }else if (leaveType.equals("3")){
                    leaveType = "调休";
                }else if (leaveType.equals("4")){
                    leaveType = "年假";
                }else if (leaveType.equals("5")){
                    leaveType = "婚假";
                }else if (leaveType.equals("6")){
                    leaveType = "产假";
                }else if (leaveType.equals("7")){
                    leaveType = "其他";
                }
                remarks = "请假类型："+leaveType+ "\n"
                        +"开始时间："+startTime+ "\n"
                        +"结束时间："+endTime;
            }else if(procDefKey.equals("goout")){
                name = "外出";
                GoOut out = goOutService.getById(approvalId);
                out.setAct(act);
                out.setComment(comment);
                goOutService.auditSave(out);
                map = goOutService.getGoOutById(approvalId,type);
                String gooutDay = map.get("gooutDay").toString();
                String startTime = map.get("startTime").toString();
                String endTime = map.get("endTime").toString();
                remarks =  "开始时间："+startTime+ "\n"
                        +"结束时间："+endTime+ "\n"
                        +"外出天数："+gooutDay;
            }else if(procDefKey.equals("evection")){
                name = "出差";
                OaEvection oaEvection = oaEvectionService.getById(approvalId);
                oaEvection.setAct(act);
                oaEvection.setComment(comment);
                oaEvectionService.auditSave(oaEvection);
                map = oaEvectionService.getEvectionById(approvalId, type);
                String address = map.get("address").toString();
                String startTime = map.get("startTime").toString();
                String endTime = map.get("endTime").toString();
                remarks =  "开始时间："+startTime+ "\n"
                        +"结束时间："+endTime+ "\n"
                        +"出差地点:"+address;
            }else if(procDefKey.equals("overtime")){
                name = "加班";
                WorkOvertimeForm workOvertimeForm = workOvertimeFormService.getById(approvalId);
                workOvertimeForm.setAct(act);
                workOvertimeForm.setComment(comment);
                workOvertimeFormService.auditSave(workOvertimeForm);
                map = workOvertimeFormService.getOverTimeById(approvalId, type);
                String longTime = map.get("longTime").toString();
                String startTime = map.get("startTime").toString();
                String endTime = map.get("endTime").toString();
                remarks =  "开始时间："+startTime+ "\n"
                        +"结束时间："+endTime+ "\n"
                        +"加班时长（小时）："+longTime;
            }else if(procDefKey.equals("sealform")){
                name = "用印";
                WorkSealForm workSealForm = workSealFormService.getById(approvalId);
                workSealForm.setAct(act);
                workSealForm.setComment(comment);
                workSealFormService.auditSave(workSealForm);
                map = workSealFormService.getUseSealById(approvalId, type);
                remarks = "用印部门："+ map.get("officeName")+"\n"
                        +"经办人："+map.get("user")+ "\n"
                        +"日期："+map.get("applicationDate");
            }else if(procDefKey.equals("pettyCash")){
                name = "备用金";
                WorkPettyCash workPettyCash = workPettyCashService.getById(approvalId);
                workPettyCash.setAct(act);
                workPettyCash.setComment(comment);
                workPettyCashService.auditSave(workPettyCash);
                map = workPettyCashService.getPettyCashById(approvalId, type);
                remarks = "备用金申请部门："+map.get("applicantOfficeName")+ "\n"
                        +"申请人"+map.get("applicantName")+"\n"
                        +"使用日期："+ map.get("useDateStr")+"\n"
                        +"归还日期："+ map.get("returnDateStr");
            }else if(procDefKey.equals("payment")){
                name = "付款";
                WorkPayment workPayment = workPaymentService.getById(approvalId);
                workPayment.setAct(act);
                workPayment.setComment(comment);
                workPaymentService.auditSave(workPayment);
                map = workPaymentService.getPaymentById(approvalId, type);
                remarks = "付款申请部门："+map.get("officeName")+ "\n"
                        +"付款事由："+map.get("reason")+"\n"
                        +"付款金额："+map.get("amount");
            }else if(procDefKey.equals("reimbur")){
                name = "报销";
                WorkReimbur workReimbur = workReimburService.getById(approvalId);
                workReimbur.setAct(act);
                workReimbur.setComment(comment);
                workReimburService.auditSave(workReimbur);
                map = workReimburService.getReimburById(approvalId, type);
                remarks = "报销申请部门："+map.get("officeName")+ "\n"
                       +"报销总额："+map.get("totalAmount");
            }else if(procDefKey.equals("oaPerformance")){
                name = "绩效自评";
                OaPerformance oaPerformance = oaPerformanceService.getById(approvalId);
                oaPerformance.setAct(act);
                oaPerformance.setComment(comment);
                oaPerformanceService.auditSave(oaPerformance);
                map = oaPerformanceService.getBuyById(approvalId, type);
                remarks = "绩效自评申请部门："+map.get("officeName")+ "\n"
                        +"绩效自评内容："+map.get("lastPerformance")+"\n"
                        +"绩效自评时间："+map.get("createDate");
            }else if(procDefKey.equals("allApprove")){
                name = "通用审批";
                OaAll oaAll = oaAllService.getById(approvalId);
                oaAll.setAct(act);
                oaAll.setComment(comment);
                oaAllService.auditSave(oaAll);
                map = oaAllService.getLeaveById(approvalId, type);
                remarks = "通用审批申请部门："+map.get("officeName")+ "\n"
                        +"通用审批内容："+map.get("applyContent")+"\n"
                        +"通用审批详情："+map.get("approveDetail");
            }
            else if(procDefKey.equals("oaBuy")){
                name = "采购";
                OaBuy oaBuy = oaBuyService.getById(approvalId);
                oaBuy.setAct(act);
                oaBuy.setComment(comment);
                oaBuyService.auditSave(oaBuy);
                map = oaBuyService.getBuyById(approvalId, type);
                remarks = "采购申请部门："+map.get("officeName")+ "\n"
                        +"采购申请原由："+map.get("applyContent")+"\n"
                        +"采购申请时间："+map.get("createDate");
            }

            String status = map.get("status").toString();
            Pushinfo pushinfo = new Pushinfo();
            Map extras = new HashMap();
            if (status.equals("3") || status.equals("4") ){
                extras.put("id", approvalId);
                extras.put("procDefKey",procDefKey);
                aliase = map.get("users").toString();
                pushinfo.setCurrentUser(UserUtils.getUser());
                pushinfo.setUserId(UserUtils.getUser().getId());
                if (status.equals("3")){
                    content = "你的"+name+"申请已通过";
                    extras.put("type", "4003");
                    pushinfo.setType("4003");
                    pushStatus = "审批通过";
                }else {
                    content = "你的"+name+"申请已驳回";
                    extras.put("type", "4004");
                    pushinfo.setType("4004");
                    pushStatus = "审批驳回";
                }

            }else if (status.equals("2")){
                content = map.get("userName").toString()+"的"+name+"申请需要你审批";
                extras.put("id", approvalId);
                extras.put("procDefKey",procDefKey);
                pushinfo.setCurrentUser(UserUtils.getUser());
                pushinfo.setUserId(UserUtils.getUser().getId());
                extras.put("type", "4001");
                pushinfo.setType("4001");
                pushStatus = "审批中";
                List<Map> process = (List<Map>)map.get("process");
                for (Map maps:process){
                    if(maps.get("activityName").equals("待审批")){
                        aliase = maps.get("userId").toString();
                    }
                }
            }
            pushinfo.setPushId(approvalId);
            pushinfo.setTitle(title);
            pushinfo.setRemarks(remarks);
            pushinfo.setContent(content);
            pushinfo.setPushUserId(aliase);
            pushinfo.setRemarks(remarks);
            pushinfo.setStatus(pushStatus);
            pushinfo.setAddcontent(procDefKey);
            pushinfo.setParentType("singleApproval");
            User user = UserUtils.get(aliase);
            pushinfo.setMobile("ios,android");
            if (user!=null && user.getCompany()!=null && user.getCompany().getId()!=null){
                pushinfo.setCompanyId(user.getCompany().getId());
            }
            pushinfoService.save(pushinfo);
            Pushinfo selectPush = new Pushinfo();
            selectPush.setPushId(approvalId);
            selectPush.setPushUserId(UserUtils.getUser().getId());
            List<Pushinfo> pushinfos = pushinfoService.findList(selectPush);
            if (pushinfos!=null && pushinfos.size()!=0){
                Pushinfo push = pushinfos.get(0);
                push.setStatus(pushStatus);
                pushinfoService.save(push);
            }
            JPushClientUtil.sendNotificationToAlias(title, content, extras, aliase);
            j.put("data",map);
            actTaskService.isProcessEnd(procInsId);
        }catch (Exception e){
            j.setErrorCode(ErrorCode.code_2004);
            j.setMsg("流程审核失败");
            j.setSuccess(false);
            logger.info("e="+e.getMessage());
        }
        return j;
    }

    /**
     * 删除申请
     * @param
     * @return
     */
    @Transactional
    @RequestMapping(value = "deleteTask", method=RequestMethod.GET)
    @ResponseBody
    public AjaxJson deleteTask(HttpServletRequest request, HttpServletResponse response) {
        HashMap<String, String> requestMap = findRequestMap(request);
        String taskId = requestMap.get("taskId");
        String id = requestMap.get("approvalId");
        String procInsId = requestMap.get("procInsId");
        String procDefKey = requestMap.get("procDefKey");
        String deleteReason = requestMap.get("deleteReason");
        AjaxJson j = new AjaxJson();
        try {
            actTaskService.endProcessInstance(procInsId, deleteReason);
            if(procDefKey.equals("leave")){
                Leave leave = new Leave();
                leave.setId(id);
                leaveService.delete(leave);
            }else if(procDefKey.equals("goout")){
                GoOut out = new GoOut();
                out.setId(id);
                goOutService.delete(out);
            }else if(procDefKey.equals("evection")){
                OaEvection oaEvection = new OaEvection();
                oaEvection.setId(id);
                oaEvectionService.delete(oaEvection);
            }else if(procDefKey.equals("overtime")){
                WorkOvertimeForm workOvertimeForm = new WorkOvertimeForm();
                workOvertimeForm.setId(id);
                workOvertimeFormService.delete(workOvertimeForm);
            }else if(procDefKey.equals("sealform")){
                WorkSealForm workSealForm = new WorkSealForm();
                workSealForm.setId(id);
                workSealFormService.delete(workSealForm);
            }else if(procDefKey.equals("pettyCash")){
                WorkPettyCash workPettyCash = new WorkPettyCash();
                workPettyCash.setId(id);
                workPettyCashService.delete(workPettyCash);
            }else if(procDefKey.equals("payment")){
                WorkPayment workPayment = new WorkPayment();
                workPayment.setId(id);
                workPaymentService.delete(workPayment);
            }else if(procDefKey.equals("reimbur")){
                WorkReimbur workReimbur = new WorkReimbur();
                workReimbur.setId(id);
                workReimburService.delete(workReimbur);
            }else if(procDefKey.equals("oaPerformance")){
                OaPerformance oaPerformance = new OaPerformance();
                oaPerformance.setId(id);
                oaPerformanceService.delete(oaPerformance);
            }else if(procDefKey.equals("allApprove")){
                OaAll oaAll = new OaAll();
                oaAll.setId(id);
                oaAllService.delete(oaAll);
            }
            else if(procDefKey.equals("oaBuy")){
                OaBuy oaBuy = new OaBuy();
                oaBuy.setId(id);
                oaBuyService.delete(oaBuy);
            }
            actTaskService.deleteTask(taskId,deleteReason);

            j.setMsg("删除申请成功");
            j.setErrorCode(ErrorCode.code_1004);
        }catch (Exception e){
            j.setErrorCode(ErrorCode.code_2004);
            logger.info("e="+e.getMessage());
            j.setMsg("删除申请失败");
            j.setSuccess(false);
        }
        return j;
    }

    /**
     * 撤销申请
     * @param
     * @return
     */
    @Transactional
    @RequestMapping(value = "endProcessInstance", method=RequestMethod.POST)
    @ResponseBody
    public AjaxJson endProcessInstance(HttpServletRequest request, HttpServletResponse response) {
        HashMap<String, String> requestMap = findRequestMap(request);
        String procInsId = requestMap.get("procInsId");
        String id = requestMap.get("approvalId");
        String procDefKey = requestMap.get("procDefKey");
        String deleteReason = requestMap.get("deleteReason");
        AjaxJson j = new AjaxJson();
        try {
            if(procDefKey.equals("leave")){
                Leave leave = leaveService.getById(id);
                leave.setStatus("5");
                leave.preUpdate();
                leaveService.update(leave);
                Map map = leaveService.getLeaveById(id,"1");
                map.put("state","3");
                j.put("data",map);
            }else if(procDefKey.equals("goout")){
                GoOut out = goOutService.getById(id);
                out.setStatus("5");
                out.preUpdate();
                goOutService.update(out);
                Map map = goOutService.getGoOutById(id, "1");
                map.put("state","3");
                j.put("data",map);
            }else if(procDefKey.equals("evection")){
                OaEvection oaEvection = oaEvectionService.getById(id);
                oaEvection.setStatus("5");
                oaEvection.preUpdate();
                oaEvectionService.update(oaEvection);
                Map map = oaEvectionService.getEvectionById(id,"1");
                map.put("state","3");
                j.put("data",map);
            }else if(procDefKey.equals("overtime")){
                WorkOvertimeForm workOvertimeForm = workOvertimeFormService.getById(id);
                workOvertimeForm.setStatus("5");
                workOvertimeForm.preUpdate();
                workOvertimeFormService.update(workOvertimeForm);
                Map map = workOvertimeFormService.getOverTimeById(id,"1");
                map.put("state","3");
                j.put("data",map);
            }else if(procDefKey.equals("sealform")){
                WorkSealForm workSealForm = workSealFormService.getById(id);
                workSealForm.setStatus("5");
                workSealForm.preUpdate();
                workSealFormService.update(workSealForm);
                Map map = workSealFormService.getUseSealById(id,"1");
                map.put("state","3");
                j.put("data",map);
            }
            else if(procDefKey.equals("pettyCash")){
                WorkPettyCash workPettyCash = workPettyCashService.getById(id);
                workPettyCash.setStatus("5");
                workPettyCash.preUpdate();
                workPettyCashService.update(workPettyCash);
                Map map = workPettyCashService.getPettyCashById(id,"1");
                map.put("state","3");
                j.put("data",map);
            }
            else if(procDefKey.equals("payment")){
                WorkPayment workPayment = workPaymentService.getById(id);
                workPayment.setStatus("5");
                workPayment.preUpdate();
                workPaymentService.update(workPayment);
                Map map = workPaymentService.getPaymentById(id,"1");
                map.put("state","3");
                j.put("data",map);
            }
            else if(procDefKey.equals("reimbur")){
                WorkReimbur workReimbur = workReimburService.getById(id);
                workReimbur.setStatus("5");
                workReimbur.preUpdate();
                workReimburService.update(workReimbur);
                Map map = workReimburService.getReimburById(id,"1");
                map.put("state","3");
                j.put("data",map);
            }
            else if(procDefKey.equals("oaPerformance")){
                OaPerformance oaPerformance = oaPerformanceService.getById(id);
                oaPerformance.setStatus("5");
                oaPerformance.preUpdate();
                oaPerformanceService.update(oaPerformance);
                Map map = oaPerformanceService.getBuyById(id,"1");
                map.put("state","3");
                j.put("data",map);
            }
            else if(procDefKey.equals("allApprove")){
                OaAll oaAll = oaAllService.getById(id);
                oaAll.setStatus("5");
                oaAll.preUpdate();
                oaAllService.update(oaAll);
                Map map = oaAllService.getLeaveById(id,"1");
                map.put("state","3");
                j.put("data",map);
            }
            else if(procDefKey.equals("oaBuy")){
                OaBuy oaBuy = oaBuyService.getById(id);
                oaBuy.setStatus("5");
                oaBuy.preUpdate();
                oaBuyService.update(oaBuy);
                Map map = oaBuyService.getBuyById(id,"1");
                map.put("state","3");
                j.put("data",map);
            }
            actTaskService.endProcessInstance(procInsId, deleteReason);
            WorkProjectNotify workProjectNotify = new WorkProjectNotify();
            workProjectNotify.setNotifyId(id);
            workProjectNotifyService.readByNotifyId(workProjectNotify);
            pushinfoService.updateDelflagByPushId(id,"1");
            ApprovalCopy approvalCopy = new ApprovalCopy();
            approvalCopy.setApprovalId(id);
            approvalCopyService.deletes(approvalCopy);
            logger.error("---------------");
            logger.error(j.getJsonStr());
            logger.error("---------------");
            j.setMsg("撤销申请成功");
            j.setErrorCode(ErrorCode.code_1004);
        }catch (Exception e){
            j.setErrorCode(ErrorCode.code_2004);
            logger.info(e.getMessage());
            j.setMsg("撤销申请失败");
            j.setSuccess(false);
        }
        return j;
    }

    /**
     * 重新申请
     * @param
     * @return
     */
    @Transactional
    @RequestMapping(value = "aginProcessInstance", method=RequestMethod.POST)
    @ResponseBody
    public AjaxJson aginProcessInstance(HttpServletRequest request, HttpServletResponse response)throws Exception {
        HashMap<String, String> requestMap = findRequestMap(request);
        Map<String, Object> variables = Maps.newHashMap();
        String taskId = requestMap.get("taskId");
        String taskName = requestMap.get("taskName");
        String taskDefKey = requestMap.get("taskDefKey");
        String procInsId = requestMap.get("procInsId");
        String procDefId = requestMap.get("procDefId");
        String procDefKey = requestMap.get("procDefKey");
        String flag = requestMap.get("flag");
        String approvalId = requestMap.get("approvalId");
        String comment = URLDecoder.decode(requestMap.get("comment")==null?"":requestMap.get("comment"), "UTF-8");
        AjaxJson j = new AjaxJson();

        try {
            if(taskDefKey.equals("modifyApply")){
                Act act = new Act();
                act.setTaskId(taskId);
                act.setTaskName(taskName);
                act.setTaskDefKey(taskDefKey);
                act.setProcInsId(procInsId);
                act.setProcDefId(procDefId);
                act.setFlag(flag);
                act.setComment(comment);

                if(procDefKey.equals("leave")){
                    Leave leave = leaveService.getById(approvalId);
                    leave.setAct(act);
                    leave.setComment(comment);
                    leave.setStatus("1");
                    leaveService.save(leave,variables,"1");
                }else if(procDefKey.equals("goout")){
                    GoOut out = goOutService.getById(approvalId);
                    out.setAct(act);
                    out.setComment(comment);
                    out.setStatus("1");
                    goOutService.save(out, variables,"1");
                }else if(procDefKey.equals("evection")){
                    OaEvection oaEvection = oaEvectionService.getById(approvalId);
                    oaEvection.setAct(act);
                    oaEvection.setComment(comment);
                    oaEvection.setStatus("1");
                    oaEvectionService.submit(oaEvection, variables,"1");
                }else if(procDefKey.equals("overtime")){
                    WorkOvertimeForm workOvertimeForm = workOvertimeFormService.getById(approvalId);
                    workOvertimeForm.setAct(act);
                    workOvertimeForm.setComment(comment);
                    workOvertimeForm.setStatus("1");
                    workOvertimeFormService.present(workOvertimeForm, variables,"1");
                }else if(procDefKey.equals("sealform")){
                    WorkSealForm workSealForm = workSealFormService.getById(approvalId);
                    workSealForm.setAct(act);
                    workSealForm.setStatus("1");
                    workSealForm.setComment(comment);
                    workSealFormService.save(workSealForm, variables,"1");
                }else if(procDefKey.equals("joincompany")){
                    Useroffice companyinfo = companyinfoService.getById(approvalId);
                    companyinfo.setAct(act);
                    companyinfo.setStatus("1");
                    companyinfo.setComment(comment);
                    companyinfoService.save(companyinfo, variables);
                }else if(procDefKey.equals("pettyCash")){
                    WorkPettyCash workPettyCash = workPettyCashService.getById(approvalId);
                    workPettyCash.setAct(act);
                    workPettyCash.setStatus("1");
                    workPettyCash.setComment(comment);
                    workPettyCashService.save(workPettyCash, variables,"1");
                }else if(procDefKey.equals("payment")){
                    WorkPayment workPayment = workPaymentService.getById(approvalId);
                    workPayment.setAct(act);
                    workPayment.setStatus("1");
                    workPayment.setComment(comment);
                    workPaymentService.save(workPayment, variables,"1");
                }else if(procDefKey.equals("reimubr")){
                    WorkReimbur workReimbur = workReimburService.getById(approvalId);
                    workReimbur.setAct(act);
                    workReimbur.setStatus("1");
                    workReimbur.setComment(comment);
                    workReimburService.save(workReimbur, variables,"1");
                }
                else if(procDefKey.equals("oaPerformance")){
                    OaPerformance oaPerformance = oaPerformanceService.getById(approvalId);
                    oaPerformance.setAct(act);
                    oaPerformance.setStatus("1");
                    oaPerformance.setComment(comment);
                    oaPerformanceService.save(oaPerformance, variables);
                }
                else if(procDefKey.equals("allApprove")){
                    OaAll oaAll = oaAllService.getById(approvalId);
                    oaAll.setAct(act);
                    oaAll.setStatus("1");
                    oaAll.setComment(comment);
                    oaAllService.save(oaAll, variables);
                }
                else if(procDefKey.equals("oaBuy")){
                    OaBuy oaBuy = oaBuyService.getById(approvalId);
                    oaBuy.setAct(act);
                    oaBuy.setStatus("1");
                    oaBuy.setComment(comment);
                    oaBuyService.save(oaBuy, variables);
                }
                Pushinfo selectPush = new Pushinfo();
                selectPush.setPushId(approvalId);
                List<Pushinfo> pushinfos = pushinfoService.findList(selectPush);
                if (pushinfos!=null && pushinfos.size()!=0){
                    pushinfoService.updateStatusByPushId(approvalId,"0");
                }
                String companyId = UserUtils.getSelectCompany().getId();
                //该公司下所有的角色
                List<Role> roleList = systemService.getRoleList("",companyId);
                Role role = new Role();
                if (roleList!=null && roleList.size()!=0){
                    for (Role r :roleList){
                        //要的是管理员
                        if (StringUtils.isNotBlank(r.getEnname()) && r.getEnname().equals("gly")){
                            role = r;
                            break;
                        }
                    }
                }
                //该公司下拥有管理员角色的所有员工
                List<User> userList = userDao.findUserByRole(role);
                //该公司下拥有管理员角色的所有员工
                List<String> assigneeList = new ArrayList<String>();
                if (userList!=null && userList.size()!=0) {
                    for (User user : userList) {
                        assigneeList.add(user.getId());
                    }
                }
                String title = "企业申请";
                String content="团队申请已重新发起";
                Map extras = new HashMap();

                extras.put("type", "2002");
                extras.put("id", approvalId);
                extras.put("userId",UserUtils.getUser().getId());
                extras.put("userName",UserUtils.getUser().getName());
                //向所有管理员发送推送
                int num = 0 ;
                if(assigneeList!=null && assigneeList.size()>0){
                    for(String alias : assigneeList){
                        if(com.jeeplus.common.utils.StringUtils.isNotBlank(alias)){
                            boolean b = JPushClientUtil.sendNotificationToAlias(title, content, extras, alias);
                            if(b) num++;
                        }
                    }
                }

                if (num>0){
                    j.setMsg("再次/撤销申请审核成功!");
                }else {
                    j.setMsg("当前流程不能再次/撤销申请!");
                    j.setErrorCode(ErrorCode.code_2006);
                    j.setSuccess(false);
                }
                j.setMsg("再次/撤销申请审核成功");
                j.setErrorCode(ErrorCode.code_1004);
            }else {
                j.setErrorCode(ErrorCode.code_1009);
                j.setMsg("当前流程不能再次/撤销申请");
                j.setSuccess(false);
            }

        }catch (Exception e){
            j.setErrorCode(ErrorCode.code_2004);
            j.setMsg("再次/撤销申请审核失败");
            j.setSuccess(false);
            logger.info("e="+e.getMessage());
        }
        return j;
    }

    /**
     * 提醒一下
     */
    @Transactional
    @ResponseBody
    @RequestMapping(value = "remindApprover", method=RequestMethod.GET)
    public AjaxJson remindApprover (String userId,String procDefKey,String approvalId,HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes)throws Exception
    {
        AjaxJson j=new AjaxJson();
        String name = "";
        String remarks = "";
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        //c.add(Calendar.DATE, - 3);
        c.add(Calendar.HOUR, - 3);
        Date now = c.getTime();
        Pushinfo push = new Pushinfo();
        push.setPushUserId(userId);
        push.setStatus("催办中");
        push.setUserId(UserUtils.getUser().getId());
        push.setPushId(approvalId);
        List<Pushinfo> list = pushinfoService.findList(push);
        Date updatedate = new Date();
        boolean count = false;
        if (list!=null &&list.size()==1){
            Pushinfo p = list.get(0);
            count = true;
            updatedate = p.getUpdateDate();
        }
        if(procDefKey.equals("leave")){
            Leave leave = leaveService.getById(approvalId);
            name = "请假申请";
            if (leave.getStatus().equals("1") || leave.getStatus().equals("2")){
                leave.setStatus("6");
                leaveService.update(leave);
            }else if (leave.getStatus().equals("6") && count){
                if (now.getTime()<updatedate.getTime()){
                    j.setMsg("提醒失败，提醒间隔为三小时");
                    j.setErrorCode(ErrorCode.code_2003);
                    return j;
                }
            }

        }else if(procDefKey.equals("goout")){
            name = "外出申请";
            GoOut out = goOutService.getById(approvalId);
            if (out.getStatus().equals("1") || out.getStatus().equals("2")) {
                out.setStatus("6");
                goOutService.update(out);
            }else if (out.getStatus().equals("6") && count){
                if (now.getTime()<updatedate.getTime()){
                    j.setMsg("提醒失败，提醒间隔为三小时");
                    j.setErrorCode(ErrorCode.code_2003);
                    return j;
                }
            }
        }else if(procDefKey.equals("evection")){
            name = "出差申请";
            OaEvection oaEvection = oaEvectionService.getById(approvalId);
            if (oaEvection.getStatus().equals("1") || oaEvection.getStatus().equals("2")) {
                oaEvection.setStatus("6");
                oaEvectionService.update(oaEvection);
            }else if (oaEvection.getStatus().equals("6") && count){
                if (now.getTime()<updatedate.getTime()){
                    j.setMsg("提醒失败，提醒间隔为三小时");
                    j.setErrorCode(ErrorCode.code_2003);
                    return j;
                }
            }
        }else if(procDefKey.equals("overtime")){
            name = "加班申请";
            WorkOvertimeForm workOvertimeForm = workOvertimeFormService.getById(approvalId);
            if (workOvertimeForm.getStatus().equals("1") || workOvertimeForm.getStatus().equals("2")) {
                workOvertimeForm.setStatus("6");
                workOvertimeFormService.save(workOvertimeForm);
            }else if (workOvertimeForm.getStatus().equals("6") && count){
                if (now.getTime()<updatedate.getTime()){
                    j.setMsg("提醒失败，提醒间隔为三小时");
                    j.setErrorCode(ErrorCode.code_2003);
                    return j;
                }
            }
        }else if(procDefKey.equals("sealform")){
            name = "用印申请";
            WorkSealForm workSealForm = workSealFormService.getById(approvalId);
            if (workSealForm.getStatus().equals("1") || workSealForm.getStatus().equals("2")) {
                workSealForm.setStatus("6");
                workSealFormService.save(workSealForm);
            }else if (workSealForm.getStatus().equals("6") && count){
                if (now.getTime()<updatedate.getTime()){
                    j.setMsg("提醒失败，提醒间隔为三小时");
                    j.setErrorCode(ErrorCode.code_2003);
                    return j;
                }
            }
        }else if(procDefKey.equals("pettyCash")){
            name = "备用金申请";
            WorkPettyCash workPettyCash = workPettyCashService.getById(approvalId);
            if (workPettyCash.getStatus().equals("1") || workPettyCash.getStatus().equals("2")) {
                workPettyCash.setStatus("6");
                workPettyCashService.save(workPettyCash);
            }else if (workPettyCash.getStatus().equals("6") && count){
                if (now.getTime()<updatedate.getTime()){
                    j.setMsg("提醒失败，提醒间隔为三小时");
                    j.setErrorCode(ErrorCode.code_2003);
                    return j;
                }
            }
        }else if(procDefKey.equals("payment")){
            name = "付款申请";
            WorkPayment workPayment = workPaymentService.getById(approvalId);
            if (workPayment.getStatus().equals("1") || workPayment.getStatus().equals("2")) {
                workPayment.setStatus("6");
                workPaymentService.save(workPayment);
            }else if (workPayment.getStatus().equals("6") && count){
                if (now.getTime()<updatedate.getTime()){
                    j.setMsg("提醒失败，提醒间隔为三小时");
                    j.setErrorCode(ErrorCode.code_2003);
                    return j;
                }
            }
        }else if(procDefKey.equals("reimbur")){
            name = "报销申请";
            WorkReimbur workReimbur = workReimburService.getById(approvalId);
            if (workReimbur.getStatus().equals("1") || workReimbur.getStatus().equals("2")) {
                workReimbur.setStatus("6");
                workReimburService.save(workReimbur);
            }else if (workReimbur.getStatus().equals("6") && count){
                if (now.getTime()<updatedate.getTime()){
                    j.setMsg("提醒失败，提醒间隔为三小时");
                    j.setErrorCode(ErrorCode.code_2003);
                    return j;
                }
            }
        }
        else if(procDefKey.equals("oaPerformance")){
            name = "绩效自评";
            OaPerformance oaPerformance = oaPerformanceService.getById(approvalId);
            if (oaPerformance.getStatus().equals("1") || oaPerformance.getStatus().equals("2")) {
                oaPerformance.setStatus("6");
                oaPerformanceService.save(oaPerformance);
            }else if (oaPerformance.getStatus().equals("6") && count){
                if (now.getTime()<updatedate.getTime()){
                    j.setMsg("提醒失败，提醒间隔为三小时");
                    j.setErrorCode(ErrorCode.code_2003);
                    return j;
                }
            }
        }
        else if(procDefKey.equals("allApprove")){
            name = "通用审批";
            OaAll oaAll = oaAllService.getById(approvalId);
            if (oaAll.getStatus().equals("1") || oaAll.getStatus().equals("2")) {
                oaAll.setStatus("6");
                oaAllService.save(oaAll);
            }else if (oaAll.getStatus().equals("6") && count){
                if (now.getTime()<updatedate.getTime()){
                    j.setMsg("提醒失败，提醒间隔为三小时");
                    j.setErrorCode(ErrorCode.code_2003);
                    return j;
                }
            }
        }
        else if(procDefKey.equals("oaBuy")){
            name = "采购申请";
            OaBuy oaBuy = oaBuyService.getById(approvalId);
            if (oaBuy.getStatus().equals("1") || oaBuy.getStatus().equals("2")) {
                oaBuy.setStatus("6");
                oaBuyService.save(oaBuy);
            }else if (oaBuy.getStatus().equals("6") && count){
                if (now.getTime()<updatedate.getTime()){
                    j.setMsg("提醒失败，提醒间隔为三小时");
                    j.setErrorCode(ErrorCode.code_2003);
                    return j;
                }
            }
        }

        String title="审批";
        String content = UserUtils.getUser().getName()+"的"+ name+"需要你审批";
        Map extras = new HashMap();
        extras.put("type", "4002");
        extras.put("id", approvalId);
        extras.put("procDefKey", procDefKey);
        String alias = userId;
        Pushinfo selectPush = new Pushinfo();
        selectPush.setPushId(approvalId);
        selectPush.setPushUserId(alias);
        List<Pushinfo> pushinfos = pushinfoService.findList(selectPush);
        if (pushinfos!=null && pushinfos.size()!=0){
            Pushinfo pushs = pushinfos.get(0);
            pushs.setType("4002");
            pushs.setStatus("催办中");
            pushinfoService.save(pushs);
            boolean b = JPushClientUtil.sendNotificationToAlias(title, content, extras, alias);
            if (b){
                j.setMsg("提醒成功");
                j.setErrorCode(ErrorCode.code_1004);
            }else {
                j.setMsg("提醒失败");
                j.setErrorCode(ErrorCode.code_2006);
                j.setSuccess(false);
            }
            return j;
        }else {
            j.setMsg("提醒失败");
            j.setErrorCode(ErrorCode.code_2006);
            j.setSuccess(false);
            return j;
        }


    }

    @RequestMapping(value={"workReportShow"}, method={RequestMethod.GET})
    @ResponseBody
    public AjaxJson workReportShow(HttpServletRequest request, HttpServletResponse response, Model model)
            throws Exception
    {
        AjaxJson j = new AjaxJson();
        try {
            WorkReport workReport = new WorkReport();
            User user = UserUtils.getUser();
            workReport.setSelf(true);
            workReport.setCompanyId(user.getComId());
            workReport.setCreateBy(user);
            List<WorkReport> list = workReportService.findGetList(workReport);
            int count = 0;
            if(list==null){
                j.setSuccess(false);
                j.setErrorCode(ErrorCode.code_2005);
                j.setMsg("获取显示失败");
                j.put("data", "0");
            }else {
                for(WorkReport workReport1:list){
                    String readFlag = workReport1.getReadFlag();
                    if (readFlag.equals("0")){
                        count ++;
                    }
                }
                j.put("count",count+"");
                j.setErrorCode(ErrorCode.code_1004);
                j.setMsg("获取显示成功");
            }

        } catch (Exception e) {
            j.setErrorCode(ErrorCode.code_2004);
            j.setMsg("获取显示失败");
            j.put("data", "");
            logger.info("---------e:" + e.getMessage());
        }
        return j;
    }

    @RequestMapping(value={"aduitShow"}, method={RequestMethod.GET})
    @ResponseBody
    public AjaxJson aduitShow(HttpServletRequest request, HttpServletResponse response, Model model)
            throws Exception
    {
        AjaxJson j = new AjaxJson();
        try {
            Office company = UserUtils.getSelectCompany();
            ApprovalCopy approvalCopy = new ApprovalCopy();
            approvalCopy.setCCId(UserUtils.getUser().getId());
            approvalCopy.setDelFlag("0");
            approvalCopy.setReadFlag("0");
            List<ApprovalCopy> list = approvalCopyService.findList(approvalCopy);
            Act act = new Act();
            List<Act> actList = actTaskService.todoLists(act);
            Map<String,String> map = new HashMap<String,String>();
            int count = 0;
            int actCount = 0;
            if(list!=null && list.size()!=0){
                for(ApprovalCopy a:list){
                    String readFlag = a.getReadFlag();
                    String type = a.getType();
                    String approvalId = a.getApprovalId();
                    if (readFlag.equals("0")){
                        if (type.equals("leave")) {
                            Leave leave = leaveService.getById(approvalId);
                            if (leave != null && company.getId().equals(leave.getCompanyId())) {
                                count++;
                            }
                        } else if (type.equals("goout")) {
                            GoOut goOut = goOutService.getById(approvalId);
                            if (goOut != null && company.getId().equals(goOut.getCompanyId())) {
                                count++;
                            }
                        } else if (type.equals("evection")) {
                            OaEvection evection = oaEvectionService.getById(approvalId);
                            if (evection != null && company.getId().equals(evection.getCompanyId())) {
                                count++;
                            }
                        } else if (type.equals("sealform")) {
                            WorkSealForm useseal = workSealFormService.getById(approvalId);
                            if (useseal != null && company.getId().equals(useseal.getCompanyId())) {
                                count++;
                            }
                        } else if (type.equals("overtime")) {
                            WorkOvertimeForm overtime = workOvertimeFormService.getById(approvalId);
                            if (overtime != null && company.getId().equals(overtime.getCompanyId())) {
                                count++;
                            }
                        }else if (type.equals("pettyCash")) {
                            WorkPettyCash workPettyCash = workPettyCashService.getById(approvalId);
                            if (workPettyCash != null && company.getId().equals(workPettyCash.getCompanyId())) {
                                count++;
                            }
                        }else if (type.equals("payment")) {
                            WorkPayment workPayment = workPaymentService.getById(approvalId);
                            if (workPayment != null && company.getId().equals(workPayment.getCompanyId())) {
                                count++;
                            }
                        }else if (type.equals("reimbur")) {
                            WorkReimbur workReimbur = workReimburService.getById(approvalId);
                            if (workReimbur != null && company.getId().equals(workReimbur.getCompanyId())) {
                                count++;
                            }
                        }
                        else if (type.equals("oaPerformance")) {
                            OaPerformance oaPerformance = oaPerformanceService.getById(approvalId);
                            if (oaPerformance != null && company.getId().equals(oaPerformance.getCompanyId())) {
                                count++;
                            }
                        }
                        else if (type.equals("allApprove")) {
                            OaAll oaAll = oaAllService.getById(approvalId);
                            if (oaAll != null && company.getId().equals(oaAll.getCompanyId())) {
                                count++;
                            }
                        }
                        else if (type.equals("oaBuy")) {
                            OaBuy oaBuy = oaBuyService.getById(approvalId);
                            if (oaBuy != null && company.getId().equals(oaBuy.getCompanyId())) {
                                count++;
                            }
                        }
                    }
                }
            }
            map.put("copyCount",count+"");
            j.setMsg("获取显示成功");
            j.setErrorCode(ErrorCode.code_1004);
            if(actList!=null &&actList.size()!=0){
                for (int i=0;i< actList.size();i++) {
                    Act act1 = actList.get(i);
                    String procDef =act1.getProcDef().toString();
                    if(act1.getProcInsId()!=null && !procDef.equals("")){
                        Leave leave = new Leave();
                        WorkOvertimeForm overtimeform  = new WorkOvertimeForm();
                        GoOut goout = new GoOut();
                        WorkSealForm sealform = new WorkSealForm();
                        OaEvection evection = new OaEvection();
                        WorkPettyCash workPettyCash = new WorkPettyCash();
                        WorkPayment workPayment = new WorkPayment();
                        WorkReimbur workReimbur = new WorkReimbur();
                        OaPerformance oaPerformance = new OaPerformance();
                        OaAll oaAll = new OaAll();
                        OaBuy oaBuy = new OaBuy();
                        if (procDef.contains("leave")){
                            leave = leaveService.getByProcessInstanceId(act1.getProcInsId());
                        }else if (procDef.contains("overtime")){
                            overtimeform  = workOvertimeFormService.getByProcessInstanceId(act1.getProcInsId());
                        }else if (procDef.contains("goout")){
                            goout = goOutService.getByProcessInstanceId(act1.getProcInsId());
                        }else if (procDef.contains("sealform")){
                            sealform = workSealFormService.getByProcessInstanceId(act1.getProcInsId());
                        }else if (procDef.contains("evection")){
                            evection = oaEvectionService.getByProcessInstanceId(act1.getProcInsId());
                        }else if (procDef.contains("pettyCash")){
                            workPettyCash = workPettyCashService.getByProcessInstanceId(act1.getProcInsId());
                        }else if (procDef.contains("payment")){
                            workPayment = workPaymentService.getByProcessInstanceId(act1.getProcInsId());
                        }else if (procDef.contains("reimbur")){
                            workReimbur = workReimburService.getByProcessInstanceId(act1.getProcInsId());
                        }
                        else if (procDef.contains("oaPerformance")){
                            oaPerformance = oaPerformanceService.getByProcessInstanceId(act1.getProcInsId());
                        }else if (procDef.contains("allApprove")){
                            oaAll = oaAllService.getByProcessInstanceId(act1.getProcInsId());
                        }
                        else if (procDef.contains("oaBuy")){
                            oaBuy = oaBuyService.getByProcessInstanceId(act1.getProcInsId());
                        }

                        if(leave!=null && leave.getId()!=null && company.getId().equals(leave.getCompanyId())){
                            actCount++;
                        }
                        if(overtimeform!=null && overtimeform.getId()!=null && company.getId().equals(overtimeform.getCompanyId())){
                            actCount++;
                        }
                        if(goout!=null  && goout.getId()!=null && company.getId().equals(goout.getCompanyId())) {
                            actCount++;
                        }
                        if(sealform!=null && sealform.getId()!=null && company.getId().equals(sealform.getCompanyId())) {
                            actCount++;
                        }
                        if(evection!=null  && evection.getId()!=null && company.getId().equals(evection.getCompanyId())) {
                            actCount++;
                        }
                        if(workPettyCash!=null && workPettyCash.getId()!=null && company.getId().equals(workPettyCash.getCompanyId())) {
                            actCount++;
                        }
                        if(workPayment!=null && workPayment.getId()!=null && company.getId().equals(workPayment.getCompanyId())) {
                            actCount++;
                        }
                        if(workReimbur!=null && workReimbur.getId()!=null && company.getId().equals(workReimbur.getCompanyId())) {
                            actCount++;
                        }
                        if(oaPerformance!=null && oaPerformance.getId()!=null && company.getId().equals(oaPerformance.getCompanyId())) {
                            actCount++;
                        }
                        if(oaAll!=null && oaAll.getId()!=null && company.getId().equals(oaAll.getCompanyId())) {
                            actCount++;
                        }
                        if(oaBuy!=null && oaBuy.getId()!=null && company.getId().equals(oaBuy.getCompanyId())) {
                            actCount++;
                        }
                    }
                }
            }
            map.put("aduitCount",actCount+"");
            j.setMsg("获取显示成功");
            j.setErrorCode(ErrorCode.code_1004);
            j.put("data",map);
        } catch (Exception e) {
            j.setErrorCode(ErrorCode.code_2004);
            j.setMsg("获取显示失败");
            j.put("data", "");
            logger.info("---------e:" + e.getMessage());
        }
        return j;
    }

    @RequestMapping(value={"workShow"}, method={RequestMethod.GET})
    @ResponseBody
    public AjaxJson workShow(HttpServletRequest request, HttpServletResponse response, Model model)
            throws Exception
    {
        AjaxJson j = new AjaxJson();
        try {
            Office company = UserUtils.getSelectCompany();
            ApprovalCopy approvalCopy = new ApprovalCopy();
            approvalCopy.setCCId(UserUtils.getUser().getId());
            approvalCopy.setDelFlag("0");
            approvalCopy.setReadFlag("0");
            List<ApprovalCopy> list = approvalCopyService.findList(approvalCopy);
            WorkReport workReport = new WorkReport();
            User user = UserUtils.getUser();
            workReport.setCreateBy(user);
            workReport.setSelf(true);
            workReport.setCompanyId(user.getComId());
            List<WorkReport> workReportList = workReportService.findGetList(workReport);
            OaNotify oaNotify = new OaNotify();
            //oaNotify.setCreateBy(user);
            oaNotify.setStatus("1");
            oaNotify.setCompany(new Office(user.getComId()));
            oaNotify.setSelf(true);
            oaNotify.setReadFlag("1");
            oaNotify.setCurrentUser(user);
            List<OaNotify> oaNotifyList= oaNotifyService.findList(oaNotify);
            Act act = new Act();
            List<Act> listAct = actTaskService.todoLists(act);
            Map<String,String> map = new HashMap<String,String>();
            boolean aduitStatus = false;
            j.setMsg("获取显示成功");
            /*if(list!=null &&list.size()!=0){
                for(ApprovalCopy a:list){
                    String readFlag = a.getReadFlag();
                    String type = a.getType();
                    String approvalId = a.getApprovalId();
                    if (readFlag.equals("0")){
                        if (type.equals("leave")) {
                            Leave leave = leaveService.getById(approvalId);
                            if (leave != null && company.getId().equals(leave.getCompanyId())) {
                                aduitStatus = true;
                                break;
                            }
                        } else if (type.equals("goout")) {
                            GoOut goOut = goOutService.getById(approvalId);
                            if (goOut != null && company.getId().equals(goOut.getCompanyId())) {
                                aduitStatus = true;
                                break;
                            }
                        } else if (type.equals("evection")) {
                            OaEvection evection = oaEvectionService.getById(approvalId);
                            if (evection != null && company.getId().equals(evection.getCompanyId())) {
                                aduitStatus = true;
                                break;
                            }
                        } else if (type.equals("sealform")) {
                            WorkSealForm useseal = workSealFormService.getById(approvalId);
                            if (useseal != null && company.getId().equals(useseal.getCompanyId())) {
                                aduitStatus = true;
                                break;
                            }
                        } else if (type.equals("overtime")) {
                            WorkOvertimeForm overtime = workOvertimeFormService.getById(approvalId);
                            if (overtime != null && company.getId().equals(overtime.getCompanyId())) {
                                aduitStatus = true;
                                break;
                            }
                        }else if (type.equals("pettyCash")) {
                            WorkPettyCash workPettyCash = workPettyCashService.getById(approvalId);
                            if (workPettyCash != null && company.getId().equals(workPettyCash.getCompanyId())) {
                                aduitStatus = true;
                                break;
                            }
                        }else if (type.equals("payment")) {
                            WorkPayment workPayment = workPaymentService.getById(approvalId);
                            if (workPayment != null && company.getId().equals(workPayment.getCompanyId())) {
                                aduitStatus = true;
                                break;
                            }
                        }else if (type.equals("reimbur")) {
                            WorkReimbur workReimbur = workReimburService.getById(approvalId);
                            if (workReimbur != null && company.getId().equals(workReimbur.getCompanyId())) {
                                aduitStatus = true;
                                break;
                            }
                        }
                        else if (type.equals("oaPerformance")) {
                            OaPerformance oaPerformance = oaPerformanceService.getById(approvalId);
                            if (oaPerformance != null && company.getId().equals(oaPerformance.getCompanyId())) {
                                aduitStatus = true;
                                break;
                            }
                        } else if (type.equals("allApprove")) {
                            OaAll oaAll = oaAllService.getById(approvalId);
                            if (oaAll != null && company.getId().equals(oaAll.getCompanyId())) {
                                aduitStatus = true;
                                break;
                            }
                        }
                        else if (type.equals("oaBuy")) {
                            OaBuy oaBuy = oaBuyService.getById(approvalId);
                            if (oaBuy != null && company.getId().equals(oaBuy.getCompanyId())) {
                                aduitStatus = true;
                                break;
                            }
                        }
                    }
                }
            }*/
            /*if(listAct!=null &&listAct.size()!=0){
                for (int i=0;i< listAct.size();i++) {
                    Act act1 = listAct.get(i);
                    String procDef =act1.getProcDef().toString();
                    if(act1.getProcInsId()!=null && !procDef.equals("")){
                        Leave leave = new Leave();
                        WorkOvertimeForm overtimeform  = new WorkOvertimeForm();
                        GoOut goout = new GoOut();
                        WorkSealForm sealform = new WorkSealForm();
                        OaEvection evection = new OaEvection();
                        WorkPettyCash workPettyCash = new WorkPettyCash();
                        WorkPayment workPayment = new WorkPayment();
                        WorkReimbur workReimbur = new WorkReimbur();
                        OaPerformance oaPerformance = new OaPerformance();
                        OaAll oaAll = new OaAll();
                        OaBuy oaBuy = new OaBuy();
                        if (procDef.contains("leave")){
                            leave = leaveService.getByProcessInstanceId(act1.getProcInsId());
                        }else if (procDef.contains("overtime")){
                            overtimeform  = workOvertimeFormService.getByProcessInstanceId(act1.getProcInsId());
                        }else if (procDef.contains("goout")){
                            goout = goOutService.getByProcessInstanceId(act1.getProcInsId());
                        }else if (procDef.contains("sealform")){
                            sealform = workSealFormService.getByProcessInstanceId(act1.getProcInsId());
                        }else if (procDef.contains("evection")){
                            evection = oaEvectionService.getByProcessInstanceId(act1.getProcInsId());
                        }else if (procDef.contains("pettyCash")){
                            workPettyCash = workPettyCashService.getByProcessInstanceId(act1.getProcInsId());
                        }else if (procDef.contains("payment")){
                            workPayment = workPaymentService.getByProcessInstanceId(act1.getProcInsId());
                        }else if (procDef.contains("reimbur")){
                            workReimbur = workReimburService.getByProcessInstanceId(act1.getProcInsId());
                        }
                        else if (procDef.contains("oaPerformance")){
                            oaPerformance = oaPerformanceService.getByProcessInstanceId(act1.getProcInsId());
                        } else if (procDef.contains("allApprove")){
                            oaAll = oaAllService.getByProcessInstanceId(act1.getProcInsId());
                        }
                        else if (procDef.contains("oaBuy")){
                            oaBuy = oaBuyService.getByProcessInstanceId(act1.getProcInsId());
                        }
                        if(leave!=null && leave.getId()!=null && company.getId().equals(leave.getCompanyId())){
                            aduitStatus = true;
                            break;
                        }
                        if(overtimeform!=null && overtimeform.getId()!=null && company.getId().equals(overtimeform.getCompanyId())){
                            aduitStatus = true;
                            break;
                        }
                        if(goout!=null  && goout.getId()!=null && company.getId().equals(goout.getCompanyId())) {
                            aduitStatus = true;
                            break;
                        }
                        if(sealform!=null && sealform.getId()!=null && company.getId().equals(sealform.getCompanyId())) {
                            aduitStatus = true;
                            break;
                        }
                        if(evection!=null  && evection.getId()!=null && company.getId().equals(evection.getCompanyId())) {
                            aduitStatus = true;
                            break;
                        }
                        if(workPettyCash!=null && workPettyCash.getId()!=null && company.getId().equals(workPettyCash.getCompanyId())) {
                            aduitStatus = true;
                            break;
                        }
                        if(workPayment!=null && workPayment.getId()!=null && company.getId().equals(workPayment.getCompanyId())) {
                            aduitStatus = true;
                            break;
                        }
                        if(workReimbur!=null && workReimbur.getId()!=null && company.getId().equals(workReimbur.getCompanyId())) {
                            aduitStatus = true;
                            break;
                        }
                        if(oaPerformance!=null && oaPerformance.getId()!=null && company.getId().equals(oaPerformance.getCompanyId())) {
                            aduitStatus = true;
                            break;
                        }
                        if(oaAll!=null && oaAll.getId()!=null && company.getId().equals(oaAll.getCompanyId())) {
                            aduitStatus = true;
                            break;
                        }
                        if(oaBuy!=null && oaBuy.getId()!=null && company.getId().equals(oaBuy.getCompanyId())) {
                            aduitStatus = true;
                            break;
                        }
                    }
                }
            }*/
            if (aduitStatus){
                map.put("aduitStatus","0");
            }else {
                map.put("aduitStatus","1");
            }
            if (workReportList!=null && workReportList.size()!=0){
                for(WorkReport workReport1:workReportList){
                    String readFlag = workReport1.getReadFlag();
                    map.put("workReportStatus","1");
                    if (readFlag.equals("0")){
                        map.put("workReportStatus","0");
                        break;
                    }
                }
            }else {
                map.put("workReportStatus","1");
            }
            if (oaNotifyList!=null && oaNotifyList.size()!=0){
                map.put("oaNotifyStatus","0");
            }else {
                map.put("oaNotifyStatus","1");
            }
            j.put("data",map);
        } catch (Exception e) {
            j.setErrorCode(ErrorCode.code_2004);
            j.setMsg("获取显示失败");
            j.put("data", "");
            logger.info("---------e:" + e.getMessage());
        }
        return j;
    }
}
