package com.sys.bus.jx.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.aop.Enhancer;
import com.jfinal.core.ActionKey;
import com.jfinal.core.Controller;
import com.jfinal.json.Json;
import com.sys.bus.hr.model.Person;
import com.sys.bus.jx.service.*;
import com.sys.bus.model.*;
import com.sys.bus.sys.wx.WxMsgType;
import com.sys.core.model.DataBean;
import com.sys.core.model.PageBean;
import com.sys.core.utils.ConstUtil;
import com.sys.core.utils.R;
import com.sys.core.utils.SessionUtil;
import com.sys.core.utils.Tool;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;


/**
 * 绩效管理控制器
 */
public class JxManagerController extends Controller {
    static JxManagerService jxManagerService = Enhancer.enhance(JxManagerService.class);
    static JxCycleService jxCycleService = Enhancer.enhance(JxCycleService.class);
    static OrgService orgService = Enhancer.enhance(OrgService.class);
    static JxCommonService jxCommonService = Enhancer.enhance(JxCommonService.class);
    static WflogService wflogService = Enhancer.enhance(WflogService.class);
    static WxMsgService wxMsgService = Enhancer.enhance(WxMsgService.class);
    static WxPersonService wxPersonService = Enhancer.enhance(WxPersonService.class);
    static PersonManagerService personManagerService = Enhancer.enhance(PersonManagerService.class);
    static PerformanceService performanceService = Enhancer.enhance(PerformanceService.class);

    /**
     * 跳转绩效管理列表页面
     */
    @ActionKey("/jx/toJxManagerPage")
    public void toJxManagerPage() {
        Person person = SessionUtil.getCurrentPerson();
        boolean isAdmin = SessionUtil.isAdmin();
        //获取所有状态为生效的考核周期
        List<Cycle> jxCycleList = jxCycleService.getJxCycleList();
        this.setAttr("jxCycleList", jxCycleList);
        if (isAdmin) {
            List<Org> enableOrgList = orgService.getOrgList();
            this.setAttr("enableOrgList", enableOrgList);
        } else {
            //获取员工有效的考核组织
            List<Org> enableOrgList = orgService.getOrgList(person.getId());
            this.setAttr("enableOrgList", enableOrgList);
        }
        this.getSession().removeAttribute("jxAllEntry_query");
        Object jxmanagerQuery = getSession().getAttribute("jxManager_query");
        if(jxmanagerQuery!=null){
            JSONObject json =JSONObject.parseObject(jxmanagerQuery.toString());

            this.setAttr("cycle_name", json.getString("cycle_name"));
            this.setAttr("khOrg", json.getString("khOrg"));
            this.setAttr("page", json.getInteger("page"));
            this.setAttr("limit", json.getInteger("limit"));
        }



        this.render("jxManagerList.html");
    }

    /**
     * 获取绩效管理列表数据
     *
     * @throws Exception
     */
    @ActionKey("/jx/getJxManagerList")
    public void getJxManagerList() throws Exception {
        String cycleName = this.getPara("cycle_name");
        String khOrg = this.getPara("khOrg");
        int pageNumber = this.getParaToInt("page", 1);
        int pageSize = this.getParaToInt("limit", ConstUtil.PAGE_SIZE);

       // String manual = this.getPara("manual");
        if(cycleName !=null){
            JSONObject json = new JSONObject();
            json.put("cycle_name", cycleName);
            json.put("khOrg", khOrg);
            json.put("page", pageNumber);
            json.put("limit", pageSize);

            getSession().setAttribute("jxManager_query",json.toJSONString());
        }else if(getSession().getAttribute("jxManager_query")!=null){
            JSONObject json =JSONObject.parseObject(getSession().getAttribute("jxManager_query").toString());
            cycleName = json.getString("cycle_name");
            khOrg = json.getString("khOrg");
            pageNumber = json.getInteger("page");
            pageSize = json.getInteger("limit");
        }

        PageBean pageBean = jxManagerService.getJxManagerList(SessionUtil.getCurrentPerson(), pageNumber, pageSize, cycleName, khOrg, SessionUtil.isAdmin());
        this.renderJson(pageBean);
    }

