123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- package com.ruoyi.qdtl.service.impl;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.convert.Convert;
- import cn.hutool.core.date.DateUtil;
- import cn.hutool.core.util.NumberUtil;
- import cn.hutool.core.util.ObjectUtil;
- import cn.hutool.json.JSONObject;
- import com.ruoyi.common.utils.DateUtils;
- import com.ruoyi.qdtl.domain.TlInspectionLocationLog;
- import com.ruoyi.qdtl.domain.UserCheckPoint;
- import com.ruoyi.qdtl.mapper.TlInspectionLocationLogMapper;
- import com.ruoyi.qdtl.service.ITlInspectionLocationLogService;
- import org.gavaghan.geodesy.Ellipsoid;
- import org.gavaghan.geodesy.GeodeticCalculator;
- import org.gavaghan.geodesy.GlobalCoordinates;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- /**
- * 巡检记录管理Service业务层处理
- *
- * @author ruoyi
- * @date 2022-03-10
- */
- @Service
- public class TlInspectionLocationLogServiceImpl implements ITlInspectionLocationLogService {
- @Autowired
- private TlInspectionLocationLogMapper tlInspectionLocationLogMapper;
- /**
- * 查询巡检记录管理
- *
- * @param id 巡检记录管理主键
- * @return 巡检记录管理
- */
- @Override
- public TlInspectionLocationLog selectTlInspectionLocationLogById(Long id) {
- return tlInspectionLocationLogMapper.selectTlInspectionLocationLogById(id);
- }
- /**
- * 查询巡检记录管理列表
- *
- * @param tlInspectionLocationLog 巡检记录管理
- * @return 巡检记录管理
- */
- @Override
- public List<TlInspectionLocationLog> selectTlInspectionLocationLogList(TlInspectionLocationLog tlInspectionLocationLog) {
- return tlInspectionLocationLogMapper.selectTlInspectionLocationLogList(tlInspectionLocationLog);
- }
- @Override
- public List<TlInspectionLocationLog> selectTlInspectionLocationLogTrailList(TlInspectionLocationLog tlInspectionLocationLog) {
- return tlInspectionLocationLogMapper.selectTlInspectionLocationLogTrailList(tlInspectionLocationLog);
- }
- /**
- * 新增巡检记录管理
- *
- * @param tlInspectionLocationLog 巡检记录管理
- * @return 结果
- */
- @Override
- public int insertTlInspectionLocationLog(TlInspectionLocationLog tlInspectionLocationLog) {
- if (ObjectUtil.isNull(tlInspectionLocationLog.getCreateTime())) {
- tlInspectionLocationLog.setCreateTime(DateUtils.getNowDate());
- }
- return tlInspectionLocationLogMapper.insertTlInspectionLocationLog(tlInspectionLocationLog);
- }
- /**
- * 修改巡检记录管理
- *
- * @param tlInspectionLocationLog 巡检记录管理
- * @return 结果
- */
- @Override
- public int updateTlInspectionLocationLog(TlInspectionLocationLog tlInspectionLocationLog) {
- return tlInspectionLocationLogMapper.updateTlInspectionLocationLog(tlInspectionLocationLog);
- }
- /**
- * 批量删除巡检记录管理
- *
- * @param ids 需要删除的巡检记录管理主键
- * @return 结果
- */
- @Override
- public int deleteTlInspectionLocationLogByIds(Long[] ids) {
- return tlInspectionLocationLogMapper.deleteTlInspectionLocationLogByIds(ids);
- }
- /**
- * 删除巡检记录管理信息
- *
- * @param id 巡检记录管理主键
- * @return 结果
- */
- @Override
- public int deleteTlInspectionLocationLogById(Long id) {
- return tlInspectionLocationLogMapper.deleteTlInspectionLocationLogById(id);
- }
- @Override
- public Date queryMaxDate() {
- return tlInspectionLocationLogMapper.queryMaxDate();
- }
- @Override
- public List<TlInspectionLocationLog> queryByCondition(String date, String checkpointCard, String deviceId) {
- return tlInspectionLocationLogMapper.queryByCondition(date, checkpointCard, deviceId);
- }
- /**
- * 根据人员统计巡检次数
- *
- * @return
- */
- @Override
- public List<UserCheckPoint> queryUserGroup() {
- return tlInspectionLocationLogMapper.queryUserGroup();
- }
- /**
- * 查询经纬度非空的轨迹list数据
- *
- * @param date
- * @return
- */
- @Override
- public List<TlInspectionLocationLog> selectListByDate(String date) {
- return tlInspectionLocationLogMapper.selectListByDate(date);
- }
- @Override
- public double queryDistance(String date, String deviceId) {
- List<TlInspectionLocationLog> deviceTrails = this.selectListByDate(date);
- // 对轨迹按照设备编码分组
- Map<String, List<TlInspectionLocationLog>> deviceTrail = deviceTrails.stream().collect(Collectors.groupingBy(TlInspectionLocationLog::getDeviceCode));
- // 对每一个设备循环累计里程
- double distance = 0;
- for (Map.Entry<String, List<TlInspectionLocationLog>> stringListEntry : deviceTrail.entrySet()) {
- List<TlInspectionLocationLog> origin = stringListEntry.getValue();
- if (origin.size() < 2) {
- continue;
- }
- // 对原始list分成2组list,一个去掉头节点,一个去掉尾节点
- List<TlInspectionLocationLog> subPre = CollUtil.sub(origin, 0, origin.size() - 1);
- List<TlInspectionLocationLog> subAfter = CollUtil.sub(origin, 1, origin.size());
- for (int i = 0; i < subPre.size(); i++) {
- String fencePre = subPre.get(i).getFence();
- String fenceAfter = subAfter.get(i).getFence();
- // 计算2点之间距离
- GlobalCoordinates source = new GlobalCoordinates(Convert.toDouble(fencePre.split(",")[1]), Convert.toDouble(fencePre.split(",")[0]));
- GlobalCoordinates target = new GlobalCoordinates(Convert.toDouble(fenceAfter.split(",")[1]), Convert.toDouble(fenceAfter.split(",")[0]));
- // 创建GeodeticCalculator,调用计算方法
- double ellipsoidalDistance = new GeodeticCalculator().calculateGeodeticCurve(Ellipsoid.WGS84, source, target).getEllipsoidalDistance();
- distance = NumberUtil.add(distance, ellipsoidalDistance);
- }
- }
- return NumberUtil.div(distance, 1000, 3);
- }
- @Override
- public List<JSONObject> queryDistanceByDateRange(String startDate, String endDate) {
- List<TlInspectionLocationLog> locationLogList = tlInspectionLocationLogMapper.queryDistanceByDateRange(startDate, endDate);
- // 解析根据日期分组
- Map<String, List<TlInspectionLocationLog>> collect = locationLogList.stream().collect(Collectors.groupingBy(a -> DateUtil.formatDate(a.getCreateTime())));
- List<JSONObject> result = new ArrayList<>();
- for (Map.Entry<String, List<TlInspectionLocationLog>> stringListEntry : collect.entrySet()) {
- double distance = 0;
- List<TlInspectionLocationLog> origin = stringListEntry.getValue();
- if (origin.size() < 2) {
- continue;
- }
- // 对原始list分成2组list,一个去掉头节点,一个去掉尾节点
- List<TlInspectionLocationLog> subPre = CollUtil.sub(origin, 0, origin.size() - 1);
- List<TlInspectionLocationLog> subAfter = CollUtil.sub(origin, 1, origin.size());
- for (int i = 0; i < subPre.size(); i++) {
- String fencePre = subPre.get(i).getFence();
- String fenceAfter = subAfter.get(i).getFence();
- // 计算2点之间距离
- GlobalCoordinates source = new GlobalCoordinates(Convert.toDouble(fencePre.split(",")[1]), Convert.toDouble(fencePre.split(",")[0]));
- GlobalCoordinates target = new GlobalCoordinates(Convert.toDouble(fenceAfter.split(",")[1]), Convert.toDouble(fenceAfter.split(",")[0]));
- // 创建GeodeticCalculator,调用计算方法
- double ellipsoidalDistance = new GeodeticCalculator().calculateGeodeticCurve(Ellipsoid.WGS84, source, target).getEllipsoidalDistance();
- distance = NumberUtil.add(distance, ellipsoidalDistance);
- }
- JSONObject jb = new JSONObject();
- jb.set("date", stringListEntry.getKey());
- jb.set("week", DateUtil.dayOfWeekEnum(DateUtil.parseDate(stringListEntry.getKey())).toChinese("周"));
- jb.set("distance", NumberUtil.div(distance, 1000, 3));
- result.add(jb);
- }
- return CollUtil.sortByProperty(result, "date");
- }
- }
|