jiaosong
2023-08-18 26e4b49b3b51e123e9ce2b055c8e0d37d35df260
server/src/main/resources/mappers/PlansExtMapper.xml
@@ -123,7 +123,7 @@
  <select id="selectByModel" parameterType="doumeemes.dao.ext.dto.QueryPlansExtDTO" resultMap="PlansExtListVO">
  SELECT
  `a`.*
    ,(  SELECT sum( b.PLAN_NUM ) FROM  workorder b  WHERE b.deleted = 0 AND b.PLAN_ID = a.id and b.status !=6) AS workorderDistributNum
    , ifnull((  SELECT sum(  b.UNQUALIFIED_NUM + QUALIFIED_NUM ) FROM  workorder b  WHERE b.deleted = 0  AND b.PLAN_ID = a.id  and b.status  = 4 ),0) AS workorderDistributNum
    from plans a
    <where>
    <if test="id != null">
@@ -287,8 +287,34 @@
    and to_days(`a`.`CREATE_TIME`)=to_days(now())
  </where>
  </select>
  <select id="selectProcedureProcessList" parameterType="doumeemes.dao.ext.dto.QueryPlansExtDTO" resultType="doumeemes.dao.business.dto.statistics.ProcedureProcessModel">
    select a.PROCEDURE_ID as procedureId,
    b.name as procedureName,
    sum(a.num) as num,
    count(DISTINCT(a.id)) as planCount,
    (select sum(d.QUALIFIED_NUM) from workorder_record d where d.DELETED=0 and d.PLAN_ID=a.id and d.TYPE=1) as qualifiedNum ,
    (select sum(d.UNQUALIFIED_NUM) from workorder_record d where d.DELETED=0 and d.PLAN_ID=a.id and d.TYPE=1) as unqualifiedNum
    from plans a
    left join procedures b on a.PROCEDURE_ID =b.ID
    where ( a.`STATUS` in (1,4) or a.`STATUS`=6 and EXISTS(select e.id from workorder_record e where e.PLAN_ID = a.id and TO_DAYS(now())=TO_DAYS(e.CREATE_TIME)))
    and a.ROOT_DEPART_ID=#{rootDepartId} and a.DEPART_ID=#{departId}
    and b.DELETED=0 and a.ROOT_DEPART_ID=132
    GROUP BY a.PROCEDURE_ID
    order by b.SORTNUM
  </select>
  <select id="selectStatisticsList" parameterType="doumeemes.dao.ext.dto.QueryPlansExtDTO" resultType="doumeemes.dao.business.dto.statistics.ProcedurePlansPageModel">
    select a.status,a.NUM,m.name as categoryName,m.code as materialCode
    ,(select sum(b.UNQUALIFIED_NUM) from workorder_record b where b.type=1 and b.DELETED=0 and b.PLAN_ID=a.id) as unqualifiedNum
    ,(select sum(b.QUALIFIED_NUM) from workorder_record b where b.type=1 and b.DELETED=0 and b.PLAN_ID=a.id) as qualifiedNum
    FROM `plans` `a`
    LEFT JOIN `material_distribute` c ON a.MATERIAL_ID=c.ID
    LEFT JOIN `material` m ON c.MATERIAL_ID=m.ID
    where (a.status in (1,4) or (a.status=6 and EXISTS(select b.id from workorder_record b where b.type=1 and b.DELETED=0 and b.PLAN_ID=a.id) ))
    and a.deleted=0 and a.ROOT_DEPART_ID=#{rootDepartId} and a.DEPART_ID=#{departId}
    order by a.CREATE_TIME
  </select>
  <select id="selectList" parameterType="doumeemes.dao.ext.dto.QueryPlansExtDTO" resultMap="PlansExtListVO">
    SELECT
  SELECT
      `a`.*,
      `dmodel`.`ID` AS DMODEL_ID,
      `dmodel`.`NAME` AS DMODEL_NAME,
@@ -363,11 +389,13 @@
      `usermodel`.`SYSTEMID` AS USERMODEL_SYSTEMID,
      `usermodel`.`INVALID_TIME` AS USERMODEL_INVALID_TIME,
      `usermodel`.`TYPE` AS USERMODEL_TYPE
    ,(  SELECT sum( b.PLAN_NUM ) FROM  workorder b  WHERE b.deleted = 0 AND b.PLAN_ID = a.id  and b.status !=6) AS workorderDistributNum ,
    , ifnull((  SELECT sum(  b.UNQUALIFIED_NUM + QUALIFIED_NUM ) FROM  workorder b  WHERE b.deleted = 0  AND b.PLAN_ID = a.id  and b.status  = 4 ),0) AS workorderDistributNum ,
    `mmodel`.name as materialName , `mmodel`.code as materialCode ,`fmodel`.name as factoryName , `pmodel`.name as produceName ,
      concat(`usermodel`.realname,' ',`usermodel`.mobile) as planUserName , `umodel`.name as unitName ,
      w.PLAN_CODE as workPlanCode
      w.PLAN_CODE as workPlanCode , w.SALESORDER as salesOrder ,
      w.START_DATE as workPlanStartDate  , w.PLAN_DATE as workPlanEndDate,
      w.`PLAN_DATE` as workPlanPlanDate,
      ifnull((select  sum(worder.UNQUALIFIED_NUM + worder.QUALIFIED_NUM ) from workorder worder where worder.PLAN_ID = a.id and worder.STATUS = 4  ),0) as produceNum
    FROM `plans` `a`
    LEFT JOIN `department` `dmodel` ON a.DEPART_ID=dmodel.ID
    LEFT JOIN `material_distribute` `mdmodel` ON a.MATERIAL_ID=mdmodel.ID
