package com.zcloud.controller.bus;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.zcloud.entity.system.User;
import com.zcloud.service.bus.*;
import com.zcloud.service.dockingManagement.KeyProcessesService;
import com.zcloud.service.dockingManagement.ResponsiblePersonService;
import com.zcloud.service.notice.NoticeRemindLogService;
import com.zcloud.service.system.*;
import com.zcloud.util.*;
import org.apache.commons.io.FileUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.zcloud.controller.base.BaseController;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.service.filemanager.MfolderService;

import javax.annotation.Resource;

/**
 * 说明：企业管理
 * 作者：luoxiaobao
 * 时间：2020-12-24
 * 官网：www.zcloudchina.com
 */
@Controller
@RequestMapping("/corpinfo")
public class CorpInfoController extends BaseController {

    @Autowired
    private CorpInfoService corpinfoService;
    @Autowired
    private ElectronicFenceService electronicfenceService;
    @Autowired
    private MaintenanceUserInfoService maintenanceuserinfoService;
    @Autowired
    private CorpInfo2Service corpinfo2Service;
    @Autowired
    private ImgFilesService imgfilesService;
    @Autowired
    private ImgFileService imgfileService;
    @Autowired
    private UsersService usersService;
    @Autowired
    private CorpInfo4Service corpinfo4Service;
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private MfolderService mfolderService;
    @Autowired
    private MSMLoginService msmloginService;
    @Autowired
    private HiddenCheckService hiddenCheckService;
    @Autowired
    private HiddenService hiddenService;
    @Autowired
    private CheckUserService checkUserService;
    @Autowired
    private RecordItemService recordItemService;
    @Autowired
    private CheckRecordService checkRecordService;
    @Autowired
    private ListStatisticsService listStatisticsService;
    @Autowired
    private AllWorkItemService allWorkItemService;
    @Autowired
    private DictionariesService dictionariesService;
    @Autowired
    private ShiftWorkRulesService shiftWorkRulesService;
    @Autowired
    private ShiftWorkPeriodService shiftWorkPeriodService;
    @Autowired
    private CorpinfoRelatedService corpinfoRelatedService;
    @Autowired
    private CorpTypeService corptypeService;
    @Autowired
    private CorpTimeService corpTimeService;

    @Autowired
    private RoleService roleService;
    @Autowired
    private NoticeRemindLogService noticeRemindLogService;

    @Autowired
    private VIPAdjustmentLogService vipAdjustmentLogService;
    @Autowired
    private MaintenanceFlowService maintenanceFlowService;
    @Autowired
    private MaintenanceManagementService maintenanceManagementService;

    @Autowired
    private ResourceCorpService resourcecorpService;
    @Autowired
    private CorpPlsInfoService corpplsinfoService;
    @Autowired
    private OfficeService officeService;
    @Autowired
    private Smb smb;

    //corpinfo/updCorpType
    @RequestMapping(value = "/updCorpType")
    @ResponseBody
    public ReturnMap updCorpType() {
        PageData pageData = this.getPageData();
        corpinfoRelatedService.updCorpType(pageData);
        return ReturnMap.ok();
    }


    /**
     * 新增
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/add")
    @RequiresPermissions("corpinfo:add")
    @ResponseBody
    @Transactional
    public Object add(@RequestParam(value = "imgFiles", required = false) MultipartFile[] imgFiles, @RequestParam(value = "fourFiles", required = false) MultipartFile[] fourFiles) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        PageData agentNum = new PageData();
        PageData pRold = new PageData();
        pRold.put("ISMAIN", "1");
        if ("1".equals(Jurisdiction.getUSER_ID())) {
            pRold.put("PARENT_ID", pd.get("VIPLEVEL"));
        }
        List<PageData> mainRoles = roleService.getRoleListByPid(pRold);
        if (mainRoles != null && mainRoles.size() > 0) {
            String CORPINFO_ID = this.get32UUID();
            pd.put("CORPINFO_ID", CORPINFO_ID);    //主键
            saveOfficeList(pd);
            // 保存企业信息
            saveCorpInfo(pd);
            saveElectronicFence(pd);
            if ("2".equals(pd.get("STATUS"))) {
                saveCorpTrial(pd);
            }
            // 保存企业安全标准化及企业相关属性信息
            // 重大危险源等
            corpinfoRelatedService.save(pd);
            // 保存四色图及营业执照
            PageData img = new PageData();
            img.put("FOREIGN_KEY", pd.get("CORPINFO_ID"));
            img.put("EDITFOURTYPE", pd.get("EDITFOURTYPE"));
            if (imgFiles != null && imgFiles.length > 0) {
                img.put("TYPE", "1");
                editCorpImg(imgFiles, img);
            }

            if (fourFiles != null && fourFiles.length > 0) {
                img.put("TYPE", "2");
                editCorpImg(fourFiles, img);
            }
            // 保存部门信息
            PageData dept = saveDeptInfo(pd);
            // 保存主用户
            saveUserInfo(pd, mainRoles, dept);
            saveMaintenanceUserInfo(pd);
            // 保存体系文件
            saveMfolder(pd);
            pd.put("RESOURCECORP_ID", this.get32UUID());    //主键
            pd.put("ISDELETE", "0");    //是否删除
            pd.put("STATUS", "1");    //资源库使用状态   1 启用 2禁用
//			pd.put("CORPINFO_ID", corpId);
            pd.put("OPERATOR", Jurisdiction.getUsername());    //操作人
            pd.put("OPERATTIME", DateUtil.date2Str(new Date()));    //操作时间
            pd.put("CREATOR", Jurisdiction.getUsername());    //创建人
            pd.put("CREATTIME", DateUtil.date2Str(new Date()));    //创建时间
            resourcecorpService.save(pd);
            // 新增初始化排班
            initWorkRules(pd.getString("CORPINFO_ID"));
            if ("0".equals(pd.get("PERSONNEL_POSITION").toString())) {
                corpplsinfoService.saveOrUpdate(pd);
            }
            map.put("pd", pd);
            map.put("result", errInfo);
        } else {
            map.put("pd", pd);
            map.put("result", "success");
            map.put("message", "此会员异常，请联系管理员。");
        }
        return map;
    }
    @Transactional(rollbackFor = Exception.class)
    private void saveOfficeList(PageData pd) throws Exception {
        String CORPINFO_ID = pd.getString("CORPINFO_ID");
        // 保存对应的工种信息三个
        ArrayList<PageData> officeList = new ArrayList<>();
        PageData office = new PageData();
        office.put("CORPINFO_ID", CORPINFO_ID);
        office.put("WORK_NAME", "厂区员工");
        office.put("THUMBNAIL", "peo_blue");
        office.put("REMARK", "person_000002_blue");
        office.put("ISDELETE", 0);
        office.put("OPERATOR", 1);
        office.put("CREATOR", 1);
        office.put("OPERATTIME", DateUtil.date2Str(new Date()));
        office.put("CREATTIME", DateUtil.date2Str(new Date()));
        office.put("STATUS", 0);
        PageData office2 = new PageData();
        office2.put("CORPINFO_ID", CORPINFO_ID);
        office2.put("WORK_NAME", "外来访客");
        office2.put("THUMBNAIL", "peo_yellow");
        office2.put("REMARK", "person_000002_yellow");
        office2.put("ISDELETE", 0);
        office2.put("STATUS", 0);
        office2.put("OPERATOR", 1);
        office2.put("CREATOR", 1);
        office2.put("OPERATTIME", DateUtil.date2Str(new Date()));
        office2.put("CREATTIME", DateUtil.date2Str(new Date()));
        PageData office3 = new PageData();
        office3.put("CORPINFO_ID", CORPINFO_ID);
        office3.put("WORK_NAME", "第三方人员");
        office3.put("THUMBNAIL", "peo_red");
        office3.put("REMARK", "person_000002_red");
        office3.put("ISDELETE", 0);
        office3.put("STATUS", 0);
        office3.put("OPERATOR", 1);
        office3.put("CREATOR", 1);
        office3.put("OPERATTIME", DateUtil.date2Str(new Date()));
        office3.put("CREATTIME", DateUtil.date2Str(new Date()));
        officeList.add(office);
        officeList.add(office2);
        officeList.add(office3);
        // 有定位系统哪么就的 对接到定位系统里
        if ("0".equals(pd.getString("PERSONNEL_POSITION"))) {
            for (int i = 0; i < officeList.size(); i++) {
                // 对接工种 到 定位系统
                PageData off = new PageData();
                off.put("officeName", officeList.get(i).getString("WORK_NAME"));
                off.put("remark", officeList.get(i).getString("REMARK"));
                off.put("status", officeList.get(i).getString("STATUS"));
                off.put("thumbnail", officeList.get(i).getString("THUMBNAIL"));
                PLSUtil.GeneralPostNotInPls(pd.getString("POST_URL") + "/deploy/office", off, pd);
            }
            PageData pageData = new PageData();
            pageData.put("currentPage", 1);
            pageData.put("showCount", 999);
            if ("0".equals(pd.getString("PERSONNEL_TYPE"))) {
                // 单体版
                // /deploy/office/list
                JSONObject jsonObject = PLSUtil.GeneralList(pd.getString("POST_URL") + "/deploy/office/list", pageData, PLSUtil.getTokenNotInPlsTable(pd));
                if (jsonObject != null && "200".equals(jsonObject.getString("code"))) {
                    JSONArray data = jsonObject.getJSONArray("rows");
                    for (int i = 0; i < data.size(); i++) {
                        JSONObject jsonObject1 = data.getJSONObject(i);
                        if ("厂区员工".equals(jsonObject1.getString("officeName"))) {
                            office.put("WORK_ID", jsonObject1.getString("id"));
                        }
                        if ("外来访客".equals(jsonObject1.getString("officeName"))) {
                            office2.put("WORK_ID", jsonObject1.getString("id"));
                        }
                        if ("第三方人员".equals(jsonObject1.getString("officeName"))) {
                            office3.put("WORK_ID", jsonObject1.getString("id"));
                        }
                    }
                }
            } else {
                // 集团版
                JSONObject jsonObject = PLSUtil.GeneralList(pd.getString("POST_URL") + "/deploy/office/list", pageData, PLSUtil.getTokenNotInPlsTable(pd));
                if (jsonObject != null && "200".equals(jsonObject.getString("code"))) {
                    JSONArray data = jsonObject.getJSONArray("rows");
                    for (int i = 0; i < data.size(); i++) {
                        JSONObject jsonObject1 = data.getJSONObject(i);
                        if ("厂区员工".equals(jsonObject1.getString("officeName"))) {
                            office.put("WORK_ID", jsonObject1.getString("id"));
                        }
                        if ("外来访客".equals(jsonObject1.getString("officeName"))) {
                            office2.put("WORK_ID", jsonObject1.getString("id"));
                        }
                        if ("第三方人员".equals(jsonObject1.getString("officeName"))) {
                            office3.put("WORK_ID", jsonObject1.getString("id"));
                        }
                    }
                }
            }
        }
        officeService.saveBatch(officeList);
    }

    /**
     * 删除
     *
     * @param out
     * @throws Exception
     */
    @Resource
    private KeyProcessesService keyProcessesService;
    @Resource
    private ResponsiblePersonService responsiblePersonService;

    @RequestMapping(value = "/delete")
    @RequiresPermissions("corpinfo:del")
    @ResponseBody
    public Object delete() throws Exception {
        Map<String, String> map = new HashMap<String, String>();
        String errInfo = "success";
        PageData pd = this.getPageData();
        corpinfoService.delete(pd);
        // 删除对接信息
        keyProcessesService.delete(pd);
        responsiblePersonService.delete(pd);
        usersService.deleteUsers(pd);            //删除用户
        map.put("result", errInfo);                //返回结果
        return map;
    }

