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.entity.SafeCheckRegion;
|
import com.gkhy.safePlatform.safeCheck.model.dto.req.SafeCheckQuotaPageReqDTO;
|
import com.gkhy.safePlatform.safeCheck.model.dto.req.SafeCheckRegionPageReqDTO;
|
import com.gkhy.safePlatform.safeCheck.model.dto.req.SafeCheckRegionReqDTO;
|
import com.gkhy.safePlatform.safeCheck.model.dto.req.SafeCheckRfidReqDTO;
|
import com.gkhy.safePlatform.safeCheck.model.dto.resp.*;
|
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.security.Principal;
|
import java.util.HashMap;
|
import java.util.List;
|
|
|
@RestController
|
@RequestMapping("/safeCheckRegion")
|
public class SafeCheckRegionController {
|
|
@Autowired
|
private SafeCheckBaseManagerService safeCheckBaseManagerService;
|
|
/**
|
* @description 获取所有有效的区域名称
|
*/
|
@GetMapping("/select/listRegionName")
|
public ResultVO<List<SafeCheckRegionNameRespDTO>> listRegionName(){
|
List<SafeCheckRegionNameRespDTO> safeCheckRegionNameRespDTOS = safeCheckBaseManagerService.listRegionName();
|
return new ResultVO<>(ResultCodes.OK, safeCheckRegionNameRespDTOS);
|
}
|
|
|
/**
|
* @description 新增巡检区域
|
*/
|
@PostMapping("/insert/saveRegion")
|
public ResultVO<String> saveRegion(Authentication authentication, @RequestBody SafeCheckRegionReqDTO safeCheckRegionReqDTO){
|
|
ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal();
|
|
int saveResult = safeCheckBaseManagerService.saveRegion(currentUser, safeCheckRegionReqDTO);
|
ResultVO resultVO = new ResultVO<>("200","新增巡检区域成功");
|
resultVO.setCount(saveResult);
|
return resultVO;
|
}
|
|
/**
|
* @description 根据id删除巡检区域
|
*/
|
@PostMapping("/delete/deleteRegionById")
|
public ResultVO<String> deleteRegionById(Authentication authentication, @RequestBody SafeCheckRegionReqDTO safeCheckRegionReqDTO){
|
Long id = safeCheckRegionReqDTO.getId();
|
ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal();
|
|
int deleteResult = safeCheckBaseManagerService.deleteRegionById(currentUser,id);
|
|
ResultVO resultVO = new ResultVO<>("200","删除巡检区域成功");
|
resultVO.setCount(deleteResult);
|
return resultVO;
|
}
|
|
|
/**
|
* @description 根据id更新巡检区域
|
*/
|
@PostMapping("/update/updateRegionById")
|
public ResultVO<String> updateRegionById(Authentication authentication, @RequestBody SafeCheckRegionReqDTO safeCheckRegionReqDTO){
|
ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal();
|
safeCheckBaseManagerService.updateRegionById(currentUser, safeCheckRegionReqDTO);
|
ResultVO resultVO = new ResultVO<>("200","更新巡检区域成功");
|
return resultVO;
|
}
|
|
|
/**
|
* @description 根据巡检区域id查询数据
|
*/
|
@PostMapping("/select/getRegionById")
|
public ResultVO<SafeCheckRegionRespDTO> getRegionById(@RequestBody SafeCheckRegionReqDTO safeCheckRegionReqDTO){
|
Long id = safeCheckRegionReqDTO.getId();
|
SafeCheckRegionRespDTO regionByIdAndUuid = safeCheckBaseManagerService.getRegionById(id);
|
ResultVO resultVO = new ResultVO<>(ResultCodes.OK,regionByIdAndUuid);
|
return resultVO;
|
}
|
|
|
/**
|
* @description 查询所有数据并进行分页展示
|
*/
|
@PostMapping("/select/listRegionByPage")
|
public ResultVO<Page<SafeCheckRegionPageRespDTO>> listRegionByPage(Authentication authentication,@RequestBody SafeCheckRegionPageReqDTO safeCheckRegionPageReqDTO){
|
ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal();
|
Integer pageIndex = safeCheckRegionPageReqDTO.getPageIndex();
|
Integer pageSize = safeCheckRegionPageReqDTO.getPageSize();
|
if (pageIndex == 0 || pageSize == 0){
|
throw new AusinessException(E.DATA_PARAM_NULL,"当前页码或当前页显示数不能为0");
|
}
|
HashMap<String, Object> selectCondition = new HashMap<>();
|
selectCondition.put("regionName",safeCheckRegionPageReqDTO.getRegionName());
|
selectCondition.put("regionTypeId",safeCheckRegionPageReqDTO.getRegionTypeId());
|
Page pageInfo = new Page(pageIndex, pageSize);
|
pageInfo = safeCheckBaseManagerService.listRegionByPage(pageInfo,selectCondition,currentUser);
|
return new ResultVO<>(ResultCodes.OK,pageInfo);
|
}
|
|
}
|