package com.gkhy.safePlatform.safeCheck.controller; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.gkhy.safePlatform.commons.co.ContextCacheUser; import com.gkhy.safePlatform.commons.enums.E; import com.gkhy.safePlatform.commons.enums.ResultCodes; import com.gkhy.safePlatform.commons.exception.AusinessException; import com.gkhy.safePlatform.commons.vo.ResultVO; import com.gkhy.safePlatform.safeCheck.model.dto.req.SafeCheckQuotaPageReqDTO; import com.gkhy.safePlatform.safeCheck.model.dto.req.SafeCheckQuotaReqDTO; import com.gkhy.safePlatform.safeCheck.model.dto.resp.ListQuotasRespDTO; import com.gkhy.safePlatform.safeCheck.model.dto.resp.SafeCheckQuotaRespDTO; import com.gkhy.safePlatform.safeCheck.model.dto.resp.SafeCheckQuotaUpdateRespDTO; import com.gkhy.safePlatform.safeCheck.service.SafeCheckBaseManagerService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.*; import java.util.List; @RestController @RequestMapping("/safeCheckQuota") public class SafeCheckQuotaController { @Autowired private SafeCheckBaseManagerService safeCheckBaseManagerService; /** * 获取所有的巡检指标 */ @PostMapping("/select/listQuotas") public ResultVO> listQuotas(Authentication authentication){ ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal(); List list = safeCheckBaseManagerService.listQuotas(currentUser); ResultVO resultVO = new ResultVO<>(ResultCodes.OK,list); return resultVO; } /** * @description 新增巡检指标 */ @PostMapping("/insert/saveQuota") public ResultVO saveQuota(Authentication authentication, @RequestBody SafeCheckQuotaReqDTO safeCheckQuotaReqDTO){ ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal(); int saveResult = safeCheckBaseManagerService.saveQuota(currentUser, safeCheckQuotaReqDTO); ResultVO resultVO = new ResultVO<>("200","新增巡检指标成功"); resultVO.setCount(saveResult); return resultVO; } /*** * @description 根据巡检指标id删除指标 */ @PostMapping("/delete/deleteQuotaById") public ResultVO deleteQuota(Authentication authentication, @RequestBody SafeCheckQuotaReqDTO safeCheckQuotaReqDTO){ ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal(); Long quotaId = safeCheckQuotaReqDTO.getId(); safeCheckBaseManagerService.deleteQuotaById(currentUser, quotaId); ResultVO resultVO = new ResultVO<>("200","删除巡检指标成功"); return resultVO; } /** * @description 根据巡检指标id更新巡检指标 */ @PostMapping("/update/updateQuotaById") public ResultVO updateQuota(Authentication authentication, @RequestBody SafeCheckQuotaReqDTO safeCheckQuotaReqDTO){ ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal(); safeCheckBaseManagerService.updateQuotaById(currentUser,safeCheckQuotaReqDTO); ResultVO resultVO = new ResultVO<>("200","更新巡检指标成功"); return resultVO; } /** * @description 根据巡检指标id查询巡检指标(有效状态) */ @GetMapping("/select/getQuotaById") public ResultVO getQuataById(Long id){ SafeCheckQuotaUpdateRespDTO safeCheckQuota = safeCheckBaseManagerService.getQuataById(id); ResultVO resultVO = new ResultVO<>(ResultCodes.OK,safeCheckQuota); return resultVO; } /** * @description 根据巡检指标名称查询巡检指标(有效状态) */ @GetMapping("/select/getQuotaByName") public ResultVO getQuotaByName(String quotaName){ if (quotaName == null){ throw new AusinessException(E.DATA_PARAM_NULL,"查询条件不能为空"); } SafeCheckQuotaRespDTO safeCheckQuota = safeCheckBaseManagerService.getQuotaByName(quotaName); if (safeCheckQuota == null){ return new ResultVO<>("200","查询不到相关数据"); } return new ResultVO<>(ResultCodes.OK,safeCheckQuota); } /** * @description 查询所有数据并进行分页展示 */ @PostMapping("/select/listQuotaByPage") public ResultVO> listQuotaByPage(@RequestBody SafeCheckQuotaPageReqDTO safeCheckQuotaPageReqDTO){ Integer pageIndex = safeCheckQuotaPageReqDTO.getPageIndex(); Integer pageSize = safeCheckQuotaPageReqDTO.getPageSize(); String quotaName = safeCheckQuotaPageReqDTO.getQuotaName(); if (pageIndex == 0 || pageSize == 0){ throw new AusinessException(E.DATA_PARAM_NULL,"当前页码或当前页显示数不能为0"); } Page pageInfo = new Page(pageIndex, pageSize); pageInfo = safeCheckBaseManagerService.listQuotaByPage(pageInfo,quotaName); return new ResultVO<>(ResultCodes.OK,pageInfo); } }