    /**
     * 资源库企业列表
     *
     * @param page
     * @throws Exception
     */
    @RequestMapping(value = "/resList")
    @RequiresPermissions("corpinfo:list")
    @ResponseBody
    public Object resList(Page page) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        String KEYWORDS = pd.getString("KEYWORDS");                        //关键词检索条件
        if (Tools.notEmpty(KEYWORDS)) pd.put("KEYWORDS", KEYWORDS.trim());
        page.setPd(pd);
        List<PageData> varList = corpinfoService.resList(page);    //列出CorpInfo列表
        map.put("varList", varList);
        map.put("page", page);
        map.put("result", errInfo);
        return map;
    }


    /**
     * 修改
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/edit", headers = "content-type=multipart/form-data")
    @ResponseBody
    @Transactional
    public Object edit(@RequestParam(value = "imgFiles", required = false) MultipartFile[] imgFiles, @RequestParam(value = "fourFiles", required = false) MultipartFile[] fourFiles) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = this.getPageData();

        PageData oldCorp = corpinfoService.findById(pd);

        Boolean updateVipLevel = false;
        if (oldCorp != null && oldCorp.get("VIPLEVEL") != null && Tools.notEmpty(oldCorp.get("VIPLEVEL").toString()) && !oldCorp.getString("VIPLEVEL").equals(pd.getString("VIPLEVEL"))) {
            updateVipLevel = true;
        }

        if (updateVipLevel && "0".equals(pd.get("PERSONNEL_POSITION").toString())) {
            if (!PLSUtil.testUrl(pd.getString("POST_URL") + "/auth/login",
                    pd.getString("ACCOUNT"), pd.getString("PASSWORD"),
                    pd.getString("CORPINFO_ID"))) {
                pd.put("result", errInfo);
                pd.put("message", "人员定位系统设置不正确,请确认后重试!");
                return pd;
            }
            // 修改为人员定位企业
            try {
                corpplsinfoService.saveOrUpdate(pd);
                corpplsinfoService.asyncPLSInfo(pd);
            } catch (Exception e) {
                e.printStackTrace();
                errInfo = "fail";
                pd.put("result", errInfo);
                pd.put("message", "人员定位系统设置不正确,请确认后重试!");
                return pd;
            }
        }

        PageData agentNum = new PageData();
        // 非ADMIN 并且修改了企业会员级别
        if (!"1".equals(Jurisdiction.getUSER_ID()) && updateVipLevel) {
            // 代理用户虚判断是否有足够的权限新建公司
            pd.put("USER_ID", Jurisdiction.getUSER_ID());
            pd.put("CORPLEVEL", pd.get("VIPLEVEL"));
            if (agentNum == null || agentNum.get("NUMBER") == null || Tools.isEmpty(agentNum.get("NUMBER").toString()) || Integer.valueOf(agentNum.get("NUMBER").toString()) <= 0) {
                map.put("pd", pd);
                map.put("result", "success");
                map.put("message", "企业级别数据不足。");
                return map;
            }
            pd.put("VIPLEVEL", agentNum.get("CORPLEVEL"));
        }
        pd.put("OPERATOR", Jurisdiction.getUsername());    //操作人
        pd.put("OPERATTIME", DateUtil.date2Str(new Date()));    //操作时间
        if (!Tools.isEmpty(pd.get("CORP_OF_TYPEAll"))) {
            PageData corptypePd = new PageData();
            corptypePd.put("CORPTYPE_ID", pd.get("CORP_OF_TYPEAll"));
            PageData corptype = corptypeService.findById(corptypePd);
            if (null != corptype) {
                if ("0".equals(corptype.get("PARENT_ID").toString())) {
                    pd.put("CORP_OF_TYPE", corptype.get("CORPTYPE_ID"));
                } else {
                    pd.put("CORP_OF_TYPE", corptype.get("PARENT_ID"));
                    pd.put("CORP_OF_TYPE2", corptype.get("CORPTYPE_ID"));
                }
            }
        }

        corpinfoService.edit(pd);
        if (Jurisdiction.getAGENCY_MANAGEMENT_ID() != null && !"".equals(Jurisdiction.getAGENCY_MANAGEMENT_ID())) {
            pd.put("AGENCY_MANAGEMENT_ID", Jurisdiction.getAGENCY_MANAGEMENT_ID());
        }
        //市场人员逻辑暂时隐掉
//		PageData cpd = new PageData();
//		cpd = maintenanceuserinfoService.findById(pd);
//		if(cpd != null){
//			maintenanceuserinfoService.edit(pd);
//		}else{
//			saveMaintenanceUserInfo(pd);
//		}
        PageData img = new PageData();
        img.put("FOREIGN_KEY", pd.get("CORPINFO_ID"));
        img.put("EDITFOURTYPE", pd.get("EDITFOURTYPE"));
        if (imgFiles != null && imgFiles.length > 0) {
            img.put("TYPE", "1");
            editCorpImg(imgFiles, img);
        }
        if (fourFiles != null && fourFiles.length > 0) {
//		if("1".equals(pd.get("FOURTYPE").toString())) {
            img.put("TYPE", "2");
            editCorpImg(fourFiles, img);
        }
        corpinfoRelatedService.edit(pd);
        map.put("pd", pd);
        map.put("result", errInfo);
        PageData dept = new PageData();
        dept.put("NAME", pd.get("CORP_NAME"));
        dept.put("OLDNAME", oldCorp.get("CORP_NAME"));
        dept.put("PARENT_ID", '0');
        dept.put("CORPINFO_ID", pd.get("CORPINFO_ID"));            //企业ID
        departmentService.editCornDept(dept);
        PageData user = new PageData();
        user.put("OLDUSERNAME", oldCorp.get("CORP_NAME"));            //用户名
        user.put("USERNAME", pd.get("CORP_NAME"));            //用户名
        user.put("NAME", pd.get("CORP_NAME"));            //用户名
        user.put("CORPINFO_ID", pd.get("CORPINFO_ID"));            //企业ID
        user.put("PASSWORD", new SimpleHash("SHA-1", pd.getString("CORP_NAME"), "Aa@123456").toString());
        //密码加密
        usersService.updateCornUser(user);
        // 如果修改了公司级别，修改该公司下用户角色
        if (updateVipLevel) {
            PageData vipLevel = new PageData();
            vipLevel.put("PARENT_ID", pd.get("VIPLEVEL"));
            String mainRoleId = "";
            String generalRoleId = "";
            vipLevel.put("ISMAIN", "1");
            PageData mainRole = roleService.getRoleByPidAndMain(vipLevel);
//			vipLevel.put("ISMAIN", "0");
//			PageData generalRole = roleService.getRoleByPidAndMain(vipLevel);
            if (mainRole != null && mainRole.get("ROLE_ID") != null) {
                mainRoleId = mainRole.getString("ROLE_ID");
//				generalRoleId = generalRole.getString("ROLE_ID");
            } else {
                // 分组内角色不全
                map.put("message", "此等级会员异常，请联系管理员。");
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return map;
            }
            PageData userRole = new PageData();
            userRole.put("CORPINFO_ID", pd.get("CORPINFO_ID"));
            userRole.put("ROLE_ID", mainRoleId);
            userRole.put("ISMAIN", "1");
            usersService.updateUserRole(userRole);
//			userRole.put("ROLE_ID", generalRoleId);
            userRole.put("PARENT_ID", pd.get("VIPLEVEL"));
            userRole.put("ISMAIN", "0");
            usersService.updateGeneralUserRole(userRole);
        }
        return map;
    }

    @RequestMapping(value = "/editIsReceive")
    @ResponseBody
    public Object editIsReceive() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd = corpinfoService.findById(pd);
        if (pd.get("ISRECEIVE").toString().equals("1")) {
            pd.put("ISRECEIVE", "0");
        } else {
            pd.put("ISRECEIVE", "1");
        }
        corpinfoService.editIsReceive(pd);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    @RequestMapping(value = "/updateISuse")
    @ResponseBody
    public Object updateISuse() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd.put("ISUSE", "1");
        corpinfoService.updateISuse(pd);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    @RequestMapping(value = "/updateuse")
    @ResponseBody
    public Object updateuse() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd.put("ISUSE", "0");
        corpinfoService.updateuse(pd);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    @RequestMapping(value = "/goStop")
    @ResponseBody
    public Object goStop() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd.put("OPERATOR", Jurisdiction.getUsername());    //操作人
        pd.put("OPERATTIME", DateUtil.date2Str(new Date()));    //操作时间
        pd.put("ISDELETE", '0');
        pd.put("ISSTOP", '0');
        pd.put("ID", this.get32UUID());
        corpinfoService.editStatus(pd);
        corpinfoService.deleteStop(pd);
        corpinfoService.goStop(pd);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    @RequestMapping(value = "/goFormal")
    @ResponseBody
    @Transactional
    public Object goFormal() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        String msg = "";
        PageData pd = new PageData();
        pd = this.getPageData();
        if (Jurisdiction.getAGENCY_MANAGEMENT_ID() != null && !Jurisdiction.getAGENCY_MANAGEMENT_ID().trim().equals("")) {
            PageData pageData = corpinfoService.findUserNumById(pd);
        }
        corpinfoService.goFormal(pd);
        corpinfoService.deleteTrial(pd);

        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    @RequestMapping(value = "/goStart")
    @ResponseBody
    public Object goStart() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        PageData cpd = corpinfoService.findBytrialId(pd);
        System.out.println(cpd.get("TRIALDAY"));
        if (cpd.get("TRIALDAY") == null) {
            corpinfoService.editStartStatus(pd);
        } else {
            corpinfoService.editTrialStatus(pd);
        }
        corpinfoService.deleteStart(pd);
        pd.put("OPERATOR", Jurisdiction.getUsername());    //操作人
        pd.put("OPERATTIME", DateUtil.date2Str(new Date()));    //操作时间
        pd.put("ISDELETE", '0');
        pd.put("ISSTOP", '1');
        pd.put("ID", this.get32UUID());
        corpinfoService.goStart(pd);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 列表
     *
     * @param page
     * @throws Exception
     */
    @RequestMapping(value = "/list")
    @RequiresPermissions("corpinfo:list")
    @ResponseBody
    public Object list(Page page) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        String KEYWORDS = pd.getString("KEYWORDS");                        //关键词检索条件
        if (Tools.notEmpty(KEYWORDS)) pd.put("KEYWORDS", KEYWORDS.trim());
        if (!Jurisdiction.getUsername().equals("admin") && !Jurisdiction.getUsername().equals("adminsuper")) {
            pd.put("PROXY_ACCOUNT_PLATFORM", "平台");
            pd.put("USER_ID", Jurisdiction.getUSER_ID());
        }
        page.setPd(pd);
        List<PageData> varList = corpinfoService.corplistPage(page);    //列出CorpInfo列表
        if (varList != null && varList.size() > 0) {
            String[] corpIds = new String[varList.size()];
            for (int i = 0; i < varList.size(); i++) {
                corpIds[i] = varList.get(i).getString("CORPINFO_ID");
            }

            PageData pd2 = new PageData();
            pd2.put("corpIds", corpIds);
            Page page2 = new Page();
            page2.setPd(pd2);
            List<PageData> msmLoginList = msmloginService.getCountByCorpInfoIds(page2);


            for (PageData pageData : varList) {
                String corpId = pageData.getString("CORPINFO_ID");
                Object msmCount = "0";
                for (PageData msmLogin : msmLoginList) {
                    if (corpId.equals(msmLogin.getString("CORPINFO_ID"))) {
                        msmCount = msmLogin.get("msmcount");
                    }
                }
                pageData.put("msmCount", msmCount);
            }
        }
        map.put("varList", varList);
        map.put("page", page);
        map.put("result", errInfo);
        return map;
    }
