后台-退料申请

This commit is contained in:
bns_han 2023-12-21 20:17:36 +08:00
parent b19a375a4b
commit 5564d3d391
7 changed files with 922 additions and 0 deletions

View File

@ -371,6 +371,7 @@
LEFT JOIN ma_machine mm on mm.ma_id = lod.ma_id
WHERE tta.agreement_id = #{agreementId}
and tt.task_type = '29'
and mt.type_id is not null
) AS subquery1
LEFT JOIN
(
@ -390,6 +391,7 @@
LEFT JOIN ma_type mt4 ON mt4.type_id = mt3.parent_id
WHERE tta.agreement_id = #{agreementId}
and tt.task_type = '36'
and mt.type_id is not null
) AS subquery2
ON subquery1.type_id = subquery2.type_id
</select>

View File

@ -0,0 +1,140 @@
package com.bonus.sgzb.material.controller;
import com.bonus.sgzb.common.core.utils.StringUtils;
import com.bonus.sgzb.common.core.web.controller.BaseController;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.core.web.page.TableDataInfo;
import com.bonus.sgzb.common.log.annotation.Log;
import com.bonus.sgzb.common.log.enums.BusinessType;
import com.bonus.sgzb.material.domain.BackApplyInfo;
import com.bonus.sgzb.material.service.BackApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @description 退料申请
* @author hay
* @date 2023/12/20 11:46
*/
@Api(tags = "退料申请")
@RestController
@RequestMapping("/backApply")
public class BackApplyController extends BaseController {
@Autowired
private BackApplyService backApplyService;
/**
* 获取退料审核列表
*/
@ApiOperation(value = "获取退料审核列表")
@GetMapping("/getBackApplyList")
public TableDataInfo getBackApplyList(@RequestBody BackApplyInfo bean)
{
startPage();
List<BackApplyInfo> list = backApplyService.getBackApplyList(bean);
return getDataTable(list);
}
/**
* 获取在用物料列表
*/
@ApiOperation(value = "获取在用物料列表")
@GetMapping("/getMaterialList")
public TableDataInfo getMaterialList(@RequestBody BackApplyInfo bean)
{
startPage();
List<BackApplyInfo> list = backApplyService.getMaterialList(bean);
return getDataTable(list);
}
/**
* 退料申请详情
*/
@ApiOperation(value = "退料申请详情")
@GetMapping("/getView")
public TableDataInfo getView(@RequestBody BackApplyInfo bean)
{
startPage();
List<BackApplyInfo> list = backApplyService.getView(bean);
return getDataTable(list);
}
/**
* 退料申请详情修改
*/
@ApiOperation(value = "退料申请详情修改")
@PostMapping("/setModify")
public AjaxResult setModify(@RequestBody BackApplyInfo bean)
{
return backApplyService.setModify(bean);
}
/**
* 退料申请删除
*/
@ApiOperation(value = "退料申请删除")
@GetMapping("/del")
public AjaxResult del(@RequestBody BackApplyInfo bean)
{
return backApplyService.del(bean);
}
@Log(title = "领料申请提交", businessType = BusinessType.INSERT)
@PostMapping("submitBackApply")
public AjaxResult submitBackApply(@RequestBody BackApplyInfo bean) {
if (StringUtils.isNull(bean)) {
return AjaxResult.error("参数错误");
}
try {
//生成退料编码
String code = backApplyService.genderBackCode();
if (StringUtils.isEmpty(code)) {
return AjaxResult.error("后台退料编号生成异常,请重试!");
}
bean.setCode(code);
// 创建任务
boolean addTaskResult = backApplyService.insertSelective(bean) > 0;
if (addTaskResult && bean.getTaskId() != null) {
//任务协议表(tm_task_agreement)
Boolean addTaskAgreementRes = backApplyService.insertTaskAgreement(bean)>0;
if (addTaskAgreementRes){
//退料任务表(back_apply_info)
Boolean addBackApply=backApplyService.insertBackApply(bean)>0;
if (addBackApply && bean.getId()!=null){
if (!StringUtils.isEmpty(bean.getTypeId()) && !StringUtils.isEmpty(bean.getNum())){
String[] typeId = bean.getTypeId().split(",");
String[] num = bean.getNum().split(",");
for (int i=0;i< typeId.length;i++){
String typeIdStr=typeId[i];
String numStr=num[i];
bean.setTypeId(typeIdStr);
bean.setNum(numStr);
int re =backApplyService.upload(bean);
if (re<1){
return AjaxResult.error("退料申请详情创建失败");
}
}
}else {
return AjaxResult.error("未获取到物料类型或数量");
}
}else {
return AjaxResult.error("创建退料申请失败");
}
}else {
return AjaxResult.error("创建任务协议失败");
}
} else {
return AjaxResult.error("创建任务失败");
}
return AjaxResult.success("退料申请创建成功,已完成");
} catch (Exception e) {
return AjaxResult.error("创建任务失败," + e.getCause().toString() + "," + e.getMessage());
}
}
}

