硬件版本各数量计算

This commit is contained in:
SjS 2025-04-10 15:02:19 +08:00
parent 08d8520aee
commit 0c88acaa03
7 changed files with 139 additions and 19 deletions

View File

@ -43,6 +43,22 @@ public class HardwareVersion extends BaseEntity
@ApiModelProperty("数量")
private Integer quantity;
@Excel(name = "已绑定")
@ApiModelProperty("已绑定")
private Integer bound;
@Excel(name = "未绑定")
@ApiModelProperty("未绑定")
private Integer unBound;
@Excel(name = "丢损")
@ApiModelProperty("丢损")
private Integer lost;
@Excel(name = "已录入数量")
@ApiModelProperty("已录入数量")
private Integer enteredNum;
@Excel(name = "未录入数量")
@ApiModelProperty("未录入数量")
private Integer notEnteredNum;

View File

@ -0,0 +1,18 @@
package com.ruoyi.bst.hardwareVersion.domain.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum SelectCondition {
BOUND("NotNULL"), // 已绑定查询条件
UNBOUND("NULL"); // 未绑定查询条件
private final String condition;
}

View File

@ -71,4 +71,18 @@ public interface HardwareVersionMapper
* @return 结果
*/
public int deleteHardwareVersionByIds(Long[] ids);
int selectNum(@Param("query") HardwareVersionVO hardwareVersion,@Param("condition") String condition);
/**
* 已绑定版本数
*/
int countBoundNum(Long id);
/**
* 未绑定版本数
*/
int countUnBoundNum(Long id);
}

View File

@ -19,27 +19,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectHardwareVersionVo">
select
id,
parent_id,
ancestors,
version,
production_time,
quantity,
not_entered_num,
instructions,
create_time,
remark
from bst_hardware_version
bhv.id,
bhv.parent_id,
bhv.ancestors,
bhv.version,
bhv.production_time,
bhv.quantity,
bhv.not_entered_num,
bhv.instructions,
bhv.create_time,
bhv.remark
from bst_hardware_version bhv
</sql>
<sql id="searchCondition">
<if test="query.parentId != null "> and parent_id = #{query.parentId}</if>
<if test="query.ancestors != null and query.ancestors != ''"> and ancestors = #{query.ancestors}</if>
<if test="query.version != null and query.version != ''"> and version like concat('%', #{query.version}, '%')</if>
<if test="query.productionTime != null "> and production_time = #{query.productionTime}</if>
<if test="query.quantity != null "> and quantity = #{query.quantity}</if>
<if test="query.notEnteredNum != null "> and not_entered_num = #{query.notEnteredNum}</if>
<if test="query.instructions != null and query.instructions != ''"> and instructions like concat('%', #{query.instructions}, '%')</if>
<if test="query.id != null "> and bhv.id = #{query.id}</if>
<if test="query.parentId != null "> and bhv.parent_id = #{query.parentId}</if>
<if test="query.ancestors != null and query.ancestors != ''"> and bhv.ancestors = #{query.ancestors}</if>
<if test="query.version != null and query.version != ''"> and bhv.version like concat('%', #{query.version}, '%')</if>
<if test="query.productionTime != null "> and bhv.production_time = #{query.productionTime}</if>
<if test="query.quantity != null "> and bhv.quantity = #{query.quantity}</if>
<if test="query.notEnteredNum != null "> and bhv.not_entered_num = #{query.notEnteredNum}</if>
<if test="query.instructions != null and query.instructions != ''"> and bhv.instructions like concat('%', #{query.instructions}, '%')</if>
${query.params.dataScope}
</sql>
@ -55,6 +56,31 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where id = #{id}
</select>
<select id="selectNum" resultType="java.lang.Integer">
select count(bd.id) as count
from bst_hardware_version bhv
left join bst_device bd on bhv.id = bd.hardware_version_id
<choose>
<when test="condition == 'NotNULL'">
and bd.mch_id IS NOT NULL
</when>
<when test="condition == 'NULL'">
and bd.mch_id IS NULL
</when>
</choose>
<where>
<include refid="searchCondition"></include>
</where>
</select>
<select id="countBoundNum" resultType="java.lang.Integer">
select count(1) from bst_device where hardware_version_id = #{hardwareVersionId} and mch_id is not null
</select>
<select id="countUnBoundNum" resultType="java.lang.Integer">
select count(1) from bst_device where hardware_version_id = #{hardwareVersionId} and mch_id is null
</select>
<insert id="insertHardwareVersion" parameterType="HardwareVersion" useGeneratedKeys="true" keyProperty="id">
insert into bst_hardware_version
<trim prefix="(" suffix=")" suffixOverrides=",">

View File

@ -60,4 +60,6 @@ public interface HardwareVersionService
* @return 结果
*/
public int deleteHardwareVersionById(Long id);
List<HardwareVersionVO> computeNumber(HardwareVersionQuery query);
}

View File

@ -1,7 +1,10 @@
package com.ruoyi.bst.hardwareVersion.service.impl;
import java.util.List;
import com.ruoyi.bst.hardwareVersion.domain.enums.SelectCondition;
import com.ruoyi.common.utils.DateUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.bst.hardwareVersion.mapper.HardwareVersionMapper;
@ -94,4 +97,45 @@ public class HardwareVersionServiceImpl implements HardwareVersionService
{
return hardwareVersionMapper.deleteHardwareVersionById(id);
}
@Override
public List<HardwareVersionVO> computeNumber(HardwareVersionQuery query) {
List<HardwareVersionVO> list = hardwareVersionMapper.selectHardwareVersionList(query);
for (HardwareVersionVO hardwareVersionVO : list) {
if (hardwareVersionVO.getParentId() != 0){
int boundNum = hardwareVersionMapper.countBoundNum(hardwareVersionVO.getId());
hardwareVersionVO.setBound(boundNum);
int unBoundNum = hardwareVersionMapper.countUnBoundNum(hardwareVersionVO.getId());
hardwareVersionVO.setUnBound(unBoundNum);
int enteredNum =boundNum + unBoundNum;
hardwareVersionVO.setEnteredNum(enteredNum);
}
}
//统计父版本的各个特征数量
for (HardwareVersionVO parentVersion : list) {
if (parentVersion.getParentId() == 0){
int totalBound = 0;
int totalUnBound = 0;
int totalEntered = 0;
for (HardwareVersionVO childVersion : list) {
if (childVersion.getParentId().equals(parentVersion.getId())){
totalBound += childVersion.getBound();
totalUnBound += childVersion.getUnBound();
totalEntered += childVersion.getEnteredNum();
}
}
parentVersion.setBound(totalBound);
parentVersion.setUnBound(totalUnBound);
parentVersion.setEnteredNum(totalEntered);
}
}
for (HardwareVersionVO parentVersion : list) {
if (parentVersion.getParentId() == 0){
parentVersion.setLost(parentVersion.getQuantity()-parentVersion.getEnteredNum()-parentVersion.getNotEnteredNum());
}
}
return list;
}
}

View File

@ -39,7 +39,7 @@ public class HardwareVersionController extends BaseController
{
startPage();
startOrderBy();
List<HardwareVersionVO> list = hardwareVersionService.selectHardwareVersionList(query);
List<HardwareVersionVO> list = hardwareVersionService.computeNumber(query);
return getDataTable(list);
}