cjl
2024-03-28 33b9d2c203a9998272088ecdf43a15dd53669967
screen-api/src/main/java/com/moral/api/service/impl/SpecialDeviceServiceImpl.java
@@ -3,22 +3,24 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moral.api.config.Interceptor.UserHelper;
import com.moral.api.entity.*;
import com.moral.api.mapper.DailyMapper;
import com.moral.api.mapper.HistorySecondCruiserMapper;
import com.moral.api.mapper.SpecialDeviceMapper;
import com.moral.api.mapper.SysDictTypeMapper;
import com.moral.api.pojo.bo.ExcelBO;
import com.moral.api.pojo.dto.historySecondCruiser.HistorySecondCruiserListDTO;
import com.moral.api.pojo.dto.historySecondCruiser.HistorySecondCruiserResultCountDTO;
import com.moral.api.pojo.dto.historySecondCruiser.HistorySecondCruiserResultDTO;
import com.moral.api.pojo.enums.SysDictTypeEnum;
import com.moral.api.pojo.vo.device.AppDeviceVo;
import com.moral.api.pojo.vo.excel.DailyVo;
import com.moral.api.pojo.vo.user.QxUser;
import com.moral.api.service.OrganizationService;
import com.moral.api.service.SpecialDeviceHistoryService;
import com.moral.api.service.SpecialDeviceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.api.service.SysAreaService;
import com.moral.api.service.SysDictTypeService;
import com.moral.constant.Constants;
@@ -27,7 +29,6 @@
import com.moral.util.FileUtils;
import com.moral.util.GeodesyUtils;
import com.moral.util.TokenUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -35,9 +36,7 @@
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.math.BigDecimal;
import java.text.ParseException;
@@ -83,6 +82,9 @@
    @Autowired
    RedisTemplate redisTemplate;
    @Autowired
    private SysAreaService sysAreaService;
    private final static Double dis = 50d;
@@ -110,9 +112,10 @@
        orgIds.add(orgId);
        integerList.addAll(orgIds);
        QueryWrapper<SpecialDeviceHistory> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("mac", "name")
        queryWrapper.select("DISTINCT mac, name").lambda();
                //.eq("special_type", Constants.SPECIAL_DEVICE_CRUISER)
                .eq("is_delete", Constants.NOT_DELETE)
        queryWrapper.eq("is_delete", Constants.NOT_DELETE)
                .in("organization_id", integerList);
        return specialDeviceHistoryService.listMaps(queryWrapper);
    }
