mapper.java定义xml的sql

impl.java

/**
 * 生产执行 服务实现类
 *
 * @author zq
 * @since 2025-07-25
 */
@Service
@RequiredArgsConstructor
public class ExecTaskServiceImpl implements IExecTaskService {

    private final IAssignService assignService;

    private final ExecTaskMapper execTaskMapper;

    @Override
    public TableDataInfo<ExecTaskVO> queryPage(ExecTaskPageQuery taskPageQuery) {
        // 工站数据权限
        Set<Long> taskIds = queryTaskIds(taskPageQuery);
        if (CollectionUtil.isEmpty(taskIds)) {
            return new TableDataInfo<>();
        }
        Page<ExecTaskVO> page = execTaskMapper.queryPage(taskPageQuery, taskPageQuery.page());
        return new TableDataInfo<>(page.getRecords(), page.getTotal());
    }

    private Set<Long> queryTaskIds(ExecTaskPageQuery taskPageQuery) {
        Assign assignQuery = new Assign();
//        assignQuery.setAssignRole(taskPageQuery.getWorkstationId());
        assignQuery.setAssignType(2);// 0-人员 1-部门 2-工站
        return assignService.queryDataId(assignQuery);
    }
}

mapper.java

/**
 * 生产执行 Mapper接口
 *
 * @author zq
 * @since 2025-07-25
 */
public interface ExecTaskMapper {

    Page<ExecTaskVO> queryPage(@Param("query") ExecTaskPageQuery taskPageQuery, @Param("page") Page<ExecTaskVO> page);

    Page<ExecTaskVO> querySchedulePage(@Param("query") ExecTaskPageQuery taskPageQuery, @Param("page") Page<ExecTaskVO> page);

}

mapper.xml

