Compare commits

..

No commits in common. "91515b24e8bc4c8a6c5c97fca746833fc44a9882" and "a89936cb7036c91c1545bbbcd91d4922e6b6c950" have entirely different histories.

9 changed files with 9 additions and 958 deletions

View File

@ -508,81 +508,4 @@ public class MaterialMachineController extends BaseController {
ExcelUtil<MaterialStorageAndUseNumInfo> util = new ExcelUtil<>(MaterialStorageAndUseNumInfo.class);
util.exportExcel(response, list, "综合查询--材料站设备保有量查询");
}
/**
* 供需平衡数据查询
* @param bean
* @return
*/
@ApiOperation(value = "综合查询--材料站供应需求平衡数据查询")
@GetMapping("/getDemandAndSupply")
public AjaxResult getDemandAndSupply(MaterialRetainedEquipmentInfo bean) {
bean.setIsExport(1);
Integer pageIndex = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
Integer pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
List<MaterialProvideNumInfo> list = materialMachineService.getDemandAndSupply(bean);
return AjaxResult.success(ListPagingUtil.paging(pageIndex, pageSize, list));
}
/**
* 供需平衡数据查询不带分页
* @param bean
* @return
*/
@ApiOperation(value = "综合查询--材料站供应需求平衡数据查询不带分页")
@GetMapping("/getDemandAndSupplyNoPage")
public AjaxResult getDemandAndSupplyNoPage(MaterialRetainedEquipmentInfo bean) {
bean.setIsExport(0);
List<MaterialProvideNumInfo> list = materialMachineService.getDemandAndSupply(bean);
MaterialProvideNumInfo dto = new MaterialProvideNumInfo();
if (CollectionUtils.isNotEmpty(list)) {
MaterialProvideNumInfo retainedEquipmentInfo = list.get(0);
dto.setBusinessNum(retainedEquipmentInfo.getBusinessNum());
dto.setSupplyNum(retainedEquipmentInfo.getSupplyNum());
dto.setStoreNum(retainedEquipmentInfo.getStoreNum());
dto.setUseNum(retainedEquipmentInfo.getUseNum());
}
return AjaxResult.success(dto);
}
/**
* 导出材料站设备保有量查询
* @param response
* @param bean
*/
@ApiOperation(value = "综合查询--材料站供应需求平衡数据查询")
@PostMapping("/exportDemandAndSupply")
public void exportDemandAndSupply(HttpServletResponse response, MaterialRetainedEquipmentInfo bean) {
bean.setIsExport(0);
List<MaterialProvideNumInfo> list = materialMachineService.getDemandAndSupply(bean);
ExcelUtil<MaterialProvideNumInfo> util = new ExcelUtil<>(MaterialProvideNumInfo.class);
util.exportExcel(response, list, "综合查询--材料站供应需求平衡数据查询");
}
/**
* 供需平衡数据在用二级页面查询
* @param bean
* @return
*/
@ApiOperation(value = "综合查询--材料站供应需求平衡数据在用二级页面查询")
@GetMapping("/getUseDemandAndSupply")
public AjaxResult getUseDemandAndSupply(MaterialRetainedEquipmentInfo bean) {
startPage();
List<MaterialSecondInfo> list = materialMachineService.getUseDemandAndSupply(bean);
return AjaxResult.success(getDataTable(list));
}
/**
* 导出供需平衡数据在用二级页面查询
* @param response
* @param bean
*/
@ApiOperation(value = "综合查询--材料站供应需求平衡数据在用二级页面查询")
@PostMapping("/exportUseDemandAndSupply")
public void exportUseDemandAndSupply(HttpServletResponse response, MaterialRetainedEquipmentInfo bean) {
bean.setIsExport(0);
List<MaterialSecondInfo> list = materialMachineService.getUseDemandAndSupply(bean);
ExcelUtil<MaterialSecondInfo> util = new ExcelUtil<>(MaterialSecondInfo.class);
util.exportExcel(response, list, "综合查询--材料站供应需求平衡数据在用二级页面查询");
}
}

View File

