package com.newfiber.api.pc.controller.EventsManage; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.plugins.Page; import com.newfiber.api.core.bean.ReqBodyObj; import com.newfiber.api.core.bean.RespBodyObj; import com.newfiber.api.pc.dao.EventsManage.ComplaintDao; import com.newfiber.api.pc.dao.EventsManage.EventTraceDao; import com.newfiber.api.pc.model.EventsManage.Complaint; import com.newfiber.api.pc.model.EventsManage.ComplaintQuery; import com.newfiber.api.pc.model.EventsManage.EventTrace; import com.newfiber.api.pc.model.EventsManage.EventTraceQuery; import java.net.URLDecoder; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.ResponseBody; /** * Created by XuChengChao on 2017/12/16.---事件跟踪控制器 */ @Controller public class ComplainTraceController { @Autowired private EventTraceDao eventTraceDao; @Autowired private ComplaintDao complaintDao; /** * 添加跟踪事项 * @param request * @param * @return */ @PostMapping(value = "eventTrace/selectTraceEventList",produces = "application/json;charset=UTF-8") @ResponseBody public RespBodyObj addTraceEvent(HttpServletRequest request, ReqBodyObj<Map<String,Object>> param){ String userNo = request.getHeader("userNo"); EventTrace eventTrace = new EventTrace(); eventTrace.setEventNo((String) param.getData().get("eventNo")); eventTrace.setUserNo(userNo); JSONObject json = new JSONObject(); try { int add = eventTraceDao.insertSelective(eventTrace); return RespBodyObj.ok(); }catch (Exception e){ e.printStackTrace(); return RespBodyObj.error(); } } /** * 删除事件跟踪 * @param * @return */ @PostMapping(value = "evnetTrace/deleteEventTrace",produces = "application/json;charset=UTF-8") @ResponseBody public RespBodyObj deleteEventTrace(ReqBodyObj<Map<String,Long []>> param){ Long [] serials = param.getData().get("serials"); EventTraceQuery query = new EventTraceQuery(); JSONObject json = new JSONObject(); try { for (int i=0;i<serials.length;i++){ Long serial = serials[i]; query.createCriteria().andSerialEqualTo(serial); int delete = eventTraceDao.deleteByExample(query); query.clear(); } return RespBodyObj.ok(); }catch (Exception e){ e.printStackTrace(); return RespBodyObj.error(); } } /** * 查询跟踪事件 * @param request * @return */ @PostMapping(value = "eventTrace/getEventTraceList",produces = "application/json;charset=UTF-8") @ResponseBody public RespBodyObj getEventTraceList(HttpServletRequest request,ReqBodyObj<Map<String,Object>> param){ Map<String,Object> map = param.getData(); Integer eventSource = (Integer) map.get("eventSource"); Integer eventUrgency = (Integer) map.get("eventUrgency"); String startTime = (String) map.get("startTime"); String endTime = (String) map.get("endTime"); String eventType = (String) map.get("eventType"); String str = (String) map.get("str"); String divisionNo = (String) map.get("divisionNo"); Integer eventStatus = (Integer) map.get("eventStatu"); String tel = (String) map.get("tel"); String riverNo = (String) map.get("riverNo"); Integer page = param.getCurrent(); Integer rows = param.getSize(); String userNo = request.getHeader("userNo"); int startRow = 0; int pageSize =10; try { ComplaintQuery query = new ComplaintQuery(); ComplaintQuery.Criteria criteria = query.createCriteria(); query.setPageNo(page); query.setPageSize(rows); if (eventType != null && eventType !=""){ criteria.andComplainTypeEqualTo(eventType); } if (divisionNo != null && divisionNo != ""){ criteria.andDivisionNoEqualTo(divisionNo); } if (userNo != null){ query.setUserNo(userNo); } if (riverNo != null){ criteria.andRiverNoEqualTo(riverNo); } if (eventSource != null){ criteria.andEventSourceEqualTo(eventSource); } if (eventUrgency != null){ criteria.andComplainUrgencyEqualTo(eventUrgency); } if (eventStatus != null){ if (eventStatus == 7){ criteria.andEventStatusIdNotEqualTo(5); criteria.andEventStatusIdNotEqualTo(6); }else{ criteria.andEventStatusIdEqualTo(eventStatus); } } if (str != null && str != ""){ String str1 = URLDecoder.decode(str,"UTF-8"); criteria.andEventContentLike("%"+str1+"%"); } if (tel != null && tel != ""){ criteria.andComplainPersonTelLike("%"+tel+"%"); } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date time1 = null; Date time2 = null; if (startTime != null && endTime != null){ time1 = sdf.parse(startTime); time2 = sdf.parse(endTime); criteria.andComplainTimeBetween(time1,time2); } List<Complaint> list = complaintDao.selectEventTraceList(query); int count = 0; Page page1 = new Page(); if(list !=null && list.size() > 0){ count = list.size(); } page1.setTotal(count); page1.setRecords(list); return RespBodyObj.ok(page1); }catch (Exception e){ e.printStackTrace(); return RespBodyObj.error(); } } /** * 查询可供用户添加的追踪事项 * @param request * @return */ @PostMapping(value = "eventTrace/selectAddableTraceEvent",produces = "application/json;charset=UTF-8") @ResponseBody public RespBodyObj selectAddableTraceEvent(HttpServletRequest request,ReqBodyObj param){ Integer page = param.getCurrent(); Integer rows = param.getSize(); Integer startRow = 0; Page page1 = new Page(); try { String userNo = request.getHeader("userNo"); if (page!= null){ startRow = (page-1)*rows; } List<Complaint> list = complaintDao.selectAddableTraceEvent(userNo,startRow,rows); int count = complaintDao.countAddableTraceEvent(userNo); page1.setRecords(list); page1.setTotal(count); return RespBodyObj.ok(page1); }catch (Exception e){ e.printStackTrace(); return RespBodyObj.error(); } } }