<?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.yami.shop.dao.ShopCategoryLogMapper">


    <select id="groupByCode" resultType="com.yami.shop.bean.vo.ShopCategoryLogVO">
        SELECT
        p.task_code AS taskCode,
        p.task_name  AS taskName,
        max(p.create_time) AS createTime,
        p.create_by AS createBy,
        COUNT(IF(p.is_fail = 1, 1, NULL)) AS successStatus,
        COUNT(IF(p.is_fail = 0, 1, NULL)) AS failureStatus,
        u.username AS createByName,
        r.role_name AS createByRole
        from tz_shop_category_log p
        left join tz_sys_user u on p.create_by = u.user_id
        left join tz_sys_user_role ur on u.user_id = ur.user_id
        left join tz_sys_role r on ur.role_id = r.role_id
        <where>
            <if test="shopId != null">p.shop_id = #{shopId}</if>
        </where>
        GROUP BY p.task_code,p.task_name, p.create_by, u.username, r.role_name
    </select>
</mapper>