@ -1,188 +0,0 @@
package com.bonus.material.clz.domain.vo;
import com.bonus.common.core.annotation.Excel;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* @description 综合查询--材料站供应需求vo
* @author ma_sh
* @date 2024/2/26 14:51
*/
@ApiModel(description = "材料站供应需求vo")
@Data
public class MaterialProvideNumInfo {
private static final long serialVersionUID = 2227217051604273598L;
@ApiModelProperty(value = "是否app 0 是1 否")
private Integer isApp;
@ApiModelProperty(value = "是否导出 0 是1 否")
private Integer isExport;
@ApiModelProperty(value = "主键id")
private Integer id;
@ApiModelProperty(value = "工程id")
private String proId;
@ApiModelProperty(value = "分公司")
private String impUnitName;
@ApiModelProperty(value = "项目部")
private String departName;
@ApiModelProperty(value = "工程名称")
@Excel(name = "工程名称", width = 50)
private String proName;
@ApiModelProperty(value = "施工类型")
private String constructionType;
@ApiModelProperty(value = "物资类型")
private String materialType;
@ApiModelProperty(value = "物资名称")
@Excel(name = "物资名称")
private String typeName;
@ApiModelProperty(value = "规格ID")
private Integer typeId;
@ApiModelProperty(value = "规格型号")
@Excel(name = "规格型号")
private String typeModelName;
@ApiModelProperty(value = "机具类型")
private String jiJuType;
@ApiModelProperty(value = "计量单位")
@Excel(name = "计量单位")
private String unit;
@ApiModelProperty(value = "业务需求数量")
@Excel(name = "业务需求数量",align = HorizontalAlignment.RIGHT)
private BigDecimal businessNum;
@ApiModelProperty(value = "实际供应数量")
@Excel(name = "实际供应数量",align = HorizontalAlignment.RIGHT)
private BigDecimal supplyNum;
@ApiModelProperty(value = "在库数量")
@Excel(name = "在库数量",align = HorizontalAlignment.RIGHT)
private BigDecimal storeNum;
@ApiModelProperty(value = "在用数量")
@Excel(name = "在用数量",align = HorizontalAlignment.RIGHT)
private BigDecimal useNum;
@ApiModelProperty(value = "数量")
private BigDecimal allNum;
@ApiModelProperty(value = "购置单价")
private BigDecimal buyPrice;
@ApiModelProperty(value = "管理模式")
private String manageType;
@ApiModelProperty(value = "创建者")
private String createBy;
@ApiModelProperty(value = "创建时间")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
@ApiModelProperty(value = "更新者")
private String updateBy;
@ApiModelProperty(value = "更新时间 ")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
@ApiModelProperty(value = "关键字")
private String keyWord;
@ApiModelProperty(value = "一级类型id")
private Integer firstTypeId;
@ApiModelProperty(value = "二级类型id")
private Integer secondTypeId;
@ApiModelProperty(value = "三级类型id")
private Integer thirdTypeId;
/**
* 是否伸展APP
*/
private boolean expanded = false;
private String maCode;
/** 本次检验日期 */
@ApiModelProperty(value = "本次检验日期")
@DateTimeFormat(pattern="yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd")
private Date thisCheckTime;
/** 下次检验日期 */
@ApiModelProperty(value = "下次检验日期")
@DateTimeFormat(pattern="yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd")
private Date nextCheckTime;
/**
* 状态(0 =正常1= 3个月检测到期2= 1个月检测到期3= 已过期)
*/
private String status;
@ApiModelProperty(value = "班组id")
private String teamId;
/**
* 班组长账号
*/
private String teamLeaderIdCard;
@ApiModelProperty(value = "i8工程id")
private String externalId;
@ApiModelProperty(value = "身份证号码")
private String idCard;
@ApiModelProperty(value = "实施单位id")
private String impUnit;
/**
* i8工程id集合
*/
private List<String> projectIdList;
private Long maId;
private Long deptId;
@ApiModelProperty(value = "项目部名称")
private String proCenter;
@ApiModelProperty(value = "物资类型")
private String materialName;
@ApiModelProperty(value = "开始时间")
private String startTime;
@ApiModelProperty(value = "结束时间")
private String endTime;
private String unitValue;
}

