emis-service/emis-biz/src/main/resources/mapper/EmisTransPlanRuleMapper.xml

193 lines
11 KiB
XML
Raw Normal View History

<?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.xdadan.erp.emis.mapper.EmisTransPlanRuleMapper">
<resultMap type="EmisTransPlanRule" id="EmisTransPlanRuleResult" extends="com.xdadan.erp.emis.mapper.EmisBaseMapper.EmisBaseResult">
<result property="id" column="id" />
<result property="parentId" column="parent_id" />
<result property="ancestors" column="ancestors" />
<result property="lineName" column="line_name" />
<result property="transType" column="trans_type" />
<result property="productType" column="product_type" />
<result property="startSiteCode" column="start_site_code" />
<result property="startSiteName" column="start_site_name" />
<result property="nextSiteCode" column="next_site_code" />
<result property="nextSiteName" column="next_site_name" />
<result property="supplierCode" column="supplier_code" />
<result property="status" column="status" />
</resultMap>
<sql id="selectEmisTransPlanRuleVo">
select r.id, r.parent_id, r.ancestors, r.line_name, r.trans_type, r.product_type, r.start_site_code,
s1.site_name as start_site_name, r.next_site_code, s2.site_name as next_site_name, r.supplier_code,
r.status, r.remark, r.del_flag, r.create_by, r.create_time, r.update_by, r.update_time, r.create_site, r.update_site
from emis_trans_plan_rule r
left join emis_site s1 on r.start_site_code = s1.site_code and s1.del_flag=0
left join emis_site s2 on r.next_site_code = s2.site_code and s2.del_flag=0
</sql>
<select id="selectEmisTransPlanRuleList" parameterType="EmisTransPlanRule" resultMap="EmisTransPlanRuleResult">
<include refid="selectEmisTransPlanRuleVo"/>
<where>
<if test="parentId != null"> and r.parent_id = #{parentId}</if>
<if test="ancestors != null and ancestors != ''"> and r.ancestors like concat(#{ancestors}, '%')</if>
<if test="lineName != null and lineName != ''"> and r.line_name like concat('%', #{lineName}, '%')</if>
<if test="transType != null and transType != ''"> and ( FIND_IN_SET(#{transType},r.trans_type) )</if>
<if test="productType != null and productType != ''"> and ( FIND_IN_SET(#{productType},r.product_type) )</if>
<if test="startSiteCode != null and startSiteCode != ''"> and r.start_site_code = #{startSiteCode}</if>
<if test="nextSiteCode != null and nextSiteCode != ''"> and r.next_site_code = #{nextSiteCode}</if>
<if test="supplierCode != null and supplierCode != ''"> and ( FIND_IN_SET(#{supplierCode},r.supplier_code) )</if>
<if test="status != null and status != ''"> and r.status = #{status}</if>
and r.del_flag = '0'
</where>
order by parent_id, create_time desc
</select>
<select id="selectEmisTransPlanRuleTree" parameterType="EmisTransPlanRule" resultMap="EmisTransPlanRuleResult">
<include refid="selectEmisTransPlanRuleVo"/>
<where>
<if test="parentId != null">and r.parent_id = #{parentId}</if>
<if test="ancestors != null and ancestors != ''">and r.ancestors like concat(#{ancestors}, '%')</if>
<if test="lineName != null and lineName != ''">and r.line_name =#{lineName}</if>
<if test="transType != null and transType != ''">and ( FIND_IN_SET(#{transType},r.trans_type) )</if>
<if test="productType != null and productType != ''">and ( FIND_IN_SET(#{productType},r.product_type) )
</if>
<if test="startSiteCode != null and startSiteCode != ''">and r.start_site_code = #{startSiteCode}</if>
<if test="nextSiteCode != null and nextSiteCode != ''">and r.next_site_code = #{nextSiteCode}</if>
<if test="supplierCode != null and supplierCode != ''">and ( FIND_IN_SET(#{supplierCode},r.supplier_code)
)
</if>
<if test="status != null and status != ''">and r.status = #{status}</if>
and r.del_flag = '0'
</where>
order by parent_id, create_time desc
</select>
<select id="selectEmisTransPlanRuleById" parameterType="Long" resultMap="EmisTransPlanRuleResult">
<include refid="selectEmisTransPlanRuleVo"/>
where r.id = #{id} and r.del_flag = '0'
</select>
<select id="selectChildrenEmisTransPlanRuleById" parameterType="Long" resultMap="EmisTransPlanRuleResult">
<include refid="selectEmisTransPlanRuleVo"/>
where r.parent_id = #{id} and r.del_flag = '0'
</select>
<select id="hasChildByEmisTransPlanRuleId" parameterType="Long" resultType="Integer">
select count(1) from emis_trans_plan_rule
where parent_id = #{id} and del_flag = '0'
</select>
<select id="selectSupplierNamesByCodes" parameterType="String" resultType="String">
SELECT GROUP_CONCAT(s.name)
FROM emis_supplier s
WHERE FIND_IN_SET(s.code, #{supplierCodes}) AND s.del_flag = 0
</select>
<select id="selectProductTypeNamesByCodes" parameterType="String" resultType="String">
SELECT GROUP_CONCAT(s.prod_name)
FROM emis_trans_product s
WHERE FIND_IN_SET(s.prod_code, #{productType}) AND s.del_flag = 0
</select>
<insert id="insertEmisTransPlanRule" parameterType="EmisTransPlanRule" useGeneratedKeys="true" keyProperty="id">
insert into emis_trans_plan_rule
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="parentId != null">parent_id,</if>
<if test="ancestors != null">ancestors,</if>
<if test="lineName != null">line_name,</if>
<if test="transType != null">trans_type,</if>
<if test="productType != null">product_type,</if>
<if test="startSiteCode != null">start_site_code,</if>
<if test="nextSiteCode != null">next_site_code,</if>
<if test="supplierCode != null">supplier_code,</if>
<if test="status != null">status,</if>
<if test="remark != null">remark,</if>
<if test="delFlag != null">del_flag,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="createSite != null">create_site,</if>
<if test="updateSite != null">update_site,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="parentId != null">#{parentId},</if>
<if test="ancestors != null">#{ancestors},</if>
<if test="lineName != null">#{lineName},</if>
<if test="transType != null">#{transType},</if>
<if test="productType != null">#{productType},</if>
<if test="startSiteCode != null">#{startSiteCode},</if>
<if test="nextSiteCode != null">#{nextSiteCode},</if>
<if test="supplierCode != null">#{supplierCode},</if>
<if test="status != null">#{status},</if>
<if test="remark != null">#{remark},</if>
<if test="delFlag != null">#{delFlag},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="createSite != null">#{createSite},</if>
<if test="updateSite != null">#{updateSite},</if>
</trim>
</insert>
<update id="updateEmisTransPlanRule" parameterType="EmisTransPlanRule">
update emis_trans_plan_rule
<trim prefix="SET" suffixOverrides=",">
<if test="parentId != null">parent_id = #{parentId},</if>
<if test="ancestors != null">ancestors = #{ancestors},</if>
<if test="lineName != null">line_name = #{lineName},</if>
<if test="transType != null">trans_type = #{transType},</if>
<if test="productType != null">product_type = #{productType},</if>
<if test="startSiteCode != null">start_site_code = #{startSiteCode},</if>
<if test="nextSiteCode != null">next_site_code = #{nextSiteCode},</if>
<if test="supplierCode != null">supplier_code = #{supplierCode},</if>
<if test="status != null">status = #{status},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="createSite != null">create_site = #{createSite},</if>
<if test="updateSite != null">update_site = #{updateSite},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteEmisTransPlanRuleById" parameterType="Long">
update emis_trans_plan_rule set del_flag = '1' where id = #{id}
</delete>
<delete id="deleteEmisTransPlanRuleByIds" parameterType="String">
update emis_trans_plan_rule set del_flag = '1' where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="selectSupplierInfoByConditions" resultMap="EmisTransPlanRuleResult">
SELECT DISTINCT r.id, r.parent_id, r.ancestors, r.line_name, r.trans_type, r.product_type,
r.start_site_code, s1.site_name as start_site_name, r.next_site_code, s2.site_name as next_site_name,
r.supplier_code, GROUP_CONCAT(s.name) as supplier_name, r.status, r.remark, r.del_flag,
r.create_by, r.create_time, r.update_by, r.update_time, r.create_site, r.update_site
FROM emis_trans_plan_rule r
LEFT JOIN emis_site s1 ON r.start_site_code = s1.site_code AND s1.del_flag = 0
LEFT JOIN emis_site s2 ON r.next_site_code = s2.site_code AND s2.del_flag = 0
LEFT JOIN emis_supplier s ON FIND_IN_SET(s.code, r.supplier_code) AND s.del_flag = 0
WHERE r.del_flag = 0
<if test="transType != null and transType != ''">
AND FIND_IN_SET(#{transType}, r.trans_type)
</if>
<if test="startSiteCode != null and startSiteCode != ''">
AND r.start_site_code = #{startSiteCode}
</if>
<if test="nextSiteCode != null and nextSiteCode != ''">
AND r.next_site_code = #{nextSiteCode}
</if>
AND r.status = '1'
</select>
</mapper>