<?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.collect.mapper.CollectBasicMapper">
    <update id="updateStatusById">
		UPDATE material_management_collect_basics SET status = #{type}
		WHERE id = #{id}
	</update>
    <select id="findWareHouseList"
            resultType="com.jeeplus.test.materialManagement.collect.service.dto.WareHouseSummaryDto">
        SELECT
			a.id,
			a.create_by,
			a.create_date,
			a.trade_name,
			a.trade_number
		FROM
			material_management_warehouse_basics a
			${ew.customSqlSegment}
		ORDER BY a.update_date DESC
    </select>
    <select id="findChildIds" resultType="java.lang.String">
		select id from sys_office where parent_id = #{department}
	</select>
	<select id="findList" resultType="com.jeeplus.test.materialManagement.collect.service.dto.CollectDto">
		SELECT
        	DISTINCT
			a.id,
			a.create_by,
			a.create_date,
			a.status,
			a.proc_ins_id,
			a.process_definition_id,
			a.collect_no,
			a.handled_by,
			a.handled_by_office,
			a.collect_date,
			b.goods_name,
			b.id as detail_id,
			so.name as handledByOfficeName,
			su.name as handledByName,
			art.ID_ as task_id,
			returna.status as status_return,
			returna.proc_ins_id as proc_ins_id_return,
			returna.process_definition_id as process_definition_id_return,
			returna.id as return_id,
			art_r.ID_ as task_id_return
		FROM
			material_management_collect_basics a
			left join sys_user su on a.handled_by = su.id
			left join sys_office so on a.handled_by_office = so.id
			left join material_management_collect_detailed b on a.id = b.basic_id and b.del_flag = '0'
			left join act_ru_task art ON a.proc_ins_id = art.PROC_INST_ID_
			left join material_management_collect_basics_return returna on returna.basic_id = a.id and returna.del_flag = '0'
			left join act_ru_task art_r ON returna.proc_ins_id = art_r.PROC_INST_ID_
			${ew.customSqlSegment}
		ORDER BY a.update_date DESC
	</select>
	<select id="getUserNameByUserId" resultType="java.lang.String">
		select name from sys_user where id = #{id}
	</select>
	<select id="selectReturnByBasicId" resultType="com.jeeplus.test.materialManagement.collect.domain.CollectBasicsReturn">
		select *
		from material_management_collect_basics_return
		where basic_id = #{id}
	</select>
	<update id="setCauseEmptyById">
		update material_management_collect_basics_return set remarks = null where id = #{id}
	</update>
</mapper>
