|
@@ -0,0 +1,250 @@
|
|
|
+package com.welampiot.controller;
|
|
|
+
|
|
|
+import com.welampiot.common.BaseResult;
|
|
|
+import com.welampiot.common.InterfaceResultEnum;
|
|
|
+import com.welampiot.dto.PatrolManageDTO;
|
|
|
+import com.welampiot.dto.PatrolSpotDTO;
|
|
|
+import com.welampiot.dto.PatrolTaskDTO;
|
|
|
+import com.welampiot.dto.PatrolTaskSpotDTO;
|
|
|
+import com.welampiot.service.*;
|
|
|
+import com.welampiot.utils.ToolUtils;
|
|
|
+import com.welampiot.vo.PatrolManageVO;
|
|
|
+import com.welampiot.vo.PatrolTaskVO;
|
|
|
+import org.json.JSONArray;
|
|
|
+import org.json.JSONObject;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * ClassName: PatrolManageController
|
|
|
+ * Package: com.welampiot.controller
|
|
|
+ * Description:
|
|
|
+ *
|
|
|
+ * @Author: zhj_Start
|
|
|
+ * @Create: 2023/6/29 - 16:54
|
|
|
+ * @Version: v1.0
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@CrossOrigin
|
|
|
+@RequestMapping("/patrolManage")
|
|
|
+public class PatrolManageController {
|
|
|
+ @Autowired
|
|
|
+ private ToolUtils toolUtils;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PatrolManageService patrolManageService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PatrolSpotService patrolSpotService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RepairPersonnelService repairPersonnelService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PatrolTaskService patrolTaskService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PatrolTaskSpotService patrolTaskSpotService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 巡视计划列表
|
|
|
+ * @param request 分页、路段筛选、关键字搜索
|
|
|
+ * @return 巡视计划列表
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/patrolManageList", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> patrolManageList(HttpServletRequest request) {
|
|
|
+ Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ Integer areaId = (Integer) toolUtils.getRequestContent(request,"areaId",1);
|
|
|
+ Integer sectionId = (Integer) toolUtils.getRequestContent(request,"sectionId",1);
|
|
|
+ Integer provinceId = (Integer) toolUtils.getRequestContent(request,"provinceId",1);
|
|
|
+ Integer cityId = (Integer) toolUtils.getRequestContent(request,"cityId",1);
|
|
|
+ String keyword = (String) toolUtils.getRequestContent(request,"keyword",2);
|
|
|
+ int page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
|
|
|
+ int count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count"));
|
|
|
+
|
|
|
+ PatrolManageVO vo = new PatrolManageVO();
|
|
|
+ vo.setPage(count * (page - 1));
|
|
|
+ vo.setCount(count);
|
|
|
+ vo.setSectionId(sectionId);
|
|
|
+ vo.setAreaId(areaId);
|
|
|
+ vo.setCityId(cityId);
|
|
|
+ vo.setProvinceId(provinceId);
|
|
|
+ vo.setKeyword(keyword);
|
|
|
+ vo.setSectionList(toolUtils.getSectionList(request));
|
|
|
+ List<PatrolManageDTO> patrolManageList = patrolManageService.getPatrolManageList(vo);
|
|
|
+ List<PatrolManageDTO> list = new ArrayList<>();
|
|
|
+ patrolManageList.forEach(patrolManageDTO -> {
|
|
|
+ if (patrolManageDTO.getId() != null) {
|
|
|
+ List<PatrolSpotDTO> spotList = patrolSpotService.getPatrolSpotList(patrolManageDTO.getId());
|
|
|
+ patrolManageDTO.setSpotList(spotList);
|
|
|
+ }
|
|
|
+ list.add(patrolManageDTO);
|
|
|
+ });
|
|
|
+ PatrolManageVO patrolManageVO = new PatrolManageVO();
|
|
|
+ patrolManageVO.setList(list);
|
|
|
+ patrolManageVO.setTotal(patrolManageService.getPatrolManageCount(vo));
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,patrolManageVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 巡视计划下拉列表
|
|
|
+ * @param request 用户名
|
|
|
+ * @return 巡视计划下拉列表
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/patrolManageNav", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> patrolManageNav(HttpServletRequest request) {
|
|
|
+ Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ String username = (String) toolUtils.getRequestContent(request,"username",2);
|
|
|
+ if (username == null) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
|
|
|
+ Integer userid = repairPersonnelService.getUserIdByUsername(username);
|
|
|
+ List<PatrolManageDTO> patrolDownList = patrolManageService.getPatrolDownList(userid);
|
|
|
+ PatrolManageVO patrolManageVO = new PatrolManageVO();
|
|
|
+ patrolManageVO.setList(patrolDownList);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,patrolManageVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加编辑巡视计划
|
|
|
+ * @param request 要添加编辑的巡视属性
|
|
|
+ * @return 更新巡视计划数据
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/savePatrolManage", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> savePatrolManage(HttpServletRequest request) throws ParseException {
|
|
|
+ Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ Integer id = (Integer) toolUtils.getRequestContent(request,"id",1);
|
|
|
+ Integer sectionId = (Integer) toolUtils.getRequestContent(request,"sectionId",1);
|
|
|
+ Integer count = (Integer) toolUtils.getRequestContent(request,"count",1);
|
|
|
+ String planStartTime = (String) toolUtils.getRequestContent(request,"planStartTime",2);
|
|
|
+ String planEndTime = (String) toolUtils.getRequestContent(request,"planEndTime",2);
|
|
|
+ String username = (String) toolUtils.getRequestContent(request,"username",2);
|
|
|
+ String spotList = (String) toolUtils.getRequestContent(request,"spotList",2);
|
|
|
+
|
|
|
+ if (sectionId == 0) return toolUtils.response(InterfaceResultEnum.LACK_SECTION_ERROR,version);
|
|
|
+ if (planStartTime.length() == 0 || planEndTime.length() == 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_PATROL_TIME_ERROR,version);
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ long startTime = simpleDateFormat.parse(planStartTime).getTime();
|
|
|
+ long endTime = simpleDateFormat.parse(planEndTime).getTime();
|
|
|
+ if (startTime > endTime)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.TIME_EXCEPTION_ERROR,version);
|
|
|
+ if (spotList.length() == 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
|
|
|
+ JSONArray spotArray = new JSONArray(spotList);
|
|
|
+
|
|
|
+ PatrolManageDTO patrolManageDTO = new PatrolManageDTO();
|
|
|
+ patrolManageDTO.setSectionId(sectionId);
|
|
|
+ patrolManageDTO.setCount(count);
|
|
|
+ patrolManageDTO.setPlanStartTime(planStartTime);
|
|
|
+ patrolManageDTO.setPlanEndTime(planEndTime);
|
|
|
+ if (id == 0) { // 添加
|
|
|
+ Integer userid = repairPersonnelService.getUserIdByUsername(username);
|
|
|
+ patrolManageDTO.setUserid(userid);
|
|
|
+ long l = System.currentTimeMillis();
|
|
|
+ String format = simpleDateFormat.format(l);
|
|
|
+ patrolManageDTO.setCreateTime(format);
|
|
|
+ patrolManageService.addPatrolManageData(patrolManageDTO);
|
|
|
+ Integer dtoId = patrolManageDTO.getId();
|
|
|
+ for (int i = 0; i < spotArray.length(); i ++) {
|
|
|
+ JSONObject spotObject = spotArray.getJSONObject(i);
|
|
|
+ String longitude = spotObject.getString("longitude");
|
|
|
+ String latitude = spotObject.getString("latitude");
|
|
|
+ String name = spotObject.getString("name");
|
|
|
+ if (longitude.length() == 0 || latitude.length() == 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_LOCATION_ERROR,version);
|
|
|
+ if (name.length() == 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_PATROL_SPOT_NAME_ERROR,version);
|
|
|
+ PatrolSpotDTO patrolSpotDTO = new PatrolSpotDTO();
|
|
|
+ patrolSpotDTO.setLatitude(latitude);
|
|
|
+ patrolSpotDTO.setLongitude(longitude);
|
|
|
+ patrolSpotDTO.setName(name);
|
|
|
+ patrolSpotDTO.setPatrolManageId(dtoId);
|
|
|
+ patrolSpotService.addPatrolSpotData(patrolSpotDTO);
|
|
|
+ }
|
|
|
+ } else { // 编辑
|
|
|
+ patrolManageDTO.setId(id);
|
|
|
+ patrolManageService.updatePatrolManageData(patrolManageDTO);
|
|
|
+ // 删除之前的数据,重新添加新数据
|
|
|
+ patrolSpotService.deletePatrolSpotIdByManageId(id);
|
|
|
+ PatrolSpotDTO spotDTO = new PatrolSpotDTO();
|
|
|
+ spotDTO.setPatrolManageId(id);
|
|
|
+ for (int i = 0; i < spotArray.length(); i ++) {
|
|
|
+ JSONObject spotObject = spotArray.getJSONObject(i);
|
|
|
+ String longitude = spotObject.getString("longitude");
|
|
|
+ String latitude = spotObject.getString("latitude");
|
|
|
+ String name = spotObject.getString("name");
|
|
|
+ if (longitude.length() == 0 || latitude.length() == 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_LOCATION_ERROR,version);
|
|
|
+ if (name.length() == 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_PATROL_SPOT_NAME_ERROR,version);
|
|
|
+ spotDTO.setName(name);
|
|
|
+ spotDTO.setLatitude(latitude);
|
|
|
+ spotDTO.setLongitude(longitude);
|
|
|
+ patrolSpotService.addPatrolSpotData(spotDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 巡视任务列表
|
|
|
+ * @param request 分页,路段筛选
|
|
|
+ * @return 巡视任务列表
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/patrolTaskList", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> patrolTaskList(HttpServletRequest request) throws ParseException {
|
|
|
+ Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ Integer page = (Integer) toolUtils.getRequestContent(request,"page",1);
|
|
|
+ Integer count = (Integer) toolUtils.getRequestContent(request,"count",1);
|
|
|
+ Integer status = (Integer) toolUtils.getRequestContent(request,"status",1);
|
|
|
+ Integer areaId = (Integer) toolUtils.getRequestContent(request,"areaId",1);
|
|
|
+ Integer sectionId = (Integer) toolUtils.getRequestContent(request,"sectionId",1);
|
|
|
+ Integer provinceId = (Integer) toolUtils.getRequestContent(request,"provinceId",1);
|
|
|
+ Integer cityId = (Integer) toolUtils.getRequestContent(request,"cityId",1);
|
|
|
+ String username = (String) toolUtils.getRequestContent(request,"username",2);
|
|
|
+ String keyword = (String) toolUtils.getRequestContent(request,"keyword",2);
|
|
|
+ String date = (String) toolUtils.getRequestContent(request,"date",2);
|
|
|
+ if (username == null) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
|
|
|
+ String startDate = "", endDate = "";
|
|
|
+ if (date.length() != 0) {
|
|
|
+ List<String> strings = Arrays.asList(date.split("/"));
|
|
|
+ startDate = strings.get(0) + " 00:00:00";
|
|
|
+ endDate = strings.get(1) + " 23:59:59";
|
|
|
+ }
|
|
|
+
|
|
|
+ PatrolTaskVO patrolTaskVO = new PatrolTaskVO();
|
|
|
+ patrolTaskVO.setPage(page);
|
|
|
+ patrolTaskVO.setCount(count);
|
|
|
+ patrolTaskVO.setStatus(status);
|
|
|
+ patrolTaskVO.setAreaId(areaId);
|
|
|
+ patrolTaskVO.setSectionId(sectionId);
|
|
|
+ patrolTaskVO.setProvinceId(provinceId);
|
|
|
+ patrolTaskVO.setCityId(cityId);
|
|
|
+ patrolTaskVO.setKeyword(keyword);
|
|
|
+ patrolTaskVO.setStartDate(startDate);
|
|
|
+ patrolTaskVO.setEndDate(endDate);
|
|
|
+
|
|
|
+ List<PatrolTaskDTO> patrolTaskList = patrolTaskService.getPatrolTaskList(patrolTaskVO);
|
|
|
+ List<PatrolTaskDTO> list = new ArrayList<>();
|
|
|
+ patrolTaskList.forEach(dto -> {
|
|
|
+ if (dto.getId() != null) {
|
|
|
+ List<PatrolTaskSpotDTO> patrolTaskSpotList = patrolTaskSpotService.getPatrolTaskSpotList(dto.getId());
|
|
|
+ dto.setSpotList(patrolTaskSpotList);
|
|
|
+ }
|
|
|
+ list.add(dto);
|
|
|
+ });
|
|
|
+ PatrolTaskVO vo = new PatrolTaskVO();
|
|
|
+ vo.setList(list);
|
|
|
+ vo.setTotal(patrolTaskService.getPatrolTaskTotal(patrolTaskVO));
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,vo);
|
|
|
+ }
|
|
|
+}
|