综合查询

This commit is contained in:
bns_han 2024-02-27 18:44:28 +08:00
parent 3878c5a23f
commit b6de4c1d84
12 changed files with 904 additions and 0 deletions

View File

@ -0,0 +1,59 @@
package com.bonus.sgzb.material.controller;
import com.bonus.sgzb.common.core.utils.poi.ExcelUtil;
import com.bonus.sgzb.common.core.web.controller.BaseController;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.log.annotation.Log;
import com.bonus.sgzb.common.log.enums.BusinessType;
import com.bonus.sgzb.material.domain.BackRecord;
import com.bonus.sgzb.material.domain.ProjUsingRecord;
import com.bonus.sgzb.material.service.BackRecordService;
import com.bonus.sgzb.material.service.ProjUsingRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* @description 综合查询--工程机具使用查询
* @author hay
* @date 2024/2/26 14:15
*/
@Api(tags = "综合查询--工程机具使用查询")
@RestController
@RequestMapping("/projUsingRecord")
public class ProjUsingRecordController extends BaseController {
@Autowired
private ProjUsingRecordService projUsingRecordService;
/**
* 工程机具使用列表
*/
@ApiOperation(value = "综合查询--工程机具使用列表")
@GetMapping("/getProjUsingRecordList")
public AjaxResult getProjUsingRecordList(ProjUsingRecord bean) {
startPage();
List<ProjUsingRecord> list = projUsingRecordService.getProjUsingRecordList(bean);
return AjaxResult.success(getDataTable(list));
}
/**
* 导出综合查询工程机具使用列表
*/
@ApiOperation("导出综合查询工程机具使用列表")
@Log(title = "导出综合查询工程机具使用列表", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, ProjUsingRecord bean)
{
List<ProjUsingRecord> list = projUsingRecordService.getProjUsingRecordList(bean);
ExcelUtil<ProjUsingRecord> util = new ExcelUtil<ProjUsingRecord>(ProjUsingRecord.class);
util.exportExcel(response, list, "综合查询--工程机具使用");
}
}

View File

@ -0,0 +1,59 @@
package com.bonus.sgzb.material.controller;
import com.bonus.sgzb.common.core.utils.poi.ExcelUtil;
import com.bonus.sgzb.common.core.web.controller.BaseController;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.log.annotation.Log;
import com.bonus.sgzb.common.log.enums.BusinessType;
import com.bonus.sgzb.material.domain.ProjUsingRecord;
import com.bonus.sgzb.material.domain.StorageStatus;
import com.bonus.sgzb.material.service.ProjUsingRecordService;
import com.bonus.sgzb.material.service.StorageStatusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* @description 综合查询--机具仓储状态查询
* @author hay
* @date 2024/2/26 14:15
*/
@Api(tags = "综合查询--机具仓储状态查询")
@RestController
@RequestMapping("/storageStatus")
public class StorageStatusController extends BaseController {
@Autowired
private StorageStatusService storageStatusService;
/**
* 机具仓储状态查询列表
*/
@ApiOperation(value = "综合查询--机具仓储状态查询列表")
@GetMapping("/getStorageStatusList")
public AjaxResult getStorageStatusList(StorageStatus bean) {
startPage();
List<StorageStatus> list = storageStatusService.getStorageStatusList(bean);
return AjaxResult.success(getDataTable(list));
}
/**
* 导出综合查询机具仓储状态查询列表
*/
@ApiOperation("导出综合查询机具仓储状态查询列表")
@Log(title = "导出综合查询机具仓储状态查询列表", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, StorageStatus bean)
{
List<StorageStatus> list = storageStatusService.getStorageStatusList(bean);
ExcelUtil<StorageStatus> util = new ExcelUtil<StorageStatus>(StorageStatus.class);
util.exportExcel(response, list, "综合查询--工程机具使用");
}
}

View File

