refactor(smartfactory): 优化搬运组金额规格查询和删除逻辑
- 修改 HandlingGroupAmountSpecificationsController 中的查询逻辑,按搬运组 ID 分组 - 在 HandlingGroupAmountSpecificationsServiceImpl 中实现批量删除功能,同时删除关联的 HandlingGroupUserAmount 记录 - 在 HandlingGroupUserAmountService 接口和实现类中添加按搬运组 ID 查询的方法 - 更新 HandlingGroupUserAmountMapper 和 XML 映射文件,支持按搬运组 ID 查询- 优化 HandlingGroupAmountSpecificationsMapper XML 映射文件中的查询语句,提高查询效率
This commit is contained in:
parent
bb49e919cb
commit
e31365ad90
@ -106,17 +106,17 @@ public class HandlingGroupAmountSpecificationsController {
|
||||
PageResult<HandlingGroupAmountSpecificationsRespVO> result = BeanUtils.toBean(pageResult, HandlingGroupAmountSpecificationsRespVO.class);
|
||||
// 计算合计 - 先根据工厂+搬运组+日期进行分组
|
||||
Map<String, List<HandlingGroupAmountSpecificationsRespVO>> map = result.getList().stream().collect(Collectors.groupingBy(a -> a.getFactoryId() + "_" + a.getHandlingGroupId() + "_" + a.getDateStr()));
|
||||
List<Long> ids = result.getList().stream().map(HandlingGroupAmountSpecificationsRespVO::getId).collect(Collectors.toList());
|
||||
List<Long> ids = result.getList().stream().map(HandlingGroupAmountSpecificationsRespVO::getHandlingGroupId).distinct().collect(Collectors.toList());
|
||||
Map<Long, List<HandlingGroupUserAmountDO>> handlingGroupUserAmountMap = new HashMap<>();
|
||||
if (CollUtil.isNotEmpty(ids)) {
|
||||
List<HandlingGroupUserAmountDO> list = handlingGroupUserAmountService.getByHandlingGroupAmountSpecificationsId(ids);
|
||||
handlingGroupUserAmountMap = list.stream().collect(Collectors.groupingBy(HandlingGroupUserAmountDO::getHandlingGroupAmountSpecificationsId));
|
||||
List<HandlingGroupUserAmountDO> list = handlingGroupUserAmountService.getByHandlingGroupIds(ids);
|
||||
handlingGroupUserAmountMap = list.stream().collect(Collectors.groupingBy(HandlingGroupUserAmountDO::getHandlingGroupId));
|
||||
}
|
||||
for (HandlingGroupAmountSpecificationsRespVO handlingGroupAmountSpecificationsDO : result.getList()) {
|
||||
String key = handlingGroupAmountSpecificationsDO.getFactoryId() + "_" + handlingGroupAmountSpecificationsDO.getHandlingGroupId() + "_" + handlingGroupAmountSpecificationsDO.getDateStr();
|
||||
handlingGroupAmountSpecificationsDO.setTotalAmount(getSumValue(map.get(key), HandlingGroupAmountSpecificationsRespVO::getAmount, BigDecimal::add));
|
||||
handlingGroupAmountSpecificationsDO.setTotalNum(getSumValue(map.get(key), HandlingGroupAmountSpecificationsRespVO::getTotalCount, Integer::sum));
|
||||
List<HandlingGroupUserAmountDO> items = handlingGroupUserAmountMap.get(handlingGroupAmountSpecificationsDO.getId());
|
||||
List<HandlingGroupUserAmountDO> items = handlingGroupUserAmountMap.get(handlingGroupAmountSpecificationsDO.getHandlingGroupId());
|
||||
if (CollUtil.isNotEmpty(items)) {
|
||||
List<HandlingGroupUserAmountItemVO> handlingGroupUserAmountItemVOS = BeanUtils.toBean(items, HandlingGroupUserAmountItemVO.class);
|
||||
handlingGroupAmountSpecificationsDO.setHandlingGroupUserAmountItemVOS(handlingGroupUserAmountItemVOS);
|
||||
|
@ -72,4 +72,6 @@ public interface HandlingGroupUserAmountMapper extends BaseMapperX<HandlingGroup
|
||||
* @return
|
||||
*/
|
||||
List<HandlingGroupUserAmountDO> getByHandlingGroupAmountSpecificationsId(@Param("handlingGroupAmountSpecificationsIds") List<Long> handlingGroupAmountSpecificationsIds);
|
||||
|
||||
List<HandlingGroupUserAmountDO> getByHandlingGroupIds(@Param("handlingGroupIds") List<Long> handlingGroupIds);
|
||||
}
|
||||
|
@ -7,8 +7,10 @@ import cn.iocoder.yudao.module.smartfactory.controller.admin.handlinggroup.vo.Ha
|
||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.handlinggroupamountspecifications.dto.HandlingGroupAmountSpecificationsTotalNumDTO;
|
||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.handlinggroupamountspecifications.vo.*;
|
||||
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.handlinggroupamountspecifications.HandlingGroupAmountSpecificationsDO;
|
||||
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.handlinggroupuseramount.HandlingGroupUserAmountDO;
|
||||
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.handlingspecifications.HandlingSpecificationsDO;
|
||||
import cn.iocoder.yudao.module.smartfactory.dal.mysql.handlinggroupamountspecifications.HandlingGroupAmountSpecificationsMapper;
|
||||
import cn.iocoder.yudao.module.smartfactory.service.handlinggroupuseramount.HandlingGroupUserAmountService;
|
||||
import cn.iocoder.yudao.module.smartfactory.service.handlingspecifications.HandlingSpecificationsService;
|
||||
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
||||
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
||||
@ -41,6 +43,8 @@ public class HandlingGroupAmountSpecificationsServiceImpl implements HandlingGro
|
||||
private HandlingGroupAmountSpecificationsMapper handlingGroupAmountSpecificationsMapper;
|
||||
@Resource
|
||||
private HandlingSpecificationsService handlingSpecificationsService;
|
||||
@Resource
|
||||
private HandlingGroupUserAmountService handlingGroupUserAmountService;
|
||||
|
||||
@Resource
|
||||
private AdminUserApi userApi;
|
||||
@ -64,8 +68,7 @@ public class HandlingGroupAmountSpecificationsServiceImpl implements HandlingGro
|
||||
@Override
|
||||
public PageResult<HandlingGroupAmountSpecificationsDO> getHandlingGroupAmountSpecificationsPage(HandlingGroupAmountSpecificationsPageReqVO pageReqVO) {
|
||||
// 判断当前登录人是否属于工厂主管
|
||||
AdminUserRespDTO userRespDTO = userApi.getUser(getLoginUserId()).getCheckedData();
|
||||
List<DeptRespDTO> deptRespDTOS = deptApi.getDeptByLeaderId(userRespDTO.getDeptId()).getCheckedData();
|
||||
List<DeptRespDTO> deptRespDTOS = deptApi.getDeptByLeaderId(getLoginUserId()).getCheckedData();
|
||||
if (CollUtil.isNotEmpty(deptRespDTOS)) {
|
||||
pageReqVO.setFactoryIds(deptRespDTOS.stream().map(DeptRespDTO::getFactoryId).distinct().collect(Collectors.toList()));
|
||||
}
|
||||
@ -152,17 +155,21 @@ public class HandlingGroupAmountSpecificationsServiceImpl implements HandlingGro
|
||||
|
||||
@Override
|
||||
public void batchDelete(HandlingGroupAmountSpecificationsBatchDelVO vo) {
|
||||
handlingGroupAmountSpecificationsMapper.delete(new LambdaQueryWrapper<HandlingGroupAmountSpecificationsDO>()
|
||||
List<HandlingGroupAmountSpecificationsDO> list = handlingGroupAmountSpecificationsMapper.selectList(new LambdaQueryWrapper<HandlingGroupAmountSpecificationsDO>()
|
||||
.eq(HandlingGroupAmountSpecificationsDO::getFactoryId, vo.getFactoryId())
|
||||
.eq(HandlingGroupAmountSpecificationsDO::getHandlingGroupId, vo.getHandlingGroupId())
|
||||
.eq(HandlingGroupAmountSpecificationsDO::getDateStr, vo.getDateStr()));
|
||||
}
|
||||
List<Long> ids = list.stream().map(HandlingGroupAmountSpecificationsDO::getId).collect(Collectors.toList());
|
||||
handlingGroupAmountSpecificationsMapper.deleteBatchIds(ids);
|
||||
|
||||
handlingGroupUserAmountService.remove(new LambdaQueryWrapper<HandlingGroupUserAmountDO>()
|
||||
.in(HandlingGroupUserAmountDO::getHandlingGroupAmountSpecificationsId, ids)
|
||||
);
|
||||
}
|
||||
@Override
|
||||
public HandlingGroupAmountSpecificationsTotalNumVO getTotalNum(HandlingGroupAmountSpecificationsTotalNumDTO dto) {
|
||||
// 判断当前登录人是否属于工厂主管
|
||||
AdminUserRespDTO userRespDTO = userApi.getUser(getLoginUserId()).getCheckedData();
|
||||
List<DeptRespDTO> deptRespDTOS = deptApi.getDeptByLeaderId(userRespDTO.getDeptId()).getCheckedData();
|
||||
List<DeptRespDTO> deptRespDTOS = deptApi.getDeptByLeaderId(getLoginUserId()).getCheckedData();
|
||||
if (CollUtil.isNotEmpty(deptRespDTOS)) {
|
||||
dto.setFactoryIds(deptRespDTOS.stream().map(DeptRespDTO::getFactoryId).distinct().collect(Collectors.toList()));
|
||||
}
|
||||
|
@ -95,4 +95,6 @@ public interface HandlingGroupUserAmountService extends IService<HandlingGroupUs
|
||||
* @return
|
||||
*/
|
||||
List<HandlingGroupUserAmountDO> getByHandlingGroupAmountSpecificationsId(List<Long> handlingGroupAmountSpecificationsIds);
|
||||
|
||||
List<HandlingGroupUserAmountDO> getByHandlingGroupIds(List<Long> handlingGroupIds);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.smartfactory.service.handlinggroupuseramount;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils;
|
||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.handlinggroupuseramount.dto.StaffWagesPageDTO;
|
||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.handlinggroupuseramount.vo.*;
|
||||
@ -80,6 +81,7 @@ public class HandlingGroupUserAmountServiceImpl extends ServiceImpl<HandlingGrou
|
||||
// 插入
|
||||
createReqVO.setFactoryId(handlingGroupAmountSpecificationsDO.getFactoryId());
|
||||
HandlingGroupUserAmountDO handlingGroupUserAmount = BeanUtils.toBean(createReqVO, HandlingGroupUserAmountDO.class);
|
||||
handlingGroupUserAmount.setHandlingGroupId(handlingGroupAmountSpecificationsDO.getHandlingGroupId());
|
||||
handlingGroupUserAmountMapper.insertOrUpdate(handlingGroupUserAmount);
|
||||
}
|
||||
|
||||
@ -144,5 +146,10 @@ public class HandlingGroupUserAmountServiceImpl extends ServiceImpl<HandlingGrou
|
||||
return handlingGroupUserAmountMapper.getByHandlingGroupAmountSpecificationsId(handlingGroupAmountSpecificationsIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HandlingGroupUserAmountDO> getByHandlingGroupIds(List<Long> handlingGroupIds) {
|
||||
return handlingGroupUserAmountMapper.getByHandlingGroupIds(handlingGroupIds);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -21,10 +21,6 @@
|
||||
LEFT JOIN sf_handling_specifications AS b ON a.handling_specifications_id = b.id
|
||||
LEFT JOIN sf_staff AS c ON c.id = a.staff_id
|
||||
left join sf_handling_group as d on a.handling_group_id = d.id
|
||||
<if test="vo.porterName != null and vo.porterName != ''">
|
||||
left join sf_handling_group_user_amount as e on a.id = e.handling_group_amount_specifications_id
|
||||
left join sf_staff as g on g.id = e.user_id
|
||||
</if>
|
||||
<where>
|
||||
a.deleted = 0
|
||||
and b.deleted = 0
|
||||
@ -47,7 +43,13 @@
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="vo.porterName != null and vo.porterName != ''">
|
||||
and g.nick_name like concat('%', #{vo.porterName}, '%')
|
||||
AND EXISTS (
|
||||
select e.id from sf_handling_group_user_amount as e
|
||||
left join sf_staff as g on g.id = e.user_id
|
||||
where a.id = e.handling_group_amount_specifications_id
|
||||
and g.nick_name like concat('%', #{vo.porterName}, '%')
|
||||
and e.deleted = 0
|
||||
)
|
||||
</if>
|
||||
<if test="vo.createTime != null and vo.createTime.length > 0">
|
||||
<if test="vo.createTime[0] != null">
|
||||
@ -58,9 +60,6 @@
|
||||
</if>
|
||||
</if>
|
||||
</where>
|
||||
<if test="vo.porterName != null and vo.porterName != ''">
|
||||
group by a.id
|
||||
</if>
|
||||
</select>
|
||||
<select id="getHandlingGroupAmountSpecifications"
|
||||
resultType="cn.iocoder.yudao.module.smartfactory.dal.dataobject.handlinggroupamountspecifications.HandlingGroupAmountSpecificationsDO">
|
||||
@ -107,8 +106,6 @@
|
||||
sum(a.amount) as amount
|
||||
from sf_handling_group_amount_specifications AS a
|
||||
left join sf_staff as b on a.staff_id = b.id
|
||||
left join sf_handling_group_user_amount as c on a.id = c.handling_group_amount_specifications_id
|
||||
left join sf_staff as d on d.id = c.user_id
|
||||
<where>
|
||||
a.deleted = 0
|
||||
<if test="dto.factoryId != null">
|
||||
@ -127,7 +124,17 @@
|
||||
and b.nick_name like concat('%', #{dto.forkliftDriverName}, '%')
|
||||
</if>
|
||||
<if test="dto.porterName != null and dto.porterName != ''">
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
c.id
|
||||
FROM
|
||||
sf_handling_group_user_amount AS c
|
||||
LEFT JOIN sf_staff AS d ON d.id = c.user_id
|
||||
WHERE
|
||||
c.deleted = 0
|
||||
and a.id = c.handling_group_amount_specifications_id
|
||||
and d.nick_name like concat('%', #{dto.porterName}, '%')
|
||||
)
|
||||
</if>
|
||||
<if test="dto.createTime != null and dto.createTime.length > 0">
|
||||
<if test="dto.createTime[0] != null">
|
||||
|
@ -149,4 +149,21 @@
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="getByHandlingGroupIds"
|
||||
resultType="cn.iocoder.yudao.module.smartfactory.dal.dataobject.handlinggroupuseramount.HandlingGroupUserAmountDO">
|
||||
select a.*,
|
||||
b.nick_name as userName
|
||||
FROM sf_handling_group_user_amount as a
|
||||
LEFT JOIN sf_staff as b on a.user_id = b.id
|
||||
<where>
|
||||
a.deleted = 0
|
||||
and b.deleted = 0
|
||||
<if test="handlingGroupIds != null and handlingGroupIds.size() > 0">
|
||||
and a.handling_group_id in
|
||||
<foreach collection="handlingGroupIds" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
||||
|
Loading…
Reference in New Issue
Block a user