jinpengyong
2023-11-10 c8cc61e84189d8f986f7c4657d543408021b3da0
Merge branch 'dev' of http://blit.7drlb.com:8888/r/moral into wb
1 files added
7 files modified
313 ■■■■■ changed files
screen-api/src/main/java/com/moral/api/controller/CruiserController.java 4 ●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/impl/UserServiceImpl.java 66 ●●●●● patch | view | raw | blame | history
screen-common/src/main/java/com/moral/util/TokenUtils.java 6 ●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/mapper/HistorySecondCruiserMapper.java 3 ●●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/pojo/dto/cruiser/CruiserListDTO.java 35 ●●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/service/impl/HistorySecondCruiserServiceImpl.java 103 ●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/service/impl/ManageCoordinateDetailServiceImpl.java 46 ●●●●● patch | view | raw | blame | history
screen-manage/src/main/resources/mapper/HistorySecondCruiserMapper.xml 50 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/controller/CruiserController.java
@@ -242,10 +242,6 @@
        if (!params.containsKey("mac") || !params.containsKey("startTime") || !params.containsKey("endTime")){
            return;
        }
        System.out.println(CruiserController.class.getResource("/word/尘负荷监测报告.docx").getPath());
        URL resource = getClass().getResource("/word/尘负荷监测报告.docx");
        String path = resource.getPath();
        System.out.println(path);
        Map<String, Object> map = dustldService.dailyDustlds(params);
        if (ObjectUtils.isEmpty(map)){
            throw new BusinessException("未找到路段信息");
screen-api/src/main/java/com/moral/api/service/impl/UserServiceImpl.java
@@ -23,6 +23,7 @@
import com.moral.api.service.ResponsibilityUnitService;
import com.moral.api.service.UserService;
import com.moral.api.utils.OperationLogUtils;
import com.moral.api.utils.StringUtils;
import com.moral.api.utils.WechatUtils;
import com.moral.api.vo.WxMssVo;
import com.moral.constant.Constants;
@@ -116,6 +117,27 @@
        }
        ResponsibilityUnit responsibilityUnit = responsibilityUnitMapper.selectById(userBo.getUnitId());
        List<Integer> list = responsibilityUnitMapper.selectCodeList(SysDictTypeEnum.SYS_DEVICE.value, userBo.getId());
        result.put("userName", userBo.getUserName());
        result.put("unitId",userBo.getUnitId());
        result.put("userId", userBo.getId());
        result.put("account", userBo.getAccount());
        List<FileVo> listFile =  fileTableService.list(userBo.getId(), FileTableEnum.APP_ALLOCATION.value);
        result.put("file", CollectionUtils.isNotEmpty(listFile)?listFile.get(0):new FileVo());
        result.put("unName",Objects.nonNull(responsibilityUnit)&&Objects.nonNull(responsibilityUnit.getUnitName())?responsibilityUnit.getUnitName():"管理员登陆");
        result.put("device",ObjectUtils.isEmpty(list)? StateEnum.NOT_EFFECTIVE.value :StateEnum.TAKE_EFFECT.value);
        String userIdStr = new StringBuffer("00").append(userBo.getId().toString()).toString();
        String tokenResult = TokenUtils.getTokenById(userIdStr);
        if(StringUtils.isNotEmpty(tokenResult)){
            result.put("token", tokenResult);
            result.put("code", ResponseCodeEnum.SUCCESS.getCode());
            result.put("msg", ResponseCodeEnum.SUCCESS.getMsg());
            sysLog("登陆了用户:" + userBo.getAccount()+" ;openId:"+openId,userBo);
            //添加openId到user表中
            User user = userMapper.selectById(userBo.getId());
            user.setOpenId(openId);
            userMapper.updateById(user);
            return result;
        }
        //封装用户信息
        Map<String, Object> userInfo = new LinkedHashMap<>();
        userInfo.put("userId", userBo.getId());