@@ -420,6 +448,12 @@
      </if>
      <if test="planDate != null">
        AND `a`.`PLAN_DATE` = #{planDate}
      </if>
      <if test="planDateStartDate != null and planDateStartDate != ''">
        AND `a`.`PLAN_DATE` >= concat(#{planDateStartDate},' 00:00:00')
      </if>
      <if test="planDateEndDate != null and planDateEndDate != ''">
        AND concat(#{planDateEndDate},' 23:59:59') >= `a`.`PLAN_DATE`
      </if>
      <if test="materialId != null">
        AND `a`.`MATERIAL_ID` = #{materialId}
@@ -763,14 +797,14 @@
      <if test="usermodelInvalidTime != null">
        AND `usermodel`.`INVALID_TIME` = #{usermodelInvalidTime}
      </if>
      <if test="startDate != null">
        AND `a`.`PLAN_DATE` >= #{startDate}
      </if>
      <if test="endDate != null">
        AND   #{endDate} >= `a`.`PLAN_DATE`
      </if>
<!--      <if test="startDate != null">-->
<!--        AND `a`.`PLAN_DATE` >= #{startDate}-->
<!--      </if>-->
<!--      <if test="endDate != null">-->
<!--        AND   #{endDate} >= `a`.`PLAN_DATE`-->
<!--      </if>-->
      <if test="mixParam != null and mixParam!=''">
        AND  (mmodel.name like concat('%',#{mixParam},'%') or mmodel.code like concat('%',#{mixParam},'%') or pmodel.name like concat('%',#{mixParam},'%'))
        AND  (mmodel.name like concat('%',#{mixParam},'%') or mmodel.code like concat('%',#{mixParam},'%') or pmodel.name like concat('%',#{mixParam},'%')  or a.BATCH like concat('%',#{mixParam},'%') or w.SALESORDER like concat('%',#{mixParam},'%') )
      </if>
      <if test="usermodelInvalidTime != null">
        AND `usermodel`.`INVALID_TIME` = #{usermodelInvalidTime}
@@ -1320,4 +1354,15 @@
           )
    </foreach>
  </insert>
  <select id="getPlansStaticticsData" parameterType="doumeemes.dao.ext.dto.QueryPlansExtDTO" resultType="doumeemes.dao.business.dto.statistics.StatisticsPlanDataModel">
    SELECT count(a.id) as ingNum,
    (select count(b.id)  FROM `plans` b where b.DELETED = 0 and b.PROCEDURE_ID=#{procedureId}  AND b.ROOT_DEPART_ID = #{rootDepartId} AND b.DEPART_ID = #{departId}  AND  (b.`STATUS` in (1,4) and  now() > b.plan_Date  )) as delayNum,
    (select count(distinct(b.CREATE_USER))  FROM `workorder_record` b left join workorder c on b.workorder_id =c.id where b.PROCEDURE_ID=#{procedureId}  AND b.DELETED = 0 AND b.ROOT_DEPART_ID = #{rootDepartId} AND b.DEPART_ID = #{departId}  AND c.status in (0,1,2,3,4,7)) as prouserNum,
    (select count(distinct(b.PRO_DEVICE_ID))  FROM `workorder_record` b left join workorder c on b.workorder_id =c.id where b.PROCEDURE_ID=#{procedureId}  AND b.DELETED = 0 AND b.ROOT_DEPART_ID = #{rootDepartId} AND b.DEPART_ID = #{departId}  AND c.status in (0,1,2,3,4,7)) as deviceNum,
    (select sum(ifnull(b.UNQUALIFIED_NUM,0))  FROM `workorder_record` b left join workorder c on b.workorder_id =c.id where b.PROCEDURE_ID=#{procedureId}  AND b.DELETED = 0 AND b.ROOT_DEPART_ID = #{rootDepartId} AND b.DEPART_ID = #{departId}  AND c.status=4) as unqualifiedNum,
    (select sum(ifnull(b.NUM,0))  FROM `workorder_record` b left join workorder c on b.workorder_id =c.id where b.PROCEDURE_ID=#{procedureId}  AND b.DELETED = 0 AND b.ROOT_DEPART_ID = #{rootDepartId} AND b.DEPART_ID = #{departId}  AND c.status=4) as doneNum
    FROM `plans` `a`
    where
    a.DELETED = 0 AND a.ROOT_DEPART_ID = #{rootDepartId} AND a.DEPART_ID = #{departId} and a.PROCEDURE_ID=#{procedureId} AND a.`STATUS` in (1,4)
  </select>
</mapper>