add feedback

plp
chenshuichuan 2 years ago
parent ee6d81f1cf
commit b08f32db4a

@ -308,3 +308,21 @@ CREATE TABLE `iot_frpc_proxy_server`
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_unicode_ci
ROW_FORMAT = DYNAMIC COMMENT ='代理服务';
CREATE TABLE `iot_feedback`
(
`id` bigint NOT NULL AUTO_INCREMENT COMMENT 'id',
`title` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_cs DEFAULT NULL COMMENT '标题',
`content` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_cs DEFAULT NULL COMMENT '内容',
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '更新者',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
`tenant_id` bigint NOT NULL DEFAULT '0' COMMENT '租户编号',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_unicode_ci
ROW_FORMAT = DYNAMIC COMMENT ='代理服务器';

@ -26,6 +26,6 @@ public interface ErrorCodeConstants {
ErrorCode MQTT_RECORD_NOT_EXISTS = new ErrorCode(1_003_000_000, "GoView 项目不存在");
ErrorCode FRPC_PROXY_SERVER_NOT_EXISTS = new ErrorCode(1_003_000_000, "GoView 项目不存在");
ErrorCode FRPS_SERVER_NOT_EXISTS = new ErrorCode(1_003_000_000, "GoView 项目不存在");
ErrorCode FEEDBACK_NOT_EXISTS = new ErrorCode(1_003_000_001, "用户反馈不存在");
}

@ -0,0 +1,95 @@
package cn.iocoder.yudao.module.iot.controller.admin.feedback;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
import cn.iocoder.yudao.module.iot.controller.admin.feedback.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.feedback.FeedbackDO;
import cn.iocoder.yudao.module.iot.service.feedback.FeedbackService;
@Tag(name = "管理后台 - 用户反馈")
@RestController
@RequestMapping("/iot/feedback")
@Validated
public class FeedbackController {
@Resource
private FeedbackService feedbackService;
@PostMapping("/create")
@Operation(summary = "创建用户反馈")
@PreAuthorize("@ss.hasPermission('iot:feedback:create')")
public CommonResult<Long> createFeedback(@Valid @RequestBody FeedbackSaveReqVO createReqVO) {
return success(feedbackService.createFeedback(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新用户反馈")
@PreAuthorize("@ss.hasPermission('iot:feedback:update')")
public CommonResult<Boolean> updateFeedback(@Valid @RequestBody FeedbackSaveReqVO updateReqVO) {
feedbackService.updateFeedback(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除用户反馈")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('iot:feedback:delete')")
public CommonResult<Boolean> deleteFeedback(@RequestParam("id") Long id) {
feedbackService.deleteFeedback(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得用户反馈")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('iot:feedback:query')")
public CommonResult<FeedbackRespVO> getFeedback(@RequestParam("id") Long id) {
FeedbackDO feedback = feedbackService.getFeedback(id);
return success(BeanUtils.toBean(feedback, FeedbackRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得用户反馈分页")
@PreAuthorize("@ss.hasPermission('iot:feedback:query')")
public CommonResult<PageResult<FeedbackRespVO>> getFeedbackPage(@Valid FeedbackPageReqVO pageReqVO) {
PageResult<FeedbackDO> pageResult = feedbackService.getFeedbackPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, FeedbackRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出用户反馈 Excel")
@PreAuthorize("@ss.hasPermission('iot:feedback:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportFeedbackExcel(@Valid FeedbackPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<FeedbackDO> list = feedbackService.getFeedbackPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "用户反馈.xls", "数据", FeedbackRespVO.class,
BeanUtils.toBean(list, FeedbackRespVO.class));
}
}

@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.iot.controller.admin.feedback.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 用户反馈分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class FeedbackPageReqVO extends PageParam {
@Schema(description = "标题")
private String title;
@Schema(description = "内容")
private String content;
@Schema(description = "标签")
private String tags;
@Schema(description = "创建者")
private String creator;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

@ -0,0 +1,38 @@
package cn.iocoder.yudao.module.iot.controller.admin.feedback.vo;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 用户反馈 Response VO")
@Data
@ExcelIgnoreUnannotated
public class FeedbackRespVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "4919")
@ExcelProperty("id")
private Long id;
@Schema(description = "标题", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("标题")
private String title;
@Schema(description = "内容")
@ExcelProperty("内容")
private String content;
@Schema(description = "标签")
@ExcelProperty("标签")
private String tags;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
@Schema(description = "创建者")
@ExcelProperty("创建者")
private String creator;
}

@ -0,0 +1,25 @@
package cn.iocoder.yudao.module.iot.controller.admin.feedback.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 用户反馈新增/修改 Request VO")
@Data
public class FeedbackSaveReqVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "4919")
private Long id;
@Schema(description = "标题", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "标题不能为空")
private String title;
@Schema(description = "内容")
private String content;
@Schema(description = "标签")
private String tags;
}

@ -0,0 +1,43 @@
package cn.iocoder.yudao.module.iot.dal.dataobject.feedback;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* DO
*
* @author
*/
@TableName("iot_feedback")
@KeySequence("iot_feedback_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class FeedbackDO extends BaseDO {
/**
* id
*/
@TableId
private Long id;
/**
*
*/
private String title;
/**
*
*/
private String content;
/**
*
*/
private String tags;
}

@ -0,0 +1,30 @@
package cn.iocoder.yudao.module.iot.dal.mysql.feedback;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.iot.dal.dataobject.feedback.FeedbackDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.iot.controller.admin.feedback.vo.*;
/**
* Mapper
*
* @author
*/
@Mapper
public interface FeedbackMapper extends BaseMapperX<FeedbackDO> {
default PageResult<FeedbackDO> selectPage(FeedbackPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<FeedbackDO>()
.eqIfPresent(FeedbackDO::getTitle, reqVO.getTitle())
.eqIfPresent(FeedbackDO::getContent, reqVO.getContent())
.eqIfPresent(FeedbackDO::getTags, reqVO.getTags())
.eqIfPresent(FeedbackDO::getCreator, reqVO.getCreator())
.betweenIfPresent(FeedbackDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(FeedbackDO::getId));
}
}

@ -0,0 +1,55 @@
package cn.iocoder.yudao.module.iot.service.feedback;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.module.iot.controller.admin.feedback.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.feedback.FeedbackDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* Service
*
* @author
*/
public interface FeedbackService {
/**
*
*
* @param createReqVO
* @return
*/
Long createFeedback(@Valid FeedbackSaveReqVO createReqVO);
/**
*
*
* @param updateReqVO
*/
void updateFeedback(@Valid FeedbackSaveReqVO updateReqVO);
/**
*
*
* @param id
*/
void deleteFeedback(Long id);
/**
*
*
* @param id
* @return
*/
FeedbackDO getFeedback(Long id);
/**
*
*
* @param pageReqVO
* @return
*/
PageResult<FeedbackDO> getFeedbackPage(FeedbackPageReqVO pageReqVO);
}

@ -0,0 +1,74 @@
package cn.iocoder.yudao.module.iot.service.feedback;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import cn.iocoder.yudao.module.iot.controller.admin.feedback.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.feedback.FeedbackDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.iot.dal.mysql.feedback.FeedbackMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
/**
* Service
*
* @author
*/
@Service
@Validated
public class FeedbackServiceImpl implements FeedbackService {
@Resource
private FeedbackMapper feedbackMapper;
@Override
public Long createFeedback(FeedbackSaveReqVO createReqVO) {
// 插入
FeedbackDO feedback = BeanUtils.toBean(createReqVO, FeedbackDO.class);
feedbackMapper.insert(feedback);
// 返回
return feedback.getId();
}
@Override
public void updateFeedback(FeedbackSaveReqVO updateReqVO) {
// 校验存在
validateFeedbackExists(updateReqVO.getId());
// 更新
FeedbackDO updateObj = BeanUtils.toBean(updateReqVO, FeedbackDO.class);
feedbackMapper.updateById(updateObj);
}
@Override
public void deleteFeedback(Long id) {
// 校验存在
validateFeedbackExists(id);
// 删除
feedbackMapper.deleteById(id);
}
private void validateFeedbackExists(Long id) {
if (feedbackMapper.selectById(id) == null) {
throw exception(FEEDBACK_NOT_EXISTS);
}
}
@Override
public FeedbackDO getFeedback(Long id) {
return feedbackMapper.selectById(id);
}
@Override
public PageResult<FeedbackDO> getFeedbackPage(FeedbackPageReqVO pageReqVO) {
return feedbackMapper.selectPage(pageReqVO);
}
}

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.iot.dal.mysql.feedback.FeedbackMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

@ -0,0 +1,146 @@
package cn.iocoder.yudao.module.iot.service.feedback;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import javax.annotation.Resource;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.iot.controller.admin.feedback.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.feedback.FeedbackDO;
import cn.iocoder.yudao.module.iot.dal.mysql.feedback.FeedbackMapper;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import javax.annotation.Resource;
import org.springframework.context.annotation.Import;
import java.util.*;
import java.time.LocalDateTime;
import static cn.hutool.core.util.RandomUtil.*;
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
/**
* {@link FeedbackServiceImpl}
*
* @author
*/
@Import(FeedbackServiceImpl.class)
public class FeedbackServiceImplTest extends BaseDbUnitTest {
@Resource
private FeedbackServiceImpl feedbackService;
@Resource
private FeedbackMapper feedbackMapper;
@Test
public void testCreateFeedback_success() {
// 准备参数
FeedbackSaveReqVO createReqVO = randomPojo(FeedbackSaveReqVO.class).setId(null);
// 调用
Long feedbackId = feedbackService.createFeedback(createReqVO);
// 断言
assertNotNull(feedbackId);
// 校验记录的属性是否正确
FeedbackDO feedback = feedbackMapper.selectById(feedbackId);
assertPojoEquals(createReqVO, feedback, "id");
}
@Test
public void testUpdateFeedback_success() {
// mock 数据
FeedbackDO dbFeedback = randomPojo(FeedbackDO.class);
feedbackMapper.insert(dbFeedback);// @Sql: 先插入出一条存在的数据
// 准备参数
FeedbackSaveReqVO updateReqVO = randomPojo(FeedbackSaveReqVO.class, o -> {
o.setId(dbFeedback.getId()); // 设置更新的 ID
});
// 调用
feedbackService.updateFeedback(updateReqVO);
// 校验是否更新正确
FeedbackDO feedback = feedbackMapper.selectById(updateReqVO.getId()); // 获取最新的
assertPojoEquals(updateReqVO, feedback);
}
@Test
public void testUpdateFeedback_notExists() {
// 准备参数
FeedbackSaveReqVO updateReqVO = randomPojo(FeedbackSaveReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> feedbackService.updateFeedback(updateReqVO), FEEDBACK_NOT_EXISTS);
}
@Test
public void testDeleteFeedback_success() {
// mock 数据
FeedbackDO dbFeedback = randomPojo(FeedbackDO.class);
feedbackMapper.insert(dbFeedback);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbFeedback.getId();
// 调用
feedbackService.deleteFeedback(id);
// 校验数据不存在了
assertNull(feedbackMapper.selectById(id));
}
@Test
public void testDeleteFeedback_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> feedbackService.deleteFeedback(id), FEEDBACK_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetFeedbackPage() {
// mock 数据
FeedbackDO dbFeedback = randomPojo(FeedbackDO.class, o -> { // 等会查询到
o.setTitle(null);
o.setContent(null);
o.setTags(null);
o.setCreator(null);
o.setCreateTime(null);
});
feedbackMapper.insert(dbFeedback);
// 测试 title 不匹配
feedbackMapper.insert(cloneIgnoreId(dbFeedback, o -> o.setTitle(null)));
// 测试 content 不匹配
feedbackMapper.insert(cloneIgnoreId(dbFeedback, o -> o.setContent(null)));
// 测试 tags 不匹配
feedbackMapper.insert(cloneIgnoreId(dbFeedback, o -> o.setTags(null)));
// 测试 creator 不匹配
feedbackMapper.insert(cloneIgnoreId(dbFeedback, o -> o.setCreator(null)));
// 测试 createTime 不匹配
feedbackMapper.insert(cloneIgnoreId(dbFeedback, o -> o.setCreateTime(null)));
// 准备参数
FeedbackPageReqVO reqVO = new FeedbackPageReqVO();
reqVO.setTitle(null);
reqVO.setContent(null);
reqVO.setTags(null);
reqVO.setCreator(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
PageResult<FeedbackDO> pageResult = feedbackService.getFeedbackPage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbFeedback, pageResult.getList().get(0));
}
}

@ -29,4 +29,8 @@ DELETE FROM "iot_mqtt_record";
DELETE FROM "iot_frps_server";
-- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里
DELETE FROM "iot_frpc_proxy_server";
DELETE FROM "iot_frpc_proxy_server";
-- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里
DELETE FROM "iot_feedback";

@ -249,7 +249,7 @@ CREATE TABLE IF NOT EXISTS "iot_frps_server"
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint ,
"tenant_id" bigint,
PRIMARY KEY ("id")
) COMMENT '代理服务器';
CREATE TABLE IF NOT EXISTS "iot_frpc_proxy_server"
@ -276,3 +276,17 @@ CREATE TABLE IF NOT EXISTS "iot_frpc_proxy_server"
) COMMENT '代理服务';
CREATE TABLE IF NOT EXISTS "iot_feedback"
(
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"title" varchar NOT NULL,
"content" varchar,
"tags" varchar,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint NOT NULL,
PRIMARY KEY ("id")
) COMMENT '用户反馈';

Loading…
Cancel
Save