供应功能
This commit is contained in:
parent
90853274b2
commit
c6c6e37496
|
|
@ -654,45 +654,45 @@ public class ComplexQueryServiceImpl implements ComplexQueryService {
|
|||
// 1、查询工程对应的物资名称、型号、需求数量、已供数量
|
||||
List<ProjUsingRecord> list = complexQueryMapper.getStatisticsList(bean);
|
||||
|
||||
// 创建缓存Map,key为typeId,value为对应的库存信息
|
||||
Map<Long, RetainedEquipmentInfo> inventoryCache = new HashMap<>();
|
||||
// // 创建缓存Map,key为typeId,value为对应的库存信息
|
||||
// Map<Long, RetainedEquipmentInfo> inventoryCache = new HashMap<>();
|
||||
|
||||
for (ProjUsingRecord item : list) {
|
||||
// 2、计算需求数量,已供数量的差值
|
||||
BigDecimal needNum = new BigDecimal(item.getNeedNum());
|
||||
BigDecimal supplyNum = new BigDecimal(item.getSupplyNum());
|
||||
BigDecimal diffNum = needNum.subtract(supplyNum);
|
||||
item.setDiffNum(diffNum.toString());
|
||||
|
||||
// 3、查询该工程设备的在用数量
|
||||
ProjUsingRecord projUsingRecord3 = complexQueryMapper.getUsNum(item);
|
||||
if (projUsingRecord3 != null && projUsingRecord3.getUsNum() != null) {
|
||||
item.setUsNum(projUsingRecord3.getUsNum());
|
||||
} else {
|
||||
item.setUsNum(BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
// 4、根据typeId查询库存信息(使用缓存优化)
|
||||
Long typeId = Long.valueOf(item.getTypeId());
|
||||
|
||||
RetainedEquipmentInfo bean1 = inventoryCache.get(typeId);
|
||||
if (bean1 == null) {
|
||||
// 如果缓存中没有,则查询数据库并放入缓存
|
||||
bean1 = complexQueryMapper.selectInventory(item);
|
||||
inventoryCache.put(typeId, bean1);
|
||||
}
|
||||
|
||||
// 设置库存相关信息
|
||||
item.setStoreNum(bean1.getStoreNum());
|
||||
item.setRepairNum(bean1.getRepairNum());
|
||||
item.setAllUsNum(bean1.getUsNum());
|
||||
|
||||
// 使用三元运算符处理null值
|
||||
BigDecimal inputNum = bean1.getInputNum() != null ? bean1.getInputNum() : BigDecimal.ZERO;
|
||||
BigDecimal repairInputNum = bean1.getRepairInputNum() != null ? bean1.getRepairInputNum() : BigDecimal.ZERO;
|
||||
item.setInputNum(inputNum.add(repairInputNum));
|
||||
item.setAllNum(bean1.getAllNum());
|
||||
}
|
||||
// for (ProjUsingRecord item : list) {
|
||||
// // 2、计算需求数量,已供数量的差值
|
||||
// BigDecimal needNum = new BigDecimal(item.getNeedNum());
|
||||
// BigDecimal supplyNum = new BigDecimal(item.getSupplyNum());
|
||||
// BigDecimal diffNum = needNum.subtract(supplyNum);
|
||||
// item.setDiffNum(diffNum.toString());
|
||||
//
|
||||
// // 3、查询该工程设备的在用数量
|
||||
// ProjUsingRecord projUsingRecord3 = complexQueryMapper.getUsNum(item);
|
||||
// if (projUsingRecord3 != null && projUsingRecord3.getUsNum() != null) {
|
||||
// item.setUsNum(projUsingRecord3.getUsNum());
|
||||
// } else {
|
||||
// item.setUsNum(BigDecimal.ZERO);
|
||||
// }
|
||||
//
|
||||
// // 4、根据typeId查询库存信息(使用缓存优化)
|
||||
// Long typeId = Long.valueOf(item.getTypeId());
|
||||
//
|
||||
// RetainedEquipmentInfo bean1 = inventoryCache.get(typeId);
|
||||
// if (bean1 == null) {
|
||||
// // 如果缓存中没有,则查询数据库并放入缓存
|
||||
// bean1 = complexQueryMapper.selectInventory(item);
|
||||
// inventoryCache.put(typeId, bean1);
|
||||
// }
|
||||
//
|
||||
// // 设置库存相关信息
|
||||
// item.setStoreNum(bean1.getStoreNum());
|
||||
// item.setRepairNum(bean1.getRepairNum());
|
||||
// item.setAllUsNum(bean1.getUsNum());
|
||||
//
|
||||
// // 使用三元运算符处理null值
|
||||
// BigDecimal inputNum = bean1.getInputNum() != null ? bean1.getInputNum() : BigDecimal.ZERO;
|
||||
// BigDecimal repairInputNum = bean1.getRepairInputNum() != null ? bean1.getRepairInputNum() : BigDecimal.ZERO;
|
||||
// item.setInputNum(inputNum.add(repairInputNum));
|
||||
// item.setAllNum(bean1.getAllNum());
|
||||
// }
|
||||
return list;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
|||
|
|
@ -565,24 +565,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</select>
|
||||
<select id="getStatisticsList" resultType="com.bonus.material.basic.domain.ProjUsingRecord">
|
||||
SELECT
|
||||
typeId,
|
||||
proId,
|
||||
impUnitName,
|
||||
proName,
|
||||
typeName,
|
||||
modelName as typeModelName,
|
||||
unit,
|
||||
jiJuType,
|
||||
SUM(needNum) as needNum,
|
||||
SUM(outNum) as supplyNum
|
||||
|
||||
SUM(outNum) as supplyNum,
|
||||
SUM(outNum) - SUM(needNum) as diffNum
|
||||
FROM (
|
||||
-- 语句一的结果,作为outNum
|
||||
SELECT
|
||||
mt.type_id as typeId,
|
||||
bp.pro_id as proId,
|
||||
sd.dept_name AS impUnitName,
|
||||
bp.pro_name as proName,
|
||||
mt2.type_name as typeName,
|
||||
mt.type_name as modelName,
|
||||
mt.unit_name as unit,
|
||||
CASE mt.jiju_type
|
||||
WHEN 2 THEN
|
||||
'安全工器具'
|
||||
ELSE
|
||||
'施工机具'
|
||||
END jiJuType,
|
||||
SUM(sai.num) as outNum,
|
||||
0 as needNum
|
||||
FROM
|
||||
|
|
@ -591,6 +596,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
LEFT JOIN ma_type mt2 on mt2.type_id=mt.parent_id
|
||||
LEFT JOIN bm_agreement_info bai on sai.agreement_id=bai.agreement_id
|
||||
LEFT JOIN bm_project bp on bai.project_id=bp.pro_id
|
||||
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
|
||||
WHERE
|
||||
sai.lease_id is not null
|
||||
and bp.pro_name is not null
|
||||
|
|
@ -620,24 +626,34 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
SELECT
|
||||
mt.type_id as typeId,
|
||||
bp.pro_id as proId,
|
||||
sd.dept_name AS impUnitName,
|
||||
bp.pro_name as proName,
|
||||
mt2.type_name as typeName,
|
||||
mt.type_name as modelName,
|
||||
mt.unit_name as unit,
|
||||
CASE mt.jiju_type
|
||||
WHEN 2 THEN
|
||||
'安全工器具'
|
||||
ELSE
|
||||
'施工机具'
|
||||
END jiJuType,
|
||||
0 as outNum,
|
||||
SUM(lad.pre_num) as needNum
|
||||
FROM
|
||||
lease_apply_details lad
|
||||
LEFT JOIN lease_apply_info lai on lad.parent_id=lai.id
|
||||
LEFT JOIN tm_task tt on lai.task_id = tt.task_id
|
||||
LEFT JOIN tm_task_agreement tta on tt.task_id = tta.task_id
|
||||
LEFT JOIN bm_agreement_info bai on tta.agreement_id = bai.agreement_id
|
||||
LEFT JOIN ma_type mt on mt.type_id=lad.type_id
|
||||
LEFT JOIN ma_type mt2 on mt2.type_id=mt.parent_id
|
||||
LEFT JOIN bm_project bp on lai.project_id=bp.pro_id
|
||||
LEFT JOIN bm_project bp on bai.project_id=bp.pro_id
|
||||
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
|
||||
WHERE
|
||||
bp.pro_name is not null
|
||||
and mt.del_flag='0'
|
||||
and tt.task_type = '19'
|
||||
and tt.task_status in (1, 3, 4, 5)
|
||||
and mt.del_flag=0
|
||||
and tt.task_type = '2'
|
||||
and tt.task_status in (3, 4)
|
||||
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
|
||||
AND DATE_FORMAT( lad.create_time, '%Y-%m-%d' ) BETWEEN #{startTime} AND #{endTime}
|
||||
</if>
|
||||
|
|
@ -656,8 +672,58 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
and mt2.type_name like concat('%', #{typeName}, '%')
|
||||
</if>
|
||||
GROUP BY bp.pro_id, mt.type_id
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- 语句三的结果,作为needNum
|
||||
SELECT
|
||||
mt.type_id as typeId,
|
||||
bp.pro_id as proId,
|
||||
sd.dept_name AS impUnitName,
|
||||
bp.pro_name as proName,
|
||||
mt2.type_name as typeName,
|
||||
mt.type_name as modelName,
|
||||
mt.unit_name as unit,
|
||||
CASE mt.jiju_type
|
||||
WHEN 2 THEN
|
||||
'安全工器具'
|
||||
ELSE
|
||||
'施工机具'
|
||||
END jiJuType,
|
||||
0 as outNum,
|
||||
SUM(lpd.num) as needNum
|
||||
FROM
|
||||
lease_publish_details lpd
|
||||
LEFT JOIN lease_apply_info lai on lpd.parent_id=lai.id
|
||||
LEFT JOIN tm_task tt on lai.task_id = tt.task_id
|
||||
LEFT JOIN ma_type mt on mt.type_id=lpd.type_id
|
||||
LEFT JOIN ma_type mt2 on mt2.type_id=mt.parent_id
|
||||
LEFT JOIN bm_project bp on lai.project_id=bp.pro_id
|
||||
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
|
||||
WHERE
|
||||
bp.pro_name is not null
|
||||
and mt.del_flag='0'
|
||||
and tt.task_type = '19'
|
||||
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
|
||||
AND DATE_FORMAT( lpd.create_time, '%Y-%m-%d' ) BETWEEN #{startTime} AND #{endTime}
|
||||
</if>
|
||||
<if test="keyWord != null and keyWord != ''">
|
||||
and (
|
||||
mt2.type_name like concat('%', #{keyWord}, '%') or
|
||||
mt.type_name like concat('%', #{keyWord}, '%') or
|
||||
bp.pro_name like concat('%', #{keyWord}, '%') or
|
||||
mt.unit_name like concat('%', #{keyWord}, '%')
|
||||
)
|
||||
</if>
|
||||
<if test="proName != null and proName != ''">
|
||||
and bp.pro_name like concat('%', #{proName}, '%')
|
||||
</if>
|
||||
<if test="typeName != null and typeName != ''">
|
||||
and mt2.type_name like concat('%', #{typeName}, '%')
|
||||
</if>
|
||||
GROUP BY bp.pro_id, mt.type_id
|
||||
) combined
|
||||
GROUP BY typeId, proId
|
||||
GROUP BY proId,jiJuType
|
||||
ORDER BY proId
|
||||
</select>
|
||||
<select id="getUsNum" resultType="com.bonus.material.basic.domain.ProjUsingRecord">
|
||||
|
|
|
|||
Loading…
Reference in New Issue