//	/**导出到excel(企业隐患管理使用)
//	 * @param
//	 * @throws Exception
//	 */
//	@RequestMapping(value="/excelNormal")
//	public ModelAndView excelNormal() throws Exception{
//		ModelAndView mv = new ModelAndView();
//		PageData pd = new PageData();
//		pd = this.getPageData();
//		String ids [] = pd.get("ids").toString().split(",");
//		pd.put("IDS", ids);
//		Map<String,Object> dataMap = new HashMap<String,Object>();
//		List<String> titles = new ArrayList<String>();
//		titles.add("企业名称");	//1
//		titles.add("开户日期");	//2
//		titles.add("交付日期");	//3
//		titles.add("有效使用结束时间");	//4
//		titles.add("企业用户来源");	//5
//		titles.add("开户人");	//6
//		titles.add("所属区域");	//7
//		titles.add("会员级别");	//8
//		dataMap.put("titles", titles);
//		List<PageData> varOList = corpinfoService.listExcelInfo(pd);
//		List<PageData> varList = new ArrayList<PageData>();
//		for(int i=0;i<varOList.size();i++){
//			PageData vpd = new PageData();
//			vpd.put("var1", varOList.get(i).getString("CORP_NAME"));	    //1
//			if(varOList.get(i).get("SOURCE") != null && Tools.notEmpty(varOList.get(i).get("SOURCE").toString())) {
//				if("1".equals(varOList.get(i).get("SOURCE").toString())) {
//					vpd.put("var2", "隐患快报");	    //2
//				} else if("2".equals(varOList.get(i).get("SOURCE").toString()) || "3".equals(varOList.get(i).get("SOURCE").toString())) {
//					vpd.put("var2", "隐患排查");	    //2
//				}
//			}
//			vpd.put("var3", varOList.get(i).getString("HIDDENDESCR"));	    //3
//			if(varOList.get(i).get("STATE") != null && Tools.notEmpty(varOList.get(i).get("STATE").toString())) {
//				String stateStr = "";
//				switch (varOList.get(i).get("STATE").toString()) {
//					case "1":
//						stateStr = "未整改";
//						break;
//					case "2":
//						stateStr = "已整改";
//						break;
//					case "3":
//						stateStr = "待验收";
//						break;
//					case "4":
//						stateStr = "已验收";
//						break;
//					case "-1":
//						stateStr = "已过期";
//						break;
//
//					default:
//						break;
//				}
//				vpd.put("var4", stateStr);	    //4
//			}
//			vpd.put("var5", varOList.get(i).getString("CREATTIME"));	    //5
//			vpd.put("var6", varOList.get(i).getString("CREATORNAME"));	    //6
//			vpd.put("var7", varOList.get(i).getString("RECTIFICATIONORNAME"));	    //7
//			vpd.put("var8", varOList.get(i).getString("CHECKNAME"));	    //8
//			varList.add(vpd);
//		}
//		dataMap.put("varList", varList);
//		ObjectExcelView erv = new ObjectExcelView();
//		mv = new ModelAndView(erv,dataMap);
//		return mv;
//	}

    /**
     * 列表
     *
     * @param page
     * @throws Exception
     */
    @RequestMapping(value = "/usedList")
    @RequiresPermissions("corpinfo:list")
    @ResponseBody
    public Object usedList(Page page) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        String KEYWORDS = pd.getString("KEYWORDS");                        //关键词检索条件
        if (Tools.notEmpty(KEYWORDS)) pd.put("KEYWORDS", KEYWORDS.trim());
        if (!Jurisdiction.getUsername().equals("admin") && !Jurisdiction.getUsername().equals("adminsuper")) {
            //pd.put("CREATOR", Jurisdiction.getUsername());
            pd.put("CREATUSERID", Jurisdiction.getUSER_ID());
        }
        page.setPd(pd);
        List<PageData> varList = corpinfoService.usedCorpList(page);    //列出CorpInfo列表
        map.put("varList", varList);
        map.put("page", page);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 列表
     *
     * @param page
     * @throws Exception
     */
    @RequestMapping(value = "/todoSendMsg")
    @ResponseBody
    public Object todoSendMsg(Page page) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        Map<String, Object> mes = new HashMap<String, Object>();
        mes.put("phone", pd.getString("LR_MOBILE"));
        mes.put("templateCode", "SMS_462275023");

        List<PageData> paramsList = new ArrayList<PageData>();
        PageData params1 = new PageData();
        PageData params2 = new PageData();
        PageData params3 = new PageData();

        // 第1个参数
        params1.put("name", "name");// 存入短信模板中的参数名称
        params1.put("value", pd.get("LR_NAME"));// 存入上面参数名称所传递的值
        paramsList.add(params1);

        // 第2个参数
        params2.put("name", "time");// 存入短信模板中的参数名称
        params2.put("value", DateUtil.date2Str(new Date(), "yyyy年MM月dd日"));// 存入上面参数名称所传递的值
        paramsList.add(params2);
        // 第3个参数
        params3.put("name", "days");// 存入短信模板中的参数名称
        params3.put("value", pd.get("REMAININGTIME"));// 存入上面参数名称所传递的值
        paramsList.add(params3);
        // 发送短信
        SendSmsResponse ssms = AliSmsUtil.sendSms(mes, paramsList);
        // 记录日志
        PageData log = new PageData();
        log.put("NOTICE_REMIND_LOG_ID", UuidUtil.get32UUID());
        log.put("CORPINFO_ID", pd.getString("CORPINFO_ID"));
        log.put("TYPE", "2");
        log.put("CREATOR", Jurisdiction.getUsername());
        log.put("CREATTIME", DateUtil.date2Str(new Date()));
        log.put("REMAININGTIME", pd.get("REMAININGTIME"));
        noticeRemindLogService.save(log);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 列表
     *
     * @param page
     * @throws Exception
     */
    @RequestMapping(value = "/remindList")
    @ResponseBody
    public Object remindList(Page page) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        page.setPd(pd);
        List<PageData> varList = noticeRemindLogService.list(page);
        map.put("varList", varList);
        map.put("page", page);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 列表
     *
     * @param page
     * @throws Exception
     */
    @RequestMapping(value = "/stoplist")
    @RequiresPermissions("corpinfo:list")
    @ResponseBody
    public Object stoplist(Page page) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        String KEYWORDS = pd.getString("KEYWORDS");                        //关键词检索条件
        if (Tools.notEmpty(KEYWORDS)) pd.put("KEYWORDS", KEYWORDS.trim());
        if (!Jurisdiction.getUsername().equals("admin") && !Jurisdiction.getUsername().equals("adminsuper")) {
            if (Jurisdiction.getAGENCY_MANAGEMENT_ID() != null && !Jurisdiction.getAGENCY_MANAGEMENT_ID().trim().equals("")) {
                if (Jurisdiction.getRnumbers().indexOf("R20230626219293") > -1) { // 运维人员
                    // 代理分账号
                    pd.put("PROXY_SUB_ACCOUNT", Jurisdiction.getUSER_ID());
                }
                if (Jurisdiction.getRnumbers().indexOf("R20230626739034") > -1) {
                    // 代理主账号
                    pd.put("PROXY_ACCOUNT", Jurisdiction.getAGENCY_MANAGEMENT_ID());
                }
            } else {
                if (Jurisdiction.getRnumbers().indexOf("R20230626219293") > -1) { // 运维人员
                    // 平台分账号
                    pd.put("PLATFORM_SUB_ACCOUNT", Jurisdiction.getUSER_ID());
                }
            }
        }
        page.setPd(pd);
        List<PageData> varList = corpinfoService.corpstoplistPage(page);    //列出CorpInfo列表
        if (varList != null && varList.size() > 0) {
            String[] corpIds = new String[varList.size()];
            for (int i = 0; i < varList.size(); i++) {
                corpIds[i] = varList.get(i).getString("CORPINFO_ID");
            }

            PageData pd2 = new PageData();
            pd2.put("corpIds", corpIds);
            Page page2 = new Page();
            page2.setPd(pd2);
            List<PageData> msmLoginList = msmloginService.getCountByCorpInfoIds(page2);


            for (PageData pageData : varList) {
                String corpId = pageData.getString("CORPINFO_ID");
                Object msmCount = "0";
                for (PageData msmLogin : msmLoginList) {
                    if (corpId.equals(msmLogin.getString("CORPINFO_ID"))) {
                        msmCount = msmLogin.get("msmcount");
                    }
                }
                pageData.put("msmCount", msmCount);
            }
        }
        map.put("varList", varList);
        map.put("page", page);
        map.put("result", errInfo);
        return map;
    }


    /**
     * 企业内存用量列表
     *
     * @param page
     * @throws Exception
     */
    @RequestMapping(value = "/listUsage")
    @RequiresPermissions("corpinfo:list")
    @ResponseBody
    public Object listUsage(Page page) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        String KEYWORDS = pd.getString("KEYWORDS");                        //关键词检索条件
        if (Tools.notEmpty(KEYWORDS)) pd.put("KEYWORDS", KEYWORDS.trim());
        if (!Jurisdiction.getUsername().equals("admin") && !Jurisdiction.getUsername().equals("adminsuper")) {
            //pd.put("CREATOR", Jurisdiction.getUsername());
            pd.put("CREATUSERID", Jurisdiction.getUSER_ID());
        }
        page.setPd(pd);
        List<PageData> varList = corpinfo2Service.corplistPage(page);    //列出CorpInfo列表
        map.put("varList", varList);
        map.put("page", page);
        map.put("result", errInfo);
        return map;
    }


    /**
     * 市场管理-指定人员-获取项目负责人下拉列表
     *
     * @throws Exception
     */
    @RequestMapping(value = "/getProjectLeadersList")
    @ResponseBody
    public Object getProjectLeadersList() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        String AGENCY_MANAGEMENT_ID = pd.getString("AGENCY_MANAGEMENT_ID");            // 校验此企业是否存在代理机构
        if (Tools.notEmpty(AGENCY_MANAGEMENT_ID)) pd.put("AGENCY_MANAGEMENT_ID", AGENCY_MANAGEMENT_ID.trim());
        String WHETHER_PRE_SALE_SERVICE = pd.getString("WHETHER_PRE_SALE_SERVICE");            // 校验此企业是否存在代理机构
        if (Tools.notEmpty(WHETHER_PRE_SALE_SERVICE))
            pd.put("WHETHER_PRE_SALE_SERVICE", WHETHER_PRE_SALE_SERVICE.trim());
        List<PageData> dataList = corpinfoService.getProjectLeadersList(pd);
        map.put("dataList", dataList);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 市场管理-指定人员-修改项目负责人
     *
     * @throws Exception
     */
    @RequestMapping(value = "/editProjectLeader")
    @ResponseBody
    @Transactional
    public Object editProjectLeader() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        String PROJECTLEADER_ID = pd.getString("PROJECTLEADER_ID");
        if (Tools.notEmpty(PROJECTLEADER_ID)) pd.put("PROJECTLEADER_ID", PROJECTLEADER_ID.trim());        // 获取项目负责人ID
        String CORPINFO_ID = pd.getString("CORPINFO_ID");
        if (Tools.notEmpty(CORPINFO_ID)) pd.put("CORPINFO_ID", CORPINFO_ID.trim());        // 获取企业ID
        corpinfoService.editProjectLeader(pd);
        pd.put("FLOW_STEP", "1");        // 待制定实施
        pd.put("FLOW_ACTION", Jurisdiction.getUsername() + "指定项目负责人:" + pd.getString("PROJECTLEADER_NAME"));
        saveMaintenanceFlow(pd);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 市场管理-充值-获取剩余时长和短信剩余
     *
     * @throws Exception
     */
    @RequestMapping(value = "/getMonEditInfo")
    @ResponseBody
    public Object getMonEditInfo() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        String CORPINFO_ID = pd.getString("CORPINFO_ID");        // 获取企业ID
        if (Tools.notEmpty(CORPINFO_ID)) pd.put("CORPINFO_ID", CORPINFO_ID.trim());
        List<PageData> dataList = corpinfoService.getMonEditInfo(pd);        // 根据企业ID查询企业剩余时长和短信剩余
        if (dataList.size() > 0 && dataList.get(0) != null) {
            for (PageData pageData : dataList) {
                String dateEnd = String.valueOf(pageData.get("useRemainingDuration"));
                if (Tools.notEmpty(dateEnd)) {
                    Date date = DateUtil.fomatDate(dateEnd);
                    Date now = new Date();
                    if (date.compareTo(now) < 0) {        // 查看是否已经过期
                        String useRemainingDuration = DateUtil.dayComparePrecise(date, now).toString();        // 计算两天之内相差几年几月几日
                        pageData.put("useRemainingDuration", new StringBuilder().append("已过期").append(useRemainingDuration).toString());
                    } else {
                        String useRemainingDuration = DateUtil.dayComparePrecise(now, date).toString();        // 计算两天之内相差几年几月几日
                        pageData.put("useRemainingDuration", useRemainingDuration);
                    }
                } else {
                    pageData.put("useRemainingDuration", "未交付");
                }
            }
        } else {
            dataList.clear();
            PageData pageData = new PageData();
            pageData.put("useRemainingDuration", "未交付");
            dataList.add(pageData);
        }
        map.put("dataList", dataList);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 市场管理-充值-提交表单
     *
     * @throws Exception
     */
    @RequestMapping(value = "/monEnable")
    @ResponseBody
    public Object monEnable(@RequestParam(value = "file", required = false) MultipartFile file) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        // 生存企业使用期限信息
        PageData time = new PageData();

        time.put("CORP_TIME_ID", this.get32UUID());    //主键
        time.put("CORPINFO_ID", pd.get("CORPINFO_ID"));
        time.put("OPERATOR", Jurisdiction.getUsername());    //操作人
        time.put("OPERATTIME", DateUtil.date2Str(new Date()));    //操作时间
        time.put("CREATOR", Jurisdiction.getUsername());    //创建人
        time.put("CREATTIME", DateUtil.date2Str(new Date()));    //创建时间
        PageData maxEndDate = corpTimeService.findMaxEndDate(pd);
        String startDate = DateUtil.date2Str(new Date(), "yyyy-MM-dd");// 开始时间默认今天
        // 如果今天之后还有使用期限。，则以结尾作为开头
        if (maxEndDate != null && maxEndDate.get("USE_DATE_END") != null && Tools.notEmpty(maxEndDate.get("USE_DATE_END").toString())) {
            startDate = maxEndDate.get("USE_DATE_END").toString();
        }
        time.put("USE_DATE_START", startDate);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dDate = sdf.parse(startDate);
        Calendar cal = Calendar.getInstance();
        cal.setTime(dDate);//设置起时间
        String rechargeUsageDuration = pd.getString("rechargeUsageDuration");
        if (Tools.notEmpty(rechargeUsageDuration)) pd.put("rechargeUsageDuration", rechargeUsageDuration.trim());
        cal.add(Calendar.YEAR, Integer.valueOf(pd.getString("rechargeUsageDuration")));//增加n年
        time.put("USE_DATE_END", sdf.format(cal.getTime()));
        cal.add(Calendar.MONTH, 1);//增加一个月
        time.put("RETENTION_DATA_DATE", sdf.format(cal.getTime()));
        time.put("ISIN", "0");
        time.put("ISDELETE", "0");
        if (null != file && !file.isEmpty()) {
            String ffile = DateUtil.getDays();
            String fileName = this.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
            smb.sshSftp(file, fileName, Const.FILEPATHFILE + ffile);
            time.put("CONTRACT_FILE", Const.FILEPATHFILE + ffile + "/" + fileName);
        }
        corpTimeService.save(time);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }


    /**
     * 市场管理-获取会员等级列表
     *
     * @throws Exception
     */
    @RequestMapping(value = "/getviplevelList")
    @ResponseBody
    public Object getVipLevelList() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        List<PageData> dataList = corpinfoService.getVipLevelList();
        map.put("dataList", dataList);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 市场管理-会员调整
     *
     * @throws Exception
     */
    @RequestMapping(value = "/vipEnable")
    @ResponseBody
    @Transactional
    public Object vipEnable(@RequestParam(value = "file", required = false) MultipartFile file) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        String CORPINFO_ID = pd.getString("CORPINFO_ID"); // 企业ID
        String VIP_OLD_ID = pd.getString("VIP_OLD_ID"); // 原会员等级ID
        String VIP_CHANGE_ID = pd.getString("VIP_CHANGE_ID"); // 新会员等级ID
        if (!VIP_OLD_ID.equals(VIP_CHANGE_ID)) {        // 判断新旧会员是否一致
            corpinfoService.editVipLevel(pd);        // 更新企业及下属账户会员等级

            PageData vipAd = new PageData(); // 会员调整日志信息
            vipAd.put("ID", this.get32UUID());    //主键
            vipAd.put("CORPINFO_ID", pd.get("CORPINFO_ID"));
            vipAd.put("OPERATOR", Jurisdiction.getUsername());    //操作人
            vipAd.put("OPERATTIME", DateUtil.date2Str(new Date()));    //操作时间
            vipAd.put("CREATOR", Jurisdiction.getUsername());    //创建人
            vipAd.put("CREATTIME", DateUtil.date2Str(new Date()));    //创建时间
            vipAd.put("NOTES", "用户:" + Jurisdiction.getUsername() + "将会员等级从\"" + pd.getString("VIP_OLD_NAME") + "\"调整为\"" + pd.getString("VIP_CHANGE_NAME") + "\"");
            vipAd.put("ISDELETE", "0");
            vipAd.put("OLD_VIPLEVEL", VIP_OLD_ID); // 原会员等级
            vipAd.put("NEW_VIPLEVEL", VIP_CHANGE_ID); // 新会员等级
            if (null != file && !file.isEmpty()) {
                String ffile = DateUtil.getDays();
                String fileName = this.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
                smb.sshSftp(file, fileName, Const.FILEPATHFILE + ffile);
                vipAd.put("CONTRACT_FILE", Const.FILEPATHFILE + ffile + "/" + fileName);
            }
            vipAdjustmentLogService.save(vipAd);
        }

        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 实施提醒
     *
     * @throws Exception
     */
    @RequestMapping(value = "/implementationReminder")
    @ResponseBody
    @Transactional
    public Object implementationReminder() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        String userId = Jurisdiction.getUSER_ID();        // 获取当前登录用户ID
        pd.put("USER_ID", userId);
        User user = usersService.getUserAndRoleById(userId);
        if ("市场人员".equals(user.getRole().getROLE_NAME())) {        // 判断当前登录用户是否为市场人员或项目负责人
            pd.put("ROLE_NAME", "市场人员");
        } else if ("项目负责人".equals(user.getRole().getROLE_NAME())) {
            pd.put("ROLE_NAME", "项目负责人");
        } else {
            map.put("result", errInfo);
            return map;
        }
        List<PageData> dataList = maintenanceFlowService.implementationReminder(pd);        // 获取该用户对应的客户实施超过三个月的列表
        StringBuilder data = new StringBuilder();
        if (dataList != null && dataList.size() > 0) {
            for (PageData pageData : dataList) {
                data.append(pageData.getString("CORP_NAME")).append("、");        // 返回符合的企业名称
            }
            data.deleteCharAt(data.length() - 1);

            String[] corpIds = new String[dataList.size()];
            for (int i = 0; i < dataList.size(); i++) {
                corpIds[i] = dataList.get(i).getString("CORPINFO_ID");
            }
            PageData pd2 = new PageData();
            pd2.put("corpIds", corpIds);
            maintenanceFlowService.updateReminderCount(pd2);        // 更新实施提醒次数
        } else {        // 没有符合的企业
            map.put("result", errInfo);
            return map;
        }
        map.put("data", data.toString());
        map.put("result", errInfo);
        return map;
    }


    /**
     * 项目负责人管理-开始部署-修改实施人员
     *
     * @throws Exception
     */
    @RequestMapping(value = "/editImplementPerson")
    @ResponseBody
    @Transactional
    public Object editImplementPerson() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        String CORPINFO_ID = pd.getString("CORPINFO_ID");
        if (Tools.notEmpty(CORPINFO_ID)) pd.put("CORPINFO_ID", CORPINFO_ID.trim());        // 获取企业ID

        String IMPLEMENTPSERSON_ID = pd.getString("IMPLEMENTPSERSON_ID");
        if (Tools.notEmpty(IMPLEMENTPSERSON_ID)) pd.getString("IMPLEMENTPSERSON_ID");        // 获取实施人员ID

        maintenanceuserinfoService.editImplementPerson(pd);
        pd.put("FLOW_STEP", "2"); // 已经部署还未部署完成
        pd.put("FLOW_ACTION", Jurisdiction.getUsername() + "指定实施人员:" + pd.getString("IMPLEMENTPSERSON_NAME"));
        saveMaintenanceFlow(pd);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 项目负责人管理-实施延期审批-获取审批申请信息
     *
     * @throws Exception
     */
    @RequestMapping(value = "/getApprovalInfo")
    @ResponseBody
    public Object getApprovalInfo() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        String CORPINFO_ID = pd.getString("CORPINFO_ID");
        if (Tools.notEmpty(CORPINFO_ID)) pd.put("CORPINFO_ID", CORPINFO_ID.trim());
        List<PageData> dataList = maintenanceFlowService.getApprovalInfo(pd);

        map.put("dataList", dataList);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 项目负责人管理-实施延期审批-审批表单提交
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/implementationDelay")
    @ResponseBody
    @Transactional
    public Object implementationDelay() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        String ISPASSED = pd.getString("ISPASSED");
        if ("1".equals(ISPASSED)) {
            pd.put("FLOW_STEP", "-1");
            pd.put("FLOW_ACTION", Jurisdiction.getUsername() + "通过延期审批");
            saveMaintenanceFlow(pd);
        }
        maintenanceFlowService.updateApprovalInfo(pd);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 项目负责人管理-开始验收
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/startAcceptance")
    @ResponseBody
    public Object startAcceptance() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        String CORPINFO_ID = pd.getString("CORPINFO_ID");
        if (Tools.notEmpty(CORPINFO_ID)) pd.put("CORPINFO_ID", CORPINFO_ID.trim());
        pd.put("FLOW_STEP", "4");        // 验收阶段
        pd.put("FLOW_ACTION", Jurisdiction.getUsername() + "开始验收阶段");
        saveMaintenanceFlow(pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 项目负责人管理-获取验收报告信息
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getAccReportInfo")
    @ResponseBody
    public Object getAccReportInfo() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        String CORPINFO_ID = pd.getString("CORPINFO_ID");
        if (Tools.notEmpty(CORPINFO_ID)) pd.put("CORPINFO_ID", CORPINFO_ID.trim());
        pd = maintenanceFlowService.getAccReportInfo(pd);
        if (pd != null && pd.containsKey("ACCREP_FILE")) {
            pd.put("captureIsType", false);
            pd.put("FOREIGN_KEY", pd.getString("CORPINFO_ID"));
        } else {
            pd = new PageData();
            pd.put("CORPINFO_ID", CORPINFO_ID.trim());
            pd.put("captureIsType", true);
        }
        PageData pd2 = new PageData();
        pd2.put("FOREIGN_KEY", pd.getString("CORPINFO_ID"));
        pd2.put("TYPE", 27);
        List<PageData> Imgs = imgfilesService.listAll(pd2);
        map.put("Imgs", Imgs);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 项目负责人管理-验收报告表单提交
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/submitAccReport")
    @ResponseBody
    @Transactional
    public Object submitAccReport(@RequestParam(value = "file") MultipartFile file) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        if (null != file && !file.isEmpty()) {
            String ffile = DateUtil.getDays();
            String fileName = this.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
            Smb.sshSftp(file, fileName, Const.FILEPATHFILE + pd.getString("CORPINFO_ID") + "/" + ffile);
            pd.put("ACCREP_FILE", Const.FILEPATHFILE + pd.getString("CORPINFO_ID") + "/" + ffile + "/" + fileName);
        }
        pd.put("FLOW_STEP", "4");
        pd.put("FLOW_ACTION", Jurisdiction.getUsername() + "提交验收报告");
        saveMaintenanceFlow(pd);
        maintenanceFlowService.updateAccReport(pd);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }


    /**
     * 项目负责人管理-交付-交付确认信息
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/deliveryConfirmation")
    @ResponseBody
    public Object deliveryConfirmation(@RequestParam(value = "file", required = false) MultipartFile file) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        String CORPINFO_ID = pd.getString("CORPINFO_ID");
        if (Tools.notEmpty(CORPINFO_ID)) pd.put("CORPINFO_ID", CORPINFO_ID.trim());
        maintenanceFlowService.deliveryConfirmation(pd);
        PageData time = new PageData();
        time.put("CORP_TIME_ID", this.get32UUID());    //主键
        time.put("CORPINFO_ID", pd.get("CORPINFO_ID"));
        time.put("TERM", pd.get("TERM"));
        time.put("OPERATOR", Jurisdiction.getUsername());    //操作人
        time.put("OPERATTIME", DateUtil.date2Str(new Date()));    //操作时间
        time.put("CREATOR", Jurisdiction.getUsername());    //创建人
        time.put("CREATTIME", DateUtil.date2Str(new Date()));    //创建时间
        time.put("ISDELETE", "0");
        if (null != file && !file.isEmpty()) {
            String ffile = DateUtil.getDays();
//			String filePath = PathUtil.getProjectpath() + Const.FILEPATHFILE + ffile;	//文件上传路径
//			String fileName = FileUpload.fileUp(file, filePath, this.get32UUID());				//执行上传
            String fileName = this.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
            smb.sshSftp(file, fileName, Const.FILEPATHFILE + ffile);
            time.put("CONTRACT_FILE", Const.FILEPATHFILE + ffile + "/" + fileName);
        } else {
            time.put("CONTRACT_FILE", pd.get("CONTRACT_FILE"));
        }
        corpTimeService.delete(time);
        corpTimeService.save(time);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 项目负责人管理-交付-获取交付信息
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getDeliveryInfo")
    @ResponseBody
    public Object getDeliveryInfo() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        String CORPINFO_ID = pd.getString("CORPINFO_ID");
        if (Tools.notEmpty(CORPINFO_ID)) pd.put("CORPINFO_ID", CORPINFO_ID.trim());
        List<PageData> dataList = maintenanceFlowService.getDeliveryInfo(pd);
        if (dataList.get(0).getString("DELIVERY_INFO") != null)
            pd.put("DELIVERY_INFO", dataList.get(0).getString("DELIVERY_INFO"));
        if (dataList.get(0).getString("DELIVERDATE") != null)
            pd.put("DELIVERDATE", dataList.get(0).getString("DELIVERDATE"));
        if (dataList.get(0).getString("OPERATIONPERSON_ID") != null)
            pd.put("OPERATIONPERSON_ID", dataList.get(0).getString("OPERATIONPERSON_ID"));
        if (dataList.get(0).getString("TERM") != null) pd.put("TERM", dataList.get(0).getString("TERM"));
        if (dataList.get(0).getString("CONTRACT_FILE") != null)
            pd.put("CONTRACT_FILE", dataList.get(0).getString("CONTRACT_FILE"));
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 项目负责人管理-交付-确认交付
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/confirmedDelivery")
    @ResponseBody
    @Transactional
    public Object confirmedDelivery(@RequestParam(value = "file", required = false) MultipartFile file) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        pd.put("FLOW_STEP", "5");        // 交付完成
        pd.put("FLOW_ACTION", Jurisdiction.getUsername() + "交付成功");
        saveMaintenanceFlow(pd);
        maintenanceFlowService.confirmedDelivery(pd);        // 更改交付信息
        corpinfoService.updateDeliveryDate(pd);        // 更改交付日期

        if (pd.getString("TERM").equals("0")) {
//			if (null != file && !file.isEmpty()) {
//				String  ffile = DateUtil.getDays();
//				String fileName = this.get32UUID()+file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
//				smb.sshSftp(file, fileName, Const.FILEPATHFILE + ffile);
//				pd.put("CONTRACT_FILE", Const.FILEPATHFILE + ffile + "/" + fileName);
//				corpTimeService.updateCorpTime(pd);
//			}
        } else {
            // 生存企业使用期限信息
            corpTimeService.delete(pd);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//			String DELIVERDATE = sdf.format(new Date());
//			pd.put("DELIVERDATE", pd.get("DELIVERDATE"));
            PageData time = new PageData();
            time.put("CORP_TIME_ID", this.get32UUID());    //主键
            time.put("CORPINFO_ID", pd.get("CORPINFO_ID"));
            time.put("OPERATOR", Jurisdiction.getUsername());    //操作人
            time.put("OPERATTIME", DateUtil.date2Str(new Date()));    //操作时间
            time.put("CREATOR", Jurisdiction.getUsername());    //创建人
            time.put("CREATTIME", DateUtil.date2Str(new Date()));    //创建时间
            time.put("TERM", pd.get("TERM"));
            time.put("USE_DATE_START", pd.get("DELIVERDATE"));
            String deliverDate = pd.getString("DELIVERDATE");
            Date dDate = sdf.parse(deliverDate);
            Calendar cal = Calendar.getInstance();
            cal.setTime(dDate);//设置起时间
            cal.add(Calendar.YEAR, Integer.valueOf(pd.getString("TERM"))); //增加n年
            time.put("USE_DATE_END", sdf.format(cal.getTime()));
            cal.add(Calendar.MONTH, 1);//增加一个月
            time.put("RETENTION_DATA_DATE", sdf.format(cal.getTime()));
            time.put("ISIN", "1");
            time.put("ISDELETE", "0");
            if (null != file && !file.isEmpty()) {
                String ffile = DateUtil.getDays();
                String fileName = this.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
                smb.sshSftp(file, fileName, Const.FILEPATHFILE + ffile);
                time.put("CONTRACT_FILE", Const.FILEPATHFILE + ffile + "/" + fileName);
            }
            corpTimeService.save(time);
        }

        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }


    /**
     * 去修改页面获取数据
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/goEdit")
    @ResponseBody
    public Object goEdit() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
//		if(pd.get("CORPINFO_ID")==null || Tools.isEmpty(pd.get("CORPINFO_ID").toString())) {
//			pd.put("CORPINFO_ID",Jurisdiction.getCORPINFO_ID());
//		}

        PageData cpd = new PageData();
        cpd.put("CORPINFO_ID", pd.getString("CORPINFO_ID"));
        if (!"".equals(Jurisdiction.getAGENCY_MANAGEMENT_ID()) && null != (Jurisdiction.getAGENCY_MANAGEMENT_ID())) {
            cpd.put("AGENCY_MANAGEMENT_ID", Jurisdiction.getAGENCY_MANAGEMENT_ID());
        } else {
            cpd.put("AGENCY_MANAGEMENT_ID", pd.getString("AGENCY_MANAGEMENT_ID"));
        }
        cpd = maintenanceuserinfoService.findById(cpd);    //根据ID读取
        pd = corpinfoService.findById(pd);    //根据ID读取
        PageData pd2 = new PageData();
        pd2.put("FOREIGN_KEY", pd.getString("CORPINFO_ID"));
        pd2.put("TYPE", 1);
        List<PageData> busImgs = imgfilesService.listAll(pd2);//营业执照图片

        pd2.put("TYPE", 2);
        List<PageData> fourImgs = imgfilesService.listAll(pd2);//四色图照图片
        if (pd != null && pd.get("FOURTYPE") != null && Tools.notEmpty(pd.get("FOURTYPE").toString())) {
            if ("2".equals(pd.get("FOURTYPE").toString())) {
                if (fourImgs != null && fourImgs.size() > 0) {
                    PageData fourImg3D = new PageData();
                    fourImg3D.put("name", fourImgs.get(0).get("FILEPATH"));
                    pd.put("FFILE", fourImg3D);
                }
            } else {
                map.put("fourImgs", fourImgs);
            }
        }

        List<String> POSSESSIONALL = new ArrayList<String>();
        if (pd.get("PROVINCE") != null && Tools.notEmpty(pd.get("PROVINCE").toString())) {
            POSSESSIONALL.add(pd.get("PROVINCE").toString());
        }
        if (pd.get("CITY") != null && Tools.notEmpty(pd.get("CITY").toString())) {
            POSSESSIONALL.add(pd.get("CITY").toString());
        }
        if (pd.get("COUNTY") != null && Tools.notEmpty(pd.get("COUNTY").toString())) {
            POSSESSIONALL.add(pd.get("COUNTY").toString());
        }
        if (pd.get("VILLAGE") != null && Tools.notEmpty(pd.get("VILLAGE").toString())) {
            POSSESSIONALL.add(pd.get("VILLAGE").toString());
        }
        if (pd.get("STREET") != null && Tools.notEmpty(pd.get("STREET").toString())) {
            POSSESSIONALL.add(pd.get("STREET").toString());
        }
//		if(POSSESSIONALL != null && POSSESSIONALL.size() > 0) {
//			pd.put("posOption", initDicTreeByNum(POSSESSIONALL.get(POSSESSIONALL.size()-1),POSSESSIONALL.size()));
//		}
        List<String> ECO_TYPEALL = new ArrayList<String>();
        if (pd.get("ECO_TYPE") != null && Tools.notEmpty(pd.get("ECO_TYPE").toString())) {
            ECO_TYPEALL.add(pd.get("ECO_TYPE").toString());
        }
        if (pd.get("ECO_TYPE2") != null && Tools.notEmpty(pd.get("ECO_TYPE2").toString())) {
            ECO_TYPEALL.add(pd.get("ECO_TYPE2").toString());
        }
//		if(ECO_TYPEALL != null && ECO_TYPEALL.size() > 0) {
//			pd.put("ecoOption", initDicTree(ECO_TYPEALL.get(ECO_TYPEALL.size()-1)));
//		}
        List<String> CORP_TYPEALL = new ArrayList<String>();
        if (pd.get("CORP_TYPE") != null && Tools.notEmpty(pd.get("CORP_TYPE").toString())) {
            CORP_TYPEALL.add(pd.get("CORP_TYPE").toString());
        }
        if (pd.get("CORP_TYPE2") != null && Tools.notEmpty(pd.get("CORP_TYPE2").toString())) {
            CORP_TYPEALL.add(pd.get("CORP_TYPE2").toString());
        }
        if (pd.get("CORP_TYPE3") != null && Tools.notEmpty(pd.get("CORP_TYPE3").toString())) {
            CORP_TYPEALL.add(pd.get("CORP_TYPE3").toString());
        }
        if (pd.get("CORP_TYPE4") != null && Tools.notEmpty(pd.get("CORP_TYPE4").toString())) {
            CORP_TYPEALL.add(pd.get("CORP_TYPE4").toString());
        }
//		if(CORP_TYPEALL != null && CORP_TYPEALL.size() > 0) {
//			pd.put("industryOption", initDicTree(CORP_TYPEALL.get(CORP_TYPEALL.size()-1)));
//		}
        if (Tools.notEmpty(pd.getString("CORP_OF_TYPE"))) {
            PageData corpOfType = new PageData();
            corpOfType.put("CORPTYPE_ID", pd.get("CORP_OF_TYPE"));
            corpOfType = corptypeService.findById(corpOfType);
            pd.put("CORP_OF_TYPE_NAME", corpOfType.get("NAME"));

        }
        if (Tools.notEmpty(pd.getString("CORP_OF_TYPE2"))) {
            PageData corpOfType2 = new PageData();
            corpOfType2.put("CORPTYPE_ID", pd.get("CORP_OF_TYPE2"));
            corpOfType2 = corptypeService.findById(corpOfType2);
            pd.put("CORP_OF_TYPE_NAME2", corpOfType2.get("NAME"));
        }

        pd.put("POSSESSION", POSSESSIONALL);
        pd.put("ECO_TYPEALL", ECO_TYPEALL);
        pd.put("INDUSTRYALL", CORP_TYPEALL);
        if ("0".equals(pd.get("PERSONNEL_POSITION").toString())) {
            pd.putAll(corpplsinfoService.findById(pd));
        }
        map.put("pd", pd);
        map.put("cpd", cpd);
        map.put("busImgs", busImgs);
        map.put("fourImgs", fourImgs);
        map.put("result", errInfo);
        return map;
    }


    @RequestMapping(value = "/goLogin")
    @ResponseBody
    public Object goLogin() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        if (pd.get("CORPINFO_ID") == null || Tools.isEmpty(pd.get("CORPINFO_ID").toString())) {
            pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
        }
        pd = corpinfoService.findById(pd);    //根据ID读取
        PageData users = new PageData();
        users.put("USERNAME", pd.getString("CORP_NAME"));
        users = usersService.findByUsername(users);
        map.put("pd", pd);
        map.put("USERNAME", Jurisdiction.getUsername());
        map.put("users", users);
        map.put("result", errInfo);
        return map;
    }

    @RequestMapping(value = "/corpListAll")
    @ResponseBody
    public Object corpListAll() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        if (!Jurisdiction.getUsername().equals("admin") && !Jurisdiction.getUsername().equals("adminsuper")) {
            pd.put("CREATOR", Jurisdiction.getUsername());
        }
        System.out.println(Jurisdiction.getUsername());
        List<PageData> corpinfoList = corpinfoService.listAll(pd);
        map.put("corpinfoList", corpinfoList);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 获取企业集合
     *
     * @return
     */
    @RequestMapping(value = "/listAll")
    @ResponseBody
    public Object listAll() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        List<PageData> varList = corpinfoService.listAll(pd);
        map.put("varList", varList);                //返回结果
        map.put("result", errInfo);                //返回结果
        return map;
    }

    /**
     * 判断企业是否存在
     *
     * @return
     */
    @RequestMapping(value = "/hasCorp")
    @ResponseBody
    public Object hasUser() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        String msg = "";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd = corpinfoService.findByName(pd);
        if (pd != null) {
            map.put("pd", pd);
            errInfo = "error";
            msg = "企业名称重复";
        }

        map.put("msg", msg);
        map.put("result", errInfo);                //返回结果
        return map;
    }

    /**
     * 判断代理商创建企业数量
     *
     * @return
     */
    @RequestMapping(value = "/getCreatCount")
    @ResponseBody
    public Object getCreatCount() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        if (!Jurisdiction.getUsername().equals("admin") && !Jurisdiction.getUsername().equals("adminsuper")) {
            pd.put("CREATOR", Jurisdiction.getUsername());
            List<PageData> corpinfoList = corpinfoService.listAll(pd);
            pd.put("USER_ID", Jurisdiction.getUSER_ID());
            PageData user = usersService.findById(pd);
            if (Integer.parseInt(user.getString("CREATCOUNT")) <= corpinfoList.size()) {
                errInfo = "error";
            }
            map.put("sykhs", Integer.parseInt(user.getString("CREATCOUNT")) - corpinfoList.size());
        }
        map.put("result", errInfo);                //返回结果
        return map;
    }

    /**
     * 批量删除
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/deleteAll")
    @RequiresPermissions("corpinfo:del")
    @ResponseBody
    public Object deleteAll() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        String DATA_IDS = pd.getString("DATA_IDS");
        if (Tools.notEmpty(DATA_IDS)) {
            String ArrayDATA_IDS[] = DATA_IDS.split(",");
            corpinfoService.deleteAll(ArrayDATA_IDS);
            errInfo = "success";
        } else {
            errInfo = "error";
        }
        map.put("result", errInfo);                //返回结果
        return map;
    }

    /**
     * 导出到excel
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/excel")
    @RequiresPermissions("toExcel")
    public ModelAndView exportExcel() throws Exception {
        ModelAndView mv = new ModelAndView();
        PageData pd = new PageData();
        pd = this.getPageData();
        Map<String, Object> dataMap = new HashMap<String, Object>();
        List<String> titles = new ArrayList<String>();
        titles.add("企业名称");    //1
        titles.add("统一社会信用代码");    //2
        titles.add("所属区域");    //3
        titles.add("通讯地址");    //4
        titles.add("成立时间");    //5
        titles.add("规模");    //6
        titles.add("经度");    //7
        titles.add("纬度");    //8
        titles.add("邮政编码");    //9
        titles.add("职工人数(人)");    //10
        titles.add("占地面积（㎡）");    //11
        titles.add("资产总额（万元）");    //12
        titles.add("注册资金（万元）");    //13
        titles.add("上年度实际营收（万元）");    //14
        titles.add("年利润（万元）");    //15
        titles.add("经济类型");    //16
        titles.add("所属行业");    //17
        titles.add("所属专业");    //18
        titles.add("所属小专业");    //19
        titles.add("法定代表人");    //20
        titles.add("法人职务");    //21
        titles.add("法人办公电话");    //22
        titles.add("法人手机号");    //23
        titles.add("联系人");    //24
        titles.add("联系人手机号");    //25
        titles.add("整改负责人");    //26
        titles.add("整改人电话");    //27
        titles.add("是否删除");    //28
        titles.add("修改人");    //29
        titles.add("修改时间");    //30
        titles.add("添加时间");    //31
        titles.add("添加人");    //32
        dataMap.put("titles", titles);
        List<PageData> varOList = corpinfoService.listAll(pd);
        List<PageData> varList = new ArrayList<PageData>();
        for (int i = 0; i < varOList.size(); i++) {
            PageData vpd = new PageData();
            vpd.put("var1", varOList.get(i).getString("CORP_NAME"));        //1
            vpd.put("var2", varOList.get(i).getString("CODE"));        //2
            vpd.put("var3", varOList.get(i).getString("COMPANY_AREA"));        //3
            vpd.put("var4", varOList.get(i).getString("ADDRESS"));        //4
            vpd.put("var5", varOList.get(i).getString("CREATE_DATE"));        //5
            vpd.put("var6", varOList.get(i).getString("SCALE"));        //6
            vpd.put("var7", varOList.get(i).get("LONGITUDE").toString());    //7
            vpd.put("var8", varOList.get(i).get("LATITUDE").toString());    //8
            vpd.put("var9", varOList.get(i).getString("POSTAL_CODE"));        //9
            vpd.put("var10", varOList.get(i).get("EMPLOYEES").toString());    //10
            vpd.put("var11", varOList.get(i).get("AREA_COVERED").toString());    //11
            vpd.put("var12", varOList.get(i).get("TOTALASSETS").toString());    //12
            vpd.put("var13", varOList.get(i).get("REGCAPITAL").toString());    //13
            vpd.put("var14", varOList.get(i).get("SALESREVENUE").toString());    //14
            vpd.put("var15", varOList.get(i).get("ANNUALPROFIT").toString());    //15
            vpd.put("var16", varOList.get(i).getString("ECO_TYPE"));        //16
            vpd.put("var17", varOList.get(i).getString("INDUSTRY"));        //17
            vpd.put("var18", varOList.get(i).getString("CORP_TYPE"));        //18
            vpd.put("var19", varOList.get(i).getString("CORP_TYPE_SMALL"));        //19
            vpd.put("var20", varOList.get(i).getString("LR_NAME"));        //20
            vpd.put("var21", varOList.get(i).getString("LR_POSITION"));        //21
            vpd.put("var22", varOList.get(i).getString("LR_PHONE"));        //22
            vpd.put("var23", varOList.get(i).getString("LR_MOBILE"));        //23
            vpd.put("var24", varOList.get(i).getString("CONTACTS"));        //24
            vpd.put("var25", varOList.get(i).getString("CONTACTS_PHONE"));        //25
            vpd.put("var26", varOList.get(i).getString("CHECKPERSON"));        //26
            vpd.put("var27", varOList.get(i).getString("CHECKPERSONPHONE"));        //27
            vpd.put("var28", varOList.get(i).get("ISDELETE").toString());    //28
            vpd.put("var29", varOList.get(i).getString("OPERATOR"));        //29
            vpd.put("var30", varOList.get(i).getString("OPERATTIME"));        //30
            vpd.put("var31", varOList.get(i).getString("CREATTIME"));        //31
            vpd.put("var32", varOList.get(i).getString("CREATOR"));        //32
            varList.add(vpd);
        }
        dataMap.put("varList", varList);
        ObjectExcelView erv = new ObjectExcelView();
        mv = new ModelAndView(erv, dataMap);
        return mv;
    }

    /**
     * 根据所属行业，专业，小专业列表 获取数据
     *
     * @param page
     * @throws Exception
     */
    @RequestMapping(value = "/listByCorpType")
    @RequiresPermissions("corpinfo:list")
    @ResponseBody
    public Object listByCorpType(Page page) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        String KEYWORDS = pd.getString("KEYWORDS");                        //关键词检索条件
        if (Tools.notEmpty(KEYWORDS)) pd.put("KEYWORDS", KEYWORDS.trim());
        List<PageData> varList = corpinfoService.listByCorpType(pd);    //列出CorpInfo列表
        map.put("varList", varList);
        map.put("result", errInfo);
        return map;
    }

    /**
     * @param page
     * @throws Exception
     */
    @RequestMapping(value = "/resetPwd")
    @RequiresPermissions("corpinfo:edit")
    @ResponseBody
    public Object resetPwd(Page page) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        String msg = "";
        PageData pd = new PageData();
        pd = this.getPageData();
        PageData userPd = new PageData();
        //corpInfo
        userPd.put("CORPINFO_ID", pd.get("corpInfo"));
        List<PageData> mainUser = usersService.findCorpMain(userPd); //企业的主账号
        if (mainUser.size() > 0) {
            for (PageData pageData : mainUser) {
                String pwd = new SimpleHash("SHA-1", pageData.getString("USERNAME"), "Aa@123456").toString();
                PageData updateUser = new PageData();
                updateUser.put("PASSWORD", pwd);
                updateUser.put("USER_ID", pageData.getString("USER_ID"));
                usersService.editPassword(updateUser);
            }

        } else {
            errInfo = "error";
            msg = "该企业未找到主账号，请联系管理员！";
        }

        map.put("msg", msg);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 交付
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/deliver")
    @ResponseBody
    public Object deliver(@RequestParam(value = "file", required = false) MultipartFile file) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        if (pd.get("OPERATIONTYPE") != null && Tools.notEmpty(pd.get("OPERATIONTYPE").toString()) && "1".equals(pd.get("OPERATIONTYPE").toString())) { // 清除基础信息
            // 查询隐患检查图片
            List<String> hcImgList = imgfileService.listHiddenCheckImgs(pd);
            // 删除图片文件

            if (hcImgList != null && hcImgList.size() > 0) {
                for (int i = 0; i < hcImgList.size(); i++) {
                    String files = hcImgList.get(i);
                    Smb.delete(String.valueOf(files));
                }
            }

//			// 删除隐患验收照片数据
//			imgfilesService.deleteHiddenCheckImgs(pd);
            // 删除隐患验收照片数据
            imgfileService.deleteHiddenCheckImgs(pd);
            // 删除清单验收数据
            hiddenCheckService.deleteByCorp(pd);
            // 查询隐患照片（隐患照片及整改照片）
            List<String> hImgList = imgfileService.listHiddenImgs(pd);
            // 删除图片文件
//			Smb.deleteFiles(hImgList);
            if (hImgList != null && hImgList.size() > 0) {
                for (int i = 0; i < hImgList.size(); i++) {
                    String file1 = hImgList.get(i);
                    Smb.delete(String.valueOf(file1));
                }
            }
            // 删除隐患照片（包括隐患照片及整改照片）
            imgfileService.deleteHiddenImgs(pd);
            // 删除所有隐患
            hiddenService.hiddenEndTrial(pd);
            // 删除清单检查记录检查人
            checkUserService.deleteByCorp(pd);
            // 删除清单检查记录检查项
            recordItemService.deleteByCorp(pd);
            // 删除清单检查记录
            checkRecordService.deleteByCorp(pd);
            // 删除每日清单应检查数
            listStatisticsService.deleteByCorp(pd);
        }
        // 修改企业信息
        corpinfoService.editDeliver(pd);
        // 生存企业使用期限信息
        PageData time = new PageData();

        time.put("CORP_TIME_ID", this.get32UUID());    //主键
        time.put("CORPINFO_ID", pd.get("CORPINFO_ID"));
        time.put("OPERATOR", Jurisdiction.getUsername());    //操作人
        time.put("OPERATTIME", DateUtil.date2Str(new Date()));    //操作时间
        time.put("CREATOR", Jurisdiction.getUsername());    //创建人
        time.put("CREATTIME", DateUtil.date2Str(new Date()));    //创建时间
        time.put("USE_DATE_START", pd.get("DELIVERDATE"));
        String deliverDate = pd.getString("DELIVERDATE");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dDate = sdf.parse(deliverDate);
        Calendar cal = Calendar.getInstance();
        cal.setTime(dDate);//设置起时间
        cal.add(Calendar.YEAR, Integer.valueOf(pd.getString("TERM")));//增加一年
        time.put("USE_DATE_END", sdf.format(cal.getTime()));
        cal.add(Calendar.MONTH, 1);//增加一个月
        time.put("RETENTION_DATA_DATE", sdf.format(cal.getTime()));
        time.put("ISIN", "1");
        time.put("ISDELETE", "0");
        if (null != file && !file.isEmpty()) {
            String ffile = DateUtil.getDays();
//			String filePath = PathUtil.getProjectpath() + Const.FILEPATHFILE + ffile;	//文件上传路径
//			String fileName = FileUpload.fileUp(file, filePath, this.get32UUID());				//执行上传
            String fileName = this.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
            smb.sshSftp(file, fileName, Const.FILEPATHFILE + ffile);
            time.put("CONTRACT_FILE", Const.FILEPATHFILE + ffile + "/" + fileName);
        }
        corpTimeService.save(time);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 企业续费
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/renew")
    @ResponseBody
    public Object renew(@RequestParam(value = "file", required = false) MultipartFile file) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        // 生存企业使用期限信息
        PageData time = new PageData();

        time.put("CORP_TIME_ID", this.get32UUID());    //主键
        time.put("CORPINFO_ID", pd.get("CORPINFO_ID"));
        time.put("OPERATOR", Jurisdiction.getUsername());    //操作人
        time.put("OPERATTIME", DateUtil.date2Str(new Date()));    //操作时间
        time.put("CREATOR", Jurisdiction.getUsername());    //创建人
        time.put("CREATTIME", DateUtil.date2Str(new Date()));    //创建时间
        PageData maxEndDate = corpTimeService.findMaxEndDate(pd);
        String startDate = DateUtil.date2Str(new Date(), "yyyy-MM-dd");// 开始时间默认今天
        // 如果今天之后还有使用期限。，则以结尾作为开头
        if (maxEndDate != null && maxEndDate.get("USE_DATE_END") != null && Tools.notEmpty(maxEndDate.get("USE_DATE_END").toString())) {
            startDate = maxEndDate.get("USE_DATE_END").toString();
        }
        time.put("USE_DATE_START", startDate);