<?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.zq.mes.craft.mapper.ExecTaskMapper">

    <resultMap id="execTaskVOResultMap" type="com.zq.mes.craft.domain.vo.ExecTaskVO">
        <result property="packagingSpec" column="packaging_spec"
                typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
        <result property="unitOfCode" column="unit_of_measure"/>
    </resultMap>

    <select id="queryPage" resultMap="execTaskVOResultMap">

        <include refid="queryTask"></include>
        ORDER BY task.scheduled_time DESC,task.priority DESC

    </select>

    <select id="querySchedulePage" resultMap="execTaskVOResultMap">

        <include refid="queryTask"></include>
        ORDER BY task.scheduled_time DESC

    </select>

    <sql id="queryTask">

        SELECT
        task.task_id,
        task.task_code,
        task.workorder_code,
        task.priority,
        task.prod_status,
        task.expected_start_time,
        task.expected_end_time,
        task.assembly_id,
        task.assembly_name,
        task.item_id,
        task.item_code,
        task.item_name,
        task.specification,
        task.packaging_spec,
        task.packaging_spec_str,
        task.quantity,
        task.unit_of_measure,
        task.batch_code,
        task.doc_type,
        task.scheduled_time,
        task.team_id,
        task.team_name,
        task.shift_id,
        task.shift_name,
        task.plan_start_time,
        task.plan_end_time,
        task.route_id,
        task.route_name,
        task.sche_status,
        card.alone_pack,
        card.task_card_id,
        card.task_card_code,
        card.task_card_name,
        card.preparation_state_flag,
        card.preparation_file_flag,
        card.preparation_sign_flag,
        card.inspection_state_flag,
        card.inspection_file_flag,
        card.inspection_sign_flag
        FROM
        pro_leps_task task
        LEFT JOIN task_card card ON task.task_id = card.task_id
        AND task.del_flag = 0
        AND card.del_flag = 0
        <where>
            <if test="query.status != null">
                AND card.`status` = #{query.status}
            </if>
            <if test="query.priority != null">
                AND task.priority = #{query.priority}
            </if>
            <if test="query.docType != null and query.docType !=''">
                AND task.doc_type = #{query.docType}
            </if>
            <if test="query.workorderCode != null and query.workorderCode !=''">
                AND task.workorder_code LIKE CONCAT( '%', #{query.workorderCode}, '%' )
            </if>
            <if test="query.taskCode != null and query.taskCode !=''">
                AND task.task_code LIKE CONCAT( '%', #{query.taskCode}, '%' )
            </if>
            <if test="query.itemCode != null and query.itemCode !=''">
                AND task.item_code LIKE CONCAT( '%', #{query.itemCode}, '%' )
            </if>
            <if test="query.itemName != null and query.itemName !=''">
                AND task.item_name LIKE CONCAT( '%', #{query.itemName}, '%' )
            </if>
            <if test="query.specification != null and query.specification !=''">
                AND task.specification LIKE CONCAT( '%', #{query.specification}, '%' )
            </if>
            <if test="query.batchCode != null and query.batchCode !=''">
                AND task.batch_code LIKE CONCAT( '%', #{query.batchCode}, '%' )
            </if>
            <if test="query.assemblyName != null and query.assemblyName !=''">
                AND task.assembly_name LIKE CONCAT( '%', #{query.assemblyName}, '%' )
            </if>
            <if test="query.packagingSpecStr != null and query.packagingSpecStr !=''">
                AND task.packaging_spec_str LIKE CONCAT( '%', #{query.packagingSpecStr}, '%' )
            </if>
            <if test="query.quantity != null">
                AND task.quantity LIKE CONCAT( '%', #{query.quantity}, '%' )
            </if>
            <if test="query.teamName != null and query.teamName !=''">
                AND task.team_name LIKE CONCAT( '%', #{query.teamName}, '%' )
            </if>
            <if test="query.shiftName != null and query.shiftName !=''">
                AND task.shift_name LIKE CONCAT( '%', #{query.shiftName}, '%' )
            </if>
            <if test="query.scheduledTimeStart != null and query.scheduledTimeStart !=''">
                AND task.scheduled_time &gt; CONCAT(#{query.scheduledTimeStart}, ' 00:00:00' )
            </if>
            <if test="query.scheduledTimeEnd != null and query.scheduledTimeEnd !=''">
                AND task.scheduled_time &lt; CONCAT(#{query.scheduledTimeEnd}, ' 23:59:59' )
            </if>
            <if test="query.expectedStartTimeStart != null and query.expectedStartTimeStart !=''">
                AND task.expected_start_time &gt; CONCAT(#{query.expectedStartTimeStart}, ' 00:00:00' )
            </if>
            <if test="query.expectedStartTimeEnd != null and query.expectedStartTimeEnd !=''">
                AND task.expected_start_time &lt; CONCAT(#{query.expectedStartTimeEnd}, ' 23:59:59' )
            </if>
            <if test="query.expectedEndTimeStart != null and query.expectedEndTimeStart !=''">
                AND task.expected_end_time &gt; CONCAT(#{query.expectedEndTimeStart}, ' 00:00:00' )
            </if>
            <if test="query.expectedEndTimeEnd != null and query.expectedEndTimeEnd !=''">
                AND task.expected_end_time &lt; CONCAT(#{query.expectedEndTimeEnd}, ' 23:59:59' )
            </if>
            <if test="query.keyWord != null and query.keyWord !=''">
                AND (
                task.task_code LIKE CONCAT( '%', #{query.keyWord}, '%' )
                OR task.item_code LIKE CONCAT( '%', #{query.keyWord}, '%' )
                OR task.item_name LIKE CONCAT( '%', #{query.keyWord}, '%' )
                OR task.specification LIKE CONCAT( '%', #{query.keyWord}, '%' )
                OR task.batch_code LIKE CONCAT( '%', #{query.keyWord}, '%' )
                OR task.assembly_name LIKE CONCAT( '%', #{query.keyWord}, '%' )
                OR task.team_name LIKE CONCAT( '%', #{query.keyWord}, '%' )
                OR task.shift_name LIKE CONCAT( '%', #{query.keyWord}, '%' )
                )
            </if>
            <if test="query.prodStatuses != null and !query.prodStatuses.isEmpty()">
                AND task.prod_status IN
                <foreach collection="query.prodStatuses" item="prodStatus" open="(" close=")" separator=",">
                    #{prodStatus}
                </foreach>
            </if>
            <if test="query.scheStatuses != null and !query.scheStatuses.isEmpty()">
                AND task.sche_status IN
                <foreach collection="query.scheStatuses" item="scheStatus" open="(" close=")" separator=",">
                    #{scheStatus}
                </foreach>
            </if>
            <if test="query.taskIds != null and !query.taskIds.isEmpty()">
                AND task.task_id IN
                <foreach collection="query.taskIds" item="taskId" open="(" close=")" separator=",">
                    #{taskId}
                </foreach>
            </if>
        </where>

    </sql>

</mapper>

posted @ 2025-07-25 16:40  南翔技校毕业后  阅读(8)  评论(0)    收藏  举报