@@ -135,14 +157,7 @@
            //生成token,并存入redis
            String token = TokenUtils.getTokenApp(new StringBuffer("00").append(userBo.getId().toString()).toString(),userInfo);
            result.put("token", token);
            result.put("userName", userBo.getUserName());
            result.put("unitId",userBo.getUnitId());
            result.put("userId", userBo.getId());
            result.put("account", userBo.getAccount());
            List<FileVo> listFile =  fileTableService.list(userBo.getId(), FileTableEnum.APP_ALLOCATION.value);
            result.put("file", CollectionUtils.isNotEmpty(listFile)?listFile.get(0):new FileVo());
            result.put("unName",Objects.nonNull(responsibilityUnit)&&Objects.nonNull(responsibilityUnit.getUnitName())?responsibilityUnit.getUnitName():"管理员登陆");
            result.put("device",ObjectUtils.isEmpty(list)? StateEnum.NOT_EFFECTIVE.value :StateEnum.TAKE_EFFECT.value);
        } catch (Exception e) {
            log.error("token生成异常:" + e.getMessage());
            result.put("code", ResponseCodeEnum.TOKEN_CREATE_ERROR.getCode());
@@ -191,7 +206,26 @@
//            String nickName = rawDataJson.getString("nickName");
//            String avatarUrl = rawDataJson.getString("avatarUrl");
        }
        String userIdStr = new StringBuffer("00").append(user.getId().toString()).toString();
        String tokenResult = TokenUtils.getTokenById(userIdStr);
        result.put("userName", user.getUserName());
        result.put("unitId",user.getUnitId());
        List<FileVo> listFile =  fileTableService.list(user.getId(), FileTableEnum.APP_ALLOCATION.value);
        result.put("file", CollectionUtils.isNotEmpty(listFile)?listFile.get(0):new FileVo());
        result.put("userId", user.getId());
        result.put("account", user.getAccount());
        ResponsibilityUnit responsibilityUnit = responsibilityUnitMapper.selectById(user.getUnitId());
        List<Integer> list = responsibilityUnitMapper.selectCodeList(SysDictTypeEnum.SYS_DEVICE.value, user.getId());
        result.put("device",ObjectUtils.isEmpty(list)? StateEnum.NOT_EFFECTIVE.value : StateEnum.TAKE_EFFECT.value);
        result.put("unName",Objects.nonNull(responsibilityUnit)&&Objects.nonNull(responsibilityUnit.getUnitName())?responsibilityUnit.getUnitName():"管理员登陆");
        result.put("openId",openid);
        if(StringUtils.isNotEmpty(tokenResult)){
            result.put("token", tokenResult);
            result.put("code", ResponseCodeEnum.SUCCESS.getCode());
            result.put("msg", ResponseCodeEnum.SUCCESS.getMsg());
            sysLog("登陆了用户:" + user.getAccount()+" ;openId:"+openid,user);
            return result;
        }
        Map<String, Object> userInfo = new LinkedHashMap<>();
        userInfo.put("userId", user.getId());
        userInfo.put("account", user.getAccount());