    /**
     * 跳转到考核人员页面
     */
    @ActionKey("/jx/toJxEntryPage")
    public void toJxEntryPage() {
        List<Entry> jxEntryList = new ArrayList<Entry>();
        String entryno = this.getPara("entryno");
        String personName = this.getPara("personName");
        String back = this.getPara("back");
        if(StringUtils.isNotBlank(back)){
            this.setAttr("back",back);
        }
        //Integer appType= 9;
        if (!StringUtils.isBlank(entryno)) {
            jxEntryList = jxCommonService.getJxEntryListAndManager(entryno, personName);
            EntryNo entryNo = jxCommonService.getEntryNoById(entryno);
            if (entryNo != null) {
                this.setAttr("orgid", entryNo.getEntrynoOrgid());
                this.setAttr("orgname", entryNo.getEntrynoOrgname());
                this.setAttr("cycleid", entryNo.getEntrynoCycleid());
                this.setAttr("cyclename", entryNo.getEntrynoCyclename());
                this.setAttr("apptype", entryNo.getEntrynoAppnode());
                this.setAttr("entryno", entryno);
                this.setAttr("entryNo", entryNo);
            }

            for (Entry entry : jxEntryList) {
                // String atype = entry.getEntryApptype();
                //int typeValue = 0;
//                try {
//                    //typeValue = Integer.valueOf(atype);
//                }catch (Exception e){
//                }
                // if(typeValue<appType){
                // appType = typeValue;
                // }
                // if(appType==0){
                //    break;
                // }
            }
//            this.setAttr("appType",appType.toString());
        }
        this.setAttr("jxEntryList", jxEntryList);
        this.setAttr("personName", personName);
        //获取所有状态为生效的考核周期
        List<Cycle> jxCycleList = jxCycleService.getJxCycleList();
        this.setAttr("jxCycleList", jxCycleList);
        //获取员工有效的考核组织
        List<Org> enableOrgList = orgService.getEnableOrgList(SessionUtil.getCurrentPerson().getId());
        this.setAttr("enableOrgList", enableOrgList);
        //this.setAttr("apptype",type);
        this.render("jxEntryList.html");
    }

    /**
     * 跳转到kpi页面
     * 绩效经理查看kpi
     */
    @ActionKey("/jx/toJxKpiPage")
    public void toJxKpiPage() {
        String type = this.getPara("type");
        String entryid = this.getPara("entryid");
        String appeal = this.getPara("appeal");
        String back = this.getPara("back");
        String orgId = this.getPara("orgId");

        Entry jxEntry = jxCommonService.getJxentryByIdAndAttachment(entryid);
        List<Kpi> kpiList = jxCommonService.getKpiList(entryid);
        //--绩效节点类型    0编辑 5 指标审核中  7待启动评分  1 评分中 2 待启动评级  3评级中   9完成
        String entryNoStatus = jxCommonService.getEntryNoByEntryId(entryid).getEntrynoAppnode();
        boolean beforScoreWf = false;
        if (entryNoStatus.equals("5") || entryNoStatus.equals("7")) {
            beforScoreWf = true;
        }
        this.setAttr("histFlag",performanceService.existHistoryKpi(entryid));
        this.setAttr("wfLog", wflogService.getWfLog(entryid));
        this.setAttr("beforScoreWf", beforScoreWf);
        this.setAttr("kpiList", kpiList);
        this.setAttr("jxEntry", jxEntry);
        //this.setAttr("orgId",orgId);
        this.setAttr("apptype", type);
        if("1".equals(jxEntry.getEntryMbstatus())){
            this.setAttr("makeBetter",true);
        }
        if(StringUtils.isNotBlank(appeal)){
            this.setAttr("appeal",true);
        }
        if(StringUtils.isNotBlank(back)){
            this.setAttr("back",back);
        }
        BigDecimal entryScorelv1 = jxEntry.getEntryScorelv1();
        BigDecimal entryScorelv2 = jxEntry.getEntryScorelv2();
        BigDecimal entryScorelv3 = jxEntry.getEntryScorelv3();
        this.setAttr("lv1",entryScorelv1!=null);
        this.setAttr("lv2",entryScorelv2!=null);
        this.setAttr("lv3",entryScorelv3!=null);

        Integer entryAppManagerLv = jxEntry.getEntryAppManagerLv();
        this.setAttr("lv"+entryAppManagerLv,true);
        //this.setAttr("isAllKpi",true);
        this.render("jxKpiList.html");
    }

