This commit is contained in:
parent
cc09b903fb
commit
b2971abc78
|
|
@ -467,8 +467,6 @@ public class ComplexQueryController extends BaseController {
|
|||
@ApiOperation(value = "施工机具需求、供应分析统计表")
|
||||
@GetMapping("/getStatisticsList")
|
||||
public AjaxResult getStatisticsList(ProjUsingRecord bean) {
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
bean.setUserId(loginUser.getUserid());
|
||||
startPage();
|
||||
List<ProjUsingRecord> pageList = complexQueryService.getStatisticsList(bean);
|
||||
return AjaxResult.success(getDataTable(pageList));
|
||||
|
|
|
|||
|
|
@ -639,29 +639,43 @@ public class ComplexQueryServiceImpl implements ComplexQueryService {
|
|||
@Override
|
||||
public List<ProjUsingRecord> getStatisticsList(ProjUsingRecord bean) {
|
||||
try {
|
||||
//1、查询工程对应的物资名称、型号、需求数量、已供数量
|
||||
// 1、查询工程对应的物资名称、型号、需求数量、已供数量
|
||||
List<ProjUsingRecord> list = complexQueryMapper.getStatisticsList(bean);
|
||||
for (ProjUsingRecord item : list){
|
||||
//2、计算需求数量,已供数量的差值
|
||||
//使用 BigDecimal 处理小数运算
|
||||
|
||||
// 创建缓存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、查询该工程设备的在用数量
|
||||
|
||||
// 3、查询该工程设备的在用数量
|
||||
ProjUsingRecord projUsingRecord3 = complexQueryMapper.getUsNum(item);
|
||||
if (projUsingRecord3 != null && projUsingRecord3.getUsNum() != null){
|
||||
if (projUsingRecord3 != null && projUsingRecord3.getUsNum() != null) {
|
||||
item.setUsNum(projUsingRecord3.getUsNum());
|
||||
} else {
|
||||
BigDecimal usNum = BigDecimal.ZERO;
|
||||
item.setUsNum(usNum);
|
||||
item.setUsNum(BigDecimal.ZERO);
|
||||
}
|
||||
//4、根据typeId查询,总库存数量、总在修数量、总待入库数量、总保有量
|
||||
RetainedEquipmentInfo bean1 = complexQueryMapper.selectInventory(item);
|
||||
|
||||
// 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值
|
||||
|
||||
// 使用三元运算符处理null值
|
||||
BigDecimal inputNum = bean1.getInputNum() != null ? bean1.getInputNum() : BigDecimal.ZERO;
|
||||
BigDecimal repairInputNum = bean1.getRepairInputNum() != null ? bean1.getRepairInputNum() : BigDecimal.ZERO;
|
||||
item.setInputNum(inputNum.add(repairInputNum));
|
||||
|
|
|
|||
|
|
@ -508,16 +508,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</select>
|
||||
<select id="getStatisticsList" resultType="com.bonus.material.basic.domain.ProjUsingRecord">
|
||||
SELECT
|
||||
COALESCE(t1.typeId, t2.typeId) as typeId,
|
||||
COALESCE(t1.proId, t2.proId) as proId,
|
||||
COALESCE(t1.proName, t2.proName) as proName,
|
||||
COALESCE(t1.typeName, t2.typeName) as typeName,
|
||||
COALESCE(t1.modelName, t2.modelName) as typeModelName,
|
||||
COALESCE(t1.unit, t2.unit) as unit,
|
||||
COALESCE(t2.num, 0) as needNum, -- 语句二的num作为needNum
|
||||
COALESCE(t1.num, 0) as supplyNum -- 语句一的num作为outNum
|
||||
typeId,
|
||||
proId,
|
||||
proName,
|
||||
typeName,
|
||||
modelName as typeModelName,
|
||||
unit,
|
||||
SUM(needNum) as needNum,
|
||||
SUM(outNum) as supplyNum
|
||||
|
||||
FROM (
|
||||
-- 语句一的结果作为outNum
|
||||
-- 语句一的结果,作为outNum
|
||||
SELECT
|
||||
mt.type_id as typeId,
|
||||
bp.pro_id as proId,
|
||||
|
|
@ -525,7 +526,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
mt2.type_name as typeName,
|
||||
mt.type_name as modelName,
|
||||
mt.unit_name as unit,
|
||||
SUM(sai.num) as num
|
||||
SUM(sai.num) as outNum,
|
||||
0 as needNum
|
||||
FROM
|
||||
slt_agreement_info sai
|
||||
LEFT JOIN ma_type mt on mt.type_id=sai.type_id
|
||||
|
|
@ -554,9 +556,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
and mt2.type_name like concat('%', #{typeName}, '%')
|
||||
</if>
|
||||
GROUP BY bp.pro_id, mt.type_id
|
||||
) t1
|
||||
LEFT JOIN (
|
||||
-- 语句二的结果作为needNum
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- 语句二的结果,作为needNum
|
||||
SELECT
|
||||
mt.type_id as typeId,
|
||||
bp.pro_id as proId,
|
||||
|
|
@ -564,11 +567,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
mt2.type_name as typeName,
|
||||
mt.type_name as modelName,
|
||||
mt.unit_name as unit,
|
||||
SUM(lad.pre_num) as num
|
||||
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 tt on lai.task_id = tt.task_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
|
||||
|
|
@ -595,99 +599,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
and mt2.type_name like concat('%', #{typeName}, '%')
|
||||
</if>
|
||||
GROUP BY bp.pro_id, mt.type_id
|
||||
) t2 ON t1.typeId = t2.typeId AND t1.proId = t2.proId
|
||||
|
||||
UNION
|
||||
|
||||
SELECT
|
||||
COALESCE(t1.typeId, t2.typeId) as typeId,
|
||||
COALESCE(t1.proId, t2.proId) as proId,
|
||||
COALESCE(t1.proName, t2.proName) as proName,
|
||||
COALESCE(t1.typeName, t2.typeName) as typeName,
|
||||
COALESCE(t1.modelName, t2.modelName) as typeModelName,
|
||||
COALESCE(t1.unit, t2.unit) as unit,
|
||||
COALESCE(t2.num, 0) as needNum, -- 语句二的num作为needNum
|
||||
COALESCE(t1.num, 0) as supplyNum -- 语句一的num作为outNum
|
||||
FROM (
|
||||
-- 语句一的结果作为outNum
|
||||
SELECT
|
||||
mt.type_id as typeId,
|
||||
bp.pro_id as proId,
|
||||
bp.pro_name as proName,
|
||||
mt2.type_name as typeName,
|
||||
mt.type_name as modelName,
|
||||
mt.unit_name as unit,
|
||||
SUM(sai.num) as num
|
||||
FROM
|
||||
slt_agreement_info sai
|
||||
LEFT JOIN ma_type mt on mt.type_id=sai.type_id
|
||||
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
|
||||
WHERE
|
||||
sai.lease_id is not null
|
||||
and bp.pro_name is not null
|
||||
and mt.del_flag='0'
|
||||
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
|
||||
AND DATE_FORMAT( sai.start_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
|
||||
) t1
|
||||
RIGHT JOIN (
|
||||
-- 语句二的结果作为needNum
|
||||
SELECT
|
||||
mt.type_id as typeId,
|
||||
bp.pro_id as proId,
|
||||
bp.pro_name as proName,
|
||||
mt2.type_name as typeName,
|
||||
mt.type_name as modelName,
|
||||
mt.unit_name as unit,
|
||||
SUM(lad.pre_num) as num
|
||||
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 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
|
||||
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)
|
||||
<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>
|
||||
<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
|
||||
) t2 ON t1.typeId = t2.typeId AND t1.proId = t2.proId
|
||||
) combined
|
||||
GROUP BY typeId, proId
|
||||
ORDER BY proId
|
||||
</select>
|
||||
<select id="getUsNum" resultType="com.bonus.material.basic.domain.ProjUsingRecord">
|
||||
|
|
|
|||
Loading…
Reference in New Issue