@@ -204,21 +238,13 @@
        userInfo.put("wechat", user.getWechat());
        userInfo.put("expireTime", DateUtils.dateToDateString(user.getExpireTime()));
        userInfo.put("isAdmin", user.getIsAdmin());
        ResponsibilityUnit responsibilityUnit = responsibilityUnitMapper.selectById(user.getUnitId());
        List<Integer> list = responsibilityUnitMapper.selectCodeList(SysDictTypeEnum.SYS_DEVICE.value, user.getId());
        try {
            //生成token,并存入redis
            String token = TokenUtils.getTokenApp(new StringBuffer("00").append(user.getId().toString()).toString(),userInfo);
            result.put("token", token);
            result.put("userName", user.getUserName());
            result.put("unitId",user.getUnitId());
            List<FileVo> listFile =  fileTableService.list(user.getId(), FileTableEnum.APP_ALLOCATION.value);
            result.put("file", CollectionUtils.isNotEmpty(listFile)?listFile.get(0):new FileVo());
            result.put("userId", user.getId());
            result.put("account", user.getAccount());
            result.put("device",ObjectUtils.isEmpty(list)? StateEnum.NOT_EFFECTIVE.value : StateEnum.TAKE_EFFECT.value);
            result.put("unName",Objects.nonNull(responsibilityUnit)&&Objects.nonNull(responsibilityUnit.getUnitName())?responsibilityUnit.getUnitName():"管理员登陆");
            result.put("openId",openid);
        } catch (Exception e) {
            log.error("token生成异常:" + e.getMessage());
            result.put("code", ResponseCodeEnum.TOKEN_CREATE_ERROR.getCode());
screen-common/src/main/java/com/moral/util/TokenUtils.java
@@ -197,7 +197,11 @@
     * @Date: 2021/5/21
     */
    public static String getTokenById(Integer id) {
         return (String)redisTemplate.opsForHash().get("user_token", String.valueOf(id));
         return (String) getTokenById(id.toString());
    }
    public static String getTokenById(String id) {
        return (String)redisTemplate.opsForHash().get("user_token", String.valueOf(id));
    }
screen-manage/src/main/java/com/moral/api/mapper/HistorySecondCruiserMapper.java
@@ -6,6 +6,7 @@
import com.moral.api.entity.HistorySecondCruiser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.moral.api.pojo.dto.cruiser.CruiserDTO;
import com.moral.api.pojo.dto.cruiser.CruiserListDTO;
/**
 * <p>
@@ -19,4 +20,6 @@
    List<CruiserDTO> getCruiserInfo(Map<String,Object> params);
    List<CruiserListDTO> cruiserList(Map<String,Object> params);
}
screen-manage/src/main/java/com/moral/api/pojo/dto/cruiser/CruiserListDTO.java
New file
@@ -0,0 +1,35 @@
package com.moral.api.pojo.dto.cruiser;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.Objects;
@Data
public class CruiserListDTO {
    /**
     * 数据时间
     */
    private String time;
    /**
     * 纬度
     */
    private Double flyLat;
    /**
     * 经度
     */
    private Double flyLon;
    private Integer coordinateId;
    private Integer id;
    private Integer state;
}
screen-manage/src/main/java/com/moral/api/service/impl/HistorySecondCruiserServiceImpl.java
@@ -2,6 +2,7 @@
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.api.entity.HistorySecondCruiser;
import com.moral.api.entity.ManageCoordinateDetail;
import com.moral.api.entity.Sensor;
@@ -10,28 +11,20 @@
import com.moral.api.mapper.ManageCoordinateDetailMapper;
import com.moral.api.mapper.SpecialDeviceMapper;
import com.moral.api.pojo.dto.cruiser.CruiserDTO;
import com.moral.api.service.DeviceService;
import com.moral.api.pojo.dto.cruiser.CruiserListDTO;
import com.moral.api.service.HistorySecondCruiserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.api.service.SpecialDeviceService;
import com.moral.api.util.RoadUtils;
import com.moral.constant.Constants;
import com.moral.constant.RedisConstants;
import com.moral.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import java.sql.Wrapper;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -172,82 +165,34 @@
    @Override
    public Map<String, Object> getCruiserCompare(Map<String, Object> params) {
        HashMap<String,Object> rsMap = new HashMap<>();
        String mac = params.get("mac").toString();
        String time1 = params.get("time1").toString();
        List<CruiserListDTO> list = historySecondCruiserMapper.cruiserList(params);
        List<CruiserDTO> cruiserInfo = new ArrayList<>();
        ArrayList<ManageCoordinateDetail> rsList1 = new ArrayList<>();
        params.put("dateFormat", "%Y-%m-%d %H:%i:%s");
        List<ManageCoordinateDetail> manageCoordinateDetails = manageCoordinateDetailMapper.selectList(null);
        List<CruiserDTO> cruiserInfo = (List<CruiserDTO>) redisTemplate.opsForHash().get(RedisConstants.DATE_COORDINATE, mac + time1);
        if (ObjectUtils.isEmpty(cruiserInfo)){
            cruiserInfo = historySecondCruiserMapper.getCruiserInfo(params);
            cruiserInfo = cruiserInfo.stream().distinct().collect(Collectors.toList());
            cruiserInfo.removeIf(o->{
                if (ObjectUtils.isEmpty(o.getFlyLon()) || ObjectUtils.isEmpty(o.getFlyLat())) {
                    return true;
                }
                double lon = o.getFlyLon();
                double lat = o.getFlyLat();
                double[] doubles = RoadUtils.transformWGS84ToBD09(lon, lat);
                Matcher matcher = Pattern.compile("\\d*\\.\\d{8}").matcher(""+doubles[0]);
                matcher.find();
                String s = matcher.group();
                Matcher matcher1 = Pattern.compile("\\d*\\.\\d{8}").matcher(""+doubles[1]);
                matcher1.find();
                String s1 = matcher1.group();
                o.setFlyLon(Double.parseDouble(s));
                o.setFlyLat(Double.parseDouble(s1));
                o.setData(lon+"_"+lat);
//            o.setFlyLon(doubles[0]);
//            o.setFlyLat(doubles[1]);
                if (lon < 70 || lon > 150 || lat < 20 || lat > 60) {
                    return true;
                }
                return false;
            });
            redisTemplate.opsForHash().put(RedisConstants.DATE_COORDINATE,mac+time1,cruiserInfo);
            //设置过期时间
            redisTemplate.opsForHash().getOperations().expire(RedisConstants.DATE_COORDINATE,6000, TimeUnit.SECONDS);
        }
//        List<CruiserDTO> cruiserInfo = historySecondCruiserMapper.getCruiserInfo(params);
        log.info(""+cruiserInfo.size());
        if (ObjectUtils.isEmpty(manageCoordinateDetails)){
            rsMap.put("rsData",cruiserInfo);
            rsMap.put("data",rsList1);
            return rsMap;
        }
        for (int i=cruiserInfo.size()-1;i>0;i--) {
            CruiserDTO cruiserDTO = cruiserInfo.get(i);
            String data = cruiserDTO.getData();
            String[] rs = data.split("_");
            String flyLon = rs[0];
            String flyLat = rs[1];
//            double lonDouble = Double.parseDouble(flyLon);
//            double latDouble = Double.parseDouble(flyLat);
            for (ManageCoordinateDetail manageCoordinateDetail : manageCoordinateDetails) {
                String latitude = manageCoordinateDetail.getLatitude().toString();
                String longitude = manageCoordinateDetail.getLongitude().toString();
//                double lonDouble1 = Double.parseDouble(longitude);
//                double latDouble1 = Double.parseDouble(latitude);
//                if (latDouble1==latDouble && lonDouble==lonDouble1){
                    if (flyLon.equals(longitude) && flyLat.equals(latitude)){
                    manageCoordinateDetail.setCode(data);
                    manageCoordinateDetail.setLongitude(cruiserDTO.getFlyLon());
                    manageCoordinateDetail.setLatitude(cruiserDTO.getFlyLat());
                    rsList1.add(manageCoordinateDetail);
                    cruiserInfo.remove(i);
                    break;
                }
        for(CruiserListDTO c : list){
            String date = new StringBuilder().append(c.getFlyLon()).append("_").append(c.getFlyLat()).toString();
            if(c.getState().equals(0)){
                CruiserDTO cruiserDTO = new CruiserDTO();
                cruiserDTO.setTime(c.getTime());
                cruiserDTO.setFlyLat(c.getFlyLat());
                cruiserDTO.setFlyLon(c.getFlyLon());
                cruiserDTO.setData(date);
                cruiserDTO.setState("1");
                cruiserInfo.add(cruiserDTO);
            }else {
                ManageCoordinateDetail detail = new ManageCoordinateDetail();
                detail.setId(c.getId());
                detail.setCoordinateId(c.getCoordinateId());
                detail.setLongitude(c.getFlyLon());
                detail.setLatitude(c.getFlyLat());
                detail.setState(c.getState().toString());
                detail.setCode(date);
                rsList1.add(detail);
            }
        }
        rsMap.put("rsData",cruiserInfo);
        rsMap.put("data",rsList1);
        rsMap.put("message","有"+cruiserInfo.size()+"个不在里面,"+"一共有"+(cruiserInfo.size()+rsList1.size())+"个");
        return rsMap;
    }
}
screen-manage/src/main/java/com/moral/api/service/impl/ManageCoordinateDetailServiceImpl.java
@@ -18,6 +18,7 @@
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
@@ -225,35 +226,24 @@
                log.info(j+"");
            }
        }else {
            for (int i=cruiserInfo.size()-1;i>0;i--) {
                CruiserDTO cruiserDTO = cruiserInfo.get(i);
                Double flyLat = cruiserDTO.getFlyLat();
                Double flyLon = cruiserDTO.getFlyLon();
                for (ManageCoordinateDetail manageCoordinateDetail : manageCoordinateDetails) {
                    String latitude = manageCoordinateDetail.getLatitude().toString();
                    String longitude = manageCoordinateDetail.getLongitude().toString();
//                    double lonDouble1 = Double.parseDouble(longitude);
//                    double latDouble1 = Double.parseDouble(latitude);
//                    if (lonDouble1==flyLon && flyLat==latDouble1 ){
                    if (longitude.equals(flyLon+"") && latitude.equals(flyLat+"")){
                        cruiserInfo.remove(i);
                        break;
                    }
                }
            }
            Map<String,Integer> map = new HashMap<>(manageCoordinateDetails.size()+50);
            manageCoordinateDetails.forEach(it->map.put(it.getLatitude()+"_"+it.getLongitude(),it.getId()));
            List<ManageCoordinateDetail> result = new ArrayList<>();
            for (CruiserDTO cruiserDTO : cruiserInfo) {
                Double flyLat = cruiserDTO.getFlyLat();
                Double flyLon = cruiserDTO.getFlyLon();
                ManageCoordinateDetail rsDTO = new ManageCoordinateDetail();
                rsDTO.setLatitude(flyLat);
                rsDTO.setLongitude(flyLon);
                rsDTO.setState("2");
                rsDTO.setCreateTime(new Date());
                rsDTO.setUpdateTime(new Date());
                rsDTO.setCoordinateId(coordinateId);
                manageCoordinateDetailMapper.insert(rsDTO);
                j++;
                log.info(j+"");
                String fly = cruiserDTO.getFlyLat()+"_"+cruiserDTO.getFlyLon();
               if(!map.containsKey(fly)){
                   ManageCoordinateDetail rsDTO = new ManageCoordinateDetail();
                   rsDTO.setLatitude(cruiserDTO.getFlyLat());
                   rsDTO.setLongitude(cruiserDTO.getFlyLon());
                   rsDTO.setState("2");
                   rsDTO.setCreateTime(new Date());
                   rsDTO.setUpdateTime(new Date());
                   rsDTO.setCoordinateId(coordinateId);
                   result.add(rsDTO);
               }
            }
            if(!CollectionUtils.isEmpty(result)){
                this.saveBatch(result);
            }
        }
        return 200;