@ -0,0 +1,212 @@
package com.bonus.sgzb.material.domain;
import com.bonus.sgzb.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.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
* @description 综合查询--退料查询
* @author hay
* @date 2024/2/26 14:51
*/
@ApiModel(description = "退料查询")
@Data
public class ProjUsingRecord {
private static final long serialVersionUID = 2227217051604273598L;
@ApiModelProperty(value = "")
private Integer id;
/**
* 协议号
*/
@ApiModelProperty(value = "协议号")
@Excel(name = "协议号")
private String agreementCode;
/**
* 往来单位Id
*/
@ApiModelProperty(value = "往来单位Id")
private Integer unitId;
/**
* 往来单位
*/
@ApiModelProperty(value = "往来单位")
@Excel(name = "往来单位")
private String unitName;
/**
* 工程Id
*/
@ApiModelProperty(value = "工程Id")
private Integer proId;
/**
* 工程名称
*/
@ApiModelProperty(value = "工程名称")
@Excel(name = "工程名称")
private String proName;
/**
* 类型名称
*/
@ApiModelProperty(value = "类型名称")
@Excel(name = "机具名称")
private String typeName;
/**
* 规格ID
*/
@ApiModelProperty(value = "规格ID")
private Integer typeId;
/**
* 规格型号
*/
@ApiModelProperty(value = "规格型号")
@Excel(name = "规格名称")
private String typeModelName;
/**
* 退料单号
*/
@ApiModelProperty(value = "退料单号")
private String code;
/**
* 设备编码
*/
@ApiModelProperty(value = "设备编码")
private String maCode;
/**
* 计量单位
*/
@ApiModelProperty(value = "计量单位")
@Excel(name = "单位")
private String unit;
/**
* 租赁数量
*/
@ApiModelProperty(value = "租赁数量")
@Excel(name = "租赁数量",cellType = Excel.ColumnType.NUMERIC)
private Double outNum;
/**
* 归还数量
*/
@ApiModelProperty(value = "归还数量")
@Excel(name = "归还数量",cellType = Excel.ColumnType.NUMERIC)
private Double backNum;
/**
* 在用数量
*/
@ApiModelProperty(value = "在用数量")
@Excel(name = "在用数量",cellType = Excel.ColumnType.NUMERIC)
private Double usNum;
/**
* 在用总价值
*/
@ApiModelProperty(value = "在用总价值")
private Double usPrice;
/**
* 投入总价值
*/
@ApiModelProperty(value = "投入总价值")
private Double totalPrice;
/**
* 退料人
*/
@ApiModelProperty(value = "退料人")
private String backPerson;
/**
* 创建者
*/
@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 remark;
/**
* 关键字
*/
@ApiModelProperty(value = "关键字")
private String keyWord;
@ApiModelProperty(value="开始时间")
private String startTime;
@ApiModelProperty(value="结束时间")
private String endTime;
/**
* 设备所属类型
*/
@ApiModelProperty(value = "数据所属组织")
private Integer companyId;
/**
* 装备管理方式(0编号 1计数)
*/
@ApiModelProperty(value = "装备管理方式")
private int manageType;
/**
* 装备管理方式(0编号 1计数)
*/
@ApiModelProperty(value = "装备管理方式名称")
private String manageTypeName;
/**
* 实时库存
*/
@ApiModelProperty(value = "实时库存")
private Double num;
}

View File

