This commit is contained in:
XaoLi717 2024-09-14 10:06:43 +08:00
parent 7c60197e2c
commit b37b6ead1f
20 changed files with 960 additions and 2 deletions

View File

@ -17,6 +17,7 @@
<module>yudao-module-infra</module>
<!-- <module>yudao-module-member</module>-->
<module>yudao-module-bpm</module>
<module>yudao-module-home</module>
<!-- <module>yudao-module-report</module>-->
<!-- <module>yudao-module-mp</module>-->
<!-- <module>yudao-module-pay</module>-->

View File

@ -26,7 +26,7 @@ public class MvcConfiguration implements WebMvcConfigurer {
if (thymeleafViewResolver != null) {
Map<String, Object> 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);

23
yudao-module-home/pom.xml Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao</artifactId>
<version>${revision}</version>
</parent>
<artifactId>yudao-module-home</artifactId>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
<description>
home模块,主要用于首页的功能,例如数据收集,项目管理,数据表数据
</description>
<modules>
<module>yudao-module-home-api</module>
<module>yudao-module-home-biz</module>
</modules>
</project>

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-home</artifactId>
<version>${revision}</version>
</parent>
<artifactId>yudao-module-home-api</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>
api模块,主要用于首页的功能,例如数据收集,项目管理,数据表数据
</description>
<dependencies>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-common</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,15 @@
package cn.iocoder.yudao.module.home.enums;
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
/**
* Bpm 错误码枚举类
* <p>
* 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, "主要用于首页的项目数据不存在");
}

View File

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-home</artifactId>
<version>${revision}</version>
</parent>
<artifactId>yudao-module-home-biz</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>
biz模块,主要用于首页的功能,例如数据收集,项目管理,数据表数据
</description>
<dependencies>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-bpm-api</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-mybatis</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-home-api</artifactId>
<version>2.1.0-jdk8-snapshot</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel-core</artifactId>
<version>3.3.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-excel</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-home-api</artifactId>
<version>2.1.0-jdk8-snapshot</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -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<Long> createDataInfo(@Valid @RequestBody DataInfoSaveReqVO createReqVO) {
return success(dataInfoService.createDataInfo(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新首页数据统计")
@PreAuthorize("@ss.hasPermission('home:data-info:update')")
public CommonResult<Boolean> 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<Boolean> 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<DataInfoRespVO> 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<PageResult<DataInfoRespVO>> getDataInfoPage(@Valid DataInfoPageReqVO pageReqVO) {
PageResult<DataInfoDO> 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<DataInfoDO> list = dataInfoService.getDataInfoPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "首页数据统计.xls", "数据", DataInfoRespVO.class,
BeanUtils.toBean(list, DataInfoRespVO.class));
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<String> get() {
return CommonResult.success("true22");
}
}

View File

@ -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") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 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;
}

View File

@ -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<DataInfoDO> {
default PageResult<DataInfoDO> selectPage(DataInfoPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<DataInfoDO>()
.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));
}
}

View File

@ -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<DataInfoDO> getDataInfoPage(DataInfoPageReqVO pageReqVO);
}

View File

@ -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<DataInfoDO> getDataInfoPage(DataInfoPageReqVO pageReqVO) {
return dataInfoMapper.selectPage(pageReqVO);
}
}

View File

@ -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.home.dal.mysql.datainfo.DataInfoMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

View File

@ -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<DataInfoDO> pageResult = dataInfoService.getDataInfoPage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbDataInfo, pageResult.getList().get(0));
}
}

View File

@ -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 '主要用于首页的项目数据';

View File

@ -0,0 +1,2 @@
DELETE FROM "des_datainfo";
DELETE FROM "des_homePJ";

View File

@ -51,6 +51,11 @@
<artifactId>yudao-module-bpm-biz</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-home-biz</artifactId>
<version>${revision}</version>
</dependency>
<!-- 支付服务。默认注释,保证编译速度 -->
<!-- <dependency>-->
<!-- <groupId>cn.iocoder.boot</groupId>-->