//		String deliverDate = pd.getString("DELIVERDATE");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dDate = sdf.parse(startDate);
        Calendar cal = Calendar.getInstance();
        cal.setTime(dDate);//设置起时间
        cal.add(Calendar.YEAR, Integer.valueOf(pd.getString("TERM")));//增加n年
        time.put("USE_DATE_END", sdf.format(cal.getTime()));
        cal.add(Calendar.MONTH, 1);//增加一个月
        time.put("RETENTION_DATA_DATE", sdf.format(cal.getTime()));
        time.put("ISIN", "0");
        time.put("ISDELETE", "0");
        if (null != file && !file.isEmpty()) {
            String ffile = DateUtil.getDays();
//			String filePath = PathUtil.getProjectpath() + Const.FILEPATHFILE + ffile;	//文件上传路径
//			String fileName = FileUpload.fileUp(file, filePath, this.get32UUID());				//执行上传
            String fileName = this.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
            smb.sshSftp(file, fileName, Const.FILEPATHFILE + ffile);
            time.put("CONTRACT_FILE", Const.FILEPATHFILE + ffile + "/" + fileName);
        }
        corpTimeService.save(time);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 企业过期后启用
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/enable")
    @ResponseBody
    public Object enable(@RequestParam(value = "file", required = false) MultipartFile file) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        // 生存企业使用期限信息
        PageData time = new PageData();

        time.put("CORP_TIME_ID", this.get32UUID());    //主键
        time.put("CORPINFO_ID", pd.get("CORPINFO_ID"));
        time.put("OPERATOR", Jurisdiction.getUsername());    //操作人
        time.put("OPERATTIME", DateUtil.date2Str(new Date()));    //操作时间
        time.put("CREATOR", Jurisdiction.getUsername());    //创建人
        time.put("CREATTIME", DateUtil.date2Str(new Date()));    //创建时间
        String startDate = DateUtil.date2Str(new Date(), "yyyy-MM-dd");
        time.put("USE_DATE_START", startDate);