@@ -206,7 +209,7 @@
                    });
                }
            }else {
                BigDecimal dataValue = Objects.nonNull(list.getDataValue())?BigDecimal.valueOf(Integer.parseInt(list.getDataValue())):BigDecimal.ZERO;
                BigDecimal dataValue = Objects.nonNull(list.getDataValue())?BigDecimal.valueOf(Double.parseDouble(list.getDataValue())):BigDecimal.ZERO;
                result.forEach(it->{
                    it.setAvgNum(it.getAvgNum().add(dataValue));
                });
@@ -220,8 +223,8 @@
    private BigDecimal numAvg(List<String> list , BigDecimal num){
        int nums = 1;
        for (int i=0;i<list.size();i=i+2){
            if(num.compareTo(BigDecimal.valueOf(Integer.parseInt(list.get(i))))>= 0 ){
                return num.add(BigDecimal.valueOf(Integer.parseInt(list.get(nums))));
            if(num.compareTo(BigDecimal.valueOf(Double.parseDouble(list.get(i))))>= 0 ){
                return num.add(BigDecimal.valueOf(Double.parseDouble(list.get(i+1))));
            }
            nums+=2;
        }
@@ -323,10 +326,11 @@
        String type = params.get("type").toString();
        String code = params.get("code").toString();
        String area = params.get("area").toString();
        String mac = params.get("mac").toString();
        rsMap.put("area",area);
        rsMap.put("mac",mac.substring(9));
        String value = JSON.toJSONString(rsMap);
        String mac = params.get("mac").toString();
        QueryWrapper<TbDaily> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("mac",mac);
        queryWrapper.likeRight("time",time1.substring(0,10));
@@ -442,29 +446,40 @@
    /**
     * 下载走航车日报
     * @param id
     * @param ids
     * @return
     */
    @Override
    public DailyVo loadDaily(Integer id) {
        ArrayList<String> rsList = new ArrayList<>();
        DailyVo dailyVo = new DailyVo();
        TbDaily tbDaily = dailyMapper.selectById(id);
        if (tbDaily==null){
            return null;
    public List<DailyVo> loadDaily(List<Integer> ids) {
        ArrayList<DailyVo> dailyVos = new ArrayList<>();
        for (Integer id : ids) {
            ArrayList<String> rsList = new ArrayList<>();
            DailyVo dailyVo = new DailyVo();
            TbDaily tbDaily = dailyMapper.selectById(id);
            SysArea areaByCode = sysAreaService.getAreaByCode(Integer.parseInt(tbDaily.getCode()));
            if (tbDaily==null){
                continue;
            }
            String images = tbDaily.getImages();
            if (!ObjectUtils.isEmpty(images)){
                String[] split = images.split(",");
                List<String> list1 = Arrays.asList(split);
                dailyVo.setImages(list1);
            }else {
                dailyVo.setImages(rsList);
            }
            String value = tbDaily.getValue();
            Map map = JSON.parseObject(value, Map.class);
            List<String> list = (List<String>) map.get("time");
            String join = String.join("-", list);
            map.put("time",join);
            dailyVo.setCode(map);
            dailyVo.setName(areaByCode.getAreaName());
            dailyVo.setType(tbDaily.getType().equals("car")?"走航车":"无人机");
            dailyVos.add(dailyVo);
        }
        String images = tbDaily.getImages();
        if (!ObjectUtils.isEmpty(images)){
            String[] split = images.split(",");
            List<String> list1 = Arrays.asList(split);
            dailyVo.setImages(list1);
        }else {
            dailyVo.setImages(rsList);
        }
        String value = tbDaily.getValue();
        Map map = JSON.parseObject(value, Map.class);
        dailyVo.setCode(map);
        return dailyVo;
        return dailyVos;
    }
    /**
@@ -482,9 +497,11 @@
        Object mac = params.get("mac");
        if (!ObjectUtils.isEmpty(mac)){
            String MAC = mac.toString();
            String[] split = mac.toString().split(",");
            List<String> list = Arrays.asList(split);
            List<String> macList = new ArrayList<>(new TreeSet<>(list));
            QueryWrapper<TbDaily> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("type",type).eq("code",code).eq("mac",MAC);
            queryWrapper.eq("type",type).eq("code",code).in("mac",macList);
            queryWrapper.between("time",startTime,endTime);
            List<TbDaily> dailies = dailyMapper.selectList(queryWrapper);
            for (TbDaily daily : dailies) {
@@ -504,6 +521,20 @@
            excelBOS.add(excelBO);
        }
        return excelBOS;
    }
    @Override
    public List<AppDeviceVo> selectSpecialDevice() {
        QxUser user = UserHelper.getCurrentUser();
        Integer organizationId = user.getOrganizationId();
//        Integer organizationId=71;
        List<AppDeviceVo> appDeviceVos;
        if (organizationId!=24){
            appDeviceVos = specialDeviceMapper.selectSpecialDevice(organizationId);
        }else {
            appDeviceVos = specialDeviceMapper.selectSpecialDevice(null);
        }
        return appDeviceVos;
    }
    //计算平均值和最大值
@@ -732,4 +763,35 @@
    }
    /**
     *
     */
      private double getDivisor(String code,double num){
          double rs = 0.0;
        if (code.contains("-")){
            String data = code.substring(1);
            rs = num - Double.parseDouble(data);
        } else if (code.contains("*")){
            String data = code.substring(1);
            rs = num * Double.parseDouble(data);
        } else if (code.contains("/")){
            String data = code.substring(1);
            rs = num / Double.parseDouble(data);
        } else if (code.contains(",")){
            String[] split = code.split(",");
            for (String s : split) {
                String[] split1 = s.split("<");
                double sp1 = Double.parseDouble(split1[0]);
                double sp2 = Double.parseDouble(split1[1]);
                double sp3 = Double.parseDouble(split1[2]);
                if (num>=sp1 && num<=sp2){
                    rs = num + sp3;
                }
            }
        }else {
            rs = num + Double.parseDouble(code);
        }
        return rs;
      }
}