@ -0,0 +1,206 @@
package com.bonus.sgzb.material.domain;
import com.bonus.sgzb.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.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
* @description 综合查询--退料查询
* @author hay
* @date 2024/2/26 14:51
*/
@ApiModel(description = "退料查询")
@Data
public class StorageStatus {
private static final long serialVersionUID = 2227217051604273598L;
@ApiModelProperty(value = "")
private Integer id;
/**
* 协议号
*/
@ApiModelProperty(value = "协议号")
private String agreementCode;
/**
* 类型名称
*/
@ApiModelProperty(value = "类型名称")
@Excel(name = "机具名称")
private String typeName;
/**
* 规格ID
*/
@ApiModelProperty(value = "规格ID")
private Integer typeId;
/**
* 规格型号
*/
@ApiModelProperty(value = "规格型号")
@Excel(name = "规格名称")
private String typeModelName;
/**
* 计量单位
*/
@ApiModelProperty(value = "计量单位")
@Excel(name = "单位")
private String unit;
/**
* 在库数量
*/
@ApiModelProperty(value = "在库数量")
@Excel(name = "在库数量",cellType = Excel.ColumnType.NUMERIC)
private Double num;
/**
* 在用数量
*/
@ApiModelProperty(value = "在用数量")
@Excel(name = "在用数量",cellType = Excel.ColumnType.NUMERIC)
private Double usNum;
/**
* 在修数量
*/
@ApiModelProperty(value = "在修数量")
@Excel(name = "在修数量",cellType = Excel.ColumnType.NUMERIC)
private Double repairNum;
/**
* 修试后待入库
*/
@ApiModelProperty(value = "修试后待入库")
@Excel(name = "修试后待入库",cellType = Excel.ColumnType.NUMERIC)
private Double repairInputNum;
/**
* 新购待入库
*/
@ApiModelProperty(value = "新购待入库")
@Excel(name = "新购待入库",cellType = Excel.ColumnType.NUMERIC)
private Double inputNum;
/**
* 总保有量
*/
@ApiModelProperty(value = "总保有量")
@Excel(name = "总保有量",cellType = Excel.ColumnType.NUMERIC)
private Double allNum;
/**
* 是否计数
*/
@ApiModelProperty(value = "是否计数")
@Excel(name = "是否计数")
private Double manageType;
/**
* 租赁数量
*/
@ApiModelProperty(value = "租赁数量")
@Excel(name = "租赁数量",cellType = Excel.ColumnType.NUMERIC)
private Double outNum;
/**
* 归还数量
*/
@ApiModelProperty(value = "归还数量")
@Excel(name = "归还数量",cellType = Excel.ColumnType.NUMERIC)
private Double backNum;
/**
* 在用总价值
*/
@ApiModelProperty(value = "在用总价值")
private Double usPrice;
/**
* 投入总价值
*/
@ApiModelProperty(value = "投入总价值")
private Double totalPrice;
/**
* 退料人
*/
@ApiModelProperty(value = "退料人")
private String backPerson;
/**
* 创建者
*/
@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 remark;
/**
* 关键字
*/
@ApiModelProperty(value = "关键字")
private String keyWord;
@ApiModelProperty(value="开始时间")
private String startTime;
@ApiModelProperty(value="结束时间")
private String endTime;
/**
* 设备所属类型
*/
@ApiModelProperty(value = "数据所属组织")
private Integer companyId;
/**
* 装备管理方式(0编号 1计数)
*/
@ApiModelProperty(value = "装备管理方式名称")
private String manageTypeName;
}

View File

@ -0,0 +1,23 @@
package com.bonus.sgzb.material.mapper;
import com.bonus.sgzb.material.domain.BackRecord;
import com.bonus.sgzb.material.domain.ProjUsingRecord;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* @description 综合查询--工程机具使用查询
* @author hay
* @date 2024/2/26 14:19
*/
@Mapper
public interface ProjUsingRecordMapper {
/**
* 综合查询--工程机具使用查询列表
* @param bean
* @return List<ProjUsingRecord>
*/
List<ProjUsingRecord> getProjUsingRecordList(ProjUsingRecord bean);
}

View File

@ -0,0 +1,23 @@
package com.bonus.sgzb.material.mapper;
import com.bonus.sgzb.material.domain.ProjUsingRecord;
import com.bonus.sgzb.material.domain.StorageStatus;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* @description 综合查询--机具仓储状态查询
* @author hay
* @date 2024/2/26 14:19
*/
@Mapper
public interface StorageStatusMapper {
/**
* 综合查询--机具仓储状态查询列表
* @param bean
* @return List<StorageStatus>
*/
List<StorageStatus> getStorageStatusList(StorageStatus bean);
}

View File

