Commit ff2a6626 by 林冲

培训计划接口接口实现

1 parent 2031e57c
package cn.com.glsx.dj.riskmanage.dto.learningcenter;
import cn.com.glsx.dj.riskmanage.model.learningcenter.LearningCenterTrainingPlan;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
public class TrainingPlanDTO implements Serializable {
public class TrainingPlanDTO extends LearningCenterTrainingPlan implements Serializable {
private static final long serialVersionUID = -1795510151751099552L;
/**
* 主键id
*/
private Integer id;
/**
* 应用场景 (1:等级考试)
*/
private Byte sceneType;
/**
* 计划名称
*/
private String planName;
/**
* 考试id
*/
private Integer examId;
/**
* 考试名称
*/
private String examName;
/**
* 开单权限 (0:不启用, 1:启用)
*/
private Byte orderPermissionStatus;
/**
* 开单权限类型 (1:锁定开单权限, 完成培训计划后开放 2:开单权限已开放, 限时锁定)
*/
private Byte orderPermissionType;
/**
* 限时锁定参数
*/
private Integer limitTimeParam;
/**
* 创建人
*/
private String createdBy;
/**
* 创建时间
*/
private Date createdDate;
/**
* 修改人
*/
private String updatedBy;
/**
* 修改时间
*/
private Date updatedDate;
/**
* 删除标识(D:已删除;N:未删除)
*/
private String deletedFlag;
/**
* 白名单 (北森员工标识, 以英文逗号分隔)
*/
private String whiteList;
/**
* 状态,0草稿、1生效、2失效
*/
private Byte status;
/**
* 课程数量
*/
@ApiModelProperty(notes = "课程数量")
private Integer courseNum;
/**
* 计划阶段人数
*/
@ApiModelProperty(notes = "计划阶段人数")
private Integer personNum;
@ApiModelProperty(notes = "创建时间开始时间")
private String startTime;
@ApiModelProperty(notes = "创建时间结束时间")
private String endTime;
}
package cn.com.glsx.dj.riskmanage.dto.learningcenter;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* 培训计划人员-分页查询请求
*/
@Data
public class TrainingPlanPersonPageDTO implements Serializable {
private static final long serialVersionUID = -1872940429855314420L;
/** 培训计划ID */
@ApiModelProperty(notes = "培训计划ID", required = true)
private Integer planId;
/** 员工姓名(模糊) */
@ApiModelProperty(notes = "员工姓名(支持模糊搜索)")
private String personName;
/** 手机号码(模糊) */
@ApiModelProperty(notes = "手机号码(支持模糊搜索)")
private String phoneNumber;
/** 所属部门(下拉单选,来自列表字段) */
@ApiModelProperty(notes = "所属部门(下拉单选)")
private Integer departId;
@ApiModelProperty(notes = "部门名称")
private String departName;
/** 职务(下拉单选,来自列表字段) */
@ApiModelProperty(notes = "职务(下拉单选)Id")
private String jobId;
@ApiModelProperty(notes = "职务名称")
private String jobName;
/** 人员状态(下拉单选,来自列表字段) */
@ApiModelProperty(notes = "人员状态(下拉单选)在职状态 0否 1是")
private Integer personStatus;
/** 开单权限(0:已锁定, 1:已解锁,下拉单选) */
@ApiModelProperty(notes = "开单权限(0:已锁定, 1:已解锁)")
private Byte openOrderStatus;
/** 入职日期-开始(yyyy-MM-dd) */
@ApiModelProperty(notes = "入职日期开始(yyyy-MM-dd)")
private Date entryStartDate;
/** 入职日期-结束(yyyy-MM-dd) */
@ApiModelProperty(notes = "入职日期结束(yyyy-MM-dd)")
private Date entryEndDate;
@ApiModelProperty(notes = "入职日期")
private Date entryDate;
/** 排序字段:entryDate */
@ApiModelProperty(notes = "排序字段:entryDate")
private String sortField;
/** 排序方向:asc 或 desc(默认desc) */
@ApiModelProperty(notes = "排序方向:asc 或 desc(默认desc)")
private String sortOrder;
@ApiModelProperty(notes = "北森用户Id集合")
private List<Integer> personIds;
@ApiModelProperty(notes = "北森用户Id")
private Integer personId;
/** 已完成课程数量(支持排序) */
@ApiModelProperty(notes = "已完成课程数量(支持排序)")
private Integer completedCourseCount;
}
package cn.com.glsx.dj.riskmanage.remote;
import cn.com.glsx.dj.riskmanage.dto.learningcenter.TrainingPlanPersonPageDTO;
import cn.com.glsx.framework.core.annotation.*;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import java.util.List;
@ApiService(value = "学习中心,培训计划人员", owner = "linchong")
public interface LearningCenterTrainingPlanPersonRemote {
@ApiMethod("根据培训计划ID和开单权限查询人员ID集合")
@ApiParams({
@ApiParam(name = "planId", notes = "培训计划ID", dataType = ApiParam.DataTypeEnum.INTEGER, required = true),
@ApiParam(name = "openOrderStatus", notes = "开单权限(0:已锁定, 1:已解锁)", dataType = ApiParam.DataTypeEnum.BYTE)
})
@ApiResponse("人员ID集合")
RpcResponse<List<Integer>> queryPersonIdsByPlanAndStatus(Integer planId, Byte openOrderStatus);
RpcResponse<RpcPagination<TrainingPlanPersonPageDTO>> pageList(RpcPagination<TrainingPlanPersonPageDTO> pagination);
@ApiMethod("解锁开单权限")
@ApiParams({
......
package cn.com.glsx.dj.riskmanage.remote.learningcenter;
import cn.com.glsx.dj.riskmanage.dto.learningcenter.TrainingPlanPersonPageDTO;
import cn.com.glsx.dj.riskmanage.remote.LearningCenterTrainingPlanPersonRemote;
import cn.com.glsx.dj.riskmanage.service.learningcenter.LearningCenterTrainingPlanPersonService;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
@Slf4j
@DubboService(retries = 0, timeout = 30000)
public class LearningCenterTrainingPlanPersonRemoteImpl implements LearningCenterTrainingPlanPersonRemote {
......@@ -18,9 +18,9 @@ public class LearningCenterTrainingPlanPersonRemoteImpl implements LearningCente
private LearningCenterTrainingPlanPersonService learningCenterTrainingPlanPersonService;
@Override
public RpcResponse<List<Integer>> queryPersonIdsByPlanAndStatus(Integer planId, Byte openOrderStatus) {
public RpcResponse<RpcPagination<TrainingPlanPersonPageDTO>> pageList(RpcPagination<TrainingPlanPersonPageDTO> pagination){
try {
return RpcResponse.success(learningCenterTrainingPlanPersonService.queryPersonIdsByPlanAndStatus(planId, openOrderStatus));
return RpcResponse.success(RpcPagination.copyPage(learningCenterTrainingPlanPersonService.pageList(pagination)));
} catch (RpcServiceException e) {
log.error(e.getMessage(), e);
return RpcResponse.error(e);
......
package cn.com.glsx.dj.riskmanage.service.learningcenter;
import cn.com.glsx.dj.riskmanage.dto.learningcenter.TrainingPlanPersonPageDTO;
import cn.com.glsx.dj.riskmanage.mapper.learningcenter.LearningCenterTrainingPlanPersonMapper;
import cn.com.glsx.dj.riskmanage.model.learningcenter.LearningCenterTrainingPlanPerson;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.core.util.RpcAssert;
import cn.com.glsx.merchants.dto.beisen.BeiSenEmployeeListRequestDTO;
import cn.com.glsx.merchants.dto.beisen.BeiSenEmployeeListResonseDTO;
import cn.com.glsx.merchants.remote.MerchantStaffRemote;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import java.util.List;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@Slf4j
......@@ -19,22 +29,84 @@ import java.util.stream.Collectors;
public class LearningCenterTrainingPlanPersonService {
private final LearningCenterTrainingPlanPersonMapper learningCenterTrainingPlanPersonMapper;
private final MerchantStaffRemote merchantStaffRemote;
/**
* 根据培训计划ID和开单权限查询人员ID集合
*/
public List<Integer> queryPersonIdsByPlanAndStatus(Integer planId, Byte openOrderStatus) {
RpcAssert.assertNotNull(planId, DefaultErrorEnum.PARAMETER_NULL, "planId not be null");
public Page<TrainingPlanPersonPageDTO> pageList(RpcPagination<TrainingPlanPersonPageDTO> pagination) {
TrainingPlanPersonPageDTO condition = pagination.getCondition();
RpcAssert.assertNotNull(condition.getPlanId(), DefaultErrorEnum.PARAMETER_NULL, "planId not be null");
try {
Example example = new Example(LearningCenterTrainingPlanPerson.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("planId", planId);
criteria.andEqualTo("planId", condition.getPlanId());
criteria.andEqualTo("deletedFlag", "N");
if (openOrderStatus != null) {
criteria.andEqualTo("openOrderStatus", openOrderStatus);
if (condition.getOpenOrderStatus() != null) {
criteria.andEqualTo("openOrderStatus", condition.getOpenOrderStatus());
}
List<LearningCenterTrainingPlanPerson> persons = learningCenterTrainingPlanPersonMapper.selectByExample(example);
return persons.stream().map(LearningCenterTrainingPlanPerson::getPersonId).collect(Collectors.toList());
List<Integer> userIdList = persons.stream().map(LearningCenterTrainingPlanPerson::getPersonId).collect(Collectors.toList());
BeiSenEmployeeListRequestDTO requestDTO = new BeiSenEmployeeListRequestDTO();
requestDTO.setUserIds(userIdList);
requestDTO.setEmployeeName(condition.getPersonName());
requestDTO.setMobilePhone(condition.getPhoneNumber());
requestDTO.setOIdDepartmentIds(Collections.singletonList(condition.getDepartId()));
requestDTO.setOIdJobPostIds(Collections.singletonList(condition.getJobId()));
requestDTO.setStatus(condition.getPersonStatus());
requestDTO.setEntryStartDate(condition.getEntryStartDate());
requestDTO.setSortField(condition.getSortField());
requestDTO.setSortOrder(condition.getSortOrder());
RpcPagination rpcPagination = new RpcPagination();
rpcPagination.setPageNum(pagination.getPageNum());
rpcPagination.setPageSize(pagination.getPageSize());
rpcPagination.setCondition(rpcPagination);
RpcResponse<RpcPagination<BeiSenEmployeeListResonseDTO>> rpcResponse = merchantStaffRemote.getBeisenUserWithConditions(rpcPagination);
// 检查响应结果
if (!rpcResponse.isSuccess() || rpcResponse.getResult() == null) {
log.warn("query beisen user failed, planId: {}", condition.getPlanId());
return new Page<>(pagination.getPageNum(), pagination.getPageSize());
}
RpcPagination<BeiSenEmployeeListResonseDTO> beisenPage = rpcResponse.getResult();
// 创建 Page 对象
Page<TrainingPlanPersonPageDTO> page = new Page<>(pagination.getPageNum(), pagination.getPageSize());
page.setTotal(beisenPage.getTotal());
// 构建人员ID与开单权限的映射关系
Map<Integer, LearningCenterTrainingPlanPerson> personOpenOrderStatusMap = persons.stream()
.collect(Collectors.toMap(LearningCenterTrainingPlanPerson::getPersonId, Function.identity()));
// 转换数据并填充开单权限
List<TrainingPlanPersonPageDTO> resultList = new ArrayList<>();
if (beisenPage.getList() != null && !beisenPage.getList().isEmpty()) {
for (BeiSenEmployeeListResonseDTO employeeDTO : beisenPage.getList()) {
TrainingPlanPersonPageDTO dto = new TrainingPlanPersonPageDTO();
dto.setPlanId(condition.getPlanId());
dto.setPersonId(employeeDTO.getUserID());
dto.setPersonName(employeeDTO.getName());
dto.setPhoneNumber(employeeDTO.getMobilePhone());
dto.setDepartId(employeeDTO.getOldDepartmentId());
// todo
dto.setDepartName("");
dto.setJobId(employeeDTO.getOIdJobPostId());
dto.setJobName(employeeDTO.getOIdJobPost());
dto.setPersonStatus(employeeDTO.getZzStatus());
// 设置开单权限状态
Byte openOrderStatus = personOpenOrderStatusMap.get(employeeDTO.getUserID()).getOpenOrderStatus();
dto.setOpenOrderStatus(openOrderStatus != null ? openOrderStatus : (byte) 0);
dto.setEntryDate(employeeDTO.getEntryDate());
// todo
dto.setCompletedCourseCount(null);
resultList.add(dto);
}
}
page.addAll(resultList);
return page;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new RpcServiceException(DefaultErrorEnum.DATABASE_ERROR, e.getMessage());
......
......@@ -43,8 +43,8 @@
<if test="status != null">
AND t.status = #{status}
</if>
<if test="createdBy != null and createdBy != ''">
AND t.created_by LIKE CONCAT('%', #{createdBy}, '%')
<if test="creator != null and creator != ''">
AND t.creator LIKE CONCAT('%', #{creator}, '%')
</if>
<if test="startTime != null and startTime != ''">
AND t.created_date &gt;= #{startTime}
......
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    1. 功能实现的正确性与健壮性

    问题:

    • TrainingPlanDTO 类继承了 LearningCenterTrainingPlan 类,但移除了大部分字段,这可能导致数据不完整。
    • 新增的 startTime 和 endTime 字段是 String 类型,而不是 Date 类型,这可能会导致日期格式问题和难以处理的日期比较操作。
    • LearningCenterTrainingPlanPersonService 中的 pageList 方法存在一些潜在的问题:
      • rpcPagination.setCondition(rpcPagination); 这一行代码可能是一个错误,应设置实际的条件对象。
      • dto.setDepartName("") 和 dto.setCompletedCourseCount(null) 这两行代码中的 todo 注释表明这里可能存在未完成的实现。
      • PageHelper 没有被调用,因此分页功能可能无法正常工作。

    优化建议:

    • 确保 TrainingPlanDTO 类继承 LearningCenterTrainingPlan 类时,所有必要的字段都得到保留。
    • 将 startTime 和 endTime 字段改为 Date 类型,以提高日期处理的准确性。
    • 完成 LearningCenterTrainingPlanPersonService 中的 todo 项。
    • 在 pageList 方法中调用 PageHelper.startPage(pagination.getPageNum(), pagination.getPageSize()); 来启用分页功能。

    2. 安全性与潜在风险

    问题:

    • 代码中没有明显的安全漏洞,但需要注意输入验证,特别是在从外部接收数据时。
    • LearningCenterTrainingPlanPersonService 中对 BeiSenEmployeeListRequestDTO 的设置缺乏严格的输入验证,这可能导致潜在的安全风险。

    优化建议:

    • 添加输入验证逻辑,确保接收到的数据符合预期格式和范围。
    • 对敏感字段(如用户ID、手机号码等)进行适当的加密或脱敏处理。

    3. 是否符合最佳实践

    问题:

    • TrainingPlanDTO 类继承了 LearningCenterTrainingPlan 类,这可能不符合单一职责原则。
    • LearningCenterTrainingPlanPersonService 中的 pageList 方法过长且复杂,可以考虑拆分为多个方法以提高可读性和可维护性。
    • 缺少详细的注释和文档,特别是对于复杂的业务逻辑部分。

    优化建议:

    • 避免不必要的类继承,保持类的单一职责。
    • 将复杂的业务逻辑拆分为多个方法,并添加适当的注释和文档。
    • 提供详细的API文档,以便其他开发者理解和使用这些接口。

    4. 性能与资源利用效率

    问题:

    • LearningCenterTrainingPlanPersonService 中的 pageList 方法在处理大量数据时可能会遇到性能瓶颈。
    • 使用 PageHelper 时,确保数据库查询和数据处理过程高效,避免不必要的数据加载。

    优化建议:

    • 对关键路径进行性能测试,找出潜在的性能瓶颈。
    • 使用索引和缓存来提高数据库查询效率。
    • 优化数据处理逻辑,减少不必要的内存占用和计算。

    5. Commits信息的清晰性与准确性

    问题:

    • 提交信息“培训计划接口接口实现”不够清晰,没有明确指出具体的更改内容和目的。

    优化建议:

    • 提供更详细的提交信息,描述具体的更改内容和目的,例如:“重构 TrainingPlanDTO 类并实现 TrainingPlanPersonPageDTO 分页查询”。

    评分明细

    1. 功能实现的正确性与健壮性:25/40
    2. 安全性与潜在风险:25/30
    3. 是否符合最佳实践:15/20
    4. 性能与资源利用效率:3/5
    5. Commits信息的清晰性与准确性:2/5

    总分: 70分


    以上是对该员工代码的详细审查报告,希望这些建议能够帮助改进代码的质量。

Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!