    /**
     * 保存考核人员kpi
     */
    @ActionKey("/jx/saveJxKpis")
    public void saveJxKpis() throws Exception {
        JSONObject jsonObj = Tool.getRequestObject(this.getRequest());
        String entryid = jxManagerService.saveJxKpis(jsonObj);
        this.renderJson(R.isOK("entryid", entryid));
    }

    /**
     * 保存考核人员信息
     */
    @ActionKey("/jx/saveJxEntrys")
    public void saveJxEntrys() throws Exception {
        JSONObject jsonObj = Tool.getRequestObject(this.getRequest());
        String entryno = jxManagerService.saveJxEntrys(jsonObj, SessionUtil.getCurrentPerson());
        this.renderJson(R.isOK("entryno", entryno));
    }

    /**
     * 绩效经理启动考核评分
     */
    @ActionKey("/jx/startJxEntrysWf")
    public void startJxEntrysWf() throws Exception {
        JSONObject jsonObj = Tool.getRequestObject(this.getRequest());
        String entryno = jxManagerService.startJxEntrysWf(jsonObj, SessionUtil.getCurrentPerson());
        this.renderJson(R.isOK("entryno", entryno));
    }

    /**
     * 无需处理申诉
     */
    @ActionKey("/jx/appealNoUpdate")
    public void appealNoUpdate() throws Exception {
        String entryId = this.getPara("entryId");
        String reason = this.getPara("reason");
        jxManagerService.appealNoUpdate(entryId,reason);
        this.renderJson(R.isOK());
    }
    /**
     * 处理申诉
     */
    @ActionKey("/jx/appealUpdate")
    public void appealUpdate() throws Exception {
        String entryId = this.getPara("entryId");
        String scoreSumAppeal = this.getPara("scoreSumAppeal");
        String updateReason = this.getPara("updateReason");
        String ratingAppeal = this.getPara("ratingAppeal");
        jxManagerService.appealUpdate(entryId,scoreSumAppeal,ratingAppeal,updateReason);
        this.renderJson(R.isOK());
    }


    /**
     * 发送微信消息
     */
    @ActionKey("/jx/sendWxMsg")
    public void sendWxMsg() throws Exception {
//        String type = this.getPara("type");
        String id = this.getPara("id");
        String type = this.getPara("type");
      // 1 被考核人编辑指标  2上级领导审核指标中 3自评中  4评分中  5 待确认  6修改指标后待确认  7面谈
//        String idType = this.getPara("idType");
        WxMsgType msgType = null;
        String personId = null;
        String personName = null;
        Entry entry = Entry.dao.findById(id);
        personId = entry.getEntryKhpersonid();
        personName = entry.getEntryKhpersonname();
        if("1".equals(type)){
            msgType = WxMsgType.GRMB;
        }else if("2".equals(type)){
            msgType = WxMsgType.SJSH;
            personId = entry.getEntrySuperId();
            personName = entry.getEntrySuperName();
        }else if("3".equals(type)){
            msgType = WxMsgType.GRZP;
        }else if("4".equals(type)){
            msgType = WxMsgType.LDPF;
            personId = entry.getEntrySuperId();
            personName = entry.getEntrySuperName();
        }else if("5".equals(type)){
            msgType = WxMsgType.GRJG;
        }else if("6".equals(type)){
            msgType = WxMsgType.GRJGSS;
        }else if("7".equals(type)){
            msgType = WxMsgType.JXMT;
            personId = entry.getEntrySuperId();
            personName = entry.getEntrySuperName();
        }
        wxMsgService.sendEntryWxMsg(entry,msgType,personId,personName,true);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", "success");
        this.renderJson(jsonObject);
    }



//    /**
//     * 批量发送微信消息
//     */
//    @ActionKey("/jx/sendAllWxMsg")
//    public void sendAllWxMsg() throws Exception {
//        String type = this.getPara("type");
//        String entryNo = this.getPara("entryNo");
////        String idType = this.getPara("idType");
//        int count = jxManagerService.sendWxMsg(entryNo, type);
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("code", "success");
//        jsonObject.put("count", count);
//        this.renderJson(jsonObject);
//    }

