| <?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.PlansExtMapper"> | 
|   | 
|   <!-- 管理页面查询 --> | 
|   <resultMap id="PlansExtListVO" type="doumeemes.dao.ext.vo.PlansExtListVO" autoMapping="true"> | 
|     <id column="ID" jdbcType="INTEGER" property="id"/> | 
|     <association property="dmodel" javaType="doumeemes.dao.business.model.Department"> | 
|       <id column="DMODEL_ID" jdbcType="INTEGER" property="id"/> | 
|       <result column="DMODEL_DELETED" jdbcType="TINYINT" property="deleted"/> | 
|       <result column="DMODEL_CREATE_USER" jdbcType="INTEGER" property="createUser"/> | 
|       <result column="DMODEL_CREATE_TIME" jdbcType="TIMESTAMP" property="createTime"/> | 
|       <result column="DMODEL_UPDATE_USER" jdbcType="INTEGER" property="updateUser"/> | 
|       <result column="DMODEL_UPDATE_TIME" jdbcType="TIMESTAMP" property="updateTime"/> | 
|       <result column="DMODEL_NAME" jdbcType="VARCHAR" property="name"/> | 
|       <result column="DMODEL_REMARK" jdbcType="VARCHAR" property="remark"/> | 
|       <result column="DMODEL_ROOT_ID" jdbcType="INTEGER" property="rootId"/> | 
|       <result column="DMODEL_PARENT_ID" jdbcType="INTEGER" property="parentId"/> | 
|       <result column="DMODEL_COMPANY_ID" jdbcType="INTEGER" property="companyId"/> | 
|       <result column="DMODEL_TYPE" jdbcType="TINYINT" property="type"/> | 
|       <result column="DMODEL_ERP_ID" jdbcType="VARCHAR" property="erpId"/> | 
|       <result column="DMODEL_STATUS" jdbcType="INTEGER" property="status"/> | 
|       <result column="DMODEL_VALID_TIME" jdbcType="TIMESTAMP" property="validTime"/> | 
|       <result column="DMODEL_INVALID_TIME" jdbcType="TIMESTAMP" property="invalidTime"/> | 
|     </association> | 
|     <association property="mmodel" javaType="doumeemes.dao.business.model.Material"> | 
|       <id column="MMODEL_ID" jdbcType="INTEGER" property="id"/> | 
|       <result column="MMODEL_DELETED" jdbcType="TINYINT" property="deleted"/> | 
|       <result column="MMODEL_CREATE_USER" jdbcType="INTEGER" property="createUser"/> | 
|       <result column="MMODEL_CREATE_TIME" jdbcType="TIMESTAMP" property="createTime"/> | 
|       <result column="MMODEL_UPDATE_USER" jdbcType="INTEGER" property="updateUser"/> | 
|       <result column="MMODEL_UPDATE_TIME" jdbcType="TIMESTAMP" property="updateTime"/> | 
|       <result column="MMODEL_REMARK" jdbcType="VARCHAR" property="remark"/> | 
|       <result column="MMODEL_ROOT_DEPART_ID" jdbcType="INTEGER" property="rootDepartId"/> | 
|       <result column="MMODEL_NAME" jdbcType="VARCHAR" property="name"/> | 
|       <result column="MMODEL_CODE" jdbcType="VARCHAR" property="code"/> | 
|       <result column="MMODEL_ATTR" jdbcType="VARCHAR" property="attr"/> | 
|       <result column="MMODEL_UNION_NAME" jdbcType="VARCHAR" property="unionName"/> | 
|       <result column="MMODEL_UNIT_ID" jdbcType="INTEGER" property="unitId"/> | 
|       <result column="MMODEL_CATE_UNION_ID" jdbcType="INTEGER" property="cateUnionId"/> | 
|       <result column="MMODEL_FORMATION" jdbcType="TINYINT" property="formation"/> | 
|       <result column="MMODEL_QRCODE_ID" jdbcType="VARCHAR" property="qrcodeId"/> | 
|       <result column="MMODEL_STATUS" jdbcType="TINYINT" property="status"/> | 
|       <result column="MMODEL_VALID_TIME" jdbcType="TIMESTAMP" property="validTime"/> | 
|       <result column="MMODEL_INVALID_TIME" jdbcType="TIMESTAMP" property="invalidTime"/> | 
|       <result column="MMODEL_CHECK_WAY" jdbcType="TINYINT" property="checkWay"/> | 
|       <result column="MMODEL_QUALITY_REQUIRE" jdbcType="VARCHAR" property="qualityRequire"/> | 
|       <result column="MMODEL_CHECK_NOTE" jdbcType="VARCHAR" property="checkNote"/> | 
|     </association> | 
|     <association property="pmodel" javaType="doumeemes.dao.business.model.Procedures"> | 
|       <id column="PMODEL_ID" jdbcType="INTEGER" property="id"/> | 
|       <result column="PMODEL_DELETED" jdbcType="TINYINT" property="deleted"/> | 
|       <result column="PMODEL_CREATE_USER" jdbcType="INTEGER" property="createUser"/> | 
|       <result column="PMODEL_CREATE_TIME" jdbcType="TIMESTAMP" property="createTime"/> | 
|       <result column="PMODEL_UPDATE_USER" jdbcType="INTEGER" property="updateUser"/> | 
|       <result column="PMODEL_UPDATE_TIME" jdbcType="TIMESTAMP" property="updateTime"/> | 
|       <result column="PMODEL_REMARK" jdbcType="VARCHAR" property="remark"/> | 
|       <result column="PMODEL_ROOT_DEPART_ID" jdbcType="INTEGER" property="rootDepartId"/> | 
|       <result column="PMODEL_DEPART_ID" jdbcType="INTEGER" property="departId"/> | 
|       <result column="PMODEL_CODE" jdbcType="VARCHAR" property="code"/> | 
|       <result column="PMODEL_NAME" jdbcType="VARCHAR" property="name"/> | 
|       <result column="PMODEL_SORTNUM" jdbcType="INTEGER" property="sortnum"/> | 
|       <result column="PMODEL_ORG_ID" jdbcType="INTEGER" property="orgId"/> | 
|       <result column="PMODEL_USER_ID" jdbcType="INTEGER" property="userId"/> | 
|       <result column="PMODEL_PICKING_WAREHOUSE_ID" jdbcType="INTEGER" property="pickingWarehouseId"/> | 
|       <result column="PMODEL_PRODUCE_WAREHOUSE_ID" jdbcType="INTEGER" property="produceWarehouseId"/> | 
|       <result column="PMODEL_LEVEL" jdbcType="TINYINT" property="level"/> | 
|     </association> | 
|     <association property="fmodel" javaType="doumeemes.dao.business.model.Department"> | 
|       <id column="FMODEL_ID" jdbcType="INTEGER" property="id"/> | 
|       <result column="FMODEL_DELETED" jdbcType="TINYINT" property="deleted"/> | 
|       <result column="FMODEL_CREATE_USER" jdbcType="INTEGER" property="createUser"/> | 
|       <result column="FMODEL_CREATE_TIME" jdbcType="TIMESTAMP" property="createTime"/> | 
|       <result column="FMODEL_UPDATE_USER" jdbcType="INTEGER" property="updateUser"/> | 
|       <result column="FMODEL_UPDATE_TIME" jdbcType="TIMESTAMP" property="updateTime"/> | 
|       <result column="FMODEL_NAME" jdbcType="VARCHAR" property="name"/> | 
|       <result column="FMODEL_REMARK" jdbcType="VARCHAR" property="remark"/> | 
|       <result column="FMODEL_ROOT_ID" jdbcType="INTEGER" property="rootId"/> | 
|       <result column="FMODEL_PARENT_ID" jdbcType="INTEGER" property="parentId"/> | 
|       <result column="FMODEL_COMPANY_ID" jdbcType="INTEGER" property="companyId"/> | 
|       <result column="FMODEL_TYPE" jdbcType="TINYINT" property="type"/> | 
|       <result column="FMODEL_ERP_ID" jdbcType="VARCHAR" property="erpId"/> | 
|       <result column="FMODEL_STATUS" jdbcType="INTEGER" property="status"/> | 
|       <result column="FMODEL_VALID_TIME" jdbcType="TIMESTAMP" property="validTime"/> | 
|       <result column="FMODEL_INVALID_TIME" jdbcType="TIMESTAMP" property="invalidTime"/> | 
|     </association> | 
|     <association property="umodel" javaType="doumeemes.dao.business.model.Unit"> | 
|       <id column="UMODEL_ID" jdbcType="INTEGER" property="id"/> | 
|       <result column="UMODEL_DELETED" jdbcType="TINYINT" property="deleted"/> | 
|       <result column="UMODEL_CREATE_USER" jdbcType="INTEGER" property="createUser"/> | 
|       <result column="UMODEL_CREATE_TIME" jdbcType="TIMESTAMP" property="createTime"/> | 
|       <result column="UMODEL_UPDATE_USER" jdbcType="INTEGER" property="updateUser"/> | 
|       <result column="UMODEL_UPDATE_TIME" jdbcType="TIMESTAMP" property="updateTime"/> | 
|       <result column="UMODEL_REMARK" jdbcType="VARCHAR" property="remark"/> | 
|       <result column="UMODEL_ROOT_DEPART_ID" jdbcType="INTEGER" property="rootDepartId"/> | 
|       <result column="UMODEL_NAME" jdbcType="VARCHAR" property="name"/> | 
|       <result column="UMODEL_TYPE" jdbcType="TINYINT" property="type"/> | 
|       <result column="UMODEL_STATUS" jdbcType="TINYINT" property="status"/> | 
|     </association> | 
|     <association property="usermodel" javaType="doumeemes.dao.system.model.SystemUser"> | 
|       <id column="USERMODEL_ID" jdbcType="INTEGER" property="id"/> | 
|       <result column="USERMODEL_DELETED" jdbcType="TINYINT" property="deleted"/> | 
|       <result column="USERMODEL_CREATE_USER" jdbcType="INTEGER" property="createUser"/> | 
|       <result column="USERMODEL_CREATE_TIME" jdbcType="TIMESTAMP" property="createTime"/> | 
|       <result column="USERMODEL_UPDATE_USER" jdbcType="INTEGER" property="updateUser"/> | 
|       <result column="USERMODEL_UPDATE_TIME" jdbcType="TIMESTAMP" property="updateTime"/> | 
|       <result column="USERMODEL_FIXED" jdbcType="TINYINT" property="fixed"/> | 
|       <result column="USERMODEL_PASSWORD" jdbcType="VARCHAR" property="password"/> | 
|       <result column="USERMODEL_SALT" jdbcType="VARCHAR" property="salt"/> | 
|       <result column="USERMODEL_AVATAR" jdbcType="VARCHAR" property="avatar"/> | 
|       <result column="USERMODEL_MOBILE" jdbcType="VARCHAR" property="mobile"/> | 
|       <result column="USERMODEL_EMAIL" jdbcType="VARCHAR" property="email"/> | 
|       <result column="USERMODEL_SEX" jdbcType="VARCHAR" property="sex"/> | 
|       <result column="USERMODEL_BIRTHDAY" jdbcType="DATE" property="birthday"/> | 
|       <result column="USERMODEL_EMP_NO" jdbcType="VARCHAR" property="empNo"/> | 
|       <result column="USERMODEL_REALNAME" jdbcType="VARCHAR" property="realname"/> | 
|       <result column="USERMODEL_USERNAME" jdbcType="VARCHAR" property="username"/> | 
|       <result column="USERMODEL_SYSTEMID" jdbcType="VARCHAR" property="systemid"/> | 
|       <result column="USERMODEL_INVALID_TIME" jdbcType="TIMESTAMP" property="invalidTime"/> | 
|       <result column="USERMODEL_TYPE" jdbcType="INTEGER" property="type"/> | 
|     </association> | 
|   </resultMap> | 
|   <select id="selectByModel" parameterType="doumeemes.dao.ext.dto.QueryPlansExtDTO" resultMap="PlansExtListVO"> | 
|   SELECT | 
|   `a`.* | 
|     , 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"> | 
|       AND `a`.`ID` = #{id} | 
|     </if> | 
|     <if test="deleted != null"> | 
|       AND `a`.`DELETED` = #{deleted} | 
|     </if> | 
|     <if test="createUser != null"> | 
|       AND `a`.`CREATE_USER` = #{createUser} | 
|     </if> | 
|     <if test="createTime != null"> | 
|       AND `a`.`CREATE_TIME` = #{createTime} | 
|     </if> | 
|     <if test="updateUser != null"> | 
|       AND `a`.`UPDATE_USER` = #{updateUser} | 
|     </if> | 
|     <if test="paused != null"> | 
|       AND `a`.`PAUSED` = #{paused} | 
|     </if> | 
|     <if test="type != null"> | 
|       AND `a`.`TYPE` = #{type} | 
|     </if> | 
|     <if test="updateTime != null"> | 
|       AND `a`.`UPDATE_TIME` = #{updateTime} | 
|     </if> | 
|     <if test="remark != null and remark != ''"> | 
|       AND `a`.`REMARK` = #{remark} | 
|     </if> | 
|     <if test="rootDepartId != null"> | 
|       AND `a`.`ROOT_DEPART_ID` = #{rootDepartId} | 
|     </if> | 
|     <if test="departId != null"> | 
|       AND `a`.`DEPART_ID` = #{departId} | 
|     </if> | 
|     <if test="origin != null"> | 
|       AND `a`.`ORIGIN` = #{origin} | 
|     </if> | 
|     <if test="planDate != null"> | 
|       AND `a`.`PLAN_DATE` = #{planDate} | 
|     </if> | 
|     <if test="materialId != null"> | 
|       AND `a`.`MATERIAL_ID` = #{materialId} | 
|     </if> | 
|     <if test="procedureId != null"> | 
|       AND `a`.`PROCEDURE_ID` = #{procedureId} | 
|     </if> | 
|     <if test="factoryId != null"> | 
|       AND `a`.`FACTORY_ID` = #{factoryId} | 
|     </if> | 
|     <if test="unitId != null"> | 
|       AND `a`.`UNIT_ID` = #{unitId} | 
|     </if> | 
|     <if test="num != null"> | 
|       AND `a`.`NUM` = #{num} | 
|     </if> | 
|     <if test="batch != null and batch != ''"> | 
|       AND `a`.`BATCH` = #{batch} | 
|     </if> | 
|     <if test="urgent != null"> | 
|       AND `a`.`URGENT` = #{urgent} | 
|     </if> | 
|     <if test="importId != null"> | 
|       AND `a`.`IMPORT_ID` = #{importId} | 
|     </if> | 
|     <if test="userId != null"> | 
|       AND `a`.`USER_ID` = #{userId} | 
|     </if> | 
|     <if test="status != null"> | 
|       AND `a`.`STATUS` = #{status} | 
|     </if> | 
|     <if test="publishDate != null"> | 
|       AND `a`.`PUBLISH_DATE` = #{publishDate} | 
|     </if> | 
|       <if test="procedureIds != null and procedureIds.size()>0"> | 
|         AND a.`PROCEDURE_ID` in <foreach collection="procedureIds" item="item" separator="," open="(" close=")">#{item}</foreach> | 
|       </if> | 
|       <if test="departIds != null and departIds.size()>0"> | 
|         AND exists (select d.id from company_user d where   d.user_id=a.user_id and d.department_id | 
|         in <foreach collection="departIds" item="item" separator="," open="(" close=")">#{item}</foreach>) | 
|       </if> | 
|   </where> | 
| limit 1 | 
|   </select> | 
|   <select id="selectCountToday" parameterType="doumeemes.dao.ext.dto.QueryPlansExtDTO" resultType="java.lang.Integer"> | 
|   SELECT count(1) | 
|     from plans a | 
|     <where> | 
|     <if test="id != null"> | 
|       AND `a`.`ID` = #{id} | 
|     </if> | 
|     <if test="deleted != null"> | 
|       AND `a`.`DELETED` = #{deleted} | 
|     </if> | 
|     <if test="createUser != null"> | 
|       AND `a`.`CREATE_USER` = #{createUser} | 
|     </if> | 
|     <if test="createTime != null"> | 
|       AND `a`.`CREATE_TIME` = #{createTime} | 
|     </if> | 
|     <if test="updateUser != null"> | 
|       AND `a`.`UPDATE_USER` = #{updateUser} | 
|     </if> | 
|     <if test="paused != null"> | 
|       AND `a`.`PAUSED` = #{paused} | 
|     </if> | 
|       <if test="type != null"> | 
|         AND `a`.`TYPE` = #{type} | 
|       </if> | 
|     <if test="updateTime != null"> | 
|       AND `a`.`UPDATE_TIME` = #{updateTime} | 
|     </if> | 
|     <if test="remark != null and remark != ''"> | 
|       AND `a`.`REMARK` = #{remark} | 
|     </if> | 
|     <if test="rootDepartId != null"> | 
|       AND `a`.`ROOT_DEPART_ID` = #{rootDepartId} | 
|     </if> | 
|     <if test="departId != null"> | 
|       AND `a`.`DEPART_ID` = #{departId} | 
|     </if> | 
|     <if test="origin != null"> | 
|       AND `a`.`ORIGIN` = #{origin} | 
|     </if> | 
|     <if test="planDate != null"> | 
|       AND `a`.`PLAN_DATE` = #{planDate} | 
|     </if> | 
|     <if test="materialId != null"> | 
|       AND `a`.`MATERIAL_ID` = #{materialId} | 
|     </if> | 
|     <if test="procedureId != null"> | 
|       AND `a`.`PROCEDURE_ID` = #{procedureId} | 
|     </if> | 
|     <if test="factoryId != null"> | 
|       AND `a`.`FACTORY_ID` = #{factoryId} | 
|     </if> | 
|     <if test="unitId != null"> | 
|       AND `a`.`UNIT_ID` = #{unitId} | 
|     </if> | 
|     <if test="num != null"> | 
|       AND `a`.`NUM` = #{num} | 
|     </if> | 
|     <if test="batch != null and batch != ''"> | 
|       AND `a`.`BATCH` = #{batch} | 
|     </if> | 
|     <if test="urgent != null"> | 
|       AND `a`.`URGENT` = #{urgent} | 
|     </if> | 
|     <if test="importId != null"> | 
|       AND `a`.`IMPORT_ID` = #{importId} | 
|     </if> | 
|     <if test="userId != null"> | 
|       AND `a`.`USER_ID` = #{userId} | 
|     </if> | 
|     <if test="status != null"> | 
|       AND `a`.`STATUS` = #{status} | 
|     </if> | 
|     <if test="publishDate != null"> | 
|       AND `a`.`PUBLISH_DATE` = #{publishDate} | 
|     </if> | 
|     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 | 
|     GROUP BY a.PROCEDURE_ID | 
|     order by b.SORTNUM--> | 
|   | 
|     select t.PROCEDURE_ID  as procedureId,count(t.id) as planCount, t.SORTNUM,t.procedureName,sum(t.num) as num ,sum(t.qualifiedNum) as qualifiedNum,sum(t.unqualifiedNum) as unqualifiedNum | 
|     from (select    a.id,a.PROCEDURE_ID  , | 
|     b.name as procedureName, | 
|     a.num as num, | 
|     b.SORTNUM, | 
|     (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 b.DELETED=0 | 
|     and a.ROOT_DEPART_ID=#{rootDepartId} and a.DEPART_ID=#{departId} | 
|     ) t | 
|     GROUP BY t.PROCEDURE_ID | 
|     order by t.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,m.name as materialName | 
|     ,(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 to_days(b.create_time)=to_days(now())) )) | 
|     and a.deleted=0 and a.ROOT_DEPART_ID=#{rootDepartId} and a.DEPART_ID=#{departId} and a.PROCEDURE_ID=#{procedureId} | 
|     order by a.CREATE_TIME | 
|   </select> | 
|   <select id="selectList" parameterType="doumeemes.dao.ext.dto.QueryPlansExtDTO" resultMap="PlansExtListVO"> | 
|   SELECT | 
|       `a`.*, | 
|       `dmodel`.`ID` AS DMODEL_ID, | 
|       `dmodel`.`NAME` AS DMODEL_NAME, | 
|       `dmodel`.`REMARK` AS DMODEL_REMARK, | 
|       `dmodel`.`ROOT_ID` AS DMODEL_ROOT_ID, | 
|       `dmodel`.`PARENT_ID` AS DMODEL_PARENT_ID, | 
|       `dmodel`.`COMPANY_ID` AS DMODEL_COMPANY_ID, | 
|       `dmodel`.`TYPE` AS DMODEL_TYPE, | 
|       `dmodel`.`ERP_ID` AS DMODEL_ERP_ID, | 
|       `dmodel`.`STATUS` AS DMODEL_STATUS, | 
|       `dmodel`.`VALID_TIME` AS DMODEL_VALID_TIME, | 
|       `dmodel`.`INVALID_TIME` AS DMODEL_INVALID_TIME, | 
|       `mmodel`.`ID` AS MMODEL_ID, | 
|       `mmodel`.`REMARK` AS MMODEL_REMARK, | 
|       `mmodel`.`ROOT_DEPART_ID` AS MMODEL_ROOT_DEPART_ID, | 
|       `mmodel`.`NAME` AS MMODEL_NAME, | 
|       `mmodel`.`CODE` AS MMODEL_CODE, | 
|       `mmodel`.`ATTR` AS MMODEL_ATTR, | 
|       `mmodel`.`UNION_NAME` AS MMODEL_UNION_NAME, | 
|       `mmodel`.`UNIT_ID` AS MMODEL_UNIT_ID, | 
|       `mmodel`.`CATE_UNION_ID` AS MMODEL_CATE_UNION_ID, | 
|       `mmodel`.`FORMATION` AS MMODEL_FORMATION, | 
|       `mmodel`.`QRCODE_ID` AS MMODEL_QRCODE_ID, | 
|       `mmodel`.`STATUS` AS MMODEL_STATUS, | 
|       `mmodel`.`VALID_TIME` AS MMODEL_VALID_TIME, | 
|       `mmodel`.`INVALID_TIME` AS MMODEL_INVALID_TIME, | 
|       `mmodel`.`CHECK_WAY` AS MMODEL_CHECK_WAY, | 
|       `mmodel`.`QUALITY_REQUIRE` AS MMODEL_QUALITY_REQUIRE, | 
|       `mmodel`.`CHECK_NOTE` AS MMODEL_CHECK_NOTE, | 
|       `pmodel`.`ID` AS PMODEL_ID, | 
|       `pmodel`.`DELETED` AS PMODEL_DELETED, | 
|       `pmodel`.`CREATE_USER` AS PMODEL_CREATE_USER, | 
|       `pmodel`.`CREATE_TIME` AS PMODEL_CREATE_TIME, | 
|       `pmodel`.`UPDATE_USER` AS PMODEL_UPDATE_USER, | 
|       `pmodel`.`UPDATE_TIME` AS PMODEL_UPDATE_TIME, | 
|       `pmodel`.`REMARK` AS PMODEL_REMARK, | 
|       `pmodel`.`ROOT_DEPART_ID` AS PMODEL_ROOT_DEPART_ID, | 
|       `pmodel`.`DEPART_ID` AS PMODEL_DEPART_ID, | 
|       `pmodel`.`CODE` AS PMODEL_CODE, | 
|       `pmodel`.`NAME` AS PMODEL_NAME, | 
|       `pmodel`.`SORTNUM` AS PMODEL_SORTNUM, | 
|       `pmodel`.`ORG_ID` AS PMODEL_ORG_ID, | 
|       `pmodel`.`USER_ID` AS PMODEL_USER_ID, | 
|       `pmodel`.`PICKING_WAREHOUSE_ID` AS PMODEL_PICKING_WAREHOUSE_ID, | 
|       `pmodel`.`PRODUCE_WAREHOUSE_ID` AS PMODEL_PRODUCE_WAREHOUSE_ID, | 
|       `pmodel`.`LEVEL` AS PMODEL_LEVEL, | 
|       `fmodel`.`ID` AS FMODEL_ID, | 
|       `fmodel`.`NAME` AS FMODEL_NAME, | 
|       `fmodel`.`REMARK` AS FMODEL_REMARK, | 
|       `fmodel`.`ROOT_ID` AS FMODEL_ROOT_ID, | 
|       `fmodel`.`PARENT_ID` AS FMODEL_PARENT_ID, | 
|       `fmodel`.`COMPANY_ID` AS FMODEL_COMPANY_ID, | 
|       `fmodel`.`TYPE` AS FMODEL_TYPE, | 
|       `fmodel`.`ERP_ID` AS FMODEL_ERP_ID, | 
|       `fmodel`.`STATUS` AS FMODEL_STATUS, | 
|       `fmodel`.`VALID_TIME` AS FMODEL_VALID_TIME, | 
|       `fmodel`.`INVALID_TIME` AS FMODEL_INVALID_TIME, | 
|       `umodel`.`ID` AS UMODEL_ID, | 
|       `umodel`.`REMARK` AS UMODEL_REMARK, | 
|       `umodel`.`NAME` AS UMODEL_NAME, | 
|       `umodel`.`TYPE` AS UMODEL_TYPE, | 
|       `umodel`.`STATUS` AS UMODEL_STATUS, | 
|       `usermodel`.`ID` AS USERMODEL_ID, | 
|       `usermodel`.`AVATAR` AS USERMODEL_AVATAR, | 
|       `usermodel`.`MOBILE` AS USERMODEL_MOBILE, | 
|       `usermodel`.`EMAIL` AS USERMODEL_EMAIL, | 
|       `usermodel`.`SEX` AS USERMODEL_SEX, | 
|       `usermodel`.`BIRTHDAY` AS USERMODEL_BIRTHDAY, | 
|       `usermodel`.`EMP_NO` AS USERMODEL_EMP_NO, | 
|       `usermodel`.`REALNAME` AS USERMODEL_REALNAME, | 
|       `usermodel`.`USERNAME` AS USERMODEL_USERNAME, | 
|       `usermodel`.`SYSTEMID` AS USERMODEL_SYSTEMID, | 
|       `usermodel`.`INVALID_TIME` AS USERMODEL_INVALID_TIME, | 
|       `usermodel`.`TYPE` AS USERMODEL_TYPE | 
|     , 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.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 | 
|     LEFT JOIN `material` `mmodel` ON mdmodel.MATERIAL_ID=mmodel.ID | 
|     LEFT JOIN `procedures` `pmodel` ON a.PROCEDURE_ID=pmodel.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 `WORK_PLANS` w on w.id = a.WORK_PLANS_ID | 
|     <where> | 
|       <if test="id != null"> | 
|         AND `a`.`ID` = #{id} | 
|       </if> | 
|       <if test="deleted != null"> | 
|         AND `a`.`DELETED` = #{deleted} | 
|       </if> | 
|   <!--    <if test="createUser != null"> | 
|         AND `a`.`CREATE_USER` = #{createUser} | 
|       </if>--> | 
|       <if test="createTime != null"> | 
|         AND `a`.`CREATE_TIME` = #{createTime} | 
|       </if> | 
|       <if test="updateUser != null"> | 
|         AND `a`.`UPDATE_USER` = #{updateUser} | 
|       </if> | 
|   | 
|       <if test="workPlanId != null"> | 
|         AND `a`.`WORK_PLANS_ID` = #{workPlanId} | 
|       </if> | 
|       <if test="paused != null"> | 
|         AND `a`.`PAUSED` = #{paused} | 
|       </if> | 
|       <if test="type != null"> | 
|         AND `a`.`TYPE` = #{type} | 
|       </if> | 
|       <if test="updateTime != null"> | 
|         AND `a`.`UPDATE_TIME` = #{updateTime} | 
|       </if> | 
|       <if test="remark != null and remark != ''"> | 
|         AND `a`.`REMARK` = #{remark} | 
|       </if> | 
|       <if test="rootDepartId != null"> | 
|         AND `a`.`ROOT_DEPART_ID` = #{rootDepartId} | 
|       </if> | 
|       <if test="departId != null"> | 
|         AND `a`.`DEPART_ID` = #{departId} | 
|       </if> | 
|       <if test="origin != null"> | 
|         AND `a`.`ORIGIN` = #{origin} | 
|       </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} | 
|       </if> | 
|       <if test="procedureId != null"> | 
|         AND `a`.`PROCEDURE_ID` = #{procedureId} | 
|       </if> | 
|       <if test="factoryId != null"> | 
|         AND `a`.`FACTORY_ID` = #{factoryId} | 
|       </if> | 
|       <if test="unitId != null"> | 
|         AND `a`.`UNIT_ID` = #{unitId} | 
|       </if> | 
|       <if test="num != null"> | 
|         AND `a`.`NUM` = #{num} | 
|       </if> | 
|       <if test="batch != null and batch != ''"> | 
|         AND `a`.`BATCH` = #{batch} | 
|       </if> | 
|       <if test="urgent != null"> | 
|         AND `a`.`URGENT` = #{urgent} | 
|       </if> | 
|       <if test="importId != null"> | 
|         AND `a`.`IMPORT_ID` = #{importId} | 
|       </if> | 
|       <if test="userId != null"> | 
|         AND `a`.`USER_ID` = #{userId} | 
|       </if> | 
|       <if test="status != null"> | 
|         AND `a`.`STATUS` = #{status} | 
|       </if> | 
|       <if test="statusList != null and statusList.size()>0"> | 
|         AND `a`.`STATUS` in <foreach collection="statusList" open="(" close=")" item="item" separator=",">#{item}</foreach> | 
|       </if> | 
|       <if test="publishDate != null"> | 
|         AND `a`.`PUBLISH_DATE` = #{publishDate} | 
|       </if> | 
|       <if test="workPlanCode != null and workPlanCode != ''"> | 
|         AND `w`.`PLAN_CODE` like concat('%',#{workPlanCode},'%') | 
|       </if> | 
|       <if test="dmodelId != null"> | 
|         AND `dmodel`.`ID` = #{dmodelId} | 
|       </if> | 
|       <if test="dmodelDeleted != null"> | 
|         AND `dmodel`.`DELETED` = #{dmodelDeleted} | 
|       </if> | 
|       <if test="dmodelCreateUser != null"> | 
|         AND `dmodel`.`CREATE_USER` = #{dmodelCreateUser} | 
|       </if> | 
|       <if test="dmodelCreateTime != null"> | 
|         AND `dmodel`.`CREATE_TIME` = #{dmodelCreateTime} | 
|       </if> | 
|       <if test="dmodelUpdateUser != null"> | 
|         AND `dmodel`.`UPDATE_USER` = #{dmodelUpdateUser} | 
|       </if> | 
|       <if test="dmodelUpdateTime != null"> | 
|         AND `dmodel`.`UPDATE_TIME` = #{dmodelUpdateTime} | 
|       </if> | 
|       <if test="dmodelName != null and dmodelName != ''"> | 
|         AND `dmodel`.`NAME` = #{dmodelName} | 
|       </if> | 
|       <if test="dmodelRemark != null and dmodelRemark != ''"> | 
|         AND `dmodel`.`REMARK` = #{dmodelRemark} | 
|       </if> | 
|       <if test="dmodelRootId != null"> | 
|         AND `dmodel`.`ROOT_ID` = #{dmodelRootId} | 
|       </if> | 
|       <if test="dmodelParentId != null"> | 
|         AND `dmodel`.`PARENT_ID` = #{dmodelParentId} | 
|       </if> | 
|       <if test="dmodelCompanyId != null"> | 
|         AND `dmodel`.`COMPANY_ID` = #{dmodelCompanyId} | 
|       </if> | 
|       <if test="dmodelType != null"> | 
|         AND `dmodel`.`TYPE` = #{dmodelType} | 
|       </if> | 
|       <if test="dmodelErpId != null and dmodelErpId != ''"> | 
|         AND `dmodel`.`ERP_ID` = #{dmodelErpId} | 
|       </if> | 
|       <if test="dmodelStatus != null"> | 
|         AND `dmodel`.`STATUS` = #{dmodelStatus} | 
|       </if> | 
|       <if test="dmodelValidTime != null"> | 
|         AND `dmodel`.`VALID_TIME` = #{dmodelValidTime} | 
|       </if> | 
|       <if test="dmodelInvalidTime != null"> | 
|         AND `dmodel`.`INVALID_TIME` = #{dmodelInvalidTime} | 
|       </if> | 
|       <if test="mmodelId != null"> | 
|         AND `mmodel`.`ID` = #{mmodelId} | 
|       </if> | 
|       <if test="mmodelDeleted != null"> | 
|         AND `mmodel`.`DELETED` = #{mmodelDeleted} | 
|       </if> | 
|       <if test="mmodelCreateUser != null"> | 
|         AND `mmodel`.`CREATE_USER` = #{mmodelCreateUser} | 
|       </if> | 
|       <if test="mmodelCreateTime != null"> | 
|         AND `mmodel`.`CREATE_TIME` = #{mmodelCreateTime} | 
|       </if> | 
|       <if test="mmodelUpdateUser != null"> | 
|         AND `mmodel`.`UPDATE_USER` = #{mmodelUpdateUser} | 
|       </if> | 
|       <if test="mmodelUpdateTime != null"> | 
|         AND `mmodel`.`UPDATE_TIME` = #{mmodelUpdateTime} | 
|       </if> | 
|       <if test="mmodelRemark != null and mmodelRemark != ''"> | 
|         AND `mmodel`.`REMARK` = #{mmodelRemark} | 
|       </if> | 
|       <if test="mmodelRootDepartId != null"> | 
|         AND `mmodel`.`ROOT_DEPART_ID` = #{mmodelRootDepartId} | 
|       </if> | 
|       <if test="mmodelName != null and mmodelName != ''"> | 
|         AND `mmodel`.`NAME` = #{mmodelName} | 
|       </if> | 
|       <if test="mmodelCode != null and mmodelCode != ''"> | 
|         AND `mmodel`.`CODE` = #{mmodelCode} | 
|       </if> | 
|       <if test="mmodelAttr != null and mmodelAttr != ''"> | 
|         AND `mmodel`.`ATTR` = #{mmodelAttr} | 
|       </if> | 
|       <if test="mmodelUnionName != null and mmodelUnionName != ''"> | 
|         AND `mmodel`.`UNION_NAME` = #{mmodelUnionName} | 
|       </if> | 
|       <if test="mmodelUnitId != null"> | 
|         AND `mmodel`.`UNIT_ID` = #{mmodelUnitId} | 
|       </if> | 
|       <if test="mmodelCateUnionId != null"> | 
|         AND `mmodel`.`CATE_UNION_ID` = #{mmodelCateUnionId} | 
|       </if> | 
|       <if test="mmodelFormation != null"> | 
|         AND `mmodel`.`FORMATION` = #{mmodelFormation} | 
|       </if> | 
|       <if test="mmodelQrcodeId != null and mmodelQrcodeId != ''"> | 
|         AND `mmodel`.`QRCODE_ID` = #{mmodelQrcodeId} | 
|       </if> | 
|       <if test="mmodelStatus != null"> | 
|         AND `mmodel`.`STATUS` = #{mmodelStatus} | 
|       </if> | 
|       <if test="mmodelValidTime != null"> | 
|         AND `mmodel`.`VALID_TIME` = #{mmodelValidTime} | 
|       </if> | 
|       <if test="mmodelInvalidTime != null"> | 
|         AND `mmodel`.`INVALID_TIME` = #{mmodelInvalidTime} | 
|       </if> | 
|       <if test="mmodelCheckWay != null"> | 
|         AND `mmodel`.`CHECK_WAY` = #{mmodelCheckWay} | 
|       </if> | 
|       <if test="mmodelQualityRequire != null and mmodelQualityRequire != ''"> | 
|         AND `mmodel`.`QUALITY_REQUIRE` = #{mmodelQualityRequire} | 
|       </if> | 
|       <if test="mmodelCheckNote != null and mmodelCheckNote != ''"> | 
|         AND `mmodel`.`CHECK_NOTE` = #{mmodelCheckNote} | 
|       </if> | 
|       <if test="pmodelId != null"> | 
|         AND `pmodel`.`ID` = #{pmodelId} | 
|       </if> | 
|       <if test="pmodelDeleted != null"> | 
|         AND `pmodel`.`DELETED` = #{pmodelDeleted} | 
|       </if> | 
|       <if test="pmodelCreateUser != null"> | 
|         AND `pmodel`.`CREATE_USER` = #{pmodelCreateUser} | 
|       </if> | 
|       <if test="pmodelCreateTime != null"> | 
|         AND `pmodel`.`CREATE_TIME` = #{pmodelCreateTime} | 
|       </if> | 
|       <if test="pmodelUpdateUser != null"> | 
|         AND `pmodel`.`UPDATE_USER` = #{pmodelUpdateUser} | 
|       </if> | 
|       <if test="pmodelUpdateTime != null"> | 
|         AND `pmodel`.`UPDATE_TIME` = #{pmodelUpdateTime} | 
|       </if> | 
|       <if test="pmodelRemark != null and pmodelRemark != ''"> | 
|         AND `pmodel`.`REMARK` = #{pmodelRemark} | 
|       </if> | 
|       <if test="pmodelRootDepartId != null"> | 
|         AND `pmodel`.`ROOT_DEPART_ID` = #{pmodelRootDepartId} | 
|       </if> | 
|       <if test="pmodelDepartId != null"> | 
|         AND `pmodel`.`DEPART_ID` = #{pmodelDepartId} | 
|       </if> | 
|       <if test="pmodelCode != null and pmodelCode != ''"> | 
|         AND `pmodel`.`CODE` = #{pmodelCode} | 
|       </if> | 
|       <if test="pmodelName != null and pmodelName != ''"> | 
|         AND `pmodel`.`NAME` = #{pmodelName} | 
|       </if> | 
|       <if test="pmodelSortnum != null"> | 
|         AND `pmodel`.`SORTNUM` = #{pmodelSortnum} | 
|       </if> | 
|       <if test="pmodelOrgId != null"> | 
|         AND `pmodel`.`ORG_ID` = #{pmodelOrgId} | 
|       </if> | 
|       <if test="pmodelUserId != null"> | 
|         AND `pmodel`.`USER_ID` = #{pmodelUserId} | 
|       </if> | 
|       <if test="pmodelPickingWarehouseId != null"> | 
|         AND `pmodel`.`PICKING_WAREHOUSE_ID` = #{pmodelPickingWarehouseId} | 
|       </if> | 
|       <if test="pmodelProduceWarehouseId != null"> | 
|         AND `pmodel`.`PRODUCE_WAREHOUSE_ID` = #{pmodelProduceWarehouseId} | 
|       </if> | 
|       <if test="pmodelLevel != null"> | 
|         AND `pmodel`.`LEVEL` = #{pmodelLevel} | 
|       </if> | 
|       <if test="fmodelId != null"> | 
|         AND `fmodel`.`ID` = #{fmodelId} | 
|       </if> | 
|       <if test="fmodelDeleted != null"> | 
|         AND `fmodel`.`DELETED` = #{fmodelDeleted} | 
|       </if> | 
|       <if test="fmodelCreateUser != null"> | 
|         AND `fmodel`.`CREATE_USER` = #{fmodelCreateUser} | 
|       </if> | 
|       <if test="fmodelCreateTime != null"> | 
|         AND `fmodel`.`CREATE_TIME` = #{fmodelCreateTime} | 
|       </if> | 
|       <if test="fmodelUpdateUser != null"> | 
|         AND `fmodel`.`UPDATE_USER` = #{fmodelUpdateUser} | 
|       </if> | 
|       <if test="fmodelUpdateTime != null"> | 
|         AND `fmodel`.`UPDATE_TIME` = #{fmodelUpdateTime} | 
|       </if> | 
|       <if test="fmodelName != null and fmodelName != ''"> | 
|         AND `fmodel`.`NAME` = #{fmodelName} | 
|       </if> | 
|       <if test="fmodelRemark != null and fmodelRemark != ''"> | 
|         AND `fmodel`.`REMARK` = #{fmodelRemark} | 
|       </if> | 
|       <if test="fmodelRootId != null"> | 
|         AND `fmodel`.`ROOT_ID` = #{fmodelRootId} | 
|       </if> | 
|       <if test="fmodelParentId != null"> | 
|         AND `fmodel`.`PARENT_ID` = #{fmodelParentId} | 
|       </if> | 
|       <if test="fmodelCompanyId != null"> | 
|         AND `fmodel`.`COMPANY_ID` = #{fmodelCompanyId} | 
|       </if> | 
|       <if test="fmodelType != null"> | 
|         AND `fmodel`.`TYPE` = #{fmodelType} | 
|       </if> | 
|       <if test="fmodelErpId != null and fmodelErpId != ''"> | 
|         AND `fmodel`.`ERP_ID` = #{fmodelErpId} | 
|       </if> | 
|       <if test="fmodelStatus != null"> | 
|         AND `fmodel`.`STATUS` = #{fmodelStatus} | 
|       </if> | 
|       <if test="fmodelValidTime != null"> | 
|         AND `fmodel`.`VALID_TIME` = #{fmodelValidTime} | 
|       </if> | 
|       <if test="fmodelInvalidTime != null"> | 
|         AND `fmodel`.`INVALID_TIME` = #{fmodelInvalidTime} | 
|       </if> | 
|       <if test="umodelId != null"> | 
|         AND `umodel`.`ID` = #{umodelId} | 
|       </if> | 
|       <if test="umodelDeleted != null"> | 
|         AND `umodel`.`DELETED` = #{umodelDeleted} | 
|       </if> | 
|       <if test="umodelCreateUser != null"> | 
|         AND `umodel`.`CREATE_USER` = #{umodelCreateUser} | 
|       </if> | 
|       <if test="umodelCreateTime != null"> | 
|         AND `umodel`.`CREATE_TIME` = #{umodelCreateTime} | 
|       </if> | 
|       <if test="umodelUpdateUser != null"> | 
|         AND `umodel`.`UPDATE_USER` = #{umodelUpdateUser} | 
|       </if> | 
|       <if test="umodelUpdateTime != null"> | 
|         AND `umodel`.`UPDATE_TIME` = #{umodelUpdateTime} | 
|       </if> | 
|       <if test="umodelRemark != null and umodelRemark != ''"> | 
|         AND `umodel`.`REMARK` = #{umodelRemark} | 
|       </if> | 
|       <if test="umodelRootDepartId != null"> | 
|         AND `umodel`.`ROOT_DEPART_ID` = #{umodelRootDepartId} | 
|       </if> | 
|       <if test="umodelName != null and umodelName != ''"> | 
|         AND `umodel`.`NAME` = #{umodelName} | 
|       </if> | 
|       <if test="umodelType != null"> | 
|         AND `umodel`.`TYPE` = #{umodelType} | 
|       </if> | 
|       <if test="umodelStatus != null"> | 
|         AND `umodel`.`STATUS` = #{umodelStatus} | 
|       </if> | 
|       <if test="usermodelId != null"> | 
|         AND `usermodel`.`ID` = #{usermodelId} | 
|       </if> | 
|       <if test="usermodelDeleted != null"> | 
|         AND `usermodel`.`DELETED` = #{usermodelDeleted} | 
|       </if> | 
|       <if test="usermodelCreateUser != null"> | 
|         AND `usermodel`.`CREATE_USER` = #{usermodelCreateUser} | 
|       </if> | 
|       <if test="usermodelCreateTime != null"> | 
|         AND `usermodel`.`CREATE_TIME` = #{usermodelCreateTime} | 
|       </if> | 
|       <if test="usermodelUpdateUser != null"> | 
|         AND `usermodel`.`UPDATE_USER` = #{usermodelUpdateUser} | 
|       </if> | 
|       <if test="usermodelUpdateTime != null"> | 
|         AND `usermodel`.`UPDATE_TIME` = #{usermodelUpdateTime} | 
|       </if> | 
|       <if test="usermodelFixed != null"> | 
|         AND `usermodel`.`FIXED` = #{usermodelFixed} | 
|       </if> | 
|       <if test="usermodelPassword != null and usermodelPassword != ''"> | 
|         AND `usermodel`.`PASSWORD` = #{usermodelPassword} | 
|       </if> | 
|       <if test="usermodelSalt != null and usermodelSalt != ''"> | 
|         AND `usermodel`.`SALT` = #{usermodelSalt} | 
|       </if> | 
|       <if test="usermodelAvatar != null and usermodelAvatar != ''"> | 
|         AND `usermodel`.`AVATAR` = #{usermodelAvatar} | 
|       </if> | 
|       <if test="usermodelMobile != null and usermodelMobile != ''"> | 
|         AND `usermodel`.`MOBILE` = #{usermodelMobile} | 
|       </if> | 
|       <if test="usermodelEmail != null and usermodelEmail != ''"> | 
|         AND `usermodel`.`EMAIL` = #{usermodelEmail} | 
|       </if> | 
|       <if test="usermodelSex != null and usermodelSex != ''"> | 
|         AND `usermodel`.`SEX` = #{usermodelSex} | 
|       </if> | 
|       <if test="usermodelBirthday != null"> | 
|         AND `usermodel`.`BIRTHDAY` = #{usermodelBirthday} | 
|       </if> | 
|       <if test="usermodelEmpNo != null and usermodelEmpNo != ''"> | 
|         AND `usermodel`.`EMP_NO` = #{usermodelEmpNo} | 
|       </if> | 
|       <if test="usermodelRealname != null and usermodelRealname != ''"> | 
|         AND `usermodel`.`REALNAME` = #{usermodelRealname} | 
|       </if> | 
|       <if test="usermodelUsername != null and usermodelUsername != ''"> | 
|         AND `usermodel`.`USERNAME` = #{usermodelUsername} | 
|       </if> | 
|       <if test="usermodelSystemid != null and usermodelSystemid != ''"> | 
|         AND `usermodel`.`SYSTEMID` = #{usermodelSystemid} | 
|       </if> | 
|       <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="mixParam != null and 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} | 
|       </if> | 
|       <if test="usermodelType != null"> | 
|         AND `usermodel`.`TYPE` = #{usermodelType} | 
|       </if> | 
|       <choose> | 
|         <when test="procedureIds != null and procedureIds.size()>0 and (departIds == null or departIds.size()==0)"> | 
|           and (a.`PROCEDURE_ID` in | 
|           <foreach collection="procedureIds" item="item" separator="," open="(" close=")">#{item}</foreach> | 
|           <if test="createUser != null"> | 
|             or `a`.`CREATE_USER` = #{createUser} OR a.user_id = #{createUser} | 
|           </if> | 
|               ) | 
|         </when> | 
|         <when test="departIds != null and departIds.size()>0"> | 
|           AND ( exists (select d.id from company_user d where (d.user_id=a.CREATE_USER OR d.user_id=a.user_id)  and d.department_id | 
|           in <foreach collection="departIds" item="item" separator="," open="(" close=")">#{item}</foreach>) | 
|           <if test="createUser != null"> | 
|             or `a`.`CREATE_USER` = #{createUser}  OR a.user_id = #{createUser} | 
|           </if> | 
|           <if test="procedureIds != null and procedureIds.size()>0"> | 
|             or a.`PROCEDURE_ID` in | 
|             <foreach collection="procedureIds" item="item" separator="," open="(" close=")">#{item}</foreach> | 
|           </if> | 
|           ) | 
|         </when> | 
|         <otherwise> | 
|           <if test="createUser != null"> | 
|             AND    (`a`.`CREATE_USER` = #{createUser}  OR a.user_id = #{createUser}) | 
|           </if> | 
|         </otherwise> | 
|       </choose> | 
|   <!--    <if test="procedureIds != null and procedureIds.size()>0 and (departIds == null or departIds.size()==0)"> | 
|         and a.`PROCEDURE_ID` in | 
|         <foreach collection="procedureIds" item="item" separator="," open="(" close=")">#{item}</foreach> | 
|       </if>--> | 
|       <if test="procedureIdList != null and procedureIdList.size()>0"> | 
|         AND a.`PROCEDURE_ID` in <foreach collection="procedureIdList" item="item" separator="," open="(" close=")">#{item}</foreach> | 
|       </if> | 
|   | 
|     </where> | 
|      order by a.PLAN_DATE desc,a.URGENT asc,mmodel.code asc | 
|   </select> | 
|   <select id="selectCount" parameterType="doumeemes.dao.ext.dto.QueryPlansExtDTO" resultType="java.lang.Integer"> | 
|     SELECT count(1) | 
|     FROM `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 `procedures` `pmodel` ON a.PROCEDURE_ID=pmodel.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> | 
|       <if test="id != null"> | 
|         AND `a`.`ID` = #{id} | 
|       </if> | 
|       <if test="deleted != null"> | 
|         AND `a`.`DELETED` = #{deleted} | 
|       </if> | 
|       <if test="createUser != null"> | 
|         AND `a`.`CREATE_USER` = #{createUser} | 
|       </if> | 
|       <if test="createTime != null"> | 
|         AND `a`.`CREATE_TIME` = #{createTime} | 
|       </if> | 
|       <if test="updateUser != null"> | 
|         AND `a`.`UPDATE_USER` = #{updateUser} | 
|       </if> | 
|       <if test="paused != null"> | 
|         AND `a`.`PAUSED` = #{paused} | 
|       </if> | 
|       <if test="type != null"> | 
|         AND `a`.`TYPE` = #{type} | 
|       </if> | 
|       <if test="updateTime != null"> | 
|         AND `a`.`UPDATE_TIME` = #{updateTime} | 
|       </if> | 
|       <if test="remark != null and remark != ''"> | 
|         AND `a`.`REMARK` = #{remark} | 
|       </if> | 
|       <if test="rootDepartId != null"> | 
|         AND `a`.`ROOT_DEPART_ID` = #{rootDepartId} | 
|       </if> | 
|       <if test="departId != null"> | 
|         AND `a`.`DEPART_ID` = #{departId} | 
|       </if> | 
|       <if test="origin != null"> | 
|         AND `a`.`ORIGIN` = #{origin} | 
|       </if> | 
|       <if test="planDate != null"> | 
|         AND `a`.`PLAN_DATE` = #{planDate} | 
|       </if> | 
|       <if test="materialId != null"> | 
|         AND `a`.`MATERIAL_ID` = #{materialId} | 
|       </if> | 
|       <if test="procedureId != null"> | 
|         AND `a`.`PROCEDURE_ID` = #{procedureId} | 
|       </if> | 
|       <if test="factoryId != null"> | 
|         AND `a`.`FACTORY_ID` = #{factoryId} | 
|       </if> | 
|       <if test="unitId != null"> | 
|         AND `a`.`UNIT_ID` = #{unitId} | 
|       </if> | 
|       <if test="num != null"> | 
|         AND `a`.`NUM` = #{num} | 
|       </if> | 
|       <if test="batch != null and batch != ''"> | 
|         AND `a`.`BATCH` = #{batch} | 
|       </if> | 
|       <if test="urgent != null"> | 
|         AND `a`.`URGENT` = #{urgent} | 
|       </if> | 
|       <if test="importId != null"> | 
|         AND `a`.`IMPORT_ID` = #{importId} | 
|       </if> | 
|       <if test="userId != null"> | 
|         AND `a`.`USER_ID` = #{userId} | 
|       </if> | 
|       <if test="status != null"> | 
|         AND `a`.`STATUS` = #{status} | 
|       </if> | 
|       <if test="statusList != null and statusList.size()>0"> | 
|         AND `a`.`STATUS` in <foreach collection="statusList" open="(" close=")" item="item" separator=",">#{item}</foreach> | 
|       </if> | 
|       <if test="publishDate != null"> | 
|         AND `a`.`PUBLISH_DATE` = #{publishDate} | 
|       </if> | 
|       <if test="dmodelId != null"> | 
|         AND `dmodel`.`ID` = #{dmodelId} | 
|       </if> | 
|       <if test="dmodelDeleted != null"> | 
|         AND `dmodel`.`DELETED` = #{dmodelDeleted} | 
|       </if> | 
|       <if test="dmodelCreateUser != null"> | 
|         AND `dmodel`.`CREATE_USER` = #{dmodelCreateUser} | 
|       </if> | 
|       <if test="dmodelCreateTime != null"> | 
|         AND `dmodel`.`CREATE_TIME` = #{dmodelCreateTime} | 
|       </if> | 
|       <if test="dmodelUpdateUser != null"> | 
|         AND `dmodel`.`UPDATE_USER` = #{dmodelUpdateUser} | 
|       </if> | 
|       <if test="dmodelUpdateTime != null"> | 
|         AND `dmodel`.`UPDATE_TIME` = #{dmodelUpdateTime} | 
|       </if> | 
|       <if test="dmodelName != null and dmodelName != ''"> | 
|         AND `dmodel`.`NAME` = #{dmodelName} | 
|       </if> | 
|       <if test="dmodelRemark != null and dmodelRemark != ''"> | 
|         AND `dmodel`.`REMARK` = #{dmodelRemark} | 
|       </if> | 
|       <if test="dmodelRootId != null"> | 
|         AND `dmodel`.`ROOT_ID` = #{dmodelRootId} | 
|       </if> | 
|       <if test="dmodelParentId != null"> | 
|         AND `dmodel`.`PARENT_ID` = #{dmodelParentId} | 
|       </if> | 
|       <if test="dmodelCompanyId != null"> | 
|         AND `dmodel`.`COMPANY_ID` = #{dmodelCompanyId} | 
|       </if> | 
|       <if test="dmodelType != null"> | 
|         AND `dmodel`.`TYPE` = #{dmodelType} | 
|       </if> | 
|       <if test="dmodelErpId != null and dmodelErpId != ''"> | 
|         AND `dmodel`.`ERP_ID` = #{dmodelErpId} | 
|       </if> | 
|       <if test="dmodelStatus != null"> | 
|         AND `dmodel`.`STATUS` = #{dmodelStatus} | 
|       </if> | 
|       <if test="dmodelValidTime != null"> | 
|         AND `dmodel`.`VALID_TIME` = #{dmodelValidTime} | 
|       </if> | 
|       <if test="dmodelInvalidTime != null"> | 
|         AND `dmodel`.`INVALID_TIME` = #{dmodelInvalidTime} | 
|       </if> | 
|       <if test="mmodelId != null"> | 
|         AND `mmodel`.`ID` = #{mmodelId} | 
|       </if> | 
|       <if test="mmodelDeleted != null"> | 
|         AND `mmodel`.`DELETED` = #{mmodelDeleted} | 
|       </if> | 
|       <if test="mmodelCreateUser != null"> | 
|         AND `mmodel`.`CREATE_USER` = #{mmodelCreateUser} | 
|       </if> | 
|       <if test="mmodelCreateTime != null"> | 
|         AND `mmodel`.`CREATE_TIME` = #{mmodelCreateTime} | 
|       </if> | 
|       <if test="mmodelUpdateUser != null"> | 
|         AND `mmodel`.`UPDATE_USER` = #{mmodelUpdateUser} | 
|       </if> | 
|       <if test="mmodelUpdateTime != null"> | 
|         AND `mmodel`.`UPDATE_TIME` = #{mmodelUpdateTime} | 
|       </if> | 
|       <if test="mmodelRemark != null and mmodelRemark != ''"> | 
|         AND `mmodel`.`REMARK` = #{mmodelRemark} | 
|       </if> | 
|       <if test="mmodelRootDepartId != null"> | 
|         AND `mmodel`.`ROOT_DEPART_ID` = #{mmodelRootDepartId} | 
|       </if> | 
|       <if test="mmodelName != null and mmodelName != ''"> | 
|         AND `mmodel`.`NAME` = #{mmodelName} | 
|       </if> | 
|       <if test="mmodelCode != null and mmodelCode != ''"> | 
|         AND `mmodel`.`CODE` = #{mmodelCode} | 
|       </if> | 
|       <if test="mmodelAttr != null and mmodelAttr != ''"> | 
|         AND `mmodel`.`ATTR` = #{mmodelAttr} | 
|       </if> | 
|       <if test="mmodelUnionName != null and mmodelUnionName != ''"> | 
|         AND `mmodel`.`UNION_NAME` = #{mmodelUnionName} | 
|       </if> | 
|       <if test="mmodelUnitId != null"> | 
|         AND `mmodel`.`UNIT_ID` = #{mmodelUnitId} | 
|       </if> | 
|       <if test="mmodelCateUnionId != null"> | 
|         AND `mmodel`.`CATE_UNION_ID` = #{mmodelCateUnionId} | 
|       </if> | 
|       <if test="mmodelFormation != null"> | 
|         AND `mmodel`.`FORMATION` = #{mmodelFormation} | 
|       </if> | 
|       <if test="mmodelQrcodeId != null and mmodelQrcodeId != ''"> | 
|         AND `mmodel`.`QRCODE_ID` = #{mmodelQrcodeId} | 
|       </if> | 
|       <if test="mmodelStatus != null"> | 
|         AND `mmodel`.`STATUS` = #{mmodelStatus} | 
|       </if> | 
|       <if test="mmodelValidTime != null"> | 
|         AND `mmodel`.`VALID_TIME` = #{mmodelValidTime} | 
|       </if> | 
|       <if test="mmodelInvalidTime != null"> | 
|         AND `mmodel`.`INVALID_TIME` = #{mmodelInvalidTime} | 
|       </if> | 
|       <if test="mmodelCheckWay != null"> | 
|         AND `mmodel`.`CHECK_WAY` = #{mmodelCheckWay} | 
|       </if> | 
|       <if test="mmodelQualityRequire != null and mmodelQualityRequire != ''"> | 
|         AND `mmodel`.`QUALITY_REQUIRE` = #{mmodelQualityRequire} | 
|       </if> | 
|       <if test="mmodelCheckNote != null and mmodelCheckNote != ''"> | 
|         AND `mmodel`.`CHECK_NOTE` = #{mmodelCheckNote} | 
|       </if> | 
|       <if test="pmodelId != null"> | 
|         AND `pmodel`.`ID` = #{pmodelId} | 
|       </if> | 
|       <if test="pmodelDeleted != null"> | 
|         AND `pmodel`.`DELETED` = #{pmodelDeleted} | 
|       </if> | 
|       <if test="pmodelCreateUser != null"> | 
|         AND `pmodel`.`CREATE_USER` = #{pmodelCreateUser} | 
|       </if> | 
|       <if test="pmodelCreateTime != null"> | 
|         AND `pmodel`.`CREATE_TIME` = #{pmodelCreateTime} | 
|       </if> | 
|       <if test="pmodelUpdateUser != null"> | 
|         AND `pmodel`.`UPDATE_USER` = #{pmodelUpdateUser} | 
|       </if> | 
|       <if test="pmodelUpdateTime != null"> | 
|         AND `pmodel`.`UPDATE_TIME` = #{pmodelUpdateTime} | 
|       </if> | 
|       <if test="pmodelRemark != null and pmodelRemark != ''"> | 
|         AND `pmodel`.`REMARK` = #{pmodelRemark} | 
|       </if> | 
|       <if test="pmodelRootDepartId != null"> | 
|         AND `pmodel`.`ROOT_DEPART_ID` = #{pmodelRootDepartId} | 
|       </if> | 
|       <if test="pmodelDepartId != null"> | 
|         AND `pmodel`.`DEPART_ID` = #{pmodelDepartId} | 
|       </if> | 
|       <if test="pmodelCode != null and pmodelCode != ''"> | 
|         AND `pmodel`.`CODE` = #{pmodelCode} | 
|       </if> | 
|       <if test="pmodelName != null and pmodelName != ''"> | 
|         AND `pmodel`.`NAME` = #{pmodelName} | 
|       </if> | 
|       <if test="pmodelSortnum != null"> | 
|         AND `pmodel`.`SORTNUM` = #{pmodelSortnum} | 
|       </if> | 
|       <if test="pmodelOrgId != null"> | 
|         AND `pmodel`.`ORG_ID` = #{pmodelOrgId} | 
|       </if> | 
|       <if test="pmodelUserId != null"> | 
|         AND `pmodel`.`USER_ID` = #{pmodelUserId} | 
|       </if> | 
|       <if test="pmodelPickingWarehouseId != null"> | 
|         AND `pmodel`.`PICKING_WAREHOUSE_ID` = #{pmodelPickingWarehouseId} | 
|       </if> | 
|       <if test="pmodelProduceWarehouseId != null"> | 
|         AND `pmodel`.`PRODUCE_WAREHOUSE_ID` = #{pmodelProduceWarehouseId} | 
|       </if> | 
|       <if test="pmodelLevel != null"> | 
|         AND `pmodel`.`LEVEL` = #{pmodelLevel} | 
|       </if> | 
|       <if test="fmodelId != null"> | 
|         AND `fmodel`.`ID` = #{fmodelId} | 
|       </if> | 
|       <if test="fmodelDeleted != null"> | 
|         AND `fmodel`.`DELETED` = #{fmodelDeleted} | 
|       </if> | 
|       <if test="fmodelCreateUser != null"> | 
|         AND `fmodel`.`CREATE_USER` = #{fmodelCreateUser} | 
|       </if> | 
|       <if test="fmodelCreateTime != null"> | 
|         AND `fmodel`.`CREATE_TIME` = #{fmodelCreateTime} | 
|       </if> | 
|       <if test="fmodelUpdateUser != null"> | 
|         AND `fmodel`.`UPDATE_USER` = #{fmodelUpdateUser} | 
|       </if> | 
|       <if test="fmodelUpdateTime != null"> | 
|         AND `fmodel`.`UPDATE_TIME` = #{fmodelUpdateTime} | 
|       </if> | 
|       <if test="fmodelName != null and fmodelName != ''"> | 
|         AND `fmodel`.`NAME` = #{fmodelName} | 
|       </if> | 
|       <if test="fmodelRemark != null and fmodelRemark != ''"> | 
|         AND `fmodel`.`REMARK` = #{fmodelRemark} | 
|       </if> | 
|       <if test="fmodelRootId != null"> | 
|         AND `fmodel`.`ROOT_ID` = #{fmodelRootId} | 
|       </if> | 
|       <if test="fmodelParentId != null"> | 
|         AND `fmodel`.`PARENT_ID` = #{fmodelParentId} | 
|       </if> | 
|       <if test="fmodelCompanyId != null"> | 
|         AND `fmodel`.`COMPANY_ID` = #{fmodelCompanyId} | 
|       </if> | 
|       <if test="fmodelType != null"> | 
|         AND `fmodel`.`TYPE` = #{fmodelType} | 
|       </if> | 
|       <if test="fmodelErpId != null and fmodelErpId != ''"> | 
|         AND `fmodel`.`ERP_ID` = #{fmodelErpId} | 
|       </if> | 
|       <if test="fmodelStatus != null"> | 
|         AND `fmodel`.`STATUS` = #{fmodelStatus} | 
|       </if> | 
|       <if test="fmodelValidTime != null"> | 
|         AND `fmodel`.`VALID_TIME` = #{fmodelValidTime} | 
|       </if> | 
|       <if test="fmodelInvalidTime != null"> | 
|         AND `fmodel`.`INVALID_TIME` = #{fmodelInvalidTime} | 
|       </if> | 
|       <if test="umodelId != null"> | 
|         AND `umodel`.`ID` = #{umodelId} | 
|       </if> | 
|       <if test="umodelDeleted != null"> | 
|         AND `umodel`.`DELETED` = #{umodelDeleted} | 
|       </if> | 
|       <if test="umodelCreateUser != null"> | 
|         AND `umodel`.`CREATE_USER` = #{umodelCreateUser} | 
|       </if> | 
|       <if test="umodelCreateTime != null"> | 
|         AND `umodel`.`CREATE_TIME` = #{umodelCreateTime} | 
|       </if> | 
|       <if test="umodelUpdateUser != null"> | 
|         AND `umodel`.`UPDATE_USER` = #{umodelUpdateUser} | 
|       </if> | 
|       <if test="umodelUpdateTime != null"> | 
|         AND `umodel`.`UPDATE_TIME` = #{umodelUpdateTime} | 
|       </if> | 
|       <if test="umodelRemark != null and umodelRemark != ''"> | 
|         AND `umodel`.`REMARK` = #{umodelRemark} | 
|       </if> | 
|       <if test="umodelRootDepartId != null"> | 
|         AND `umodel`.`ROOT_DEPART_ID` = #{umodelRootDepartId} | 
|       </if> | 
|       <if test="umodelName != null and umodelName != ''"> | 
|         AND `umodel`.`NAME` = #{umodelName} | 
|       </if> | 
|       <if test="umodelType != null"> | 
|         AND `umodel`.`TYPE` = #{umodelType} | 
|       </if> | 
|       <if test="umodelStatus != null"> | 
|         AND `umodel`.`STATUS` = #{umodelStatus} | 
|       </if> | 
|       <if test="usermodelId != null"> | 
|         AND `usermodel`.`ID` = #{usermodelId} | 
|       </if> | 
|       <if test="usermodelDeleted != null"> | 
|         AND `usermodel`.`DELETED` = #{usermodelDeleted} | 
|       </if> | 
|       <if test="usermodelCreateUser != null"> | 
|         AND `usermodel`.`CREATE_USER` = #{usermodelCreateUser} | 
|       </if> | 
|       <if test="usermodelCreateTime != null"> | 
|         AND `usermodel`.`CREATE_TIME` = #{usermodelCreateTime} | 
|       </if> | 
|       <if test="usermodelUpdateUser != null"> | 
|         AND `usermodel`.`UPDATE_USER` = #{usermodelUpdateUser} | 
|       </if> | 
|       <if test="usermodelUpdateTime != null"> | 
|         AND `usermodel`.`UPDATE_TIME` = #{usermodelUpdateTime} | 
|       </if> | 
|       <if test="usermodelFixed != null"> | 
|         AND `usermodel`.`FIXED` = #{usermodelFixed} | 
|       </if> | 
|       <if test="usermodelPassword != null and usermodelPassword != ''"> | 
|         AND `usermodel`.`PASSWORD` = #{usermodelPassword} | 
|       </if> | 
|       <if test="usermodelSalt != null and usermodelSalt != ''"> | 
|         AND `usermodel`.`SALT` = #{usermodelSalt} | 
|       </if> | 
|       <if test="usermodelAvatar != null and usermodelAvatar != ''"> | 
|         AND `usermodel`.`AVATAR` = #{usermodelAvatar} | 
|       </if> | 
|       <if test="usermodelMobile != null and usermodelMobile != ''"> | 
|         AND `usermodel`.`MOBILE` = #{usermodelMobile} | 
|       </if> | 
|       <if test="usermodelEmail != null and usermodelEmail != ''"> | 
|         AND `usermodel`.`EMAIL` = #{usermodelEmail} | 
|       </if> | 
|       <if test="usermodelSex != null and usermodelSex != ''"> | 
|         AND `usermodel`.`SEX` = #{usermodelSex} | 
|       </if> | 
|       <if test="usermodelBirthday != null"> | 
|         AND `usermodel`.`BIRTHDAY` = #{usermodelBirthday} | 
|       </if> | 
|       <if test="usermodelEmpNo != null and usermodelEmpNo != ''"> | 
|         AND `usermodel`.`EMP_NO` = #{usermodelEmpNo} | 
|       </if> | 
|       <if test="usermodelRealname != null and usermodelRealname != ''"> | 
|         AND `usermodel`.`REALNAME` = #{usermodelRealname} | 
|       </if> | 
|       <if test="usermodelUsername != null and usermodelUsername != ''"> | 
|         AND `usermodel`.`USERNAME` = #{usermodelUsername} | 
|       </if> | 
|       <if test="usermodelSystemid != null and usermodelSystemid != ''"> | 
|         AND `usermodel`.`SYSTEMID` = #{usermodelSystemid} | 
|       </if> | 
|       <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="mixParam != null and mixParam!=''"> | 
|         AND  (mmodel.name like concat('%',#{mixParam},'%') or mmodel.code like concat('%',#{mixParam},'%') or pmodel.name like concat('%',#{mixParam},'%')) | 
|       </if> | 
|       <if test="usermodelInvalidTime != null"> | 
|         AND `usermodel`.`INVALID_TIME` = #{usermodelInvalidTime} | 
|       </if> | 
|       <if test="usermodelType != null"> | 
|         AND `usermodel`.`TYPE` = #{usermodelType} | 
|       </if> | 
|   <!--    <if test="procedureIds != null and procedureIds.size()>0"> | 
|         AND a.`PROCEDURE_ID` in <foreach collection="procedureIds" item="item" separator="," open="(" close=")">#{item}</foreach> | 
|       </if> | 
|   | 
|       <if test="departIds != null and departIds.size()>0"> | 
|         AND exists (select d.id from company_user d where   d.user_id=a.user_id and d.department_id | 
|             in <foreach collection="departIds" item="item" separator="," open="(" close=")">#{item}</foreach>) | 
|       </if>--> | 
|       <if test="procedureIdList != null and procedureIdList.size()>0"> | 
|         AND a.`PROCEDURE_ID` in <foreach collection="procedureIdList" item="item" separator="," open="(" close=")">#{item}</foreach> | 
|       </if> | 
|       <choose> | 
|         <when test="procedureIds != null and procedureIds.size()>0 and (departIds == null or departIds.size()==0)"> | 
|           and (a.`PROCEDURE_ID` in | 
|           <foreach collection="procedureIds" item="item" separator="," open="(" close=")">#{item}</foreach> | 
|           <if test="createUser != null"> | 
|             or `a`.`CREATE_USER` = #{createUser} OR a.user_id = #{createUser} | 
|           </if> | 
|           ) | 
|         </when> | 
|         <when test="departIds != null and departIds.size()>0"> | 
|           AND ( exists (select d.id from company_user d where (d.user_id=a.CREATE_USER OR d.user_id=a.user_id)  and d.department_id | 
|           in <foreach collection="departIds" item="item" separator="," open="(" close=")">#{item}</foreach>) | 
|           <if test="createUser != null"> | 
|             or `a`.`CREATE_USER` = #{createUser}  OR a.user_id = #{createUser} | 
|           </if> | 
|           <if test="procedureIds != null and procedureIds.size()>0"> | 
|             or a.`PROCEDURE_ID` in | 
|             <foreach collection="procedureIds" item="item" separator="," open="(" close=")">#{item}</foreach> | 
|           </if> | 
|           ) | 
|         </when> | 
|         <otherwise> | 
|           <if test="createUser != null"> | 
|             AND    (`a`.`CREATE_USER` = #{createUser}  OR a.user_id = #{createUser}) | 
|           </if> | 
|         </otherwise> | 
|       </choose> | 
|     </where> | 
|   </select> | 
|   | 
|   <insert id="insertBatch"  > | 
|     insert into `plans` ( | 
|       `ID`, | 
|       `DELETED`, | 
|       `CREATE_USER`, | 
|       `CREATE_TIME`, | 
|       `UPDATE_USER`, | 
|       `UPDATE_TIME`, | 
|       `REMARK`, | 
|       `ROOT_DEPART_ID`, | 
|       `DEPART_ID`, | 
|       `ORIGIN`, | 
|       `PLAN_DATE`, | 
|       `MATERIAL_ID`, | 
|       `PROCEDURE_ID`, | 
|       `FACTORY_ID`, | 
|       `UNIT_ID`, | 
|       `NUM`, | 
|       `BATCH`, | 
|       `URGENT`, | 
|       `IMPORT_ID`, | 
|       `USER_ID`, | 
|       `STATUS`, | 
|       `PAUSED`, | 
|       `TYPE`, | 
|       `PUBLISH_DATE`, | 
|     BACKORDER_ID | 
|     ) | 
|     values | 
|     <foreach collection="list" item="item" separator=","> | 
|            ( | 
|              #{item.id}, | 
|              #{item.deleted}, | 
|              #{item.createUser}, | 
|              #{item.createTime}, | 
|              #{item.updateUser}, | 
|              #{item.updateTime}, | 
|              #{item.remark}, | 
|              #{item.rootDepartId}, | 
|              #{item.departId}, | 
|              #{item.origin}, | 
|              #{item.planDate}, | 
|              #{item.materialId}, | 
|              #{item.procedureId}, | 
|              #{item.factoryId}, | 
|              #{item.unitId}, | 
|              #{item.num}, | 
|              #{item.batch}, | 
|              #{item.item.urgent}, | 
|              #{item.importId}, | 
|              #{item.userId}, | 
|              #{item.status}, | 
|              #{item.paused}, | 
|              #{item.type}, | 
|              #{item.publishDate}, | 
|             #{item.backorderId} | 
|            ) | 
|     </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 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 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) AND to_days(b.create_time)=to_days(now())) as prouserNum, | 
|     (select count(distinct(b.PRO_GROUP_ID))  FROM   workorder   b  where   b.PROCEDURE_ID=#{procedureId}  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) AND to_days(b.create_time)=to_days(now())) 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 AND to_days(b.create_time)=to_days(now())) 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 AND to_days(b.create_time)=to_days(now())) 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> |