//		String deliverDate = pd.getString("DELIVERDATE");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dDate = sdf.parse(startDate);
        Calendar cal = Calendar.getInstance();
        String TERM = pd.getString("TERM");
        if (TERM.length() > 1) {        // 判断日期是否为个位数
            Date termDate = sdf.parse(TERM);
            cal.setTime(termDate);
            time.put("USE_DATE_END", sdf.format(cal.getTime()));
            cal.add(Calendar.MONTH, 1);//增加一个月
            time.put("RETENTION_DATE_DATE", sdf.format(cal.getTime()));
        } else {
            cal.setTime(dDate);//设置起时间
            cal.add(Calendar.YEAR, Integer.parseInt(TERM));//增加一年
            time.put("USE_DATE_END", sdf.format(cal.getTime()));
            cal.add(Calendar.MONTH, 1);//增加一个月
            time.put("RETENTION_DATA_DATE", sdf.format(cal.getTime()));
        }
        time.put("NOTES", pd.getString("NOTES"));
        time.put("ISIN", "1");
        time.put("ISDELETE", "0");
        if (null != file && !file.isEmpty()) {
            String ffile = DateUtil.getDays();
//			String filePath = PathUtil.getProjectpath() + Const.FILEPATHFILE + ffile;	//文件上传路径
//			String fileName = FileUpload.fileUp(file, filePath, this.get32UUID());				//执行上传
            String fileName = this.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
            smb.sshSftp(file, fileName, Const.FILEPATHFILE + ffile);
            time.put("CONTRACT_FILE", Const.FILEPATHFILE + ffile + "/" + fileName);
        }
        corpTimeService.save(time);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    @RequestMapping(value = "/endTrial")
    @ResponseBody
    public Object endTrial() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        // 查询隐患检查图片
        List<String> hcImgList = imgfileService.listHiddenCheckImgs(pd);
        // 删除图片文件
