<?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="cn.iocoder.yudao.module.mes.dal.mysql.task.TaskDetailMapper">

    <!--
        一般情况下，尽可能使用 Mapper 进行 CRUD 增删改查即可。
        无法满足的场景，例如说多表关联查询，才使用 XML 编写 SQL。
        代码生成器暂时只生成 Mapper XML 文件本身，更多推荐 MybatisX 快速开发插件来生成查询。
        文档可见：https://www.iocoder.cn/MyBatis/x-plugins/
     -->
    <resultMap id="BaseResultMap" type="cn.iocoder.yudao.module.mes.dal.dataobject.task.TaskDetailDO">
        <id column="id" property="id" />
        <result column="product_id" property="productId" />
        <result column="unit_id" property="unitId" />
        <result column="task_id" property="taskId" />
        <result column="number" property="number" />
        <result column="package_size" property="packageSize" />
        <result column="project_name" property="projectName" />
        <result column="tech_requirements" property="techRequirements" />
        <result column="remark" property="remark" />
        <result column="is_enable" property="isEnable" />
        <result column="creator" property="creator" />
        <result column="create_time" property="createTime" />
        <result column="updater" property="updater" />
        <result column="update_time" property="updateTime" />
        <result column="deleted" property="deleted" />
        <result column="tenant_id" property="tenantId" />
        <result column="package_number" property="packageNumber" />
        <result column="finish_date" property="finishDate" />
        <result column="boxing_date" property="boxingDate" />
        <result column="arrive_date" property="arriveDate" />
        <result column="bar_code" property="barCode" />
        <result column="attachment" property="attachment" />
        <result column="sale_order_code" property="saleOrderCode" />
    </resultMap>
    <resultMap id="sumResultMap" type="cn.iocoder.yudao.module.mes.dal.dataobject.task.TaskDetailSumResult">
        <result column="product_id" property="productId" />
        <result column="task_id" property="taskId" />
        <result column="number" property="number" />
    </resultMap>
    <sql id="Base_Column_List">
        id, product_id, unit_id, task_id, `number`, package_size, project_name,
            tech_requirements, remark, is_enable, creator, create_time, updater, update_time,
            deleted, tenant_id, package_number, finish_date, boxing_date, arrive_date,
            bar_code, attachment, sale_order_code
    </sql>

    <!-- 根据ID查询 -->
    <select id="selectSumListByTaskId" parameterType="long" resultMap="sumResultMap">
        SELECT product_id, task_id, SUM(number) AS number
        FROM mes_task_detail
        WHERE task_id = #{taskId}
        GROUP BY product_id;
    </select>
</mapper>