|
@@ -0,0 +1,140 @@
|
|
|
|
+/**
|
|
|
|
+ * Copyright (c) 2018 业主系统 All rights reserved.
|
|
|
|
+ * <p>
|
|
|
|
+ * https://www.yezhu.io
|
|
|
|
+ * <p>
|
|
|
|
+ * 版权所有,侵权必究!
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+package com.kioor.message.controller;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+import com.kioor.annotation.Login;
|
|
|
|
+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;
|
|
|
|
+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.MessageDTO;
|
|
|
|
+import com.kioor.messageboard.service.MessageService;
|
|
|
|
+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.Date;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 留言
|
|
|
|
+ *
|
|
|
|
+ * @author Mark sunlightcs@gmail.com
|
|
|
|
+ */
|
|
|
|
+@AllArgsConstructor
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/api/message")
|
|
|
|
+@Tag(name = "留言")
|
|
|
|
+public class ApiMessageController {
|
|
|
|
+
|
|
|
|
+ private final MessageService messageService;
|
|
|
|
+
|
|
|
|
+ private final HousingEstateService housingEstateService;
|
|
|
|
+
|
|
|
|
+ @Login
|
|
|
|
+ @GetMapping("page")
|
|
|
|
+ @Operation(summary = "分页")
|
|
|
|
+ @Parameters({
|
|
|
|
+ @Parameter(name = Constant.PAGE, description = "当前页码,从1开始", required = true),
|
|
|
|
+ @Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true),
|
|
|
|
+ @Parameter(name = Constant.ORDER_FIELD, description = "排序字段"),
|
|
|
|
+ @Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)"),
|
|
|
|
+ @Parameter(name = "housingEstateId", description = "小区id"),
|
|
|
|
+ @Parameter(name = "Id", description = "留言板id")
|
|
|
|
+ })
|
|
|
|
+ public Result<PageData<MessageDTO>> page(@Parameter(hidden = true) @RequestParam Map<String, Object> params) {
|
|
|
|
+ //小区和留言板id不能同时为空
|
|
|
|
+ if(params.get("housingEstateId") == null && params.get("Id") == null){
|
|
|
|
+ return new Result().error(ErrorCode.NOT_NULL,"小区和留言板不能同时为空");
|
|
|
|
+ }
|
|
|
|
+ PageData<MessageDTO> page = messageService.page(params);
|
|
|
|
+ //校验小区状态
|
|
|
|
+ if(page.getList()!=null && !page.getList().isEmpty()){
|
|
|
|
+ int status = housingEstateService.checkStatus(page.getList().get(0).getHousingEstateId());
|
|
|
|
+ if(status!=1) {
|
|
|
|
+ return new Result().error(ErrorCode.INTERNAL_SERVER_ERROR, "无法访问,小区当前状态为" + HousingEstateStatus.fromCode(status).getDescription());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return new Result<PageData<MessageDTO>>().ok(page);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Login
|
|
|
|
+ @Operation(summary = "信息")
|
|
|
|
+ @GetMapping("{id}")
|
|
|
|
+ public Result<MessageDTO> info(@PathVariable("id") Long id) {
|
|
|
|
+ MessageDTO messageDTO = messageService.get(id);
|
|
|
|
+ //校验小区状态
|
|
|
|
+ if(messageDTO!=null){
|
|
|
|
+ int status = housingEstateService.checkStatus(messageDTO.getHousingEstateId());
|
|
|
|
+ if(status!=1) {
|
|
|
|
+ return new Result().error(ErrorCode.INTERNAL_SERVER_ERROR, "无法访问,小区当前状态为" + HousingEstateStatus.fromCode(status).getDescription());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return new Result<MessageDTO>().ok(messageDTO);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Login
|
|
|
|
+ @PostMapping
|
|
|
|
+ @Operation(summary = "保存")
|
|
|
|
+ public Result save(@RequestBody MessageDTO dto, @Parameter(hidden = true) @RequestAttribute("userId") Long userId) {
|
|
|
|
+ //效验数据
|
|
|
|
+ ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
|
|
|
|
+ dto.setEditUser(userId);
|
|
|
|
+ dto.setEditTime(new Date());
|
|
|
|
+ if(dto.getShowNameFlag()==null){
|
|
|
|
+ dto.setShowNameFlag(1);
|
|
|
|
+ }
|
|
|
|
+ if(dto.getShowRoomFlag()==null){
|
|
|
|
+ dto.setShowRoomFlag(1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ messageService.save(dto);
|
|
|
|
+
|
|
|
|
+ return new Result();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Login
|
|
|
|
+ @PutMapping
|
|
|
|
+ @Operation(summary = "修改")
|
|
|
|
+ public Result update(@RequestBody MessageDTO dto, @Parameter(hidden = true) @RequestAttribute("userId") Long userId) {
|
|
|
|
+ //效验数据
|
|
|
|
+ ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
|
|
|
|
+
|
|
|
|
+ messageService.update(dto);
|
|
|
|
+
|
|
|
|
+ return new Result();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Login
|
|
|
|
+ @DeleteMapping
|
|
|
|
+ @Operation(summary = "删除")
|
|
|
|
+ public Result delete(@RequestBody Long[] ids) {
|
|
|
|
+ //效验数据
|
|
|
|
+ AssertUtils.isArrayEmpty(ids, "id");
|
|
|
|
+
|
|
|
|
+ messageService.deleteBatchIds(Arrays.asList(ids));
|
|
|
|
+
|
|
|
|
+ return new Result();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|