//		Smb.delete(hcImgList);
        if (hcImgList != null && hcImgList.size() > 0) {
            for (int i = 0; i < hcImgList.size(); i++) {
                String file2 = hcImgList.get(i);
                Smb.delete(String.valueOf(file2));
            }
        }
//		// 删除隐患验收照片数据
//		imgfilesService.deleteHiddenCheckImgs(pd);
        // 删除隐患验收照片数据
        imgfileService.deleteHiddenCheckImgs(pd);
        // 删除清单验收数据
        hiddenCheckService.deleteByCorp(pd);
        // 查询隐患照片（隐患照片及整改照片）
        List<String> hImgList = imgfilesService.listHiddenImgs(pd);
        // 删除图片文件
//		Smb.delete(hImgList);
        if (hImgList != null && hImgList.size() > 0) {
            for (int i = 0; i < hImgList.size(); i++) {
                String file4 = hImgList.get(i);
                Smb.delete(String.valueOf(file4));
            }
        }
        // 删除隐患照片（包括隐患照片及整改照片）
        imgfileService.deleteHiddenImgs(pd);
        // 删除所有隐患
        hiddenService.hiddenEndTrial(pd);
        // 删除清单检查记录检查人
        checkUserService.deleteByCorp(pd);
        // 删除清单检查记录检查项
        recordItemService.deleteByCorp(pd);
        // 删除清单检查记录
        checkRecordService.deleteByCorp(pd);
        // 删除每日清单应检查数
        listStatisticsService.deleteByCorp(pd);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 初始化数据字典懒加载下拉树
     *
     * @param dictionaries_id
     * @return
     * @throws Exception
     */
    public List<PageData> initDicTree(String dictionaries_id) throws Exception {
        PageData dic = new PageData();
        dic.put("DICTIONARIES_ID", dictionaries_id);
        dic = dictionariesService.findById(dic);
        dic.put("value", dic.get("DICTIONARIES_ID"));
        dic.put("id", dic.get("DICTIONARIES_ID"));
        dic.put("label", dic.get("NAME"));
        List<PageData> industryOption = dictionariesService.getTreeFromBelow(new ArrayList<PageData>(), dic);
        return industryOption;
    }

    /**
     * 初始化数据字典懒加载下拉树（根据编码）
     *
     * @param dictionaries_id
     * @return
     * @throws Exception
     */
    public List<PageData> initDicTreeByNum(String dictionaries_bianma, int level) throws Exception {
        PageData dic = new PageData();
        dic.put("BIANMA", dictionaries_bianma);
        dic = dictionariesService.findByBianma(dic);
        dic.put("value", dic.get("DICTIONARIES_ID"));
        dic.put("numValue", dic.get("BIANMA"));
        dic.put("id", dic.get("DICTIONARIES_ID"));
        dic.put("label", dic.get("NAME"));
        dic.put("level", level);

        PageData agent = new PageData();
        Map<String, Object> agentArea = new HashMap<String, Object>();
        int num = 1;//递归的次数
        List<PageData> industryOption = dictionariesService.getTreeFromBelow(new ArrayList<PageData>(), dic, level, agent, num);
        return industryOption;
    }

    public boolean editCorpImg(MultipartFile[] files, PageData pd) throws Exception {
        String TYPE = pd.getString("TYPE");
        String FOREIGN_KEY = pd.getString("FOREIGN_KEY");
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        if (TYPE.equals("2") && pd.get("EDITFOURTYPE") != null && Tools.notEmpty(pd.get("EDITFOURTYPE").toString()) && pd.get("EDITFOURTYPE").toString().equals("false")) {//先删除原四色图(json)
            PageData pd2 = new PageData();
            pd2.put("FOREIGN_KEY", FOREIGN_KEY);
            pd2.put("TYPE", TYPE);
            List<PageData> four = imgfilesService.listAll(pd2);
            for (PageData pageData : four) {
                File old = new File(PathUtil.getProjectpath() + pageData.getString("FILEPATH"));
                old.delete();
                imgfilesService.delete(pageData);
            }
        }
        if (files != null && files.length > 0) {
            for (int i = 0; i < files.length; i++) {
                MultipartFile file = files[i];
//                 保存文件
                File tempFile = new File(file.getOriginalFilename());
                FileUtils.copyInputStreamToFile(file.getInputStream(), tempFile);
                if (!FileUpload.isImage(tempFile) && !TYPE.equals("2")) {//四色图改为json文件,不用判断类型
                    map.put("result", "failed");
                    map.put("exception", "上传图片格式不正确，请重新上传");
                    return false;
                }
                tempFile.delete();

                String ffile = DateUtil.getDays();
                String filePath = PathUtil.getProjectpath() + Const.FILEPATHFILE + ffile;    //文件上传路径
                String fileName = "";                //执0行上传

                if (null != file && !file.isEmpty()) {
//        			String filePath = PathUtil.getProjectpath() +"/"+ Const.FILEPATHYHTP + ffile;	//文件上传路径
                    //fileName = FileUpload.fileUp(file, filePath, this.get32UUID());				//执行上传
                    fileName = this.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
                    byte[] bytes = file.getBytes();
                    Smb.sshSftp(file, fileName, Const.FILEPATHYHTP + ffile);
                }
                pd.put("IMGFILES_ID", this.get32UUID());
                pd.put("FILEPATH", Const.FILEPATHYHTP + ffile + "/" + fileName);
                imgfilesService.save(pd);
            }
        }

        map.put("result", errInfo);
        return true;
    }

    public void initWorkRules(String corpInfnId) throws Exception {
        List<PageData> ruleList = new ArrayList<PageData>();
        List<PageData> periodList = new ArrayList<PageData>();
        PageData rule1 = new PageData();
        rule1.put("SHIFTWORKRULES_ID", get32UUID());
        rule1.put("NAME", "常白班");
        rule1.put("CORPINFO_ID", corpInfnId);
        rule1.put("CREATTIME", DateUtil.date2Str(new Date()));
        rule1.put("OPERATTIME", DateUtil.date2Str(new Date()));
        rule1.put("ISDELETE", "0");
        rule1.put("PARENTID", "0");
        rule1.put("LEVEL", "1");
        rule1.put("ISCUSTOM", "0");

        PageData rule1_1 = new PageData();
        rule1_1.put("SHIFTWORKRULES_ID", get32UUID());
        rule1_1.put("NAME", "周六日双休");
        rule1_1.put("CORPINFO_ID", corpInfnId);
        rule1_1.put("CREATTIME", DateUtil.date2Str(new Date()));
        rule1_1.put("OPERATTIME", DateUtil.date2Str(new Date()));
        rule1_1.put("ISDELETE", "0");
        rule1_1.put("PARENTID", rule1.get("SHIFTWORKRULES_ID"));
        rule1_1.put("LEVEL", "2");
        rule1_1.put("ISCUSTOM", "1");

        PageData period1_1 = new PageData();
        period1_1.put("SHIFTWORKPERIOD_ID", get32UUID());
        period1_1.put("ONDAY", "5");
        period1_1.put("OFFDAY", "2");
        period1_1.put("CORPINFO_ID", corpInfnId);
        period1_1.put("CREATTIME", DateUtil.date2Str(new Date()));
        period1_1.put("OPERATTIME", DateUtil.date2Str(new Date()));
        period1_1.put("ISDELETE", "0");
        period1_1.put("SHIFTWORKRULES_ID", rule1_1.get("SHIFTWORKRULES_ID"));
        period1_1.put("SORT", "1");
        period1_1.put("ISEND", "1");


        PageData rule1_2 = new PageData();
        rule1_2.put("SHIFTWORKRULES_ID", get32UUID());
        rule1_2.put("NAME", "周日单休");
        rule1_2.put("CORPINFO_ID", corpInfnId);
        rule1_2.put("CREATTIME", DateUtil.date2Str(new Date()));
        rule1_2.put("OPERATTIME", DateUtil.date2Str(new Date()));
        rule1_2.put("ISDELETE", "0");
        rule1_2.put("PARENTID", rule1.get("SHIFTWORKRULES_ID"));
        rule1_2.put("LEVEL", "2");
        rule1_2.put("ISCUSTOM", "1");

        PageData period1_2 = new PageData();
        period1_2.put("SHIFTWORKPERIOD_ID", get32UUID());
        period1_2.put("ONDAY", "6");
        period1_2.put("OFFDAY", "1");
        period1_2.put("CORPINFO_ID", corpInfnId);
        period1_2.put("CREATTIME", DateUtil.date2Str(new Date()));
        period1_2.put("OPERATTIME", DateUtil.date2Str(new Date()));
        period1_2.put("ISDELETE", "0");
        period1_2.put("SHIFTWORKRULES_ID", rule1_2.get("SHIFTWORKRULES_ID"));
        period1_2.put("SORT", "1");
        period1_2.put("ISEND", "1");


        PageData rule1_3 = new PageData();
        rule1_3.put("SHIFTWORKRULES_ID", get32UUID());
        rule1_3.put("NAME", "每日");
        rule1_3.put("CORPINFO_ID", corpInfnId);
        rule1_3.put("CREATTIME", DateUtil.date2Str(new Date()));
        rule1_3.put("OPERATTIME", DateUtil.date2Str(new Date()));
        rule1_3.put("ISDELETE", "0");
        rule1_3.put("PARENTID", rule1.get("SHIFTWORKRULES_ID"));
        rule1_3.put("LEVEL", "2");
        rule1_3.put("ISCUSTOM", "0");

        PageData rule2 = new PageData();
        rule2.put("SHIFTWORKRULES_ID", get32UUID());
        rule2.put("NAME", "倒班");
        rule2.put("CORPINFO_ID", corpInfnId);
        rule2.put("CREATTIME", DateUtil.date2Str(new Date()));
        rule2.put("OPERATTIME", DateUtil.date2Str(new Date()));
        rule2.put("ISDELETE", "0");
        rule2.put("PARENTID", "0");
        rule2.put("LEVEL", "1");
        rule2.put("ISCUSTOM", "0");


        PageData rule2_1 = new PageData();
        rule2_1.put("SHIFTWORKRULES_ID", get32UUID());
        rule2_1.put("NAME", "一天一休");
        rule2_1.put("CORPINFO_ID", corpInfnId);
        rule2_1.put("CREATTIME", DateUtil.date2Str(new Date()));
        rule2_1.put("OPERATTIME", DateUtil.date2Str(new Date()));
        rule2_1.put("ISDELETE", "0");
        rule2_1.put("PARENTID", rule2.get("SHIFTWORKRULES_ID"));
        rule2_1.put("LEVEL", "2");
        rule2_1.put("ISCUSTOM", "1");

        PageData period2_1 = new PageData();
        period2_1.put("SHIFTWORKPERIOD_ID", get32UUID());
        period2_1.put("ONDAY", "1");
        period2_1.put("OFFDAY", "1");
        period2_1.put("CORPINFO_ID", corpInfnId);
        period2_1.put("CREATTIME", DateUtil.date2Str(new Date()));
        period2_1.put("OPERATTIME", DateUtil.date2Str(new Date()));
        period2_1.put("ISDELETE", "0");
        period2_1.put("SHIFTWORKRULES_ID", rule2_1.get("SHIFTWORKRULES_ID"));
        period2_1.put("SORT", "1");
        period2_1.put("ISEND", "1");

        ruleList.add(rule1);
        ruleList.add(rule1_1);
        ruleList.add(rule1_2);
        ruleList.add(rule1_3);
        ruleList.add(rule2);
        ruleList.add(rule2_1);
        periodList.add(period1_1);
        periodList.add(period1_2);
        periodList.add(period2_1);
        for (PageData rule : ruleList) {
            shiftWorkRulesService.save(rule);
        }
        System.out.println(periodList.size());
        for (PageData period : periodList) {
            shiftWorkPeriodService.save(period);
        }

    }


    /**
     * 保存企业信息
     *
     * @param pd
     */
    private void saveCorpInfo(PageData pd) throws Exception {

        pd.put("ISDELETE", "0");    //是否删除
        pd.put("ISDELIVER", "0");    //是否交付 1-已交付 0- 未交付
        pd.put("ISRECEIVE", "1");    //是否发送短信0不发1发
        pd.put("ISUSE", "0");    //是否启用
        pd.put("SMS_COUNT", "500");    //短息条数
        pd.put("OPERATOR", Jurisdiction.getUsername());    //操作人
        pd.put("OPERATTIME", DateUtil.date2Str(new Date()));    //操作时间
        pd.put("CREATOR", Jurisdiction.getUsername());    //创建人
        pd.put("CREATUSERID", Jurisdiction.getUSER_ID());    //创建人
        pd.put("CREATTIME", DateUtil.date2Str(new Date()));    //创建时间
        if (!Tools.isEmpty(pd.get("CORP_OF_TYPEAll"))) {
            PageData corptypePd = new PageData();
            corptypePd.put("CORPTYPE_ID", pd.get("CORP_OF_TYPEAll"));
            PageData corptype = corptypeService.findById(corptypePd);
            if (null != corptype) {
                if ("0".equals(corptype.get("PARENT_ID").toString())) {
                    pd.put("CORP_OF_TYPE", corptype.get("CORPTYPE_ID"));
                } else {
                    pd.put("CORP_OF_TYPE", corptype.get("PARENT_ID"));
                    pd.put("CORP_OF_TYPE2", corptype.get("CORPTYPE_ID"));
                }
            }
        }
        corpinfoService.save(pd);
    }

    /**
     * 保存围栏信息
     *
     * @param pd
     */
    private void saveElectronicFence(PageData pd) throws Exception {
        pd.put("CORPINFO_ID", pd.getString("CORPINFO_ID"));
        pd.put("ELECTRONIC_FENCE_AREA_ID", this.get32UUID());    //主键
        pd.put("ELECTRONIC_FENCE_AREA_NAME", pd.getString("CORP_NAME"));    //是否交付 1-已交付 0- 未交付
        pd.put("PARENT_ID", "0");    //是否发送短信0不发1发
        pd.put("ISDELETE", "0");    //是否启用
        pd.put("OPERATOR", Jurisdiction.getUsername());    //操作人
        pd.put("OPERATTIME", DateUtil.date2Str(new Date()));    //操作时间
        pd.put("CREATOR", Jurisdiction.getUsername());    //创建人
        pd.put("CREATTIME", DateUtil.date2Str(new Date()));    //创建时间
        electronicfenceService.save(pd);
    }

    /**
     * 保存试用企业信息
     *
     * @param pd
     */
    private void saveCorpTrial(PageData pd) throws Exception {
        Date d = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currdate = format.format(d);
        System.out.println(pd.get("TRIALTIME"));
        System.out.println("现在的日期是：" + currdate);

        Calendar ca = Calendar.getInstance();
//		ca.setTime(currdate);
        ca.add(Calendar.DATE, Integer.parseInt((String) pd.get("TRIALTIME")));// num为增加的天数，可以改变的
        d = ca.getTime();
        String enddate = format.format(d);
        System.out.println("增加天数以后的日期：" + enddate);
        pd.put("ID", this.get32UUID());    //主键
        pd.get("CORPINFO_ID");
        pd.put("ISDELETE", "0");    //是否删除
        pd.put("ISTRIAL", "0");    //
        pd.put("OPERATOR", Jurisdiction.getUsername());    //操作人
        pd.put("OPERATTIME", DateUtil.date2Str(new Date()));    //操作时间
        pd.put("TRIALTIME", enddate);
        corpinfoService.saveTrial(pd);
    }

    /**
     * 保存用户信息
     *
     * @param pd
     */
    @Transactional(rollbackFor = Exception.class)
    private void saveMaintenanceUserInfo(PageData pd) throws Exception {
        PageData muser = new PageData();
        muser.put("MAINTENANCE_ID", this.get32UUID());            //ID 主键
        muser.put("CORPINFO_ID", pd.get("CORPINFO_ID"));            //企业ID
        muser.put("MARKETING_PERSON", Tools.notEmpty(pd.getString("MARKETING_PERSON")) ? pd.get("MARKETING_PERSON") : "1");
        muser.put("AGENCY_MANAGEMENT_ID", Jurisdiction.getAGENCY_MANAGEMENT_ID());
        muser.put("ISDELETE", "0");                            //是否为主账号
        muser.put("CREATOR", Jurisdiction.getUsername());    //添加人
        muser.put("CREATTIME", DateUtil.date2Str(new Date()));    //添加时间
        muser.put("OPERATOR", Jurisdiction.getUsername());    //操作人
        muser.put("OPERATTIME", DateUtil.date2Str(new Date()));    //操作时间
        muser.put("ISDELETE", "0");//是否为主账号
        muser.put("WHETHER_PRE_SALE_SERVICE", pd.get("WHETHER_PRE_SALE_SERVICE"));
        muser.put("WHETHER_AFTER_SALES_SERVICE", pd.get("WHETHER_AFTER_SALES_SERVICE"));

        maintenanceuserinfoService.save(muser);                    //执行保存

    }


    /**
     * 保存部门信息
     *
     * @param pd
     */
    @Transactional(rollbackFor = Exception.class)
    private PageData saveDeptInfo(PageData pd) throws Exception {
        PageData dept = new PageData();
        dept.put("DEPARTMENT_ID", this.get32UUID());            //ID 主键
        dept.put("NAME", pd.get("CORP_NAME"));
        dept.put("PARENT_ID", 0);
        dept.put("ISSUPERVISE", 0);
        dept.put("TEL", pd.get("LR_MOBILE"));            //用户名
        dept.put("HEADMAN", pd.get("LR_NAME"));            //用户名
        dept.put("CORPINFO_ID", pd.get("CORPINFO_ID"));            //企业ID
        dept.put("ISSUPERVISE", "0");            //企业ID
        departmentService.save(dept);
        return dept;
    }

    /**
     * 保存用户信息
     *
     * @param pd
     */
    @Transactional(rollbackFor = Exception.class)

    private void saveUserInfo(PageData pd, List<PageData> mainRoles, PageData dept) throws Exception {
        PageData user = new PageData();
        user.put("USER_ID", this.get32UUID());            //ID 主键
        user.put("USERNAME", pd.get("CORP_NAME"));            //用户名
        user.put("NAME", pd.get("CORP_NAME"));            //用户名
        user.put("CORPINFO_ID", pd.get("CORPINFO_ID"));            //企业ID
        user.put("ROLE_ID", mainRoles.get(0).get("ROLE_ID"));            //角色 默认管理员
        user.put("LAST_LOGIN", "");                        //最后登录时间
        user.put("DEPARTMENT_ID", dept.get("DEPARTMENT_ID"));//部门
        user.put("IP", "");                                //IP
        user.put("RIGHTS", "788664966448");
        user.put("STATUS", "0");                            //状态
        user.put("ISMAIN", "1");                            //是否为主账号
        user.put("ISDELETE", "0");                            //是否为主账号
        user.put("SKIN", "pcoded-navbar navbar-image-3,navbar pcoded-header navbar-expand-lg navbar-light header-dark,");        //用户默认皮肤
        user.put("PASSWORD", new SimpleHash("SHA-1", pd.getString("CORP_NAME"), "Aa@123456").toString());            //密码加密
        if (null == usersService.findByUsername(user)) {    //判断用户名是否存在
            usersService.saveUser(user);                    //执行保存
            //	System.out.println(user.getString("PASSWORD"));
        } else {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            //throw new RuntimeException("用户已被注册!");//抛出异常 方便回滚
        }
    }

    /**
     * 保存体系文件信息
     *
     * @param pd
     */
    private void saveMfolder(PageData pd) throws Exception {
        for (String folderName : Const.CORP_FOLDERS) {
            PageData folder = new PageData();
            folder.put("MFOLDER_ID", this.get32UUID());            //主键
            folder.put("FILEPATH", "");                            //路径
            folder.put("NAME", folderName);    //文件夹名称
            folder.put("CTIME", DateUtil.date2Str(new Date()));    //创建时间
            folder.put("UNAME", Jurisdiction.getName());        //上传者
            folder.put("MASTER", Jurisdiction.getUsername());    //所属人
            folder.put("CORPINFO_ID", pd.get("CORPINFO_ID"));    //企业
            folder.put("PARENT_ID", "0");    //目录
            folder.put("FILESIZE", "");
            folder.put("SHARE", "no");
            mfolderService.save(folder);
        }
    }

    /**
     * 保存企业流程记录
     *
     * @param pd
     */
    private void saveMaintenanceFlow(PageData pd) throws Exception {
        PageData flow = new PageData();
        flow.put("ID", this.get32UUID());
        flow.put("CORPINFO_ID", pd.getString("CORPINFO_ID"));
        flow.put("ISDELETE", "0");
        flow.put("CREATOR", Jurisdiction.getUsername());    //添加人
        flow.put("CREATTIME", DateUtil.date2Str(new Date()));    //添加时间
        if (pd.getString("STATUS") != null) {
            flow.put("STATUS", pd.getString("STATUS"));
        } else {
            flow.put("STATUS", "1");        // 状态为1: 正式
        }
        if (pd.getString("NOTES") == null || Tools.isEmpty(pd.getString("NOTES"))) {
            flow.put("NOTES", "无");
        } else {
            flow.put("NOTES", pd.getString("NOTES"));
        }
        flow.put("STEP", pd.getString("FLOW_STEP"));        // 获取步骤状态码
        flow.put("ACTION", pd.getString("FLOW_ACTION"));        // 操作详情
        maintenanceFlowService.save(flow);
    }


    /**
     * 列表
     *
     * @param page
     * @throws Exception
     */
    @RequestMapping(value = "/videolistPage")
    @RequiresPermissions("corpinfo:list")
    @ResponseBody
    public Object videolistPage(Page page) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
