package cn.ksource.web.facade.timetask; import java.io.ByteArrayInputStream; import java.io.File; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TimeZone; import javax.annotation.Resource; import net.sf.json.JSONObject; import org.apache.commons.lang.StringUtils; import org.dom4j.Attribute; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.io.SAXReader; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.lhw.util.CRequest; import com.lhw.util.CResponse; import com.lhw.util.MyHttpPost; import cn.ksource.beans.GG_MESSAGE; import cn.ksource.beans.SC_PARTNER_CUSTOMER_INFO; import cn.ksource.beans.SC_PARTNER_CUSTOMER_SUB; import cn.ksource.beans.SC_WORKFLOW_CI_HEALTH; import cn.ksource.config.SysConfigConstants; import cn.ksource.core.dao.BaseDao; import cn.ksource.core.dao.SqlParameter; import cn.ksource.core.fulltext.FullTextConstants; import cn.ksource.core.util.ConvertUtil; import cn.ksource.core.util.DateUtil; import cn.ksource.core.util.EmailUtil; import cn.ksource.core.util.HttpCharset; import cn.ksource.core.util.HttpUtil; import cn.ksource.core.util.JsonUtil; import cn.ksource.core.util.NumberUtil; import cn.ksource.core.util.SMSUtil; import cn.ksource.core.util.StringUtil; import cn.ksource.web.Constants; import cn.ksource.web.controller.wechat.util.WechatConstants; import cn.ksource.web.facade.health.HealthFacade; import cn.ksource.web.facade.satis.SatisfactionFacade; import cn.ksource.web.service.DataDictionaryService; import cn.ksource.web.service.WorkOrderCodeService; import cn.ksource.web.service.timetask.TimeTaskService; import cn.ksource.web.service.wechat.WechatService; @Service("timeTaskFacade") public class TimeTaskFacadeImpl implements TimeTaskFacade{ @Autowired private BaseDao baseDao; @Autowired private WorkOrderCodeService workOrderCodeService; @Autowired private DataDictionaryService dataDictionaryService; @Autowired private SatisfactionFacade satisfactionFacade; @Autowired private HealthFacade healthFacade; @Resource(name="timeTaskService") private TimeTaskService timeTaskService; @Autowired private WechatService wechatService; @Override public boolean updateIncidentTime() { //查询事件的sla通知信息 long time = DateUtil.getCurrentDate14(); List paramList2 = new ArrayList(); String updateSql = "UPDATE SC_INCIDENT_SLA_NOTICE SET STATUS = 2 WHERE ID = :id "; List users = new ArrayList(); //查询在当前时间之前的所有时间,如果在当前时间之前有需要通知的响应超时事件工单,则将该工单,更新为响应超时 String selectSql1 = "SELECT A.*,B.NAME,B.ORDER_CODE,B.ID AS ORDER_ID FROM SC_INCIDENT_SLA_NOTICE A,SC_WORKFLOW_INCIDENT B WHERE A.INCIDENT_ID = B.ID AND A.NOTICE_TIME <= :time AND A.TYPE = 1 AND A.STATUS = 1 "; List orders = baseDao.queryForList(selectSql1,new SqlParameter("time",time)); if(null!=orders && orders.size()>0) { List paramList = new ArrayList(); for(Map order : orders) { String incidentId = ConvertUtil.obj2StrBlank(order.get("INCIDENT_ID")); SqlParameter sqlParameter = new SqlParameter(); sqlParameter.addValue("id", incidentId); paramList.add(sqlParameter); SqlParameter sqlParameter2 = new SqlParameter(); sqlParameter2.addValue("id", ConvertUtil.obj2StrBlank(order.get("ID"))); paramList2.add(sqlParameter2); } String updateIncidnetSql = "UPDATE SC_WORKFLOW_INCIDENT SET ANSWER_TIMEOUT = 1 WHERE ID = :id "; baseDao.executeBatch(updateIncidnetSql,paramList); users.addAll(orders); } //查询在当前时间之前的所有时间,如果在当前时间之前有需要通知的所有处理超时的工单,则将该工单更新为处理超时 String selectSql2 = "SELECT A.*,B.NAME,B.ORDER_CODE,B.ID AS ORDER_ID FROM SC_INCIDENT_SLA_NOTICE A,SC_WORKFLOW_INCIDENT B WHERE A.INCIDENT_ID = B.ID AND A.NOTICE_TIME <= :time AND A.TYPE = 2 AND A.STATUS = 1 "; List dealOrders = baseDao.queryForList(selectSql2,new SqlParameter("time",time)); if(null!=dealOrders && dealOrders.size()>0) { List paramList = new ArrayList(); for(Map order : dealOrders) { String incidentId = ConvertUtil.obj2StrBlank(order.get("INCIDENT_ID")); SqlParameter sqlParameter = new SqlParameter(); sqlParameter.addValue("id", incidentId); paramList.add(sqlParameter); SqlParameter sqlParameter2 = new SqlParameter(); sqlParameter2.addValue("id", ConvertUtil.obj2StrBlank(order.get("ID"))); paramList2.add(sqlParameter2); } String updateIncidnetSql = "UPDATE SC_WORKFLOW_INCIDENT SET DEAL_TIMEOUT = 1 WHERE ID = :id "; baseDao.executeBatch(updateIncidnetSql,paramList); users.addAll(dealOrders); } if(paramList2.size()>0) { baseDao.executeBatch(updateSql,paramList2); } //进行消息通知 //查询所有用户表中的用户信息 if(null!=users && users.size()>0) { Map userMap = new HashMap(); String selectSql = "SELECT * FROM GG_USER WHERE ZT = 1 "; List ggUsers = baseDao.queryForList(selectSql); if(null!=ggUsers && ggUsers.size()>0) { for(Map u : ggUsers) { userMap.put(u.get("ID"), u); } //开始发送消息 for(Map msg : users) { String noticeUsers = ConvertUtil.obj2StrBlank(msg.get("NOTICE_USERS")); if(StringUtil.notEmpty(noticeUsers)) { String[] noticeUser = noticeUsers.split(","); List emails = new ArrayList(); List openIds = new ArrayList(); //手机号码字符串 String mobile = ""; List cacheUserId = new ArrayList(); for(String us : noticeUser) { if(StringUtil.notEmpty(us)) { String[] userMsg = us.split("-"); String uId = userMsg[0]; if(!cacheUserId.contains(uId) && userMap.containsKey(uId)) { cacheUserId.add(uId); Map user = (Map)userMap.get(uId); String isWechat = ConvertUtil.obj2StrBlank(user.get("ISWECHAT")); Object remindType = user.get("REMIND_TYPE"); if(isWechat.equals("2") && ((null!=remindType && remindType.toString().substring(2, 3).equals("1"))||null==remindType)) { //发送微信通知 String openId = ConvertUtil.obj2StrBlank(user.get("OPEN_ID")); if(StringUtil.notEmpty(openId)) { openIds.add(openId); } } String isEmail = ConvertUtil.obj2StrBlank(user.get("ISEMAIL")); if(isEmail.equals("2") && null!=remindType && remindType.toString().substring(1, 2).equals("1")) { //发送邮件通知 String email = ConvertUtil.obj2StrBlank(user.get("EMAIL")); if(StringUtil.notEmpty(email)) { emails.add(email); } } String isPhone = ConvertUtil.obj2StrBlank(user.get("ISPHONE")); if(isPhone.equals("2") && null!=remindType && remindType.toString().substring(0, 1).equals("1")) { //组装手机号码 String telphoneNum = ConvertUtil.obj2StrBlank(user.get("SJHM")); if(StringUtil.isNotBlank(telphoneNum)){ if(mobile.equals("")){ mobile = mobile + telphoneNum; }else{ mobile = mobile + "," + telphoneNum; } } } } } } String type = ConvertUtil.obj2StrBlank(msg.get("TYPE")); Integer outTime = ConvertUtil.obj2Integer(msg.get("OUT_TIME")); String orderName = ConvertUtil.obj2StrBlank(msg.get("NAME")); String orderCode = ConvertUtil.obj2StrBlank(msg.get("ORDER_CODE")); String orderId = ConvertUtil.obj2StrBlank(msg.get("ORDER_ID")); String title = new String(); StringBuffer buffer = new StringBuffer("您有新的"); String smsTitle = new String(); if(null == outTime) { outTime = 0; } if(type.equals("1")) { buffer.append("响应"); } else { buffer.append("处理"); } StringBuffer buffer2 = new StringBuffer(); buffer2.append("工单名称:"); buffer2.append(orderName); if(outTime>0) { smsTitle = "超时事件管理"; title = "事件工单超时提醒"; buffer.append("超时事件工单,"); buffer2.append(",超时时间:"); buffer2.append(outTime).append("分钟"); } else if (outTime == 0) { smsTitle = "超时事件管理"; title = "事件工单超时提醒"; buffer.append("超时事件工单,"); } else { smsTitle = "即将超时事件管理"; title = "事件工单响应超时前提醒"; buffer.append("即将超时的事件工单,"); buffer2.append(",距离超时时间:"); buffer2.append(-outTime).append("分钟"); } buffer.append(buffer2.toString()); buffer.append(",请及时进行处理"); String content = buffer.toString(); //发送短信 try { if(StringUtil.notEmpty(mobile)) { SMSUtil.sendSMS(SMSUtil.getOrderTipMsg(smsTitle,buffer2.toString()),mobile); } } catch (Exception e) { System.out.println("------------------------>发送短信异常"); } if(emails.size()>0) { String[] email = (String[])emails.toArray(new String[emails.size()]); try { EmailUtil.sendEmail(email, title, content, null); } catch (Exception e) { System.out.println("------------------------>发送邮件异常"); } } if(openIds.size()>0) { String[] openId = (String[])openIds.toArray(new String[openIds.size()]); try { String wxUrl = WechatConstants.ORDER_EW_INCIDENT_DETAIL_ADDRESS+"?orderId="+orderId; GG_MESSAGE message = new GG_MESSAGE(); message.setTitle(title); message.setContent(content); message.setSender_name(Constants.company_name); message.setSend_time(time); message.setOrder_code(orderCode); message.setWx_url(wxUrl); wechatService.sendSysMsg(openId, message); } catch (Exception e) { System.out.println("------------------------>发送微信信息异常"); } } } } } } //查询事件工单表中,响应超时状态为未超时的工单 /*String responseSql = "SELECT ID,NAME,ANSWER_TIMEOUT_TIME FROM SC_WORKFLOW_INCIDENT WHERE ANSWER_TIMEOUT = 2 AND ANSWER_TIME IS NULL "; List responseTimes = baseDao.queryForList(responseSql); long nowTime = DateUtil.getCurrentDate14(); if(null!=responseTimes && responseTimes.size()>0) { List respParameters = new ArrayList(); for(Map respTime : responseTimes) { long answer_timeout_time = ConvertUtil.obj2Long(respTime.get("answer_timeout_time")); if(nowTime > answer_timeout_time) { SqlParameter sqlParameter = new SqlParameter(); sqlParameter.put("id", respTime.get("ID")); respParameters.add(sqlParameter); } } if(respParameters.size()>0) { String updateRespSql = "UPDATE SC_WORKFLOW_INCIDENT SET ANSWER_TIMEOUT = 1 WHERE ID = :id "; baseDao.executeBatch(updateRespSql,respParameters); } } //查询所有事件工单表中,所有解决时间为空,并且处理未超时的工单 String resolveSql = "SELECT ID,DEAL_TIMEOUT_TIME FROM SC_WORKFLOW_INCIDENT WHERE DEAL_TIMEOUT = 2 AND RESOLVE_TIME IS NULL"; List resolveTimes = baseDao.queryForList(resolveSql); if(null!=resolveTimes && resolveTimes.size()>0) { List resolveParameters = new ArrayList(); for(Map resolveTime : resolveTimes) { long deal_timeout_time = ConvertUtil.obj2Long(resolveTime.get("DEAL_TIMEOUT_TIME")); if(nowTime > deal_timeout_time) { SqlParameter sqlParameter = new SqlParameter(); sqlParameter.put("id", resolveTime.get("ID")); resolveParameters.add(sqlParameter); } } if(resolveParameters.size()>0) { String updateResolveSql = "UPDATE SC_WORKFLOW_INCIDENT SET DEAL_TIMEOUT = 1 WHERE ID = :id "; baseDao.executeBatch(updateResolveSql,resolveParameters); } }*/ return true; } @Override public boolean saveHealthOrder() { long today = DateUtil.getCurrentDate8(); long nextWeek = DateUtil.getDateAdd(today, 7, 8); //查询一周内需要生成的工单 StringBuilder sql=new StringBuilder(); sql.append("SELECT DISTINCT A.*,C.ID AS TASKID,C.PLAN_EXE_DATE FROM CI_HEALTH_PLAN A INNER JOIN CI_HEALTH_PLAN_TIMER C ON A.ID=C.PLAN_ID LEFT JOIN CI_HEALTH_PLAN_CILIST B ON A.ID=B.PLAN_ID "); sql.append(" WHERE A.STATE=:state AND C.PLAN_EXE_DATE >=:today AND C.PLAN_EXE_DATE<:nextWeek AND C.STATE=1"); Map paramMap = new HashMap(); paramMap.put("state", Constants.CI_HEALTH_PLAN_TIMER_STATE_WJX);//未进行 paramMap.put("today", today); paramMap.put("nextWeek", nextWeek); List tasks = baseDao.queryForList(sql.toString(),paramMap); long createTime = DateUtil.getCurrentDate14(); //循环启动流程 if(null!=tasks && tasks.size()>0){ List backParam = new ArrayList(); for(Map task : tasks) { String cus_id = ConvertUtil.obj2StrBlank(task.get("CUS_ID")); //通过项目编号查询项目信息 if(StringUtil.notEmpty(cus_id)) { String remind_id = ConvertUtil.obj2StrBlank(task.get("PROJECT_ITEM_ID")); String customerId = ConvertUtil.obj2StrBlank(task.get("CUS_ID")); String planId=ConvertUtil.obj2StrBlank(task.get("ID")); //更新ci_health_plan中的 上次执行时间和下次执行时间 String nowDate=ConvertUtil.obj2Str(DateUtil.getCurrentDate8()); SqlParameter params=new SqlParameter("plan_id",planId); params.addValue("nowDate",nowDate); String next_exe_date=baseDao.queryForString("select min(plan_exe_date) from ci_health_plan_timer where plan_id=:plan_id and plan_exe_date >:nowDate",params); if(StringUtil.notEmpty(next_exe_date)) { params.addValue("next_exe_date", next_exe_date); baseDao.execute("update ci_health_plan set last_exe_date=:nowDate,next_exe_date=:next_exe_date where id=:plan_id", params); } //end ****更新ci_health_plan中的 上次执行时间和下次执行时间*** String subCustomerId = ConvertUtil.obj2StrBlank(task.get("SUB_CUS_ID")); SC_PARTNER_CUSTOMER_INFO customer = new SC_PARTNER_CUSTOMER_INFO(customerId).getInstanceById(); String customerName = customer.getCustomer_name(); //添加体检流程数据 String insertSql = "INSERT INTO SC_WORKFLOW_CI_HEALTH(ID,ORDER_CODE,NAME,CUSTOMER_ID,CUSTOMER_NAME,CREATE_TIME,STATE,SUB_CUSTOMER_ID,SUB_CUSTOMER_NAME) " + "VALUES (:id,:order_code,:name,:customer_id,:customer_name,:create_time,1,:sub_customer_id,:sub_customer_name)"; Map param = new HashMap(); String orderId = StringUtil.getUUID(); param.put("id", orderId); String orderCode = workOrderCodeService.getCiHealthOrderCode(); param.put("order_code", orderCode); param.put("customer_id", customerId); param.put("customer_name", customerName); param.put("create_time", createTime); param.put("plan_id", planId); param.put("name", "健康检查-"+task.get("PLAN_NAME").toString()); if(StringUtil.notEmpty(subCustomerId)) { param.put("sub_customer_id", subCustomerId); //如果客户编号与所属单位编号一致,说明为客户本身,修改人:杨凯 if (StringUtils.equalsIgnoreCase(customerId, subCustomerId)) { param.put("sub_customer_name", new SC_PARTNER_CUSTOMER_INFO(subCustomerId).getInstanceById().getCustomer_name()); } else { param.put("sub_customer_name", new SC_PARTNER_CUSTOMER_SUB(subCustomerId).getInstanceById().getCustomer_name()); } } else { param.put("sub_customer_id", null); param.put("sub_customer_name", null); } baseDao.execute(insertSql, param); Map pm = new HashMap(); //查询该计划对应客户指定的设备 String ciSql="SELECT A.ID ,A.CI_ID FROM CI_HEALTH_PLAN_CILIST A,CMDB_CI_BASE B WHERE A.CI_ID=B.ID AND A.STATE=1 AND A.PLAN_ID=:planId AND B.CUS_ID = :customerId"; if(StringUtil.notEmpty(subCustomerId)) { ciSql += " AND B.SUB_CUS_ID = :subCustomerId "; pm.put("subCustomerId", subCustomerId); } else { ciSql += " AND (B.SUB_CUS_ID IS NULL OR B.SUB_CUSTOMER_ID = '')"; } pm.put("planId", planId); pm.put("customerId", customerId); List devices = baseDao.queryForList(ciSql,pm); if(null!=devices && devices.size()>0) { String insertDeviceSql = "INSERT INTO SC_WORKFLOW_CI_HEALTH_CIDETAIL(ID,ORDER_ID,CI_ID,DEAL_STATE) VALUES (:id,:order_id,:ci_id,3)"; List deviceParam = new ArrayList(); for(Map device : devices) { SqlParameter sqlParameter = new SqlParameter(); String orderCiId=StringUtil.getUUID(); sqlParameter.put("id",orderCiId ); sqlParameter.put("order_id", orderId); sqlParameter.put("ci_id", device.get("CI_ID")); deviceParam.add(sqlParameter); //查询该设备下的指标 StringBuilder itemSql=new StringBuilder(); itemSql.append("SELECT C.ID FROM CI_HEALTH_CUSTOMIZE_DETAIL A,CI_HEALTH_CUSTOMER_ITEM B,CI_HEALTH_ITEM C "); itemSql.append(" WHERE A.CUSTOMER_ITEM_ID=B.ID AND B.ITEM_ID=C.ID AND B.USING_STATE=1 AND C.STATE=1 AND A.CI_ID=:ci_id"); List itemList=baseDao.queryForList(itemSql.toString(), sqlParameter); sqlParameter.put("ci_id", device.get("CI_ID")); //添加健康检查指标 if(null!=itemList && itemList.size()>0){ for(Map itemMap:itemList){ String insertItemSql="INSERT INTO SC_WORKFLOW_ITEM_HEALTH_CIDETAIL(ID,ORDER_CI_ID,ORDER_ID,CI_ID,ITEM_ID,DEAL_STATE) " + " VALUES(:id,:orderCiId,:orderId,:ciId,:itemId,3)"; SqlParameter itemParam=new SqlParameter(); itemParam.addValue("id",StringUtil.getUUID()) .addValue("orderCiId", orderCiId) .addValue("orderId", orderId) .addValue("ciId", device.get("CI_ID")) .addValue("itemId", itemMap.get("ID")); baseDao.execute(insertItemSql, itemParam); } } } baseDao.executeBatch(insertDeviceSql, deviceParam); } //查询健康体检流程设备分类 StringBuilder categorySql=new StringBuilder(); categorySql.append("SELECT A.CATEGORY_NAME,A.ID AS CATEGORYID,B.ID AS ITEMID,B.ITEM_NAME FROM HEALTH_CUSTOMER_COMMONS_CATEGORY A,HEALTH_CUSTOMER_COMMONS_ITEM B"); categorySql.append(" WHERE A.ID=B.CATEGORY_ID AND A.PLAN_ID=:planId AND A.USING_STATE=1 AND B.USING_STATE=1"); List categoryList=baseDao.queryForList(categorySql.toString(), new SqlParameter().addValue("planId", planId)); //添加健康体检流程设备分类 if(null!=categoryList && categoryList.size()>0){ for(Map categoryMap:categoryList){ StringBuilder inserCategorySql=new StringBuilder(); inserCategorySql.append("INSERT INTO CI_HEALTH_PATROL_COMMON_RECORD(ID,CATEGORY_ID,CATEGORY_NAME,ITEM_ID,ITEM_NAME,ORDER_ID)"); inserCategorySql.append(" VALUES(:id,:categoryId,:categoryName,:itemId,:itemName,:orderId)"); SqlParameter categoryParam=new SqlParameter(); categoryParam.addValue("id",StringUtil.getUUID()) .addValue("categoryId", categoryMap.get("CATEGORYID")) .addValue("categoryName", categoryMap.get("CATEGORY_NAME")) .addValue("itemId", categoryMap.get("ITEMID")) .addValue("itemName", categoryMap.get("ITEM_NAME")) .addValue("orderId", orderId); baseDao.execute(inserCategorySql.toString(), categoryParam); } } //启动流程 SC_WORKFLOW_CI_HEALTH health = new SC_WORKFLOW_CI_HEALTH(orderId).getInstanceById(); healthFacade.startHealthWorkFlow(health); SqlParameter sqlParameter = new SqlParameter(); sqlParameter.put("id", task.get("TASKID")); sqlParameter.put("state", Constants.CI_HEALTH_PLAN_TIMER_STATE_YWC); sqlParameter.put("create_time", createTime); sqlParameter.put("flow_id", orderId); backParam.add(sqlParameter); } } if(backParam.size()>0) { String updateSql = "UPDATE CI_HEALTH_PLAN_TIMER SET STATE = :state,ORDER_DATE = :create_time,FLOW_ID = :flow_id WHERE ID = :id"; baseDao.executeBatch(updateSql, backParam); } } return true; } @SuppressWarnings("rawtypes") @Override public boolean savemakeSatisData() { Map last_time = dataDictionaryService.getDataDictionaryByKey(Constants.SATIS_LAST_TIME); String date = ConvertUtil.obj2StrBlank(last_time.get("DATAVALUE")); String nowDate = DateUtil.getDay(); int dateInt = 0; if(StringUtil.isEmpty(date)){ dateInt = 2; }else{ dateInt = ConvertUtil.obj2Int(date); } int nowdateInt = ConvertUtil.obj2Int(nowDate); String month = ConvertUtil.obj2StrBlank(DateUtil.getCurrentDate6()); System.out.println("==========="+month); if(nowdateInt <= dateInt){ month = DateUtil.getMonthAdd("yyyyMM", -1); } // month="201806"; //查询是否本月已存在月度满意度数据 List yueList = baseDao.queryForList("SELECT * FROM TOTLE_SATIS_INFO WHERE MONTH = :month ", new SqlParameter("month",month)); //查询调查过的数据 String sqlxy = "SELECT A.CUSTOMER_ID,WB.BUSINESSTYPE ,AVG(SCORE) AS AVGSCORE,COUNT(A.ID) AS NUM FROM ORDER_SATIS_INFO A,WORKFLOW_BASE WB WHERE A.CARD_MONTH = :card_month AND A.BUSINESS_ID = WB.ID AND WB.BUSINESSTYPE=8 GROUP BY A.CUSTOMER_ID,WB.BUSINESSTYPE "; String sqlczxy = "SELECT A.CUSTOMER_ID,WB.BUSINESSTYPE ,AVG(SCORE) AS AVGSCORE,COUNT(A.ID) AS NUM FROM ORDER_SATIS_INFO A,WORKFLOW_BASE WB WHERE A.CARD_MONTH = :card_month AND A.BUSINESS_ID = WB.ID AND WB.BUSINESSTYPE=10 GROUP BY A.CUSTOMER_ID,WB.BUSINESSTYPE "; String sqlzc = "SELECT CUSTOMER_ID,AVG(SCORE) AS AVGSCORE,COUNT(ID) AS NUM FROM AUDITING_SATIS_INFO WHERE CARD_MONTH = :card_month GROUP BY CUSTOMER_ID "; Map paramMap = new HashMap(); paramMap.put("card_month", month); List orderList = baseDao.queryForList(sqlxy,paramMap); List orderCzList = baseDao.queryForList(sqlczxy,paramMap); List zcList = baseDao.queryForList(sqlzc,paramMap); Map cacheMap = new HashMap(); Map cuscacheMap = new HashMap(); Map cusqzcacheMap = new HashMap(); String allscore = ""; List qzList = new ArrayList(); Map qzparam = new HashMap(); //取出模板数据 StringBuffer sql = new StringBuffer("SELECT B.*,A.ALL_SCORE,A.STATE FROM KPI_SATIS_TEMPLATE A,KPI_CONFIG B WHERE A.ID = B.TEMPLATE_ID "); qzList = baseDao.queryForList(sql.toString(), qzparam); if(qzList.size() > 0){ //取出已有月度满意度数据的项目和权重模板 if(yueList.size() > 0){ for(Map map1:yueList){ for(Map map:orderList){ //存在月度满意度,取出权重模板 if(map.get("CUSTOMER_ID").equals(map1.get("CUSTOMER_ID"))){ String template_id = ConvertUtil.obj2StrBlank(map1.get("TEMPLATE_ID")); cusqzcacheMap.put(map.get("CUSTOMER_ID"), template_id+"-"+map1.get("ID")+"-"+map1.get("CREATE_TIME")); } } for(Map map:orderCzList){ //存在月度满意度,取出权重模板 if(map.get("CUSTOMER_ID").equals(map1.get("CUSTOMER_ID"))){ String template_id = ConvertUtil.obj2StrBlank(map1.get("TEMPLATE_ID")); cusqzcacheMap.put(map.get("CUSTOMER_ID"), template_id+"-"+map1.get("ID")+"-"+map1.get("CREATE_TIME")); } } for(Map map:zcList){ //存在月度满意度,取出权重模板 if(map.get("CUSTOMER_ID").equals(map1.get("CUSTOMER_ID"))){ String template_id = ConvertUtil.obj2StrBlank(map1.get("TEMPLATE_ID")); cusqzcacheMap.put(map.get("CUSTOMER_ID"), template_id+"-"+map1.get("ID")+"-"+map1.get("CREATE_TIME")); } } } } //取出所有的满意度调查的项目 getAllcustomer(orderList, zcList, cuscacheMap,orderCzList); //响应类工单总数量 List xycount = baseDao.queryForList("SELECT * FROM WORKFLOW_BASE WHERE BUSINESSTYPE = 8 AND (WFSTATE = 2 OR WFSTATE = 4) AND DATE_FORMAT(CREATETIME,'%Y%m') = :card_month ",paramMap); //驻场响应类工单总数量 List zcxycount = baseDao.queryForList("SELECT * FROM WORKFLOW_BASE WHERE BUSINESSTYPE = 10 AND (WFSTATE = 2 OR WFSTATE = 4) AND DATE_FORMAT(CREATETIME,'%Y%m') = :card_month ",paramMap); //驻场满意度需调查数量 List zccount = baseDao.queryForList("(SELECT A.CUSTOMER_ID ,B.USER_ID,B.USER_NAME FROM SC_PARTNER_CUSTOMER_SUB A ,SC_CUSTOMER_ZC_UESR B WHERE B.CUSTOMER_ID = A.ID ) UNION ALL (SELECT D.CUSTOMER_ID ,D.USER_ID,D.USER_NAME FROM SC_PARTNER_CUSTOMER_INFO C ,SC_CUSTOMER_ZC_UESR D WHERE D.CUSTOMER_ID = C.ID )"); //设置客户的响应支持类、驻场服务,得分,权重 setcusMsg(cuscacheMap, cusqzcacheMap, qzList, xycount,zccount,zcxycount); List paramList = new ArrayList(); List paramCzList = new ArrayList(); List zparamList = new ArrayList(); String protem = ""; for(Object key : cuscacheMap.keySet()){ String creattime = ConvertUtil.obj2StrBlank(DateUtil.getCurrentDate14()); SqlParameter param = new SqlParameter(); String id = StringUtil.getUUID(); Map map6 = (Map)cuscacheMap.get(key); if(!StringUtil.isEmpty(ConvertUtil.obj2StrBlank(map6.get("CUNZAI_ID")))){ protem = protem + key +","; } List orderList2 = (List)map6.get("orderList"); List orderList3 = (List)map6.get("orderCzList"); List totalList = (List)map6.get("totalList"); if((orderList2 != null && orderList2.size() > 0)||(totalList != null && totalList.size() > 0) || orderList3 != null && orderList3.size() > 0){ if(cusqzcacheMap.get(key) != null){ if(StringUtil.isEmpty(ConvertUtil.obj2StrBlank(cusqzcacheMap.get(key)).split("-")[2])){ creattime = ConvertUtil.obj2StrBlank(cusqzcacheMap.get(key)).split("-")[2]; } } double score = 0; param.put("ID", id); param.put("CUSTOMER_ID", key); param.put("MONTH", month); param.put("REQUEST_SCORE", map6.get("QUEALL_SCORE")); param.put("CREATE_TIME", creattime); param.put("UPDATE_TIME", DateUtil.getCurrentDate14()); param.put("TEMPLATE_ID", map6.get("TEMPLATE_ID")); if(orderList2 != null && orderList2.size() > 0){ for(Map map:orderList2){ if(ConvertUtil.obj2Double(map.get("AVGSCORE"))==0.0){ map.put("AVGSCORE", map.get("DEFAULT_SCORE")); } SqlParameter param1 = new SqlParameter(); String idtwo = StringUtil.getUUID(); param1.put("ID", idtwo); param1.put("BUS_ID", id); param1.put("ALL_COUNT", map.get("SATIS_COUNT")); param1.put("SATIS_COUNT", map.get("NUM")); param1.put("SATIS_QZ", map.get("SATIS_QZ")); param1.put("FG_RATE", map.get("FGL")); param1.put("REQUEST_FG_RATE",map.get("QUEFG_RATE")); param1.put("SATIS_SCORE", NumberUtil.round(ConvertUtil.obj2Double(map.get("AVGSCORE")), 2)); param1.put("REQUEST_SATIS_SCORE", map.get("QUESATIS_SCORE")); param1.put("SATIS_TYPE", 1); if(orderList3==null || orderList3.size()==0){ score = NumberUtil.add(score, NumberUtil.mul(ConvertUtil.obj2Double(map.get("AVGSCORE")), ConvertUtil.obj2Double(map.get("SATIS_QZ")))); }else{ score = NumberUtil.add(score, NumberUtil.mul(ConvertUtil.obj2Double(map.get("AVGSCORE")), NumberUtil.mul(ConvertUtil.obj2Double(map.get("SATIS_QZ")), 0.5))); } paramList.add(param1); } } if(orderList3 != null && orderList3.size() > 0){ for(Map map:orderList3){ if(ConvertUtil.obj2Double(map.get("AVGSCORE"))==0.0){ map.put("AVGSCORE", map.get("DEFAULT_SCORE")); } SqlParameter param1 = new SqlParameter(); String idtwo = StringUtil.getUUID(); param1.put("ID", idtwo); param1.put("BUS_ID", id); param1.put("ALL_COUNT", map.get("SATIS_COUNT")); param1.put("SATIS_COUNT", map.get("NUM")); param1.put("SATIS_QZ", map.get("SATIS_QZ")); param1.put("FG_RATE", map.get("FGL")); param1.put("REQUEST_FG_RATE",map.get("QUEFG_RATE")); param1.put("SATIS_SCORE", NumberUtil.round(ConvertUtil.obj2Double(map.get("AVGSCORE")), 2)); param1.put("REQUEST_SATIS_SCORE", map.get("QUESATIS_SCORE")); param1.put("SATIS_TYPE", 6); if(orderList2==null || orderList2.size()==0){ score = NumberUtil.add(score, NumberUtil.mul(ConvertUtil.obj2Double(map.get("AVGSCORE")), ConvertUtil.obj2Double(map.get("SATIS_QZ")))); }else{ score = NumberUtil.add(score, NumberUtil.mul(ConvertUtil.obj2Double(map.get("AVGSCORE")), NumberUtil.mul(ConvertUtil.obj2Double(map.get("SATIS_QZ")), 0.5))); } paramCzList.add(param1); } } if(totalList != null && totalList.size() > 0){ for(Map map:totalList){ if(ConvertUtil.obj2Double(map.get("AVGSCORE"))==0.0){ map.put("AVGSCORE", map.get("DEFAULT_SCORE")); } SqlParameter param1 = new SqlParameter(); String idtwo = StringUtil.getUUID(); param1.put("ID", idtwo); param1.put("BUS_ID", id); param1.put("ALL_COUNT", map.get("SATIS_COUNT")); param1.put("SATIS_COUNT", map.get("NUM")); param1.put("SATIS_QZ", map.get("SATIS_QZ")); param1.put("FG_RATE", map.get("FGL")); param1.put("REQUEST_FG_RATE",map.get("QUEFG_RATE")); param1.put("SATIS_SCORE", NumberUtil.round(ConvertUtil.obj2Double(map.get("AVGSCORE")), 2)); param1.put("REQUEST_SATIS_SCORE", map.get("QUESATIS_SCORE")); param1.put("SATIS_TYPE", 3); paramList.add(param1); System.out.println(score); score = NumberUtil.add(score, NumberUtil.mul(ConvertUtil.obj2Double(map.get("AVGSCORE")), ConvertUtil.obj2Double(map.get("SATIS_QZ")))); } } score = NumberUtil.div(score, 100.0, 2); param.put("ALL_SCORE", score); zparamList.add(param); } } if(!StringUtil.isEmpty(protem)){ protem = protem.substring(0, protem.length()-1); String[] ids = protem.split(","); List params = new ArrayList(); for(int i=0;i list = timeTaskService.getKnowledgeList(businessId,beginTime,endTime); String json = JsonUtil.list2Json(list); Map params = new HashMap(); params.put("data", json); System.out.println(FullTextConstants.getUpdate_data_source_path()); HttpUtil.doPost(FullTextConstants.getUpdate_data_source_path(), params, HttpCharset.UTF8); return true; } /** * 定时更新工单数据 */ @Override public boolean updateOrderDataSource(String beginTime,String endTime) { long today = DateUtil.getCurrentDate8(); long day = DateUtil.getDateAdd(today, -1, 8); if(!StringUtil.notEmptyNum(beginTime)) { beginTime = ConvertUtil.obj2StrBlank(day); } beginTime = beginTime + "000000"; if(!StringUtil.notEmptyNum(endTime)) { endTime = ConvertUtil.obj2StrBlank(day); } endTime = endTime + "240000"; List result = new ArrayList(); //查询事件信息 List incidents = timeTaskService.getIncidentList(beginTime,endTime); //查询驻场运维工单事件信息 List zcyws = timeTaskService.getZcywList(beginTime,endTime); //查询问题工单信息 List questions = timeTaskService.getQuestionList(beginTime,endTime); //查询设备采集工单信息 //List adds = timeTaskService.getAddList(beginTime,endTime); //查询例行维保工单信息 List reminds = timeTaskService.getRemind(beginTime,endTime); //查询月度巡检工单信息 List monthChecks = timeTaskService.getMonthCheck(beginTime,endTime); result.addAll(incidents); result.addAll(zcyws); result.addAll(questions); //result.addAll(adds); result.addAll(reminds); result.addAll(monthChecks); String json = JsonUtil.list2Json(result); System.out.println("order---------->"+json); Map params = new HashMap(); params.put("data", json); System.out.println(FullTextConstants.getUpdate_data_source_path()); HttpUtil.doPost(FullTextConstants.getUpdate_data_source_path(), params, HttpCharset.UTF8); return true; } /** * 取得有调查数据的所有项目 * @param orderList * @param zcList * @param cuscacheMap */ private void getAllcustomer(List orderList, List zcList, Map cuscacheMap,List orderCzList) { if(orderList.size() > 0){ for(Map map:orderList){ Map proMap = (Map)cuscacheMap.get(map.get("CUSTOMER_ID")); List orderList2 = new ArrayList(); List totalList = new ArrayList();; if(proMap == null){ Map map2 = new HashMap(); map2.put("CUSTOMER_ID", map.get("CUSTOMER_ID")); orderList2.add(map); map2.put("orderList", orderList2); cuscacheMap.put(map.get("CUSTOMER_ID"), map2); }else{ if(proMap.get("orderList") != null){ orderList2 = (List)proMap.get("orderList"); } orderList2.add(map); proMap.put("orderList", orderList2); cuscacheMap.put(map.get("CUSTOMER_ID"), proMap); } } } if(orderCzList.size() > 0){ for(Map map:orderCzList){ Map proMap = (Map)cuscacheMap.get(map.get("CUSTOMER_ID")); List orderList3 = new ArrayList(); List totalList = new ArrayList();; if(proMap == null){ Map map2 = new HashMap(); map2.put("CUSTOMER_ID", map.get("CUSTOMER_ID")); orderList3.add(map); map2.put("orderCzList", orderList3); cuscacheMap.put(map.get("CUSTOMER_ID"), map2); }else{ if(proMap.get("orderCzList") != null){ orderList3 = (List)proMap.get("orderCzList"); } orderList3.add(map); proMap.put("orderCzList", orderList3); cuscacheMap.put(map.get("CUSTOMER_ID"), proMap); } } } if(zcList.size() > 0){ for(Map map:zcList){ Map proMap = (Map)cuscacheMap.get(map.get("CUSTOMER_ID")); List totalList = new ArrayList();; if(proMap == null){ Map map2 = new HashMap(); map2.put("CUSTOMER_ID", map.get("CUSTOMER_ID")); totalList.add(map); map2.put("totalList", totalList); cuscacheMap.put(map.get("CUSTOMER_ID"), map2); }else{ if(proMap.get("totalList") != null){ totalList = (List)proMap.get("totalList"); } totalList.add(map); proMap.put("totalList", totalList); cuscacheMap.put(map.get("CUSTOMER_ID"), proMap); } } } } /** * 设置响应支持类、驻场服务,得分,权重等信息 * @param cuscacheMap * @param cusqzcacheMap * @param qzList * @param xycount * @param zccount */ private void setcusMsg(Map cuscacheMap, Map cusqzcacheMap, List qzList, List xycount, List zccount, List zcxycount) { for(Object key:cuscacheMap.keySet()){ Map pro = (Map)cuscacheMap.get(key); List orderList2 = new ArrayList(); List orderList4 = new ArrayList(); orderList2 = (List)pro.get("orderList"); orderList4 = (List)pro.get("orderCzList"); List totalList = new ArrayList(); totalList = (List)pro.get("totalList"); if(orderList2 != null && orderList2.size() >0 ){ for(Map map1:orderList2){ for(Map map:qzList){ if(StringUtil.isEmpty(ConvertUtil.obj2StrBlank(cusqzcacheMap.get(key)))){ if(ConvertUtil.obj2Integer(map.get("STATE")) == 1 ){ if(ConvertUtil.obj2Integer(map.get("SATIS_TYPE")) == 1 && ConvertUtil.obj2Integer(map1.get("BUSINESSTYPE")) == Constants.WORKFLOW_BASE_BUSINESS_TYPE_INCIDENT){ //计算响应类应调查数量 int xynum = 0; xynum = setReqSatisCount(xycount, map1,xynum); //设置客户的覆盖率,得分,权重等信息 setproDetail(pro, map1, map, xynum); } } }else{ String[] templateid = ConvertUtil.obj2StrBlank(cusqzcacheMap.get(key)).split("-"); pro.put("CUNZAI_ID", templateid[1]); if(templateid[0].equals(ConvertUtil.obj2StrBlank(map.get("TEMPLATE_ID")))){ if(ConvertUtil.obj2Integer(map.get("SATIS_TYPE")) == 1 && ConvertUtil.obj2Integer(map1.get("BUSINESSTYPE")) == Constants.WORKFLOW_BASE_BUSINESS_TYPE_INCIDENT){ //计算响应类应调查数量 int xynum = 0; xynum = setReqSatisCount(xycount, map1,xynum); //设置客户的覆盖率,得分,权重等信息 setczmbDetail(pro, map1, map, templateid,xynum); } } } } } }else{ List orderList3 = new ArrayList(); //响应类调查为空时,设置响应类的满意度数据 setXyKong(qzList, xycount,orderList3, key, pro); } if(orderList4 != null && orderList4.size() >0 ){ for(Map map1:orderList4){ for(Map map:qzList){ if(StringUtil.isEmpty(ConvertUtil.obj2StrBlank(cusqzcacheMap.get(key)))){ if(ConvertUtil.obj2Integer(map.get("STATE")) == 1 ){ if(ConvertUtil.obj2Integer(map.get("SATIS_TYPE")) == 1 && ConvertUtil.obj2Integer(map1.get("BUSINESSTYPE")) == Constants.WORKFLOW_BASE_BUSINESS_TYPE_INCIDENT_LOCAL){ //计算响应类应调查数量 int xynum = 0; xynum = setReqSatisCount(zcxycount, map1,xynum); //设置客户的覆盖率,得分,权重等信息 setproDetail(pro, map1, map, xynum); } } }else{ String[] templateid = ConvertUtil.obj2StrBlank(cusqzcacheMap.get(key)).split("-"); pro.put("CUNZAI_ID", templateid[1]); if(templateid[0].equals(ConvertUtil.obj2StrBlank(map.get("TEMPLATE_ID")))){ if(ConvertUtil.obj2Integer(map.get("SATIS_TYPE")) == 1 && ConvertUtil.obj2Integer(map1.get("BUSINESSTYPE")) == Constants.WORKFLOW_BASE_BUSINESS_TYPE_INCIDENT_LOCAL){ //计算响应类应调查数量 int xynum = 0; xynum = setReqSatisCount(zcxycount, map1,xynum); //设置客户的覆盖率,得分,权重等信息 setczmbDetail(pro, map1, map, templateid,xynum); } } } } } }else{ List orderList3 = new ArrayList(); //响应类调查为空时,设置响应类的满意度数据 setZcXyKong(qzList, xycount,orderList3, key, pro); } if(totalList != null && totalList.size() >0 ){ int zcsl = 0; for(Map map1:totalList){ for(Map map:qzList){ if(StringUtil.isEmpty(ConvertUtil.obj2StrBlank(cusqzcacheMap.get(key)))){ if(ConvertUtil.obj2Integer(map.get("STATE")) == 1 ){ if(ConvertUtil.obj2Integer(map.get("SATIS_TYPE")) == 3 ){ //计算驻场服务应调查数量 int zcnum = 0; zcnum = setReqSatisCount(zccount, map1,zcnum); //驻场类实际调查数量 zcsl = zcsl + 1; //设置项目的覆盖率,得分,权重等信息 setproDetail(pro, map1, map, zcnum); } } }else{ String[] templateid = ConvertUtil.obj2StrBlank(cusqzcacheMap.get(key)).split("-"); pro.put("CUNZAI_ID", templateid[1]); if(map.get("TEMPLATE_ID").equals(templateid[0]) ){ if(ConvertUtil.obj2Integer(map.get("SATIS_TYPE")) == 3 ){ //计算驻场服务应调查数量 int zcnum = 0; zcnum = setReqSatisCount(zccount, map1,zcnum); //驻场类实际调查数量 zcsl = zcsl + 1; //设置项目的覆盖率,得分,权重等信息 setczmbDetail(pro, map1, map, templateid,zcnum); } } } } } if(zcsl == 0){ //驻场调查为空时,设置驻场类的满意度数据 setZcKong(qzList,zccount,totalList, key, pro); } }else{ List totalList3 = new ArrayList(); //驻场调查为空时,设置驻场类的满意度数据 setZcKong(qzList,zccount,totalList3, key, pro); } } } /** * 计算满意度应调查数量 * @param xycount * @param map1 * @param xynum * @return */ private int setReqSatisCount(List xycount, Map map1, int xynum) { for(Map map3:xycount){ if(map1.get("CUSTOMER_ID").equals(map3.get("CUSTOMER_ID"))){ xynum += 1; } } return xynum; } /** * 设置项目存在模板时的覆盖率、得分等信息 * @param pro * @param map1 * @param map * @param templateid * @param xynum */ private void setczmbDetail(Map pro, Map map1, Map map, String[] templateid,int xynum) { pro.put("QUEALL_SCORE", map.get("ALL_SCORE")); pro.put("TEMPLATE_ID", templateid[0]); pro.put("SATIS_BUSTYPE", map.get("SATIS_BUSTYPE")); map1.put("QUEFG_RATE", map.get("FG_RATE")); map1.put("QUESATIS_SCORE", map.get("SATIS_SCORE")); map1.put("SATIS_QZ", map.get("SATIS_QZ")); map1.put("DEFAULT_SCORE", map.get("DEFAULT_SCORE")); map1.put("SATIS_COUNT", xynum); double fgl = 0; if(xynum != 0){ double fgltemp = NumberUtil.div(ConvertUtil.obj2Double(map1.get("NUM")), ConvertUtil.obj2Double(xynum)); fgl = NumberUtil.mul(fgltemp,100.0); } fgl = NumberUtil.round(fgl,0); map1.put("FGL", fgl); } /** * 设置项目不存在模板时的覆盖率、得分等信息 * @param pro * @param map1 * @param map * @param xynum */ private void setproDetail(Map pro, Map map1, Map map, int xynum) { pro.put("QUEALL_SCORE", map.get("ALL_SCORE")); pro.put("TEMPLATE_ID", map.get("TEMPLATE_ID")); pro.put("SATIS_BUSTYPE", map.get("SATIS_BUSTYPE")); map1.put("QUEFG_RATE", map.get("FG_RATE")); map1.put("QUESATIS_SCORE", map.get("SATIS_SCORE")); map1.put("SATIS_QZ", map.get("SATIS_QZ")); map1.put("DEFAULT_SCORE", map.get("DEFAULT_SCORE")); map1.put("SATIS_COUNT", xynum); double fgl = 0; if(xynum != 0){ fgl = NumberUtil.mul(NumberUtil.div(ConvertUtil.obj2Double(map1.get("NUM")), ConvertUtil.obj2Double(xynum), 2),100.00); } fgl = NumberUtil.round(fgl,0); map1.put("FGL", fgl); } /** * 设置响应类调查数据为空时的满意度数据 * @param qzList * @param xycount * @param orderList * @param key * @param pro */ private void setXyKong(List qzList, List xycount,List orderList, Object key, Map pro) { for(Map map:qzList){ if(ConvertUtil.obj2Integer(map.get("STATE")) == 1 ){ if(ConvertUtil.obj2Integer(map.get("SATIS_TYPE")) == 1){ int fvcount = 0; if(xycount.size() > 0){ for(Map map3:xycount){ if(map3.get("CUSTOMER_ID") != null && key.equals(map3.get("CUSTOMER_ID"))){ if((ConvertUtil.obj2StrBlank(map3.get("BUSINESSTYPE"))).equals(Constants.WORKFLOW_BASE_BUSINESS_TYPE_INCIDENT.toString())){ fvcount += 1; } } } } Map orderMap = new HashMap(); orderMap.put("SATIS_COUNT", fvcount); orderMap.put("FGL", 0); orderMap.put("SATIS_QZ", map.get("SATIS_QZ")); orderMap.put("QUEFG_RATE", map.get("FG_RATE")); orderMap.put("QUESATIS_SCORE", map.get("SATIS_SCORE")); orderMap.put("DEFAULT_SCORE", map.get("DEFAULT_SCORE")); orderMap.put("CUSTOMER_ID", key); orderMap.put("BUS_TYPE", 1); orderMap.put("AVGSCORE", 0); orderMap.put("NUM", 0); orderMap.put("BUSINESSTYPE", Constants.WORKFLOW_BASE_BUSINESS_TYPE_INCIDENT); orderList.add(orderMap); } } } pro.put("orderList", orderList); } /** * 设置驻场响应类调查数据为空时的满意度数据 * @param qzList * @param xycount * @param orderList * @param key * @param pro */ private void setZcXyKong(List qzList, List xycount,List orderList, Object key, Map pro) { for(Map map:qzList){ if(ConvertUtil.obj2Integer(map.get("STATE")) == 1 ){ if(ConvertUtil.obj2Integer(map.get("SATIS_TYPE")) == 6){ int fvcount = 0; if(xycount.size() > 0){ for(Map map3:xycount){ if(map3.get("CUSTOMER_ID") != null && key.equals(map3.get("CUSTOMER_ID"))){ if((ConvertUtil.obj2StrBlank(map3.get("BUSINESSTYPE"))).equals(Constants.WORKFLOW_BASE_BUSINESS_TYPE_INCIDENT_LOCAL.toString())){ fvcount += 1; } } } } Map orderMap = new HashMap(); orderMap.put("SATIS_COUNT", fvcount); orderMap.put("FGL", 0); orderMap.put("SATIS_QZ", map.get("SATIS_QZ")); orderMap.put("QUEFG_RATE", map.get("FG_RATE")); orderMap.put("QUESATIS_SCORE", map.get("SATIS_SCORE")); orderMap.put("DEFAULT_SCORE", map.get("DEFAULT_SCORE")); orderMap.put("CUSTOMER_ID", key); orderMap.put("BUS_TYPE", 1); orderMap.put("AVGSCORE", 0); orderMap.put("NUM", 0); orderMap.put("BUSINESSTYPE", Constants.WORKFLOW_BASE_BUSINESS_TYPE_INCIDENT_LOCAL); orderList.add(orderMap); } } } pro.put("orderCzList", orderList); } /** * 设置驻场数据为空时的满意度数据 * @param qzList * @param key * @param pro */ private void setZcKong(List qzList,List xycount,List totalList, Object key, Map pro) { for(Map map:qzList){ if(ConvertUtil.obj2Integer(map.get("STATE")) == 1){ if(ConvertUtil.obj2Integer(map.get("SATIS_TYPE")) == 3){ int fvcount = 0; if(xycount.size() > 0){ for(Map map3:xycount){ if(map3.get("CUSTOMER_ID") != null && key.equals(map3.get("CUSTOMER_ID"))){ fvcount += 1; } } } Map orderMap = new HashMap(); orderMap.put("SATIS_COUNT", fvcount); orderMap.put("FGL", 0); orderMap.put("SATIS_QZ", map.get("SATIS_QZ")); orderMap.put("QUEFG_RATE", map.get("FG_RATE")); orderMap.put("QUESATIS_SCORE", map.get("SATIS_SCORE")); orderMap.put("DEFAULT_SCORE", map.get("DEFAULT_SCORE")); orderMap.put("CUSTOMER_ID", key); orderMap.put("BUS_TYPE", 1); orderMap.put("AVGSCORE", 0); orderMap.put("NUM", 0); totalList.add(orderMap); } } } pro.put("totalList", totalList); } @Override public boolean updateCmdbDataSource(String beginTime, String endTime) { List list = timeTaskService.getCmdbList(beginTime,endTime); String json = JsonUtil.list2Json(list); Map params = new HashMap(); params.put("data", json); System.out.println(FullTextConstants.getUpdate_data_source_path()); HttpUtil.doPost(FullTextConstants.getUpdate_data_source_path(), params, HttpCharset.UTF8); return true; } @Override public boolean updateDocumentDataSource(String beginTime, String endTime) { List list = timeTaskService.getDocumentList(beginTime,endTime); String json = JsonUtil.list2Json(list); Map params = new HashMap(); params.put("data", json); System.out.println(FullTextConstants.getUpdate_data_source_path()); HttpUtil.doPost(FullTextConstants.getUpdate_data_source_path(), params, HttpCharset.UTF8); return true; } @Override public void savePlanDrill() { Map param=new HashMap(); Long now=DateUtil.getCurrentDate8(); Long nowTime=DateUtil.getDateAdd(now, 7, 8); param.put("nowTime", nowTime); String sql="select b.* from emergency_plan a,emergency_date b where b.plan_id=a.id and b.IS_ORDER=1 and a.state=1 and b.plan_date=:nowTime "; List list=baseDao.queryForList(sql,param); if(list.size()>0){ for(Map map:list){ String order_code = workOrderCodeService.getYatOrderCode(); param.put("order_code", order_code); param.put("yid", StringUtil.getUUID()); param.put("id", ConvertUtil.obj2StrBlank(map.get("PALN_ID"))); param.put("did", ConvertUtil.obj2StrBlank(map.get("ID"))); String sqlb="insert into emergency_drill(ID,PLAN_ID,DATE_ID,ORDER_CODE,IS_ZX) " + "values(:yid,:id,:did,:order_code,2)"; baseDao.execute(sqlb, param); } } } @Override public void saveTraffic() { try { List list=dom4jReadXMLFile(); if(list.size()>0){ String sql=" select * from traffic where state=0 or state is null"; List traList=baseDao.queryForList(sql); if(traList.size()>0){ for(Map map:traList){ String sn=ConvertUtil.obj2StrBlank(map.get("SERIAL_NUMBER")); for(Map mapa:list){ if(sn.equals(ConvertUtil.obj2StrBlank(mapa.get("sn")))){ Map param=new HashMap(); String sn1=ConvertUtil.obj2StrBlank(mapa.get("sn")); String time=ConvertUtil.obj2Str(mapa.get("tme")); time=time.replace(":", ""); String now=ConvertUtil.obj2StrBlank(DateUtil.getCurrentDate8())+time; long s=DateUtil.getMillisFormDate2Date(ConvertUtil.obj2Long(map.get("START_TIME")), ConvertUtil.obj2Long(now)); if(s>0){ param.put("state", 1); }else{ param.put("state", 0); } SimpleDateFormat format=new SimpleDateFormat("HH:mm:ss"); format.setTimeZone(TimeZone.getTimeZone("GMT_00:00")); String hs=format.format(s); param.put("hs", "00000000"+hs.replace(":", "")); param.put("now", now); param.put("sn", sn); String sqla="update traffic set TRA_STATE=:state,END_TIME=:now,LONG_TIME=:hs,state=1 where SERIAL_NUMBER=:sn"; baseDao.execute(sqla, param); } } } } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static String ls() throws Exception{ MyHttpPost myHttpPostProxy=new MyHttpPost(); CRequest reqProxy=new CRequest(); reqProxy.setParameter("vo_id","getCustCall"); reqProxy.setParameter("_secs_","lcall"); String time=""; Long now=DateUtil.getCurrentDate8(); time=ConvertUtil.obj2StrBlank(now).substring(0, 4)+"-"+ConvertUtil.obj2StrBlank(now).substring(4, 6)+ConvertUtil.obj2StrBlank(now).substring(6, 8); reqProxy.setParameter("call_date_start",time); String vproxyURL="http://"+SysConfigConstants.CALL_PATH+":"+SysConfigConstants.CALL_DK+"/v/vack"; CResponse repProxy=myHttpPostProxy.sendRequest_XML_V4(reqProxy,vproxyURL); int rcode=repProxy.getRCode(); if(rcode!=0){ System.out.println("sendRequestWithTag error="+rcode+repProxy.getmsg()); return null; }else{ System.out.println(repProxy.getParameter("xml")); return ConvertUtil.obj2StrBlank(repProxy.getParameter("xml")); } } @SuppressWarnings({ "unchecked", "rawtypes" }) private static List dom4jReadXMLFile() throws Exception { String ls=ls(); ls.replace("utf-8", "utf8"); ByteArrayInputStream tInputStringStream = new ByteArrayInputStream(ls.getBytes("UTF-8")); List trafficList=new LinkedList(); // Dom4j解析books.xml // 创建的对象reader SAXReader reader = new SAXReader(); reader.setEncoding("UTF-8"); try { // 通过reader对象的read方法加载books.xml文件,获取document对象 Document document = reader.read(tInputStringStream); reader.setEncoding("UTF8"); // 通过document对象获取根节点bookstore Element bookstore = document.getRootElement(); // 通过element对象的elementIterator方法获取迭代器 Iterator it = bookstore.elementIterator(); // 全局变量记录第几本书籍 int num = 0; // 遍历迭代器,获取根节点中的信息(书籍) while (it.hasNext()) { Map map=new HashMap(); num++; Element book = (Element) it.next(); // 获取book的属性名以及属性值 List bookAttrs = book.attributes(); for (Attribute attr : bookAttrs) { System.out.println("属性名:" + attr.getName() + "--属性值:" + attr.getStringValue()); map.put("id", attr.getStringValue()) ; } // 解析子节点的信息 Iterator itt = book.elementIterator(); while (itt.hasNext()) { Element bookChild = (Element) itt.next(); if (bookChild.getName().equals("id")) { map.put("idTwo", bookChild.getStringValue()); } if (bookChild.getName().equals("sn")) { map.put("sn",bookChild.getStringValue()); } if (bookChild.getName().equals("tms")) { map.put("tms",bookChild.getStringValue()); } if (bookChild.getName().equals("tme")) { map.put("tme",bookChild.getStringValue()); } } // 将书籍存入书籍集合中 trafficList.add(map); // 将书籍实体设置为null,节省资源 } } catch (DocumentException e) { e.printStackTrace(); } return trafficList; } @Override public Map saveTrafficYy() { Map result=QueryCallEvent("1",null,null,null); return result; } /** * * @param appver:应用版本值 * @param user:用户名 * @param pwd * @param account:企业400号码 */ @SuppressWarnings({ "unchecked", "static-access" }) public Map QueryCallEvent(String appver,String user,String pwd,String account){ Map resultMap=new HashMap(); resultMap.put("msg", "1"); try { pwd=SysConfigConstants.YY_PWD; user=SysConfigConstants.YY_USER; account=SysConfigConstants.YY_ACCOUNT; appver="1"; //获取token String token=login(appver,user, pwd); String result="用户名或者密码错误"; if("".equals(token) || "1".equals(token) || token==null){ return null; }else{ //用返回的token重新计算secrect Map tokenmap=new HashMap(); //获取当前时间 String time4=ConvertUtil.obj2StrBlank(DateUtil.getCurrentDate14());//http请求时间为当前时间 //传递Http请求参数 tokenmap.put("timestamp", time4); tokenmap.put("appver", appver); tokenmap.put("user", user); tokenmap.put("account", account); String secret =LoginUtil.signTopRequest(tokenmap, token); //发送HTTP请求 tokenmap.put("secret", secret); String url = "http://xtapi.union400.com/api/call/queryCallEvent.action"; HttpUtilTool http = new HttpUtilTool(); @SuppressWarnings("static-access") String res = http.post(tokenmap, url); System.out.println(res); if(StringUtil.notEmpty(res)){ Map info=JsonUtil.json2SimpleMap(res); List list=JsonUtil.json2List(info.get("data").toString()); if(list.size()>0){ for(Map map:list){ Map param=new HashMap(); String event=ConvertUtil.obj2StrBlank(map.get("event")); if(event.equals("alert")){ resultMap.put("msg", "0"); resultMap.put("mobile", ConvertUtil.obj2StrBlank(map.get("callingid"))); param.put("id", StringUtil.getUUID()); param.put("mobile", ConvertUtil.obj2StrBlank(map.get("callingid"))); param.put("serviceSn", ConvertUtil.obj2StrBlank(map.get("serviceSn"))); param.put("create_time", ConvertUtil.obj2StrBlank(map.get("createtime"))); String sql="insert into traffic_yy(id,mobile,servicesn,create_time) values(:id,:mobile,:serviceSn,:create_time)"; baseDao.execute(sql, param); } } } } return resultMap; } } catch (Exception e) { e.printStackTrace(); String res="异常信息如下:"+e.toString(); return null; } } public static String expiredtime=null;//有效时间 public static String token=null; public static String login(String appver,String user,String pwd){ try { if(expiredtime==null){//有效时间为空则执行登录 String tokens=loginmethod(appver, user, pwd); return tokens; }else{//不为空 //获取当前时间 Date endtime = new Date(new Date().getTime());//Thu Jul 13 19:24:24 CST 2017 //有效时间 SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss"); Date date = formatter.parse(expiredtime);//Fri Jul 14 19:24:45 CST 2017 long time=diffSecond(endtime, date)/60/60; if(time>1){//有效时间与当前时间比较大于60分钟返回token return token; }else{//否则重新登录 String tokens=loginmethod(appver, user, pwd); return tokens; } } } catch (Exception e) { e.printStackTrace(); } return null; } /** * 给定时间1与给定时间2相差秒数 * * @param inDate * @return */ public static long diffSecond(Date date1, Date date2) { if (date1 == null || date2 == null) return 0; long diff = Math.abs(date2.getTime() - date1.getTime()); long diffSec = diff / 1000; return diffSec; } public static String loginmethod(String appver,String user,String pwd){ try { LoginUtil lutil=new LoginUtil(); @SuppressWarnings({ "unchecked", "static-access" }) Map mappram=lutil.union400Login(appver, user, pwd); String url = "http://xtapi.union400.com/api/union400Login.action"; HttpUtilTool http = new HttpUtilTool(); @SuppressWarnings("static-access") String res = http.post(mappram, url); JSONObject json = JSONObject.fromObject(res); //取出token和expiredtime Iterator iter = json.keySet().iterator(); Map map = new HashMap(); while (iter.hasNext()) { String key = (String) iter.next(); String value = json.getString(key); map.put(key, value); } String errcode=map.get("errcode"); if("1".equals(errcode)){ return errcode; }else{ JSONObject jsonqdate = JSONObject.fromObject(map.get("data")); Iterator iterdata = jsonqdate.keySet().iterator(); Map mapjsondate = new HashMap(); while (iterdata.hasNext()) { String key = (String) iterdata.next(); String value = jsonqdate.getString(key); mapjsondate.put(key, value); } expiredtime=mapjsondate.get("expiredtime"); token=mapjsondate.get("token"); return token; } } catch (Exception e) { e.printStackTrace(); } return null; } public static String QueryCallRecord(String appver,String user,String pwd,String account,String startTime,String endTime,String pageSize,String pageNow){ try { //获取token String token=login(appver,user, pwd); String result="用户名或者密码错误"; if("".equals(token) || "1".equals(token) || token==null){ return result; }else{ //用返回的token重新计算secrect Map tokenmap=new HashMap(); //获取当前时间 String time4=ConvertUtil.obj2StrBlank(DateUtil.getCurrentDate14());//http请求时间为当前时间 //传递Http请求参数 tokenmap.put("timestamp", time4); tokenmap.put("appver", appver); tokenmap.put("user", user); tokenmap.put("account", account); tokenmap.put("startTime", startTime); tokenmap.put("endTime", endTime); tokenmap.put("pageSize", pageSize); tokenmap.put("pageNow", pageNow); String secret = LoginUtil.signTopRequest(tokenmap, token); //发送HTTP请求 tokenmap.put("secret", secret); String url = "http://xtapi.union400.com/api/call/queryCallRecord.action"; HttpUtilTool http = new HttpUtilTool(); @SuppressWarnings("static-access") String res = http.post(tokenmap, url); System.out.println(res); return res; } } catch (Exception e) { e.printStackTrace(); String res="异常信息如下:"+e.toString(); return res; } } }