feat(产品模块开发): 完善产品相关接口

完善模块列表接口:
1、增加顶级模块(全部需求)
2、计算各模块下包含的需求数量
This commit is contained in:
OTTO 2023-10-18 16:29:55 +08:00
parent 405ab7e4e8
commit ee248889ac
8 changed files with 90 additions and 19 deletions

View File

@ -44,6 +44,10 @@ public class PmsProductModule extends BaseEntity
@ApiModelProperty(value = "排序")
private Integer sort;
/** 需求数量 */
@ApiModelProperty(value = "需求数量")
private Integer requirementCount;
/** 删除标志0代表存在 2代表删除 */
private String delFlag;

View File

@ -22,6 +22,9 @@ public class TreeSelect implements Serializable {
/** 节点名称 */
private String label;
/** 节点数据 */
private Object data;
/** 子节点 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<TreeSelect> children;
@ -35,6 +38,7 @@ public class TreeSelect implements Serializable {
{
this.id = pmsProductModule.getId();
this.label = pmsProductModule.getModuleName();
this.data=pmsProductModule.getRequirementCount();
this.children = pmsProductModule.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
}
}

View File

@ -64,10 +64,10 @@ public interface PmsProductModuleMapper
/**
* 查询产品下相同父级模块相同名称的模块数量
*
* @param name
* @param productId
* @param parentId
* @return
*/
Integer selectPmsProductModuleByNameCount(@Param("name") String name, @Param("productId") Long productId, @Param("parentId") Long parentId);
Integer selectPmsProductModuleByNameCount(@Param("name") String name, @Param("productId") Long productId);
}

View File

@ -1,6 +1,7 @@
package com.ruoyi.pms.product.mapper;
import java.util.List;
import com.ruoyi.pms.product.domain.PmsProductRequirement;
import org.apache.ibatis.annotations.Mapper;
@ -60,4 +61,12 @@ public interface PmsProductRequirementMapper
* @return 结果
*/
public int deletePmsProductRequirementByIds(Long[] ids);
/**
* 查询需求数量
*
* @param pmsProductRequirementSearch
* @return
*/
Integer selectPmsProductRequirementCount(PmsProductRequirement pmsProductRequirementSearch);
}

View File

@ -9,7 +9,9 @@ import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.pms.product.domain.PmsProductRequirement;
import com.ruoyi.pms.product.domain.vo.TreeSelect;
import com.ruoyi.pms.product.mapper.PmsProductRequirementMapper;
import com.ruoyi.pms.product.service.IPmsProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -30,6 +32,8 @@ public class PmsProductModuleServiceImpl implements IPmsProductModuleService
private PmsProductModuleMapper pmsProductModuleMapper;
@Autowired
private IPmsProductService pmsProductService;
@Autowired
private PmsProductRequirementMapper pmsProductRequirementMapper;
/**
* 查询产品模块
@ -64,7 +68,7 @@ public class PmsProductModuleServiceImpl implements IPmsProductModuleService
@Override
public int insertPmsProductModule(PmsProductModule pmsProductModule)
{
checkNameDuplicates(pmsProductModule.getModuleName(),pmsProductModule.getPmsProductId(),pmsProductModule.getParentId());
checkNameDuplicates(pmsProductModule.getModuleName(),pmsProductModule.getPmsProductId());
pmsProductModule.setCreateBy(SecurityUtils.getUsername());
pmsProductModule.setCreateTime(DateUtils.getNowDate());
//检查产品id是否存在
@ -79,10 +83,10 @@ public class PmsProductModuleServiceImpl implements IPmsProductModuleService
* @param parentId
* @return
*/
private void checkNameDuplicates(String name,Long productId,Long parentId){
Integer count = pmsProductModuleMapper.selectPmsProductModuleByNameCount(name,productId,parentId);
private void checkNameDuplicates(String name,Long productId){
Integer count = pmsProductModuleMapper.selectPmsProductModuleByNameCount(name,productId);
if(count>0){
throw new ServiceException("该产品模块名称在该产品的相同父级模块下已存在(产品模块名称[%s])",name);
throw new ServiceException("该产品模块名称已存在(产品模块名称[%s])",name);
}
}
@ -98,7 +102,7 @@ public class PmsProductModuleServiceImpl implements IPmsProductModuleService
PmsProductModule oldPmsProductModule=pmsProductModuleMapper.selectPmsProductModuleById(pmsProductModule.getId());
if(StringUtils.isNotEmpty(pmsProductModule.getModuleName())
&&!pmsProductModule.getModuleName().equals(oldPmsProductModule.getModuleName())){
checkNameDuplicates(pmsProductModule.getModuleName(),oldPmsProductModule.getPmsProductId(),pmsProductModule.getParentId());
checkNameDuplicates(pmsProductModule.getModuleName(),oldPmsProductModule.getPmsProductId());
}
pmsProductModule.setUpdateBy(SecurityUtils.getUsername());
pmsProductModule.setUpdateTime(DateUtils.getNowDate());
@ -134,10 +138,40 @@ public class PmsProductModuleServiceImpl implements IPmsProductModuleService
}
return pmsProductModuleMapper.deletePmsProductModuleById(id);
}
public static List<PmsProductModule> aggregateCounts(List<PmsProductModule> nodeList, Long parentId) {
List<PmsProductModule> result = new ArrayList<>();
for (PmsProductModule node : nodeList) {
if (node.getParentId() == parentId) {
List<PmsProductModule> children = aggregateCounts(nodeList, node.getId());
int totalChildCount = node.getRequirementCount();
for (PmsProductModule child : children) {
totalChildCount += child.getRequirementCount();
}
node.setRequirementCount(totalChildCount);
result.add(node);
}
}
return result;
}
@Override
public List<TreeSelect> selectPmsProductModuleTreeList(PmsProductModule pmsProductModule) {
List<PmsProductModule> moduleList = selectPmsProductModuleList(pmsProductModule);
// 父级需求数需包含子级需求数
aggregateCounts(moduleList,0L);
// 构建顶级模块全部需求
PmsProductModule allPmsProductModule=new PmsProductModule();
allPmsProductModule.setPmsProductId(pmsProductModule.getPmsProductId());
allPmsProductModule.setId(0L);
allPmsProductModule.setModuleName("全部需求");
// 计算全部需求数量
PmsProductRequirement pmsProductRequirementSearch=new PmsProductRequirement();
pmsProductRequirementSearch.setPmsProductId(pmsProductModule.getPmsProductId());
Integer requirementCount=pmsProductRequirementMapper.selectPmsProductRequirementCount(pmsProductRequirementSearch);
allPmsProductModule.setRequirementCount(requirementCount);
moduleList.add(allPmsProductModule);
return buildModuleTreeSelect(moduleList);
}
public List<TreeSelect> buildModuleTreeSelect(List<PmsProductModule> moduleList)

