|
@@ -1,10 +1,15 @@
|
|
|
package cn.cslg.report.controller;
|
|
|
|
|
|
import cn.cslg.report.common.core.base.Constants;
|
|
|
+import cn.cslg.report.common.utils.Response;
|
|
|
+import cn.cslg.report.entity.Report;
|
|
|
+import cn.cslg.report.service.business.ReportService;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
@Tag(name = "报告管理")
|
|
@@ -12,4 +17,40 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
@RequestMapping(Constants.REPORT_API + "/report")
|
|
|
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
|
public class ReportController {
|
|
|
+ private final ReportService reportService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param report 报告类
|
|
|
+ * @author 沈永艺
|
|
|
+ * @date 2022-11-4
|
|
|
+ * @see ReportService
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/addReport", method = RequestMethod.POST)
|
|
|
+ @Operation(summary = "新增报告")
|
|
|
+ public String addReport(Report report) {
|
|
|
+ // TODO: 2022/11/4 关于错误提示与对应的错误码还需要制定 避免前台看到失败字样 用网络异常来代替说明
|
|
|
+ // 目前的错误说明有
|
|
|
+ // 添加成功 是正常添加成功
|
|
|
+ // 网络异常,添加失败 是数据库的操作或返回的数据有问题但没抛出异常
|
|
|
+ // 请求失败 是Service抛出了异常
|
|
|
+ // 服务器无响应 是未知情况 需要重点查看
|
|
|
+ // 网络异常 是传入参数出现了问题
|
|
|
+ // 以上的说明可以参考或者改变,按照实际情况使用,另外这些说明我没有设置CODE码,建议加上
|
|
|
+
|
|
|
+ if (report != null) {
|
|
|
+ Integer flag = reportService.addReport(report);
|
|
|
+ switch (flag) {
|
|
|
+ case 1:
|
|
|
+ return Response.success("添加成功");
|
|
|
+ case 0:
|
|
|
+ return Response.error("网络异常,添加失败");
|
|
|
+ case -1:
|
|
|
+ return Response.error("请求失败");
|
|
|
+ default:
|
|
|
+ return Response.error("服务器无响应");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return Response.error("网络异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|