View File

@ -0,0 +1,108 @@
package com.bonus.sgzb.material.domain;
import com.bonus.sgzb.common.core.annotation.Excel;
import com.bonus.sgzb.common.core.web.domain.BaseEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @description 退料
* @author hay
* @date 2023/12/20 11:56
*/
@Data
public class BackApplyInfo extends BaseEntity {
private static final long serialVersionUID = 1L;
/** 退料ID */
@ApiModelProperty(value = "退料ID")
private Long id;
/** 退料单号 */
@Excel(name = "退料单号")
@ApiModelProperty(value = "退料单号")
private String code;
/** 任务ID */
@ApiModelProperty(value = "任务ID")
private Integer taskId;
/** 签订日期 */
@Excel(name = "签订日期")
@ApiModelProperty(value = "签订日期")
private String signTime;
/** 退料人员 */
@Excel(name = "退料人员")
@ApiModelProperty(value = "退料人员")
private String backPerson;
/** 联系电话 */
@Excel(name = "联系电话")
@ApiModelProperty(value = "联系电话")
private String phone;
/** 机具公司审核人 */
@ApiModelProperty(value = "机具公司审核人")
private Integer directAuditBy;
/** 机具公司审批时间 */
@ApiModelProperty(value = "机具公司审批时间")
private String directAuditTime;
/** 机具公司审批备注 */
@ApiModelProperty(value = "机具公司审批备注")
private String directAuditRemark;
/** 创建者 */
@ApiModelProperty(value = "创建者")
private String createBy;
/** 创建时间 */
@ApiModelProperty(value = "创建时间")
private Date createTime;
/** 更新者 */
@ApiModelProperty(value = "更新者")
private String updateBy;
/** 更新时间 */
@ApiModelProperty(value = "更新时间")
private Date updateTime;
/** 备注 */
@ApiModelProperty(value = "备注")
private String remark;
/** 数据所属组织 */
@ApiModelProperty(value = "数据所属组织")
private Long companyId;
@ApiModelProperty(value = "关键字")
private String keyWord;
@ApiModelProperty(value = "工程id")
private Integer lotId;
@ApiModelProperty(value = "工程名称")
private String lotName;
@ApiModelProperty(value = "单位id")
private Integer unitId;
@ApiModelProperty(value = "单位名称")
private String unitName;
@ApiModelProperty(value = "退料日期")
private String backTime;
private String typeId;
private String typeCode;
private String num;
private String typeByNum;
}

View File

@ -0,0 +1,42 @@
package com.bonus.sgzb.material.mapper;
import com.bonus.sgzb.material.domain.AgreementInfo;
import com.bonus.sgzb.material.domain.BackApplyInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
/**
* @author hay
* @date 2023/12/20 14:56
*/
@Mapper
public interface BackApplyMapper {
/**
* 获取退料审核列表
*/
List<BackApplyInfo> getBackApplyList(BackApplyInfo bean);
/**
* 获取在用物料列表
*/
List<BackApplyInfo> getMaterialList(BackApplyInfo bean);
int selectTaskNumByMonth(@Param("date") Date date, @Param("taskType") Integer taskType);
int insertTask(BackApplyInfo bean);
int insertTaskAgreement(BackApplyInfo bean);
int insertBackApply(BackApplyInfo bean);
int upload(BackApplyInfo bean);
List<BackApplyInfo> getView(BackApplyInfo bean);
int setModify(@Param("detailsId") int detailsId, @Param("num") int num);
int del(BackApplyInfo bean);
}

View File

