|
@@ -0,0 +1,228 @@
|
|
|
+package com.welampiot.controller;
|
|
|
+
|
|
|
+import com.welampiot.common.BaseResult;
|
|
|
+import com.welampiot.common.InterfaceResultEnum;
|
|
|
+import com.welampiot.dto.RepairInfoDTO;
|
|
|
+import com.welampiot.dto.RepairPersonnelDTO;
|
|
|
+import com.welampiot.service.RepairInfoService;
|
|
|
+import com.welampiot.service.RepairPersonnelService;
|
|
|
+import com.welampiot.utils.ToolUtils;
|
|
|
+import com.welampiot.vo.RepairInfoVO;
|
|
|
+import com.welampiot.vo.RepairPersonnelDetailsVO;
|
|
|
+import com.welampiot.vo.RepairPersonnelVO;
|
|
|
+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.util.Objects;
|
|
|
+
|
|
|
+/**
|
|
|
+ * ClassName: RepairController
|
|
|
+ * Package: com.welampiot.controller
|
|
|
+ * Description:
|
|
|
+ *
|
|
|
+ * @Author: zhj_Start
|
|
|
+ * @Create: 2023/5/16 - 10:33
|
|
|
+ * @Version: v1.0
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@CrossOrigin
|
|
|
+@RequestMapping("/repair")
|
|
|
+public class RepairController {
|
|
|
+ @Autowired
|
|
|
+ private RepairPersonnelService repairPersonnelService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ToolUtils toolUtils;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RepairInfoService repairInfoService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取维修人员列表
|
|
|
+ * @param request 分页、维修人员名称关键字搜索、用户id筛选
|
|
|
+ * @return 维修人员list
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "getList", method = RequestMethod.POST)
|
|
|
+ public BaseResult getList(HttpServletRequest request) {
|
|
|
+ int version = (int) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ int page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
|
|
|
+ int count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count"));
|
|
|
+ String username = (String) toolUtils.getRequestContent(request,"username",2);
|
|
|
+ String keyword = (String) toolUtils.getRequestContent(request,"keyword",2);
|
|
|
+
|
|
|
+ RepairPersonnelDTO dto = new RepairPersonnelDTO();
|
|
|
+ dto.setPage(count * (page - 1));
|
|
|
+ dto.setCount(count);
|
|
|
+ dto.setKeyword(keyword);
|
|
|
+ Integer userId = repairPersonnelService.getUserIdByUsername(username);
|
|
|
+ dto.setOwnId(userId);
|
|
|
+ RepairPersonnelVO repairPersonnelVO = repairPersonnelService.getListByRepairPersonnelDTO(dto);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,repairPersonnelVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取维修人员详情
|
|
|
+ * @param request 维修人员id
|
|
|
+ * @return 维修人员详情对象 RepairPersonnelDetailsVO
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/details", method = RequestMethod.POST)
|
|
|
+ public BaseResult details(HttpServletRequest request) {
|
|
|
+ int version = (int) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ int userId = (int) toolUtils.getRequestContent(request,"userId",1);
|
|
|
+ if (userId == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
|
|
|
+ RepairPersonnelDetailsVO repairPersonnelDetailsVO = repairPersonnelService.getDetailsByRepairPersonnelDTO(userId);
|
|
|
+ if (repairPersonnelDetailsVO == null) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,repairPersonnelDetailsVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加编辑维修人员
|
|
|
+ * @param request 需要添加编辑的维修人员的属性
|
|
|
+ * @return 更新维修人员数据
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "save", method = RequestMethod.POST)
|
|
|
+ public BaseResult save(HttpServletRequest request) {
|
|
|
+ int version = (int) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ int id = (int) toolUtils.getRequestContent(request,"id",1);
|
|
|
+ int groupId = (int) toolUtils.getRequestContent(request,"groupId",1);
|
|
|
+ String name = request.getParameter("name");
|
|
|
+ String section = request.getParameter("section");
|
|
|
+ String email = request.getParameter("email");
|
|
|
+ String phone = request.getParameter("phone");
|
|
|
+ String number = request.getParameter("number");
|
|
|
+ String company = request.getParameter("company");
|
|
|
+ String username = request.getParameter("username");
|
|
|
+
|
|
|
+ RepairPersonnelDTO dto = new RepairPersonnelDTO();
|
|
|
+ dto.setName(name);
|
|
|
+ dto.setNumber(number);
|
|
|
+ dto.setSection(section);
|
|
|
+ dto.setEmail(email);
|
|
|
+ dto.setPhone(phone);
|
|
|
+ dto.setCompany(company);
|
|
|
+ dto.setGroupId(groupId);
|
|
|
+
|
|
|
+ if (id == 0) { // 添加
|
|
|
+ Integer userId = repairPersonnelService.getUserIdByUsername(username);
|
|
|
+ dto.setOwnId(userId);
|
|
|
+ if (name == null || name.length() == 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_REPAIR_PERSONNEL_NAME_ERROR,version);
|
|
|
+ if (number == null || number.length() == 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_REPAIR_PERSONNEL_NUMBER_ERROR,version);
|
|
|
+ if (email == null || email.length() == 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_REPAIR_PERSONNEL_EMAIL_ERROR,version);
|
|
|
+ if (phone == null || phone.length() == 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_REPAIR_PERSONNEL_PHONE_ERROR,version);
|
|
|
+ if (groupId == 0 || String.valueOf(groupId).length() == 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_REPAIR_PERSONNEL_GROUP_ID_ERROR,version);
|
|
|
+
|
|
|
+ RepairPersonnelDTO repairPersonnelDTO = new RepairPersonnelDTO();
|
|
|
+ repairPersonnelDTO.setName(name);
|
|
|
+ repairPersonnelDTO.setOwnId(userId);
|
|
|
+ if (repairPersonnelService.findRepairPersonnelByDTO(repairPersonnelDTO) > 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.REPAIR_PERSONNEL_NAME_UNIQUE_ERROR,version);
|
|
|
+ repairPersonnelDTO = new RepairPersonnelDTO();
|
|
|
+ repairPersonnelDTO.setNumber(number);
|
|
|
+ repairPersonnelDTO.setOwnId(userId);
|
|
|
+ if (repairPersonnelService.findRepairPersonnelByDTO(repairPersonnelDTO) > 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.REPAIR_PERSONNEL_NUMBER_UNIQUE_ERROR,version);
|
|
|
+ repairPersonnelService.addRepairPersonnelDataByDTO(dto);
|
|
|
+ } else { // 编辑
|
|
|
+ dto.setId(id);
|
|
|
+ Integer userId = repairPersonnelService.getUserIdByUsername(username);
|
|
|
+ dto.setOwnId(userId);
|
|
|
+ Integer userIdById = repairPersonnelService.findUserIdById(id);
|
|
|
+ if (!Objects.equals(userIdById, userId))
|
|
|
+ return toolUtils.response(InterfaceResultEnum.USER_HAS_NOT_MODIFY_PRIVILEGE,version);
|
|
|
+ RepairPersonnelDTO repairPersonnelDTO = new RepairPersonnelDTO();
|
|
|
+ repairPersonnelDTO.setId(id);
|
|
|
+ repairPersonnelDTO.setName(name);
|
|
|
+ repairPersonnelDTO.setOwnId(userId);
|
|
|
+ if (repairPersonnelService.findRepairPersonnelByDTO(repairPersonnelDTO) > 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.REPAIR_PERSONNEL_NAME_UNIQUE_ERROR,version);
|
|
|
+ repairPersonnelDTO = new RepairPersonnelDTO();
|
|
|
+ repairPersonnelDTO.setId(id);
|
|
|
+ repairPersonnelDTO.setNumber(number);
|
|
|
+ repairPersonnelDTO.setOwnId(userId);
|
|
|
+ if (repairPersonnelService.findRepairPersonnelByDTO(repairPersonnelDTO) > 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.REPAIR_PERSONNEL_NUMBER_UNIQUE_ERROR,version);
|
|
|
+ repairPersonnelService.updateRepairPersonnelDataByDTO(dto);
|
|
|
+ }
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除维修人员
|
|
|
+ * @param request 要删除的维修人员的id
|
|
|
+ * @return 删除成功
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/del", method = RequestMethod.POST)
|
|
|
+ public BaseResult del(HttpServletRequest request){
|
|
|
+ int version = (int) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ String id = request.getParameter("id");
|
|
|
+ if (id == null || id.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
|
|
|
+ String[] split = id.split(",");
|
|
|
+ for (String repairPersonnelId : split) {
|
|
|
+ int l = Integer.parseInt(repairPersonnelId);
|
|
|
+ repairPersonnelService.deleteRepairPersonnelDataByDTO(l);
|
|
|
+ }
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取维修记录
|
|
|
+ * @param request 维修人员id
|
|
|
+ * @return 维修记录
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/repairInfo", method = RequestMethod.POST)
|
|
|
+ public BaseResult repairInfo(HttpServletRequest request) {
|
|
|
+ int version = (int) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ int id = (int) toolUtils.getRequestContent(request,"id",1);
|
|
|
+ int page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
|
|
|
+ int count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count"));
|
|
|
+
|
|
|
+ RepairInfoDTO dto = new RepairInfoDTO();
|
|
|
+ dto.setRepairUserid(id);
|
|
|
+ dto.setPage(count * (page - 1));
|
|
|
+ dto.setCount(count);
|
|
|
+
|
|
|
+ RepairInfoVO repairInfoVO = repairInfoService.getRepairInfoByDTO(dto);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,repairInfoVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取维修人员下拉列表
|
|
|
+ * @param request 用户id
|
|
|
+ * @return 返回维修人员下拉列表
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/nav", method = RequestMethod.POST)
|
|
|
+ public BaseResult nav(HttpServletRequest request) {
|
|
|
+ int version = (int) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ String username = request.getParameter("username");
|
|
|
+ Integer id = repairPersonnelService.getUserIdByUsername(username);
|
|
|
+ RepairPersonnelVO repairPersonnelVO = repairPersonnelService.getRepairPersonnelDropDownListByDTO(id);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,repairPersonnelVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除维修记录
|
|
|
+ * @param request 要删除的维修记录的id
|
|
|
+ * @return 操作成功
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/delInfo", method = RequestMethod.POST)
|
|
|
+ public BaseResult delInfo(HttpServletRequest request) {
|
|
|
+ int version = (int) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ String id = request.getParameter("id");
|
|
|
+ if (id == null || id.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
|
|
|
+ String[] split = id.split(",");
|
|
|
+ for (String repairInfoId : split) {
|
|
|
+ int l = Integer.parseInt(repairInfoId);
|
|
|
+ repairInfoService.deleteRepairInfoDataById(l);
|
|
|
+ }
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
|
+ }
|
|
|
+}
|