gz_gqj/src/main/resources/mappers/plan/PlanOutMapper.xml

346 lines
16 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.gzgqj.business.plan.mapper.PlanOutMapper">
<insert id="insertProOutInfo" useGeneratedKeys="true" keyProperty="id">
insert into t_plan_out( pro_id, consignor, shipment_date, remarks, create_time, create_day, creater
)VALUES (#{proId},#{userName},#{createDay},#{remarks},now(),CURRENT_DATE,#{creater})
</insert>
<insert id="insertProNeedDetails">
insert into t_plan_out_detail(
out_id, type, name, module, unit, module_id, fh_num, tz_num, remarks, data_type )values (
#{outId},#{type},#{name},#{module},#{unit},#{moduleId},#{fhNum},#{tzNum},#{remarks},#{dataType} )
</insert>
<insert id="addNeedInfo">
insert into t_pro_need_info (
pro_id, type, name, module, module_id, need_type, unit, need_num, fh_num, tz_num, remarks
) values (#{proId},#{type},#{name},#{module},#{moduleId},#{needType},#{unit},#{needNum},#{fhNum},#{tzNum},#{remarks})
</insert>
<update id="updateNeedInfo">
update t_pro_need_info set fh_num=#{fhNum} ,tz_num=#{tzNum},remarks=#{remarks}
where id=#{id}
</update>
<!--更新 统计数量-->
<update id="updatePriPlanInfo">
update t_pro_plan_info set record_num=#{recordNum},out_num=#{outNum},tz_num=#{tzNum},last_day=#{lastDay},
status=#{status},out2_num=#{outNum2},record2_num=#{recordNum}
where pro_id=#{proId}
</update>
<delete id="deleteProOut">
delete from t_plan_out where id=#{id}
</delete>
<select id="getProPlanPage" resultType="com.bonus.gzgqj.business.plan.entity.ProPlanInfoVo">
select
ppi.pro_id proId, ppi.need_num needNum,pro.`NAME` proName,tz_num,
ppi.plan_num planNum,ppi.record_num recordNum,
ppi.out_num outNum, ppi.status, IFNULL(ROUND((ppi.out_num+ppi.tz_num)*100/ppi.need_num,0),0) progress,
ppi.last_day lastDay
from t_pro_plan_info ppi
LEFT JOIN bm_project pro on ppi.pro_id=pro.id
<where>
<if test="status!=null and status!=''">
and ppi.status=#{status}
</if>
<if test="proName!=null and proName!=''">
and pro.`NAME` like concat('%',#{proName},'%')
</if>
</where>
</select>
<select id="getPorInfoDetail" resultType="com.bonus.gzgqj.business.plan.entity.ProNeedInfo">
select pni.id,pni.pro_id proId,pni.type,pni.name,pni.module,pni.module_id,pni.need_type needType,
IFNULL(pni.unit,'-') unit ,IFNULL(pni.need_num,0) needNum ,(pni.fh_num+pni.tz_num )fhNum ,pro.`NAME` proName ,
IF(pni.need_num-pni.fh_num-pni.tz_num >0,pni.need_num-pni.fh_num-pni.tz_num,0) diff, IFNULL(ROUND((pni.fh_num+pni.tz_num)*100/pni.need_num,0),0) progress,
IF(pni.need_type=1,'计划内','计划外') typeName ,pni.tz_num ,pni.remarks
from t_pro_need_info pni
LEFT JOIN bm_project pro on pni.pro_id=pro.id
<where>
pni.need_type=1
<if test="proId!=null and proId!=''">
and pni.`pro_id` like concat('%',#{proId},'%')
</if>
<if test="module!=null and module!=''">
and pni.`module` like concat('%',#{module},'%')
</if>
<if test="name!=null and name!=''">
and pni.`name` like concat('%',#{name},'%')
</if>
</where>
</select>
<select id="getPorInfoDetail2" resultType="com.bonus.gzgqj.business.plan.entity.ProNeedInfo">
select pni.id,pni.pro_id proId,pni.type,pni.name,pni.module,pni.module_id,pni.need_type needType,
IFNULL(pni.unit,'-') unit ,IFNULL(pni.need_num,0) needNum ,(pni.fh_num )fhNum ,pro.`NAME` proName ,
IF(pni.need_num-pni.fh_num-pni.tz_num >0,pni.need_num-pni.fh_num-pni.tz_num,0) diff, IFNULL(ROUND((pni.fh_num+pni.tz_num)*100/pni.need_num,0),0) progress,
IF(pni.need_type=1,'计划内','计划外') typeName ,pni.tz_num tzNum,pni.remarks
from t_pro_need_info pni
LEFT JOIN bm_project pro on pni.pro_id=pro.id
<where>
<if test="proId!=null and proId!=''">
and pni.`pro_id` like concat('%',#{proId},'%')
</if>
<if test="module!=null and module!=''">
and pni.`module` like concat('%',#{module},'%')
</if>
<if test="name!=null and name!=''">
and pni.`name` like concat('%',#{name},'%')
</if>
</where>
</select>
<select id="getProDevSelected" resultType="com.bonus.gzgqj.business.plan.entity.ProDevSelect">
select distinct mt.id ,mt.`NAME`,mt.parent_id
from mm_type mt
where mt.`LEVEL`=3 and mt.IS_ACTIVE=1
</select>
<select id="getDevChilderList" resultType="com.bonus.gzgqj.business.plan.entity.ProDevSelect">
select distinct mt.id ,mt.`NAME`,mt.parent_id pId,mt.UNIT,mt.NUM,mt1.`NAME` pName,mt2.`NAME` ppName
from mm_type mt
LEFT JOIN mm_type mt1 on mt.PARENT_ID=mt1.id and mt.`LEVEL`=4 and mt1.`LEVEL`=3 and mt1.IS_ACTIVE=1
LEFT JOIN mm_type mt2 on mt1.PARENT_ID=mt2.id and mt1.`LEVEL`=3 and mt2.IS_ACTIVE=1
LEFT JOIN t_pro_need_info pni on pni.module_id=mt.id and pni.pro_id=#{proId}
where mt.`LEVEL`=4 and mt.IS_ACTIVE=1 and pni.id is null
and mt.parent_id=#{pId}
</select>
<select id="getProNeedInfo" resultType="com.bonus.gzgqj.business.plan.entity.ProNeedInfo">
select id, pro_id proId,type, name,
module,module_id moduleId,need_type needType,unit,need_num needNum,fh_num fhNum
,tz_num tzNum,remarks
from t_pro_need_info
WHERE id=#{id}
</select>
<select id="getProPlanInfo" resultType="com.bonus.gzgqj.business.plan.entity.ProPlanInfoVo">
select
ppi.pro_id proId, ppi.need_num needNum,
ppi.plan_num planNum,ppi.record_num recordNum,
ppi.out_num outNum, ppi.status,out2_num outNum2,record2_num recordNum2,
ppi.last_day lastDay
from t_pro_plan_info ppi
where ppi.pro_id=#{proId}
</select>
<select id="getStatistics" resultType="com.bonus.gzgqj.business.plan.entity.StatisticsVo">
select sum(need_num) needNum ,sum(fh_num+tz_num) fhNum,SUM(IF(need_num-fh_num-tz_num,need_num-fh_num-tz_num,0)) dfhNum,
ROUND(sum(fh_num+tz_num)/sum(need_num)*100) fh,100- ROUND(sum(fh_num+tz_num) /sum(need_num)*100) dfh
from t_pro_need_info
WHERE need_type=1
UNION
select IFNULL( sum(need_num),0) needNum ,IFNULL(sum(fh_num),0) fhNum,IFNULL(SUM(IF(need_num-fh_num-tz_num,need_num-fh_num-tz_num,0)),0) dfhNum,0,0
from t_pro_need_info
WHERE need_type=2
</select>
<!--超出 数量-->
<select id="getOverNum" resultType="com.bonus.gzgqj.business.plan.entity.StatisticsVo">
SELECT IFNULL(SUM(pni.need_num-mt.NUM),0) num
from t_pro_need_info pni
left join mm_type mt on pni.module_id=mt.id
where pni.need_type=1
</select>
<select id="getOutTimes" resultType="com.bonus.gzgqj.business.plan.entity.OutDetailInfoVo">
select id, create_day createDay,create_time
from t_plan_out
where pro_id=#{proId}
order by create_time desc
</select>
<select id="getOutDetails" resultType="com.bonus.gzgqj.business.plan.entity.OutDetailInfoVo">
select consignor userName,create_day createDay,remarks,pro_id proId
from t_plan_out
where id=#{id}
</select>
<!--查询历史新增的-->
<select id="getHisAddData" resultType="com.bonus.gzgqj.business.plan.entity.ProNeedInfo">
select pni.id,pni.pro_id proId,pni.type,pni.name,pni.module,pni.module_id,pni.need_type needType,
IFNULL(pni.unit,'-') unit ,pni.need_num needNum ,pni.fh_num fhNum
,pni.tz_num,pni.remarks
from t_pro_need_info pni
where pni.module_id=#{moduleId} and pni.pro_id=#{proId}
</select>
<select id="getOutDetailsInfo" resultType="java.lang.String">
select CONCAT(name,":",SUM(fh_num)) detail
from t_plan_out_detail
where out_id=#{id}
GROUP BY name
</select>
<!--批次详情接口-->
<select id="getOutDetailList" resultType="com.bonus.gzgqj.business.plan.entity.ProNeedInfo">
select id,out_id id ,
type, name,
module, unit,
module_id moduleId, fh_num fhNum,
tz_num tzNum, remarks,
data_type dataType
from t_plan_out_detail pod
<where>
out_id=#{id}
<if test="module!=null and module!=''">
and pod.`module` like concat('%',#{module},'%')
</if>
<if test="name!=null and name!=''">
and pod.`name` like concat('%',#{name},'%')
</if>
</where>
</select>
<select id="getDfhList" resultType="com.bonus.gzgqj.business.plan.entity.ProNeedInfo">
select pni.id,pni.pro_id proId,pni.type,pni.name,pni.module,pni.module_id,pni.need_type needType,
IFNULL(pni.unit,'-') unit ,IFNULL(pni.need_num,0) needNum ,(pni.fh_num+pni.tz_num )fhNum ,pro.`NAME` proName
,pni.tz_num ,pni.remarks
from t_pro_need_info pni
LEFT JOIN bm_project pro on pni.pro_id=pro.id
<where>
pni.need_type=1 and (pni.need_num-pni.fh_num-pni.tz_num)>0
<if test="proId!=null and proId!=''">
and pni.`pro_id` like concat('%',#{proId},'%')
</if>
<if test="module!=null and module!=''">
and pni.`module` like concat('%',#{module},'%')
</if>
<if test="name!=null and name!=''">
and pni.`name` like concat('%',#{name},'%')
</if>
</where>
</select>
<select id="getProPlanListByProId" resultType="com.bonus.gzgqj.business.plan.entity.PlanApplyBean">
SELECT
plan.id,
plan.CODE,pro.name proName ,
plan.project_id projectId,
plan.project_part projectPart,
plan.project_content projectContent,
plan.need_time needTime,
plan.creator,
plan.create_time createTime,
plan.remark,
plan.STATUS,
plan.updater,
plan.status_type statusType
FROM
t_plan_apply plan
left join bm_project pro on plan.project_id=pro.ID
<where>
plan.project_id=#{proId} and plan.status_type=1
<if test="keyWord !=null and keyWord !=''">
and (
pro.name like concat('%',#{keyWord},'%') or
plan.creator like concat('%',#{keyWord},'%') or
plan.CODE like concat('%',#{keyWord},'%') or
plan.need_time like concat('%',#{keyWord},'%') or
plan.project_part like concat('%',#{keyWord},'%') or
plan.project_content like concat('%',#{keyWord},'%') or
plan.remark like concat('%',#{keyWord},'%')
)
</if>
<if test="auditStatus !=null and auditStatus !=''">
and plan.STATUS=#{auditStatus}
</if>
</where>
order by plan.update_time DESC
</select>
<select id="getDataInfoByPage" resultType="com.bonus.gzgqj.business.plan.entity.ProNeedInfo">
select pni.id,pni.type,pni.name,pni.module,pni.module_id moduleId,pni.need_num needNum,pni.fh_num fhNum,pni.tz_num tzNum,
IF(pni.need_num-pni.fh_num-pni.tz_num >0,pni.need_num-pni.fh_num-pni.tz_num,0) diff,
pro.num proNum,plan.num planNum,pni.unit,pro2.name proName
from t_pro_need_info pni
LEFT JOIN(
select count(pro_id) num ,module_id
FROM t_pro_need_info
GROUP BY module_id
)pro on pro.module_id=pni.module_id
LEFT JOIN (
select model_id ,count(apply_id) num
FROM t_plan_details
GROUP BY model_id
)plan on plan.model_id=pni.module_id
LEFT JOIN bm_project pro2 on pni.pro_id=pro2.id
<where>
<if test='typeSource=="1"'>
and pni.fh_num=0
</if>
<if test='typeSource=="2"'>
and pni.fh_num>0
</if>
<if test="module!=null and module!=''">
and pni.`module` like concat('%',#{module},'%')
</if>
<if test="name!=null and name!=''">
and pni.`name` like concat('%',#{name},'%')
</if>
</where>
</select>
<select id="getDataPlanByPage" resultType="com.bonus.gzgqj.business.plan.entity.PlanApplyBean">
SELECT
plan.id,
plan.CODE,pro.name proName ,
plan.project_id projectId,
plan.project_part projectPart,
plan.project_content projectContent,
plan.need_time needTime,
plan.creator,
plan.create_time createTime,
plan.remark,
plan.STATUS,
plan.updater,tdd.need_num needNum ,
plan.status_type statusType ,tdd.model_id moduleId
FROM
t_plan_apply plan
left join bm_project pro on plan.project_id=pro.ID
left join t_plan_details tdd on plan.id=tdd.apply_id
where tdd.model_id=#{moduleId} and plan.status_type=1
</select>
<!--查询模型-->
<select id="getDataInfoDetails" resultType="com.bonus.gzgqj.business.plan.entity.ProNeedInfo">
select pni.id,pni.type,pni.name,pni.module,pni.module_id moduleId,pni.need_num needNum,pni.fh_num fhNum,pni.tz_num tzNum,
pro.num proNum,plan.num planNum,pni.unit,if(pni.need_num-pni.fh_num-pni.tz_num>0,pni.need_num-pni.fh_num-pni.tz_num,0) wfhNum,
mt.num kuNum ,ABS(pni.need_num-pni.fh_num-pni.tz_num-mt.num) clNum
from t_pro_need_info pni
left join mm_type mt on mt.id=pni.module_id and mt.`LEVEL`=4
LEFT JOIN(
select count(pro_id) num ,module_id
FROM t_pro_need_info
GROUP BY module_id
)pro on pro.module_id=pni.module_id
LEFT JOIN (
select model_id ,count(apply_id) num
FROM t_plan_details
GROUP BY model_id
)plan on plan.model_id=pni.module_id
where pni.module_id=#{moduleId}
</select>
<select id="getWarnInfoPage" resultType="com.bonus.gzgqj.business.plan.entity.ProNeedInfo">
select tni.pro_id,tni.type,tni.`name`,tni.module,tni.module_id moduleId ,tni.unit,tni.need_num needNum,tni.id ,mt.num,
FLOOR(tni.need_num-mt.num) diff
from t_pro_need_info tni
left join mm_type mt on mt.id=tni.module_id and mt.`LEVEL`=4
where tni.need_num-mt.NUM>0
<if test="module!=null and module!=''">
and pni.`module` like concat('%',#{module},'%')
</if>
<if test="name!=null and name!=''">
and pni.`name` like concat('%',#{name},'%')
</if>
</select>
<select id="getWarnInfoPage2" resultType="com.bonus.gzgqj.business.plan.entity.ProNeedInfo">
select tni.pro_id,tni.type,tni.`name`,tni.module,tni.module_id moduleId ,
tni.unit,tni.need_num needNum,tni.id ,pro2.name proName,tni.fh_num fhNum
from t_pro_need_info tni
LEFT JOIN bm_project pro2 on tni.pro_id=pro2.id
where 1=1 and tni.need_type=2
<if test="module!=null and module!=''">
and pni.`module` like concat('%',#{module},'%')
</if>
<if test="name!=null and name!=''">
and pni.`name` like concat('%',#{name},'%')
</if>
</select>
</mapper>