|
@@ -0,0 +1,120 @@
|
|
|
+/**
|
|
|
+ * Copyright (c) 2018 业主系统 All rights reserved.
|
|
|
+ * <p>
|
|
|
+ * https://www.yezhu.io
|
|
|
+ * <p>
|
|
|
+ * 版权所有,侵权必究!
|
|
|
+ */
|
|
|
+
|
|
|
+package com.kioor.messageboard.controller;
|
|
|
+
|
|
|
+
|
|
|
+import com.kioor.annotation.Login;
|
|
|
+import com.kioor.common.exception.ErrorCode;
|
|
|
+import com.kioor.common.utils.Result;
|
|
|
+import com.kioor.common.validator.AssertUtils;
|
|
|
+import com.kioor.common.validator.ValidatorUtils;
|
|
|
+import com.kioor.common.validator.group.AddGroup;
|
|
|
+import com.kioor.common.validator.group.DefaultGroup;
|
|
|
+import com.kioor.common.validator.group.UpdateGroup;
|
|
|
+import com.kioor.messageboard.dto.MessageBoardDTO;
|
|
|
+import com.kioor.messageboard.service.MessageBoardService;
|
|
|
+import com.kioor.room.enums.HousingEstateStatus;
|
|
|
+import com.kioor.room.service.HousingEstateService;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.Parameter;
|
|
|
+import io.swagger.v3.oas.annotations.Parameters;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 留言板
|
|
|
+ *
|
|
|
+ * @author Mark sunlightcs@gmail.com
|
|
|
+ */
|
|
|
+@AllArgsConstructor
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/messageboard")
|
|
|
+@Tag(name = "留言板")
|
|
|
+public class ApiMessageBoardController {
|
|
|
+
|
|
|
+ private final MessageBoardService messageBoardService;
|
|
|
+
|
|
|
+ private final HousingEstateService housingEstateService;
|
|
|
+
|
|
|
+ @Login
|
|
|
+ @GetMapping("infoByHousingEstate")
|
|
|
+ @Operation(summary = "根据小区查看留言板详情")
|
|
|
+ @Parameters({
|
|
|
+ @Parameter(name = "housingEstateId", description = "小区id",required = true)
|
|
|
+ })
|
|
|
+ public Result<MessageBoardDTO> infoByHousingEstate(@Parameter(hidden = true) @RequestParam Map<String, Object> params) {
|
|
|
+ if(params.get("housingEstateId") == null){
|
|
|
+ return new Result().error("小区不能为空");
|
|
|
+ }
|
|
|
+ int status = housingEstateService.checkStatus((Long) params.get("housingEstateId"));
|
|
|
+ if(status!=1) {
|
|
|
+ return new Result().error(ErrorCode.INTERNAL_SERVER_ERROR, "无法访问,小区当前状态为" + HousingEstateStatus.fromCode(status).getDescription());
|
|
|
+ }
|
|
|
+ MessageBoardDTO dto = messageBoardService.infoByHousingEstate((Long) params.get("housingEstateId"));
|
|
|
+
|
|
|
+ return new Result<MessageBoardDTO>().ok(dto);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Login
|
|
|
+ @Operation(summary = "信息")
|
|
|
+ @GetMapping("{id}")
|
|
|
+ public Result<MessageBoardDTO> info(@PathVariable("id") Long id) {
|
|
|
+ MessageBoardDTO messageBoardDTO = messageBoardService.get(id);
|
|
|
+ //校验小区状态
|
|
|
+ if(messageBoardDTO!=null){
|
|
|
+ int status = housingEstateService.checkStatus(messageBoardDTO.getHousingEstateId());
|
|
|
+ if(status!=1) {
|
|
|
+ return new Result().error(ErrorCode.INTERNAL_SERVER_ERROR, "无法访问,小区当前状态为" + HousingEstateStatus.fromCode(status).getDescription());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new Result<MessageBoardDTO>().ok(messageBoardDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Login
|
|
|
+ @PostMapping
|
|
|
+ @Operation(summary = "保存")
|
|
|
+ public Result save(@RequestBody MessageBoardDTO dto, @Parameter(hidden = true) @RequestAttribute("userId") Long userId) {
|
|
|
+ //效验数据
|
|
|
+ ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
|
|
|
+
|
|
|
+ messageBoardService.save(dto);
|
|
|
+
|
|
|
+ return new Result();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Login
|
|
|
+ @PutMapping
|
|
|
+ @Operation(summary = "修改")
|
|
|
+ public Result update(@RequestBody MessageBoardDTO dto, @Parameter(hidden = true) @RequestAttribute("userId") Long userId) {
|
|
|
+ //效验数据
|
|
|
+ ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
|
|
|
+
|
|
|
+ messageBoardService.update(dto);
|
|
|
+
|
|
|
+ return new Result();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Login
|
|
|
+ @DeleteMapping
|
|
|
+ @Operation(summary = "删除")
|
|
|
+ public Result delete(@RequestBody Long[] ids) {
|
|
|
+ //效验数据
|
|
|
+ AssertUtils.isArrayEmpty(ids, "id");
|
|
|
+
|
|
|
+ messageBoardService.deleteBatchIds(Arrays.asList(ids));
|
|
|
+
|
|
|
+ return new Result();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|