@ -0,0 +1,38 @@
package com.bonus.sgzb.material.service;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.material.domain.AgreementInfo;
import com.bonus.sgzb.material.domain.BackApplyInfo;
import java.util.List;
/**
* @author hay
* @date 2023/12/20 14:55
*/
public interface BackApplyService {
/**
* 获取退料审核列表
*/
List<BackApplyInfo> getBackApplyList(BackApplyInfo bean);
/**
* 获取在用物料列表
*/
List<BackApplyInfo> getMaterialList(BackApplyInfo bean);
String genderBackCode();
int insertSelective(BackApplyInfo bean);
int insertTaskAgreement(BackApplyInfo bean);
int insertBackApply(BackApplyInfo bean);
int upload(BackApplyInfo bean);
List<BackApplyInfo> getView(BackApplyInfo bean);
AjaxResult setModify(BackApplyInfo bean);
AjaxResult del(BackApplyInfo bean);
}

View File

@ -0,0 +1,117 @@
package com.bonus.sgzb.material.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bonus.sgzb.common.core.utils.DateUtils;
import com.bonus.sgzb.common.core.utils.StringUtils;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.material.domain.AgreementInfo;
import com.bonus.sgzb.material.domain.BackApplyInfo;
import com.bonus.sgzb.material.mapper.BackApplyMapper;
import com.bonus.sgzb.material.service.AgreementInfoService;
import com.bonus.sgzb.material.service.BackApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
* @author hay
* @date 2023/12/20 14:55
*/
@Service
public class BackApplyServiceImpl implements BackApplyService {
@Autowired
private BackApplyMapper backApplyMapper;
@Override
public List<BackApplyInfo> getBackApplyList(BackApplyInfo bean) {
return backApplyMapper.getBackApplyList(bean);
}
@Override
public List<BackApplyInfo> getMaterialList(BackApplyInfo bean) {
return backApplyMapper.getMaterialList(bean);
}
@Override
public String genderBackCode() {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
Date nowDate = DateUtils.getNowDate();
String format = dateFormat.format(nowDate);
int taskNum = backApplyMapper.selectTaskNumByMonth(nowDate,36) + 1;
String code="";
if (taskNum>9 && taskNum<100){
code = "T" + format + "-00" + taskNum;
}else if (taskNum>99 && taskNum<1000){
code = "T" + format + "-0" + taskNum;
}else {
code = "T" + format + "-000" + taskNum;
}
return code;
}
@Override
public int insertSelective(BackApplyInfo bean) {
return backApplyMapper.insertTask(bean);
}
@Override
public int insertTaskAgreement(BackApplyInfo bean) {
return backApplyMapper.insertTaskAgreement(bean);
}
@Override
public int insertBackApply(BackApplyInfo bean) {
return backApplyMapper.insertBackApply(bean);
}
@Override
public int upload(BackApplyInfo bean) {
return backApplyMapper.upload(bean);
}
@Override
public List<BackApplyInfo> getView(BackApplyInfo bean) {
return backApplyMapper.getView(bean);
}
@Override
public AjaxResult setModify(BackApplyInfo bean) {
if (!StringUtils.isEmpty(bean.getTypeByNum())){
// 使用 parseArray 方法解析 JSON 字符串为 JSONArray 对象
JSONArray jsonArray = JSON.parseArray(bean.getTypeByNum());
// 遍历 JSONArray
for (int i = 0; i < jsonArray.size(); i++) {
// 获取当前 JSONObject
JSONObject jsonObject = jsonArray.getJSONObject(i);
// 获取 JSONObject 中的属性值
int detailsId = jsonObject.getIntValue("detailsId");
int num = jsonObject.getIntValue("num");
int res=backApplyMapper.setModify(detailsId,num);
if (res<1){
return AjaxResult.error("修改失败");
}
}
return AjaxResult.success("修改成功");
}else {
return AjaxResult.error("修改失败,未获取到参数");
}
}
@Override
public AjaxResult del(BackApplyInfo bean) {
int re =backApplyMapper.del(bean);
if (re>0){
return AjaxResult.success("删除成功");
}else {
return AjaxResult.error("删除失败");
}
}
}

View File

