mybatis

作者: 无花无酒_3cd3 | 来源:发表于2020-07-17 16:01 被阅读0次

    配置文件

    <?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.NewScanSmsSendStatisticMapper">
     <!-- 通用查询映射结果 -->
        <resultMap id="ResultMap" type="com.ScanSmsSendStatisticVo">
            <result column="stats_date" property="statsDate" />
            <result column="area" property="area" />
            <result column="city_id" property="cityId" />
            <result column="province_id" property="provinceId" />
            <result column="province_business_id" property="provinceBusinessId" />
            <result column="province_business" property="provinceBusiness" />
            <result column="org_id" property="orgId" />
            <result column="org_name" property="orgName" />
            <result column="pre_org_id" property="preOrgId"/>
            <result column="pre_org_name" property="preOrgName"/>
            <result column="send_total" property="sendTotal" />
            <result column="collect_count" property="collectCount" />
            <result column="distribute_count" property="distributeCount" />
            <result column="sign_count" property="signCount" />
            <result column="deliver_count" property="deliverCount" />
            <result column="sms_cost" property="smsCost" />
            <result column="head_config" property="headConfig" />
            <result column="order_type" property="orderType" />
            <result column="type_name" property="orderTypeName" />
        </resultMap>
        <!-- 查询 -->
    <select id="newselectStatistic" resultType="java.util.Map">
            SELECT IFNULL(SUM(send_total), 0) AS sendTotal, IFNULL(SUM(collect_count), 0) AS collectCount,
                IFNULL(SUM(distribute_count), 0) AS distributeCount, IFNULL(SUM(sign_count), 0) AS signCount,
                IFNULL(SUM(sms_cost), 0) AS smsCost
            FROM tb_scan_sms_send_statistic a
            <if test="queryDto.roleId != null ">
                INNER JOIN tr_sms_trace_permission p ON p.order_type = a.order_type AND trace_type = 1
            </if>
            WHERE stats_date BETWEEN #{queryDto.startDate} AND #{queryDto.endDate}
            <if test="queryDto.createOrgId != null ">
                AND (a.org_id = #{queryDto.createOrgId} OR a.pre_org_id = #{queryDto.createOrgId})
            </if>
            <if test="queryDto.roleId != null" >
                AND p.role_id = #{queryDto.roleId}
            </if>
        </select>
        <select id="newselectTotal" resultType="com.ScanSmsSendStatisticVo">
            SELECT * FROM tb_scan_sms_send_statistic  where id=3126905;
        </select>
       <!-- 查询 -->
        <select id="newselectList" resultMap="ResultMap">
             SELECT * FROM tb_scan_sms_send_statistic  where id  between 3126903 and 3126905
        </select>
    </mapper>
    
    

    NewScanSmsSendStatisticMapper.class

    public interface NewScanSmsSendStatisticMapper extends BaseMapper<NewScanSmsSendStatistic> {
     
        Map<String,Object> newselectStatistic(@Param("queryDto") GetScanSmsSendStatisticDto queryDto);
        ScanSmsSendStatisticVo newselectTotal(@Param("queryDto") GetScanSmsSendStatisticDto queryDto);
        List<ScanSmsSendStatisticVo> newselectList(Page<ScanSmsSendStatisticVo> page, @Param("queryDto") GetScanSmsSendStatisticDto queryDto);
    
    }
    

    第一种:返回对象用

    controller文件

     @PostMapping("wangnewData.do")
     @ResponseBody
        public ResultResp newData(@RequestBody GetScanSmsSendStatisticDto queryDto) {
    
            Map<String, Object> stringObjectMap = this.statisticService.newData(queryDto);
            return ResultResp.ok(stringObjectMap);
        }
    

    接口文件

    public interface NewScanSmsSendStatisticService extends IService<NewScanSmsSendStatistic> {
        Map<String, Object> newselectStatistic();
        ScanSmsSendStatisticVo newselectTotal(GetScanSmsSendStatisticDto queryDto);
        Page<ScanSmsSendStatisticVo> selectPage(GetScanSmsSendStatisticDto queryDto);
        Map<String ,Object> newData(GetScanSmsSendStatisticDto queryDto );
    }
    

    接口实现

    @Slf4j
    @Service
    public class NewScanSmsSendStatisticServiceImpl extends ServiceImpl<NewScanSmsSendStatisticMapper, NewScanSmsSendStatistic>
            implements NewScanSmsSendStatisticService {
     
        @Override
        public Map<String, Object> newData(GetScanSmsSendStatisticDto queryDto) {
            Map map= new HashMap();
            map.put("wang","nono");
            return map;
        }
    }
    
    

    第二种:返回list

    controller文件

      @PostMapping("wangselectPage.do")
        @ResponseBody
        public ResultResp selectPage(@RequestBody GetScanSmsSendStatisticDto queryDto) {
    
            Page<ScanSmsSendStatisticVo> scanSmsSendStatisticVoPage = this.statisticService.selectPage(queryDto);
            return ResultResp.ok(scanSmsSendStatisticVoPage);
        }
    

    接口文件

    public interface NewScanSmsSendStatisticService extends IService<NewScanSmsSendStatistic> {
        Page<ScanSmsSendStatisticVo> selectPage(GetScanSmsSendStatisticDto queryDto);
    }
    

    接口实现

      @Override
        public Page<ScanSmsSendStatisticVo> selectPage(GetScanSmsSendStatisticDto queryDto) {
            Page<ScanSmsSendStatisticVo> objectPage = new Page<>();
            this.baseMapper.newselectList(objectPage,queryDto);
            return objectPage;
        }
    

    相关文章

      网友评论

          本文标题:mybatis

          本文链接:https://www.haomeiwen.com/subject/jvgghktx.html