screen-manage/src/main/resources/mapper/HistorySecondCruiserMapper.xml
@@ -20,4 +20,54 @@
        order by time
    </select>
    <select id="cruiserList" resultType="com.moral.api.pojo.dto.cruiser.CruiserListDTO">
        WITH zb AS (
        SELECT
        DATE_FORMAT( `time`, '%Y-%m-%d %H:%i:%s' ) AS time,VALUE->> '$.flylat' AS flyLat,VALUE->> '$.flylon' AS flyLon
        FROM
        history_second_cruiser
        WHERE
        mac =  #{mac}
        AND `time` <![CDATA[>=]]> #{time1}
        AND `time` <![CDATA[<=]]> #{time2}
        ORDER BY
        time
        ),
        resultList AS (
        SELECT
        t1.time,
        t1.flyLat,
        t1.flyLon
        FROM
        zb t1
        INNER JOIN ( SELECT flyLon, flyLat, MAX( time ) AS max_time FROM zb GROUP BY flyLat, flyLon ) t2 ON t1.flyLon = t2.flyLon
        AND t1.flyLat = t2.flyLat
        AND t1.time = t2.max_time
        ),
        mx AS (
        SELECT t2.latitude,
            t2.longitude,
            t2.state,
            t2.coordinate_id ,max(t2.id) id
        FROM
        manage_coordinate t1
        LEFT JOIN manage_coordinate_detail t2 ON t1.coordinate_id = t2.coordinate_id
        LEFT JOIN special_device t3 ON t1.organization_id = t3.organization_id
        WHERE
        t1.is_del = 0
        AND t3.mac = #{mac} group by t2.latitude,
            t2.longitude,
            t2.state,
            t2.coordinate_id
        ) SELECT
        tt.time,
        tt.flyLat,
        tt.flyLon,
        COALESCE ( tt1.state, 0 ) AS state ,tt1.coordinate_id,tt1.id as id
        FROM
        resultList tt
        LEFT JOIN mx tt1 ON tt.flyLat = tt1.latitude
        AND tt.flyLon = tt1.longitude
    </select>
</mapper>