<?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.api.manage.dao.operationManagement.SysElectronicCommerceDao">

    <select id="list" parameterType="com.api.model.operationManagement.SearchElectronicCommerce" resultType="com.api.vo.operationManagement.VoElectronicCommerce">
        select sec.id,sec.code,sec.title,secc.name as electronic_commerce_category_name,su.actual_name as create_name,sec.create_date
        from sys_electronic_commerce as sec,sys_electronic_commerce_category as secc,sys_user as su
        <where>
            sec.electronic_commerce_category_id = secc.id
            and sec.create_id = su.id
            <if test="code != null and code != ''">
                and sec.code like concat('%',#{code},'%')
            </if>
            <if test="title != null and title != ''">
                and sec.title like concat('%',#{title},'%')
            </if>
            <if test="electronicCommerceCategoryId != null">
                and sec.electronic_commerce_category_id = #{electronicCommerceCategoryId}
            </if>
            <if test="createName != null and createName != ''">
                and su.actual_name like concat('%',#{createName},'%')
            </if>
            <if test="createDateStart != null">
                and sec.create_date <![CDATA[ >= ]]> #{createDateStart}
            </if>
            <if test="createDateEnd != null">
                and sec.create_date <![CDATA[ <= ]]> #{createDateEnd}
            </if>
        </where>
        order by sec.create_date DESC
    </select>

    <insert id="insert" parameterType="com.api.model.operationManagement.SysElectronicCommerce">
        insert into sys_electronic_commerce(
            code,
            title,
            content,
            electronic_commerce_category_id,
            create_id,
            create_date
        )values (
            #{code},
            #{title},
            #{content},
            #{electronicCommerceCategoryId},
            #{createId},
            #{createDate}
        )
        <selectKey keyProperty="id" resultType="java.lang.Integer">
            select LAST_INSERT_ID() AS id
        </selectKey>
    </insert>

    <select id="findById" parameterType="java.lang.Integer" resultType="com.api.vo.operationManagement.VoFBIElectronicCommerce">
        select sec.id,sec.code,sec.title,sec.electronic_commerce_category_id,secc.name as electronic_commerce_category_name,su.actual_name as create_name,sec.create_date
        from sys_electronic_commerce as sec,sys_electronic_commerce_category as secc,sys_user as su
        where sec.electronic_commerce_category_id = secc.id
        and sec.create_id = su.id and sec.id = #{id}
    </select>

    <update id="update" parameterType="com.api.model.operationManagement.SysElectronicCommerce">
        update sys_electronic_commerce
        set title = #{title},
        content = #{content},
        electronic_commerce_category_id = #{electronicCommerceCategoryId},
        modify_id = #{modifyId},
        modify_date = #{modifyDate}
    </update>

    <delete id="delete" parameterType="java.lang.Integer">
        delete from sys_electronic_commerce where id = #{id}
    </delete>


</mapper>