package com.sipai.controller.bot; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Random; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.apache.batik.ext.awt.geom.Cubic; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; import com.sipai.entity.base.CommonFile; import com.sipai.entity.bot.Bot; import com.sipai.entity.user.Company; import com.sipai.entity.user.Unit; import com.sipai.entity.user.User; import com.sipai.service.base.CommonFileService; import com.sipai.service.bot.Botservice; import com.sipai.service.company.CompanyService; import com.sipai.service.user.UnitService; import com.sipai.service.user.UserService; import com.sipai.tools.CommString; import com.sipai.tools.CommUtil; @Controller @RequestMapping("/bot/bot") public class BotController { @Resource private Botservice botservice; @Resource private UnitService unitService; @Resource private CommonFileService commonFileService; @Resource private CompanyService companyService; @RequestMapping("/botmanage.do") public String botmanage(HttpServletRequest request, Model model) { return "bot/botManage"; } @RequestMapping("/showBotEdit.do") public String showBotEdit(HttpServletRequest request, Model model, @RequestParam String bizid) { Bot bot = new Bot(); List botList = this.botservice.selectListByWhere("where bizid='" + bizid + "'"); if (botList != null && botList.size() > 0) { bot.setId(botList.get(0).getId()); bot.setBizid(bizid); bot.setDesignScale(botList.get(0).getDesignScale()); bot.setEmission(botList.get(0).getEmission()); bot.setInfluentIndex(botList.get(0).getInfluentIndex()); bot.setEffluentIndex(botList.get(0).getEffluentIndex()); bot.setProcess(botList.get(0).getProcess()); bot.setPrice(botList.get(0).getPrice()); bot.setCalculation(botList.get(0).getCalculation()); bot.setSigndate(botList.get(0).getSigndate()); bot.setFranchisePeriod(botList.get(0).getFranchisePeriod()); } else { bot.setId(CommUtil.getUUID()); bot.setBizid(bizid); } model.addAttribute("bot", bot); return "bot/botEdit"; } @RequestMapping("/updateBot.do") public ModelAndView updateBot(HttpServletRequest request, Model model, @ModelAttribute Bot bot) { User cu = (User) request.getSession().getAttribute("cu"); //判断是否有该记录 List botList = this.botservice.selectListByWhere("where id='" + bot.getId() + "'"); int result = 0; if (botList != null && botList.size() > 0) { //更新 bot.setUpsuser(cu.getId()); bot.setUpsdt(CommUtil.nowDate()); result = this.botservice.update(bot); } else { //新增 bot.setInsuser(cu.getId()); bot.setInsdt(CommUtil.nowDate()); result = this.botservice.save(bot); } String resstr = "{\"res\":\"" + result + "\",\"id\":\"" + bot.getId() + "\"}"; model.addAttribute("result", resstr); return new ModelAndView("result"); } @RequestMapping("/botList.do") public String botList(HttpServletRequest request, Model model) { return "bot/showBotList"; } @RequestMapping("/botListForApp.do") public String botListForApp(HttpServletRequest request, Model model) { return "bot/showBotListForApp"; } @RequestMapping("/getbotList.do") public String getbotList(HttpServletRequest request, Model model) { String bizidx = request.getParameter("bizid"); String wherestr = "where 1=1 "; if (bizidx != null && !bizidx.isEmpty()) { //获取公司下所有子节点 List units = unitService.getUnitChildrenById(bizidx); String userids = ""; for (Unit unit : units) { userids += "'" + unit.getId() + "',"; } if (userids != "") { userids = userids.substring(0, userids.length() - 1); wherestr += "and bizid in (" + userids + ") "; } } if (request.getParameter("search_name") != null && !request.getParameter("search_name").isEmpty()) { wherestr += " and process like '%" + request.getParameter("search_name") + "%'"; } List botList = this.botservice.selectListByWhere(wherestr); List botJsonList = new ArrayList(); List initialPointJsonListnew1 = new ArrayList(); if (botList != null && botList.size() > 0) { for (int i = 0; i < botList.size(); i++) { JSONObject botJsonObject = JSONObject.fromObject(botList.get(i)); Company company = unitService.getCompById(botList.get(i).getBizid()); //查文件 List botfiles = this.commonFileService.selectListByTableAWhere("tb_bot_file", "where masterid='" + botList.get(i).getId() + "'"); if (botfiles != null && botfiles.size() > 0) { botJsonObject.put("filetype", "yes"); botJsonObject.put("fileid", botfiles.get(0).getId()); } else { botJsonObject.put("filetype", "no"); botJsonObject.put("fileid", ""); } if (company != null) { botJsonObject.put("bizidpid", company.getPid()); botJsonObject.put("bizname", company.getName()); } botJsonList.add(botJsonObject); } //按类分 HashSet hashSet = new HashSet<>(); for (JSONObject item : botJsonList) { hashSet.add((String) item.get("bizidpid")); } Iterator iterator = hashSet.iterator(); while (iterator.hasNext()) { JSONObject jsonObject2 = new JSONObject(); jsonObject2.put("bizidpid", iterator.next()); jsonObject2.put("color", getRandColorCode()); initialPointJsonListnew1.add(jsonObject2); } for (JSONObject jsonObject2 : initialPointJsonListnew1) { List codeslist = new ArrayList(); for (JSONObject item : botJsonList) { if (jsonObject2.get("bizidpid").equals(item.get("bizidpid"))) { codeslist.add(item); } } jsonObject2.put("codes", codeslist); } // System.out.println("---:"+initialPointJsonListnew1); request.setAttribute("botlist", initialPointJsonListnew1); } request.setAttribute("result", initialPointJsonListnew1); return "result"; } @RequestMapping("/doBotEdit.do") public String doBotEdit(HttpServletRequest request, Model model, @RequestParam(value = "id") String id) { Bot bot = this.botservice.selectById(id); Company company = unitService.getCompById(bot.getBizid()); request.setAttribute("bizname", company.getName()); model.addAttribute("bot", bot); return "bot/doBotEdit"; } @RequestMapping("/doBotUpdate.do") public String doBotUpdate(HttpServletRequest request, Model model, @ModelAttribute("bot") Bot bot) { User cu = (User) request.getSession().getAttribute("cu"); bot.setUpsuser(cu.getId()); bot.setUpsdt(CommUtil.nowDate()); int res = this.botservice.update(bot); model.addAttribute("result", res); return "result"; } @RequestMapping("/getBotdata.do") public String getBotdata(HttpServletRequest request, Model model, @RequestParam String unitId) { JSONObject botObject = new JSONObject(); if (unitId != null && !unitId.equals("")) { Company company = this.companyService.selectByPrimaryKey(unitId); if (company != null) { botObject.put("bizname", company.getName()); } } List botList = this.botservice.selectListByWhere("where bizid='" + unitId + "'"); if (botList != null && botList.size() > 0) { botObject.put("designScale", botList.get(0).getDesignScale()); botObject.put("emission", botList.get(0).getEmission()); botObject.put("influentIndex", botList.get(0).getInfluentIndex()); botObject.put("effluentIndex", botList.get(0).getEffluentIndex()); botObject.put("proess", botList.get(0).getProcess()); botObject.put("price", botList.get(0).getPrice()); botObject.put("calculation", botList.get(0).getCalculation()); botObject.put("signdate", botList.get(0).getSigndate()); botObject.put("franchisePeriod", botList.get(0).getFranchisePeriod()); } request.setAttribute("result", botObject); return "result"; } /** *   *      * 获取十bai六进制的颜du色zhi代码dao.例如  "#6E36B4" , For HTML ,  *      * @return String  *       */ public static String getRandColorCode() { String r, g, b; Random random = new Random(); r = Integer.toHexString(random.nextInt(256)).toUpperCase(); g = Integer.toHexString(random.nextInt(256)).toUpperCase(); b = Integer.toHexString(random.nextInt(256)).toUpperCase(); r = r.length() == 1 ? "0" + r : r; g = g.length() == 1 ? "0" + g : g; b = b.length() == 1 ? "0" + b : b; return r + g + b; } @RequestMapping("/getBotdataForApp.do") public String getBotdataForApp(HttpServletRequest request, Model model, @RequestParam String unitId) { List botList = this.botservice.selectListByWhere("where bizid='" + unitId + "'"); JSONObject jsonObject = new JSONObject(); JSONArray jsonArray = new JSONArray(); if (botList != null && botList.size() > 0) { jsonObject.put("code", 1); jsonObject.put("msg", ""); for (Bot bot : botList) { JSONObject jsonObjectD = new JSONObject(); jsonObjectD.put("id", bot.getId()); jsonObjectD.put("LGTD", bot.getLgtd()); if (bot.getType() != null && !bot.getType().equals("")) { jsonObjectD.put("type", bot.getType()); } else { jsonObjectD.put("type", ""); } Company company = companyService.selectByPrimaryKey(bot.getBizid()); if (company != null) { jsonObjectD.put("SHORT_NAME", company.getName()); jsonObjectD.put("ADDRESS", company.getAddress()); jsonObjectD.put("sname", company.getSname()); } else { jsonObjectD.put("SHORT_NAME", ""); jsonObjectD.put("ADDRESS", bot.getAddress()); jsonObjectD.put("sname", ""); } jsonObjectD.put("emission", bot.getEmission()); jsonObjectD.put("LINE_MAP_URL", bot.getLineMapUrl()); jsonObjectD.put("lgtd", bot.getLgtd()); jsonObjectD.put("CAPFACT", ""); jsonObjectD.put("defaultLoad", bot.getDefaultLoad()); if (bot.getClickState() != null && !bot.getClickState().equals("")) { jsonObjectD.put("CLICK_STATE", bot.getClickState()); } else { jsonObjectD.put("CLICK_STATE", "false"); } jsonObjectD.put("OUTQ", ""); jsonObjectD.put("lttd", bot.getLttd()); jsonObjectD.put("INQ", ""); jsonObjectD.put("LTTD", bot.getLttd()); if (bot.getProcess() != null && !bot.getProcess().equals("")) { jsonObjectD.put("process", bot.getProcess()); } else { jsonObjectD.put("process", ""); } jsonObjectD.put("POINT_MAP_URL", bot.getPointMapUrl()); jsonObjectD.put("bizid", bot.getBizid()); jsonObjectD.put("TM", ""); jsonArray.add(jsonObjectD); } } else { jsonObject.put("code", 0); jsonObject.put("msg", ""); } jsonObject.put("result", jsonArray); request.setAttribute("result", jsonObject); return "result"; } }