fuliqi
2024-07-29 5cb926178a929e34ff4fa3a4c0f4c351f976d1e7
车辆点位在线接口
4个文件已修改
107 ■■■■ 已修改文件
ycl-server/src/main/java/com/ycl/platform/mapper/CheckIndexCarMapper.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/java/com/ycl/platform/service/ICheckIndexCarService.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/java/com/ycl/platform/service/impl/CheckIndexCarServiceImpl.java 68 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/resources/mapper/zgyw/CheckIndexCarMapper.xml 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/java/com/ycl/platform/mapper/CheckIndexCarMapper.java
@@ -1,20 +1,21 @@
package com.ycl.platform.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ycl.platform.domain.entity.CheckIndexCar;
import java.util.List;
/**
 * 车辆指标概率数据Mapper接口
 *
 *
 * @author ruoyi
 * @date 2024-04-29
 */
public interface CheckIndexCarMapper
public interface CheckIndexCarMapper extends BaseMapper<CheckIndexCar>
{
    /**
     * 查询车辆指标概率数据
     *
     *
     * @param id 车辆指标概率数据主键
     * @return 车辆指标概率数据
     */
@@ -22,7 +23,7 @@
    /**
     * 查询车辆指标概率数据列表
     *
     *
     * @param checkIndexCar 车辆指标概率数据
     * @return 车辆指标概率数据集合
     */
@@ -30,7 +31,7 @@
    /**
     * 新增车辆指标概率数据
     *
     *
     * @param checkIndexCar 车辆指标概率数据
     * @return 结果
     */
@@ -38,7 +39,7 @@
    /**
     * 修改车辆指标概率数据
     *
     *
     * @param checkIndexCar 车辆指标概率数据
     * @return 结果
     */
@@ -46,7 +47,7 @@
    /**
     * 删除车辆指标概率数据
     *
     *
     * @param id 车辆指标概率数据主键
     * @return 结果
     */
@@ -54,9 +55,12 @@
    /**
     * 批量删除车辆指标概率数据
     *
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteCheckIndexCarByIds(Long[] ids);
    public List<CheckIndexCar> selectToday(String today);
}
ycl-server/src/main/java/com/ycl/platform/service/ICheckIndexCarService.java
@@ -1,5 +1,6 @@
package com.ycl.platform.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ycl.platform.domain.entity.CheckIndexCar;
import com.ycl.platform.domain.result.HK.SnapshotDataMonitorResult;
@@ -11,7 +12,7 @@
 * @author ruoyi
 * @date 2024-04-29
 */
public interface ICheckIndexCarService
public interface ICheckIndexCarService extends IService<CheckIndexCar>
{
    /**
     * 查询车辆指标概率数据
ycl-server/src/main/java/com/ycl/platform/service/impl/CheckIndexCarServiceImpl.java
@@ -1,24 +1,29 @@
package com.ycl.platform.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycl.platform.domain.entity.CalculateReport;
import com.ycl.platform.domain.entity.CheckIndexCar;
import com.ycl.platform.domain.entity.TMonitor;
import com.ycl.platform.domain.result.HK.SnapshotDataMonitorResult;
import com.ycl.platform.mapper.CalculateReportMapper;
import com.ycl.platform.mapper.CheckIndexCarMapper;
import com.ycl.platform.service.ICheckIndexCarService;
import com.ycl.platform.service.ITMonitorService;
import com.ycl.system.entity.SysDept;
import com.ycl.system.mapper.SysDeptMapper;
import constant.ApiConstants;
import constant.CheckConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import utils.DateUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -29,7 +34,8 @@
 * @date 2024-04-29
 */
@Service
public class CheckIndexCarServiceImpl implements ICheckIndexCarService {
@Slf4j
public class CheckIndexCarServiceImpl extends ServiceImpl<CheckIndexCarMapper, CheckIndexCar> implements ICheckIndexCarService {
    @Autowired
    private CheckIndexCarMapper checkIndexCarMapper;
    @Autowired
@@ -103,12 +109,14 @@
    public int deleteCheckIndexCarById(Long id) {
        return checkIndexCarMapper.deleteCheckIndexCarById(id);
    }
    /**
     * 计算车辆点位在线率、视图库对接稳定性
     *
     *  获取分省厅、区域的map<k,v> k为deptId或者Province_deptId
     *  循环map计算点位在线率
     *  更新或新增
     * @param list
     */
    //TODO:视图库对接稳定性
    @Override
    public void siteOnline(List<SnapshotDataMonitorResult> list) {
        //设备id
@@ -130,7 +138,7 @@
            deptIds.forEach(deptId -> areaStatsMap.put(deptId + "", new AreaStats()));
            //转换为map
            //TODO:分省厅市局
            //TODO:分省厅市局  需要补充集合数据
            List<String> provinceIds = new ArrayList<>();
            Map<String, TMonitor> monitorMap = monitors.stream().collect(Collectors.toMap(TMonitor::getSerialNumber, Function.identity()));
            for (SnapshotDataMonitorResult result : list) {
@@ -158,23 +166,55 @@
                            provinceStats.offlineSites++;
                        } else {
                            //区域总抓拍量
                            provinceStats.totalSites += result.getDataCount();
                            provinceStats.totalDataSum += result.getDataCount();
                        }
                        //区域点位总数
                        provinceStats.totalDataSum++;
                        provinceStats.totalSites++;
                        areaStatsMap.put("Province_" + monitor.getDeptId(), areaStats);
                    }
                }
                areaStatsMap.put(monitor.getDeptId() + "", areaStats);
            }
            List<CheckIndexCar> checkIndexCarList = checkIndexCarMapper.selectToday(DateUtils.getDate());
            List<CheckIndexCar> checkIndexCars = new ArrayList<>();
            areaStatsMap.forEach((k, v) -> {
                if (k.startsWith("Province_")) {
                if (v.totalSites == 0) {
                    log.info("部门id为{}总点位数为0", k);
                } else {
                    CheckIndexCar checkIndexCar = new CheckIndexCar();
                    //找是否已经存在数据
                    Optional<CheckIndexCar> first;
                    if (k.startsWith("Province_")) {
                        //省厅
                        String[] idArray = k.split("_");
                        first = checkIndexCarList.stream().filter(item -> idArray[1].equals(item.getDeptId() + "") && CheckConstants.Examine_Tag_City.equals(item.getExamineTag()))
                                .findFirst();
                        checkIndexCar.setExamineTag(CheckConstants.Examine_Tag_City);
                        checkIndexCar.setDeptId(Long.parseLong(idArray[1]));
                    } else {
                        //区县
                        first = checkIndexCarList.stream().filter(item -> k.equals(item.getDeptId() + "") && CheckConstants.Examine_Tag_County.equals(item.getExamineTag()))
                                .findFirst();
                        checkIndexCar.setExamineTag(CheckConstants.Examine_Tag_County);
                        checkIndexCar.setDeptId(Long.parseLong(k));
                    }
                    checkIndexCar.setCreateTime(new Date());
                    if (first.isPresent()) {
                        checkIndexCar = first.get();
                    }
                    // 将整数转换为BigDecimal
                    BigDecimal totalSitesBd = new BigDecimal(v.totalSites);
                    BigDecimal offlineSitesBd = new BigDecimal(v.offlineSites);
                    // 执行计算,保留四位小数并四舍五入
                    BigDecimal onlineSitesBd = totalSitesBd.subtract(offlineSitesBd);
                    BigDecimal siteOnline = onlineSitesBd.divide(totalSitesBd, 4, RoundingMode.HALF_UP);
                    checkIndexCar.setSiteOnline(siteOnline);
                    checkIndexCars.add(checkIndexCar);
                }
            });
            CheckIndexCar checkIndexCar = new CheckIndexCar();
            saveOrUpdateBatch(checkIndexCars);
        }
    }
}
ycl-server/src/main/resources/mapper/zgyw/CheckIndexCarMapper.xml
@@ -3,7 +3,7 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ycl.platform.mapper.CheckIndexCarMapper">
    <resultMap type="com.ycl.platform.domain.entity.CheckIndexCar" id="CheckIndexCarResult">
        <result property="id"    column="id"    />
        <result property="deptId"    column="dept_id"    />
@@ -28,7 +28,7 @@
    <select id="selectCheckIndexCarList"  resultMap="CheckIndexCarResult">
        select tcic.*,sd.dept_name
        from t_check_index_car tcic left join sys_dept sd on tcic.dept_id = sd.dept_id
        <where>
        <where>
            <if test="deptId != null "> and tcic.dept_id = #{deptId}</if>
            <if test="examineTag != null "> and examine_tag = #{examineTag}</if>
            <if test="date != null "> and  date_format(tcic.create_time,'%Y-%m') = #{date}</if>
@@ -50,12 +50,12 @@
            </if>
        </where>
    </select>
    <select id="selectCheckIndexCarById" resultMap="CheckIndexCarResult">
        <include refid="selectCheckIndexCarVo"/>
        where id = #{id}
    </select>
    <insert id="insertCheckIndexCar"  useGeneratedKeys="true" keyProperty="id">
        insert into t_check_index_car
        <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -115,9 +115,13 @@
    </delete>
    <delete id="deleteCheckIndexCarByIds">
        delete from t_check_index_car where id in
        delete from t_check_index_car where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
    <select id="selectToday">
        select * from t_check_index_car where DATE(create_time) = #{today}
    </select>
</mapper>