@ -0,0 +1,475 @@
<?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.BackApplyMapper">
<resultMap type="com.bonus.sgzb.material.domain.AgreementInfo" id="BmAgreementInfoResult">
<result property="agreementId" column="agreement_id"/>
<result property="agreementCode" column="agreement_code"/>
<result property="signTime" column="sign_time"/>
<result property="unitId" column="unit_id"/>
<result property="unitName" column="unit_name"/>
<result property="projectId" column="project_id"/>
<result property="createBy" column="create_by"/>
<result property="leaseDay" column="lease_day"/>
<result property="planStartTime" column="plan_start_time"/>
<result property="contractCode" column="contract_code"/>
<result property="authPerson" column="auth_person"/>
<result property="phone" column="phone"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="remark" column="remark"/>
<result property="companyId" column="company_id"/>
<result property="fileName" column="file_name"/>
<result property="fileUrl" column="file_url"/>
</resultMap>
<insert id="insertTask" keyColumn="task_id" keyProperty="taskId" parameterType="com.bonus.sgzb.material.domain.BackApplyInfo" useGeneratedKeys="true">
insert into tm_task
(
<if test="taskType != null">
task_type,
</if>
<if test="taskStatus != null">
task_status,
</if>
<if test="code != null and code != ''">
code,
</if>
<if test="createBy != null and createBy != ''">
create_by,
</if>
<if test="updateBy != null and updateBy != ''">
update_by,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="remark != null and remark != ''">
remark,
</if>
<if test="companyId != null">
company_id,
</if>
create_time
) values (
<if test="taskType != null">
#{taskType},
</if>
<if test="taskStatus != null">
#{taskStatus},
</if>
<if test="code != null and code != ''">
#{code},
</if>
<if test="createBy != null and createBy != ''">
#{createBy},
</if>
<if test="updateBy != null and updateBy != ''">
#{updateBy},
</if>
<if test="updateTime != null">
#{updateTime},
</if>
<if test="remark != null and remark != ''">
#{remark},
</if>
<if test="companyId != null">
#{companyId},
</if>
NOW()
</insert>
<insert id="insertTaskAgreement">
insert into tm_task_agreement
(
<if test="taskId != null">
task_id,
</if>
<if test="agreementId != null">
agreement_id,
</if>
<if test="createBy != null and createBy != ''">
create_by,
</if>
<if test="updateBy != null and updateBy != ''">
update_by,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="remark != null and remark != ''">
remark,
</if>
<if test="companyId != null">
company_id,
</if>
create_time
) values (
<if test="taskId != null">
#{taskId},
</if>
<if test="agreementId != null">
#{agreementId},
</if>
<if test="createBy != null and createBy != ''">
#{createBy},
</if>
<if test="updateBy != null and updateBy != ''">
#{updateBy},
</if>
<if test="updateTime != null">
#{updateTime},
</if>
<if test="remark != null and remark != ''">
#{remark},
</if>
<if test="companyId != null">
#{companyId},
</if>
NOW()
)
</insert>
<insert id="insertBackApply" keyColumn="id" keyProperty="id" parameterType="com.bonus.sgzb.material.domain.BackApplyInfo" useGeneratedKeys="true">
insert into back_apply_info
(
<if test="code != null">
code,
</if>
<if test="taskId != null">
task_id,
</if>
<if test="backPerson != null and backPerson != ''">
back_person,
</if>
<if test="backTime != null and backTime != ''">
back_time,
</if>
<if test="phone != null and phone != ''">
phone,
</if>
<if test="directAuditBy != null">
direct_audit_by,
</if>
<if test="directAuditTime != null and directAuditTime != ''">
direct_audit_time,
</if>
<if test="directAuditRemark != null">
direct_audit_remark,
</if>
<if test="createBy != null and createBy != ''">
create_by,
</if>
<if test="updateBy != null and updateBy != ''">
update_by,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="remark != null and remark != ''">
remark,
</if>
<if test="companyId != null">
company_id,
</if>
create_time
) values (
<if test="code != null">
#{code},
</if>
<if test="taskId != null">
#{taskId},
</if>
<if test="backPerson != null and backPerson != ''">
#{backPerson},
</if>
<if test="backTime != null and backTime != ''">
#{backTime},
</if>
<if test="phone != null and phone != ''">
#{phone},
</if>
<if test="directAuditBy != null">
#{directAuditBy},
</if>
<if test="directAuditTime != null and directAuditTime != ''">
#{directAuditTime},
</if>
<if test="directAuditRemark != null">
#{directAuditRemark},
</if>
<if test="createBy != null and createBy != ''">
#{createBy},
</if>
<if test="updateBy != null and updateBy != ''">
#{updateBy},
</if>
<if test="updateTime != null">
#{updateTime},
</if>
<if test="remark != null and remark != ''">
#{remark},
</if>
<if test="companyId != null">
#{companyId},
</if>
NOW()
)
</insert>
<insert id="upload">
insert into back_apply_details
(
<if test="id != null">
parent_id,
</if>
<if test="typeId != null">
type_id,
</if>
<if test="num != null">
pre_num,
</if>
status,
<if test="createBy != null and createBy != ''">
create_by,
</if>
<if test="createBy != null and createBy != ''">
update_by,
</if>
update_time,
<if test="remark != null and remark != ''">
remark,
</if>
<if test="companyId != null">
company_id,
</if>
create_time
)
values (
<if test="id != null">
#{id},
</if>
<if test="typeId != null">
#{typeId},
</if>
<if test="num != null">
#{num},
</if>
'0',
<if test="createBy != null and createBy != ''">
#{createBy},
</if>
<if test="createBy != null and createBy != ''">
#{createBy},
</if>
NOW(),
<if test="remark != null and remark != ''">
#{remark},
</if>
<if test="companyId != null">
#{companyId},
</if>
NOW()
)
</insert>
<update id="setModify">
update back_apply_details
set pre_num =#{num}
where id = #{detailsId}
</update>
<delete id="del">
DELETE
FROM tm_task_agreement tta LEFT JOIN back_apply_info bai
ON bai.task_id = tta.task_id
WHERE
bai.id = #{id};
DELETE
FROM tm_task tt LEFT JOIN back_apply_info bai
ON bai.task_id = tt.task_id
WHERE
bai.id = #{id};
DELETE
FROM back_apply_details bad LEFT JOIN back_apply_info bai
ON bai.id = bad.parent_id
WHERE
bai.id = #{id};
DELETE
FROM back_apply_info
WHERE id = #{id};
</delete>
<select id="getBackApplyList" resultType="com.bonus.sgzb.material.domain.BackApplyInfo">
SELECT
bai.id,
bai.`code`,
bai.back_person as backPerson,
bai.phone,
bpl.lot_id as lotId,
bpl.lot_name as lotName,
bui.unit_id as unitId,
bui.unit_name as unitName,
bai.back_time as backTime,
bagi.agreement_code as agreementCode,
tt.task_status as taskStatus,
tta.agreement_id as agreementId,
GROUP_CONCAT(DISTINCT bad.type_id) as typeId,
GROUP_CONCAT(CONCAT_WS('/', IFNULL(mt3.type_name, ''))) AS typeName
FROM
back_apply_info bai
LEFT JOIN back_apply_details bad on bad.parent_id=bai.id
LEFT JOIN tm_task tt on tt.task_id=bai.task_id
LEFT JOIN tm_task_agreement tta on tta.task_id=tt.task_id
LEFT JOIN bm_agreement_info bagi on bagi.agreement_id=tta.agreement_id
LEFT JOIN bm_project_lot bpl on bpl.lot_id=bagi.project_id
LEFT JOIN bm_unit_info bui on bui.unit_id=bagi.unit_id
LEFT JOIN sys_user us on us.user_id=bai.create_by
LEFT JOIN ma_type mt1 ON mt1.type_id=bad.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id=mt1.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
bai.company_id=#{companyId}
<if test="keyWord != null and keyWord != ''">
and bai.`code` like concat('%', #{keyWord}, '%') or
and bai.back_person like concat('%', #{keyWord}, '%') or
and bai.phone like concat('%', #{keyWord}, '%')
</if>
GROUP BY bai.id, us.user_name, bai.phone, bpl.lot_name, bui.unit_name, bagi.plan_start_time
</select>
<select id="getMaterialList" resultType="com.bonus.sgzb.material.domain.BackApplyInfo">
SELECT subquery1.type_id as typeId,
subquery1.typeName typeCode,
subquery1.typeNames as typeName,
subquery1.out_num - COALESCE(subquery2.audit_num, 0) AS num,
subquery1.ma_code as maCode
FROM (
-- 第一个查询作为子查询
SELECT mt.type_id,
mt.type_name as typeName,
CONCAT_WS('/', IFNULL(mt3.type_name, '')) AS typeNames,
lod.out_num,
mm.ma_code
FROM tm_task_agreement tta
LEFT JOIN lease_apply_info lai on lai.task_id = tta.task_id
LEFT JOIN lease_out_details lod on lod.parent_id = lai.id
LEFT JOIN ma_type mt on mt.type_id = lod.type_id
LEFT JOIN tm_task tt on tt.task_id = tta.task_id
LEFT JOIN ma_type mt1 ON mt1.type_id = lod.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt1.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 ma_machine mm on mm.ma_id = lod.ma_id
WHERE tta.agreement_id = #{agreementId}
and tt.task_type = '29'
) AS subquery1
LEFT JOIN
(
-- 第二个查询作为子查询
SELECT mt.type_id,
mt.type_name,
CONCAT_WS('/', IFNULL(mt3.type_name, '')) AS typeNames,
bad.audit_num
FROM tm_task tt
LEFT JOIN tm_task_agreement tta on tta.task_id = tt.task_id
LEFT JOIN back_apply_info bai on bai.task_id = tta.task_id
LEFT JOIN back_apply_details bad on bad.parent_id = bai.id
LEFT JOIN ma_type mt on mt.type_id = bad.type_id
LEFT JOIN ma_type mt1 ON mt1.type_id = bad.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt1.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 tta.agreement_id = #{agreementId}
and tt.task_type = '36'
) AS subquery2
ON subquery1.type_id = subquery2.type_id
</select>
<select id="selectTaskNumByMonth" resultType="java.lang.Integer">
select count(*) from tm_task where DATE_FORMAT(create_time,'%y%m') = DATE_FORMAT(#{date},'%y%m') and task_type = #{taskType}
</select>
<select id="getView" resultType="com.bonus.sgzb.material.domain.BackApplyInfo">
SELECT
result1.*,
result2.num AS useNum
FROM
(
-- 结果1的原始查询
SELECT
bad.id as detailsId,
bpl.lot_name as lotName,
bui.unit_name as unitName,
bagi.agreement_code as agreementCode,
bai.back_person as backPerson,
bai.phone,
bad.type_id as typeId,
mt.type_name typeCode,
CONCAT_WS(
'/',
IFNULL( mt3.type_name, '' )) AS typeName,
bad.pre_num AS num,
mm.ma_code AS maCode
FROM
back_apply_details bad
LEFT JOIN back_apply_info bai ON bai.id = bad.parent_id
LEFT JOIN ma_type mt ON mt.type_id = bad.type_id
LEFT JOIN ma_type mt1 ON mt1.type_id = bad.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt1.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 ma_machine mm ON mm.type_id = bad.type_id
LEFT JOIN tm_task_agreement tta ON tta.task_id = bai.task_id
LEFT JOIN bm_agreement_info bagi ON bagi.agreement_id = tta.agreement_id
LEFT JOIN bm_project_lot bpl ON bpl.lot_id = bagi.project_id
LEFT JOIN bm_unit_info bui ON bui.unit_id = bagi.unit_id
WHERE
bai.id = #{id}
) AS result1
LEFT JOIN
(
-- 结果2的原始查询作为子查询
SELECT
subquery1.type_id AS typeId,
subquery1.typeName typeCode,
subquery1.out_num - COALESCE ( subquery2.audit_num, 0 ) AS num
FROM
(-- 第一个查询作为子查询
SELECT
mt.type_id,
mt.type_name AS typeName,
lod.out_num
FROM
tm_task_agreement tta
LEFT JOIN lease_apply_info lai ON lai.task_id = tta.task_id
LEFT JOIN lease_out_details lod ON lod.parent_id = lai.id
LEFT JOIN ma_type mt ON mt.type_id = lod.type_id
LEFT JOIN tm_task tt ON tt.task_id = tta.task_id
WHERE
tta.agreement_id = #{agreementId}
AND tt.task_type = '29'
) AS subquery1
LEFT JOIN (-- 第二个查询作为子查询
SELECT
mt.type_id,
mt.type_name,
bad.audit_num
FROM
tm_task tt
LEFT JOIN tm_task_agreement tta ON tta.task_id = tt.task_id
LEFT JOIN back_apply_info bai ON bai.task_id = tta.task_id
LEFT JOIN back_apply_details bad ON bad.parent_id = bai.id
LEFT JOIN ma_type mt ON mt.type_id = bad.type_id
WHERE
tta.agreement_id = #{agreementId}
AND tt.task_type = '36'
) AS subquery2 ON subquery1.type_id = subquery2.type_id
) AS result2 ON result1.typeId = result2.typeId;
</select>
</mapper>