@ -0,0 +1,21 @@
package com.bonus.sgzb.material.service;
import com.bonus.sgzb.material.domain.BackRecord;
import com.bonus.sgzb.material.domain.ProjUsingRecord;
import java.util.List;
/**
* @description 综合查询--工程机具使用查询
* @author hay
* @date 2024/2/26 14:19
*/
public interface ProjUsingRecordService {
/**
* 综合查询--工程机具使用查询列表
* @param bean
* @return List<ProjUsingRecord>
*/
List<ProjUsingRecord> getProjUsingRecordList(ProjUsingRecord bean);
}

View File

@ -0,0 +1,21 @@
package com.bonus.sgzb.material.service;
import com.bonus.sgzb.material.domain.ProjUsingRecord;
import com.bonus.sgzb.material.domain.StorageStatus;
import java.util.List;
/**
* @description 综合查询--机具仓储状态查询
* @author hay
* @date 2024/2/26 14:19
*/
public interface StorageStatusService {
/**
* 综合查询--机具仓储状态查询列表
* @param bean
* @return List<StorageStatus>
*/
List<StorageStatus> getStorageStatusList(StorageStatus bean);
}

View File

@ -0,0 +1,29 @@
package com.bonus.sgzb.material.service.impl;
import com.bonus.sgzb.material.domain.BackRecord;
import com.bonus.sgzb.material.domain.ProjUsingRecord;
import com.bonus.sgzb.material.mapper.BackRecordMapper;
import com.bonus.sgzb.material.mapper.ProjUsingRecordMapper;
import com.bonus.sgzb.material.service.BackRecordService;
import com.bonus.sgzb.material.service.ProjUsingRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author hay
* @date 2023/12/20 14:55
*/
@Service
public class ProjUsingRecordServiceImpl implements ProjUsingRecordService {
@Autowired
private ProjUsingRecordMapper projUsingRecordMapper;
@Override
public List<ProjUsingRecord> getProjUsingRecordList(ProjUsingRecord bean) {
return projUsingRecordMapper.getProjUsingRecordList(bean);
}
}

View File

@ -0,0 +1,29 @@
package com.bonus.sgzb.material.service.impl;
import com.bonus.sgzb.material.domain.ProjUsingRecord;
import com.bonus.sgzb.material.domain.StorageStatus;
import com.bonus.sgzb.material.mapper.ProjUsingRecordMapper;
import com.bonus.sgzb.material.mapper.StorageStatusMapper;
import com.bonus.sgzb.material.service.ProjUsingRecordService;
import com.bonus.sgzb.material.service.StorageStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author hay
* @date 2023/12/20 14:55
*/
@Service
public class StorageStatusServiceImpl implements StorageStatusService {
@Autowired
private StorageStatusMapper storageStatusMapper;
@Override
public List<StorageStatus> getStorageStatusList(StorageStatus bean) {
return storageStatusMapper.getStorageStatusList(bean);
}
}

View File