    /**
     * 绩效经理启动绩效指标
     */
    @ActionKey("/jx/startJxKpisWf")
    public void startJxKpisWf() throws Exception {
        JSONObject jsonObj = Tool.getRequestObject(this.getRequest());
        String entryno = jxManagerService.startJxKpisWf(jsonObj, SessionUtil.getCurrentPerson());
        this.renderJson(R.isOK("entryno", entryno));
    }

    /**
     * 删除kpi明细
     */
    @ActionKey("/jx/delJxKpi")
    public void delJxKpi() {
        String kpiid = this.getPara("kpiid");

        jxCommonService.delJxKpi(kpiid, SessionUtil.getCurrentPerson());
        this.renderJson(R.isOK());
    }

    /**
     * 删除考核人员信息
     */
    @ActionKey("/jx/delJxEntry")
    public void delJxEntry() {
        String entryid = this.getPara("entryid");
        jxCommonService.delJxEntry(entryid, SessionUtil.getCurrentPerson());
        this.renderJson(R.isOK());
    }
    /**
     * 刷新审批人
     */
    @ActionKey("/jx/refreshManager")
    public void refreshManager() {
        String entryId = this.getPara("entryId");
        jxManagerService.refreshManager(entryId, SessionUtil.getCurrentPerson());
        this.renderJson(R.isOK());
    }

    /**
     * 离职处理
     */
    @ActionKey("/jx/quitJxEntry")
    public void quitJxEntry() {
        String entryid = this.getPara("entryid");
        jxManagerService.quitJxEntry(entryid, SessionUtil.getCurrentPerson());
        this.renderJson(R.isOK());
    }

    /**
     * 删除考核信息
     */
    @ActionKey("/jx/delJxEntrysByEntryNo")
    public void delJxEntrysByEntryNo() {
        boolean admin = (boolean) this.getSession().getAttribute("admin");
        String entryNo = this.getPara("entryno");
        jxManagerService.delJxEntrysByEntryNo(entryNo, admin, SessionUtil.getCurrentPerson());
        this.renderJson(R.isOK());
    }

    /**
     * 绩效专员确认人员考核结果
     */
    @ActionKey("/jx/confirmJxEntrys")
    public void confirmJxEntrys() {
        String entryno = this.getPara("entryno");
        jxManagerService.confirmJxEntrys(entryno);
        this.renderJson(R.isOK("entryno", entryno));
    }

    /**
     * 绩效专员批量确认人员考核结果
     */
    @ActionKey("/jx/confirmJxEntry")
    public void confirmJxEntry() {
        String entryId = this.getPara("entryId");
        jxManagerService.confirmJxEntry(entryId);
        this.renderJson(R.isOK());
    }

//    /**
//     * 绩效经理打回评分人
//     */
//    @ActionKey("/jx/backGradingResult")
//    public void backGradingResult() {
//        String kpiid = this.getPara("kpiid");
//        String backReason = this.getPara("reason");
//        String entryid = jxManagerService.backGradingResult(kpiid, backReason, SessionUtil.getCurrentPerson());
//        this.renderJson(R.isOK("entryid", entryid));
//    }

