<?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="doumeemes.dao.ext.WorkPlansExtMapper">
|
|
<!-- 管理页面查询 -->
|
<resultMap id="WorkPlansExtListVO" type="doumeemes.dao.ext.vo.WorkPlansExtListVO" autoMapping="true">
|
<id column="ID" jdbcType="INTEGER" property="id"/>
|
</resultMap>
|
|
<resultMap id="WorkPlansVO" type="doumeemes.dao.business.vo.WorkPlansVO" autoMapping="true">
|
<id column="ID" jdbcType="INTEGER" property="id"/>
|
</resultMap>
|
|
<select id="selectList" parameterType="doumeemes.dao.ext.dto.QueryWorkPlansExtDTO" resultMap="WorkPlansExtListVO">
|
SELECT
|
`workPlans`.`ID`,
|
`workPlans`.`DELETED`,
|
`workPlans`.`CREATE_USER`,
|
`workPlans`.`CREATE_TIME`,
|
`workPlans`.`UPDATE_USER`,
|
`workPlans`.`UPDATE_TIME`,
|
`workPlans`.`REMARK`,
|
`workPlans`.`ROOT_DEPART_ID`,
|
`workPlans`.`DEPART_ID`,
|
`workPlans`.`FACTORY_ID`,
|
`workPlans`.`ORIGIN`,
|
`workPlans`.`PLAN_CODE`,
|
`workPlans`.`PLAN_DATE`,
|
`workPlans`.`START_DATE`,
|
`workPlans`.`MATERIAL_ID`,
|
`workPlans`.`UNIT_ID`,
|
`workPlans`.`NUM`,
|
`workPlans`.`BATCH`,
|
`workPlans`.`STATUS`,
|
`workPlans`.`IMPORT_ID`,
|
`workPlans`.`PAUSED`,
|
`workPlans`.`USER_ID`,
|
`workPlans`.`SALESORDER`,
|
`workPlans`.`PUBLISH_DATE`
|
FROM `work_plans` `workPlans`
|
<where>
|
<if test="id != null">
|
AND `workPlans`.`ID` = #{id}
|
</if>
|
<if test="deleted != null">
|
AND `workPlans`.`DELETED` = #{deleted}
|
</if>
|
<if test="createUser != null">
|
AND `workPlans`.`CREATE_USER` = #{createUser}
|
</if>
|
<if test="createTime != null">
|
AND `workPlans`.`CREATE_TIME` = #{createTime}
|
</if>
|
<if test="updateUser != null">
|
AND `workPlans`.`UPDATE_USER` = #{updateUser}
|
</if>
|
<if test="updateTime != null">
|
AND `workPlans`.`UPDATE_TIME` = #{updateTime}
|
</if>
|
<if test="remark != null and remark != ''">
|
AND `workPlans`.`REMARK` = #{remark}
|
</if>
|
<if test="rootDepartId != null">
|
AND `workPlans`.`ROOT_DEPART_ID` = #{rootDepartId}
|
</if>
|
<if test="departId != null">
|
AND `workPlans`.`DEPART_ID` = #{departId}
|
</if>
|
<if test="factoryId != null">
|
AND `workPlans`.`FACTORY_ID` = #{factoryId}
|
</if>
|
<if test="origin != null">
|
AND `workPlans`.`ORIGIN` = #{origin}
|
</if>
|
<if test="planCode != null and planCode != ''">
|
AND `workPlans`.`PLAN_CODE` = #{planCode}
|
</if>
|
<if test="planDate != null">
|
AND `workPlans`.`PLAN_DATE` = #{planDate}
|
</if>
|
<if test="startDate != null">
|
AND `workPlans`.`START_DATE` = #{startDate}
|
</if>
|
<if test="materialId != null">
|
AND `workPlans`.`MATERIAL_ID` = #{materialId}
|
</if>
|
<if test="unitId != null">
|
AND `workPlans`.`UNIT_ID` = #{unitId}
|
</if>
|
<if test="num != null">
|
AND `workPlans`.`NUM` = #{num}
|
</if>
|
<if test="batch != null and batch != ''">
|
AND `workPlans`.`BATCH` = #{batch}
|
</if>
|
<if test="status != null">
|
AND `workPlans`.`STATUS` = #{status}
|
</if>
|
<if test="importId != null">
|
AND `workPlans`.`IMPORT_ID` = #{importId}
|
</if>
|
<if test="paused != null">
|
AND `workPlans`.`PAUSED` = #{paused}
|
</if>
|
<if test="userId != null">
|
AND `workPlans`.`USER_ID` = #{userId}
|
</if>
|
<if test="publishDate != null">
|
AND `workPlans`.`PUBLISH_DATE` = #{publishDate}
|
</if>
|
<if test="salesorder != null">
|
AND `workPlans`.`SALESORDER` = #{salesorder}
|
</if>
|
</where>
|
</select>
|
|
<select id="getWorkPlansVOPage" parameterType="doumeemes.dao.ext.dto.QueryWorkPlansDTO" resultMap="WorkPlansVO">
|
SELECT
|
`a`.*, mmodel.CODE as materialCode, mmodel.NAME as materialName , fmodel.NAME as factoryName,usermodel.REALNAME as userName , usermodel.mobile as userMobile ,
|
umodel.NAME as unitName
|
FROM `work_plans` `a`
|
LEFT JOIN `department` `dmodel` ON a.DEPART_ID=dmodel.ID
|
LEFT JOIN `material_distribute` `mdmodel` ON a.MATERIAL_ID=mdmodel.ID
|
LEFT JOIN `material` `mmodel` ON mdmodel.MATERIAL_ID=mmodel.ID
|
LEFT JOIN `department` `fmodel` ON a.FACTORY_ID=fmodel.ID
|
LEFT JOIN `unit` `umodel` ON a.UNIT_ID=umodel.ID
|
LEFT JOIN `system_user` `usermodel` ON a.USER_ID=usermodel.ID
|
<where>
|
and a.DELETED = 0
|
<if test="rootDepartId != null">
|
AND a.ROOT_DEPART_ID = #{rootDepartId}
|
</if>
|
<if test="departId != null">
|
AND a.DEPART_ID = #{departId}
|
</if>
|
|
<if test="factoryId != null">
|
AND a.`FACTORY_ID` = #{factoryId}
|
</if>
|
<if test="planStatus != null">
|
AND a.`STATUS` = #{planStatus}
|
</if>
|
<if test="planCode != null and planCode != ''">
|
AND `a`.`PLAN_CODE` like concat('%',#{planCode},'%')
|
</if>
|
<if test="materialCode != null and materialCode != ''">
|
AND `mmodel`.`CODE` like concat('%',#{materialCode},'%')
|
</if>
|
<if test="materialName != null and materialName != ''">
|
AND `mmodel`.`NAME` like concat('%',#{materialName},'%')
|
</if>
|
<if test="batch != null and batch != ''">
|
AND `a`.`batch` like concat('%',#{batch},'%')
|
</if>
|
<if test="salesorder != null and salesorder != ''">
|
AND `a`.`SALESORDER` like concat('%',#{salesorder},'%')
|
</if>
|
<if test="startDateStart != null and startDateStart != ''">
|
AND `a`.`START_DATE` >= concat(#{startDateStart},' 00:00:00')
|
</if>
|
<if test="startDateEnd != null and startDateEnd != ''">
|
AND concat(#{startDateEnd},' 23:59:59') >= `a`.`START_DATE`
|
</if>
|
<if test="planDateStart != null and planDateStart != ''">
|
AND `a`.`PLAN_DATE` >= concat(#{planDateStart},' 00:00:00')
|
</if>
|
<if test="planDateEnd != null and planDateEnd != ''">
|
AND concat(#{planDateEnd},' 23:59:59') >= `a`.`PLAN_DATE`
|
</if>
|
</where>
|
order by a.START_DATE desc, a.CREATE_TIME desc
|
</select>
|
<select id="getPlansStaticticsData" parameterType="doumeemes.dao.ext.dto.QueryWorkPlansDTO" resultType="doumeemes.dao.business.dto.statistics.StatisticsPlanDataModel">
|
SELECT count(a.id) as ingNum,
|
(select count(b.id) FROM `work_plans` b where b.DELETED = 0 AND b.ROOT_DEPART_ID = #{rootDepartId} AND b.DEPART_ID = #{departId} AND (b.`STATUS` = 1 and to_days(now()) > to_days(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 to_days(b.create_time)=to_days(now()) 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_GROUP_ID)) FROM `workorder` b where to_days(b.create_time)=to_days(now()) and b.DELETED = 0 AND b.ROOT_DEPART_ID = #{rootDepartId} AND b.DEPART_ID = #{departId} AND b.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.DELETED = 0 AND b.ROOT_DEPART_ID = #{rootDepartId} AND b.DEPART_ID = #{departId} AND to_days(b.create_time)=to_days(now()) 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.DELETED = 0 AND b.ROOT_DEPART_ID = #{rootDepartId} AND b.DEPART_ID = #{departId} AND to_days(b.create_time)=to_days(now()) and c.status=4) as doneNum
|
FROM `work_plans` `a`
|
where
|
a.DELETED = 0 AND a.ROOT_DEPART_ID = #{rootDepartId} AND a.DEPART_ID = #{departId} AND a.`STATUS` = 1
|
</select>
|
<select id="selectStatisticsList" parameterType="doumeemes.dao.ext.dto.QueryWorkPlansDTO" resultType="doumeemes.dao.business.dto.statistics.WorkPlansPageModel">
|
select a.status,a.plan_code as code,a.num,a.id,a.NUM,m.id as materialId,m.name as materialName,m.code as materialCode
|
<!-- ,(select sum(b.num) from workorder_record b left join plans c on b.PLAN_ID=c.id where b.type=1 and b.DELETED=0 and c.WORK_PLANS_ID=a.id) as doneNum
|
,(select sum(b.QUALIFIED_NUM) from workorder_record b left join plans c on b.PLAN_ID=c.id where b.type=1 and b.DELETED=0 and c.WORK_PLANS_ID=a.id) as qualifiedNum
|
-->,(select b.route_id from bom b where b.MATERIAL_ID=c.id and b.ROOT_DEPART_ID=a.ROOT_DEPART_ID) as routeId
|
FROM `work_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= 1 or (a.status=6 and EXISTS(select b.id from workorder_record b left join plans c on b.PLAN_ID=c.id where b.type=1 and to_days(b.create_time)=to_days(now()) and b.DELETED=0 and c.WORK_PLANS_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="getWorkPlansVODetail" parameterType="doumeemes.dao.ext.dto.QueryWorkPlansDTO" resultMap="WorkPlansVO">
|
SELECT
|
`a`.*, mmodel.CODE as materialCode, mmodel.NAME as materialName , fmodel.NAME as factoryName,usermodel.REALNAME as userName ,e.NAME as userDepartName , usermodel.mobile as userMobile
|
FROM `work_plans` `a`
|
LEFT JOIN `department` `dmodel` ON a.DEPART_ID=dmodel.ID
|
LEFT JOIN `material_distribute` `mdmodel` ON a.MATERIAL_ID=mdmodel.ID
|
LEFT JOIN `material` `mmodel` ON mdmodel.MATERIAL_ID=mmodel.ID
|
LEFT JOIN `department` `fmodel` ON a.FACTORY_ID=fmodel.ID
|
LEFT JOIN `unit` `umodel` ON a.UNIT_ID=umodel.ID
|
LEFT JOIN `system_user` `usermodel` ON a.USER_ID=usermodel.ID
|
left join company_user cu on usermodel.id = cu.USER_ID and cu.ROOT_DEPART_ID = a.ROOT_DEPART_ID and cu.DELETED = 0
|
LEFT JOIN department e ON cu.DEPARTMENT_ID = e.id
|
<where>
|
and a.id = #{workPlanId}
|
</where>
|
</select>
|
|
</mapper>
|