@ -0,0 +1,126 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.sgzb.material.mapper.ProjUsingRecordMapper">
<select id="getProjUsingRecordList" resultType="com.bonus.sgzb.material.domain.ProjUsingRecord">
SELECT subquery1.agreementCode,
subquery1.unitName,
subquery1.proName,
subquery1.typeName,
subquery1.typeModelName,
subquery1.unit,
IFNULL(subquery1.outNum, 0) as outNum,
IFNULL(subquery2.backNum, 0) as backNum,
CASE
WHEN IFNULL(subquery1.outNum, 0) - IFNULL(subquery2.backNum, 0) > 0
THEN IFNULL(subquery1.outNum, 0) - IFNULL(subquery2.backNum, 0)
ELSE 0
END as usNum,
CASE
WHEN IFNULL(subquery1.outNum, 0) - IFNULL(subquery2.backNum, 0) > 0 THEN
IFNULL(subquery1.rent_price, 0) *
(IFNULL(subquery1.outNum, 0) - IFNULL(subquery2.backNum, 0))
ELSE
0
END as usPrice,
IFNULL(subquery1.outNum, 0) * IFNULL(subquery1.rent_price, 0) as totalPrice
FROM (SELECT bai.agreement_id,
mt.type_id,
mt.rent_price,
bai.agreement_code AS agreementCode,
bui.unit_name AS unitName,
bpl.lot_name AS proName,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
mt.unit_name AS unit,
SUM(IFNULL(lod.out_num, 0)) AS outNum
FROM lease_out_details lod
LEFT JOIN lease_apply_info lai ON lai.id = lod.parent_id
LEFT JOIN tm_task_agreement tta ON tta.task_id = lai.task_id
LEFT JOIN bm_agreement_info bai ON bai.agreement_id = tta.agreement_id
LEFT JOIN bm_project_lot bpl ON bpl.lot_id = bai.project_id
LEFT JOIN bm_unit_info bui ON bui.unit_id = bai.unit_id
LEFT JOIN ma_type mt ON mt.type_id = lod.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
LEFT JOIN ma_machine mm ON mm.ma_id = lod.ma_id
LEFT JOIN sys_user su ON su.user_id = lai.lease_person
where 1=1
<if test="keyWord != null and keyWord != ''">
and (bai.agreement_code like concat('%',#{keyWord},'%') or
bui.unit_name like concat('%',#{keyWord},'%') or
bpl.lot_name like concat('%',#{keyWord},'%') or
mt2.type_name like concat('%',#{keyWord},'%') or
mt.type_name like concat('%',#{keyWord},'%') or
mt.unit_name like concat('%',#{keyWord},'%')
)
</if>
<if test="unitId != null">
and bui.unit_id = #{unitId}
</if>
<if test="proId != null">
and bpl.lot_id = #{proId}
</if>
<if test="typeName != null and typeName != ''">
and mt2.type_name like concat('%',#{typeName},'%')
</if>
<if test="typeModelName != null and typeModelName != ''">
and mt.type_name like concat('%',#{typeModelName},'%')
</if>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
AND lod.create_time BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime}, ' 23:59:59')
</if>
GROUP BY bai.agreement_id,
mt.type_id) AS subquery1
LEFT JOIN (SELECT bai.agreement_id,
mt.type_id,
mt.rent_price,
bai.agreement_code AS agreementCode,
bui.unit_name AS unitName,
bpl.lot_name AS proName,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
mt.unit_name AS unit,
SUM(IFNULL(bcd.back_num, 0)) backNum
FROM back_check_details bcd
LEFT JOIN back_apply_info baif ON baif.id = bcd.parent_id
LEFT JOIN tm_task_agreement tta ON tta.task_id = baif.task_id
LEFT JOIN bm_agreement_info bai ON bai.agreement_id = tta.agreement_id
LEFT JOIN bm_project_lot bpl ON bpl.lot_id = bai.project_id
LEFT JOIN bm_unit_info bui ON bui.unit_id = bai.unit_id
LEFT JOIN ma_type mt ON mt.type_id = bcd.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
LEFT JOIN ma_machine mm ON mm.ma_id = bcd.ma_id
LEFT JOIN sys_user su ON su.user_id = baif.back_person
where 1=1
<if test="keyWord != null and keyWord != ''">
and (bai.agreement_code like concat('%',#{keyWord},'%') or
bui.unit_name like concat('%',#{keyWord},'%') or
bpl.lot_name like concat('%',#{keyWord},'%') or
mt2.type_name like concat('%',#{keyWord},'%') or
mt.type_name like concat('%',#{keyWord},'%') or
mt.unit_name like concat('%',#{keyWord},'%')
)
</if>
<if test="unitId != null">
and bui.unit_id = #{unitId}
</if>
<if test="proId != null">
and bpl.lot_id = #{proId}
</if>
<if test="typeName != null and typeName != ''">
and mt2.type_name like concat('%',#{typeName},'%')
</if>
<if test="typeModelName != null and typeModelName != ''">
and mt.type_name like concat('%',#{typeModelName},'%')
</if>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
AND bcd.create_time BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime}, ' 23:59:59')
</if>
GROUP BY bai.agreement_id,
mt.type_id) AS subquery2 ON subquery1.type_id = subquery2.type_id
AND subquery1.agreement_id = subquery2.agreement_id
</select>
</mapper>

View File

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.sgzb.material.mapper.StorageStatusMapper">
<select id="getStorageStatusList" resultType="com.bonus.sgzb.material.domain.StorageStatus">
SELECT mt2.type_name as typeName,
mt.type_name as typeModelName,
mt.unit_name as unit,
IFNULL(mt.num, 0) as num,
IFNULL(subquery1.usNum, 0) as usNum,
IFNULL(subquery2.repairNum, 0) as repairNum,
IFNULL(subquery3.repairInputNum, 0) as repairInputNum,
IFNULL(subquery4.inputNum, 0) as inputNum,
IFNULL(subquery1.usNum, 0) + IFNULL(subquery2.repairNum, 0) + IFNULL(subquery3.repairInputNum, 0) +
IFNULL(subquery4.inputNum, 0) as allNum,
CASE mt.manage_type
WHEN 0 THEN
'否'
ELSE
'是'
END manageType
FROM ma_type mt
LEFT JOIN (SELECT subquery1.type_id,
subquery1.typeName,
subquery1.typeModelName,
IFNULL(subquery1.outNum, 0) AS outNum,
IFNULL(subquery2.backNum, 0) AS backNum,
CASE
WHEN IFNULL(subquery1.outNum, 0) - IFNULL(subquery2.backNum, 0) > 0 THEN
IFNULL(subquery1.outNum, 0) - IFNULL(subquery2.backNum, 0)
ELSE 0
END AS usNum
FROM (SELECT mt.type_id,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
SUM(IFNULL(lod.out_num, 0)) AS outNum
FROM lease_out_details lod
LEFT JOIN ma_type mt ON mt.type_id = lod.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
GROUP BY mt.type_id) AS subquery1
LEFT JOIN (SELECT mt.type_id,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
SUM(IFNULL(bcd.back_num, 0)) backNum
FROM back_check_details bcd
LEFT JOIN ma_type mt ON mt.type_id = bcd.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
LEFT JOIN ma_machine mm ON mm.ma_id = bcd.ma_id
GROUP BY mt.type_id) AS subquery2
ON subquery1.type_id = subquery2.type_id) AS subquery1
ON mt.type_id = subquery1.type_id
LEFT JOIN (SELECT mt.type_id,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
SUM(
IFNULL(rad.repair_num, 0) - IFNULL(rad.repaired_num, 0) -
IFNULL(rad.scrap_num, 0)) AS repairNum
FROM repair_apply_details rad
LEFT JOIN ma_type mt ON mt.type_id = rad.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
WHERE IFNULL(rad.repair_num, 0) - IFNULL(rad.repaired_num, 0) - IFNULL(rad.scrap_num, 0) > 0
GROUP BY mt.type_id) AS subquery2 ON subquery2.type_id = mt.type_id
LEFT JOIN (SELECT mt.type_id,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
SUM(
IFNULL(rid.repair_num, 0) - IFNULL(rid.input_num, 0)) AS repairInputNum
FROM repair_input_details rid
LEFT JOIN ma_type mt ON mt.type_id = rid.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
WHERE IFNULL(rid.repair_num, 0) - IFNULL(rid.input_num, 0) > 0
GROUP BY mt.type_id) AS subquery3 ON subquery3.type_id = mt.type_id
LEFT JOIN (SELECT mt.type_id,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
SUM(
IFNULL(pcd.check_num, 0) - IFNULL(pcd.input_num, 0)) AS inputNum
FROM purchase_check_details pcd
LEFT JOIN ma_type mt ON mt.type_id = pcd.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
WHERE IFNULL(pcd.check_num, 0) - IFNULL(pcd.input_num, 0) > 0
GROUP BY mt.type_id) AS subquery4 ON subquery4.type_id = mt.type_id
LEFT JOIN ma_type mt2 on mt2.type_id = mt.parent_id
WHERE mt.`level` = 4
<if test="typeName != null and typeName != ''">
and mt2.type_name like concat('%',#{typeName},'%')
</if>
<if test="typeModelName != null and typeModelName != ''">
and mt.type_name like concat('%',#{typeModelName},'%')
</if>
</select>
</mapper>