    /**
     * 跳转到调整评分数据
     */
    @ActionKey("/jx/toModifyJxEntry")
    public void toKpiHistPage(){
        String entryId = this.getPara("entryId");
        Entry entry = jxCommonService.getJxentryById(entryId);
        String entryCycleid = entry.getEntryCycleid();
        String entryOrgid = entry.getEntryKhdeptid();
        this.setAttr("entry",entry);
        Boolean permission = jxCommonService.getPermission(entryCycleid, entryOrgid);
        this.setAttr("permission",permission);
        this.render("jxModifyEntry.html");
    }
    /**
     * 流程要求完成时间
     */
    @ActionKey("/jx/toAppTimePage")
    public void toAppTimePage(){
        String entryno = this.getPara("entryno");
        EntryNo entryNo = jxCommonService.getEntryNoById(entryno);
        this.setAttr("entryNo",entryNo);

        this.render("jxAppTime.html");
    }
    //流程要求完成时间
    @ActionKey("/jx/saveAppTime")
    public void saveAppTime()throws Exception {
        JSONObject jsonObj = Tool.getRequestObject(this.getRequest());
        EntryNo entryNO = JSON.toJavaObject(jsonObj, EntryNo.class);
        JSONObject result = new JSONObject();
        result.put("code",0);
        try{
            jxManagerService.saveAppTime(entryNO,SessionUtil.getCurrentPerson());
        }catch (Exception e){
            result.put("code",-1);
            result.put("msg",e.getMessage());
        }

        this.renderJson(result);
    }
    @ActionKey("/jx/modifyEntry")
    public void modifyEntry()throws Exception {
        JSONObject jsonObj = Tool.getRequestObject(this.getRequest());
        Entry entry = JSON.toJavaObject(jsonObj, Entry.class);
        String reason = jsonObj.getString("reason");
        JSONObject result = new JSONObject();
        result.put("code",0);
        try{
            jxManagerService.modifyEntry(entry,reason,SessionUtil.getCurrentPerson());
        }catch (Exception e){
            result.put("code",-1);
            result.put("msg",e.getMessage());
        }

        this.renderJson(result);
    }

//    /**
//     * 绩效经理退回KPI到考核人自评
//     */
//    @ActionKey("/jx/backSelf")
//    public void  backSelf() throws Exception {
//        String kpiId = this.getPara("kpiId");
//        String backReason = this.getPara("reason");
//        jxManagerService.backSelf(kpiId,backReason, SessionUtil.getCurrentPerson());
//        this.renderJson(R.isOK());
//    }

    /**
     * 绩效经理退回考核人自评
     */
    @ActionKey("/jx/backSelfEntry")
    public void backSelfEntry() throws Exception {
        String entryId = this.getPara("entryId");
        String backReason = this.getPara("reason");
        jxManagerService.backSelfEntry(entryId, backReason, SessionUtil.getCurrentPerson());
        this.renderJson(R.isOK());
    }

//    /**
//     * 绩效经理退回评分
//     */
//    @ActionKey("/jx/backScoreEntry")
//    public void backScoreEntry() throws Exception {
//        String entryId = this.getPara("entryId");
//        String backReason = this.getPara("reason");
//        jxManagerService.backScoreEntry(entryId, backReason, SessionUtil.getCurrentPerson());
//        this.renderJson(R.isOK());
//    }
    /**
     * 绩效经理调整到评分
     */
    @ActionKey("/jx/toScoreEntry")
    public void toScoreEntry() throws Exception {
        String entryId = this.getPara("entryId");
        String reason = this.getPara("reason");
        jxManagerService.toScoreEntry(entryId, reason, SessionUtil.getCurrentPerson());
        this.renderJson(R.isOK());
    }
    /**
     * 绩效经理调整层级评分审批
     */
    @ActionKey("/jx/toLevelScoreEntry")
    public void toLevelScoreEntry() throws Exception {
        String entryId = this.getPara("entryId");
        String reason = this.getPara("reason");
        String levelStr = this.getPara("level");
        int level = Integer.parseInt(levelStr);
        jxManagerService.toLevelScoreEntry(entryId, reason, level,SessionUtil.getCurrentPerson());
        this.renderJson(R.isOK());
    }
    /**
     * 跳转到复制考核数据页面
     */
    @ActionKey("/jx/toCopyJxEntrysPage")
    public void toCopyJxEntrysPage() {
        //获取所有状态为生效的考核周期
        List<Cycle> jxCycleList = jxCycleService.getJxCycleList();
        String entryno = this.getPara("entryno");
        this.setAttr("jxCycleList", jxCycleList);
        this.setAttr("entryno", entryno);
        this.render("copyJxEntrys.html");
    }

    /**
     * 复制考核数据
     */
    @ActionKey("/jx/copyJxEntrys")
    public void copyJxEntrys() {
        String entryno = this.getPara("entryno");
        String khcycle = this.getPara("khcycle");
        jxManagerService.copyJxEntrys(entryno, khcycle, SessionUtil.getCurrentPerson());
        this.renderJson(R.isOK());

    }

