package com.zcloud.controller.bus; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import com.zcloud.service.bus.CorpInfoService; import com.zcloud.service.bus.SpecialUserService; import com.zcloud.util.Jurisdiction; import net.sf.json.JSONArray; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import org.apache.shiro.authz.annotation.RequiresPermissions; import com.zcloud.controller.base.BaseController; import com.zcloud.entity.Page; import com.zcloud.util.DateUtil; import com.zcloud.util.ObjectExcelView; import com.zcloud.util.Tools; import com.zcloud.entity.PageData; import com.zcloud.service.bus.RelevantUnitService; /** * 说明:相关单位 * 作者:luoxiaobao * 时间:2022-04-20 * 官网:www.zcloudchina.com */ @Controller @RequestMapping("/relevantunit") public class RelevantUnitController extends BaseController { @Autowired private RelevantUnitService relevantunitService; @Autowired private SpecialUserService specialuserService; @Autowired private CorpInfoService corpinfoService; /**新增 * @param * @throws Exception */ @RequestMapping(value="/add") @RequiresPermissions("relevantunit:add") @ResponseBody public Object add() throws Exception{ Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd.put("RELEVANTUNIT_ID", this.get32UUID()); //主键 pd.put("CREATOR", Jurisdiction.getUSER_ID()); pd.put("CREATTIME", DateUtil.date2Str(new Date())); pd.put("OPERATOR",Jurisdiction.getUSER_ID()); pd.put("OPERATTIME",DateUtil.date2Str(new Date())); pd.put("ISDELETE","0"); relevantunitService.save(pd); map.put("result", errInfo); map.put("msg", "新增成功!"); return map; } /**删除 * @param out * @throws Exception */ @RequestMapping(value="/delete") @RequiresPermissions("relevantunit:del") @ResponseBody public Object delete() throws Exception{ Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd.put("OPERATOR",Jurisdiction.getUSER_ID()); pd.put("OPERATTIME",DateUtil.date2Str(new Date())); relevantunitService.delete(pd); map.put("msg", "删除成功!"); map.put("result", errInfo); //返回结果 return map; } /**修改 * @param * @throws Exception */ @RequestMapping(value="/edit") @RequiresPermissions("relevantunit:edit") @ResponseBody public Object edit() throws Exception{ Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd.put("OPERATOR",Jurisdiction.getUSER_ID()); pd.put("OPERATTIME",DateUtil.date2Str(new Date())); relevantunitService.edit(pd); map.put("msg", "修改成功!"); map.put("result", errInfo); return map; } /**列表 * @param page * @throws Exception */ @RequestMapping(value="/list") @RequiresPermissions("relevantunit:list") @ResponseBody public Object list(Page page) throws Exception{ Map map = new HashMap(); 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 varList = relevantunitService.list(page); //列出RelevantUnit列表 map.put("varList", varList); map.put("page", page); map.put("result", errInfo); return map; } /**去修改页面获取数据 * @param * @throws Exception */ @RequestMapping(value="/goEdit") @RequiresPermissions("relevantunit:edit") @ResponseBody public Object goEdit() throws Exception{ Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd = relevantunitService.findById(pd); //根据ID读取 map.put("pd", pd); map.put("result", errInfo); return map; } /**批量删除 * @param * @throws Exception */ @RequestMapping(value="/deleteAll") @RequiresPermissions("relevantunit:del") @ResponseBody public Object deleteAll() throws Exception{ Map map = new HashMap(); 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(","); relevantunitService.deleteAll(ArrayDATA_IDS); errInfo = "success"; }else{ errInfo = "fail"; } 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 dataMap = new HashMap(); List titles = new ArrayList(); titles.add("relevant_name"); //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("spare1"); //13 titles.add("spare2"); //14 titles.add("spare3"); //15 titles.add("spare4"); //16 titles.add("spare5"); //17 dataMap.put("titles", titles); List varOList = relevantunitService.listAll(pd); List varList = new ArrayList(); for(int i=0;i map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); String type = pd.getString("type"); if("1".equals(type)){ // 1.1.相关方单位名称。2统一社会信用代码 pd.put("RELEVANT_NAME",pd.getString("typeName")); }else if("2".equals(type)){ pd.put("RELEVANT_CODE",pd.getString("typeName")); } Integer count = relevantunitService.hasState(pd); if(count != 0){ map.put("pd",pd); errInfo = "success"; } map.put("result", errInfo); //返回结果 return map; } /**列表 * @throws Exception */ @RequestMapping(value="/listAllTree") @ResponseBody @Transactional public Object listAllTree() throws Exception{ Map map = new HashMap(); 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 unitAllList = relevantunitService.listNameAll(pd); //列出RelevantUnit列表 PageData corp = new PageData(); corp.put("RELEVANTUNIT_ID",Jurisdiction.getCORPINFO_ID()); corp.put("CORPINFO_ID",Jurisdiction.getCORPINFO_ID()); PageData corpName = corpinfoService.findById(corp); corp.put("RELEVANT_NAME", corpName.getString("CORP_NAME")); unitAllList.add(corp); String endday = DateUtil.getDay(); PageData getPD = new PageData(); getPD.put("endday",endday); List userAllList = specialuserService.listAll(getPD); if(!Tools.isEmpty(pd.get("CORPINFO_ID"))){ PageData corpinfo = new PageData(); corpinfo.put("CORPINFO_ID", pd.getString("CORPINFO_ID")); corpinfo =corpinfoService.findById(corpinfo); PageData addPd = new PageData(); addPd.put("RELEVANT_NAME",corpinfo.getString("CORP_NAME")); addPd.put("RELEVANTUNIT_ID",corpinfo.getString("CORPINFO_ID")); unitAllList.add(addPd); } Map userMap = new HashMap<>(); for (PageData pageData:userAllList){ PageData chiMap = new PageData(); chiMap.put("id",pageData.getString("SPECIALUSER_ID")); chiMap.put("pid",pageData.getString("UNIT_ID")); chiMap.put("name",pageData.getString("USERNAME")); chiMap.put("number",pageData.getString("SPECIAL_NUMBER")); String key =pageData.getString("UNIT_ID"); List mapValList = new ArrayList<>(); if(userMap.containsKey(key)){ mapValList = userMap.get(key); } mapValList.add(chiMap); userMap.put(key,mapValList); } List> valList = new ArrayList<>(); for (PageData pageData :unitAllList){ Map valMap = new HashMap<>(); String key = pageData.getString("RELEVANTUNIT_ID"); valMap.put("id",key); valMap.put("pid","0"); valMap.put("name",pageData.getString("RELEVANT_NAME")); valMap.put("children",new ArrayList<>()); if (userMap.containsKey(key)){ valMap.put("children",userMap.get(key)); } valList.add(valMap); } JSONArray arr = JSONArray.fromObject(valList); String json = arr.toString(); map.put("varList", json); map.put("result", errInfo); return map; } /**列表 * @throws Exception */ @RequestMapping(value="/listAllForHotWork") @ResponseBody @Transactional public Object listAllForHotWork() throws Exception{ Map map = new HashMap(); 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 unitAllList = relevantunitService.listNameAll(pd); //列出RelevantUnit列表 PageData corp = new PageData(); corp.put("RELEVANTUNIT_ID",Jurisdiction.getCORPINFO_ID()); corp.put("id",Jurisdiction.getCORPINFO_ID()); corp.put("CORPINFO_ID",Jurisdiction.getCORPINFO_ID()); PageData corpName = corpinfoService.findById(corp); corp.put("RELEVANT_NAME", corpName.getString("CORP_NAME")); corp.put("label", corpName.getString("CORP_NAME")); corp.put("nodeLevel", "0"); unitAllList.add(corp); String endday = DateUtil.getDay(); PageData getPD = new PageData(); getPD.put("endday",endday); getPD.put("KEYWORDS",pd.getString("KEYWORDS")); getPD.put("DEPT_IDS",pd.getString("DEPT_IDS")); List userAllList = specialuserService.listAll(getPD); if(!Tools.isEmpty(pd.get("CORPINFO_ID"))){ PageData corpinfo = new PageData(); corpinfo.put("CORPINFO_ID", pd.getString("CORPINFO_ID")); corpinfo =corpinfoService.findById(corpinfo); PageData addPd = new PageData(); if (!corpinfo.getString("CORP_NAME").equals("唐山曹妃甸煤炭港务有限公司")) { addPd.put("RELEVANT_NAME",corpinfo.getString("CORP_NAME")); addPd.put("label",corpinfo.getString("CORP_NAME")); addPd.put("nodeLevel","0"); addPd.put("RELEVANTUNIT_ID",corpinfo.getString("CORPINFO_ID")); addPd.put("id",corpinfo.getString("CORPINFO_ID")); unitAllList.add(addPd); } } map.put("varList", userAllList); map.put("deptList", unitAllList); map.put("result", errInfo); return map; } }