View File

@ -222,6 +222,9 @@ public class PmsProductRequirementServiceImpl implements IPmsProductRequirementS
}
public List<SysFileInfo> getAllFileByFileIds(String fileIds) {
if(StringUtils.isBlank(fileIds)){
return new ArrayList<>();
}
List<SysFileInfo> sysFileInfoList;
try {
sysFileInfoList = FeginUtils.getReturnData(

View File

@ -15,23 +15,33 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="createTime" column="create_time" />
<result property="createBy" column="create_by" />
<result property="delFlag" column="del_flag" />
<result property="requirementCount" column="requirementCount" />
<result property="reservedField1" column="reserved_field_1" />
<result property="reservedField2" column="reserved_field_2" />
</resultMap>
<sql id="selectPmsProductModuleVo">
select id, module_name, pms_product_id, parent_id, sort, update_time, update_by, create_time, create_by, del_flag, reserved_field_1, reserved_field_2 from pms_product_module
select id, module_name, pms_product_id, parent_id, sort, update_time, update_by, create_time, create_by, del_flag, reserved_field_1, reserved_field_2
from pms_product_module
</sql>
<sql id="selectPmsProductModuleAliasVo">
select m.id, m.module_name, m.pms_product_id, m.parent_id, m.sort, m.update_time, m.update_by, m.create_time, m.create_by, m.del_flag, m.reserved_field_1, m.reserved_field_2
,(
SELECT COUNT(*)
FROM pms_product_requirement r
WHERE r.pms_product_module_id = m.id
) AS requirementCount
from pms_product_module as m
</sql>
<select id="selectPmsProductModuleList" parameterType="PmsProductModule" resultMap="PmsProductModuleResult">
<include refid="selectPmsProductModuleVo"/>
<include refid="selectPmsProductModuleAliasVo"/>
<where>
<if test="moduleName != null and moduleName != ''"> and module_name like concat('%', #{moduleName}, '%')</if>
<if test="pmsProductId != null "> and pms_product_id = #{pmsProductId}</if>
<if test="parentId != null "> and parent_id = #{parentId}</if>
<if test="sort != null "> and sort = #{sort}</if>
<if test="reservedField1 != null and reservedField1 != ''"> and reserved_field_1 = #{reservedField1}</if>
<if test="reservedField2 != null and reservedField2 != ''"> and reserved_field_2 = #{reservedField2}</if>
<if test="moduleName != null and moduleName != ''"> and m.module_name like concat('%', #{moduleName}, '%')</if>
<if test="pmsProductId != null "> and m.pms_product_id = #{pmsProductId}</if>
<if test="parentId != null "> and m.parent_id = #{parentId}</if>
<if test="sort != null "> and m.sort = #{sort}</if>
</where>
</select>
@ -44,7 +54,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<where>
module_name = #{name}
and pms_product_id=#{productId}
<if test="parentId != null and parentId != 0"> and parent_id = #{parentId}</if>
</where>
</select>

View File

@ -33,6 +33,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectPmsProductRequirementList" parameterType="PmsProductRequirement" resultMap="PmsProductRequirementResult">
<include refid="selectPmsProductRequirementVo"/>
<include refid="selectWhere"/>
</select>
<select id="selectPmsProductRequirementCount" resultType="java.lang.Integer">
select count(0) from pms_product_requirement
<include refid="selectWhere"/>
</select>
<sql id="selectWhere">
<where>
<if test="title != null and title != ''"> and title like concat('%', #{title}, '%')</if>
<if test="statusId != null"> and status_id = #{statusId}</if>
@ -49,7 +57,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="requirementAssigneeId != null and requirementAssigneeId != ''"> and requirement_assignee_id = #{requirementAssigneeId}</if>
<if test="pmsProjectId != null and pmsProjectId != ''"> and pms_project_id = #{pmsProjectId}</if>
</where>
</select>
</sql>
<select id="selectPmsProductRequirementById" parameterType="Long" resultMap="PmsProductRequirementResult">
<include refid="selectPmsProductRequirementVo"/>