    /**
     * 查询所有周期所有人的绩效信息
     */
    @ActionKey("/jx/toJxAllEntryQueryPage")
    public void toJxAllEntryQueryPage() {
        Person person = SessionUtil.getCurrentPerson();
        boolean isAdmin = SessionUtil.isAdmin();
        //获取所有状态为生效的考核周期
        List<Cycle> jxCycleList = jxCycleService.getJxCycleList();
        this.setAttr("jxCycleList", jxCycleList);
        if (isAdmin) {
            List<Org> enableOrgList = orgService.getOrgList();
            this.setAttr("enableOrgList", enableOrgList);
        } else {
            //获取员工有效的考核组织
            List<Org> enableOrgList = orgService.getOrgList(person.getId());
            this.setAttr("enableOrgList", enableOrgList);
        }
        this.getSession().removeAttribute("jxManager_query");
        Object jxAllEntryQuery = getSession().getAttribute("jxAllEntry_query");
        if(jxAllEntryQuery!=null){
            JSONObject json =JSONObject.parseObject(jxAllEntryQuery.toString());

            this.setAttr("cycle_name", json.getString("cycle_name"));
            this.setAttr("khOrg", json.getString("khOrg"));
            this.setAttr("khPerson", json.getString("khPerson"));
            this.setAttr("page", json.getInteger("page"));
            this.setAttr("limit", json.getInteger("limit"));
        }

        this.render("jxAllEntryQueryList.html");
    }

    @ActionKey("/jx/getJxAllEntryQueryList")
    public void getJxAllEntryQueryList() {
        String cycleName = this.getPara("cycle_name");
        String khOrg = this.getPara("khOrg");
        String khPerson = this.getPara("khPerson");
        int pageNumber = this.getParaToInt("page", 1);
        int pageSize = this.getParaToInt("limit", ConstUtil.PAGE_SIZE);

        if(cycleName !=null){
            JSONObject json = new JSONObject();
            json.put("cycle_name", cycleName);
            json.put("khOrg", khOrg);
            json.put("khPerson", khPerson);
            json.put("page", pageNumber);
            json.put("limit", pageSize);

            getSession().setAttribute("jxAllEntry_query",json.toJSONString());
        }else if(getSession().getAttribute("jxAllEntry_query")!=null){
            JSONObject json =JSONObject.parseObject(getSession().getAttribute("jxAllEntry_query").toString());
            cycleName = json.getString("cycle_name");
            khPerson = json.getString("khPerson");
            khOrg = json.getString("khOrg");
            pageNumber = json.getInteger("page");
            pageSize = json.getInteger("limit");
        }

        PageBean pageBean = jxManagerService.getJxAllEntryQueryList(SessionUtil.getCurrentPerson(), pageNumber, pageSize, cycleName, khOrg, khPerson, SessionUtil.isAdmin());
        this.renderJson(pageBean);
    }

//    /**
//     * 发送邮件
//     * type = 1  考核人编辑kpi
//     * type = 2  上级领导审核kpi
//     * type = 3  自评
//     * type = 4  评分
//     */
//    @ActionKey("/jx/sendMail")
//    public void sendMail(){
//        String type = this.getPara("type");
//        String entryId = this.getPara("entryId");
//        String kpiId = this.getPara("kpiId");
//        JSONObject result = new JSONObject();
//        result.put("code", "success");
//        if(StringUtils.isNotBlank(entryId)){
//            mailService.sendEntryEmail(entryId,type);
//        }else if(StringUtils.isNotBlank(kpiId)){
//            mailService.sendKpiEmail(kpiId);
//        }else{
//            result.put("code", "fail");
//        }
//
//        this.renderJson(result);
//
//    }

