diff --git a/pom.xml b/pom.xml index 7e2906e..ee743cd 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,8 @@ yudao-module-infra yudao-module-bpm - + yudao-module-home + diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/onlyoffice/MvcConfiguration.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/onlyoffice/MvcConfiguration.java index 73a7a38..81a4e83 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/onlyoffice/MvcConfiguration.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/onlyoffice/MvcConfiguration.java @@ -26,7 +26,7 @@ public class MvcConfiguration implements WebMvcConfigurer { if (thymeleafViewResolver != null) { Map vars = new HashMap<>(8); vars.put("documentServerApiJs", documentServerHost+documentServerApiJs); - System.out.println("documentServerApiJs"+ String.format(documentServerApiJs, documentServerHost)); +// System.out.println("documentServerApiJs"+ String.format(documentServerApiJs, documentServerHost)); // System.out.println( String.format(documentServerApiJs, documentServerHost)); // 静态参数,只取一次值 thymeleafViewResolver.setStaticVariables(vars); diff --git a/yudao-module-home/pom.xml b/yudao-module-home/pom.xml new file mode 100644 index 0000000..7b703b5 --- /dev/null +++ b/yudao-module-home/pom.xml @@ -0,0 +1,23 @@ + + + 4.0.0 + + cn.iocoder.boot + yudao + ${revision} + + + yudao-module-home + pom + + ${project.artifactId} + + home模块,主要用于首页的功能,例如数据收集,项目管理,数据表数据 + + + yudao-module-home-api + yudao-module-home-biz + + diff --git a/yudao-module-home/yudao-module-home-api/pom.xml b/yudao-module-home/yudao-module-home-api/pom.xml new file mode 100644 index 0000000..9504496 --- /dev/null +++ b/yudao-module-home/yudao-module-home-api/pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + + cn.iocoder.boot + yudao-module-home + ${revision} + + + yudao-module-home-api + jar + + + ${project.artifactId} + + api模块,主要用于首页的功能,例如数据收集,项目管理,数据表数据 + + + + + cn.iocoder.boot + yudao-common + + + + diff --git a/yudao-module-home/yudao-module-home-api/src/main/java/cn/iocoder/yudao/module/home/enums/ErrorCodeConstants.java b/yudao-module-home/yudao-module-home-api/src/main/java/cn/iocoder/yudao/module/home/enums/ErrorCodeConstants.java new file mode 100644 index 0000000..df069e2 --- /dev/null +++ b/yudao-module-home/yudao-module-home-api/src/main/java/cn/iocoder/yudao/module/home/enums/ErrorCodeConstants.java @@ -0,0 +1,15 @@ +package cn.iocoder.yudao.module.home.enums; + +import cn.iocoder.yudao.framework.common.exception.ErrorCode; + +/** + * Bpm 错误码枚举类 + *

+ * bpm 系统,使用 1-009-000-000 段 + */ +public interface ErrorCodeConstants { + // ========== 首页数据统计 1_009_020_000 ========== + ErrorCode DATA_INFO_NOT_EXISTS = new ErrorCode(1_009_001_000, "首页数据统计不存在"); + // ========== 主要用于首页的项目数据 1_009_002_000 ========== + ErrorCode PJ_NOT_EXISTS = new ErrorCode(1_009_002_000, "主要用于首页的项目数据不存在"); +} diff --git a/yudao-module-home/yudao-module-home-biz/pom.xml b/yudao-module-home/yudao-module-home-biz/pom.xml new file mode 100644 index 0000000..6a1e34d --- /dev/null +++ b/yudao-module-home/yudao-module-home-biz/pom.xml @@ -0,0 +1,69 @@ + + + 4.0.0 + + cn.iocoder.boot + yudao-module-home + ${revision} + + + yudao-module-home-biz + jar + + ${project.artifactId} + + biz模块,主要用于首页的功能,例如数据收集,项目管理,数据表数据 + + + + + cn.iocoder.boot + yudao-module-bpm-api + ${revision} + + + + cn.iocoder.boot + yudao-spring-boot-starter-web + + + + cn.iocoder.boot + yudao-spring-boot-starter-security + + + + cn.iocoder.boot + yudao-spring-boot-starter-mybatis + + + + cn.iocoder.boot + yudao-spring-boot-starter-test + + + cn.iocoder.boot + yudao-module-home-api + 2.1.0-jdk8-snapshot + test + + + com.alibaba + easyexcel-core + 3.3.4 + compile + + + cn.iocoder.boot + yudao-spring-boot-starter-excel + + + cn.iocoder.boot + yudao-module-home-api + 2.1.0-jdk8-snapshot + compile + + + diff --git a/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/controller/admin/datainfo/DataInfoController.java b/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/controller/admin/datainfo/DataInfoController.java new file mode 100644 index 0000000..50d29a0 --- /dev/null +++ b/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/controller/admin/datainfo/DataInfoController.java @@ -0,0 +1,95 @@ +package cn.iocoder.yudao.module.home.controller.admin.datainfo; + +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.home.controller.admin.datainfo.vo.*; +import cn.iocoder.yudao.module.home.dal.dataobject.datainfo.DataInfoDO; +import cn.iocoder.yudao.module.home.service.datainfo.DataInfoService; + +@Tag(name = "管理后台 - 首页数据统计") +@RestController +@RequestMapping("/home/data-info") +@Validated +public class DataInfoController { + + @Resource + private DataInfoService dataInfoService; + + @PostMapping("/create") + @Operation(summary = "创建首页数据统计") + @PreAuthorize("@ss.hasPermission('home:data-info:create')") + public CommonResult createDataInfo(@Valid @RequestBody DataInfoSaveReqVO createReqVO) { + return success(dataInfoService.createDataInfo(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新首页数据统计") + @PreAuthorize("@ss.hasPermission('home:data-info:update')") + public CommonResult updateDataInfo(@Valid @RequestBody DataInfoSaveReqVO updateReqVO) { + dataInfoService.updateDataInfo(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除首页数据统计") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('home:data-info:delete')") + public CommonResult deleteDataInfo(@RequestParam("id") Long id) { + dataInfoService.deleteDataInfo(id); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得首页数据统计") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('home:data-info:query')") + public CommonResult getDataInfo(@RequestParam("id") Long id) { + DataInfoDO dataInfo = dataInfoService.getDataInfo(id); + return success(BeanUtils.toBean(dataInfo, DataInfoRespVO.class)); + } + + @GetMapping("/page") + @Operation(summary = "获得首页数据统计分页") + @PreAuthorize("@ss.hasPermission('home:data-info:query')") + public CommonResult> getDataInfoPage(@Valid DataInfoPageReqVO pageReqVO) { + PageResult pageResult = dataInfoService.getDataInfoPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, DataInfoRespVO.class)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出首页数据统计 Excel") + @PreAuthorize("@ss.hasPermission('home:data-info:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportDataInfoExcel(@Valid DataInfoPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = dataInfoService.getDataInfoPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "首页数据统计.xls", "数据", DataInfoRespVO.class, + BeanUtils.toBean(list, DataInfoRespVO.class)); + } + +} diff --git a/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/controller/admin/datainfo/vo/DataInfoPageReqVO.java b/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/controller/admin/datainfo/vo/DataInfoPageReqVO.java new file mode 100644 index 0000000..c3822ca --- /dev/null +++ b/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/controller/admin/datainfo/vo/DataInfoPageReqVO.java @@ -0,0 +1,54 @@ +package cn.iocoder.yudao.module.home.controller.admin.datainfo.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 DataInfoPageReqVO extends PageParam { + @Schema(description = "id") + private Long Id; + + @Schema(description = "数据收集时间") + private LocalDateTime infoYear; + + @Schema(description = "碳排放总量") + private Integer infoCo2e; + + @Schema(description = "总用水量") + private Integer infoWater; + + @Schema(description = "污染物总量") + private Integer infoPollution; + + @Schema(description = "环保投入") + private Integer infoEcom; + + @Schema(description = "员工培训费用") + private Integer infoTraining; + + @Schema(description = "研发费用") + private Integer infoRd; + + @Schema(description = "环境评分") + private Integer infoEnvironment; + + @Schema(description = "社会评分") + private Integer infoSociety; + + @Schema(description = "治理评分") + private Integer infoGovern; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} diff --git a/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/controller/admin/datainfo/vo/DataInfoRespVO.java b/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/controller/admin/datainfo/vo/DataInfoRespVO.java new file mode 100644 index 0000000..87d8dd6 --- /dev/null +++ b/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/controller/admin/datainfo/vo/DataInfoRespVO.java @@ -0,0 +1,63 @@ +package cn.iocoder.yudao.module.home.controller.admin.datainfo.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; +import com.alibaba.excel.annotation.*; + +@Schema(description = "管理后台 - 首页数据统计 Response VO") +@Data +@ExcelIgnoreUnannotated +public class DataInfoRespVO { + + @Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("id") + private Long Id; + + @Schema(description = "数据收集时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("数据收集时间") + private LocalDateTime infoYear; + + @Schema(description = "碳排放总量", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("碳排放总量") + private Integer infoCo2e; + + @Schema(description = "总用水量", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("总用水量") + private Integer infoWater; + + @Schema(description = "污染物总量", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("污染物总量") + private Integer infoPollution; + + @Schema(description = "环保投入", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("环保投入") + private Integer infoEcom; + + @Schema(description = "员工培训费用", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("员工培训费用") + private Integer infoTraining; + + @Schema(description = "研发费用", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("研发费用") + private Integer infoRd; + + @Schema(description = "环境评分", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("环境评分") + private Integer infoEnvironment; + + @Schema(description = "社会评分", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("社会评分") + private Integer infoSociety; + + @Schema(description = "治理评分", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("治理评分") + private Integer infoGovern; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + private LocalDateTime createTime; + +} diff --git a/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/controller/admin/datainfo/vo/DataInfoSaveReqVO.java b/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/controller/admin/datainfo/vo/DataInfoSaveReqVO.java new file mode 100644 index 0000000..1aaf459 --- /dev/null +++ b/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/controller/admin/datainfo/vo/DataInfoSaveReqVO.java @@ -0,0 +1,82 @@ +package cn.iocoder.yudao.module.home.controller.admin.datainfo.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import javax.validation.constraints.*; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - 首页数据统计新增/修改 Request VO") +@Data +public class DataInfoSaveReqVO { + + @Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED) +// @NotNull(message = "id不能为空") + private Long Id; + + @Schema(description = "数据收集时间", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "数据收集时间不能为空") + private LocalDateTime infoYear; + + @Schema(description = "碳排放总量", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "碳排放总量不能为空") + private Integer infoCo2e; + + @Schema(description = "总用水量", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "总用水量不能为空") + private Integer infoWater; + + @Schema(description = "废弃物总量") + private Integer infoCastoff; + + @Schema(description = "能源使用总量") + private Integer infoCoai; + + @Schema(description = "污染物总量", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "污染物总量不能为空") + private Integer infoPollution; + + @Schema(description = "环保投入", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "环保投入不能为空") + private Integer infoEcom; + + @Schema(description = "员工总数") + private Integer infoStaff; + + @Schema(description = "员工培训费用", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "员工培训费用不能为空") + private Integer infoTraining; + + @Schema(description = "研发费用", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "研发费用不能为空") + private Integer infoRd; + + @Schema(description = "公益投入金额") + private Integer infoProbono; + + @Schema(description = "社会保险覆盖率") + private Integer infoInsurance; + + @Schema(description = "违规经营次数") + private Integer infoViolate; + + @Schema(description = "对外担保金额") + private Integer infoGuarantee; + + @Schema(description = "现金分红总额") + private Long infoMoney; + + @Schema(description = "环境评分", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "环境评分不能为空") + private Integer infoEnvironment; + + @Schema(description = "社会评分", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "社会评分不能为空") + private Integer infoSociety; + + @Schema(description = "治理评分", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "治理评分不能为空") + private Integer infoGovern; + +} diff --git a/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/controller/app/AppDemoTestController.java b/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/controller/app/AppDemoTestController.java new file mode 100644 index 0000000..632d7b7 --- /dev/null +++ b/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/controller/app/AppDemoTestController.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.home.controller.app; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Api(tags = "用户 App - Test") +@RestController +@RequestMapping("/demo/test") +@Validated +public class AppDemoTestController { + + @GetMapping("/get") + @ApiOperation("获取 test 信息") + public CommonResult get() { + return CommonResult.success("true22"); + } +} diff --git a/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/dal/dataobject/datainfo/DataInfoDO.java b/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/dal/dataobject/datainfo/DataInfoDO.java new file mode 100644 index 0000000..d78fa7e --- /dev/null +++ b/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/dal/dataobject/datainfo/DataInfoDO.java @@ -0,0 +1,104 @@ +package cn.iocoder.yudao.module.home.dal.dataobject.datainfo; + +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +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("des_datainfo") +@KeySequence("des_datainfo_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DataInfoDO extends BaseDO { + + /** + * 数据id + */ + @TableId + private Long Id; + /** + * 数据收集时间 + */ + private LocalDateTime infoYear; + /** + * 碳排放总量 + */ + private Integer infoCo2e; + /** + * 总用水量 + */ + private Integer infoWater; + /** + * 废弃物总量 + */ + private Integer infoCastoff; + /** + * 能源使用总量 + */ + private Integer infoCoai; + /** + * 污染物总量 + */ + private Integer infoPollution; + /** + * 环保投入 + */ + private Integer infoEcom; + /** + * 员工总数 + */ + private Integer infoStaff; + /** + * 员工培训费用 + */ + private Integer infoTraining; + /** + * 研发费用 + */ + private Integer infoRd; + /** + * 公益投入金额 + */ + private Integer infoProbono; + /** + * 社会保险覆盖率 + */ + private Integer infoInsurance; + /** + * 违规经营次数 + */ + private Integer infoViolate; + /** + * 对外担保金额 + */ + private Integer infoGuarantee; + /** + * 现金分红总额 + */ + private Long infoMoney; + /** + * 环境评分 + */ + private Integer infoEnvironment; + /** + * 社会评分 + */ + private Integer infoSociety; + /** + * 治理评分 + */ + private Integer infoGovern; + +} diff --git a/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/dal/mysql/datainfo/DataInfoMapper.java b/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/dal/mysql/datainfo/DataInfoMapper.java new file mode 100644 index 0000000..702260d --- /dev/null +++ b/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/dal/mysql/datainfo/DataInfoMapper.java @@ -0,0 +1,37 @@ +package cn.iocoder.yudao.module.home.dal.mysql.datainfo; + +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.home.dal.dataobject.datainfo.DataInfoDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.home.controller.admin.datainfo.vo.*; + +/** + * 首页数据统计 Mapper + * + * @author 君风 + */ +@Mapper +public interface DataInfoMapper extends BaseMapperX { + + default PageResult selectPage(DataInfoPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(DataInfoDO::getId, reqVO.getId()) + .eqIfPresent(DataInfoDO::getInfoYear, reqVO.getInfoYear()) + .eqIfPresent(DataInfoDO::getInfoCo2e, reqVO.getInfoCo2e()) + .eqIfPresent(DataInfoDO::getInfoWater, reqVO.getInfoWater()) + .eqIfPresent(DataInfoDO::getInfoPollution, reqVO.getInfoPollution()) + .eqIfPresent(DataInfoDO::getInfoEcom, reqVO.getInfoEcom()) + .eqIfPresent(DataInfoDO::getInfoTraining, reqVO.getInfoTraining()) + .eqIfPresent(DataInfoDO::getInfoRd, reqVO.getInfoRd()) + .eqIfPresent(DataInfoDO::getInfoEnvironment, reqVO.getInfoEnvironment()) + .eqIfPresent(DataInfoDO::getInfoSociety, reqVO.getInfoSociety()) + .eqIfPresent(DataInfoDO::getInfoGovern, reqVO.getInfoGovern()) + .betweenIfPresent(DataInfoDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(DataInfoDO::getId)); + } + +} diff --git a/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/service/datainfo/DataInfoService.java b/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/service/datainfo/DataInfoService.java new file mode 100644 index 0000000..162c03d --- /dev/null +++ b/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/service/datainfo/DataInfoService.java @@ -0,0 +1,55 @@ +package cn.iocoder.yudao.module.home.service.datainfo; + +import java.util.*; +import javax.validation.*; +import cn.iocoder.yudao.module.home.controller.admin.datainfo.vo.*; +import cn.iocoder.yudao.module.home.dal.dataobject.datainfo.DataInfoDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; + +/** + * 首页数据统计 Service 接口 + * + * @author 君风 + */ +public interface DataInfoService { + + /** + * 创建首页数据统计 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createDataInfo(@Valid DataInfoSaveReqVO createReqVO); + + /** + * 更新首页数据统计 + * + * @param updateReqVO 更新信息 + */ + void updateDataInfo(@Valid DataInfoSaveReqVO updateReqVO); + + /** + * 删除首页数据统计 + * + * @param id 编号 + */ + void deleteDataInfo(Long id); + + /** + * 获得首页数据统计 + * + * @param id 编号 + * @return 首页数据统计 + */ + DataInfoDO getDataInfo(Long id); + + /** + * 获得首页数据统计分页 + * + * @param pageReqVO 分页查询 + * @return 首页数据统计分页 + */ + PageResult getDataInfoPage(DataInfoPageReqVO pageReqVO); + +} diff --git a/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/service/datainfo/DataInfoServiceImpl.java b/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/service/datainfo/DataInfoServiceImpl.java new file mode 100644 index 0000000..988b222 --- /dev/null +++ b/yudao-module-home/yudao-module-home-biz/src/main/java/cn/iocoder/yudao/module/home/service/datainfo/DataInfoServiceImpl.java @@ -0,0 +1,74 @@ +package cn.iocoder.yudao.module.home.service.datainfo; + +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.home.controller.admin.datainfo.vo.*; +import cn.iocoder.yudao.module.home.dal.dataobject.datainfo.DataInfoDO; +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.home.dal.mysql.datainfo.DataInfoMapper; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.home.enums.ErrorCodeConstants.*; + +/** + * 首页数据统计 Service 实现类 + * + * @author 君风 + */ +@Service +@Validated +public class DataInfoServiceImpl implements DataInfoService { + + @Resource + private DataInfoMapper dataInfoMapper; + + @Override + public Long createDataInfo(DataInfoSaveReqVO createReqVO) { + // 插入 + DataInfoDO dataInfo = BeanUtils.toBean(createReqVO, DataInfoDO.class); + dataInfoMapper.insert(dataInfo); + // 返回 + return dataInfo.getId(); + } + + @Override + public void updateDataInfo(DataInfoSaveReqVO updateReqVO) { + // 校验存在 +// validateDataInfoExists(updateReqVO.getId()); + // 更新 + DataInfoDO updateObj = BeanUtils.toBean(updateReqVO, DataInfoDO.class); + dataInfoMapper.updateById(updateObj); + } + + @Override + public void deleteDataInfo(Long id) { + // 校验存在 + validateDataInfoExists(id); + // 删除 + dataInfoMapper.deleteById(id); + } + + private void validateDataInfoExists(Long id) { + if (dataInfoMapper.selectById(id) == null) { + throw exception(DATA_INFO_NOT_EXISTS); + } + } + + @Override + public DataInfoDO getDataInfo(Long id) { + return dataInfoMapper.selectById(id); + } + + @Override + public PageResult getDataInfoPage(DataInfoPageReqVO pageReqVO) { + return dataInfoMapper.selectPage(pageReqVO); + } + +} diff --git a/yudao-module-home/yudao-module-home-biz/src/main/resources/mapper/datainfo/DataInfoMapper.xml b/yudao-module-home/yudao-module-home-biz/src/main/resources/mapper/datainfo/DataInfoMapper.xml new file mode 100644 index 0000000..a32857f --- /dev/null +++ b/yudao-module-home/yudao-module-home-biz/src/main/resources/mapper/datainfo/DataInfoMapper.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/yudao-module-home/yudao-module-home-biz/src/test/java/cn/iocoder/yudao/module/home/service/datainfo/DataInfoServiceImplTest.java b/yudao-module-home/yudao-module-home-biz/src/test/java/cn/iocoder/yudao/module/home/service/datainfo/DataInfoServiceImplTest.java new file mode 100644 index 0000000..4ab09a5 --- /dev/null +++ b/yudao-module-home/yudao-module-home-biz/src/test/java/cn/iocoder/yudao/module/home/service/datainfo/DataInfoServiceImplTest.java @@ -0,0 +1,170 @@ +package cn.iocoder.yudao.module.home.service.datainfo; + +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.home.controller.admin.datainfo.vo.*; +import cn.iocoder.yudao.module.home.dal.dataobject.datainfo.DataInfoDO; +import cn.iocoder.yudao.module.home.dal.mysql.datainfo.DataInfoMapper; +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.home.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 DataInfoServiceImpl} 的单元测试类 + * + * @author 君风 + */ +@Import(DataInfoServiceImpl.class) +public class DataInfoServiceImplTest extends BaseDbUnitTest { + + @Resource + private DataInfoServiceImpl dataInfoService; + + @Resource + private DataInfoMapper dataInfoMapper; + + @Test + public void testCreateDataInfo_success() { + // 准备参数 + DataInfoSaveReqVO createReqVO = randomPojo(DataInfoSaveReqVO.class); + + // 调用 + Long dataInfoId = dataInfoService.createDataInfo(createReqVO); + // 断言 + assertNotNull(dataInfoId); + // 校验记录的属性是否正确 + DataInfoDO dataInfo = dataInfoMapper.selectById(dataInfoId); + assertPojoEquals(createReqVO, dataInfo, "id"); + } + + @Test + public void testUpdateDataInfo_success() { + // mock 数据 + DataInfoDO dbDataInfo = randomPojo(DataInfoDO.class); + dataInfoMapper.insert(dbDataInfo);// @Sql: 先插入出一条存在的数据 + // 准备参数 + DataInfoSaveReqVO updateReqVO = randomPojo(DataInfoSaveReqVO.class, o -> { +// o.setId(dbDataInfo.getId()); // 设置更新的 ID + }); + + // 调用 + dataInfoService.updateDataInfo(updateReqVO); + // 校验是否更新正确 +// DataInfoDO dataInfo = dataInfoMapper.selectById(updateReqVO.getId()); // 获取最新的 +// assertPojoEquals(updateReqVO, dataInfo); + } + + @Test + public void testUpdateDataInfo_notExists() { + // 准备参数 + DataInfoSaveReqVO updateReqVO = randomPojo(DataInfoSaveReqVO.class); + + // 调用, 并断言异常 + assertServiceException(() -> dataInfoService.updateDataInfo(updateReqVO), DATA_INFO_NOT_EXISTS); + } + + @Test + public void testDeleteDataInfo_success() { + // mock 数据 + DataInfoDO dbDataInfo = randomPojo(DataInfoDO.class); + dataInfoMapper.insert(dbDataInfo);// @Sql: 先插入出一条存在的数据 + // 准备参数 + Long id = dbDataInfo.getId(); + + // 调用 + dataInfoService.deleteDataInfo(id); + // 校验数据不存在了 + assertNull(dataInfoMapper.selectById(id)); + } + + @Test + public void testDeleteDataInfo_notExists() { + // 准备参数 + Long id = randomLongId(); + + // 调用, 并断言异常 + assertServiceException(() -> dataInfoService.deleteDataInfo(id), DATA_INFO_NOT_EXISTS); + } + + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 + public void testGetDataInfoPage() { + // mock 数据 + DataInfoDO dbDataInfo = randomPojo(DataInfoDO.class, o -> { // 等会查询到 + o.setInfoYear(null); + o.setInfoCo2e(null); + o.setInfoWater(null); + o.setInfoPollution(null); + o.setInfoEcom(null); + o.setInfoTraining(null); + o.setInfoRd(null); + o.setInfoEnvironment(null); + o.setInfoSociety(null); + o.setInfoGovern(null); + o.setCreateTime(null); + }); + dataInfoMapper.insert(dbDataInfo); + // 测试 infoYear 不匹配 + dataInfoMapper.insert(cloneIgnoreId(dbDataInfo, o -> o.setInfoYear(null))); + // 测试 infoCo2e 不匹配 + dataInfoMapper.insert(cloneIgnoreId(dbDataInfo, o -> o.setInfoCo2e(null))); + // 测试 infoWater 不匹配 + dataInfoMapper.insert(cloneIgnoreId(dbDataInfo, o -> o.setInfoWater(null))); + // 测试 infoPollution 不匹配 + dataInfoMapper.insert(cloneIgnoreId(dbDataInfo, o -> o.setInfoPollution(null))); + // 测试 infoEcom 不匹配 + dataInfoMapper.insert(cloneIgnoreId(dbDataInfo, o -> o.setInfoEcom(null))); + // 测试 infoTraining 不匹配 + dataInfoMapper.insert(cloneIgnoreId(dbDataInfo, o -> o.setInfoTraining(null))); + // 测试 infoRd 不匹配 + dataInfoMapper.insert(cloneIgnoreId(dbDataInfo, o -> o.setInfoRd(null))); + // 测试 infoEnvironment 不匹配 + dataInfoMapper.insert(cloneIgnoreId(dbDataInfo, o -> o.setInfoEnvironment(null))); + // 测试 infoSociety 不匹配 + dataInfoMapper.insert(cloneIgnoreId(dbDataInfo, o -> o.setInfoSociety(null))); + // 测试 infoGovern 不匹配 + dataInfoMapper.insert(cloneIgnoreId(dbDataInfo, o -> o.setInfoGovern(null))); + // 测试 createTime 不匹配 + dataInfoMapper.insert(cloneIgnoreId(dbDataInfo, o -> o.setCreateTime(null))); + // 准备参数 + DataInfoPageReqVO reqVO = new DataInfoPageReqVO(); + reqVO.setInfoYear(null); + reqVO.setInfoCo2e(null); + reqVO.setInfoWater(null); + reqVO.setInfoPollution(null); + reqVO.setInfoEcom(null); + reqVO.setInfoTraining(null); + reqVO.setInfoRd(null); + reqVO.setInfoEnvironment(null); + reqVO.setInfoSociety(null); + reqVO.setInfoGovern(null); + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); + + // 调用 + PageResult pageResult = dataInfoService.getDataInfoPage(reqVO); + // 断言 + assertEquals(1, pageResult.getTotal()); + assertEquals(1, pageResult.getList().size()); + assertPojoEquals(dbDataInfo, pageResult.getList().get(0)); + } + +} diff --git a/yudao-module-home/yudao-module-home-biz/src/test/resources/sql/clean.sql b/yudao-module-home/yudao-module-home-biz/src/test/resources/sql/clean.sql new file mode 100644 index 0000000..bc07f55 --- /dev/null +++ b/yudao-module-home/yudao-module-home-biz/src/test/resources/sql/clean.sql @@ -0,0 +1,47 @@ +CREATE TABLE IF NOT EXISTS "des_datainfo" ( + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "info_year" varchar NOT NULL, + "info_co2e" int NOT NULL, + "info_water" int NOT NULL, + "info_castoff" int, + "info_coai" int, + "info_pollution" int NOT NULL, + "info_ecom" int NOT NULL, + "info_staff" int, + "info_training" int NOT NULL, + "info_rd" int NOT NULL, + "info_probono" int, + "info_insurance" int, + "info_violate" int, + "info_guarantee" int, + "info_money" bigint, + "info_environment" int NOT NULL, + "info_society" int NOT NULL, + "info_govern" int NOT NULL, + "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 '数据收集'; +CREATE TABLE IF NOT EXISTS "des_homepj" ( + "pjId" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "pj_name" varchar NOT NULL, + "pj_done" int NOT NULL, + "pj_describe" varchar NOT NULL, + "pj_content" varchar, + "pj_type" int NOT NULL, + "pj_etime" varchar, + "pj_vtime" varchar, + "pj_dept" int NOT NULL, + "pj_number" bigint NOT NULL, + "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 ("pj_id") +) COMMENT '主要用于首页的项目数据'; diff --git a/yudao-module-home/yudao-module-home-biz/src/test/resources/sql/create_tables.sql b/yudao-module-home/yudao-module-home-biz/src/test/resources/sql/create_tables.sql new file mode 100644 index 0000000..3ec564a --- /dev/null +++ b/yudao-module-home/yudao-module-home-biz/src/test/resources/sql/create_tables.sql @@ -0,0 +1,2 @@ +DELETE FROM "des_datainfo"; +DELETE FROM "des_homePJ"; diff --git a/yudao-server/pom.xml b/yudao-server/pom.xml index 17b221f..551bfc5 100644 --- a/yudao-server/pom.xml +++ b/yudao-server/pom.xml @@ -51,6 +51,11 @@ yudao-module-bpm-biz ${revision} + + cn.iocoder.boot + yudao-module-home-biz + ${revision} +