View File

@ -73,7 +73,7 @@ public class MaterialRetainedEquipmentInfo {
@Excel(name = "规格型号")
private String typeModelName;
@ApiModelProperty("机具类型1机具2安全工器具")
@ApiModelProperty(value = "机具类型")
@Excel(name = "机具类型")
private String jiJuType;
@ -250,7 +250,6 @@ public class MaterialRetainedEquipmentInfo {
@ApiModelProperty(value = "结束时间")
private String endTime;
@ApiModelProperty(value = "0整型 1小数")
private String unitValue;
private String unitType;

View File

@ -1,173 +0,0 @@
package com.bonus.material.clz.domain.vo;
import com.bonus.common.core.annotation.Excel;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal;
import java.util.Date;
/**
* @description 综合查询--供应在用二级页面查询
* @author ma_sh
* @date 2024/2/26 14:51
*/
@ApiModel(description = "供应在用二级页面查询")
@Data
public class MaterialSecondInfo {
private static final long serialVersionUID = 2227217051604273598L;
@ApiModelProperty(value = "主键id")
private Integer id;
@ApiModelProperty(value = "工程id")
private String proId;
@ApiModelProperty(value = "分公司")
private String impUnitName;
@ApiModelProperty(value = "项目部")
private String departName;
@ApiModelProperty(value = "项目部id")
private String departId;
@ApiModelProperty(value = "工程名称")
private String proName;
@ApiModelProperty(value = "分包单位")
@Excel(name = "分包单位", width = 25)
private String subUnitName;
@ApiModelProperty(value = "班组名称")
@Excel(name = "班组名称")
private String teamName;
@ApiModelProperty(value = "物资名称")
@Excel(name = "物资名称")
private String typeName;
@ApiModelProperty(value = "规格ID")
private Integer typeId;
@ApiModelProperty(value = "规格型号")
@Excel(name = "规格型号")
private String typeModelName;
@ApiModelProperty(value = "机具类型")
private String jiJuType;
@ApiModelProperty(value = "计量单位")
private String unit;
@ApiModelProperty(value = "领用数量")
@Excel(name = "领用数量", align = HorizontalAlignment.RIGHT)
private BigDecimal leaseNum;
@ApiModelProperty(value = "退料数量")
@Excel(name = "退料数量", align = HorizontalAlignment.RIGHT)
private BigDecimal backNum;
@ApiModelProperty(value = "在用数量")
@Excel(name = "在用数量", align = HorizontalAlignment.RIGHT)
private BigDecimal useNum;
@ApiModelProperty(value = "购置单价")
private BigDecimal buyPrice;
@ApiModelProperty(value = "管理模式")
private String manageType;
@ApiModelProperty(value = "创建者")
private String createBy;
@ApiModelProperty(value = "创建时间")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
@ApiModelProperty(value = "更新者")
private String updateBy;
@ApiModelProperty(value = "更新时间 ")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
@ApiModelProperty(value = "关键字")
private String keyWord;
@ApiModelProperty(value = "数据所属组织")
private Integer companyId;
/**
* 是否伸展APP
*/
private boolean expanded = false;
/** 本次检验日期 */
@ApiModelProperty(value = "本次检验日期")
@DateTimeFormat(pattern="yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd")
private Date thisCheckTime;
/** 下次检验日期 */
@ApiModelProperty(value = "下次检验日期")
@DateTimeFormat(pattern="yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd")
private Date nextCheckTime;
/**
* 状态(0 =正常1= 3个月检测到期2= 1个月检测到期3= 已过期)
*/
private String status;
@ApiModelProperty(value = "班组id")
private String teamId;
/**
* 班组长账号
*/
private String teamLeaderIdCard;
@ApiModelProperty(value = "i8工程id")
private String externalId;
@ApiModelProperty(value = "身份证号码")
private String idCard;
@ApiModelProperty(value = "实施单位id")
private String impUnit;
private Long maId;
@ApiModelProperty(value = "领料人")
private String leasePerson;
@ApiModelProperty(value = "协议id")
private Long agreementId;
private Long deptId;
@ApiModelProperty(value = "项目部名称")
private String proCenter;
@ApiModelProperty(value = "物资类型")
private String materialName;
@ApiModelProperty(value = "开始时间")
private String startTime;
@ApiModelProperty(value = "结束时间")
private String endTime;
private String unitValue;
private String unitType;
}

View File

@ -7,10 +7,8 @@ import com.bonus.material.clz.domain.vo.*;
import com.bonus.material.ma.domain.Machine;
import com.bonus.material.clz.domain.BmTeam;
import com.bonus.material.clz.domain.machine.MaterialStorageInfo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* @Author ma_sh
@ -264,46 +262,4 @@ public interface MaterialMachineMapper {
List<MaterialStorageAndUseNumInfo> getStoreNumAndUseList(MaterialRetainedEquipmentInfo bean);
List<MaterialRetainedEquipmentInfo> getPickDepartList(MaterialRetainedEquipmentInfo bean);
/**
* 供需平衡数据查询
* @param bean
* @return
*/
List<MaterialProvideNumInfo> getDemandAndSupply(MaterialRetainedEquipmentInfo bean);
/**
* 获取领料需求量
* @param record
* @return
*/
MaterialProvideNumInfo getLeaseDemandNum(MaterialProvideNumInfo record);
/**
* 获取领用需求量
* @param record
* @return
*/
MaterialProvideNumInfo getUseDemandNum(MaterialProvideNumInfo record);
/**
* 供需平衡数据在用二级页面查询
* @param bean
* @return
*/
List<MaterialSecondInfo> getUseDemandAndSupply(MaterialRetainedEquipmentInfo bean);
/**
* 批量查询领料需求量
* @param queryParams
* @return
*/
List<MaterialProvideNumInfo> batchQueryLeaseDemand(@Param("list") List<Map<String, Object>> queryParams);
/**
* 批量查询领用数据
* @param queryParams
* @return
*/
List<MaterialProvideNumInfo> batchQueryUseDemand(@Param("list") List<Map<String, Object>> queryParams);
}

View File

@ -184,18 +184,4 @@ public interface MaterialMachineService {
List<MaterialStorageAndUseNumInfo> getStoreNumAndUseList(MaterialRetainedEquipmentInfo bean);
List<MaterialRetainedEquipmentInfo> getPickDepartList(MaterialRetainedEquipmentInfo bean);
/**
* 供需平衡数据查询
* @param bean
* @return
*/
List<MaterialProvideNumInfo> getDemandAndSupply(MaterialRetainedEquipmentInfo bean);
/**
* 供需平衡数据在用二级页面查询
* @param bean
* @return
*/
List<MaterialSecondInfo> getUseDemandAndSupply(MaterialRetainedEquipmentInfo bean);
}

View File

@ -1153,6 +1153,14 @@ public class MaterialLeaseInfoServiceImpl implements MaterialLeaseInfoService {
materialLeaseInfoMapper.deleteLeaseApplyDetailsByParentIds(id);
// 业务逻辑代码,删除lease_out_details
materialLeaseInfoMapper.deleteById(id);
/*for (MaterialLeaseApplyDetails leaseApplyDetails : leaseApplyRequestVo.getLeaseApplyDetailsList()) {
if (!CollectionUtils.isEmpty(leaseApplyDetails.getMaCodeList())) {
for (MaterialLeaseMaCodeDto leaseMaCodeDto : leaseApplyDetails.getMaCodeList()) {
// 根据maId将设备改为在库状态
machineMapper.updateStatus(leaseMaCodeDto.getMaId(), MaMachineStatusEnum.IN_STORE.getStatus());
}
}
}*/
insertPurchaseCheckDetails(createBy, leaseApplyInfo.getTaskId(), leaseApplyRequestVo.getLeaseApplyDetailsList(), leaseApplyInfo.getId(), leaseApplyRequestVo.getLeaseApplyInfo().getIsOut());
}

View File

@ -1291,139 +1291,6 @@ public class MaterialMachineServiceImpl implements MaterialMachineService {
return materialMachineMapper.getPickDepartList(bean);
}
/**
* 供需平衡数据查询
* @param bean
* @return
*/
@Override
public List<MaterialProvideNumInfo> getDemandAndSupply(MaterialRetainedEquipmentInfo bean) {
BigDecimal totalBusinessNum = BigDecimal.ZERO.setScale(3, RoundingMode.HALF_UP);
BigDecimal totalSupplyNum = BigDecimal.ZERO.setScale(3, RoundingMode.HALF_UP);
BigDecimal totalStoreNum = BigDecimal.ZERO.setScale(3, RoundingMode.HALF_UP);
BigDecimal totalUseNum = BigDecimal.ZERO.setScale(3, RoundingMode.HALF_UP);
String username = SecurityUtils.getLoginUser().getUsername();
// 根据用户名判断用户是否为班组长
BmTeam teamData = materialMachineMapper.getTeamData(username);
Set<String> userRoles = SecurityUtils.getLoginUser().getRoles();
// 检查用户是否具有特殊角色
boolean hasSpecialRole = hasSpecialRole(userRoles);
if (!hasSpecialRole) {
if (teamData == null) {
// 根据用户名查询项目部信息
List<String> departId = mapper.getDepartId(username);
if (CollectionUtils.isNotEmpty(departId)) {
// 根据项目部id查询工程信息
List<String> projectIdList = mapper.getProjectId(departId);
if (!org.springframework.util.CollectionUtils.isEmpty(projectIdList)) {
bean.setProjectIdList(projectIdList);
}
}
}
// 部门查询赋值
extractedDept(bean);
}
List<MaterialProvideNumInfo> recordList = materialMachineMapper.getDemandAndSupply(bean);
if (CollectionUtils.isEmpty(recordList)) {
return recordList;
}
// 1. 过滤数据保留原逻辑使用并行流加速大集合过滤
if (teamData != null) {
recordList = recordList.parallelStream() // 并行流适合大集合过滤
.filter(item -> StringUtils.isBlank(item.getIdCard()) || username.equals(item.getIdCard()))
.collect(Collectors.toList());
}
// 2. 提取批量查询的关键参数工程ID + typeId避免重复创建对象
List<Map<String, Object>> queryParams = recordList.stream()
.map(record -> {
Map<String, Object> param = new HashMap<>(2);
param.put("proId", record.getProId());
param.put("typeId", record.getTypeId());
return param;
})
.collect(Collectors.toList());
// 3. 批量查询核心优化2次查询替代N次循环查询减少99%+的数据库交互
// 3.1 批量查询领料数据构建映射key=projectId_typeIdvalue=businessNum
Map<String, BigDecimal> leaseBusinessMap = materialMachineMapper.batchQueryLeaseDemand(queryParams).stream()
.collect(Collectors.toMap(
info -> getCompositeKey(info.getProId(), info.getTypeId()), // 抽成方法避免重复代码
MaterialProvideNumInfo::getBusinessNum,
(existing, replacement) -> existing // 重复key保留第一个按业务需求调整
));
// 3.2 批量查询领用数据构建映射
Map<String, BigDecimal> publishBusinessMap = materialMachineMapper.batchQueryUseDemand(queryParams).stream()
.collect(Collectors.toMap(
info -> getCompositeKey(info.getProId(), info.getTypeId()),
MaterialProvideNumInfo::getBusinessNum,
(existing, replacement) -> existing
));
// 4. 并行流处理大集合计算总和并设置record的businessNum内存操作并行化
// 用数组存储四个总和比对象更高效减少gc
BigDecimal[] totals = new BigDecimal[4];
Arrays.fill(totals, BigDecimal.ZERO);
recordList.parallelStream().forEach(record -> {
String key = getCompositeKey(record.getProId(), record.getTypeId());
// 从Map获取数据默认0避免null
BigDecimal leaseNum = leaseBusinessMap.getOrDefault(key, BigDecimal.ZERO);
BigDecimal publishNum = publishBusinessMap.getOrDefault(key, BigDecimal.ZERO);
BigDecimal businessNum = leaseNum.add(publishNum);
// 设置record的businessNum原逻辑保留
record.setBusinessNum(businessNum);
// 累加总和用同步块保证线程安全并行流必加
synchronized (totals) {
totals[0] = totals[0].add(businessNum);
totals[1] = totals[1].add(record.getSupplyNum());
totals[2] = totals[2].add(record.getStoreNum());
totals[3] = totals[3].add(record.getUseNum());
}
});
// 5. 赋值最终结果
totalBusinessNum = totals[0];
totalSupplyNum = totals[1];
totalStoreNum = totals[2];
totalUseNum = totals[3];
if (bean.getIsExport() == 0) {
MaterialProvideNumInfo info = new MaterialProvideNumInfo();
info.setBusinessNum(totalBusinessNum);
info.setSupplyNum(totalSupplyNum);
info.setStoreNum(totalStoreNum);
info.setUseNum(totalUseNum);
info.setUnit("合计");
recordList.add(0, info);
}
return recordList;
}
/**
* 工具方法生成projectId_typeId的复合key抽成方法避免重复代码
* @param projectId
* @param typeId
* @return
*/
private String getCompositeKey(Object projectId, Object typeId) {
return projectId + "_" + typeId;
}
/**
* 供需平衡数据在用二级页面查询
* @param bean
* @return
*/
@Override
public List<MaterialSecondInfo> getUseDemandAndSupply(MaterialRetainedEquipmentInfo bean) {
return materialMachineMapper.getUseDemandAndSupply(bean);
}
/**
* 设置分公司名称如果有
* @param impUnit

View File

@ -1972,331 +1972,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
WHERE
bp.external_id = #{proId}
</select>
<select id="getDemandAndSupply" resultType="com.bonus.material.clz.domain.vo.MaterialProvideNumInfo">
SELECT
mt.type_id AS typeId,
mt4.type_name AS constructionType,
mt3.type_name AS materialType,
mt2.type_name AS typeName,
mt2.type_id AS thirdTypeId,
mt.type_name AS typeModelName,
mt.unit_name AS unit,
subquery1.proId AS proId,
subquery1.proName AS proName,
subquery1.externalId AS externalId,
subquery1.impUnit AS impUnit,
subquery3.idCard AS idCard,
CASE
WHEN IFNULL(subquery1.usNum, 0) - IFNULL(subquery3.usNum, 0) &lt; 0
THEN 0
ELSE IFNULL(subquery1.usNum, 0) - IFNULL(subquery3.usNum, 0)
END
AS storeNum,
IFNULL(subquery3.usNum, 0) AS useNum,
(
CASE
WHEN IFNULL(subquery1.usNum, 0) - IFNULL(subquery3.usNum, 0) &lt; 0
THEN 0
ELSE IFNULL(subquery1.usNum, 0) - IFNULL(subquery3.usNum, 0)
END + IFNULL(subquery3.usNum, 0)
) AS supplyNum,
subquery1.proCenter AS departName,
subquery1.departName AS impUnitName,
CASE mt.manage_type
WHEN 0 THEN
'编码'
ELSE
'数量'
END manageType,
mt.unit_value AS unitValue,
CASE mt.jiju_type
WHEN 2 THEN
'安全工器具'
ELSE
'施工机具'
END jiJuType
FROM ma_type mt
LEFT JOIN (
SELECT
mt.type_id,
mt4.type_name AS constructionType,
mt4.type_id AS firstTypeId,
mt3.type_name AS materialType,
mt3.type_id AS secondTypeId,
mt2.type_name AS typeName,
mt2.type_id AS thirdTypeId,
mt.type_name AS typeModelName,
SUM(IFNULL( sai.num, 0 )) AS usNum,
bp.pro_name as proName,
bp.pro_id as proId,
bp.external_id as externalId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard,
df.project_dept AS proCenter,
sd.dept_name AS departName
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 ma_type mt3 ON mt3.type_id = mt2.parent_id
LEFT JOIN ma_type mt4 ON mt4.type_id = mt3.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 bm_unit bu ON bai.unit_id = bu.unit_id
AND bu.del_flag = '0'
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN data_center.dx_fb_son df ON bp.external_id = df.id
WHERE
sai.`status` = '0'
AND sai.is_slt = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
AND bp.external_id IS NOT NULL
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name = #{impUnitName}
</if>
<if test="proName != null and proName != ''">
AND bp.pro_name = #{proName}
</if>
<if test="departName != null and departName != ''">
AND bp.pro_center = #{departName}
</if>
<if test="typeName != null and typeName != ''">
AND mt2.type_name = #{typeName}
</if>
<if test="typeModelName != null and typeModelName != ''">
AND mt.type_name = #{typeModelName}
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
AND bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="impUnit != null and impUnit != ''">
AND bp.imp_unit = #{impUnit}
</if>
<if test="jiJuType != null and jiJuType != ''">
AND mt.jiju_type = #{jiJuType}
</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}, '%')
)
</if>
<if test="unitValue != null and unitValue != ''">
AND mt.unit_value = #{unitValue}
</if>
GROUP BY mt.type_id,
bp.pro_id
) AS subquery1 ON mt.type_id = subquery1.type_id
LEFT JOIN (
SELECT
mt.type_id,
mt4.type_name AS constructionType,
mt4.type_id AS firstTypeId,
mt3.type_name AS materialType,
mt3.type_id AS secondTypeId,
mt2.type_name AS typeName,
mt2.type_id AS thirdTypeId,
mt.type_name AS typeModelName,
SUM(IFNULL( sai.num, 0 )) AS usNum,
bp.pro_name as proName,
bp.pro_id as proId,
bp.external_id as externalId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard,
df.project_dept AS proCenter,
sd.dept_name AS departName
FROM
clz_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 ma_type mt3 ON mt3.type_id = mt2.parent_id
LEFT JOIN ma_type mt4 ON mt4.type_id = mt3.parent_id
LEFT JOIN clz_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 bm_unit bu ON bai.unit_id = bu.unit_id
AND bu.del_flag = '0'
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN data_center.dx_fb_son df ON bp.external_id = df.id
WHERE
sai.`status` = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name = #{impUnitName}
</if>
<if test="proName != null and proName != ''">
AND bp.pro_name = #{proName}
</if>
<if test="departName != null and departName != ''">
AND bp.pro_center = #{departName}
</if>
<if test="typeName != null and typeName != ''">
AND mt2.type_name = #{typeName}
</if>
<if test="typeModelName != null and typeModelName != ''">
AND mt.type_name = #{typeModelName}
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
AND bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="impUnit != null and impUnit != ''">
AND bp.imp_unit = #{impUnit}
</if>
<if test="jiJuType != null and jiJuType != ''">
AND mt.jiju_type = #{jiJuType}
</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}, '%')
)
</if>
<if test="unitValue != null and unitValue != ''">
AND mt.unit_value = #{unitValue}
</if>
GROUP BY mt.type_id,
bp.pro_id
) AS subquery3
ON mt.type_id = subquery3.type_id
AND subquery1.proId = subquery3.proId
LEFT JOIN ma_type mt2 on mt2.type_id = mt.parent_id
LEFT JOIN ma_type mt3 ON mt3.type_id = mt2.parent_id
LEFT JOIN ma_type mt4 ON mt4.type_id = mt3.parent_id
WHERE mt.`level` = 4 and mt.del_flag = '0'
AND subquery1.proName IS NOT NULL
GROUP BY mt.type_id,
subquery1.proId
</select>
<select id="getLeaseDemandNum" resultType="com.bonus.material.clz.domain.vo.MaterialProvideNumInfo">
SELECT
IFNULL( sum( lad.pre_num ), 0 ) AS businessNum
FROM
lease_apply_info lai
LEFT JOIN lease_apply_details lad ON lai.id = lad.parent_id
LEFT JOIN tm_task tt ON tt.task_id = lai.task_id
LEFT JOIN tm_task_agreement tta on tta.task_id = lai.task_id
LEFT JOIN bm_agreement_info bagi on bagi.agreement_id = tta.agreement_id
AND bagi.`status` = '1'
LEFT JOIN bm_project bp on bp.pro_id = bagi.project_id
AND bp.del_flag = '0'
WHERE
tt.task_status IN (3, 4)
AND tt.task_type = 2
<if test="typeId != null ">
AND lad.type_id = #{typeId}
</if>
<if test="proId != null and proId != '' ">
AND bp.pro_id = #{proId}
</if>
</select>
<select id="getUseDemandNum" resultType="com.bonus.material.clz.domain.vo.MaterialProvideNumInfo">
select
IFNULL(sum(lpd.num),0) as businessNum
from
lease_publish_details lpd
<where>
<if test="typeId != null ">
AND lpd.type_id = #{typeId}
</if>
<if test="proId != null and proId != '' ">
AND lpd.project_id = #{proId}
</if>
</where>
</select>
<select id="getUseDemandAndSupply" resultType="com.bonus.material.clz.domain.vo.MaterialSecondInfo">
SELECT
bui.unit_name AS teamName,
bp.pro_name AS proName,
sai.type_id AS typeId,
mt1.type_name AS typeName,
mt.type_name AS typeModelName,
mt.unit_name AS unit,
SUM( sai.num ) AS leaseNum,
SUM( CASE WHEN sai.STATUS = 0 THEN sai.num ELSE 0 END ) AS useNum,
SUM( CASE WHEN sai.STATUS = 1 THEN sai.num ELSE 0 END ) AS backNum,
bz.ssfbdw AS subUnitName
FROM
clz_slt_agreement_info sai
LEFT JOIN clz_bm_agreement_info bai ON sai.agreement_id = bai.agreement_id
LEFT JOIN bm_project bp ON bp.pro_id = bai.project_id
LEFT JOIN bm_unit bui ON bui.unit_id = bai.unit_id
LEFT JOIN ma_type mt ON sai.type_id = mt.type_id
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
LEFT JOIN `micro-tool`.bzgl_bz bz ON bp.external_id = bz.project_id
AND bz.bzmc = bui.unit_name
WHERE
bp.pro_id = #{proId}
AND sai.type_id = #{typeId}
<if test="keyWord != null and keyWord != ''">
AND (
mt1.type_name LIKE CONCAT('%',#{keyWord},'%') OR
mt.type_name LIKE CONCAT('%',#{keyWord},'%') OR
bui.unit_name LIKE CONCAT('%',#{keyWord},'%') OR
bp.pro_name LIKE CONCAT('%',#{keyWord},'%') OR
bz.ssfbdw LIKE CONCAT('%',#{keyWord},'%')
)
</if>
GROUP BY
bp.pro_id,
sai.type_id,
bui.unit_name
</select>
<select id="batchQueryLeaseDemand" resultType="com.bonus.material.clz.domain.vo.MaterialProvideNumInfo">
<!-- 批量查询领料数据 -->
SELECT
bp.pro_id AS proId,
lad.type_id AS typeId,
IFNULL( sum( lad.pre_num ), 0 ) AS businessNum
FROM
lease_apply_info lai
LEFT JOIN lease_apply_details lad ON lai.id = lad.parent_id
LEFT JOIN tm_task tt ON tt.task_id = lai.task_id
LEFT JOIN tm_task_agreement tta on tta.task_id = lai.task_id
LEFT JOIN bm_agreement_info bagi on bagi.agreement_id = tta.agreement_id
AND bagi.`status` = '1'
LEFT JOIN bm_project bp on bp.pro_id = bagi.project_id
AND bp.del_flag = '0'
WHERE
tt.task_status IN (3, 4)
AND tt.task_type = 2
AND (bp.pro_id, lad.type_id) IN
<foreach collection="list" item="item" separator="," open="(" close=")">
(#{item.proId}, #{item.typeId})
</foreach>
GROUP BY
bp.pro_id,
lad.type_id
</select>
<select id="batchQueryUseDemand" resultType="com.bonus.material.clz.domain.vo.MaterialProvideNumInfo">
select
project_id AS proId,
type_id AS typeId,
IFNULL(sum(num),0) as businessNum
from
lease_publish_details
<where>
AND (project_id, type_id) IN
<foreach collection="list" item="item" separator="," open="(" close=")">
(#{item.proId}, #{item.typeId})
</foreach>
</where>
GROUP BY
project_id,
type_id
</select>
</mapper>