    /**
     * 流程追踪
     */
    @ActionKey("/jx/toTrackWf")
    public void toTrackWf() {
        String entryNo = this.getPara("entryNo");
        //自评中
        List<Entry> selfEvaluationEntryList = jxCommonService.getSelfEvaluationEntryList(entryNo);
        //评分中
        List<Entry> gradingEntryList = jxCommonService.getGradingEntryList(entryNo);
        //考核人编辑KPI中
        Entry entry = new Entry();
        entry.setEntryNo(entryNo);
        entry.setEntryApptype("5");
        List<Entry> mySelfKpiEntryList = jxCommonService.getJxEntryByWhere(entry);
        //上级领导审核KPI中
        entry.setEntryApptype("6");
        List<Entry> selfKpiEntryList = jxCommonService.getJxEntryByWhere(entry);
//        List<RatingEntry> deptRatingList = ratingService.getRatingWfDept(entryNo);
//        List<RatingEntry> centerRatingList = ratingService.getRatingWfCenter(entryNo);
        //待确认

        //申诉

        this.setAttr("selfEvaluationEntryList", selfEvaluationEntryList);
        this.setAttr("gradingEntryList", gradingEntryList);
        this.setAttr("mySelfKpiEntryList", mySelfKpiEntryList);
        this.setAttr("selfKpiEntryList", selfKpiEntryList);

        this.setAttr("entryNo", entryNo);
//        this.setAttr("deptRatingList",deptRatingList);
//        this.setAttr("centerRatingList",centerRatingList);
        this.render("trackWf.html");
    }
    /**
     * 流程追踪
     */
    @ActionKey("/jx/toTrackWf2")
    public void toTrackWf2() {
        String entryNo = this.getPara("entryNo");
        //待确认
        List<Entry> confirmEntryList = performanceService.getConfirmEntrys(entryNo);
        //待确认
        List<Entry> confirmEntryList2 = performanceService.getConfirmEntrys2(entryNo);
        //申诉中
        List<Entry> appealEntryList = performanceService.getAppealEntrys(entryNo);

        this.setAttr("confirmEntryList", confirmEntryList);
        this.setAttr("confirmEntryList2", confirmEntryList2);
        this.setAttr("appealEntryList", appealEntryList);
        this.setAttr("entryNo", entryNo);
//        this.setAttr("deptRatingList",deptRatingList);
//        this.setAttr("centerRatingList",centerRatingList);
        this.render("trackWf2.html");
    }
    /**
     * 选择基础kpi数据
     */
    @ActionKey("/jx/toSelectBaseKpi")
    public void toSelectBaseKpi() {
        this.setAttr("entryid", this.getPara("entryid"));
        this.setAttr("type", this.getPara("type"));
        this.render("selectBaseKpi.html");
    }

    /**
     * 跳转到绩效考核创建页面
     */
    @ActionKey("/jx/toAddJxKh")
    public void toAddJxKh() {
        this.render("jxKhAdd.html");
    }


    //更新上级人员
    @ActionKey("/jx/updateSuperPerson")
    public void updateSuperPerson() {
        String entryId = this.getPara("entryId");
        String superPersonId = this.getPara("superPersonId");
        String superPersonName = this.getPara("superPersonName");
        jxManagerService.updateSuperPerson(entryId, superPersonId, superPersonName);
        this.renderJson(R.isOK());
    }

    @ActionKey("/jx/getWxPersonList")
    public void getWxPersonPage() {
        String name = this.getPara("name");
        int pageNumber = this.getParaToInt("page", 1);
        int pageSize = this.getParaToInt("limit", ConstUtil.PAGE_SIZE);
        PageBean pageBean = wxPersonService.getWxPersonQueryList(pageNumber, pageSize, name);
        this.renderJson(pageBean);
    }

//    @ActionKey("/jx/getDeptManagerList")
//    public void getDeptManagerList() {
//        String name = this.getPara("name");
//        int pageNumber = this.getParaToInt("page", 1);
//        int pageSize = this.getParaToInt("limit", ConstUtil.PAGE_SIZE);
//        PageBean pageBean = wxPersonService.getWxPersonQueryList(pageNumber, pageSize, name);
//        this.renderJson(pageBean);
//    }

