706 lines
27 KiB
XML
706 lines
27 KiB
XML
<?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.SecondaryWarehouseMapper">
|
|
<insert id="addOperate">
|
|
insert into team_lease_info (agreement_id,type_id,team_name,lease_man,phone,num,create_by,create_time,type)
|
|
values (#{agreementId},#{typeId},#{teamName},#{leaseMan},#{phone},#{num},#{createBy},now(),#{type});
|
|
</insert>
|
|
<update id="updateConfig">
|
|
UPDATE second_lot_config
|
|
SET name = #{name},
|
|
unit_id = #{unitId},
|
|
updater = #{updater},
|
|
update_time = now()
|
|
WHERE
|
|
id = #{id}
|
|
</update>
|
|
<update id="updateMachine">
|
|
UPDATE ma_machine
|
|
SET
|
|
ma_status = #{maStatus}
|
|
WHERE
|
|
ma_id = #{maId}
|
|
</update>
|
|
<update id="updateOutNum">
|
|
UPDATE lease_out_details
|
|
SET
|
|
out_num = out_num - #{outNum}
|
|
WHERE
|
|
parent_id = #{parentId} and type_id = #{typeId}
|
|
</update>
|
|
<update id="auditSeconfScrap">
|
|
UPDATE second_scrap_apply_details
|
|
SET
|
|
audit_by = #{auditBy},
|
|
audit_time = now(),
|
|
status = #{status}
|
|
WHERE
|
|
code = #{code}
|
|
</update>
|
|
<update id="updateMaMachineStatus">
|
|
UPDATE ma_machine
|
|
SET
|
|
ma_status = 22
|
|
WHERE
|
|
ma_id = #{maId}
|
|
</update>
|
|
<update id="updateDevNum">
|
|
UPDATE ma_type
|
|
SET
|
|
num = num - #{scrapNum}
|
|
WHERE
|
|
type_id = #{typeId}
|
|
</update>
|
|
<delete id="delConfig">
|
|
DELETE FROM second_lot_config
|
|
WHERE
|
|
id = #{id}
|
|
</delete>
|
|
<delete id="deleteOutNum">
|
|
DELETE FROM lease_out_details
|
|
WHERE parent_id = #{id}
|
|
AND ma_id = #{maId}
|
|
</delete>
|
|
|
|
<select id="getList" resultType="com.bonus.sgzb.material.domain.SecondaryWarehouse">
|
|
SELECT
|
|
bui.unit_id AS unitId,
|
|
lod.parent_id AS id,
|
|
tta.agreement_id AS agreementId,
|
|
bui.unit_name AS unitName,
|
|
mt1.type_name AS typeName,
|
|
mt.type_name AS modelName,
|
|
mt.manage_type as manageType,
|
|
mt.unit_name AS nuitName,
|
|
lod.type_id AS typeId,
|
|
group_concat(lod.ma_id) AS maIds,
|
|
IFNULL(SUM( lod.out_num ),0) AS Num
|
|
from lease_out_details lod
|
|
left join lease_apply_info lai on lod.parent_id=lai.id
|
|
left join tm_task_agreement tta on lai.task_id=tta.task_id
|
|
LEFT JOIN bm_agreement_info bai ON tta.agreement_id = bai.agreement_id
|
|
LEFT JOIN bm_unit_info bui ON bui.unit_id = bai.unit_id
|
|
LEFT JOIN ma_type mt ON lod.type_id = mt.type_id
|
|
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
|
|
WHERE 1=1
|
|
<if test="unitId != null and unitId != ''">
|
|
and bui.unit_id = #{unitId}
|
|
</if>
|
|
<if test="typeId != null and typeId != ''">
|
|
and mt1.type_id = #{typeId}
|
|
</if>
|
|
<if test="modelId != null and modelId != ''">
|
|
and mt.type_id = #{modelId}
|
|
</if>
|
|
<if test="leaseType != null">
|
|
and lai.lease_type = #{leaseType}
|
|
</if>
|
|
<if test="deptId != null">
|
|
and bui.dept_id = #{deptId}
|
|
</if>
|
|
<if test="keyword != null and keyword != ''">
|
|
and (bui.unit_name like concat('%', #{keyword}, '%') or
|
|
mt1.type_name like concat('%', #{keyword}, '%') or
|
|
mt.type_name like concat('%', #{keyword}, '%')
|
|
)
|
|
</if>
|
|
GROUP BY
|
|
bui.unit_id,
|
|
lod.type_id
|
|
</select>
|
|
<select id="getList1" resultType="com.bonus.sgzb.material.domain.SecondaryWarehouse">
|
|
SELECT
|
|
bui.unit_id AS unitId,
|
|
lod.id as id,
|
|
tta.agreement_id AS agreementId,
|
|
bui.unit_name AS unitName,
|
|
bp.lot_name AS proName,
|
|
mt1.type_name AS typeName,
|
|
mt.type_name AS modelName,
|
|
mt.unit_name AS nuitName,
|
|
lod.type_id AS typeId,
|
|
IFNULL(SUM( lod.out_num ),0) AS receiveNum
|
|
|
|
from lease_out_details lod
|
|
left join lease_apply_info lai on lod.parent_id=lai.id
|
|
left join tm_task_agreement tta on lai.task_id=tta.task_id
|
|
LEFT JOIN bm_agreement_info bai ON tta.agreement_id = bai.agreement_id
|
|
LEFT JOIN bm_project_lot bp ON bp.lot_id = bai.project_id
|
|
LEFT JOIN bm_unit_info bui ON bui.unit_id = bai.unit_id
|
|
LEFT JOIN ma_type mt ON lod.type_id = mt.type_id
|
|
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
|
|
WHERE 1=1
|
|
<if test="unitId != null and unitId != ''">
|
|
and bui.unit_id = #{unitId}
|
|
</if>
|
|
<if test="proId != null and proId != ''">
|
|
and bp.lot_id = #{proId}
|
|
</if>
|
|
<if test="typeId != null and typeId != ''">
|
|
and mt1.type_id = #{typeId}
|
|
</if>
|
|
<if test="modelId != null and modelId != ''">
|
|
and mt.type_id = #{modelId}
|
|
</if>
|
|
<if test="leaseType != null and leaseType != ''">
|
|
and lai.lease_type = #{leaseType}
|
|
</if>
|
|
<if test="keyword != null and keyword != ''">
|
|
and (bui.unit_name like concat('%', #{keyword}, '%') or
|
|
bp.lot_name like concat('%', #{keyword}, '%') or
|
|
mt1.type_name like concat('%', #{keyword}, '%') or
|
|
mt.type_name like concat('%', #{keyword}, '%')
|
|
)
|
|
</if>
|
|
GROUP BY
|
|
tta.agreement_id,
|
|
lod.type_id
|
|
</select>
|
|
<select id="getOperateList" resultType="com.bonus.sgzb.material.domain.TeamLeaseInfo">
|
|
SELECT
|
|
bui.unit_name AS unitName,
|
|
bp.lot_name AS proName,
|
|
mt1.type_name AS typeName,
|
|
mt.type_name AS modelName,
|
|
tli.num,
|
|
tli.lease_man AS leaseMan,
|
|
su.nick_name AS createBy,
|
|
tli.create_time AS createTime
|
|
FROM
|
|
team_lease_info tli
|
|
LEFT JOIN bm_agreement_info bai ON tli.agreement_id = bai.agreement_id
|
|
LEFT JOIN bm_project_lot bp ON bp.lot_id = bai.project_id
|
|
LEFT JOIN bm_unit_info bui ON bui.unit_id = bai.unit_id
|
|
LEFT JOIN ma_type mt ON tli.type_id = mt.type_id
|
|
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
|
|
LEFT JOIN sys_user su ON su.user_id = tli.create_by
|
|
where tli.type = #{type}
|
|
<if test="unitId != null and unitId != ''">
|
|
and bui.unit_id = #{unitId}
|
|
</if>
|
|
<if test="proId != null and proId != ''">
|
|
and bp.lot_id = #{proId}
|
|
</if>
|
|
<if test="typeId != null and typeId != ''">
|
|
and mt1.type_id = #{typeId}
|
|
</if>
|
|
<if test="modelId != null and modelId != ''">
|
|
and mt.type_id = #{modelId}
|
|
</if>
|
|
<if test="keyword != null and keyword != ''">
|
|
and (bui.unit_name like concat('%', #{keyword}, '%') or
|
|
bp.lot_name like concat('%', #{keyword}, '%') or
|
|
mt1.type_name like concat('%', #{keyword}, '%') or
|
|
mt.type_name like concat('%', #{keyword}, '%') or
|
|
tli.lease_man like concat('%', #{keyword}, '%') or
|
|
su.nick_name like concat('%', #{keyword}, '%')
|
|
)
|
|
</if>
|
|
</select>
|
|
<select id="getList2" resultType="com.bonus.sgzb.material.domain.SecondaryWarehouseVo">
|
|
SELECT
|
|
bui.unit_id AS unitId,
|
|
lod.id as id,
|
|
tta.agreement_id AS agreementId,
|
|
bui.unit_name AS unitName,
|
|
bp.lot_name AS proName,
|
|
mt1.type_name AS typeName,
|
|
mt.type_name AS modelName,
|
|
mt.unit_name AS nuitName,
|
|
lod.type_id AS typeId,
|
|
IFNULL(SUM( lod.out_num ),0) AS Num
|
|
|
|
from lease_out_details lod
|
|
left join lease_apply_info lai on lod.parent_id=lai.id
|
|
left join tm_task_agreement tta on lai.task_id=tta.task_id
|
|
LEFT JOIN bm_agreement_info bai ON tta.agreement_id = bai.agreement_id
|
|
LEFT JOIN bm_project_lot bp ON bp.lot_id = bai.project_id
|
|
LEFT JOIN bm_unit_info bui ON bui.unit_id = bai.unit_id
|
|
LEFT JOIN ma_type mt ON lod.type_id = mt.type_id
|
|
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
|
|
WHERE 1=1
|
|
<if test="unitId != null and unitId != ''">
|
|
and bui.unit_id = #{unitId}
|
|
</if>
|
|
<if test="proId != null and proId != ''">
|
|
and bp.lot_id = #{proId}
|
|
</if>
|
|
<if test="typeId != null and typeId != ''">
|
|
and mt1.type_id = #{typeId}
|
|
</if>
|
|
<if test="modelId != null and modelId != ''">
|
|
and mt.type_id = #{modelId}
|
|
</if>
|
|
<if test="keyword != null and keyword != ''">
|
|
and (bui.unit_name like concat('%', #{keyword}, '%') or
|
|
bp.lot_name like concat('%', #{keyword}, '%') or
|
|
mt1.type_name like concat('%', #{keyword}, '%') or
|
|
mt.type_name like concat('%', #{keyword}, '%')
|
|
)
|
|
</if>
|
|
GROUP BY
|
|
tta.agreement_id,
|
|
lod.type_id
|
|
</select>
|
|
<select id="getRecordsOne" resultType="com.bonus.sgzb.material.domain.TeamLeaseInfo">
|
|
SELECT
|
|
mt1.type_name AS typeName,
|
|
mt.type_name AS modelName,
|
|
mt.unit_name as nuitName,
|
|
sai.num AS num,
|
|
sai.start_time as startTime
|
|
FROM
|
|
slt_agreement_info sai
|
|
LEFT JOIN ma_type mt ON sai.type_id = mt.type_id
|
|
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
|
|
where mt.type_id = #{typeId} and sai.agreement_id=#{agreementId}
|
|
<if test="startTime != null and startTime != ''">
|
|
and DATE(sai.start_time) = #{startTime}
|
|
</if>
|
|
order by sai.start_time desc
|
|
</select>
|
|
<select id="getRecordsTwo" resultType="com.bonus.sgzb.material.domain.TeamLeaseInfo">
|
|
SELECT
|
|
mt1.type_name AS typeName,
|
|
mt.type_name AS modelName,
|
|
mt.unit_name as nuitName,
|
|
sai.num AS num,
|
|
sai.end_time as startTime
|
|
FROM
|
|
slt_agreement_info sai
|
|
LEFT JOIN ma_type mt ON sai.type_id = mt.type_id
|
|
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
|
|
where sai.agreement_id=#{agreementId} and mt.type_id = #{typeId} and sai.status = '1'
|
|
<if test="startTime != null and startTime != ''">
|
|
and DATE(sai.end_time) = #{startTime}
|
|
</if>
|
|
order by sai.end_time desc
|
|
</select>
|
|
<select id="getRecordsThree" resultType="com.bonus.sgzb.material.domain.TeamLeaseInfo">
|
|
SELECT
|
|
mt1.type_name AS typeName,
|
|
mt.type_name AS modelName,
|
|
mt.unit_name as nuitName,
|
|
sai.num AS num,
|
|
sai.start_time as startTime
|
|
FROM
|
|
slt_agreement_info sai
|
|
LEFT JOIN ma_type mt ON sai.type_id = mt.type_id
|
|
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
|
|
where sai.agreement_id=#{agreementId} and mt.type_id = #{typeId} and sai.status = '0'
|
|
<if test="startTime != null and startTime != ''">
|
|
and DATE(sai.start_time) = #{startTime}
|
|
</if>
|
|
order by sai.start_time desc
|
|
</select>
|
|
<select id="getRecordsFour" resultType="com.bonus.sgzb.material.domain.TeamLeaseInfo">
|
|
select tli.team_name as teamName,
|
|
mt1.type_name AS typeName,
|
|
mt.type_name AS modelName,
|
|
tli.num,
|
|
su.nick_name as createBy,
|
|
tli.create_time as startTime
|
|
from team_lease_info tli
|
|
LEFT JOIN ma_type mt ON tli.type_id = mt.type_id
|
|
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
|
|
left join sys_user su on su.user_id = tli.create_by
|
|
where tli.agreement_id=#{agreementId} and mt.type_id = #{typeId} and tli.type = '1'
|
|
<if test="startTime != null and startTime != ''">
|
|
and DATE(tli.create_time) = #{startTime}
|
|
</if>
|
|
</select>
|
|
<select id="getRecordsFive" resultType="com.bonus.sgzb.material.domain.TeamLeaseInfo">
|
|
select tli.team_name as teamName,
|
|
mt1.type_name AS typeName,
|
|
mt.type_name AS modelName,
|
|
tli.num,
|
|
su.nick_name as createBy,
|
|
tli.create_time as startTime
|
|
from team_lease_info tli
|
|
LEFT JOIN ma_type mt ON tli.type_id = mt.type_id
|
|
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
|
|
left join sys_user su on su.user_id = tli.create_by
|
|
where tli.agreement_id=#{agreementId} and mt.type_id = #{typeId} and tli.type = '2'
|
|
<if test="startTime != null and startTime != ''">
|
|
and DATE(tli.create_time) = #{startTime}
|
|
</if>
|
|
</select>
|
|
<select id="selectStockNum" resultType="java.lang.Integer">
|
|
SELECT(
|
|
SUM(IF( rd.type = 1, rd.out_num, 0 )) -
|
|
SUM(IF( rd.type = 2, rd.out_num, 0 ))) AS receiveNum
|
|
FROM
|
|
receive_detail rd
|
|
WHERE
|
|
unit_id = #{unitId}
|
|
AND type_id = #{typeId}
|
|
</select>
|
|
<select id="getNewRecords" resultType="com.bonus.sgzb.material.domain.TeamLeaseInfo">
|
|
select mt.type_name modelName,
|
|
mt2.type_name typeName,
|
|
mt.unit_name unitName,
|
|
rd.out_num outNum,
|
|
rd.pick_name pickName,
|
|
rd.out_time outTime,
|
|
slc.name secondName,
|
|
tg.name groupName
|
|
from receive_detail rd
|
|
left join second_lot_config slc on rd.unit_id = slc.unit_id
|
|
LEFT JOIN team_group tg on tg.id = rd.team_group_id
|
|
left join ma_type mt on rd.type_id = mt.type_id
|
|
left join ma_type mt2 on mt.parent_id = mt2.type_id
|
|
where rd.type = #{type}
|
|
<if test="teamGroupId != null">
|
|
and rd.team_group_id = #{teamGroupId}
|
|
</if>
|
|
<if test="pickName != null and pickName != ''">
|
|
and rd.pick_name = #{pickName}
|
|
</if>
|
|
<if test="startTime != null and startTime != '' and endTime != null and endTime != '' ">
|
|
AND rd.out_time BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime}, ' 23:59:59')
|
|
</if>
|
|
<if test="unitId != null">
|
|
and rd.unit_id = #{unitId}
|
|
</if>
|
|
order by rd.out_time desc
|
|
</select>
|
|
<select id="selectStockNum1" resultType="java.lang.Integer">
|
|
SELECT
|
|
(
|
|
SUM(
|
|
IF
|
|
( rd.type = 1, rd.out_num, 0 )) - SUM(
|
|
IF
|
|
( rd.type = 2, rd.out_num, 0 ))) AS receiveNum
|
|
FROM
|
|
receive_detail rd
|
|
WHERE
|
|
parent_id = #{id}
|
|
</select>
|
|
<select id="selectConfigByLotId" resultType="com.bonus.sgzb.material.domain.SecondLotConfig">
|
|
select * from second_lot_config where unit_id = #{unitId} limit 1
|
|
</select>
|
|
<select id="listConfig" resultType="com.bonus.sgzb.material.domain.SecondLotConfig">
|
|
select slc.*, bui.unit_name from second_lot_config slc
|
|
left join bm_unit_info bui on slc.unit_id = bui.unit_id
|
|
<where>
|
|
<if test="name != null and name != ''">
|
|
and slc.name like concat('%',#{name},'%')
|
|
</if>
|
|
<if test="unitId != null">
|
|
and slc.unit_id = #{unitId}
|
|
</if>
|
|
<if test="deptId != null">
|
|
and bui.dept_id = #{deptId}
|
|
</if>
|
|
</where>
|
|
</select>
|
|
<select id="listTeamGroup" resultType="com.bonus.sgzb.material.domain.TeamGroup">
|
|
select tg.*, bui.unit_name from team_group tg
|
|
left join bm_unit_info bui on tg.unit_id = bui.unit_id
|
|
<where>
|
|
<if test="name != null and name != ''">
|
|
and tg.name like concat('%',#{name},'%')
|
|
</if>
|
|
<if test="unitId != null">
|
|
and tg.unit_id = #{unitId}
|
|
</if>
|
|
<if test="deptId != null">
|
|
and bui.dept_id = #{deptId}
|
|
</if>
|
|
</where>
|
|
</select>
|
|
<select id="getMaStatusByMaId" resultType="com.bonus.sgzb.base.api.domain.MaMachine">
|
|
select mm.*,
|
|
mt.type_name modelName,
|
|
mt2.type_name typeName
|
|
from ma_machine mm
|
|
left join ma_type mt on mm.type_id = mt.type_id
|
|
left join ma_type mt2 on mt2.type_id = mt.parent_id
|
|
where ma_id = #{maId}
|
|
</select>
|
|
<select id="getUseMaStatusByMaId" resultType="com.bonus.sgzb.base.api.domain.MaMachine">
|
|
SELECT DISTINCT
|
|
mt.type_name modelName,
|
|
mt.manage_type manageType,
|
|
mt2.type_name typeName,
|
|
rd.type_id typeId,
|
|
rd.parent_id as id,
|
|
mt.unit_name AS nuitName,
|
|
SUM(rd.out_num) receiveNum,
|
|
GROUP_CONCAT(rd.ma_id) maIds
|
|
FROM (
|
|
SELECT
|
|
rd.*,
|
|
tc.type1_count,
|
|
tc.type2_count,
|
|
@rn := IF(@prev_ma_id = rd.ma_id AND @prev_type = rd.type, @rn + 1, 1) AS rn,
|
|
@prev_ma_id := rd.ma_id,
|
|
@prev_type := rd.type
|
|
FROM receive_detail rd,
|
|
(SELECT
|
|
rd.ma_id,
|
|
SUM(CASE WHEN rd.type = '1' THEN 1 ELSE 0 END) as type1_count,
|
|
SUM(CASE WHEN rd.type = '2' THEN 1 ELSE 0 END) as type2_count
|
|
FROM receive_detail rd
|
|
WHERE rd.type IN ('1', '2')
|
|
AND rd.team_group_id = #{teamGroupId}
|
|
AND rd.unit_id = #{unitId}
|
|
GROUP BY rd.ma_id) tc,
|
|
(SELECT @prev_ma_id := NULL, @prev_type := NULL, @rn := 0) vars
|
|
WHERE rd.type IN ('1', '2')
|
|
AND rd.team_group_id = #{teamGroupId}
|
|
AND rd.unit_id = #{unitId}
|
|
AND rd.ma_id = tc.ma_id
|
|
ORDER BY rd.ma_id, rd.type, rd.out_num DESC
|
|
) rd
|
|
LEFT JOIN ma_machine mm ON rd.ma_id = mm.ma_id
|
|
LEFT JOIN ma_type mt ON mt.type_id = mm.type_id
|
|
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
|
|
WHERE mm.ma_status = 132
|
|
AND ((rd.type = '1' AND rd.rn <= GREATEST(0, rd.type1_count - rd.type2_count))
|
|
OR (rd.type = '2' AND rd.rn <= GREATEST(0, rd.type2_count - rd.type1_count)))
|
|
GROUP BY rd.type_id, rd.parent_id
|
|
|
|
UNION
|
|
|
|
SELECT DISTINCT
|
|
mt.type_name modelName,
|
|
mt.manage_type manageType,
|
|
mt2.type_name typeName,
|
|
rd.type_id typeId,
|
|
rd.parent_id as id,
|
|
mt.unit_name AS nuitName,
|
|
(SUM(CASE WHEN rd.type = '1' THEN rd.out_num ELSE 0 END)
|
|
- SUM(CASE WHEN rd.type = '2' THEN rd.out_num ELSE 0 END)) AS receiveNum,
|
|
GROUP_CONCAT(rd.ma_id) maIds
|
|
FROM receive_detail rd
|
|
LEFT JOIN ma_type mt ON mt.type_id = rd.type_id
|
|
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
|
|
WHERE rd.type IN ('1', '2')
|
|
AND rd.team_group_id = #{teamGroupId}
|
|
AND rd.ma_id IS NULL
|
|
AND rd.unit_id = #{unitId}
|
|
AND NOT EXISTS (
|
|
SELECT 1
|
|
FROM receive_detail rd2
|
|
WHERE rd2.ma_id = rd.ma_id
|
|
AND ((rd2.type = '1'
|
|
AND EXISTS (
|
|
SELECT 1
|
|
FROM receive_detail rd3
|
|
WHERE rd3.ma_id = rd.ma_id
|
|
AND rd3.type = '2'
|
|
AND rd3.type_id = rd2.type_id
|
|
AND rd3.team_group_id = rd2.team_group_id
|
|
AND rd3.unit_id = rd2.unit_id))
|
|
OR (rd2.type = '2'
|
|
AND EXISTS (
|
|
SELECT 1
|
|
FROM receive_detail rd4
|
|
WHERE rd4.ma_id = rd.ma_id
|
|
AND rd4.type = '1'
|
|
AND rd4.type_id = rd2.type_id
|
|
AND rd4.team_group_id = rd2.team_group_id
|
|
AND rd4.unit_id = rd2.unit_id)))
|
|
)
|
|
GROUP BY rd.type_id
|
|
</select>
|
|
<select id="getDevCount" resultType="java.lang.Integer">
|
|
SELECT
|
|
(SUM(CASE WHEN type = 1 THEN rd.out_num ELSE 0 END) -
|
|
SUM(CASE WHEN type = 2 THEN rd.out_num ELSE 0 END)) AS count
|
|
FROM receive_detail rd
|
|
WHERE type_id = #{typeId}
|
|
GROUP BY unit_id, team_group_id
|
|
</select>
|
|
<select id="selectParentId" resultType="java.lang.Integer">
|
|
SELECT parent_id
|
|
FROM lease_out_details
|
|
WHERE parent_id = #{id}
|
|
</select>
|
|
<select id="getDevStockCount" resultType="com.bonus.sgzb.base.api.domain.MaMachine">
|
|
SELECT DISTINCT
|
|
mt.type_name modelName,
|
|
mt.manage_type manageType,
|
|
mt2.type_name typeName,
|
|
rd.type_id typeId,
|
|
tg.NAME groupName,
|
|
slc.name as name,
|
|
mt.unit_name AS nuitName,
|
|
LENGTH(GROUP_CONCAT(DISTINCT rd.ma_id)) - LENGTH(REPLACE(GROUP_CONCAT(DISTINCT rd.ma_id), ',', '')) + 1 AS receiveNum,
|
|
GROUP_CONCAT(DISTINCT rd.ma_id) maIds
|
|
FROM (
|
|
SELECT
|
|
rd.*,
|
|
tc.type1_count,
|
|
tc.type2_count,
|
|
@rn := IF(@prev_ma_id = rd.ma_id AND @prev_type = rd.type, @rn + 1, 1) AS rn,
|
|
@prev_ma_id := rd.ma_id,
|
|
@prev_type := rd.type
|
|
FROM receive_detail rd,
|
|
(SELECT
|
|
rd.ma_id,
|
|
SUM(CASE WHEN rd.type = '1' THEN 1 ELSE 0 END) as type1_count,
|
|
SUM(CASE WHEN rd.type = '2' THEN 1 ELSE 0 END) as type2_count
|
|
FROM receive_detail rd
|
|
WHERE rd.type IN ('1', '2')
|
|
|
|
<if test="unitId != null">
|
|
AND rd.unit_id = #{unitId}
|
|
</if>
|
|
GROUP BY rd.ma_id) tc,
|
|
(SELECT @prev_ma_id := NULL, @prev_type := NULL, @rn := 0) vars
|
|
WHERE rd.type IN ('1', '2')
|
|
<if test="unitId != null">
|
|
AND rd.unit_id = #{unitId}
|
|
</if>
|
|
AND rd.ma_id = tc.ma_id
|
|
ORDER BY rd.ma_id, rd.type, rd.out_num DESC
|
|
) rd
|
|
LEFT JOIN ma_machine mm ON rd.ma_id = mm.ma_id
|
|
LEFT JOIN team_group tg ON rd.team_group_id = tg.id
|
|
LEFT JOIN second_lot_config slc ON rd.unit_id = slc.unit_id
|
|
LEFT JOIN bm_unit_info bui on bui.unit_id = rd.unit_id
|
|
LEFT JOIN ma_type mt ON mt.type_id = mm.type_id
|
|
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
|
|
WHERE mm.ma_status = 132
|
|
<if test="deptId != null">
|
|
AND bui.dept_id = #{deptId}
|
|
</if>
|
|
<if test="keyword != null and keyword != ''">
|
|
AND tg.NAME like concat('%', #{keyword}, '%')
|
|
</if>
|
|
AND ((rd.type = '1' AND rd.rn <= GREATEST(0, rd.type1_count - rd.type2_count))
|
|
OR (rd.type = '2' AND rd.rn <= GREATEST(0, rd.type2_count - rd.type1_count)))
|
|
GROUP BY rd.type_id
|
|
|
|
UNION
|
|
|
|
SELECT DISTINCT
|
|
mt.type_name modelName,
|
|
mt.manage_type manageType,
|
|
mt2.type_name typeName,
|
|
rd.type_id typeId,
|
|
tg.NAME groupName,
|
|
slc.name as name,
|
|
mt.unit_name AS nuitName,
|
|
(SUM(CASE WHEN rd.type = '1' THEN rd.out_num ELSE 0 END)
|
|
- SUM(CASE WHEN rd.type = '2' THEN rd.out_num ELSE 0 END)) AS receiveNum,
|
|
GROUP_CONCAT(rd.ma_id) maIds
|
|
FROM receive_detail rd
|
|
LEFT JOIN team_group tg ON rd.team_group_id = tg.id
|
|
LEFT JOIN second_lot_config slc ON rd.unit_id = slc.unit_id
|
|
LEFT JOIN bm_unit_info bui on bui.unit_id = rd.unit_id
|
|
LEFT JOIN ma_type mt ON mt.type_id = rd.type_id
|
|
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
|
|
WHERE rd.type IN ('1', '2')
|
|
AND rd.ma_id IS NULL
|
|
<if test="unitId != null">
|
|
AND rd.unit_id = #{unitId}
|
|
</if>
|
|
<if test="deptId != null">
|
|
AND bui.dept_id = #{deptId}
|
|
</if>
|
|
<if test="keyword != null and keyword != ''">
|
|
AND tg.NAME like concat('%', #{keyword}, '%')
|
|
</if>
|
|
AND NOT EXISTS (
|
|
SELECT 1
|
|
FROM receive_detail rd2
|
|
WHERE rd2.ma_id = rd.ma_id
|
|
AND ((rd2.type = '1'
|
|
AND EXISTS (
|
|
SELECT 1
|
|
FROM receive_detail rd3
|
|
WHERE rd3.ma_id = rd.ma_id
|
|
AND rd3.type = '2'
|
|
AND rd3.type_id = rd2.type_id
|
|
AND rd3.team_group_id = rd2.team_group_id
|
|
AND rd3.unit_id = rd2.unit_id))
|
|
OR (rd2.type = '2'
|
|
AND EXISTS (
|
|
SELECT 1
|
|
FROM receive_detail rd4
|
|
WHERE rd4.ma_id = rd.ma_id
|
|
AND rd4.type = '1'
|
|
AND rd4.type_id = rd2.type_id
|
|
AND rd4.team_group_id = rd2.team_group_id
|
|
AND rd4.unit_id = rd2.unit_id)))
|
|
)
|
|
GROUP BY rd.type_id
|
|
</select>
|
|
<select id="getSecondScrapList" resultType="com.bonus.sgzb.material.domain.SecondCcrapApplyDetails">
|
|
SELECT
|
|
ssd.*,
|
|
slc.NAME AS unitName
|
|
FROM
|
|
second_scrap_apply_details ssd
|
|
LEFT JOIN second_lot_config slc ON ssd.unit_id = slc.unit_id
|
|
left join bm_unit_info bui on bui.unit_id = slc.unit_id
|
|
where 1=1
|
|
<if test="unitId != null">
|
|
AND ssd.unit_id = #{unitId}
|
|
</if>
|
|
<if test="deptId != null">
|
|
AND bui.dept_id = #{deptId}
|
|
</if>
|
|
<if test="code != null and code !=''">
|
|
AND ssd.code like concat('%', #{code}, '%')
|
|
</if>
|
|
GROUP BY
|
|
ssd.CODE
|
|
</select>
|
|
<select id="getSeconfScrapByCode" resultType="com.bonus.sgzb.material.domain.SecondCcrapApplyDetails">
|
|
select * from second_scrap_apply_details where code = #{code}
|
|
</select>
|
|
<select id="getSecondScrapListDetails" resultType="com.bonus.sgzb.material.domain.SecondCcrapApplyDetails">
|
|
select
|
|
ssd.*,
|
|
mt.type_name AS modelName,
|
|
mm.ma_code AS maCode,
|
|
mt2.type_name AS typeName
|
|
from
|
|
second_scrap_apply_details ssd
|
|
left join ma_type mt on ssd.type_id = mt.type_id
|
|
left join ma_type mt2 on mt.parent_id = mt2.type_id
|
|
left join ma_machine mm on ssd.ma_id = mm.ma_id
|
|
where
|
|
ssd.code = #{code}
|
|
</select>
|
|
<select id="getSecondScrapByMaId" resultType="com.bonus.sgzb.material.domain.SecondCcrapApplyDetails">
|
|
select mm.ma_code from second_scrap_apply_details ssd
|
|
left join ma_machine mm on ssd.ma_id = mm.ma_id
|
|
where ssd.ma_id = #{maId} and ssd.type_id = #{typeId} and ssd.status in (0,1)
|
|
</select>
|
|
<select id="getParentIdByMaIdAndTypeId" resultType="com.bonus.sgzb.material.domain.TeamLeaseInfo">
|
|
select parent_id as parentId
|
|
from lease_out_details
|
|
where ma_id = #{maId}
|
|
and type_id = #{typeId}
|
|
order by create_time desc limit 1
|
|
</select>
|
|
|
|
<insert id="addConfig">
|
|
insert into second_lot_config (name,unit_id,creater,create_time)
|
|
values (#{name},#{unitId},#{creater},now());
|
|
</insert>
|
|
<insert id="addTeamGroup">
|
|
insert into team_group (name, unit_id, creater, create_time)
|
|
values (#{name}, #{unitId}, #{creater}, now());
|
|
</insert>
|
|
<insert id="addNewOperate">
|
|
insert into receive_detail (parent_id,type_id,ma_id,out_num,out_time,type,cteater,pick_name,unit_id,team_group_id,phone)
|
|
values (#{id},#{typeId},#{maId},#{outNum},now(),#{type},#{createBy},#{leaseMan},#{unitId},#{teamGroupId},#{phone});
|
|
</insert>
|
|
<insert id="addNum">
|
|
update ma_type set num = num + #{outNum} where type_id = #{typeId}
|
|
</insert>
|
|
<insert id="secondScrapApplyDetails">
|
|
insert into second_scrap_apply_details (code,ma_id,type_id,scrap_num,create_by,create_time,unit_id,status,audit_remark,parent_id)
|
|
values (#{code},#{maId},#{typeId},#{scrapNum},#{createBy},now(),#{unitId},#{status},#{auditRemark},#{id});
|
|
</insert>
|
|
</mapper>
|