//		map.put("CITY_CODE", Jurisdiction.getUserCityCode());
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        String KEYWORDS = pd.getString("KEYWORDS");                        //关键词检索条件
        if (Tools.notEmpty(KEYWORDS)) pd.put("KEYWORDS", KEYWORDS.trim());
        page.setPd(pd);
        List<PageData> varList = corpinfo4Service.videolistPage(page);    //列出CorpInfo列表
        map.put("varList", varList);
        map.put("page", page);
        map.put("result", errInfo);

        return map;
    }

    /**
     * 实施人员管理列表
     *
     * @param page
     * @throws Exception
     */
    @RequestMapping(value = "/getImplManagementList")
    @RequiresPermissions("corpinfo:list")
    @ResponseBody
    public Object getImplManagementList(Page page) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        if (!Jurisdiction.getUsername().equals("admin") && !Jurisdiction.getUsername().equals("adminsuper")) {
            //pd.put("CREATOR", Jurisdiction.getUsername());
//			pd.put("CREATUSERID", Jurisdiction.getUSER_ID());
            if (Jurisdiction.getAGENCY_MANAGEMENT_ID() != null && !Jurisdiction.getAGENCY_MANAGEMENT_ID().trim().equals("")) {
                if (Jurisdiction.getRnumbers().indexOf("R20230626511126") > -1 || Jurisdiction.getRnumbers().indexOf("R20230626578562") > -1 || Jurisdiction.getRnumbers().indexOf("R20230626219293") > -1 || Jurisdiction.getRnumbers().indexOf("R20230626510739") > -1) { // 市场人员
                    // 代理分账号
                    pd.put("PROXY_SUB_ACCOUNT", Jurisdiction.getUSER_ID());
                }
                if (Jurisdiction.getRnumbers().indexOf("R20230626739034") > -1) {
                    // 代理主账号
                    pd.put("PROXY_ACCOUNT", Jurisdiction.getAGENCY_MANAGEMENT_ID());
                }
            } else {
                if (Jurisdiction.getRnumbers().indexOf("R20230626511126") > -1 || Jurisdiction.getRnumbers().indexOf("R20230626578562") > -1 || Jurisdiction.getRnumbers().indexOf("R20230626219293") > -1 || Jurisdiction.getRnumbers().indexOf("R20230626510739") > -1) { // 市场人员
                    // 平台分账号
                    pd.put("PLATFORM_SUB_ACCOUNT", Jurisdiction.getUSER_ID());
                }
            }
        }
        page.setPd(pd);
        // 查询列表
        List<PageData> varList = corpinfoService.listPageForImplManagementList(page);
        map.put("varList", varList);
        map.put("page", page);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 实施人员管理查询条件
     *
     * @throws Exception
     */
    @RequestMapping(value = "/getConditionList")
    @ResponseBody
    public Object getConditionList() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        // 代理机构列表
        List<PageData> varList = corpinfoService.getAgencyListForImplManagement(pd);
        // 项目负责人列表
        List<PageData> projectLeaderList = corpinfoService.getProjectLeaderListForImplManagement(pd);
        // 运维人员列表
        List<PageData> maintenancePersonList = corpinfoService.getMaintenancePersonListForImplManagement(pd);
        map.put("agencyList", varList);
        map.put("projectLeaderList", projectLeaderList);
        map.put("maintenancePersonList", maintenancePersonList);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 实施人员管理查询条件
     *
     * @throws Exception
     */
    @RequestMapping(value = "/getCorpInfoByCorpInfoId")
    @ResponseBody
    public Object getCorpInfoByCorpInfoId() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        // 企业信息
        PageData obj = corpinfoService.getCorpInfoByCorpInfoId(pd);
        map.put("pd", obj);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 实施人员管理-延期申请确认
     *
     * @throws Exception
     */
    @RequestMapping(value = "/submitApplyExtension")
    @ResponseBody
    @Transactional
    public Object submitApplyExtension() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        pd.put("FLOW_STEP", "2");
        pd.put("FLOW_ACTION", Jurisdiction.getUsername() + "申请实施延期，下次开始实施时间:" + pd.getString("APPROVAL_TIME"));
        saveMaintenanceFlow(pd);
        maintenanceFlowService.editApplyExtension(pd);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 实施人员管理-部署完成
     *
     * @throws Exception
     */
    @RequestMapping(value = "/deploymentComplete")
    @ResponseBody
    public Object deploymentComplete() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        pd.put("FLOW_STEP", "3");        // 确认部署完成
        pd.put("FLOW_ACTION", Jurisdiction.getUsername() + "确认部署完成");
        saveMaintenanceFlow(pd);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }


    /**
     * 运维管理-维护提交
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/maintenanceSubmit")
    @ResponseBody
    @Transactional
    public Object maintenanceSubmit() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        PageData maintenanceInfo = new PageData(); // 企业停用信息
        maintenanceInfo.put("ID", this.get32UUID());    //主键
        maintenanceInfo.put("CORPINFO_ID", pd.getString("CORPINFO_ID"));
        maintenanceInfo.put("OPERATOR", Jurisdiction.getUsername());    //操作人
        maintenanceInfo.put("OPERATTIME", DateUtil.date2Str(new Date()));    //操作时间
        maintenanceInfo.put("CREATOR", Jurisdiction.getUsername());    //创建人
        maintenanceInfo.put("CREATTIME", DateUtil.date2Str(new Date()));    //创建时间
        maintenanceInfo.put("NOTES", "");
        maintenanceInfo.put("ISDELETE", "0");
        maintenanceInfo.put("MAINTENANCE_REASON", pd.getString("MAINTENANCE_REASON")); // 维护原因
        String MAINTENANCE_TIME_START = pd.getString("MAINTENANCE_TIME[0]");
        String MAINTENANCE_TIME_END = pd.getString("MAINTENANCE_TIME[1]");
        Date date = DateUtil.exStr2Date(MAINTENANCE_TIME_START);
        Date date1 = DateUtil.exStr2Date(MAINTENANCE_TIME_END);
        maintenanceInfo.put("MAINTENANCE_TIME_START", DateUtil.date2Str(date));    // 维护开始时间
        maintenanceInfo.put("MAINTENANCE_TIME_END", DateUtil.date2Str(date1));    // 维护结束时间
        maintenanceInfo.put("MAINTENANCE_STATUS", "1"); // 状态改为维护中

        maintenanceInfo.put("IS_DEACTIVATE", pd.getString("IS_DEACTIVATE"));        // 是否停用
//		if ("1".equals(pd.getString("IS_DEACTIVATE"))){		// 停用
//			pd.put("OPERATOR", Jurisdiction.getUsername());	//操作人
//			pd.put("OPERATTIME", DateUtil.date2Str(new Date()));	//操作时间
//			pd.put("ISDELETE", '0');
//			pd.put("ISSTOP", '0');
//			pd.put("ID",this.get32UUID());
//			corpinfoService.editStatus(pd);
//			corpinfoService.deleteStop(pd);
//			pd.put("STOPREASON",pd.getString("MAINTENANCE_REASON"));
//			corpinfoService.goStop(pd);
//		}
        maintenanceManagementService.save(maintenanceInfo);
        PageData action = new PageData();
        action.put("CORPINFO_ID", pd.getString("CORPINFO_ID"));
        action.put("FLOW_STEP", pd.getString("OLD_STEP"));
        action.put("FLOW_ACTION", Jurisdiction.getUsername() + "将企业转为维护状态");
        saveMaintenanceFlow(action);        // 记录流程日志

        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 运维管理-停用提交
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/submitStopForm")
    @ResponseBody
    @Transactional
    public Object submitStopForm() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        String msg = "";
        PageData pd = new PageData();
        pd = this.getPageData();

        pd.put("STOP_TIME_START", pd.getString("STOP_TIME[0]"));
        pd.put("STOP_TIME_END", pd.getString("STOP_TIME[1]"));
        List<PageData> recordList = corpinfoService.getEffectDeactivateListByCorpId(pd);
        if (recordList != null && recordList.size() > 0) {
            errInfo = "dateError";
            msg = "当前企业在此日期区间存在停用，请重新选择";
            map.put("msg", msg);
            map.put("pd", pd);
            map.put("result", errInfo);
            return map;
        }
        PageData stopSchedule = new PageData();
        stopSchedule.put("ID", this.get32UUID());
        stopSchedule.put("CORPINFO_ID", pd.getString("CORPINFO_ID"));
        stopSchedule.put("OPERATOR", Jurisdiction.getUsername());    //操作人
        stopSchedule.put("OPERATTIME", DateUtil.date2Str(new Date()));    //操作时间
        stopSchedule.put("CREATOR", Jurisdiction.getUsername());    //创建人
        stopSchedule.put("CREATTIME", DateUtil.date2Str(new Date()));    //创建时间
        stopSchedule.put("ISDELETE", "0");
        stopSchedule.put("STOP_REASON", pd.getString("STOP_REASON"));
        stopSchedule.put("STOP_TIME_START", pd.getString("STOP_TIME[0]"));
        stopSchedule.put("STOP_TIME_END", pd.getString("STOP_TIME[1]"));
        corpTimeService.saveStopSchedule(stopSchedule);
//		corpinfoService.editStatus(pd);
//		corpinfoService.deleteStop(pd);
//		corpinfoService.goStop(pd);		// 企业停用

//		String MAINTENANCE_TIME_START = pd.getString("STOP_TIME[0]");
//		String MAINTENANCE_TIME_END = pd.getString("STOP_TIME[1]");
//		Date date = DateUtil.exStr2Date(MAINTENANCE_TIME_START);
//		Date date1 = DateUtil.exStr2Date(MAINTENANCE_TIME_END);
//		pd.put("MAINTENANCE_TIME_START",DateUtil.date2Str(date));	// 维护开始时间
//		pd.put("MAINTENANCE_TIME_END",DateUtil.date2Str(date1));	// 维护结束时间
//
//		maintenanceManagementService.update(pd);

        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 运维管理-维护完成
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/submitEnable")
    @ResponseBody
    @Transactional
    public Object submitEnable() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        // 启用企业
//		PageData cpd =corpinfoService.findBytrialId(pd);
//		System.out.println(cpd.get("TRIALDAY"));
//		if(cpd.get("TRIALDAY") == null){
//			corpinfoService.editStartStatus(pd);
//		}else{
//			corpinfoService.editTrialStatus(pd);
//		}
//		corpinfoService.deleteStart(pd);
//		pd.put("OPERATOR", Jurisdiction.getUsername());	//操作人
//		pd.put("OPERATTIME", DateUtil.date2Str(new Date()));	//操作时间
//		pd.put("ISDELETE", '0');
//		pd.put("ISSTOP", '1');
//		pd.put("ID",this.get32UUID());
//		pd.put("STOPREASON","维护管理启用");
//		corpinfoService.goStart(pd);

        //修改维护状态
        maintenanceManagementService.updateEnable(pd);

        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 获取当前企业维护记录
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getMaintenanceLogList")
    @ResponseBody
    public Object getMaintenanceLogList() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        List<PageData> dataList = maintenanceManagementService.getMaintenanceLogList(pd);
        map.put("dataList", dataList);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 更改四类人员
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/changePersonnel")
    @ResponseBody
    public Object changePersonnel() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        maintenanceuserinfoService.changePersonnel(pd);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 市场管理-会员调整(机构)
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/agencyVipEnable")
    @ResponseBody
    @Transactional
    public Object agencyVipEnable(@RequestParam(value = "file", required = false) MultipartFile file) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        corpinfoService.editVipGearLevel(pd); // 更改企业信息
        // 添加会员档位调整记录
        PageData changeLog = new PageData();
        changeLog.put("AGENCY_CLIENT_CHANGE_ID", this.get32UUID()); // 主键
        changeLog.put("OPERATOR", Jurisdiction.getUsername());    //操作人
        changeLog.put("OPERATE_TIME", DateUtil.date2Str(new Date()));    //操作时间
        changeLog.put("CREATOR", Jurisdiction.getUsername());    //创建人
        changeLog.put("CREATE_TIME", DateUtil.date2Str(new Date()));    //创建时间
        changeLog.put("ISDELETE", "0");
        changeLog.put("AGENCY_MANAGEMENT_ID", pd.getString("AGENCY_MANAGEMENT_ID"));
        changeLog.put("OLD_ROLE_LEVEL", pd.getString("VIP_OLD_ID"));
        changeLog.put("NEW_ROLE_LEVEL", pd.getString("VIP_CHANGE_ID"));
        changeLog.put("OLD_GEAR_LEVEL", pd.getString("GEAR_OLD_ID"));
        changeLog.put("NEW_GEAR_LEVEL", pd.getString("GEAR_CHANGE_ID"));
        changeLog.put("CHANGE_NUMBER", 1);
        if (null != file && !file.isEmpty()) {
            String ffile = DateUtil.getDays();
            String fileName = this.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
            smb.sshSftp(file, fileName, Const.FILEPATHFILE + ffile);
            changeLog.put("ATTACHMENT_PATH", Const.FILEPATHFILE + ffile + "/" + fileName);
        }
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 实施管理-部署完成照片提交
     *
     * @param file
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/submitDeploymentComplete")
    @ResponseBody
    @Transactional
    public Object submitDeploymentComplete(@RequestParam(value = "files", required = false) MultipartFile[] files) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        System.out.println(pd.get("CORPINFO_ID"));
        pd.put("FLOW_STEP", "4");
        pd.put("FLOW_ACTION", Jurisdiction.getUsername() + "部署完成并提交验收照片");
        saveMaintenanceFlow(pd);
//		maintenanceFlowService.updateAccReport(pd);
        if (files != null && files.length > 0) {
            for (int i = 0; i < files.length; i++) {
                MultipartFile file = files[i];
//                 保存文件

                String ffile = DateUtil.getDays();
                String filePath = PathUtil.getProjectpath() + Const.FILEPATHFILE + ffile;    //文件上传路径
                String fileName = "";                //执0行上传

                if (null != file && !file.isEmpty()) {
                    fileName = this.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
                    byte[] bytes = file.getBytes();
                    smb.sshSftp(file, fileName, Const.FILEPATHYHTP + ffile);
                }
                pd.put("IMGFILES_ID", this.get32UUID());
                pd.put("FILEPATH", Const.FILEPATHYHTP + ffile + "/" + fileName);
                pd.put("TYPE", 27);
                pd.put("FOREIGN_KEY", pd.get("CORPINFO_ID"));
                imgfilesService.save(pd);
            }
        }
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 项目负责人管理-验收审批提交
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/acceptanceApproval")
    @ResponseBody
    public Object acceptanceApproval() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        PageData flow = new PageData();
        flow.put("FLOW_STEP", "4");
        flow.put("CORPINFO_ID", pd.getString("CORPINFO_ID"));
        if (pd.getString("NOTES") != null) {
            flow.put("NOTES", pd.getString("NOTES"));
        }
        if (pd.getString("ISPASSED").equals("1")) {
            flow.put("FLOW_ACTION", Jurisdiction.getUsername() + "通过验收审批");
            flow.put("STATUS", "0");
        } else {
            flow.put("FLOW_ACTION", Jurisdiction.getUsername() + "未通过验收审批");
            flow.put("STATUS", "2");
        }
        saveMaintenanceFlow(flow);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 运维管理-获取企业停用记录
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getDeacivateRecordList")
    @ResponseBody
    public Object getDeacivateRecordList() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        List<PageData> dataList = corpinfoService.getDeacivateRecordList(pd);
        map.put("dataList", dataList);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 运维管理-移除企业停用记录
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/removeStopRecord")
    @ResponseBody
    public Object removeStopRecord() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();

        corpinfoService.removeStopRecord(pd);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }


}
