|
@@ -10,7 +10,9 @@ package com.kioor.room.controller;
|
|
|
|
|
|
|
|
|
import com.kioor.annotation.Login;
|
|
|
+import com.kioor.annotation.LoginUser;
|
|
|
import com.kioor.common.constant.Constant;
|
|
|
+import com.kioor.common.exception.ErrorCode;
|
|
|
import com.kioor.common.page.PageData;
|
|
|
import com.kioor.common.utils.Result;
|
|
|
import com.kioor.common.validator.AssertUtils;
|
|
@@ -20,7 +22,9 @@ import com.kioor.common.validator.group.DefaultGroup;
|
|
|
import com.kioor.common.validator.group.UpdateGroup;
|
|
|
import com.kioor.room.dto.HousingEstateDTO;
|
|
|
import com.kioor.room.dto.BuildingInitDTO;
|
|
|
+import com.kioor.room.enums.HousingEstateStatus;
|
|
|
import com.kioor.room.service.HousingEstateService;
|
|
|
+import com.kioor.user.entity.UserEntity;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
import io.swagger.v3.oas.annotations.Parameters;
|
|
@@ -54,9 +58,12 @@ public class ApiHousingEstateController {
|
|
|
@Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true),
|
|
|
@Parameter(name = Constant.ORDER_FIELD, description = "排序字段"),
|
|
|
@Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)"),
|
|
|
+ @Parameter(name = "status", description = "小区状态:0待审核,1审核通过,2审核不通过,3禁用"),
|
|
|
@Parameter(name = "name", description = "名称")
|
|
|
})
|
|
|
public Result<PageData<HousingEstateDTO>> page(@Parameter(hidden = true) @RequestParam Map<String, Object> params) {
|
|
|
+ //如果状态为空则查询已审核通过的小区
|
|
|
+// params.putIfAbsent("status", 1);
|
|
|
PageData<HousingEstateDTO> page = housingEstateService.page(params);
|
|
|
|
|
|
return new Result<PageData<HousingEstateDTO>>().ok(page);
|
|
@@ -77,6 +84,7 @@ public class ApiHousingEstateController {
|
|
|
public Result save(@RequestBody HousingEstateDTO dto, @Parameter(hidden = true) @RequestAttribute("userId") Long userId) {
|
|
|
//效验数据
|
|
|
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
|
|
|
+ dto.setStatus(0);
|
|
|
dto.setCreateUser(userId);
|
|
|
dto.setCreateDate(new Date());
|
|
|
housingEstateService.save(dto);
|
|
@@ -108,6 +116,30 @@ public class ApiHousingEstateController {
|
|
|
return new Result();
|
|
|
}
|
|
|
|
|
|
+ @Login
|
|
|
+ @PutMapping("examine")
|
|
|
+ @Operation(summary = "审核小区")
|
|
|
+ @Parameters({
|
|
|
+ @Parameter(name = "housingEstateId", description = "小区id", required = true),
|
|
|
+ @Parameter(name = "status", description = "小区状态:0待审核,1审核通过,2审核不通过,3禁用", required = true)
|
|
|
+ })
|
|
|
+ public Result examine(@Parameter(hidden = true) @RequestParam Map<String, Object> params, @LoginUser UserEntity user) {
|
|
|
+ //效验登录用户是否是管理员
|
|
|
+ if(!user.getMobile().equals("18582543217")){
|
|
|
+ return new Result().error(ErrorCode.INTERNAL_SERVER_ERROR,"非法操作,请联系管理员审核");
|
|
|
+ }
|
|
|
+ if(params.get("housingEstateId")==null||params.get("status")==null){
|
|
|
+ return new Result().error(ErrorCode.INTERNAL_SERVER_ERROR,"参数非法");
|
|
|
+ }
|
|
|
+ HousingEstateDTO housingEstate = housingEstateService.get(Long.parseLong(String.valueOf(params.get("housingEstateId"))));
|
|
|
+ if(housingEstate==null){
|
|
|
+ return new Result().error(ErrorCode.INTERNAL_SERVER_ERROR,"小区不存在");
|
|
|
+ }
|
|
|
+ housingEstate.setStatus(Integer.parseInt(String.valueOf(params.get("status"))));
|
|
|
+ housingEstateService.update(housingEstate);
|
|
|
+
|
|
|
+ return new Result();
|
|
|
+ }
|
|
|
|
|
|
@Login
|
|
|
@PostMapping("housingEstateInit")
|
|
@@ -115,14 +147,34 @@ public class ApiHousingEstateController {
|
|
|
public Result housingEstateInit(@RequestBody List<BuildingInitDTO> buildingInitDTOList, @Parameter(hidden = true) @RequestAttribute("userId") Long userId) {
|
|
|
//效验数据
|
|
|
ValidatorUtils.validateEntity(buildingInitDTOList, AddGroup.class, DefaultGroup.class);
|
|
|
-
|
|
|
+ //校验是否是同一小区的楼栋
|
|
|
+ if(!housingEstateService.checkBuildingList(buildingInitDTOList)){
|
|
|
+ return new Result().error(ErrorCode.INTERNAL_SERVER_ERROR,"参数非法,不是同一小区的数据");
|
|
|
+ }
|
|
|
+ //校验小区状态
|
|
|
+ if(!buildingInitDTOList.isEmpty()){
|
|
|
+ int status = housingEstateService.checkStatus(buildingInitDTOList.get(0).getHousingEstateId());
|
|
|
+ if(status!=1) {
|
|
|
+ return new Result().error(ErrorCode.INTERNAL_SERVER_ERROR, "无法访问,小区当前状态为" + HousingEstateStatus.fromCode(status).getDescription());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //校验小区创建者和初始化的人是否是同一人
|
|
|
+ if(!housingEstateService.checkCreateUser(buildingInitDTOList.get(0).getHousingEstateId(),userId)){
|
|
|
+ return new Result().error(ErrorCode.INTERNAL_SERVER_ERROR,"操作非法,该小区并非你创建");
|
|
|
+ }
|
|
|
+ //校验小区是否已被初始化,如果已被初始化则不允许操作
|
|
|
+ if(!housingEstateService.checkInit(buildingInitDTOList.get(0).getHousingEstateId())){
|
|
|
+ return new Result().error(ErrorCode.INTERNAL_SERVER_ERROR,"操作非法,小区已有数据,请联系管理员重置");
|
|
|
+ }
|
|
|
//先清空房号
|
|
|
- if(buildingInitDTOList.size() > 0){
|
|
|
+ if(!buildingInitDTOList.isEmpty()){
|
|
|
buildingInitDTOList.forEach(buildingInitDTO -> {
|
|
|
housingEstateService.cleanAll(buildingInitDTO.getHousingEstateId());
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
+ //更新小区初始化状态为1
|
|
|
+ housingEstateService.updateInitFlag(buildingInitDTOList.get(0).getHousingEstateId(),1);
|
|
|
+ //初始化小区信息
|
|
|
housingEstateService.buildingInit(buildingInitDTOList);
|
|
|
|
|
|
return new Result();
|