<?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.jeeplus.test.materialManagement.wareHouse.mapper.WareHouseDetailedMapper">
    <select id="getByBasicId"
            resultType="com.jeeplus.test.materialManagement.wareHouse.domain.WareHouseDetailed">
        select a.*,b.name as wareHouseMan,b.id as wareHouseManId,c.name as wareHouseManOffice,
        d.id as wareHouseTypeId, d.name as wareHouseType
        from material_management_warehouse_detailed a
        left join sys_user b on a.ware_house_man = b.id and b.del_flag = '0'
        left join sys_office c on b.office_id = c.id
        left join material_management_type d on a.ware_house_type = d.id
        where a.basic_id = #{id} and a.del_flag = '0' and a.up_flag = '0'
        ORDER BY a.create_date desc
    </select>
    <select id="getByBasicIdAll"
            resultType="com.jeeplus.test.materialManagement.wareHouse.domain.WareHouseDetailed">
        select a.*,b.name as wareHouseMan,b.id as wareHouseManId,c.name as wareHouseManOffice,
        d.id as wareHouseTypeId, d.name as wareHouseType
        from material_management_warehouse_detailed a
        left join sys_user b on a.ware_house_man = b.id and b.del_flag = '0'
        left join sys_office c on b.office_id = c.id
        left join material_management_type d on a.ware_house_type = d.id
        where a.basic_id = #{id} and a.del_flag = '0' and (a.up_flag = '1' or a.up_flag = '2')
        ORDER BY a.create_date desc
    </select>
    <select id="getByAttachmentId" resultType="com.jeeplus.test.workContract.service.dto.WorkAttachmentDto">
        SELECT
			id,
			url,
			attachment_name AS `name`,
			create_by AS `by`,
			create_date
		FROM
			work_attachment
		WHERE
			del_flag = 0
			AND attachment_id = #{id}
    </select>
    <select id="getIdByBasicId" resultType="java.lang.String">
        select a.id from material_management_warehouse_detailed a where a.basic_id = #{id} and a.del_flag = 0
    </select>
    <select id="getUsersInfo" resultType="com.jeeplus.sys.service.dto.UserDTO">
        select a.user_id as id,a.user_name as loginName  from material_user a
    </select>
    <update id="upSourceIdEmpty">
        update material_management_warehouse_detailed set source_id = null where id = #{id}
    </update>
    <delete id="deleteByBasicId">
        delete from material_management_warehouse_detailed where basic_id = #{basicId}
    </delete>
    <delete id="deleteFilesByIdList">
        delete from work_attachment where attachment_id in
        <foreach collection="attachmentIdList" item="attachmentId" open="(" separator="," close=")">
            #{attachmentId}
        </foreach>
    </delete>
    <update id="saveTradeName">
        update material_management_warehouse_detailed set
        trade_name = #{tradeName}
        where trade_name = #{oldTradeName} and ware_house_type = #{wareHouseType} and del_flag = '0'
    </update>
    <update id="saveGoodsName">
        update material_management_collect_detailed set
        goods_name = #{tradeName}
        where goods_name = #{oldTradeName} and collect_type = #{wareHouseType} and del_flag = '0'
    </update>
    <select id="getByTypeId" resultType="com.jeeplus.test.materialManagement.wareHouse.domain.WareHouseDetailed">
        SELECT
            id,
            trade_name
        FROM
            material_management_warehouse_detailed
        WHERE
            del_flag = '0'
            AND ware_house_type = #{typeId}
        GROUP BY
            trade_name
        ORDER BY
            create_date DESC
    </select>
</mapper>
