Commit 35696775 by 杨林龙

假性离线需求开发

1 parent e4de820c
Showing 36 changed files with 892 additions and 41 deletions
package cn.com.glsx.admin.common.enums;
import com.glsx.plat.exception.SystemMessage;
/**
* @author Yanglinlong
* @date 2022/3/11 18:07
*/
public enum FakeOfficeReasonEnum {
WHITELIST(1, "纳入离线白名单数据"),
SINGLE_OFFLINE(2, "车辆多设备组合单离线"),
RESIDENCE(3, "常驻地中【家庭/工作】地址离线");
private final Integer code;
private final String message;
FakeOfficeReasonEnum(Integer code, String message) {
this.code = code;
this.message = message;
}
FakeOfficeReasonEnum(SystemMessage systemMessage) {
this.code = systemMessage.getCode();
this.message = systemMessage.getMsg();
}
public static String getMessageByCode(Integer code) {
for (FakeOfficeReasonEnum reasonEnum : FakeOfficeReasonEnum.values()) {
if (reasonEnum.getCode().equals(code)) {
return reasonEnum.getMessage();
}
}
return null;
}
public Integer getCode() {
return code;
}
public String getMessage() {
return message;
}
}
......@@ -75,6 +75,39 @@ public class TypeConverseEunm {
}
/**
* 设备有源无源枚举类
*/
public enum SourceStatusEnum {
NO_SOURCE(0, "无线"),
HAS_SOURCE(1, "有线");
private final Integer sourceType;
private final String sourceTypeStr;
SourceStatusEnum(Integer sourceType, String sourceTypeStr) {
this.sourceType = sourceType;
this.sourceTypeStr = sourceTypeStr;
}
public static String getStrBySourceType(Integer sourceType) {
for (SourceEnum sourceEnum : SourceEnum.values()) {
if (sourceEnum.getSourceType().equals(sourceType)) {
return sourceEnum.getSourceTypeStr();
}
}
return null;
}
public Integer getSourceType() {
return sourceType;
}
public String getSourceTypeStr() {
return sourceTypeStr;
}
}
/**
* 设备时候在线枚举类
*/
public enum OnLineEnum {
......@@ -111,7 +144,7 @@ public class TypeConverseEunm {
* 报警类型枚举类
*/
public enum AlarmTypeEnum {
// BLACK_ZONE_ALARM(1, "黑区报警"),
// BLACK_ZONE_ALARM(1, "黑区报警"),
BLACK_ZONE_ALARM(3, "黑区报警"),
ABNORMAL_AGGREGATION_ALARM(2, "异常聚集报警"),
SECOND_AREA_ALARM(4, "二押区域报警");
......
......@@ -36,6 +36,7 @@ public class WebConfig implements WebMvcConfigurer {
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
registry.addResourceHandler("/templates/**").addResourceLocations("classpath:/templates/importVehicle.xlsx");
registry.addResourceHandler("/templates/**").addResourceLocations("classpath:/templates/importVehicleInfo.xlsx");
registry.addResourceHandler("/templates/**").addResourceLocations("classpath:/templates/importWriteListSn.xlsx");
}
}
\ No newline at end of file
package cn.com.glsx.admin.modules.controller;
import cn.com.glsx.admin.modules.model.export.FakeOfficeExport;
import cn.com.glsx.admin.modules.model.export.JudgmentExport;
import cn.com.glsx.admin.modules.model.imports.BaseImportInfo;
import cn.com.glsx.admin.modules.model.imports.WhiteListSnImport;
import cn.com.glsx.admin.modules.model.imports.WhiteListSnImportListener;
import cn.com.glsx.admin.modules.model.param.FakeOfficeSearch;
import cn.com.glsx.admin.modules.service.DeviceService;
import cn.com.glsx.admin.modules.service.FakeOfflineService;
import cn.com.glsx.admin.modules.service.VehicleService;
import cn.com.glsx.admin.modules.utils.FdfsUtils;
import cn.com.glsx.admin.modules.utils.fileupload.FileConstants;
import cn.com.glsx.admin.modules.utils.fileupload.FileUploadServerData;
import cn.com.glsx.admin.modules.utils.fileupload.FileUploadUtil;
import com.alibaba.excel.EasyExcel;
import com.github.pagehelper.PageInfo;
import com.glsx.plat.core.web.R;
import com.glsx.plat.office.excel.EasyExcelUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.List;
/**
* 假性离线Controller
*
* @author Yanglinlong
* @date 2022/3/10 19:46
*/
@Slf4j
@RestController
@RequestMapping(value = "/fakeoffline")
@Api(value = "假性离线", tags = {"假性离线"})
public class FakeOfflineController {
@Autowired
private FakeOfflineService fakeOfflineService;
@Autowired
private VehicleService vehicleService;
@Autowired
private DeviceService deviceService;
@GetMapping("/search")
@ApiOperation(value = "查询假性离线报表")
public R<List<FakeOfficeExport>> search(FakeOfficeSearch fakeOfficeSearch) {
PageInfo pageInfo = fakeOfflineService.search(fakeOfficeSearch);
return R.ok().putPageData(pageInfo);
}
@GetMapping("/export")
@ApiOperation(value = "导出假性离线报表")
public R<String> export(FakeOfficeSearch fakeOfficeSearch) {
String fileName = FdfsUtils.getFileName("假性离线导出报表");
List<FakeOfficeExport> fakeOfficeList = fakeOfflineService.export(fakeOfficeSearch);
// 将文件写入内存流 然后上传到文件服务器 返回文件服务器的地址给前端 前端执行下载
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
EasyExcelUtils.writeExcel(outputStream, fakeOfficeList, fileName, JudgmentExport.class);
FileUploadServerData uploadServerData = FileUploadUtil.uploadToFileSystem(fileName, outputStream.toByteArray(), FileConstants.EXCEL_TYPE_XLSX);
return R.ok().data(uploadServerData.getSecureUrl());
}
@GetMapping(value = "/downloadtemplate")
@ApiOperation(value = "下载白名单导入模板")
public R<String> downloadTemplate() throws Exception {
InputStream inputStream = FakeOfflineController.class.getResourceAsStream("/templates/importWriteListSn.xlsx");
String fileName = "导入白名单模板";
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
FileCopyUtils.copy(inputStream, outputStream);
FileUploadServerData uploadServerData = FileUploadUtil.uploadToFileSystem(fileName, outputStream.toByteArray(), FileConstants.EXCEL_TYPE_XLSX);
return R.ok().data(uploadServerData.getSecureUrl());
}
@PostMapping(value = "/import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@ApiOperation(value = "导入假性离线报表")
public R importWriteList(@RequestParam("file") MultipartFile file) throws Exception {
WhiteListSnImportListener listener = new WhiteListSnImportListener(vehicleService, deviceService, fakeOfflineService);
EasyExcel.read(file.getInputStream(), WhiteListSnImport.class, listener)
.head(WhiteListSnImport.class)
.ignoreEmptyRow(false)
.sheet().doRead();
BaseImportInfo importInfo = listener.getBaseImportInfo();
return R.ok().data(importInfo);
}
// @ApiOperation(value = "查询车辆位置信息接口")
// @GetMapping("/location")
// public R<List<FakeOfficeLocationBo>> fakeOfflineLocation(String vin, String deviceCode) {
// List<FakeOfficeLocationBo> fakeOfficeLocationBos = null;
// return R.ok().data(fakeOfficeLocationBos);
// }
}
package cn.com.glsx.admin.modules.entity; import com.glsx.plat.mybatis.base.BaseEntity;import lombok.Data;import lombok.experimental.Accessors; import javax.persistence.Table;import java.sql.Date; /** * 假性离线围栏数据 * * @author yangll */@Data@Accessors(chain = true)@Table(name = "t_fake_offline_fence_sn")public class FakeOfflineFenceSn extends BaseEntity { /** * 设备号 */ private String sn; /** * 是否在家庭围栏或者工作围栏内, 1表是在围栏内, 2表示不在围栏内 */ private Integer status; /** * 围栏类型: 1.家庭所在地围栏 2.工作所在地围栏 */ private Integer merchantType; /** * 进围栏时间 */ private Date entryTime; /** * 出围栏时间 */ private Date outTime;}
\ No newline at end of file
package cn.com.glsx.admin.modules.entity; import com.glsx.plat.mybatis.base.BaseEntity;import lombok.Data;import lombok.experimental.Accessors; import javax.persistence.Table; /** * 假性离线车架号数据 * * @author yangll */@Data@Accessors(chain = true)@Table(name = "t_fake_offline_vin")public class FakeOfflineVin extends BaseEntity { /** * 车架号 */ private String vin; /** * 是否是假性离线车架号, 1表是假性离线车架号, 2表示不是假性离线车架号 */ private Integer status;}
\ No newline at end of file
package cn.com.glsx.admin.modules.entity; import com.glsx.plat.mybatis.base.BaseEntity;import lombok.Data;import lombok.experimental.Accessors; import javax.persistence.Table; /** * 假性离线设备号白名单 * * @author yangll */@Data@Accessors(chain = true)@Table(name = "t_whitelist_sn")public class WhitelistSn extends BaseEntity { /** * 车架号 */ private String vin; /** * 设备号 */ private String sn; /** * 部门id */ private Long departmentId;}
\ No newline at end of file
package cn.com.glsx.admin.modules.mapper;
import cn.com.glsx.admin.modules.entity.FakeOfflineFenceSn;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* mapper
*/
@Mapper
public interface FakeOfflineFenceSnMapper extends CommonBaseMapper<FakeOfflineFenceSn> {
}
\ No newline at end of file
package cn.com.glsx.admin.modules.mapper;
import cn.com.glsx.admin.modules.entity.FakeOfflineVin;
import cn.com.glsx.admin.modules.model.export.FakeOfficeExport;
import cn.com.glsx.admin.modules.model.param.FakeOfficeSearch;
import com.glsx.plat.common.annotation.DataPerm;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
import java.util.Map;
/**
* mapper
*
* @author yangll
*/
@Mapper
public interface FakeOfflineVinMapper extends CommonBaseMapper<FakeOfflineVin> {
/**
* 通过权限获取通过家庭围栏或者工作围栏计算的假性离线车架号
*
* @return 返回假性离线车架号集合
*/
@DataPerm(permTable = "tfov", showSql = true)
List<String> getFakeOfflineVinByFence();
/**
* 根据权限获取车辆绑定设备数Map
*
* @return
*/
@DataPerm(permTable = "tv", showSql = true)
List<Map<String, Integer>> getVehicleNumMap();
/**
* 根据权限获取车架绑定设备离线数Map
*
* @return
*/
@DataPerm(permTable = "tv", showSql = true)
List<Map<String, Integer>> getOfflineVehicleNumMap();
/**
* 查询假性离线数据集合
*
* @param search
* @return
*/
@DataPerm(permTable = "tv", showSql = true)
List<FakeOfficeExport> searchFakeOfficeList(FakeOfficeSearch search);
}
\ No newline at end of file
......@@ -252,4 +252,18 @@ public interface VehicleMapper extends CommonBaseMapper<Vehicle> {
List<Vehicle> selectByOrderIds(@Param("orderIds") Collection<Long> orderIds);
/**
* 获取车辆和设备绑定关系
*
* @return
*/
List<Map<String, String>> getVehicleAndDeviceMap();
/**
* 根据权限获取该用户下面的车架号
*
* @return
*/
@DataPerm(showSql = true)
List<String> getVehicleByPermission();
}
\ No newline at end of file
package cn.com.glsx.admin.modules.mapper;
import cn.com.glsx.admin.modules.entity.WhitelistSn;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Set;
/**
* mapper
*
* @author yangll
*/
@Mapper
public interface WhitelistSnMapper extends CommonBaseMapper<WhitelistSn> {
/**
* 通过部门Id获取白名单数据
*
* @param departmentId 部门Id
* @return
*/
List<WhitelistSn> selectAllByDepartmentId(@Param("departmentId") Long departmentId);
/**
* 通过部门ID删除白名单设备号
*
* @param departmentId 部门id
*/
void logicDeleteSnByDepartmentId(@Param("departmentId") Long departmentId);
/**
* 获取白名单车架号
*
* @param deptIds 可以看见的部门Id
* @return
*/
List<String> getWriteListVin(@Param("deptIds") Set<Long> deptIds);
}
\ No newline at end of file
package cn.com.glsx.admin.modules.model;
import cn.com.glsx.devicemonitor.api.dto.response.DeviceLocationDTO;
import lombok.Data;
/**
* 假性离线查询定位信息实体类
*
* @author Yanglinlong
* @date 2022/3/10 20:27
*/
@Data
public class FakeOfficeLocationBo extends DeviceLocationDTO {
/**
* 车架号
*/
private String vin;
/**
* 车主姓名
*/
private String ownerName;
}
package cn.com.glsx.admin.modules.model.export;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* @author Yanglinlong
* @date 2022/3/10 20:13
*/
@Data
@Accessors(chain = true)
public class FakeOfficeExport {
/**
* 业务工单号
*/
@ExcelProperty(value = "业务工单号", index = 0)
private String bizOrderNo;
/**
* 姓名
*/
@ExcelProperty(value = "姓名", index = 1)
private String ownerName;
/**
* 设备号
*/
@ExcelProperty(value = "设备号", index = 2)
private String sns;
/**
* 车架号
*/
@ExcelProperty(value = "车架号", index = 3)
private String vin;
/**
* 假性离线原因
*/
@ExcelProperty(value = "假性离线原因", index = 4)
private String reason;
}
package cn.com.glsx.admin.modules.model.export;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* @author Yanglinlong
* @date 2022/3/10 20:15
*/
@Data
@Accessors(chain = true)
public class WhiteListFailExport {
/**
* 车架号
*/
@ExcelProperty(value = "车架号", index = 0)
private String vin;
/**
* 设备号
*/
@ExcelProperty(value = "设备号", index = 1)
private String sn;
/**
* 原因
*/
@ExcelProperty(value = "原因", index = 2)
private String reason;
}
......@@ -19,7 +19,7 @@ public class BaseImportInfo {
private int total;
/**
* 失败文件序列号
* 失败文件服务器地址
*/
private String failFile;
......
package cn.com.glsx.admin.modules.model.imports;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* @author Yanglinlong
* @date 2022/3/10 20:15
*/
@Data
@Accessors(chain = true)
public class WhiteListSnImport {
/**
* 车架号
*/
@ExcelProperty(value = "车架号", index = 0)
private String vin;
/**
* 设备号
*/
@ExcelProperty(value = "设备号", index = 1)
private String sn;
}
......@@ -3,10 +3,12 @@ package cn.com.glsx.admin.modules.model.param;
import cn.hutool.db.Page;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.List;
@Data
@Accessors(chain = true)
public class BasicSearch extends Page {
/**
......
......@@ -23,11 +23,6 @@ public class CommonTearDownSearch extends BasicSearch {
private String alarmEndTime;
/**
* 车辆归属组织Id
*/
private Long orgId;
/**
* 设备|工单号|车架号|姓名
*/
private String keywords;
......
......@@ -34,12 +34,6 @@ public class DeviceActiveSearch extends BasicSearch {
private Integer isOnLine;
/**
* 车辆归属组织Id
*/
@ApiModelProperty(value = "车辆归属组织Id")
private Long orgId;
/**
* 设备号|工单号|车架号|姓名
*/
@ApiModelProperty(value = "设备号|工单号|车架号|姓名")
......
package cn.com.glsx.admin.modules.model.param;
import cn.hutool.db.Page;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.List;
/**
* 假性离线搜索参数实体类
*
* @author Yanglinlong
* @date 2022/3/10 20:11
*/
@Data
@Accessors(chain = true)
public class FakeOfficeSearch extends BasicSearch {
/**
* 搜索的关键字 设备号|车架号|姓名|业务工单号
*/
@ApiModelProperty(value = "设备号|车架号|姓名|业务工单号")
private String keywords;
/**
* 车辆归属组织Id
*/
@ApiModelProperty(value = "组织Id")
private Long orgId;
/**
* 车辆集合
*/
private List<String> vinList;
}
......@@ -42,11 +42,6 @@ public class FinalPositioningSearch extends BasicSearch {
private String finalBsTimeEnd;
/**
* 组织Id
*/
private Long orgId;
/**
* 设备类型 GPS/有线 GPS/无线 OBD/OBD (该字段由t_device中的deviceType和source用 - 拼接而成)
*/
private String deviceTypeAndSource;
......
......@@ -13,11 +13,6 @@ import lombok.Data;
public class JourneyDailySearch extends BasicSearch {
/**
* 组织Id
*/
private Long orgId;
/**
* 工单号|车架号|姓名|设备号
*/
private String keywords;
......
......@@ -2,6 +2,7 @@ package cn.com.glsx.admin.modules.model.param;
import com.glsx.plat.common.utils.StringUtils;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* 行程详情查询实体
......@@ -9,6 +10,7 @@ import lombok.Data;
* @author yll
*/
@Data
@Accessors(chain = true)
public class JourneyDetailSearch extends BasicSearch {
/**
* 行程开始时间
......
......@@ -4,10 +4,6 @@ import lombok.Data;
@Data
public class JourneySearch extends BasicSearch {
/**
* 组织Id
*/
private Long orgId;
/**
* 工单号|车架号|姓名|设备号
......
......@@ -37,12 +37,6 @@ public class JudgmentSearch extends BasicSearch {
private Integer alarmStatus;
/**
* 车辆归属 组织Id
*/
@ApiModelProperty(name = "车辆归属", notes = "组织Id")
private Long orgId;
/**
* 工单号|车架号|姓名|设备号
*/
@ApiModelProperty(name = "工单号|车架号|姓名|设备号")
......
......@@ -47,11 +47,6 @@ public class OfflineSearch extends BasicSearch {
private Integer source;
/**
* 车辆归属组织Id
*/
private Long orgId;
/**
* 工单号|车架号|姓名
*/
private String keywords;
......
......@@ -16,7 +16,4 @@ public class WorkOrderSearch extends BasicSearch {
private String serviceType;
private Integer orderStatus;
private String term;
private Long orgId;
}
package cn.com.glsx.admin.modules.remote;
import cn.com.glsx.devicemonitor.api.dto.response.DeviceSearchDTO;
import cn.com.glsx.devicemonitor.api.dto.response.DeviceStatusModel;
import cn.com.glsx.devicemonitor.api.feign.DeviceFeignService;
import cn.hutool.json.JSONUtil;
import com.glsx.plat.core.web.R;
import com.google.common.collect.Maps;
import com.google.gson.reflect.TypeToken;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @author Yanglinlong
* @date 2022/3/11 18:32
*/
@Slf4j
@Service
public class RemoteFeignDeviceService {
@Autowired
private DeviceFeignService deviceFeignService;
public Map<String, DeviceStatusModel> listDeviceStatusBySns(Collection<String> sns) {
log.info("调用监控服务获取设备在线和离线的状态===" + JSONUtil.toJsonStr(sns));
DeviceSearchDTO deviceSearchDTO = new DeviceSearchDTO();
deviceSearchDTO.setSns(sns);
R<List<DeviceStatusModel>> listDeviceStatusBySnsR = deviceFeignService.listDeviceStatusBySns(deviceSearchDTO);
List<DeviceStatusModel> listDeviceStatusBySnsDataList = listDeviceStatusBySnsR.getDataList(new TypeToken<List<DeviceStatusModel>>() {
}.getType());
Map<String, DeviceStatusModel> deviceStatusBsDataMap = Maps.newHashMap();
if (CollectionUtils.isNotEmpty(listDeviceStatusBySnsDataList)) {
deviceStatusBsDataMap = listDeviceStatusBySnsDataList.stream().collect(Collectors.toMap(DeviceStatusModel::getSn, Function.identity(), (k1, k2) -> k2));
}
return deviceStatusBsDataMap;
}
}
package cn.com.glsx.admin.modules.service;
import cn.com.glsx.admin.common.constants.ConstantsDevice;
import cn.com.glsx.admin.common.enums.FakeOfficeReasonEnum;
import cn.com.glsx.admin.common.enums.TypeConverseEunm;
import cn.com.glsx.admin.modules.entity.WhitelistSn;
import cn.com.glsx.admin.modules.mapper.FakeOfflineFenceSnMapper;
import cn.com.glsx.admin.modules.mapper.FakeOfflineVinMapper;
import cn.com.glsx.admin.modules.mapper.WhitelistSnMapper;
import cn.com.glsx.admin.modules.model.export.FakeOfficeExport;
import cn.com.glsx.admin.modules.model.export.WhiteListFailExport;
import cn.com.glsx.admin.modules.model.imports.WhiteListSnImport;
import cn.com.glsx.admin.modules.model.param.FakeOfficeSearch;
import cn.com.glsx.admin.modules.remote.RemoteFeignDeviceService;
import cn.com.glsx.admin.modules.utils.FdfsUtils;
import cn.com.glsx.admin.modules.utils.fileupload.FileConstants;
import cn.com.glsx.admin.modules.utils.fileupload.FileUploadServerData;
import cn.com.glsx.admin.modules.utils.fileupload.FileUploadUtil;
import cn.com.glsx.auth.utils.ShieldContextHolder;
import cn.com.glsx.devicemonitor.api.dto.response.DeviceStatusModel;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.glsx.plat.office.excel.EasyExcelUtils;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.ByteArrayOutputStream;
import java.util.*;
/**
* 假性离线 service
*
* @author Yanglinlong
* @date 2022/3/10 19:46
*/
@Slf4j
@Service
public class FakeOfflineService extends AbstractCommonService {
@Autowired
private FakeOfflineFenceSnMapper fakeOfflineFenceSnMapper;
@Autowired
private FakeOfflineVinMapper fakeOfflineVinMapper;
@Autowired
private WhitelistSnMapper whitelistSnMapper;
@Autowired
private RemoteFeignDeviceService remoteFeignDeviceService;
/**
* 查询
*
* @param search
* @return
*/
public PageInfo search(FakeOfficeSearch search) {
// 处理用户选择部门的问题 将部门下面的用户根据角色权限查询出来
setOrgCheckedAuth(search);
// 获取假性离线车架号
Map<String, Integer> reasonMap = Maps.newHashMap();
List<String> vinList = getFakeOfficeVinList(reasonMap);
// 分页查询
Page<Object> page = PageHelper.startPage(search.getPageNumber(), search.getPageSize(), true);
search.setVinList(vinList);
List<FakeOfficeExport> fakeOfficeList = buildFakeOfficeResult(search, reasonMap);
return new PageInfo(fakeOfficeList, (int) page.getTotal());
}
/**
* 根据 车架号获取假性离线列表
*
* @param search 查询假性离线条件
* @param reasonMap 假性离线原因
* @return 返回假性离线列表
*/
public List<FakeOfficeExport> buildFakeOfficeResult(FakeOfficeSearch search, Map<String, Integer> reasonMap) {
List<FakeOfficeExport> fakeOfficeList = fakeOfflineVinMapper.searchFakeOfficeList(search);
for (FakeOfficeExport fakeOfficeExport : fakeOfficeList) {
String vin = fakeOfficeExport.getVin();
Integer code = reasonMap.get(vin);
if (FakeOfficeReasonEnum.WHITELIST.getCode().equals(code)) {
fakeOfficeExport.setReason(FakeOfficeReasonEnum.WHITELIST.getMessage());
} else if (FakeOfficeReasonEnum.RESIDENCE.getCode().equals(code)) {
fakeOfficeExport.setReason(FakeOfficeReasonEnum.RESIDENCE.getMessage());
} else if (FakeOfficeReasonEnum.SINGLE_OFFLINE.getCode().equals(code)) {
String sns = fakeOfficeExport.getSns();
String[] snArr = sns.split(",");
Map<String, DeviceStatusModel> deviceStatusMap = remoteFeignDeviceService.listDeviceStatusBySns(Arrays.asList(snArr));
StringBuilder builder = new StringBuilder("车辆多设备组合【");
for (String sn : snArr) {
DeviceStatusModel deviceStatusModel = deviceStatusMap.get(sn);
if (deviceStatusModel != null) {
Integer status = deviceStatusModel.getStatus();
if (status != null && ConstantsDevice.DEVICE_STATUS_OFFLINE == status) {
builder.append(sn).append("(").append(TypeConverseEunm.SourceStatusEnum.getStrBySourceType(deviceStatusModel.getSource())).append(") ");
}
}
}
builder.append("】设备离线");
fakeOfficeExport.setReason(builder.toString());
}
}
return fakeOfficeList;
}
/**
* 导出
*
* @param search
* @return
*/
public List<FakeOfficeExport> export(FakeOfficeSearch search) {
// 处理用户选择部门的问题 将部门下面的用户根据角色权限查询出来
setOrgCheckedAuth(search);
// 获取假性离线车架号
Map<String, Integer> reasonMap = Maps.newHashMap();
List<String> vinList = getFakeOfficeVinList(reasonMap);
search.setVinList(vinList);
return buildFakeOfficeResult(search, reasonMap);
}
/**
* 获取假性离线车架号
*
* @param reasonMap 原因 map
* @return 假性离线车架号
*/
public List<String> getFakeOfficeVinList(Map<String, Integer> reasonMap) {
List<String> vinList = Lists.newArrayList();
// 一 获取多设备单离线车架号
List<String> singleDeviceOfficeVinList = Lists.newArrayList();
// 获取车辆和设备绑定数量Map
Map<String, Integer> vehicleNumMap = Maps.newHashMap();
List<Map<String, Integer>> vehicleNumMapList = fakeOfflineVinMapper.getVehicleNumMap();
vehicleNumMapList.forEach(vehicleNumMap::putAll);
Map<String, Integer> offlineVehicleNumMap = Maps.newHashMap();
List<Map<String, Integer>> offlineVehicleNumMapList = fakeOfflineVinMapper.getOfflineVehicleNumMap();
offlineVehicleNumMapList.forEach(offlineVehicleNumMap::putAll);
for (Map.Entry<String, Integer> stringIntegerEntry : offlineVehicleNumMap.entrySet()) {
String vin = stringIntegerEntry.getKey();
Integer num = vehicleNumMap.get(vin);
// 如果设备绑定总数和车辆上的设备离线数不同 则是假性离线
if (!stringIntegerEntry.getValue().equals(num)) {
singleDeviceOfficeVinList.add(vin);
}
}
singleDeviceOfficeVinList.forEach(vin -> reasonMap.put(vin, FakeOfficeReasonEnum.SINGLE_OFFLINE.getCode()));
vinList.addAll(singleDeviceOfficeVinList);
// 二 获取设备都离线 最后定位点在家庭围栏或者工作地围栏 获取车架通过权限控制
List<String> fakeOfflineVinByFenceList = fakeOfflineVinMapper.getFakeOfflineVinByFence();
fakeOfflineVinByFenceList.forEach(vin -> reasonMap.put(vin, FakeOfficeReasonEnum.RESIDENCE.getCode()));
vinList.addAll(fakeOfflineVinByFenceList);
// 三 获取本部门以及下级部门
Set<Long> deptIds = ShieldContextHolder.getVisibleDeptIds();
// 从白名单列表获取白名单设备号及其车架号
List<String> writeListVinList = whitelistSnMapper.getWriteListVin(deptIds);
writeListVinList.forEach(vin -> reasonMap.put(vin, FakeOfficeReasonEnum.WHITELIST.getCode()));
vinList.addAll(writeListVinList);
return vinList;
}
/**
* 批量导入假性离线设备号入库
*
* @param whiteListSnImportList 假性离线白名单数据
*/
public void insertFakeOfflineList(List<WhiteListSnImport> whiteListSnImportList) {
List<WhitelistSn> whitelistSnList = Lists.newArrayList();
for (WhiteListSnImport whiteListSnImport : whiteListSnImportList) {
WhitelistSn whitelistSn = new WhitelistSn();
whitelistSn.setVin(whiteListSnImport.getVin())
.setSn(whiteListSnImport.getSn())
.setDepartmentId(ShieldContextHolder.getDepartmentId())
.setCreatedBy(ShieldContextHolder.getUserId())
.setCreatedDate(new Date());
whitelistSnList.add(whitelistSn);
}
whitelistSnMapper.insertList(whitelistSnList);
}
/**
* 逻辑清空同部门下面的所有设备号
*/
public void cleanAllWriteListOnSameDepartment() {
// 根据部门Id获取所有白名单数据
whitelistSnMapper.logicDeleteSnByDepartmentId(ShieldContextHolder.getDepartmentId());
}
public String saveFakeOfflineFailData(List<WhiteListFailExport> failList) {
String fileName = FdfsUtils.getFileName("白名单导入失败列表");
// 将文件写入内存流 然后上传到文件服务器 返回文件服务器的地址给前端 前端执行下载
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
EasyExcelUtils.writeExcel(outputStream, failList, fileName, WhiteListFailExport.class);
FileUploadServerData uploadServerData = FileUploadUtil.uploadToFileSystem(fileName, outputStream.toByteArray(), FileConstants.EXCEL_TYPE_XLSX);
return uploadServerData.getSecureUrl();
}
}
......@@ -48,6 +48,7 @@ import com.glsx.plat.common.utils.TreeModelUtil;
import com.glsx.plat.context.utils.PropertiesUtils;
import com.glsx.plat.core.web.R;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gson.reflect.TypeToken;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.ConvertUtils;
......@@ -1910,4 +1911,19 @@ public class VehicleService {
return null;
}
/**
* 获取车辆和设备绑定关系的Map集合
*
* @return 车辆和设备绑定关系的 Map集合
*/
public Map<String, String> getVehicleAndDeviceMap() {
HashMap<String, String> hashMap = Maps.newHashMap();
List<Map<String, String>> vehicleAndDeviceMapList = vehicleMapper.getVehicleAndDeviceMap();
vehicleAndDeviceMapList.forEach(hashMap::putAll);
return hashMap;
}
public List<String> getVehicleByPermission() {
return vehicleMapper.getVehicleByPermission();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.glsx.admin.modules.mapper.FakeOfflineFenceSnMapper">
<resultMap id="BaseMap" type="cn.com.glsx.admin.modules.entity.FakeOfflineFenceSn">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="sn" property="sn" jdbcType="VARCHAR"/>
<result column="status" property="status" jdbcType="TINYINT"/>
<result column="merchant_type" property="merchantType" jdbcType="TINYINT"/>
<result column="entry_time" property="entryTime" jdbcType="TIMESTAMP"/>
<result column="out_time" property="outTime" jdbcType="TIMESTAMP"/>
<result column="del_flag" property="delFlag" jdbcType="TINYINT"/>
<result column="created_date" property="createdDate" jdbcType="TIMESTAMP"/>
<result column="created_by" property="createdBy" jdbcType="INTEGER"/>
<result column="updated_date" property="updatedDate" jdbcType="TIMESTAMP"/>
<result column="updated_by" property="updatedBy" jdbcType="INTEGER"/>
</resultMap>
<sql id="BaseColumns">
a.id, a.sn, a.status, a.merchant_type, a.entry_time, a.out_time, a.del_flag, a.created_date,
a.created_by, a.updated_date, a.updated_by
</sql>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.glsx.admin.modules.mapper.FakeOfflineVinMapper">
<resultMap id="BaseMap" type="cn.com.glsx.admin.modules.entity.FakeOfflineVin">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="vin" property="vin" jdbcType="VARCHAR"/>
<result column="status" property="status" jdbcType="TINYINT"/>
<result column="del_flag" property="delFlag" jdbcType="TINYINT"/>
<result column="created_date" property="createdDate" jdbcType="TIMESTAMP"/>
<result column="created_by" property="createdBy" jdbcType="INTEGER"/>
<result column="updated_date" property="updatedDate" jdbcType="TIMESTAMP"/>
<result column="updated_by" property="updatedBy" jdbcType="INTEGER"/>
</resultMap>
<sql id="BaseColumns">
a.id, a.vin, a.status, a.del_flag, a.created_date, a.created_by, a.updated_date,
a.updated_by
</sql>
<select id="getFakeOfflineVinByFence" resultType="String">
SELECT DISTINCT tfov.vin FROM t_fake_offline_vin tfov WHERE tfov.del_flag = 0 AND tfov.`status` = 1;
</select>
<select id="getVehicleNumMap" resultType="java.util.HashMap">
select tv.vin as vin,
count(1) as num
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
where tv.del_flag = 0
and tvd.bind_status = 1
and tvd.del_flag = 0
group by tv.vin;
</select>
<select id="getOfflineVehicleNumMap" resultType="java.util.HashMap">
select tv.vin as vin,
count(tdl.sn) as num
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_device td on td.sn = tvd.sn
left join t_device_location tdl on tdl.sn = td.sn
where tv.del_flag = 0
and tvd.bind_status = 1
and tvd.del_flag = 0
and ((timestampdiff(SECOND, tdl.last_gps_time, now()) > 259200 and
timestampdiff(SECOND, tdl.last_bs_time, now()) > 259200 and td.source = 1)
or (timestampdiff(SECOND, tdl.last_bs_time, now()) > 259200 and td.source = 0))
group by tv.vin;
</select>
<select id="searchFakeOfficeList">
select tw.partner_order_no bizOrderNo,
tv.owner_name ,
group_concat(tvd.sn) sns,
tv.vin as vin
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_device td on td.sn = tvd.sn
left join t_device_location tdl on tdl.sn = td.sn
left join t_workorder tw on tw.id = tv.workorder_id
where tv.del_flag = 0
and tvd.bind_status = 1
and tvd.del_flag = 0
and ((timestampdiff(SECOND, tdl.last_gps_time, now()) > 259200 and
timestampdiff(SECOND, tdl.last_bs_time, now()) > 259200 and td.source = 1)
or (timestampdiff(SECOND, tdl.last_bs_time, now()) > 259200 and td.source = 0))
and tv.vin in
<foreach collection="vinList" separator="," open="(" close=")" item="item">
#{item}
</foreach>
<if test="checkedUserIdsStr != null and checkedUserIdsStr !=''">
and find_in_set(tv.created_by,#{checkedUserIdsStr})
</if>
<if test="keywords != null and keywords !=''">
and(
tw.partner_order_no like '%${keywords}%'
or tv.vin like '%${keywords}%'
or tv.owner_name like '%${keywords}%'
or tvd.sn like '%${keywords}%'
)
</if>
group by tv.vin;
</select>
</mapper>
\ No newline at end of file
......@@ -958,4 +958,15 @@
#{item}
</foreach>
</select>
<select id="getVehicleAndDeviceMap" resultType="java.util.HashMap">
SELECT tv.vin ,GROUP_CONCAT(tvd.sn)
FROM t_vehicle tv LEFT JOIN t_vehicle_device tvd ON tvd.vehicle_id = tv.id
WHERE tv.del_flag = 0
GROUP BY tv.vin;
</select>
<select id="getVehicleByPermission" resultType="java.lang.String">
select distinct vin from t_vehicle where del_flag = 0;
</select>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.glsx.admin.modules.mapper.WhitelistSnMapper">
<resultMap id="BaseMap" type="cn.com.glsx.admin.modules.entity.WhitelistSn">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="vin" property="vin" jdbcType="VARCHAR"/>
<result column="sn" property="sn" jdbcType="VARCHAR"/>
<result column="department_id" property="departmentId" jdbcType="INTEGER"/>
<result column="del_flag" property="delFlag" jdbcType="TINYINT"/>
<result column="created_date" property="createdDate" jdbcType="TIMESTAMP"/>
<result column="created_by" property="createdBy" jdbcType="INTEGER"/>
<result column="updated_date" property="updatedDate" jdbcType="TIMESTAMP"/>
<result column="updated_by" property="updatedBy" jdbcType="INTEGER"/>
</resultMap>
<sql id="BaseColumns">
id, vin, sn, department_id, del_flag, created_date, created_by, updated_date, updated_by
</sql>
<select id="selectAllByDepartmentId" resultMap="BaseMap">
select
<include refid="BaseColumns"/>
from t_whitelist_sn
where department_id = #{departmentId} and del_flag = 0
</select>
<update id="logicDeleteSnByDepartmentId">
update t_whitelist_sn set del_flag = 1 where department_id = #{departmentId}
</update>
<select id="getWriteListVin" resultType="String">
SELECT DISTINCT vin FROM t_whitelist_sn WHERE department_id IN
<foreach collection="deptIds" separator="," open="(" close=")" item="item">
#{item}
</foreach>
</select>
</mapper>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!