    @ActionKey("/jx/toWxPersonPage")
    public void toWxPersonPage() {
        this.render("wxPersonPage.html");
    }
    @ActionKey("/jx/upWxPerson")
    public void upWxPerson(){
        String id = this.getPara("id");
        String value = this.getPara("value");
        WxPerson p = WxPerson.dao.findById(id);
        p.setWxPersonMatchData(value);
        p.setWxPersonUpdatetime(Tool.getCurrTime());
        p.update();
        DataBean dBean = new DataBean();
        dBean.setCode(0);
        dBean.setMsg("操作成功");
        this.renderJson("data",dBean);
    }
    @ActionKey("/jx/clearWxPerson")
    public void clearWxPerson(){
        String id = this.getPara("id");
        WxPerson p = WxPerson.dao.findById(id);
        p.setWxPersonPid(null);
        p.setWxPersonPname(null);
       // p.setWxPersonMatchData(null);
        p.setWxPersonUpdatetime(Tool.getCurrTime());
        p.update();
        DataBean dBean = new DataBean();
        dBean.setCode(0);
        dBean.setMsg("操作成功");
        this.renderJson("data",dBean);
    }

//    /**
//     * 跳转到考核人员页面
//     */
//    @ActionKey("/jx/toDeptManagerPage")
//    public void toDeptManagerPage() {
//        String deptName = this.getPara("deptName");
//        String managerName = this.getPara("managerName");
//        String sameManager = this.getPara("sameManager");
//
//        PageBean deptManagerList = deptManagerService.getDeptManagerQueryList(1, 10000, deptName, managerName,sameManager);
//        this.setAttr("deptManagerList", deptManagerList.getData());
//        this.setAttr("deptName", deptName);
//        this.setAttr("managerName", managerName);
//        this.setAttr("sameManager", sameManager);
//        this.render("deptManagerList.html");
//    }
//    //更新上级人员
//    @ActionKey("/jx/updateDeptManager")
//    public void updateDeptManager() {
//
//        String deptId = this.getPara("deptId");
//        String managerId = this.getPara("managerId");
//        String managerName = this.getPara("managerName");
//        String type = this.getPara("type");
//        String sameManager = deptManagerService.updateDeptManager(deptId, type, managerId, managerName);
//        this.renderJson(R.isOK("sameManager", sameManager));
//    }
//    //删除上级人员
//    @ActionKey("/jx/deleteDeptManager")
//    public void deleteDeptManager() {
//
//        String deptId = this.getPara("deptId");
//        String type = this.getPara("type");
//        String sameManager = deptManagerService.deleteDeptManager(deptId, type);
//        this.renderJson(R.isOK("sameManager", sameManager));
//    }
//    //同步上级人员
//    @ActionKey("/jx/syncDeptManager")
//    public void syncDeptManager() {
//
//        String syncAll = this.getPara("syncAll");
//        deptManagerService.syncDeptManager("y".equals(syncAll));
//        this.renderJson(R.isOK());
//    }

    /**
     * 跳转到考核人员页面
     */
    @ActionKey("/jx/toPersonManagerPage")
    public void toPersonManagerPage() {
        String personName = this.getPara("personName");
        String managerName = this.getPara("managerName");
        String sameManager = this.getPara("sameManager");

        PageBean personManagerList = personManagerService.getPersonManagerQueryList(1, 100000, personName, managerName,sameManager);
        this.setAttr("personManagerList", personManagerList.getData());
        this.setAttr("personName", personName);
        this.setAttr("managerName", managerName);
        this.setAttr("sameManager", sameManager);
        this.getSession().removeAttribute("jxManager_query");
        this.getSession().removeAttribute("jxAllEntry_query");
        this.render("personManagerList.html");
    }
    //更新上级人员
    @ActionKey("/jx/updatePersonManager")
    public void updatePersonManager() {

        String personId = this.getPara("personId");
        String managerId = this.getPara("managerId");
        String managerName = this.getPara("managerName");
        String type = this.getPara("type");
        String sameManager = personManagerService.updatePersonManager(personId, type, managerId, managerName);
        this.renderJson(R.isOK("sameManager", sameManager));
    }
    //锁定上级人员
    @ActionKey("/jx/lockPersonManager")
    public void lockPersonManager() {
        String personId = this.getPara("personId");
        PersonManager personManager = PersonManager.dao.findById(personId);
        personManager.setPersonManagerLock("2");
        personManager.update();
        this.renderJson(R.isOK());
    }
    //解锁上级人员
    @ActionKey("/jx/unlockPersonManager")
    public void unlockPersonManager() {
        String personId = this.getPara("personId");
        PersonManager personManager = PersonManager.dao.findById(personId);
        personManager.setPersonManagerLock("1");
        personManager.update();
        this.renderJson(R.isOK());
    }
    //删除上级人员
    @ActionKey("/jx/deletePersonManager")
    public void deletePersonManager() {

        String personId = this.getPara("personId");
        String type = this.getPara("type");
        String sameManager = personManagerService.deletePersonManager(personId, type);
        this.renderJson(R.isOK("sameManager", sameManager));
    }
    //同步上级人员
    @ActionKey("/jx/syncPersonManager")
    public void syncPersonManager() {

        String syncAll = this.getPara("syncAll");
        personManagerService.syncPersonManager("n".equals(syncAll)?false:true);
        this.renderJson(R.isOK());
    }
}
