cjl
2023-10-08 523c39cfb292a76a28e8a883e583a35a40f1b77b
fix:月数据修复补充提交
3 files modified
73 ■■■■■ changed files
screen-api/src/main/java/com/moral/api/mapper/HistoryHourlyMapper.java 2 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java 53 ●●●●● patch | view | raw | blame | history
screen-api/src/main/resources/mapper/HistoryHourlyMapper.xml 18 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/mapper/HistoryHourlyMapper.java
@@ -44,4 +44,6 @@
    void updateHistoryHourly(Map<String, Object> params);
    List<HistoryHourly> listResult(Map<String, Object> params);
    List<HistoryHourly> listLikeResult(Map<String, Object> params);
}
screen-api/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java
@@ -746,43 +746,44 @@
     */
    @Override
    public List<HistoryHourly> getValueByMacAndTime(String mac, Date startDate, Date endDate) {
        QueryWrapper<HistoryHourly> wrapper = new QueryWrapper<>();
        wrapper.eq("mac", mac);
        wrapper.between("time", startDate, endDate);
        Map<String, Object> mapParams = new HashMap<>();
        mapParams.put("startDate",startDate);
        mapParams.put("endDate",endDate);
        mapParams.put("mac",mac);
        List<String> tableNames = MybatisPLUSUtils.getTableNamesByWrapper(startDate, endDate, SeparateTableType.MONTH);
        List<HistoryHourly> datas = multiTableQuery(wrapper, tableNames);
        List<HistoryHourly> datas = multiTableQuery(mapParams, tableNames);
        return datas;
    }
    @Override
    public List<HistoryHourly> getValueByMacAndTime(List<String> mac, Date startDate, Date endDate) {
        QueryWrapper<HistoryHourly> wrapper = new QueryWrapper<>();
        wrapper.in("mac", mac);
        wrapper.between("time", startDate, endDate);
        Map<String, Object> mapParams = new HashMap<>();
        mapParams.put("startDate",startDate);
        mapParams.put("endDate",endDate);
        mapParams.put("macs",mac);
        List<String> tableNames = MybatisPLUSUtils.getTableNamesByWrapper(startDate, endDate, SeparateTableType.MONTH);
        List<HistoryHourly> datas = multiTableQuery(wrapper, tableNames);
        List<HistoryHourly> datas = multiTableQuery(mapParams, tableNames);
        return datas;
    }
    @Override
    public List<HistoryHourly> getValueByMacs(List<String> macs, String time) {
        QueryWrapper<HistoryHourly> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("time", "value")
                .likeRight("time", time)
                .in("mac", macs);
        Map<String, Object> mapParams = new HashMap<>();
        mapParams.put("time",time);
        mapParams.put("macs",macs);
        Date date = DateUtils.getDate(time, DateUtils.yyyy_MM_dd_EN);
        List<String> tableNames = MybatisPLUSUtils.getTableNamesByWrapper(date, date, SeparateTableType.MONTH);
        return multiTableQuery(queryWrapper, tableNames);
        return multiTableQueryLike(mapParams, tableNames);
    }
    @Override
    public List<HistoryHourly> getHourlyDataByMacs(List<String> macs, String time) {
        QueryWrapper<HistoryHourly> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("mac","time", "value")
                .likeRight("time", time)
                .in("mac", macs);
        Map<String, Object> mapParams = new HashMap<>();
        mapParams.put("time",time);
        mapParams.put("macs",macs);
        Date date = DateUtils.getDate(time, DateUtils.yyyy_MM_dd_EN);
        List<String> tableNames = MybatisPLUSUtils.getTableNamesByWrapper(date, date, SeparateTableType.MONTH);
        return multiTableQuery(queryWrapper, tableNames);
        return multiTableQueryLike(mapParams, tableNames);
    }
    @Override
@@ -848,14 +849,22 @@
     * @Author: 陈凯裕
     * @Date: 2021/9/23
     */
    private List<HistoryHourly> multiTableQuery(QueryWrapper<HistoryHourly> wrapper, List<String> tableNames) {
    private List<HistoryHourly> multiTableQuery(Map<String, Object> params, List<String> tableNames) {
        List<HistoryHourly> result = new ArrayList<>();
        for (String tableName : tableNames) {
            MybatisPlusConfig.tableName.set(tableName);
            List<HistoryHourly> datas = historyHourlyMapper.selectList(wrapper);
            params.put("table",tableName);
            List<HistoryHourly> datas = historyHourlyMapper.listResult(params);
            result.addAll(datas);
        }
        MybatisPlusConfig.tableName.remove();
        return result;
    }
    private List<HistoryHourly> multiTableQueryLike(Map<String, Object> params, List<String> tableNames) {
        List<HistoryHourly> result = new ArrayList<>();
        for (String tableName : tableNames) {
            params.put("table",tableName);
            List<HistoryHourly> datas = historyHourlyMapper.listLikeResult(params);
            result.addAll(datas);
        }
        return result;
    }
screen-api/src/main/resources/mapper/HistoryHourlyMapper.xml
@@ -104,4 +104,22 @@
        order by time desc
    </select>
    <select id="listLikeResult" resultType="com.moral.api.entity.HistoryHourly">
        SELECT mac,time,value,version FROM history_hourly${table}
        WHERE 1 =1
        <if test="macs != null and macs.size!=0">
            and mac in
            <foreach collection="macs" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
        </if>
        <if test="mac != null and mac != ''">
            and mac = #{mac}
        </if>
        and time like concat(#{time},'%')
        order by time desc
    </select>
</mapper>