@@ -155,6 +155,33 @@ | |||
<version>2.1.7</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.poi</groupId> | |||
<artifactId>poi</artifactId> | |||
<version>4.1.0</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.poi</groupId> | |||
<artifactId>poi-ooxml</artifactId> | |||
<version>4.1.0</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>net.sf.saxon</groupId> | |||
<artifactId>saxon-dom</artifactId> | |||
<version>8.7</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.skywalking</groupId> | |||
<artifactId>apm-toolkit-logback-1.x</artifactId> | |||
<version>9.0.0</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.skywalking</groupId> | |||
<artifactId>apm-toolkit-trace</artifactId> | |||
<version>9.0.0</version> | |||
</dependency> | |||
</dependencies> | |||
<!-- 环境变量配置 --> |
@@ -0,0 +1,32 @@ | |||
package com.tuoheng.admin.config; | |||
import org.springframework.context.annotation.Bean; | |||
import org.springframework.context.annotation.Configuration; | |||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | |||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | |||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | |||
/** | |||
* 解决跨域问题 | |||
* | |||
* @author wanjing | |||
* @team tuoheng | |||
* @date 2022-11-28 | |||
*/ | |||
@Configuration | |||
public class CORSConfig { | |||
@Bean | |||
public WebMvcConfigurer corsConfigurer() { | |||
return new WebMvcConfigurerAdapter() { | |||
@Override | |||
public void addCorsMappings(CorsRegistry registry) { | |||
registry.addMapping("/**") | |||
.allowedMethods("*") | |||
.allowedOrigins("*"); | |||
} | |||
}; | |||
} | |||
} |
@@ -124,4 +124,28 @@ public class InspectionFileController { | |||
log.info("进入修改问题类型接口, id={}, questionCode={}", id, questionCode); | |||
return iInspectionFileService.editQuestionType(id, questionCode); | |||
} | |||
/** | |||
* | |||
* 删除问题处理 | |||
* | |||
* @param idList | |||
* @return | |||
*/ | |||
@DeleteMapping("/delete/{idList}") | |||
public JsonResult deletedByIdList(@PathVariable("idList") List<String> idList) { | |||
return iInspectionFileService.deletedByIdList(idList); | |||
} | |||
/** | |||
* | |||
* 导出问题清单 | |||
* | |||
* @param idList | |||
* @return | |||
*/ | |||
@GetMapping("/export/{idList}") | |||
public JsonResult exportExcleByIdList(@PathVariable("idList") List<String> idList) { | |||
return iInspectionFileService.exportExcleByIdList(idList); | |||
} | |||
} |
@@ -0,0 +1,76 @@ | |||
package com.tuoheng.admin.controller; | |||
import com.tuoheng.admin.request.iotequipment.AddIotEquipmentRequest; | |||
import com.tuoheng.admin.request.iotequipment.EditIotEquipmentRequest; | |||
import com.tuoheng.admin.request.iotequipment.QueryIotEquipmentListRequest; | |||
import com.tuoheng.admin.request.iotequipment.QueryIotEquipmentPageListRequest; | |||
import com.tuoheng.admin.service.iotequipment.IotEquipmentService; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.RequiredArgsConstructor; | |||
import org.springframework.web.bind.annotation.*; | |||
/** | |||
* 物联设备前端控制器 | |||
* | |||
* @Author wanjing | |||
* @Date 2023-11-25 | |||
*/ | |||
@RestController | |||
@RequestMapping("/iot/equipment") | |||
@RequiredArgsConstructor | |||
public class IotEquipmentController { | |||
private final IotEquipmentService iotEquipmentService; | |||
/** | |||
* 查询物联设备分页列表 | |||
*/ | |||
@GetMapping("/page/list") | |||
public JsonResult getPageList(QueryIotEquipmentPageListRequest request) { | |||
return iotEquipmentService.getPageList(request); | |||
} | |||
/** | |||
* 查询物联设备列表 | |||
*/ | |||
@GetMapping("/list") | |||
public JsonResult getList(QueryIotEquipmentListRequest request) { | |||
return iotEquipmentService.getList(request); | |||
} | |||
/** | |||
* 获取物联设备信息 | |||
*/ | |||
@GetMapping(value = "/info/{id}") | |||
public JsonResult getInfo(@PathVariable("id") String id) { | |||
return iotEquipmentService.getInfo(id); | |||
} | |||
/** | |||
* 新增获取物联设备 | |||
* | |||
* @param request | |||
* @return | |||
*/ | |||
@PostMapping("/add") | |||
public JsonResult add(AddIotEquipmentRequest request) { | |||
return iotEquipmentService.add(request); | |||
} | |||
/** | |||
* 修改获取物联设备 | |||
*/ | |||
@PutMapping("/edit") | |||
public JsonResult edit(EditIotEquipmentRequest request) { | |||
return iotEquipmentService.edit(request); | |||
} | |||
/** | |||
* 删除获取物联设备 | |||
*/ | |||
@DeleteMapping("/delete/{id}") | |||
public JsonResult deletedById(@PathVariable("id") String id) { | |||
return iotEquipmentService.deletedById(id); | |||
} | |||
} |
@@ -1,5 +1,6 @@ | |||
package com.tuoheng.admin.conver; | |||
import com.tuoheng.admin.dto.InspectionFileExportExcelDto; | |||
import com.tuoheng.admin.entity.InspectionFile; | |||
import com.tuoheng.admin.entity.InspectionFileDistribution; | |||
import com.tuoheng.admin.entity.InspectionFileExtend; | |||
@@ -25,4 +26,5 @@ public interface InspectionFileConverMapper { | |||
List<InspectionFileReportVo> fromInspectionFileListToInspectionFileHandleVoList(List<InspectionFile> inspectionFileList); | |||
List<InspectionFileExportExcelDto> fromInspectionFileListToInspectionFileExportExcelDtoList(List<InspectionFile> inspectionFileList); | |||
} |
@@ -0,0 +1,24 @@ | |||
package com.tuoheng.admin.conver; | |||
import com.tuoheng.admin.entity.IotEquipment; | |||
import com.tuoheng.admin.request.iotequipment.AddIotEquipmentRequest; | |||
import com.tuoheng.admin.request.iotequipment.EditIotEquipmentRequest; | |||
import com.tuoheng.admin.vo.IotEquipmentVo; | |||
import org.mapstruct.Mapper; | |||
import org.mapstruct.factory.Mappers; | |||
import java.util.List; | |||
@Mapper | |||
public interface IotEquipmentConverMapper { | |||
IotEquipmentConverMapper INSTANCE = Mappers.getMapper(IotEquipmentConverMapper.class); | |||
List<IotEquipmentVo> fromIotEquipmentToIotEquipmentVoList(List<IotEquipment> iotEquipmentList); | |||
IotEquipmentVo fromIotEquipmentToIotEquipmentVo(IotEquipment iotEquipment); | |||
IotEquipment fromAddIotEquipmentToIotEquipment(AddIotEquipmentRequest request); | |||
IotEquipment fromEditIotEquipmentToIotEquipment(EditIotEquipmentRequest request); | |||
} |
@@ -0,0 +1,67 @@ | |||
package com.tuoheng.admin.dto; | |||
import com.alibaba.excel.annotation.ExcelProperty; | |||
import com.alibaba.excel.annotation.write.style.ColumnWidth; | |||
import com.alibaba.excel.annotation.write.style.ContentFontStyle; | |||
import com.alibaba.excel.annotation.write.style.ContentRowHeight; | |||
import com.alibaba.excel.annotation.write.style.HeadRowHeight; | |||
import com.alibaba.excel.converters.url.UrlImageConverter; | |||
import lombok.Data; | |||
import java.net.URL; | |||
@Data | |||
@HeadRowHeight(30) | |||
@ContentRowHeight(150) | |||
@ContentFontStyle() | |||
public class InspectionFileExportExcelDto { | |||
/** | |||
* 序号 | |||
*/ | |||
@ExcelProperty(value = {"列号"}, index = 0) | |||
private Integer sequence; | |||
/** | |||
* 问题类型 | |||
*/ | |||
@ExcelProperty(value = {"问题类型"}, index = 1) | |||
private String questionDesc; | |||
/** | |||
* 问题图片 | |||
*/ | |||
@ExcelProperty(value = {"问题图片"}, index = 2, converter = UrlImageConverter.class) | |||
private URL fileOriginal; | |||
/** | |||
* 标注图片 | |||
*/ | |||
@ExcelProperty(value = {"标注图片"}, index = 3, converter = UrlImageConverter.class) | |||
private URL fileImage; | |||
/** | |||
* 位置 | |||
*/ | |||
@ExcelProperty(value = {"位置"}, index = 4) | |||
private String location; | |||
/** | |||
* 所属路段 | |||
*/ | |||
@ExcelProperty(value = {"所属路段"}, index = 5) | |||
private String roadName; | |||
/** | |||
* 所属高速 | |||
*/ | |||
@ExcelProperty(value = {"所属高速"}, index = 6) | |||
private String sectionName; | |||
/** | |||
* 状态:5待确认 10已忽略 15已确认 20已生成工单 25问题已处理 | |||
*/ | |||
@ExcelProperty(value = {"状态"}, index = 7) | |||
private String status; | |||
} |
@@ -0,0 +1,70 @@ | |||
package com.tuoheng.admin.entity; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import com.tuoheng.common.core.common.BaseEntity; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
@Data | |||
@EqualsAndHashCode(callSuper = true) | |||
@Accessors(chain = true) | |||
@TableName("th_iot_equipment") | |||
public class IotEquipment extends BaseEntity { | |||
/** | |||
* 租户id | |||
*/ | |||
private String tenantId; | |||
/** | |||
* 部门id | |||
*/ | |||
private String deptId; | |||
/** | |||
* 设备编码 | |||
*/ | |||
private String code; | |||
/** | |||
* 设备名称 | |||
*/ | |||
private String name; | |||
/** | |||
* 公路ID | |||
*/ | |||
private String roadId; | |||
/** | |||
* 路段ID | |||
*/ | |||
private String sectionId; | |||
/** | |||
* 位置 | |||
*/ | |||
private String location; | |||
/** | |||
* 纬度 | |||
*/ | |||
private String latitude; | |||
/** | |||
* 经度 | |||
*/ | |||
private String longitude; | |||
/** | |||
* 监控播放地址 | |||
*/ | |||
private String playUrl; | |||
/** | |||
* 状态:0:禁用;1:启用; | |||
*/ | |||
private Integer status; | |||
} |
@@ -34,7 +34,16 @@ public interface InspectionFileMapper extends BaseMapper<InspectionFile> { | |||
* @param map | |||
* @return | |||
*/ | |||
int deleteLogicByMap(Map<String, Object> map); | |||
int deleteLogicByInspectionId(Map<String, Object> map); | |||
/** | |||
* | |||
* 逻辑删除巡检任务问题 | |||
* | |||
* @param map | |||
* @return | |||
*/ | |||
int deleteLogicByIdList(Map<String, Object> map); | |||
/** | |||
* |
@@ -0,0 +1,38 @@ | |||
package com.tuoheng.admin.mapper; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||
import com.tuoheng.admin.entity.InspectionFile; | |||
import com.tuoheng.admin.entity.IotEquipment; | |||
import com.tuoheng.admin.request.inspectionfile.QueryInspectionFilePageListByInspectionIdRequest; | |||
import com.tuoheng.admin.request.iotequipment.QueryIotEquipmentPageListRequest; | |||
import org.apache.ibatis.annotations.Param; | |||
import java.util.List; | |||
/** | |||
* 物联设备 | |||
* | |||
* @author 拓恒 | |||
* @since 2023-11-25 | |||
*/ | |||
public interface IotEquipmentMapper extends BaseMapper<IotEquipment> { | |||
/** | |||
* 查询物联设备分页列表 | |||
* | |||
* @param request 物联设备查询实体 | |||
* @return 巡检物联设备集合 | |||
*/ | |||
Page<IotEquipment> selectPageList(@Param("page") IPage page, @Param("request") QueryIotEquipmentPageListRequest request); | |||
/** | |||
* 查询物联设备列表 | |||
* | |||
* @param request 巡检任务查询实体 | |||
* @return 巡检任务集合 | |||
*/ | |||
List<IotEquipment> selectList(@Param("request") QueryIotEquipmentPageListRequest request); | |||
} |
@@ -0,0 +1,60 @@ | |||
package com.tuoheng.admin.request.iotequipment; | |||
import lombok.Data; | |||
/** | |||
* 添加物联设备请求实体 | |||
* | |||
* @author wanjing | |||
* @team tuoheng | |||
* @date 2023-11-25 | |||
*/ | |||
@Data | |||
public class AddIotEquipmentRequest { | |||
/** | |||
* 部门ID | |||
*/ | |||
private String deptId; | |||
/** | |||
* 设备编码 | |||
*/ | |||
private String code; | |||
/** | |||
* 设备名称 | |||
*/ | |||
private String name; | |||
/** | |||
* 公路ID | |||
*/ | |||
private String roadId; | |||
/** | |||
* 路段ID | |||
*/ | |||
private String sectionId; | |||
/** | |||
* 位置 | |||
*/ | |||
private String location; | |||
/** | |||
* 纬度 | |||
*/ | |||
private String latitude; | |||
/** | |||
* 经度 | |||
*/ | |||
private String longitude; | |||
/** | |||
* 监控播放地址 | |||
*/ | |||
private String playUrl; | |||
} |
@@ -0,0 +1,65 @@ | |||
package com.tuoheng.admin.request.iotequipment; | |||
import lombok.Data; | |||
/** | |||
* 修改物联设备请求实体 | |||
* | |||
* @author wanjing | |||
* @team tuoheng | |||
* @date 2023-11-25 | |||
*/ | |||
@Data | |||
public class EditIotEquipmentRequest { | |||
/** | |||
* 设备ID | |||
*/ | |||
private String id; | |||
/** | |||
* 部门ID | |||
*/ | |||
private String deptId; | |||
/** | |||
* 设备编码 | |||
*/ | |||
private String code; | |||
/** | |||
* 设备名称 | |||
*/ | |||
private String name; | |||
/** | |||
* 公路ID | |||
*/ | |||
private String roadId; | |||
/** | |||
* 路段ID | |||
*/ | |||
private String sectionId; | |||
/** | |||
* 位置 | |||
*/ | |||
private String location; | |||
/** | |||
* 纬度 | |||
*/ | |||
private String latitude; | |||
/** | |||
* 经度 | |||
*/ | |||
private String longitude; | |||
/** | |||
* 监控播放地址 | |||
*/ | |||
private String playUrl; | |||
} |
@@ -0,0 +1,27 @@ | |||
package com.tuoheng.admin.request.iotequipment; | |||
import lombok.Data; | |||
import java.util.List; | |||
/** | |||
* 查询物联设备请求实体 | |||
* | |||
* @author wanjing | |||
* @team tuoheng | |||
* @date 2023-11-25 | |||
*/ | |||
@Data | |||
public class QueryIotEquipmentListRequest { | |||
/** | |||
* 租户Id | |||
*/ | |||
private String tenantId; | |||
/** | |||
* 部门Id list | |||
*/ | |||
private List<String> deptIdList; | |||
} |
@@ -0,0 +1,43 @@ | |||
package com.tuoheng.admin.request.iotequipment; | |||
import com.tuoheng.common.core.common.BaseQuery; | |||
import lombok.Data; | |||
import java.util.List; | |||
/** | |||
* 查询物联设备分页请求实体 | |||
* | |||
* @author wanjing | |||
* @team tuoheng | |||
* @date 2023-11-25 | |||
*/ | |||
@Data | |||
public class QueryIotEquipmentPageListRequest extends BaseQuery { | |||
/** | |||
* 租户Id | |||
*/ | |||
private String tenantId; | |||
/** | |||
* 部门Id | |||
*/ | |||
private String deptId; | |||
/** | |||
* 公路名称 | |||
*/ | |||
private String roadName; | |||
/** | |||
* 路段名称 | |||
*/ | |||
private String sectionName; | |||
/** | |||
* 部门Id list | |||
*/ | |||
private List<String> deptIdList; | |||
} |
@@ -3,32 +3,25 @@ package com.tuoheng.admin.service.accident.verify; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.tuoheng.admin.constant.SystemConstant; | |||
import com.tuoheng.admin.entity.Accident; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.admin.entity.InspectionFile; | |||
import com.tuoheng.admin.entity.User; | |||
import com.tuoheng.admin.enums.AccidentStatusEnum; | |||
import com.tuoheng.admin.enums.InspectionStatusEnum; | |||
import com.tuoheng.admin.enums.InspectionTypeEnum; | |||
import com.tuoheng.admin.enums.MarkEnum; | |||
import com.tuoheng.admin.mapper.AccidentMapper; | |||
import com.tuoheng.admin.mapper.InspectionFileMapper; | |||
import com.tuoheng.admin.mapper.InspectionMapper; | |||
import com.tuoheng.admin.request.accident.AccidentVerifyCompletedRequest; | |||
import com.tuoheng.admin.request.accident.AccidentVerifyRequest; | |||
import com.tuoheng.admin.service.third.airport.DroneControlService; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.common.core.config.common.CommonConfig; | |||
import com.tuoheng.common.core.exception.ServiceException; | |||
import com.tuoheng.common.core.utils.DateUtils; | |||
import com.tuoheng.common.core.utils.HttpUtils; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.transaction.annotation.Transactional; | |||
/** | |||
* 事故核实完成业务层处理 | |||
@@ -54,7 +47,6 @@ public class AccidentVerifyCompletedService { | |||
private DroneControlService droneControlService; | |||
/** | |||
* | |||
* 1、向机场推送返舱指令,无人机返回机场 | |||
* 2、修改该事故状态为完成 | |||
* 3、应急任务状态改为已完成 |
@@ -8,7 +8,10 @@ import com.tuoheng.admin.entity.Accident; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.admin.entity.InspectionFile; | |||
import com.tuoheng.admin.entity.User; | |||
import com.tuoheng.admin.enums.*; | |||
import com.tuoheng.admin.enums.AccidentStatusEnum; | |||
import com.tuoheng.admin.enums.InspectionStatusEnum; | |||
import com.tuoheng.admin.enums.InspectionTypeEnum; | |||
import com.tuoheng.admin.enums.MarkEnum; | |||
import com.tuoheng.admin.mapper.AccidentMapper; | |||
import com.tuoheng.admin.mapper.InspectionFileMapper; | |||
import com.tuoheng.admin.mapper.InspectionMapper; | |||
@@ -16,11 +19,16 @@ import com.tuoheng.admin.request.accident.AccidentVerifyRequest; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.common.core.config.common.CommonConfig; | |||
import com.tuoheng.common.core.exception.ServiceException; | |||
import com.tuoheng.common.core.utils.*; | |||
import com.tuoheng.common.core.utils.DateUtils; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.beans.factory.annotation.Qualifier; | |||
import org.springframework.http.*; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.transaction.annotation.Transactional; | |||
import org.springframework.web.client.RestTemplate; | |||
/** | |||
* 事故核实业务层处理 | |||
@@ -42,6 +50,10 @@ public class AccidentVerifyService { | |||
@Autowired | |||
private InspectionFileMapper inspectionFileMapper; | |||
@Autowired | |||
@Qualifier("restTemplate") | |||
private RestTemplate restTemplate; | |||
/** | |||
* 1、向机场起降平台推送指令,无人机前往事故发生地点,即获取拍摄到事故照片时所处的经纬度,并在事故地点上方悬停 | |||
* 2、修改该事故状态为处理中 | |||
@@ -190,13 +202,18 @@ public class AccidentVerifyService { | |||
log.info("调用机场平台,无人机执行定点飞行: url:{}", url); | |||
log.info("调用机场平台,无人机执行定点飞行: jsonObject:{}", jsonObject); | |||
String airPortStr = HttpUtils.doSend(url, jsonObject, null, "POST"); | |||
if (StringUtils.isEmpty(airPortStr)) { | |||
log.info("调用机场平台,无人机执行定点飞行:返回数据为空,飞行失败,jsonObject:{}", jsonObject); | |||
throw new ServiceException("机场平台返回数据为空,飞行失败"); | |||
HttpHeaders headers = new HttpHeaders(); | |||
headers.setContentType(MediaType.APPLICATION_JSON); | |||
HttpEntity httpEntity = new HttpEntity(jsonObject, headers); | |||
ResponseEntity<JsonResult> response; | |||
try { | |||
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class); | |||
} catch (Exception e) { | |||
log.error("调用机场,无人机执行定点飞行:机场接口返回数据异常, url:{}", url); | |||
log.error("调用机场,无人机执行定点飞行:机场接口返回数据异常, httpEntity:{}", httpEntity); | |||
throw new ServiceException("调用机场,无人机执行定点飞行:机场接口返回数据异常"); | |||
} | |||
JsonResult jsonResult = JacksonUtil.json2pojo(airPortStr, JsonResult.class); | |||
JsonResult jsonResult = response.getBody(); | |||
if (0 != jsonResult.getCode()) { | |||
log.info("调用机场平台,无人机执行定点飞行:飞行失败,jsonResult:{}", jsonResult.getMsg()); | |||
throw new ServiceException("机场平台返回,飞行失败"); |
@@ -1,16 +1,16 @@ | |||
package com.tuoheng.admin.service.index; | |||
import com.alibaba.fastjson.JSON; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.google.gson.JsonObject; | |||
import com.tuoheng.admin.constant.SystemConstant; | |||
import com.tuoheng.admin.vo.AirportMsgVo; | |||
import com.tuoheng.common.core.config.common.CommonConfig; | |||
import com.tuoheng.common.core.utils.HttpUtils; | |||
import com.tuoheng.common.core.utils.JacksonUtil; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.beans.factory.annotation.Qualifier; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.web.client.RestTemplate; | |||
import org.springframework.web.util.UriComponentsBuilder; | |||
import java.math.BigDecimal; | |||
import java.util.Objects; | |||
@@ -21,19 +21,33 @@ import java.util.Objects; | |||
*/ | |||
@Service | |||
@Slf4j | |||
public class IndexServiceImpl implements IndexService{ | |||
public class IndexServiceImpl implements IndexService { | |||
@Autowired | |||
@Qualifier("restTemplate") | |||
private RestTemplate restTemplate; | |||
@Override | |||
public JsonResult getAirportMsg(Integer airportId) { | |||
String url = CommonConfig.airportURL + SystemConstant.API_AIRPORT_STATUS; | |||
String param = "airportId=" + airportId; | |||
String result = HttpUtils.sendGet(url, param); | |||
JsonResult jsonResult = JacksonUtil.json2pojo(result, JsonResult.class); | |||
String url = UriComponentsBuilder.fromHttpUrl(CommonConfig.airportURL + SystemConstant.API_AIRPORT_STATUS) | |||
.queryParam("airportId", airportId) | |||
.toUriString(); | |||
JsonResult jsonResult; | |||
try { | |||
jsonResult = restTemplate.getForObject(url, JsonResult.class); | |||
} catch (Exception e) { | |||
log.info("获取机场状态,机场平台返回异常, url:{}", url); | |||
return JsonResult.error("获取机场状态,机场平台返回异常"); | |||
} | |||
if (0 != jsonResult.getCode()) { | |||
log.info("获取机场状态,机场平台返回失败,jsonResult={}", jsonResult); | |||
return JsonResult.error("获取机场状态,机场平台返回失败"); | |||
} | |||
AirportMsgVo airportMsgVo = new AirportMsgVo(); | |||
JSONObject dataObject = (JSONObject) JSONObject.toJSON(jsonResult.getData()); | |||
JSONObject wthJson = dataObject.getJSONObject("WTH"); | |||
if(Objects.nonNull(wthJson)){ | |||
if (Objects.nonNull(wthJson)) { | |||
JSONObject parmJson = wthJson.getJSONObject("parmNew"); | |||
BigDecimal hum = parmJson.getBigDecimal("Hum").divide(new BigDecimal(10), 1, BigDecimal.ROUND_HALF_UP); | |||
airportMsgVo.setHum(hum + "rh"); | |||
@@ -46,14 +60,14 @@ public class IndexServiceImpl implements IndexService{ | |||
.setWidrName(parmJson.getString("WDIRNAME")); | |||
//用角度表示风向,是把圆周分成360度,北风(N)是0度(即360度),东风(E)是90度,南风(S)是180度,西风(W)是270度 | |||
BigDecimal hpa = parmJson.getBigDecimal("Hpa"); | |||
if(hpa != null){ | |||
if (hpa != null) { | |||
BigDecimal mpa = hpa.divide(new BigDecimal(100000), 1, BigDecimal.ROUND_HALF_UP); | |||
airportMsgVo.setHpa(mpa + "Mpa"); | |||
airportMsgVo.setHpa(hpa + "Mpa"); | |||
} | |||
} | |||
JSONObject tahJson = dataObject.getJSONObject("TAH"); | |||
if(Objects.nonNull(tahJson)){ | |||
if (Objects.nonNull(tahJson)) { | |||
JSONObject parmJson = tahJson.getJSONObject("parmNew"); | |||
BigDecimal hum = parmJson.getBigDecimal("Hum").divide(new BigDecimal(10), 1, BigDecimal.ROUND_HALF_UP); | |||
airportMsgVo.setHum(hum + "rh"); | |||
@@ -61,7 +75,7 @@ public class IndexServiceImpl implements IndexService{ | |||
airportMsgVo.setTmp(tmp + "℃"); | |||
} | |||
JSONObject mountJson = dataObject.getJSONObject("mount"); | |||
if(Objects.nonNull(mountJson)){ | |||
if (Objects.nonNull(mountJson)) { | |||
airportMsgVo.setMountName(mountJson.getString("cameraName") + "、" + | |||
mountJson.getString("megaphoneName") + "、" + | |||
mountJson.getString("searchlightName") |
@@ -233,7 +233,7 @@ public class DeleteInspectionService { | |||
*/ | |||
private JsonResult deleteInspectionFileByLogic(Inspection inspection) { | |||
Map<String, Object> map = this.getInspectionMap(inspection); | |||
Integer rowId = inspectionFileMapper.deleteLogicByMap(map); | |||
Integer rowId = inspectionFileMapper.deleteLogicByInspectionId(map); | |||
log.info("删除任务, 返回结果: rowId={}", rowId); | |||
if (rowId < 0) { | |||
log.info("删除任务业务接口:逻辑删除任务问题失败"); |
@@ -62,32 +62,7 @@ public class EditHandle implements GenerateInspectionFieldHander { | |||
} | |||
return; | |||
} | |||
if (user.getId().equals(inspectionVo.getCreateUser())) { | |||
// 自己创建的任务 | |||
inspectionVo.setEdit(true); | |||
} else { | |||
// 非本人创建,判断该用户是不是该部门管理员 | |||
// 本部门主管编辑本部门任务 | |||
// 查询部门管理员,若是部门管理员可修改,非部门管理员不能修改 | |||
User userTmp = userMapper.selectOne(new LambdaQueryWrapper<User>() | |||
.eq(User::getDeptId, user.getDeptId()) | |||
.eq(User::getRoleId, DataPermissionEnum.DEPT_AND_SUB_DEPT.getCode()) | |||
.eq(User::getMark, MarkEnum.VALID.getCode())); | |||
if (ObjectUtil.isNull(userTmp)) { | |||
if (null != handler) { | |||
handler.handler(user, dept, inspectionVo); | |||
return; | |||
} | |||
} | |||
if (!user.getId().equals(userTmp.getId())) { | |||
if (null != handler) { | |||
handler.handler(user, dept, inspectionVo); | |||
return; | |||
} | |||
} | |||
inspectionVo.setEdit(true); | |||
} | |||
inspectionVo.setEdit(true); | |||
if (null != handler) { | |||
handler.handler(user, dept, inspectionVo); | |||
return; |
@@ -44,23 +44,7 @@ public class ExecuteHandle implements GenerateInspectionFieldHander { | |||
} | |||
return; | |||
} | |||
if (DataPermissionEnum.ALL.getCode() == user.getDataPermission()) { | |||
// 超级管理员不能执行任务操作 | |||
inspectionVo.setExecute(false); | |||
} else if (DataPermissionEnum.DEPT_AND_SUB_DEPT.getCode() == user.getDataPermission()) { | |||
// 管理员可对本部门的任务执行此操作 | |||
if (user.getDeptId().equals(inspectionVo.getDeptId())) { | |||
if (1 == inspectionVo.getExecutionStatus()) { | |||
inspectionVo.setExecute(true); | |||
} | |||
} | |||
} else if (DataPermissionEnum.DEPT.getCode() == user.getDataPermission()) { | |||
// 普通用户可对自己创建的任务执行此操作 | |||
if (user.getId().equals(inspectionVo.getCreateUser())) { | |||
inspectionVo.setExecute(true); | |||
} | |||
} | |||
inspectionVo.setExecute(true); | |||
if (null != handler) { | |||
handler.handler(user, dept, inspectionVo); | |||
} |
@@ -15,10 +15,14 @@ import com.tuoheng.admin.service.third.dsp.IDspService; | |||
import com.tuoheng.admin.utils.AirWeatherUtil; | |||
import com.tuoheng.admin.vo.AirWeatherVO; | |||
import com.tuoheng.common.core.config.common.CommonConfig; | |||
import com.tuoheng.common.core.exception.ServiceException; | |||
import com.tuoheng.common.core.utils.*; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.beans.factory.annotation.Qualifier; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.web.client.RestTemplate; | |||
import org.springframework.web.util.UriComponentsBuilder; | |||
import java.util.List; | |||
import java.util.Objects; | |||
@@ -45,6 +49,10 @@ public class UpdateWaittStatusService { | |||
@Autowired | |||
private IDspService dspService; | |||
@Autowired | |||
@Qualifier("restTemplate") | |||
private RestTemplate restTemplate; | |||
public void updateWaittStatus(Inspection inspection) { | |||
Inspection inspectionUpdate = new Inspection(); | |||
inspectionUpdate.setId(inspection.getId()); | |||
@@ -101,42 +109,30 @@ public class UpdateWaittStatusService { | |||
} | |||
public JsonResult getWeather(String airportUrl, Integer airportId) { | |||
log.info("获取天气信息begin"); | |||
String url = airportUrl + SystemConstant.API_AIRPORT_GET_WEATHER; | |||
String param = "airportId=" + airportId; | |||
log.info("获取天气信息, url={}", url); | |||
log.info("获取天气信息, param={}", param); | |||
String weatherStr = HttpUtils.sendGet(url, param); | |||
log.info("获取天气信息, weatherStr1={}", weatherStr); | |||
String url = UriComponentsBuilder.fromHttpUrl(CommonConfig.airportURL + SystemConstant.API_AIRPORT_GET_WEATHER) | |||
.queryParam("airportId", airportId) | |||
.toUriString(); | |||
JsonResult jsonResult; | |||
try { | |||
log.info("获取天气信息, weatherStr2={}", weatherStr); | |||
jsonResult = JacksonUtil.json2pojo(weatherStr, JsonResult.class); | |||
log.info("获取天气信息, jsonResult={}", jsonResult); | |||
jsonResult = restTemplate.getForObject(url, JsonResult.class); | |||
} catch (Exception e) { | |||
log.info("获机场列表接口异常, url:{}", url); | |||
throw new ServiceException("获机场列表接口异常"); | |||
} | |||
try { | |||
if (ObjectUtil.isEmpty(jsonResult) || Objects.requireNonNull(jsonResult).getCode() != 0) { | |||
log.info("获取天气信息失败,返回为空或code不为0"); | |||
log.info("获取天气信息失败,url={}", url); | |||
log.info("获取天气信息失败,param={}", param); | |||
log.info("获取天气信息失败,返回为空或code为0"); | |||
return JsonResult.error(EditInspectionStatusCodeEnum.GET_WEATHER_FAILED.getCode(), EditInspectionStatusCodeEnum.GET_WEATHER_FAILED.getMsg()); | |||
} | |||
if (ObjectUtil.isEmpty(jsonResult.getData())) { | |||
log.info("获取天气信息,返回数据为空"); | |||
return JsonResult.success(new AirWeatherVO()); | |||
} | |||
log.info("获取天气信息, jsonResult.getData={}", jsonResult.getData()); | |||
AirWeatherVO airWeatherVO = JSONObject.parseObject(JSONObject.toJSONString(jsonResult.getData()), AirWeatherVO.class); | |||
log.info("获取天气信息,airWeatherVO={}", airWeatherVO); | |||
return JsonResult.success(airWeatherVO); | |||
} catch (Exception e) { | |||
log.info("获取天气信息异常,url={}", url); | |||
log.info("获取天气信息异常,param={}", param); | |||
log.info("获取天气信息异常,e={}", e); | |||
log.error("获取天气信息失败,url={}", url); | |||
log.error("获取天气信息失败,异常!"); | |||
return JsonResult.error(EditInspectionStatusCodeEnum.GET_WEATHER_FAILED.getCode(), EditInspectionStatusCodeEnum.GET_WEATHER_FAILED.getMsg()); | |||
} | |||
} |
@@ -98,4 +98,24 @@ public interface IInspectionFileService { | |||
* @return | |||
*/ | |||
JsonResult editQuestionType(String id, String questionCode); | |||
/** | |||
* | |||
* 删除问题 | |||
* | |||
* @param idList | |||
* | |||
* @return | |||
*/ | |||
JsonResult deletedByIdList(List<String> idList); | |||
/** | |||
* | |||
* 导出问题清单 | |||
* | |||
* @param idList | |||
* | |||
* @return | |||
*/ | |||
JsonResult exportExcleByIdList(List<String> idList); | |||
} |
@@ -13,6 +13,8 @@ import com.tuoheng.admin.mapper.*; | |||
import com.tuoheng.admin.query.InspectionFileQuery; | |||
import com.tuoheng.admin.request.inspectionfile.*; | |||
import com.tuoheng.admin.service.inspectionfile.confirm.InspectionFileConfirmService; | |||
import com.tuoheng.admin.service.inspectionfile.delete.DeleteInspectionFileByIdListService; | |||
import com.tuoheng.admin.service.inspectionfile.export.ExportInspectionFileByIdListService; | |||
import com.tuoheng.admin.service.inspectionfile.handle.QueryInspectionFileHandleByInspectionFileIdService; | |||
import com.tuoheng.admin.service.inspectionfile.ignore.InspectionFileIgnoreService; | |||
import com.tuoheng.admin.service.inspectionfile.processing.InspectionFileProcessingService; | |||
@@ -87,6 +89,12 @@ public class InspectionFileServiceImpl implements IInspectionFileService { | |||
@Autowired | |||
private QueryInspectionFileListByDeptUserTypeService queryInspectionFileListByDeptUserTypeService; | |||
@Autowired | |||
private DeleteInspectionFileByIdListService deleteInspectionFileByIdListService; | |||
@Autowired | |||
private ExportInspectionFileByIdListService exportInspectionFileByIdListService; | |||
/** | |||
* 问题类型和任务名称 | |||
* | |||
@@ -295,4 +303,27 @@ public class InspectionFileServiceImpl implements IInspectionFileService { | |||
public JsonResult editQuestionType(String id, String questionCode) { | |||
return updateInspectionFileQuestionTypeService.update(id, questionCode); | |||
} | |||
/** | |||
* 删除问题 | |||
* | |||
* @param idList | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult deletedByIdList(List<String> idList) { | |||
return deleteInspectionFileByIdListService.deletedByIdList(idList); | |||
} | |||
/** | |||
* 导出问题清单 | |||
* | |||
* @param idList | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult exportExcleByIdList(List<String> idList) { | |||
return exportInspectionFileByIdListService.exportExcleByIdList(idList); | |||
} | |||
} |
@@ -0,0 +1,71 @@ | |||
package com.tuoheng.admin.service.inspectionfile.delete; | |||
import cn.hutool.core.collection.CollectionUtil; | |||
import com.tuoheng.admin.mapper.InspectionFileMapper; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.common.core.exception.ServiceException; | |||
import com.tuoheng.common.core.utils.DateUtils; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
/** | |||
* 修改任务问题类型业务层处理 | |||
* | |||
* @author wanjing | |||
* @team tuoheng | |||
* @date 2022-12-16 | |||
*/ | |||
@Slf4j | |||
@Service | |||
public class DeleteInspectionFileByIdListService { | |||
@Autowired | |||
private InspectionFileMapper inspectionFileMapper; | |||
/** | |||
* 修改任务问题类型 | |||
* | |||
* @return | |||
*/ | |||
public JsonResult deletedByIdList(List<String> idList) { | |||
log.info("进入删除问题接口"); | |||
String userId = CurrentUserUtil.getUserId(); | |||
JsonResult result = this.check(idList); | |||
if (0 != result.getCode()) { | |||
log.info("修改任务问题类型业务接口:校验失败:{}", result.getMsg()); | |||
return result; | |||
} | |||
Map<String, Object> map = new HashMap<>(); | |||
map.put("idList", idList); | |||
map.put("mark", 0); | |||
map.put("updateUser", userId); | |||
map.put("updateTime", DateUtils.now()); | |||
Integer rowId = inspectionFileMapper.deleteLogicByIdList(map); | |||
if (rowId <= 0) { | |||
log.info("删除问题失败:inspectionFileId:{}", idList); | |||
throw new ServiceException("删除问题失败"); | |||
} | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 检查参数 | |||
* | |||
* @param idList | |||
* @return | |||
*/ | |||
private JsonResult check(List<String> idList) { | |||
if (CollectionUtil.isEmpty(idList)) { | |||
throw new ServiceException("问题ID为空"); | |||
} | |||
return JsonResult.success(); | |||
} | |||
} |
@@ -0,0 +1,113 @@ | |||
package com.tuoheng.admin.service.inspectionfile.export; | |||
import cn.hutool.core.collection.CollectionUtil; | |||
import com.alibaba.excel.EasyExcel; | |||
import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.tuoheng.admin.constant.SystemConstant; | |||
import com.tuoheng.admin.conver.InspectionFileConverMapper; | |||
import com.tuoheng.admin.dto.InspectionFileExportExcelDto; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.admin.entity.InspectionFile; | |||
import com.tuoheng.admin.entity.User; | |||
import com.tuoheng.admin.enums.MarkEnum; | |||
import com.tuoheng.admin.mapper.InspectionFileMapper; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.common.core.exception.ServiceException; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
/** | |||
* 导出任务问题清单业务层处理 | |||
* | |||
* @author wanjing | |||
* @team tuoheng | |||
* @date 2023-11-23 | |||
*/ | |||
@Slf4j | |||
@Service | |||
public class ExportInspectionFileByIdListService { | |||
@Autowired | |||
private InspectionFileMapper inspectionFileMapper; | |||
/** | |||
* 修改任务问题类型 | |||
* | |||
* @return | |||
*/ | |||
public JsonResult exportExcleByIdList(List<String> idList) { | |||
log.info("进入导出任务问题清单接口"); | |||
User user = CurrentUserUtil.getUserInfo(); | |||
String userId = CurrentUserUtil.getUserId(); | |||
JsonResult result = this.check(idList); | |||
if (0 != result.getCode()) { | |||
log.info("导出任务问题清单:校验失败:{}", result.getMsg()); | |||
return result; | |||
} | |||
List<InspectionFile> inspectionFileList = inspectionFileMapper.selectList(Wrappers.<InspectionFile>lambdaQuery() | |||
.eq(InspectionFile::getTenantId, user.getTenantId()) | |||
.in(InspectionFile::getId, idList) | |||
.eq(InspectionFile::getMark, MarkEnum.VALID.getCode())); | |||
if (CollectionUtil.isEmpty(inspectionFileList)) { | |||
return JsonResult.success(); | |||
} | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 检查参数 | |||
* | |||
* @param idList | |||
* @return | |||
*/ | |||
private JsonResult check(List<String> idList) { | |||
if (CollectionUtil.isEmpty(idList)) { | |||
throw new ServiceException("任务ID为空"); | |||
} | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 生成excel表格 | |||
* | |||
* @param inspection | |||
* @param inspectionFileList | |||
* @param filePath | |||
* | |||
* @return | |||
*/ | |||
public JsonResult easyExcel(Inspection inspection, List<InspectionFile> inspectionFileList, String filePath) { | |||
log.info("文件输出目录及格式:filePathName={}",filePath); | |||
List<InspectionFileExportExcelDto> inspectionFileExportExcelDtoList = InspectionFileConverMapper.INSTANCE.fromInspectionFileListToInspectionFileExportExcelDtoList(inspectionFileList); | |||
List<List<String>> heads = new ArrayList<>(); | |||
String totalName = "项目名称:"+ inspection.getName(); | |||
String[] nameString = {"序号", "问题类型","问题图片", "标注图片", "位置", "所属路段", "所属高速", "状态"}; | |||
for (String excelName : nameString) { | |||
heads.add(Arrays.asList(totalName, excelName)); | |||
} | |||
//需要写出的表格(对应实体类) | |||
try { | |||
EasyExcel.write(filePath, InspectionFileExportExcelDto.class).sheet("问题清单数据") | |||
.head(heads) | |||
.registerWriteHandler(new SimpleColumnWidthStyleStrategy(20)) // 简单的列宽策略,列宽20 | |||
.doWrite(inspectionFileExportExcelDtoList); // 数据源 | |||
} catch (Exception e) { | |||
log.info("生成数据导出excel异常"); | |||
throw new RuntimeException(e); | |||
} | |||
log.info("开始写入表格中"); | |||
return JsonResult.success(); | |||
} | |||
} |
@@ -55,9 +55,9 @@ public class QueryInspectionFilePageListService { | |||
public JsonResult getPageList(QueryInspectionFilePageListRequest request) { | |||
log.info("进入查询任务问题分页列表业务, request:{}", request.toString()); | |||
String userId = CurrentUserUtil.getUserId(); | |||
String tenantId = CurrentUserUtil.getTenantId(); | |||
User user = CurrentUserUtil.getUserInfo(); | |||
String userId = user.getId(); | |||
String tenantId = user.getTenantId(); | |||
request.setTenantId(tenantId); | |||
JsonResult result = this.check(request); | |||
@@ -106,11 +106,6 @@ public class QueryInspectionFilePageListService { | |||
/** | |||
* 获取部门Id的查询范围 | |||
* 1)、deptId:如果传了值,查该部门的任务 | |||
* 2)、deptId:如果没有传值 | |||
* 2.1)、管理员:可查全部确认问题 | |||
* 2.2)、管理员/普通用户:本部门及子部门创建的任务中已确认问题 | |||
* | |||
* @param deptId | |||
* @return | |||
*/ |
@@ -0,0 +1,47 @@ | |||
package com.tuoheng.admin.service.iotequipment; | |||
import com.tuoheng.admin.request.iotequipment.AddIotEquipmentRequest; | |||
import com.tuoheng.admin.request.iotequipment.EditIotEquipmentRequest; | |||
import com.tuoheng.admin.request.iotequipment.QueryIotEquipmentListRequest; | |||
import com.tuoheng.admin.request.iotequipment.QueryIotEquipmentPageListRequest; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
public interface IotEquipmentService { | |||
/** | |||
* 查询物联设备分页列表 | |||
*/ | |||
JsonResult getPageList(QueryIotEquipmentPageListRequest request); | |||
/** | |||
* 查询物联设备列表 | |||
*/ | |||
JsonResult getList(QueryIotEquipmentListRequest request); | |||
/** | |||
* 获取物联设备信息 | |||
*/ | |||
JsonResult getInfo(String id); | |||
/** | |||
* 新增获取物联设备 | |||
* | |||
* @param request | |||
* @return | |||
*/ | |||
JsonResult add(AddIotEquipmentRequest request); | |||
/** | |||
* 修改获取物联设备 | |||
* | |||
* @param request | |||
* @return | |||
*/ | |||
JsonResult edit(EditIotEquipmentRequest request); | |||
/** | |||
* 删除获取物联设备 | |||
*/ | |||
JsonResult deletedById(String id); | |||
} |
@@ -0,0 +1,88 @@ | |||
package com.tuoheng.admin.service.iotequipment; | |||
import com.tuoheng.admin.request.iotequipment.AddIotEquipmentRequest; | |||
import com.tuoheng.admin.request.iotequipment.EditIotEquipmentRequest; | |||
import com.tuoheng.admin.request.iotequipment.QueryIotEquipmentListRequest; | |||
import com.tuoheng.admin.request.iotequipment.QueryIotEquipmentPageListRequest; | |||
import com.tuoheng.admin.service.iotequipment.add.AddIotEquipmentService; | |||
import com.tuoheng.admin.service.iotequipment.delete.DeleteEditIotEquipmentByIdService; | |||
import com.tuoheng.admin.service.iotequipment.edit.EditIotEquipmentService; | |||
import com.tuoheng.admin.service.iotequipment.query.QueryEditIotEquipmentByIdService; | |||
import com.tuoheng.admin.service.iotequipment.query.QueryEditIotEquipmentListService; | |||
import com.tuoheng.admin.service.iotequipment.query.QueryEditIotEquipmentPageListService; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.RequiredArgsConstructor; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.stereotype.Service; | |||
@Slf4j | |||
@Service | |||
@RequiredArgsConstructor | |||
public class IotEquipmentServiceImpl implements IotEquipmentService { | |||
private final QueryEditIotEquipmentPageListService queryEditIotEquipmentPageListService; | |||
private final QueryEditIotEquipmentListService queryEditIotEquipmentListService; | |||
private final QueryEditIotEquipmentByIdService queryEditIotEquipmentByIdService; | |||
private final AddIotEquipmentService addIotEquipmentService; | |||
private final EditIotEquipmentService editIotEquipmentService; | |||
private final DeleteEditIotEquipmentByIdService deleteEditIotEquipmentByIdService; | |||
/** | |||
* 查询物联设备分页列表 | |||
*/ | |||
@Override | |||
public JsonResult getPageList(QueryIotEquipmentPageListRequest request) { | |||
return queryEditIotEquipmentPageListService.getPageList(request); | |||
} | |||
/** | |||
* 查询物联设备列表 | |||
*/ | |||
@Override | |||
public JsonResult getList(QueryIotEquipmentListRequest request) { | |||
return queryEditIotEquipmentListService.getList(request); | |||
} | |||
/** | |||
* 获取物联设备信息 | |||
*/ | |||
@Override | |||
public JsonResult getInfo(String id) { | |||
return queryEditIotEquipmentByIdService.getInfoById(id); | |||
} | |||
/** | |||
* 新增获取物联设备 | |||
* | |||
* @param request | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult add(AddIotEquipmentRequest request) { | |||
return addIotEquipmentService.add(request); | |||
} | |||
/** | |||
* 修改获取物联设备 | |||
* | |||
* @param request | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult edit(EditIotEquipmentRequest request) { | |||
return editIotEquipmentService.edit(request); | |||
} | |||
/** | |||
* 删除获取物联设备 | |||
*/ | |||
@Override | |||
public JsonResult deletedById(String id) { | |||
return deleteEditIotEquipmentByIdService.deletedById(id); | |||
} | |||
} |
@@ -0,0 +1,94 @@ | |||
package com.tuoheng.admin.service.iotequipment.add; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.tuoheng.admin.conver.IotEquipmentConverMapper; | |||
import com.tuoheng.admin.entity.IotEquipment; | |||
import com.tuoheng.admin.entity.User; | |||
import com.tuoheng.admin.enums.MarkEnum; | |||
import com.tuoheng.admin.mapper.IotEquipmentMapper; | |||
import com.tuoheng.admin.request.iotequipment.AddIotEquipmentRequest; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.common.core.exception.ServiceException; | |||
import com.tuoheng.common.core.utils.DateUtils; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.RequiredArgsConstructor; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.stereotype.Service; | |||
/** | |||
* 物联设备 业务类 | |||
* | |||
* @author wanjing | |||
* @since 2023-11-25 | |||
*/ | |||
@Slf4j | |||
@Service | |||
@RequiredArgsConstructor | |||
public class AddIotEquipmentService { | |||
private final IotEquipmentMapper iotEquipmentMapper; | |||
public JsonResult add(AddIotEquipmentRequest request) { | |||
User user = CurrentUserUtil.getUserInfo(); | |||
JsonResult result = this.check(user.getTenantId(), request); | |||
if (0 != result.getCode()) { | |||
log.info("添加物联设备:校验失败:{}", result.getMsg()); | |||
return result; | |||
} | |||
IotEquipment iotEquipment = IotEquipmentConverMapper.INSTANCE.fromAddIotEquipmentToIotEquipment(request); | |||
iotEquipment.setTenantId(user.getTenantId()); | |||
iotEquipment.setCreateUser(user.getId()); | |||
iotEquipment.setCreateTime(DateUtils.now()); | |||
Integer rowId = iotEquipmentMapper.insert(iotEquipment); | |||
if (rowId <= 0) { | |||
log.info("添加物联设备:失败:{}", result.getMsg()); | |||
return JsonResult.error("添加物联设备失败"); | |||
} | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 检查参数 | |||
* | |||
* @param request | |||
* @return | |||
*/ | |||
private JsonResult check(String tenantId, AddIotEquipmentRequest request) { | |||
if (StringUtils.isEmpty(request.getCode())) { | |||
throw new ServiceException("设备编码为空"); | |||
} | |||
if (StringUtils.isEmpty(request.getName())) { | |||
throw new ServiceException("设备名称为空"); | |||
} | |||
if (StringUtils.isEmpty(request.getDeptId())) { | |||
throw new ServiceException("部门Id为空"); | |||
} | |||
if (StringUtils.isEmpty(request.getRoadId())) { | |||
throw new ServiceException("高速为空"); | |||
} | |||
if (StringUtils.isEmpty(request.getSectionId())) { | |||
throw new ServiceException("路段为空"); | |||
} | |||
if (StringUtils.isEmpty(request.getLocation())) { | |||
throw new ServiceException("位置为空"); | |||
} | |||
if (StringUtils.isEmpty(request.getLongitude()) || StringUtils.isEmpty(request.getLatitude())) { | |||
throw new ServiceException("经纬度为空"); | |||
} | |||
if (StringUtils.isEmpty(request.getPlayUrl())) { | |||
throw new ServiceException("设备地址为空"); | |||
} | |||
IotEquipment iotEquipment = iotEquipmentMapper.selectOne(new LambdaQueryWrapper<IotEquipment>() | |||
.eq(IotEquipment::getTenantId, tenantId) | |||
.eq(IotEquipment::getDeptId, request.getDeptId()) | |||
.eq(IotEquipment::getCode, request.getCode()) | |||
.eq(IotEquipment::getMark, MarkEnum.VALID.getCode())); | |||
if (ObjectUtil.isNotEmpty(iotEquipment)) { | |||
throw new ServiceException("该部门下已存在该编号设备"); | |||
} | |||
return JsonResult.success(); | |||
} | |||
} |
@@ -0,0 +1,64 @@ | |||
package com.tuoheng.admin.service.iotequipment.delete; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.tuoheng.admin.entity.IotEquipment; | |||
import com.tuoheng.admin.entity.User; | |||
import com.tuoheng.admin.enums.MarkEnum; | |||
import com.tuoheng.admin.mapper.IotEquipmentMapper; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.common.core.exception.ServiceException; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.RequiredArgsConstructor; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.stereotype.Service; | |||
/** | |||
* 物联设备 业务类 | |||
* | |||
* @author wanjing | |||
* @since 2023-11-25 | |||
*/ | |||
@Slf4j | |||
@Service | |||
@RequiredArgsConstructor | |||
public class DeleteEditIotEquipmentByIdService { | |||
private final IotEquipmentMapper iotEquipmentMapper; | |||
public JsonResult deletedById(String id) { | |||
User user = CurrentUserUtil.getUserInfo(); | |||
JsonResult result = this.check(id); | |||
if (0 != result.getCode()) { | |||
log.info("删除物联设备:校验失败:{}", result.getMsg()); | |||
return result; | |||
} | |||
Integer rowId = iotEquipmentMapper.deleteById(id); | |||
if (rowId <= 0) { | |||
log.info("删除物联设备:失败:{}", result.getMsg()); | |||
return JsonResult.error("删除物联设备失败"); | |||
} | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 检查参数 | |||
* | |||
* @param id | |||
* @return | |||
*/ | |||
private JsonResult check(String id) { | |||
if (StringUtils.isEmpty(id)) { | |||
throw new ServiceException("设备Id码为空"); | |||
} | |||
IotEquipment iotEquipment = iotEquipmentMapper.selectOne(new LambdaQueryWrapper<IotEquipment>() | |||
.eq(IotEquipment::getId, id) | |||
.eq(IotEquipment::getMark, MarkEnum.VALID.getCode())); | |||
if (ObjectUtil.isEmpty(iotEquipment)) { | |||
throw new ServiceException("该设备不存在"); | |||
} | |||
return JsonResult.success(iotEquipment); | |||
} | |||
} |
@@ -0,0 +1,100 @@ | |||
package com.tuoheng.admin.service.iotequipment.edit; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.tuoheng.admin.conver.IotEquipmentConverMapper; | |||
import com.tuoheng.admin.entity.IotEquipment; | |||
import com.tuoheng.admin.entity.User; | |||
import com.tuoheng.admin.enums.MarkEnum; | |||
import com.tuoheng.admin.mapper.IotEquipmentMapper; | |||
import com.tuoheng.admin.request.iotequipment.AddIotEquipmentRequest; | |||
import com.tuoheng.admin.request.iotequipment.EditIotEquipmentRequest; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.common.core.exception.ServiceException; | |||
import com.tuoheng.common.core.utils.DateUtils; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.RequiredArgsConstructor; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.stereotype.Service; | |||
/** | |||
* 物联设备 业务类 | |||
* | |||
* @author wanjing | |||
* @since 2023-11-25 | |||
*/ | |||
@Slf4j | |||
@Service | |||
@RequiredArgsConstructor | |||
public class EditIotEquipmentService { | |||
private final IotEquipmentMapper iotEquipmentMapper; | |||
public JsonResult edit(EditIotEquipmentRequest request) { | |||
User user = CurrentUserUtil.getUserInfo(); | |||
JsonResult result = this.check(user.getTenantId(), request); | |||
if (0 != result.getCode()) { | |||
log.info("修改物联设备:校验失败:{}", result.getMsg()); | |||
return result; | |||
} | |||
IotEquipment iotEquipment = IotEquipmentConverMapper.INSTANCE.fromEditIotEquipmentToIotEquipment(request); | |||
iotEquipment.setUpdateUser(user.getId()); | |||
iotEquipment.setUpdateTime(DateUtils.now()); | |||
Integer rowId = iotEquipmentMapper.updateById(iotEquipment); | |||
if (rowId <= 0) { | |||
log.info("修改物联设备:失败:{}", result.getMsg()); | |||
return JsonResult.error("修改物联设备失败"); | |||
} | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 检查参数 | |||
* | |||
* @param request | |||
* @return | |||
*/ | |||
private JsonResult check(String tenantId, EditIotEquipmentRequest request) { | |||
if (StringUtils.isEmpty(request.getCode())) { | |||
throw new ServiceException("设备编码为空"); | |||
} | |||
if (StringUtils.isEmpty(request.getName())) { | |||
throw new ServiceException("设备名称为空"); | |||
} | |||
if (StringUtils.isEmpty(request.getDeptId())) { | |||
throw new ServiceException("部门Id为空"); | |||
} | |||
if (StringUtils.isEmpty(request.getRoadId())) { | |||
throw new ServiceException("高速为空"); | |||
} | |||
if (StringUtils.isEmpty(request.getSectionId())) { | |||
throw new ServiceException("路段为空"); | |||
} | |||
if (StringUtils.isEmpty(request.getLocation())) { | |||
throw new ServiceException("位置为空"); | |||
} | |||
if (StringUtils.isEmpty(request.getLongitude()) || StringUtils.isEmpty(request.getLatitude())) { | |||
throw new ServiceException("经纬度为空"); | |||
} | |||
if (StringUtils.isEmpty(request.getPlayUrl())) { | |||
throw new ServiceException("设备地址为空"); | |||
} | |||
IotEquipment iotEquipment = iotEquipmentMapper.selectOne(new LambdaQueryWrapper<IotEquipment>() | |||
.eq(IotEquipment::getId, request.getId()) | |||
.eq(IotEquipment::getMark, MarkEnum.VALID.getCode())); | |||
if (ObjectUtil.isEmpty(iotEquipment)) { | |||
throw new ServiceException("该设备不存在"); | |||
} | |||
iotEquipment = iotEquipmentMapper.selectOne(new LambdaQueryWrapper<IotEquipment>() | |||
.eq(IotEquipment::getTenantId, tenantId) | |||
.eq(IotEquipment::getDeptId, request.getDeptId()) | |||
.eq(IotEquipment::getCode, request.getCode()) | |||
.eq(IotEquipment::getMark, MarkEnum.VALID.getCode())); | |||
if (ObjectUtil.isNotEmpty(iotEquipment)) { | |||
throw new ServiceException("该部门下已存在该编号设备"); | |||
} | |||
return JsonResult.success(); | |||
} | |||
} |
@@ -0,0 +1,78 @@ | |||
package com.tuoheng.admin.service.iotequipment.query; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.tuoheng.admin.conver.IotEquipmentConverMapper; | |||
import com.tuoheng.admin.entity.IotEquipment; | |||
import com.tuoheng.admin.entity.RoadInformation; | |||
import com.tuoheng.admin.entity.Section; | |||
import com.tuoheng.admin.entity.User; | |||
import com.tuoheng.admin.enums.MarkEnum; | |||
import com.tuoheng.admin.mapper.IotEquipmentMapper; | |||
import com.tuoheng.admin.mapper.RoadInformationMapper; | |||
import com.tuoheng.admin.mapper.SectionMapper; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.admin.vo.IotEquipmentVo; | |||
import com.tuoheng.common.core.exception.ServiceException; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.RequiredArgsConstructor; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.stereotype.Service; | |||
/** | |||
* 物联设备 业务类 | |||
* | |||
* @author wanjing | |||
* @since 2023-11-25 | |||
*/ | |||
@Slf4j | |||
@Service | |||
@RequiredArgsConstructor | |||
public class QueryEditIotEquipmentByIdService { | |||
private final IotEquipmentMapper iotEquipmentMapper; | |||
private final RoadInformationMapper roadInformationMapper; | |||
private final SectionMapper sectionMapper; | |||
public JsonResult getInfoById(String id) { | |||
User user = CurrentUserUtil.getUserInfo(); | |||
JsonResult result = this.check(id); | |||
if (0 != result.getCode()) { | |||
log.info("修改物联设备:校验失败:{}", result.getMsg()); | |||
return result; | |||
} | |||
IotEquipment iotEquipment = (IotEquipment) result.getData(); | |||
IotEquipmentVo iotEquipmentVo = IotEquipmentConverMapper.INSTANCE.fromIotEquipmentToIotEquipmentVo(iotEquipment); | |||
if (StringUtils.isNotEmpty(iotEquipmentVo.getRoadId())) { | |||
RoadInformation roadInformation = roadInformationMapper.selectById(iotEquipmentVo.getRoadId()); | |||
if (ObjectUtil.isNotEmpty(roadInformation)) { | |||
iotEquipmentVo.setRoadName(roadInformation.getName()); | |||
} | |||
} | |||
return JsonResult.success(iotEquipmentVo); | |||
} | |||
/** | |||
* 检查参数 | |||
* | |||
* @param id | |||
* @return | |||
*/ | |||
private JsonResult check(String id) { | |||
if (StringUtils.isEmpty(id)) { | |||
throw new ServiceException("设备Id码为空"); | |||
} | |||
IotEquipment iotEquipment = iotEquipmentMapper.selectOne(new LambdaQueryWrapper<IotEquipment>() | |||
.eq(IotEquipment::getId, id) | |||
.eq(IotEquipment::getMark, MarkEnum.VALID.getCode())); | |||
if (ObjectUtil.isEmpty(iotEquipment)) { | |||
throw new ServiceException("该设备不存在"); | |||
} | |||
return JsonResult.success(iotEquipment); | |||
} | |||
} |
@@ -0,0 +1,140 @@ | |||
package com.tuoheng.admin.service.iotequipment.query; | |||
import cn.hutool.core.collection.CollectionUtil; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.tuoheng.admin.conver.IotEquipmentConverMapper; | |||
import com.tuoheng.admin.entity.IotEquipment; | |||
import com.tuoheng.admin.entity.RoadInformation; | |||
import com.tuoheng.admin.entity.Section; | |||
import com.tuoheng.admin.entity.User; | |||
import com.tuoheng.admin.enums.DataPermissionEnum; | |||
import com.tuoheng.admin.enums.MarkEnum; | |||
import com.tuoheng.admin.mapper.DeptMapper; | |||
import com.tuoheng.admin.mapper.IotEquipmentMapper; | |||
import com.tuoheng.admin.mapper.RoadInformationMapper; | |||
import com.tuoheng.admin.mapper.SectionMapper; | |||
import com.tuoheng.admin.request.iotequipment.QueryIotEquipmentListRequest; | |||
import com.tuoheng.admin.request.iotequipment.QueryIotEquipmentPageListRequest; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.admin.vo.IotEquipmentVo; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.RequiredArgsConstructor; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.stereotype.Service; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.function.Function; | |||
import java.util.stream.Collectors; | |||
/** | |||
* 物联设备 业务类 | |||
* | |||
* @author wanjing | |||
* @since 2023-11-25 | |||
*/ | |||
@Slf4j | |||
@Service | |||
@RequiredArgsConstructor | |||
public class QueryEditIotEquipmentListService { | |||
private final DeptMapper deptMapper; | |||
private final IotEquipmentMapper iotEquipmentMapper; | |||
private final RoadInformationMapper roadInformationMapper; | |||
private final SectionMapper sectionMapper; | |||
public JsonResult getList(QueryIotEquipmentListRequest request) { | |||
User user = CurrentUserUtil.getUserInfo(); | |||
JsonResult result = this.check(request); | |||
if (0 != result.getCode()) { | |||
log.info("查询物联设备列表:校验失败:{}", result.getMsg()); | |||
return result; | |||
} | |||
// 获取部门Id的查询范围 | |||
List<String> deptIdList = this.getDeptIdList(user); | |||
request.setDeptIdList(deptIdList); | |||
List<IotEquipment> iotEquipmentList = iotEquipmentMapper.selectList(new LambdaQueryWrapper<IotEquipment>() | |||
.eq(IotEquipment::getTenantId, user.getTenantId()) | |||
.in(CollectionUtil.isNotEmpty(deptIdList), IotEquipment::getDeptId, deptIdList) | |||
.eq(IotEquipment::getMark, MarkEnum.VALID.getCode())); | |||
List<IotEquipmentVo> iotEquipmentVoList = this.buildIotEquipmentVoList(iotEquipmentList); | |||
return JsonResult.success(iotEquipmentVoList); | |||
} | |||
/** | |||
* 检查参数 | |||
* | |||
* @param request | |||
* @return | |||
*/ | |||
private JsonResult check(QueryIotEquipmentListRequest request) { | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 获取部门Id的查询范围 | |||
* | |||
* @param user | |||
* @return | |||
*/ | |||
private List<String> getDeptIdList(User user) { | |||
List<String> deptIdList; | |||
if (DataPermissionEnum.ALL.getCode() == user.getDataPermission()) { | |||
return null; | |||
} else if (DataPermissionEnum.DEPT_AND_SUB_DEPT.getCode() == user.getDataPermission()) { | |||
deptIdList = deptMapper.selectAllChildListById(user.getDeptId()); | |||
return deptIdList; | |||
} else if (DataPermissionEnum.DEPT.getCode() == user.getDataPermission()) { | |||
deptIdList = new ArrayList<>(); | |||
deptIdList.add(user.getDeptId()); | |||
} | |||
return null; | |||
} | |||
private List<IotEquipmentVo> buildIotEquipmentVoList(List<IotEquipment> iotEquipmentList) { | |||
if (CollectionUtil.isEmpty(iotEquipmentList)) { | |||
return null; | |||
} | |||
List<IotEquipmentVo> iotEquipmentVoList = IotEquipmentConverMapper.INSTANCE.fromIotEquipmentToIotEquipmentVoList(iotEquipmentList); | |||
return iotEquipmentVoList; | |||
} | |||
/** | |||
* 获取公路列表,放到map,减少循环次数 | |||
* | |||
* @param iotEquipmentList | |||
* @return | |||
*/ | |||
private Map<String, RoadInformation> getRoadInformationMap(List<IotEquipment> iotEquipmentList) { | |||
List<String> roadInformationIdList = iotEquipmentList.stream().map(o -> o.getRoadId()).collect(Collectors.toList()); | |||
List<RoadInformation> roadInformationList = roadInformationMapper.selectList(new LambdaQueryWrapper<RoadInformation>() | |||
.in(RoadInformation::getId, roadInformationIdList) | |||
.eq(RoadInformation::getMark, MarkEnum.VALID.getCode())); | |||
Map<String, RoadInformation> roadInformationMap = roadInformationList.stream().collect(Collectors.toMap(RoadInformation::getId, Function.identity())); | |||
return roadInformationMap; | |||
} | |||
/** | |||
* 获取路段列表,放到map,减少循环次数 | |||
* | |||
* @param iotEquipmentList | |||
* @return | |||
*/ | |||
private Map<String, Section> getSectionMap(List<IotEquipment> iotEquipmentList) { | |||
List<String> sectionIdList = iotEquipmentList.stream().map(o -> o.getRoadId()).collect(Collectors.toList()); | |||
List<Section> roadInformationList = sectionMapper.selectList(new LambdaQueryWrapper<Section>() | |||
.in(Section::getId, sectionIdList) | |||
.eq(Section::getMark, MarkEnum.VALID.getCode())); | |||
Map<String, Section> sectionMap = roadInformationList.stream().collect(Collectors.toMap(Section::getId, Function.identity())); | |||
return sectionMap; | |||
} | |||
} |
@@ -0,0 +1,179 @@ | |||
package com.tuoheng.admin.service.iotequipment.query; | |||
import cn.hutool.core.collection.CollectionUtil; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||
import com.tuoheng.admin.conver.IotEquipmentConverMapper; | |||
import com.tuoheng.admin.entity.*; | |||
import com.tuoheng.admin.enums.DataPermissionEnum; | |||
import com.tuoheng.admin.enums.MarkEnum; | |||
import com.tuoheng.admin.enums.code.inspection.QueryInspectionPageListCodeEnum; | |||
import com.tuoheng.admin.mapper.DeptMapper; | |||
import com.tuoheng.admin.mapper.IotEquipmentMapper; | |||
import com.tuoheng.admin.mapper.RoadInformationMapper; | |||
import com.tuoheng.admin.mapper.SectionMapper; | |||
import com.tuoheng.admin.request.iotequipment.QueryIotEquipmentPageListRequest; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.admin.vo.IotEquipmentVo; | |||
import com.tuoheng.admin.vo.accident.AccidentVo; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.RequiredArgsConstructor; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.stereotype.Service; | |||
import java.util.ArrayList; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.function.Function; | |||
import java.util.stream.Collectors; | |||
/** | |||
* 物联设备 业务类 | |||
* | |||
* @author wanjing | |||
* @since 2023-11-25 | |||
*/ | |||
@Slf4j | |||
@Service | |||
@RequiredArgsConstructor | |||
public class QueryEditIotEquipmentPageListService { | |||
private final DeptMapper deptMapper; | |||
private final IotEquipmentMapper iotEquipmentMapper; | |||
private final RoadInformationMapper roadInformationMapper; | |||
private final SectionMapper sectionMapper; | |||
public JsonResult getPageList(QueryIotEquipmentPageListRequest request) { | |||
User user = CurrentUserUtil.getUserInfo(); | |||
JsonResult result = this.check(request); | |||
if (0 != result.getCode()) { | |||
log.info("查询物联设备分页列表:校验失败:{}", result.getMsg()); | |||
return result; | |||
} | |||
// 获取部门Id的查询范围 | |||
List<String> deptIdList = this.getDeptIdList(user, user.getDeptId()); | |||
request.setDeptIdList(deptIdList); | |||
// 设置分页参数 | |||
IPage<IotEquipment> page = new Page<>(request.getPage(), request.getLimit()); | |||
// 查询结果 | |||
IPage<IotEquipment> pageData = iotEquipmentMapper.selectPageList(page, request); | |||
if (null == pageData || pageData.getTotal() == 0) { | |||
log.info("获取任务分页列表为空"); | |||
return JsonResult.success(null, QueryInspectionPageListCodeEnum.DATA_IS_FAILED.getMsg()); | |||
} | |||
List<IotEquipmentVo> iotEquipmentVoList = this.buildIotEquipmentVoList(pageData.getRecords()); | |||
// 重写返回结果对象 | |||
IPage<IotEquipmentVo> pageDataVo = new Page<>(); | |||
pageDataVo.setPages(pageData.getPages()); | |||
pageDataVo.setCurrent(pageData.getCurrent()); | |||
pageDataVo.setSize(pageData.getSize()); | |||
pageDataVo.setTotal(pageData.getTotal()); | |||
pageDataVo.setRecords(iotEquipmentVoList); | |||
return JsonResult.success(pageDataVo); | |||
} | |||
/** | |||
* 检查参数 | |||
* | |||
* @param request | |||
* @return | |||
*/ | |||
private JsonResult check(QueryIotEquipmentPageListRequest request) { | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 获取部门Id的查询范围 | |||
* | |||
* @param deptId | |||
* @return | |||
*/ | |||
private List<String> getDeptIdList(User user, String deptId) { | |||
List<String> deptIdList = new ArrayList<>(); | |||
if (!StringUtils.isEmpty(deptId)) { | |||
deptIdList.add(deptId); | |||
return deptIdList; | |||
} | |||
if (DataPermissionEnum.ALL.getCode() == user.getDataPermission()) { | |||
return null; | |||
} else { | |||
deptIdList = deptMapper.selectAllChildListById(user.getDeptId()); | |||
return deptIdList; | |||
} | |||
} | |||
private List<IotEquipmentVo> buildIotEquipmentVoList(List<IotEquipment> iotEquipmentList) { | |||
if (CollectionUtil.isEmpty(iotEquipmentList)) { | |||
return null; | |||
} | |||
List<IotEquipmentVo> iotEquipmentVoList = IotEquipmentConverMapper.INSTANCE.fromIotEquipmentToIotEquipmentVoList(iotEquipmentList); | |||
Map<String, Dept> deptMap = this.getDeptMap(iotEquipmentList); | |||
Map<String, RoadInformation> roadInformationMap = this.getRoadInformationMap(iotEquipmentList); | |||
Dept dept; | |||
RoadInformation roadInformation; | |||
for (IotEquipmentVo iotEquipmentVo : iotEquipmentVoList) { | |||
if (ObjectUtil.isNotEmpty(deptMap)) { | |||
dept = deptMap.get(iotEquipmentVo.getDeptId()); | |||
if (ObjectUtil.isNotEmpty(dept)) { | |||
iotEquipmentVo.setDeptName(dept.getName()); | |||
} | |||
} | |||
if (ObjectUtil.isNotEmpty(roadInformationMap)) { | |||
roadInformation = roadInformationMap.get(iotEquipmentVo.getRoadId()); | |||
if (ObjectUtil.isNotEmpty(roadInformation)) { | |||
iotEquipmentVo.setRoadName(roadInformation.getName()); | |||
} | |||
} | |||
} | |||
return iotEquipmentVoList; | |||
} | |||
/** | |||
* 设置列表中每一个的部门名称 | |||
* 查询到的列表中的部门Id,作为部门id列表,查询所有的部门,该结果数据量不会太大,放到map中 | |||
* | |||
* @param iotEquipmentList | |||
* @return | |||
*/ | |||
private Map<String, Dept> getDeptMap(List<IotEquipment> iotEquipmentList) { | |||
if (CollectionUtil.isEmpty(iotEquipmentList)) { | |||
return null; | |||
} | |||
List<String> deptIdList = iotEquipmentList.stream().map(o -> o.getDeptId()).collect(Collectors.toList()); | |||
List<Dept> deptList = deptMapper.selectListByIdList(deptIdList); | |||
if (CollectionUtil.isEmpty(deptList)) { | |||
return null; | |||
} | |||
Map<String, Dept> deptMap = deptList.stream().collect(Collectors.toMap(Dept::getId, Function.identity())); | |||
return deptMap; | |||
} | |||
/** | |||
* | |||
* 获取公路列表,放到map,减少循环次数 | |||
* | |||
* @param iotEquipmentList | |||
* @return | |||
*/ | |||
private Map<String, RoadInformation> getRoadInformationMap(List<IotEquipment> iotEquipmentList) { | |||
List<String> roadInformationIdList = iotEquipmentList.stream().map(o -> o.getRoadId()).collect(Collectors.toList()); | |||
List<RoadInformation> roadInformationList = roadInformationMapper.selectList(new LambdaQueryWrapper<RoadInformation>() | |||
.in(RoadInformation::getId, roadInformationIdList) | |||
.eq(RoadInformation::getMark, MarkEnum.VALID.getCode())); | |||
Map<String, RoadInformation> roadInformationMap = roadInformationList.stream().collect(Collectors.toMap(RoadInformation::getId, Function.identity())); | |||
return roadInformationMap; | |||
} | |||
} |
@@ -5,13 +5,13 @@ import com.tuoheng.admin.constant.SystemConstant; | |||
import com.tuoheng.admin.mapper.TenantMapper; | |||
import com.tuoheng.common.core.config.common.CommonConfig; | |||
import com.tuoheng.common.core.exception.ServiceException; | |||
import com.tuoheng.common.core.utils.HttpUtils; | |||
import com.tuoheng.common.core.utils.JacksonUtil; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.beans.factory.annotation.Qualifier; | |||
import org.springframework.http.*; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.web.client.RestTemplate; | |||
@Slf4j | |||
@Service | |||
@@ -20,6 +20,10 @@ public class DroneControlService { | |||
@Autowired | |||
private TenantMapper tenantMapper; | |||
@Autowired | |||
@Qualifier("restTemplate") | |||
private RestTemplate restTemplate; | |||
public JsonResult execute(JSONObject jsonObject) { | |||
log.info("进入调用机场平台,操作无人机, jsonObject={}", jsonObject); | |||
String url = CommonConfig.airportURL + SystemConstant.API_AIRPORT_DRONE_CONTROL; | |||
@@ -27,13 +31,18 @@ public class DroneControlService { | |||
log.info("调用机场平台,操作无人机: url:{}", url); | |||
log.info("调用机场平台,操作无人机: jsonObject:{}", jsonObject); | |||
String airPortStr = HttpUtils.doSend(url, jsonObject, null, "POST"); | |||
log.info("调用机场平台,操作无人机: airPortStr:{}", airPortStr); | |||
if (StringUtils.isEmpty(airPortStr)) { | |||
log.info("调用机场平台,操作无人机:返回数据为空"); | |||
return JsonResult.error(-1, "机场平台返回数据为空"); | |||
HttpHeaders headers = new HttpHeaders(); | |||
headers.setContentType(MediaType.APPLICATION_JSON); | |||
HttpEntity httpEntity = new HttpEntity(jsonObject, headers); | |||
ResponseEntity<JsonResult> response; | |||
try { | |||
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class); | |||
} catch (Exception e) { | |||
log.error("调用机场平台,操作无人机异常, url:{}", url); | |||
log.error("调用机场平台,操作无人机异常, httpEntity:{}", httpEntity); | |||
throw new ServiceException("调用机场平台,操作无人机异常"); | |||
} | |||
JsonResult jsonResult = JacksonUtil.json2pojo(airPortStr, JsonResult.class); | |||
JsonResult jsonResult = response.getBody(); | |||
if (0 != jsonResult.getCode()) { | |||
log.info("调用机场平台,操作无人机:返回失败,jsonResult:{}", jsonResult.getMsg()); | |||
return JsonResult.error(-1, "机场平台返回失败"); |
@@ -10,12 +10,16 @@ import com.tuoheng.admin.mapper.InspectionMapper; | |||
import com.tuoheng.admin.mapper.TenantMapper; | |||
import com.tuoheng.common.core.config.common.CommonConfig; | |||
import com.tuoheng.common.core.utils.DateUtils; | |||
import com.tuoheng.common.core.utils.HttpUtils; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.beans.factory.annotation.Qualifier; | |||
import org.springframework.http.HttpEntity; | |||
import org.springframework.http.HttpHeaders; | |||
import org.springframework.http.HttpMethod; | |||
import org.springframework.http.MediaType; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.web.client.RestTemplate; | |||
@Slf4j | |||
@Service | |||
@@ -27,6 +31,10 @@ public class ExecuteTaskService { | |||
@Autowired | |||
private InspectionMapper inspectionMapper; | |||
@Autowired | |||
@Qualifier("restTemplate") | |||
private RestTemplate restTemplate; | |||
public JsonResult executeTask(String userId, Inspection inspection) { | |||
log.info("进入调用机场平台方法,执行任务"); | |||
// 读取不同租户的机场平台url | |||
@@ -43,12 +51,18 @@ public class ExecuteTaskService { | |||
jsonObject.put("code", "gs"); // 与机场平台约定好的 | |||
jsonObject.put("tenantCode", tenant.getCode()); | |||
String airPortStr = HttpUtils.doSend(url, jsonObject, null, "POST"); | |||
if (StringUtils.isEmpty(airPortStr)) { | |||
log.info("进入调用机场平台方法: url:{}", url); | |||
log.info("进入调用机场平台方法: jsonObject:{}", jsonObject); | |||
log.info("立即执行任务业务:机场接口返回数据为空,飞行失败,任务id:{},任务名称:{},机场id:{},机场名称:{}, 路线id:{},路线名称:{}", | |||
inspection.getId(), inspection.getName(), inspection.getAirportId(), inspection.getAirportName(), inspection.getInspectionLine(), inspection.getInspectionLineName()); | |||
log.info("执行任务, 调用机场平台: url:{}", url); | |||
log.info("执行任务, 调用机场平台: jsonObject:{}", jsonObject); | |||
HttpHeaders headers = new HttpHeaders(); | |||
headers.setContentType(MediaType.APPLICATION_JSON); | |||
HttpEntity httpEntity = new HttpEntity(jsonObject, headers); | |||
try { | |||
restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class); | |||
} catch (Exception e) { | |||
log.info("执行任务, 调用机场平台:机场接口异常, url:{}", url); | |||
log.info("执行任务, 调用机场平台:机场接口异常, httpEntity:{}", httpEntity); | |||
return JsonResult.error(ExecuteInspectionCodeEnum.AIRPORT_RETURN_DATA_IS_NULL.getCode(), ExecuteInspectionCodeEnum.AIRPORT_RETURN_DATA_IS_NULL.getMsg()); | |||
} | |||
@@ -6,15 +6,15 @@ import com.tuoheng.admin.entity.Tenant; | |||
import com.tuoheng.admin.enums.code.AriportCodeEnum; | |||
import com.tuoheng.admin.mapper.TenantMapper; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.admin.vo.AirLineVO; | |||
import com.tuoheng.common.core.config.common.CommonConfig; | |||
import com.tuoheng.common.core.utils.HttpUtils; | |||
import com.tuoheng.common.core.utils.JacksonUtil; | |||
import com.tuoheng.common.core.exception.ServiceException; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.beans.factory.annotation.Qualifier; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.web.client.RestTemplate; | |||
import org.springframework.web.util.UriComponentsBuilder; | |||
import java.util.Objects; | |||
@@ -25,17 +25,29 @@ public class GetAirLineListService { | |||
@Autowired | |||
private TenantMapper tenantMapper; | |||
@Autowired | |||
@Qualifier("restTemplate") | |||
private RestTemplate restTemplate; | |||
public JsonResult getAirLineList(Integer droneId) { | |||
//读取不同租户的机场平台url | |||
Tenant tenant = tenantMapper.selectById(CurrentUserUtil.getTenantId()); | |||
if (ObjectUtil.isEmpty(tenant)) { | |||
return JsonResult.error(AriportCodeEnum.GET_NO_TENANT.getCode(), AriportCodeEnum.GET_NO_TENANT.getMsg()); | |||
} | |||
String url = CommonConfig.airportURL + SystemConstant.API_AIRPORT_LINE_LIST; | |||
String param = "page=1&limit=100&droneId=" + droneId; | |||
String airPortStr = HttpUtils.sendGet(url, param); | |||
JsonResult<AirLineVO> jsonResult = JacksonUtil.json2pojo(airPortStr, JsonResult.class); | |||
String url = UriComponentsBuilder.fromHttpUrl(CommonConfig.airportURL + SystemConstant.API_AIRPORT_LINE_LIST) | |||
.queryParam("page", 1) | |||
.queryParam("limit", 100) | |||
.queryParam("droneId", droneId) | |||
.toUriString(); | |||
JsonResult jsonResult; | |||
try { | |||
jsonResult = restTemplate.getForObject(url, JsonResult.class); | |||
} catch (Exception e) { | |||
log.info("获机航线列表接口异常, url:{}", url); | |||
throw new ServiceException("获机航线列表接口异常"); | |||
} | |||
if (ObjectUtil.isEmpty(jsonResult) || (!ObjectUtil.isEmpty(Objects.requireNonNull(jsonResult).getData()) && jsonResult.getCode() != 0)) { | |||
return JsonResult.error(AriportCodeEnum.BAD_REQUEST.getCode(), AriportCodeEnum.BAD_REQUEST.getMsg()); | |||
} |
@@ -7,13 +7,14 @@ import com.tuoheng.admin.enums.code.AriportCodeEnum; | |||
import com.tuoheng.admin.mapper.TenantMapper; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.common.core.config.common.CommonConfig; | |||
import com.tuoheng.common.core.utils.HttpUtils; | |||
import com.tuoheng.common.core.utils.JacksonUtil; | |||
import com.tuoheng.common.core.exception.ServiceException; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.beans.factory.annotation.Qualifier; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.web.client.RestTemplate; | |||
import org.springframework.web.util.UriComponentsBuilder; | |||
@Slf4j | |||
@Service | |||
@@ -22,19 +23,29 @@ public class GetAirportListService { | |||
@Autowired | |||
private TenantMapper tenantMapper; | |||
@Autowired | |||
@Qualifier("restTemplate") | |||
private RestTemplate restTemplate; | |||
public JsonResult getAirportList() { | |||
//读取不同租户的机场平台url | |||
Tenant tenant = tenantMapper.selectById(CurrentUserUtil.getTenantId()); | |||
if (ObjectUtil.isEmpty(tenant)) { | |||
return JsonResult.error(AriportCodeEnum.GET_NO_TENANT.getCode(), AriportCodeEnum.GET_NO_TENANT.getMsg()); | |||
} | |||
String url = CommonConfig.airportURL + SystemConstant.API_AIRPORT_LIST; | |||
String param = "page=1&limit=100&tenantCode=" + tenant.getCode(); | |||
String airPortStr = HttpUtils.sendGet(url, param); | |||
JsonResult jsonResult = JacksonUtil.json2pojo(airPortStr, JsonResult.class); | |||
String url = UriComponentsBuilder.fromHttpUrl(CommonConfig.airportURL + SystemConstant.API_AIRPORT_LIST) | |||
.queryParam("page", 1) | |||
.queryParam("limit", 100) | |||
.queryParam("tenantCode", tenant.getCode()) | |||
.toUriString(); | |||
JsonResult jsonResult; | |||
try { | |||
jsonResult = restTemplate.getForObject(url, JsonResult.class); | |||
} catch (Exception e) { | |||
log.info("获机场列表接口异常, url:{}", url); | |||
throw new ServiceException("获机场列表接口异常"); | |||
} | |||
if (ObjectUtil.isEmpty(jsonResult) || (!ObjectUtil.isEmpty(jsonResult.getData()) && jsonResult.getCode() != 0)) { | |||
return JsonResult.error(AriportCodeEnum.BAD_REQUEST.getCode(), AriportCodeEnum.BAD_REQUEST.getMsg()); | |||
} |
@@ -14,11 +14,16 @@ import com.tuoheng.admin.mapper.TenantMapper; | |||
import com.tuoheng.admin.request.accident.AccidentFlightRequest; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.common.core.config.common.CommonConfig; | |||
import com.tuoheng.common.core.utils.*; | |||
import com.tuoheng.common.core.utils.DateUtils; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.beans.factory.annotation.Qualifier; | |||
import org.springframework.http.*; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.transaction.annotation.Transactional; | |||
import org.springframework.web.client.RestTemplate; | |||
/** | |||
* @Author ChengWang | |||
@@ -34,6 +39,10 @@ public class PointFlightService { | |||
@Autowired | |||
private TenantMapper tenantMapper; | |||
@Autowired | |||
@Qualifier("restTemplate") | |||
private RestTemplate restTemplate; | |||
@Transactional | |||
public JsonResult pointFlight(AccidentFlightRequest request) { | |||
log.info("执行应急飞行起飞,request={}", request); | |||
@@ -98,15 +107,21 @@ public class PointFlightService { | |||
log.info("调用机场,新无人机执行定点飞行:url:{}", url); | |||
log.info("调用机场,新无人机执行定点飞行:jsonObject:{}", jsonObject); | |||
String airPortStr = HttpUtils.doSend(url, jsonObject, null, "POST"); | |||
if (StringUtils.isEmpty(airPortStr)) { | |||
log.info("新无人机执行定点飞行:机场接口返回数据为空,飞行失败,jsonObject:{}", jsonObject); | |||
throw new ServiceException("机场接口返回数据为空,飞行失败"); | |||
HttpHeaders headers = new HttpHeaders(); | |||
headers.setContentType(MediaType.APPLICATION_JSON); | |||
HttpEntity httpEntity = new HttpEntity(jsonObject, headers); | |||
ResponseEntity<JsonResult> response; | |||
try { | |||
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class); | |||
} catch (Exception e) { | |||
log.info("调用机场,新无人机执行定点飞行:机场接口返回数据异常, url:{}", url); | |||
log.info("调用机场,新无人机执行定点飞行:机场接口返回数据异常, httpEntity:{}", httpEntity); | |||
throw new com.aliyun.oss.ServiceException("机场接口返回数据为异常,飞行失败"); | |||
} | |||
JsonResult jsonResult = JacksonUtil.json2pojo(airPortStr, JsonResult.class); | |||
JsonResult jsonResult = response.getBody(); | |||
if (0 != jsonResult.getCode()) { | |||
log.info("调用机场平台,无人机执行定点飞行:飞行失败,jsonResult:{}", jsonResult.getMsg()); | |||
throw new com.tuoheng.common.core.exception.ServiceException("机场平台返回,飞行失败"); | |||
log.info("调用机场,新无人机执行定点飞行:飞行失败,jsonResult:{}", jsonResult.getMsg()); | |||
throw new com.tuoheng.common.core.exception.ServiceException("机场平台返回,新无人机执行定点飞行失败"); | |||
} | |||
} | |||
@@ -11,13 +11,13 @@ import com.tuoheng.admin.mapper.InspectionMapper; | |||
import com.tuoheng.admin.request.accident.ReversalFlightRequest; | |||
import com.tuoheng.common.core.config.common.CommonConfig; | |||
import com.tuoheng.common.core.exception.ServiceException; | |||
import com.tuoheng.common.core.utils.HttpUtils; | |||
import com.tuoheng.common.core.utils.JacksonUtil; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.beans.factory.annotation.Qualifier; | |||
import org.springframework.http.*; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.web.client.RestTemplate; | |||
/** | |||
* @Author ChengWang | |||
@@ -30,6 +30,10 @@ public class ReversalFlightService { | |||
@Autowired | |||
private InspectionMapper inspectionMapper; | |||
@Autowired | |||
@Qualifier("restTemplate") | |||
private RestTemplate restTemplate; | |||
/** | |||
* 应急飞行(回仓) | |||
* | |||
@@ -65,17 +69,23 @@ public class ReversalFlightService { | |||
log.info("调用机场平台,无人机执行定点飞行返航:url:{}", url); | |||
log.info("调用机场平台,原无人机执行定点飞行返航,jsonObject:{}", jsonObject); | |||
String airPortStr = HttpUtils.doSend(url, jsonObject, null, "POST"); | |||
log.info("调用无人机平台,操作无人机:airPortStr:{}", airPortStr); | |||
if (StringUtils.isEmpty(airPortStr)) { | |||
log.info("原无人机执行定点飞行返航:机场接口返回数据为空,返航失败,jsonObject:{}", jsonObject); | |||
throw new ServiceException("机场接口返回数据为空,返航失败"); | |||
HttpHeaders headers = new HttpHeaders(); | |||
headers.setContentType(MediaType.APPLICATION_JSON); | |||
HttpEntity httpEntity = new HttpEntity(jsonObject, headers); | |||
ResponseEntity<JsonResult> response; | |||
try { | |||
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class); | |||
} catch (Exception e) { | |||
log.error("调用机场平台,无人机执行定点飞行返航异常, url:{}", url); | |||
log.error("调用机场平台,无人机执行定点飞行返航异常, httpEntity:{}", httpEntity); | |||
throw new ServiceException("调用机场平台,无人机执行定点飞行返航异常"); | |||
} | |||
JsonResult jsonResult = JacksonUtil.json2pojo(airPortStr, JsonResult.class); | |||
JsonResult jsonResult = response.getBody(); | |||
if (0 != jsonResult.getCode()) { | |||
log.info("调用机场平台,无人机执行定点飞行:返航失败,jsonResult:{}", jsonResult.getMsg()); | |||
return JsonResult.error(-1, "机场平台返回失败"); | |||
} | |||
log.info("调用无人机平台返航结束"); | |||
return JsonResult.success(); | |||
} |
@@ -2,21 +2,17 @@ package com.tuoheng.admin.service.third.dsp; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.admin.request.inspection.MissionStatusRequest; | |||
import com.tuoheng.common.core.utils.HttpUtils; | |||
import com.tuoheng.common.core.exception.ServiceException; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.beans.factory.annotation.Qualifier; | |||
import org.springframework.beans.factory.annotation.Value; | |||
import org.springframework.http.*; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.web.client.RestTemplate; | |||
import java.io.BufferedOutputStream; | |||
import java.io.BufferedReader; | |||
import java.io.InputStreamReader; | |||
import java.io.PrintWriter; | |||
import java.net.HttpURLConnection; | |||
import java.net.URL; | |||
import java.util.Locale; | |||
import java.util.Map; | |||
@Slf4j | |||
@Service | |||
@@ -28,6 +24,10 @@ public class DspServiceImpl implements IDspService { | |||
@Autowired | |||
private StopAIService stopAIService; | |||
@Autowired | |||
@Qualifier("restTemplate") | |||
private RestTemplate restTemplate; | |||
/** | |||
* DSP服务API接口域名 | |||
*/ | |||
@@ -42,16 +42,37 @@ public class DspServiceImpl implements IDspService { | |||
String url = String.format(Locale.ENGLISH, "%s/api/web/serviceInst/%s/application", dspDomainUrl, dspServiceInstId); | |||
log.info("调用DSP服务, url:{}", url); | |||
log.info("调用DSP服务, jsonObject:{}", jsonObject); | |||
String result = SendPost.doPost(url, jsonObject, null); | |||
log.info("调用DSP服务, result:{}", result); | |||
return JSONObject.parseObject(result); | |||
HttpHeaders headers = new HttpHeaders(); | |||
headers.setContentType(MediaType.APPLICATION_JSON); | |||
HttpEntity httpEntity = new HttpEntity(jsonObject, headers); | |||
ResponseEntity<JsonResult> response; | |||
try { | |||
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class); | |||
} catch (Exception e) { | |||
log.error("调用DSP服务:DSP返回异常, url:{}", url); | |||
log.error("调用DSP服务:DSP返回异常, httpEntity:{}", httpEntity); | |||
throw new ServiceException("调用DSP服务:DSP返回异常"); | |||
} | |||
JsonResult jsonResult = response.getBody(); | |||
if (0 != jsonResult.getCode()) { | |||
log.info("调用DSP服务:DSP返回失败,jsonResult:{}", jsonResult.getMsg()); | |||
throw new ServiceException("调用DSP服务:DSP返回失败"); | |||
} | |||
log.info("调用DSP服务, result:{}", jsonResult); | |||
return JSONObject.parseObject(String.valueOf(jsonResult)); | |||
} | |||
@Override | |||
public JSONObject serviceStopApplication(JSONObject jsonObject) { | |||
String url = dspDomainUrl + "/api/web/serviceInst/"+jsonObject.getString("requestId")+"/stop"; | |||
String result = HttpUtils.doSend(url, jsonObject, null,"PUT"); | |||
return JSONObject.parseObject(result); | |||
String url = dspDomainUrl + "/api/web/serviceInst/" + jsonObject.getString("requestId") + "/stop"; | |||
ResponseEntity<JsonResult> response; | |||
try { | |||
response = restTemplate.exchange(url, HttpMethod.PUT, null, JsonResult.class); | |||
} catch (Exception e) { | |||
log.error("硬件停止后,停止AI分析异常!{}", e); | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "硬件停止后,停止AI分析异常!"); | |||
} | |||
return JSONObject.parseObject(response.getBody().toString()); | |||
} | |||
@Override |
@@ -5,12 +5,18 @@ import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.admin.enums.AiAnalyseStatusEnum; | |||
import com.tuoheng.admin.mapper.InspectionMapper; | |||
import com.tuoheng.common.core.utils.HttpUtils; | |||
import com.tuoheng.common.core.exception.ServiceException; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.beans.factory.annotation.Qualifier; | |||
import org.springframework.beans.factory.annotation.Value; | |||
import org.springframework.http.HttpEntity; | |||
import org.springframework.http.HttpMethod; | |||
import org.springframework.http.HttpStatus; | |||
import org.springframework.http.ResponseEntity; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.web.client.RestTemplate; | |||
@Slf4j | |||
@Service | |||
@@ -19,6 +25,10 @@ public class StopAIService { | |||
@Autowired | |||
private InspectionMapper inspectionMapper; | |||
@Autowired | |||
@Qualifier("restTemplate") | |||
private RestTemplate restTemplate; | |||
/** | |||
* DSP服务API接口域名 | |||
*/ | |||
@@ -63,8 +73,14 @@ public class StopAIService { | |||
private JSONObject serviceStopApplication(JSONObject jsonObject) { | |||
String url = dspDomainUrl + "/api/web/serviceInst/" + jsonObject.getString("requestId") + "/stop"; | |||
log.info("硬件停止后,停止AI分析,调用dsp url:{}", url); | |||
String result = HttpUtils.doSend(url, jsonObject, null, "PUT"); | |||
HttpEntity httpEntity = new HttpEntity(jsonObject); | |||
ResponseEntity<JsonResult> response = restTemplate.exchange(url, HttpMethod.PUT, httpEntity, JsonResult.class); | |||
if (response == null || !response.hasBody()) { | |||
log.error("硬件停止后,停止AI分析,调用dsp,返回为空!"); | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "硬件停止后,停止AI分析,调用dsp,返回为空"); | |||
} | |||
JsonResult result = response.getBody(); | |||
log.info("硬件停止后,停止AI分析,调用dsp result:{}", result); | |||
return JSONObject.parseObject(result); | |||
return JSONObject.parseObject(result.toString()); | |||
} | |||
} |
@@ -161,7 +161,7 @@ public class AddOidcTenantService { | |||
log.info("请求参数:{}", clientRoleDto); | |||
if (clientRoleDto.getClientId().contains("freeway")) { | |||
user.setRoleId(clientRoleDto.getRoleId()); | |||
user.setClientId(clientRoleDto.getClientId()); | |||
user.setClientId("1,2"); | |||
} | |||
} | |||
user.setDeptId(""); |
@@ -174,7 +174,7 @@ public class EditOidcTenantService { | |||
log.info("请求参数:{}", clientRoleDto); | |||
if (clientRoleDto.getClientId().contains("freeway")) { | |||
user.setRoleId(clientRoleDto.getRoleId()); | |||
user.setClientId(clientRoleDto.getClientId()); | |||
user.setClientId("1,2"); | |||
} | |||
} | |||
user.setUpdateTime(DateUtils.now()); |
@@ -0,0 +1,73 @@ | |||
package com.tuoheng.admin.utils.excel; | |||
import com.alibaba.excel.enums.CellDataTypeEnum; | |||
import com.alibaba.excel.metadata.Head; | |||
import com.alibaba.excel.metadata.data.CellData; | |||
import com.alibaba.excel.metadata.data.WriteCellData; | |||
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; | |||
import com.alibaba.excel.write.style.column.AbstractColumnWidthStyleStrategy; | |||
import org.apache.poi.ss.usermodel.Cell; | |||
import org.springframework.util.CollectionUtils; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
/** | |||
* @Title: | |||
* @description: 自动列宽 | |||
* @version: 1.0 | |||
**/ | |||
public class CustomCellWriteHandler extends AbstractColumnWidthStyleStrategy { | |||
// 增加缓存 避免重复计算,影响性能 | |||
private Map<Integer, Map<Integer, Integer>> CACHE = new HashMap<>(); | |||
@Override | |||
protected void setColumnWidth(WriteSheetHolder writeSheetHolder, List<WriteCellData<?>> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) { | |||
// 头部或者是数据行时 | |||
boolean needSetWidth = isHead || !CollectionUtils.isEmpty(cellDataList); | |||
if (needSetWidth) { | |||
// 先尝试从缓存中获取 | |||
Map<Integer, Integer> maxColumnWidthMap = CACHE.get(writeSheetHolder.getSheetNo()); | |||
if (maxColumnWidthMap == null) { | |||
maxColumnWidthMap = new HashMap<>(); | |||
CACHE.put(writeSheetHolder.getSheetNo(), maxColumnWidthMap); | |||
} | |||
Integer columnWidth = 20; | |||
Integer columnIndex = cell.getColumnIndex(); | |||
if (2 == columnIndex || 3 == columnIndex) { | |||
columnWidth = 75; | |||
} | |||
maxColumnWidthMap.put(cell.getColumnIndex(), columnWidth); | |||
writeSheetHolder.getSheet().setColumnWidth(cell.getColumnIndex(), columnWidth * 256); | |||
} | |||
} | |||
private Integer dataLength(List<WriteCellData<?>> cellDataList, Cell cell, Boolean isHead) { | |||
if (isHead) { | |||
// return cell.getStringCellValue().getBytes().length; | |||
return 20; | |||
} else { | |||
CellData cellData = cellDataList.get(0); | |||
CellDataTypeEnum type = cellData.getType(); | |||
if (type == null) { | |||
return -1; | |||
} else { | |||
// 根据数据类型,定义不同的单元格宽度 | |||
switch (type) { | |||
case STRING: | |||
// return cellData.getStringValue().getBytes().length; | |||
return 20; | |||
case BOOLEAN: | |||
// return cellData.getBooleanValue().toString().getBytes().length; | |||
return 20; | |||
case NUMBER: | |||
// return cellData.getNumberValue().toString().getBytes().length; | |||
return 20; | |||
default: | |||
return -1; | |||
} | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,53 @@ | |||
package com.tuoheng.admin.utils.excel; | |||
import com.alibaba.excel.write.style.row.AbstractRowHeightStyleStrategy; | |||
import org.apache.poi.ss.usermodel.Cell; | |||
import org.apache.poi.ss.usermodel.CellType; | |||
import org.apache.poi.ss.usermodel.Row; | |||
import java.util.Iterator; | |||
public class CustomCellWriteHeightConfig extends AbstractRowHeightStyleStrategy { | |||
/** | |||
* 默认高度 | |||
*/ | |||
private static final Integer DEFAULT_HEIGHT = 300; | |||
@Override | |||
protected void setHeadColumnHeight(Row row, int relativeRowIndex) { | |||
} | |||
@Override | |||
protected void setContentColumnHeight(Row row, int relativeRowIndex) { | |||
Iterator<Cell> cellIterator = row.cellIterator(); | |||
if (!cellIterator.hasNext()) { | |||
return; | |||
} | |||
// 默认为 1行高度 | |||
int maxHeight = 10; | |||
while (cellIterator.hasNext()) { | |||
Cell cell = cellIterator.next(); | |||
System.out.println("----- " + cell.getCellTypeEnum()); | |||
if (cell.getCellTypeEnum() == CellType.STRING) { | |||
String value = cell.getStringCellValue(); | |||
int len = value.length(); | |||
int num = 0; | |||
if (len > 50) { | |||
num = len % 50 > 0 ? len / 50 : len / 2 - 1; | |||
} | |||
if (num > 0) { | |||
for (int i = 0; i < num; i++) { | |||
value = value.substring(0, (i + 1) * 50 + i) + "\n" + value.substring((i + 1) * 50 + i, len + i); | |||
} | |||
} | |||
if (value.contains("\n")) { | |||
int length = value.split("\n").length; | |||
maxHeight = Math.max(maxHeight, length) + 1; | |||
} | |||
} | |||
} | |||
row.setHeight((short) ((maxHeight) * DEFAULT_HEIGHT)); | |||
} | |||
} |
@@ -0,0 +1,74 @@ | |||
package com.tuoheng.admin.utils.excel; | |||
import cn.hutool.core.collection.CollectionUtil; | |||
import com.alibaba.excel.enums.CellDataTypeEnum; | |||
import com.alibaba.excel.metadata.Head; | |||
import com.alibaba.excel.metadata.data.CellData; | |||
import com.alibaba.excel.metadata.data.WriteCellData; | |||
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; | |||
import com.alibaba.excel.write.style.column.AbstractColumnWidthStyleStrategy; | |||
import org.apache.poi.ss.usermodel.Cell; | |||
import org.apache.poi.ss.usermodel.Sheet; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
public class CustomCellWriteWidthConfig extends AbstractColumnWidthStyleStrategy { | |||
private final Map<Integer, Map<Integer, Integer>> CACHE = new HashMap<>(); | |||
@Override | |||
protected void setColumnWidth(WriteSheetHolder writeSheetHolder, List<WriteCellData<?>> cellDataList, Cell cell, Head head, Integer integer, Boolean isHead) { | |||
boolean needSetWidth = isHead || !CollectionUtil.isEmpty(cellDataList); | |||
if (needSetWidth) { | |||
Map<Integer, Integer> maxColumnWidthMap = CACHE.computeIfAbsent(writeSheetHolder.getSheetNo(), k -> new HashMap<>()); | |||
Integer columnWidth = this.dataLength(cellDataList, cell, isHead); | |||
// 单元格文本长度大于60换行 | |||
if (columnWidth >= 0) { | |||
if (columnWidth > 60) { | |||
columnWidth = 60; | |||
} | |||
Integer maxColumnWidth = maxColumnWidthMap.get(cell.getColumnIndex()); | |||
if (maxColumnWidth == null || columnWidth > maxColumnWidth) { | |||
maxColumnWidthMap.put(cell.getColumnIndex(), columnWidth); | |||
Sheet sheet = writeSheetHolder.getSheet(); | |||
sheet.setColumnWidth(cell.getColumnIndex(), columnWidth * 256); | |||
} | |||
} | |||
} | |||
} | |||
/** | |||
* 计算长度 | |||
* @param cellDataList | |||
* @param cell | |||
* @param isHead | |||
* @return | |||
*/ | |||
private Integer dataLength(List<WriteCellData<?>> cellDataList, Cell cell, Boolean isHead) { | |||
if (isHead) { | |||
return cell.getStringCellValue().getBytes().length; | |||
} else { | |||
CellData<?> cellData = cellDataList.get(0); | |||
CellDataTypeEnum type = cellData.getType(); | |||
if (type == null) { | |||
return -1; | |||
} else { | |||
switch (type) { | |||
case STRING: | |||
// 换行符(数据需要提前解析好) | |||
int index = cellData.getStringValue().indexOf("\n"); | |||
return index != -1 ? | |||
cellData.getStringValue().substring(0, index).getBytes().length + 1 : cellData.getStringValue().getBytes().length + 1; | |||
case BOOLEAN: | |||
return cellData.getBooleanValue().toString().getBytes().length; | |||
case NUMBER: | |||
return cellData.getNumberValue().toString().getBytes().length; | |||
default: | |||
return -1; | |||
} | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,96 @@ | |||
package com.tuoheng.admin.utils.excel; | |||
import com.alibaba.excel.metadata.Head; | |||
import com.alibaba.excel.metadata.data.ImageData; | |||
import com.alibaba.excel.metadata.data.WriteCellData; | |||
import com.alibaba.excel.write.handler.CellWriteHandler; | |||
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; | |||
import com.alibaba.excel.write.metadata.holder.WriteTableHolder; | |||
import org.apache.poi.ss.usermodel.Cell; | |||
import org.apache.poi.ss.usermodel.Sheet; | |||
import org.apache.poi.ss.util.CellRangeAddress; | |||
import org.springframework.util.CollectionUtils; | |||
import java.util.List; | |||
import java.util.Objects; | |||
/** | |||
* 修改图像处理程序 | |||
* | |||
* @author admin | |||
* @date 2023/01/16 | |||
*/ | |||
public class ImageModifyHandler implements CellWriteHandler { | |||
/** | |||
* 后单元格数据转换 | |||
* | |||
* @param writeSheetHolder 写单夹 | |||
* @param writeTableHolder 写表夹 | |||
* @param cellData 单元格数据 | |||
* @param cell 细胞 | |||
* @param head 头 | |||
* @param relativeRowIndex 相对行索引 | |||
* @param isHead 是头 | |||
*/ | |||
@Override | |||
public void afterCellDataConverted(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, | |||
WriteCellData<?> cellData, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) { | |||
boolean noImageValue = Objects.isNull(cellData) || CollectionUtils.isEmpty(cellData.getImageDataList()); | |||
if (Objects.equals(Boolean.TRUE, isHead) || noImageValue) { | |||
return; | |||
} | |||
Sheet sheet = cell.getSheet(); | |||
int mergeColumNum = getMergeColumNum(cell, sheet); | |||
int mergeRowNum = getMergeRowNum(cell, sheet); | |||
ImageData imageData = cellData.getImageDataList().get(0); | |||
imageData.setRelativeLastRowIndex(mergeRowNum - 1); | |||
imageData.setRelativeLastColumnIndex(mergeColumNum - 1); | |||
imageData.setTop(10); | |||
imageData.setBottom(10); | |||
imageData.setLeft(10); | |||
imageData.setRight(10); | |||
CellWriteHandler.super.afterCellDataConverted(writeSheetHolder, writeTableHolder, cellData, cell, head, relativeRowIndex, isHead); | |||
} | |||
/** | |||
* 得到合并行num | |||
* | |||
* @param cell 细胞 | |||
* @param sheet 表 | |||
* @return int | |||
*/ | |||
public static int getMergeRowNum(Cell cell, Sheet sheet) { | |||
int mergeSize = 1; | |||
List<CellRangeAddress> mergedRegions = sheet.getMergedRegions(); | |||
for (CellRangeAddress cellRangeAddress : mergedRegions) { | |||
if (cellRangeAddress.isInRange(cell)) { | |||
//获取合并的行数 | |||
mergeSize = cellRangeAddress.getLastRow() - cellRangeAddress.getFirstRow() + 1; | |||
break; | |||
} | |||
} | |||
return mergeSize; | |||
} | |||
/** | |||
* 得到合并列num | |||
* | |||
* @param cell 细胞 | |||
* @param sheet 表 | |||
* @return int | |||
*/ | |||
public static int getMergeColumNum(Cell cell, Sheet sheet) { | |||
int mergeSize = 1; | |||
List<CellRangeAddress> mergedRegions = sheet.getMergedRegions(); | |||
for (CellRangeAddress cellRangeAddress : mergedRegions) { | |||
if (cellRangeAddress.isInRange(cell)) { | |||
//获取合并的列数 | |||
mergeSize = cellRangeAddress.getLastColumn() - cellRangeAddress.getFirstColumn() + 1; | |||
break; | |||
} | |||
} | |||
return mergeSize; | |||
} | |||
} |
@@ -0,0 +1,106 @@ | |||
package com.tuoheng.admin.utils.excel; | |||
import cn.hutool.core.collection.CollectionUtil; | |||
import com.alibaba.excel.enums.CellDataTypeEnum; | |||
import com.alibaba.excel.metadata.Head; | |||
import com.alibaba.excel.metadata.data.ImageData; | |||
import com.alibaba.excel.metadata.data.WriteCellData; | |||
import com.alibaba.excel.util.StyleUtil; | |||
import com.alibaba.excel.write.handler.CellWriteHandler; | |||
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; | |||
import com.alibaba.excel.write.metadata.holder.WriteTableHolder; | |||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; | |||
import org.apache.poi.ss.usermodel.*; | |||
import org.apache.poi.ss.util.CellRangeAddress; | |||
import java.util.List; | |||
import java.util.Objects; | |||
/** | |||
* 图像细胞编写处理程序 | |||
* | |||
* @author admin | |||
* @date 2023/01/13 | |||
*/ | |||
public class ImageModifyHandler2 implements CellWriteHandler { | |||
@Override | |||
public void afterCellDataConverted(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, WriteCellData<?> cellData, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) { | |||
// 此处不处理表头,不处理不包含图像的 | |||
boolean noImageValue = Objects.isNull(cellData) || CollectionUtil.isEmpty(cellData.getImageDataList()); | |||
if (Objects.equals(Boolean.TRUE, isHead) || noImageValue) { | |||
return; | |||
} | |||
cellData.setType(CellDataTypeEnum.EMPTY); | |||
} | |||
@Override | |||
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<WriteCellData<?>> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) { | |||
if (CollectionUtil.isEmpty(cellDataList) || Objects.equals(Boolean.TRUE, isHead)) { | |||
return; | |||
} | |||
// cellDataList 是list的原因是 填充的情况下 可能会多个写到一个单元格 但是如果普通写入只有一个 | |||
WriteCellData<?> writeCellData = cellDataList.get(0); | |||
// 在afterCellDataConverted方法里面已经将CellDataType设置为EMPTY 此处不能用cellData.getType()来判断是否图片类型 | |||
if (Objects.isNull(writeCellData) || Objects.isNull(writeCellData.getImageDataList()) || writeCellData.getImageDataList().get(0) == null) { | |||
return; | |||
} | |||
ImageData imageData = writeCellData.getImageDataList().get(0); | |||
this.setImageValue(imageData, cell); | |||
} | |||
private void setImageValue(ImageData imageData, Cell cell) { | |||
//获取当前单元格所在的sheet | |||
Sheet sheet = cell.getRow().getSheet(); | |||
//获取当前sheet页中的所有合并单元格信息 | |||
List<CellRangeAddress> mergedRegions = sheet.getMergedRegions(); | |||
//获取当前单元格的开始列号 | |||
int firstColumn = (short) cell.getColumnIndex(); | |||
//获取当前单元格的开始行号 | |||
int firstRow = cell.getRow().getRowNum(); | |||
//获取当前单元格的结束列号 | |||
int lastColumn = (short) (cell.getColumnIndex()); | |||
//获取当前单元格的结束行号 | |||
int lastRow = cell.getRow().getRowNum(); | |||
for (CellRangeAddress mergedRegion : mergedRegions) { | |||
//判断当前单元格是否包含合并行或和并列 当前单元格的所有行号和列号都包含在合并域内 则认为当前单元格存在合并行或和并列 | |||
if (cell.getColumnIndex() >= mergedRegion.getFirstColumn() && cell.getColumnIndex() <= mergedRegion.getLastColumn() && cell.getRow().getRowNum() >= mergedRegion.getFirstRow() && cell.getRow().getRowNum() <= mergedRegion.getLastRow()) { | |||
//获取合并域的开始行号 | |||
firstRow = mergedRegion.getFirstRow(); | |||
//获取合并域的结束行号 | |||
lastRow = mergedRegion.getLastRow(); | |||
//获取合并域的开始列号 | |||
firstColumn = mergedRegion.getFirstColumn(); | |||
//获取合并域的结束列号 | |||
lastColumn = mergedRegion.getLastColumn(); | |||
break; | |||
} | |||
} | |||
imageData.setRelativeLastColumnIndex(lastColumn - 1); | |||
imageData.setRelativeLastRowIndex(lastRow - 1); | |||
int index = sheet.getWorkbook().addPicture(imageData.getImage(), HSSFWorkbook.PICTURE_TYPE_PNG); | |||
Drawing<?> drawing = sheet.getDrawingPatriarch(); | |||
if (drawing == null) { | |||
drawing = sheet.createDrawingPatriarch(); | |||
} | |||
CreationHelper helper = sheet.getWorkbook().getCreationHelper(); | |||
ClientAnchor anchor = helper.createClientAnchor(); | |||
// 图片边距:让图片不会填满整个单元格,与四周有一定边距 | |||
anchor.setDx1(StyleUtil.getCoordinate(2000)); | |||
anchor.setDx2(-StyleUtil.getCoordinate(2000)); | |||
anchor.setDy1(StyleUtil.getCoordinate(2000)); | |||
anchor.setDy2(-StyleUtil.getCoordinate(2000)); | |||
// 图片行列 | |||
anchor.setCol1(cell.getColumnIndex()); | |||
anchor.setCol2(cell.getColumnIndex() + (lastColumn - firstColumn + 1)); | |||
anchor.setRow1(cell.getRowIndex()); | |||
anchor.setRow2(cell.getRowIndex() + (lastRow - firstRow + 1)); | |||
anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE); | |||
drawing.createPicture(anchor, index); | |||
} | |||
} |
@@ -0,0 +1,89 @@ | |||
package com.tuoheng.admin.utils.excel; | |||
import com.alibaba.excel.write.metadata.style.WriteCellStyle; | |||
import com.alibaba.excel.write.metadata.style.WriteFont; | |||
import org.apache.poi.ss.usermodel.BorderStyle; | |||
import org.apache.poi.ss.usermodel.HorizontalAlignment; | |||
import org.apache.poi.ss.usermodel.VerticalAlignment; | |||
/** | |||
* EasyExcel 样式工具类 | |||
*/ | |||
public class StyleUtils { | |||
/** | |||
* 标题样式 | |||
* @return | |||
*/ | |||
public static WriteCellStyle getHeadStyle(){ | |||
// 头的策略 | |||
WriteCellStyle headWriteCellStyle = new WriteCellStyle(); | |||
// 背景颜色 | |||
// headWriteCellStyle.setFillForegroundColor(IndexedColors.LIGHT_TURQUOISE1.getIndex()); | |||
// headWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND); | |||
// 字体 | |||
WriteFont headWriteFont = new WriteFont(); | |||
headWriteFont.setFontName("宋体");//设置字体名字 | |||
headWriteFont.setFontHeightInPoints((short)14);//设置字体大小 | |||
headWriteFont.setBold(true);//字体加粗 | |||
headWriteCellStyle.setWriteFont(headWriteFont); //在样式用应用设置的字体; | |||
// 样式 | |||
headWriteCellStyle.setBorderBottom(BorderStyle.THIN);//设置底边框; | |||
headWriteCellStyle.setBottomBorderColor((short) 0);//设置底边框颜色; | |||
headWriteCellStyle.setBorderLeft(BorderStyle.THIN); //设置左边框; | |||
headWriteCellStyle.setLeftBorderColor((short) 0);//设置左边框颜色; | |||
headWriteCellStyle.setBorderRight(BorderStyle.THIN);//设置右边框; | |||
headWriteCellStyle.setRightBorderColor((short) 0);//设置右边框颜色; | |||
headWriteCellStyle.setBorderTop(BorderStyle.THIN);//设置顶边框; | |||
headWriteCellStyle.setTopBorderColor((short) 0); //设置顶边框颜色; | |||
headWriteCellStyle.setWrapped(true); //设置自动换行; | |||
headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);//设置水平对齐的样式为居中对齐; | |||
headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐的样式为居中对齐; | |||
headWriteCellStyle.setShrinkToFit(true);//设置文本收缩至合适 | |||
return headWriteCellStyle; | |||
} | |||
/** | |||
* 内容样式 | |||
* @return | |||
*/ | |||
public static WriteCellStyle getContentStyle(){ | |||
// 内容的策略 | |||
WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); | |||
// 背景绿色 | |||
// 这里需要指定 FillPatternType 为FillPatternType.SOLID_FOREGROUND 不然无法显示背景颜色.头默认了 FillPatternType所以可以不指定 | |||
// contentWriteCellStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex()); | |||
// contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND); | |||
// 设置字体 | |||
WriteFont contentWriteFont = new WriteFont(); | |||
contentWriteFont.setFontHeightInPoints((short) 12);//设置字体大小 | |||
contentWriteFont.setFontName("宋体"); //设置字体名字 | |||
contentWriteCellStyle.setWriteFont(contentWriteFont);//在样式用应用设置的字体; | |||
//设置样式; | |||
contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);//设置底边框; | |||
contentWriteCellStyle.setBottomBorderColor((short) 0);//设置底边框颜色; | |||
contentWriteCellStyle.setBorderLeft(BorderStyle.THIN); //设置左边框; | |||
contentWriteCellStyle.setLeftBorderColor((short) 0);//设置左边框颜色; | |||
contentWriteCellStyle.setBorderRight(BorderStyle.THIN);//设置右边框; | |||
contentWriteCellStyle.setRightBorderColor((short) 0);//设置右边框颜色; | |||
contentWriteCellStyle.setBorderTop(BorderStyle.THIN);//设置顶边框; | |||
contentWriteCellStyle.setTopBorderColor((short) 0); ///设置顶边框颜色; | |||
contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);// 水平居中 | |||
contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 垂直居中 | |||
contentWriteCellStyle.setWrapped(true); //设置自动换行; | |||
// contentWriteCellStyle.setShrinkToFit(true);//设置文本收缩至合适 | |||
return contentWriteCellStyle; | |||
} | |||
} |
@@ -0,0 +1,112 @@ | |||
package com.tuoheng.admin.vo; | |||
import com.fasterxml.jackson.annotation.JsonFormat; | |||
import com.tuoheng.common.core.common.BaseEntity; | |||
import lombok.Data; | |||
import org.springframework.format.annotation.DateTimeFormat; | |||
import java.util.Date; | |||
@Data | |||
public class IotEquipmentVo extends BaseEntity { | |||
/** | |||
* 主键ID | |||
*/ | |||
private String id; | |||
/** | |||
* 租户id | |||
*/ | |||
private String tenantId; | |||
/** | |||
* 部门id | |||
*/ | |||
private String deptId; | |||
/** | |||
* 部门名称 | |||
*/ | |||
private String deptName; | |||
/** | |||
* 设备编码 | |||
*/ | |||
private String code; | |||
/** | |||
* 设备名称 | |||
*/ | |||
private String name; | |||
/** | |||
* 公路ID | |||
*/ | |||
private String roadId; | |||
/** | |||
* 公路名称 | |||
*/ | |||
private String roadName; | |||
/** | |||
* 路段ID | |||
*/ | |||
private String sectionId; | |||
/** | |||
* 位置 | |||
*/ | |||
private String location; | |||
/** | |||
* 纬度 | |||
*/ | |||
private String latitude; | |||
/** | |||
* 经度 | |||
*/ | |||
private String longitude; | |||
/** | |||
* 监控播放地址 | |||
*/ | |||
private String playUrl; | |||
/** | |||
* 状态:0:禁用;1:启用; | |||
*/ | |||
private Integer status; | |||
/** | |||
* 添加人 | |||
*/ | |||
private String createUser; | |||
/** | |||
* 创建时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date createTime; | |||
/** | |||
* 更新人 | |||
*/ | |||
private String updateUser; | |||
/** | |||
* 更新时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date updateTime; | |||
/** | |||
* 有效标识 | |||
*/ | |||
private Integer mark; | |||
} |
@@ -22,9 +22,14 @@ | |||
<property name="logging.maxFileSize" value="40MB"/> | |||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender"> | |||
<encoder> | |||
<pattern>${logging.pattern}</pattern> | |||
<charset>${logging.charset}</charset> | |||
<!-- <encoder>--> | |||
<!-- <pattern>${logging.pattern}</pattern>--> | |||
<!-- <charset>${logging.charset}</charset>--> | |||
<!-- </encoder>--> | |||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> | |||
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.mdc.TraceIdMDCPatternLogbackLayout"> | |||
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{tid}] [%thread] %-5level %logger{36} -%msg%n</Pattern> | |||
</layout> | |||
</encoder> | |||
</appender> | |||
@@ -52,8 +57,19 @@ | |||
<appender-ref ref="LOG_FILE" /> | |||
</appender> | |||
<logger name="com.tuoheng" level="DEBUG" additivity="false"> | |||
<!--skywalking日志上报--> | |||
<appender name="grpc-log" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender"> | |||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> | |||
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.mdc.TraceIdMDCPatternLogbackLayout"> | |||
<Pattern>[th-waterway] %d{yyyy-MM-dd HH:mm:ss.SSS} [%X{tid}] [%thread] %-5level %logger{36} -%msg%n</Pattern> | |||
</layout> | |||
</encoder> | |||
</appender> | |||
<logger name="com.tuoheng" level="INFO" additivity="false"> | |||
<appender-ref ref="console" /> | |||
<appender-ref ref="file.async" /> | |||
<appender-ref ref="grpc-log" /> | |||
</logger> | |||
<!--log4jdbc --> | |||
<logger name="jdbc.sqltiming" level="DEBUG" additivity="false"> |
@@ -151,7 +151,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
</foreach> | |||
</insert> | |||
<update id="deleteLogicByMap" parameterType="hashmap"> | |||
<update id="deleteLogicByInspectionId" parameterType="hashmap"> | |||
update th_inspection_file | |||
<trim prefix="SET" suffixOverrides=","> | |||
<if test="updateUser != null and updateUser != ''"> update_user = #{updateUser}, </if> | |||
@@ -163,6 +163,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
</where> | |||
</update> | |||
<update id="deleteLogicByIdList" parameterType="hashmap"> | |||
update th_inspection_file | |||
<trim prefix="SET" suffixOverrides=","> | |||
<if test="updateUser != null and updateUser != ''"> update_user = #{updateUser}, </if> | |||
<if test="updateTime != null"> update_time = #{updateTime}, </if> | |||
<if test="mark != null"> mark = #{mark},</if> | |||
</trim> | |||
<where> | |||
<if test="idList != null and idList.size() > 0"> | |||
id in | |||
<foreach collection="idList" item="id" separator="," open="(" close=")"> | |||
#{id} | |||
</foreach> | |||
</if> | |||
</where> | |||
</update> | |||
<delete id="deleteByInspectionId" parameterType="String"> | |||
delete from th_inspection_file where inspection_id = #{id} | |||
</delete> |
@@ -0,0 +1,72 @@ | |||
<?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="com.tuoheng.admin.mapper.IotEquipmentMapper"> | |||
<resultMap type="com.tuoheng.admin.entity.IotEquipment" id="IotEquipmentResult"> | |||
<result property="id" column="id" /> | |||
<result property="tenantId" column="tenant_id" /> | |||
<result property="deptId" column="dept_id" /> | |||
<result property="code" column="code" /> | |||
<result property="name" column="name" /> | |||
<result property="roadId" column="road_id" /> | |||
<result property="sectionId" column="section_id" /> | |||
<result property="location" column="location" /> | |||
<result property="longitude" column="longitude" /> | |||
<result property="latitude" column="latitude" /> | |||
<result property="playUrl" column="play_url" /> | |||
<result property="status" column="status" /> | |||
<result property="createUser" column="create_user" /> | |||
<result property="createTime" column="create_time" /> | |||
<result property="updateUser" column="update_user" /> | |||
<result property="updateTime" column="update_time" /> | |||
<result property="mark" column="mark" /> | |||
</resultMap> | |||
<sql id="Base_Column_List"> | |||
id, tenant_id, dept_id, code, name, road_id, section_id, location, longitude, latitude, play_url, status, | |||
create_user, create_time, update_user, update_time, mark | |||
</sql> | |||
<sql id="selectThAccidentVo"> | |||
select id, tenant_id, dept_id, code, name, road_id, section_id, location, longitude, latitude, play_url, status, | |||
create_user, create_time, update_user, update_time, mark | |||
from th_iot_equipment | |||
</sql> | |||
<select id="selectPageList" parameterType="com.tuoheng.admin.request.iotequipment.QueryIotEquipmentPageListRequest" resultMap="IotEquipmentResult"> | |||
select <include refid="Base_Column_List"/> | |||
from th_iot_equipment | |||
<where> | |||
<if test="1 == 1"> and mark = 1 </if> | |||
<if test="request.tenantId != null and request.tenantId != ''"> and tenant_id = #{request.tenantId} </if> | |||
<if test="request.sectionName != null and request.sectionName != ''"> and section_name = #{request.sectionName} </if> | |||
<if test="request.deptIdList != null and request.deptIdList.size() > 0"> | |||
and dept_id in | |||
<foreach item="deptId" collection="request.deptIdList" open="(" separator="," close=")"> | |||
#{deptId} | |||
</foreach> | |||
</if> | |||
</where> | |||
order by create_time desc | |||
</select> | |||
<select id="selectList" parameterType="com.tuoheng.admin.request.iotequipment.QueryIotEquipmentPageListRequest" resultMap="IotEquipmentResult"> | |||
select <include refid="Base_Column_List"/> | |||
from th_iot_equipment | |||
<where> | |||
<if test="1 == 1"> and mark = 1 </if> | |||
<if test="request.tenantId != null and request.tenantId != ''"> and tenant_id = #{request.tenantId} </if> | |||
<if test="request.sectionName != null and request.sectionName != ''"> and section_name = #{request.sectionName} </if> | |||
<if test="request.deptIdList != null and request.deptIdList.size() > 0"> | |||
and dept_id in | |||
<foreach item="deptId" collection="request.deptIdList" open="(" separator="," close=")"> | |||
#{deptId} | |||
</foreach> | |||
</if> | |||
</where> | |||
order by create_time desc | |||
</select> | |||
</mapper> |
@@ -0,0 +1,86 @@ | |||
package com.tuoheng.admin; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.admin.enums.AiAnalyseTypeEnum; | |||
import org.apache.commons.collections4.CollectionUtils; | |||
import java.text.ParseException; | |||
import java.util.ArrayList; | |||
import java.util.Collection; | |||
import java.util.List; | |||
public class Test { | |||
public static void main(String[] args) throws ParseException { | |||
Integer isLive = null; | |||
boolean online_condition = AiAnalyseTypeEnum.ONLINE.getCode() == isLive; | |||
boolean offline_condition = AiAnalyseTypeEnum.OFFLINE.getCode() == isLive; | |||
System.out.println("online_condition = " + online_condition); | |||
System.out.println("offline_condition = " + offline_condition); | |||
} | |||
public static void main2() { | |||
List<String> list1 = buildList1(); | |||
List<String> list2 = buildList2(); | |||
//并集 | |||
Collection<String> union = CollectionUtils.union(list1, list2); | |||
//交集 | |||
Collection<String> intersection = CollectionUtils.intersection(list1, list2); | |||
//交集的补集 | |||
Collection<String> disjunction = CollectionUtils.disjunction(list1, list2); | |||
//集合相减 | |||
Collection<String> subtract = CollectionUtils.subtract(list1, list2); | |||
//集合相减 | |||
Collection<String> subtract2 = CollectionUtils.subtract(list2, list1); | |||
System.out.println("并集:" + union); | |||
System.out.println("交集" + intersection); | |||
System.out.println("交集的补集" + disjunction); | |||
System.out.println("集合相减" + subtract); | |||
System.out.println("集合相减" + subtract2); | |||
} | |||
private static List<String> buildList1() { | |||
List<String> list1 = new ArrayList<>(); | |||
list1.add("a"); | |||
list1.add("b"); | |||
list1.add("c"); | |||
return list1; | |||
} | |||
private static List<String> buildList2() { | |||
List<String> list2 = new ArrayList<>(); | |||
list2.add("b"); | |||
list2.add("e"); | |||
list2.add("d"); | |||
return list2; | |||
} | |||
private static List<String> jiao(List<String> oldList, List<String> newList) { | |||
// 交集 | |||
oldList.retainAll(newList); | |||
System.out.println(oldList.toString()); // b | |||
return oldList; | |||
} | |||
private static List<String> bing(List<String> oldList, List<String> newList) { | |||
// 交集 | |||
oldList.retainAll(newList); | |||
System.out.println(oldList.toString()); // b | |||
return oldList; | |||
} | |||
private static List<String> cha(List<String> oldList, List<String> newList) { | |||
// 差集 | |||
oldList.retainAll(newList); | |||
System.out.println(oldList.toString()); // b | |||
return oldList; | |||
} | |||
} |
@@ -0,0 +1,279 @@ | |||
package com.tuoheng.admin; | |||
import java.io.File; | |||
import java.io.FileOutputStream; | |||
import java.math.BigInteger; | |||
import java.sql.Connection; | |||
import java.sql.DriverManager; | |||
import java.sql.PreparedStatement; | |||
import java.sql.ResultSet; | |||
import java.sql.SQLException; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import org.apache.poi.xwpf.usermodel.ParagraphAlignment; | |||
import org.apache.poi.xwpf.usermodel.XWPFDocument; | |||
import org.apache.poi.xwpf.usermodel.XWPFParagraph; | |||
import org.apache.poi.xwpf.usermodel.XWPFRun; | |||
import org.apache.poi.xwpf.usermodel.XWPFTable; | |||
import org.apache.poi.xwpf.usermodel.XWPFTableCell; | |||
import org.apache.poi.xwpf.usermodel.XWPFTableRow; | |||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc; | |||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; | |||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr; | |||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl; | |||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblGrid; | |||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblGridCol; | |||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc; | |||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc; | |||
import com.alibaba.fastjson.JSONObject; | |||
public class WordExportTable { | |||
public static final String driverUrl = "jdbc:mysql://127.0.0.1:3306/tuoheng_freeway?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&useSSL=false"; | |||
public static final String username = "root"; | |||
public static final String password = "123456"; | |||
/** | |||
* 导出数据库需要与driverUrl中连接的数据库一致 | |||
*/ | |||
public static final String dataBase = "snowy-pub"; | |||
/** | |||
* 不需要导出的表,可为null | |||
*/ | |||
public static final String notTbales = "'op_roles','op_menus'"; | |||
/** | |||
* 匹配前缀不导出,可为null | |||
*/ | |||
public static final String notLike = "'sys_%'"; | |||
/** | |||
* 文档标题 | |||
*/ | |||
public static final String title = "数据库设计详细说明书"; | |||
/** | |||
* 输出文档地址 | |||
*/ | |||
public static final String path = "/apps/db/"; | |||
/** | |||
* 输出文档名称 | |||
*/ | |||
public static final String fileName = "数据库设计详细说明书V1.0.0.docx"; | |||
public static void main(String[] args)throws Exception { | |||
//Blank Document | |||
XWPFDocument document= new XWPFDocument(); | |||
//添加标题 | |||
XWPFParagraph titleParagraph = document.createParagraph(); | |||
//设置段落居中 | |||
titleParagraph.setAlignment(ParagraphAlignment.CENTER); | |||
XWPFRun titleParagraphRun = titleParagraph.createRun(); | |||
titleParagraphRun.setText(title); | |||
titleParagraphRun.setColor("000000"); | |||
titleParagraphRun.setFontSize(20); | |||
WordExportTable we = new WordExportTable(); | |||
List<JSONObject> list= we.getTables(dataBase); | |||
for (JSONObject json : list) { | |||
List<String[]> columns = we.getTablesDetail(dataBase, json.getString("name")); | |||
addTable(document, json.getString("name"), json.getString("remark"), columns); | |||
} | |||
//Write the Document in file system | |||
FileOutputStream out = new FileOutputStream(new File(path+fileName)); | |||
document.write(out); | |||
out.close(); | |||
System.out.println("create_table document written success."); | |||
} | |||
private List<String[]> getTablesDetail(String schema, String tableName){ | |||
List<String[]> list = new ArrayList<>(); | |||
Connection connection = null; | |||
PreparedStatement preparedStatement = null; | |||
ResultSet resultSet = null; | |||
try { | |||
//加载数据库驱动 | |||
Class.forName("com.mysql.jdbc.Driver"); | |||
//通过驱动管理类获取数据库链接 | |||
connection = DriverManager.getConnection(driverUrl, username, password); | |||
//定义sql语句 ?表示占位符 | |||
String sql = "SELECT COLUMN_NAME , COLUMN_TYPE , COLUMN_DEFAULT , IS_NULLABLE , COLUMN_COMMENT " | |||
+" FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = ? and table_name = ? "; | |||
//获取预处理statement | |||
preparedStatement = connection.prepareStatement(sql); | |||
//设置参数,第一个参数为sql语句中参数的序号(从1开始),第二个参数为设置的参数值 | |||
preparedStatement.setString(1, schema); | |||
preparedStatement.setString(2, tableName); | |||
//向数据库发出sql执行查询,查询出结果集 | |||
resultSet = preparedStatement.executeQuery(); | |||
int i = 1; | |||
//遍历查询结果集 | |||
while(resultSet.next()){ | |||
String[] str = new String[7]; | |||
str[0] = i+""; | |||
str[1] = resultSet.getString("COLUMN_NAME"); | |||
str[2] = resultSet.getString("COLUMN_TYPE"); | |||
str[3] = resultSet.getString("COLUMN_DEFAULT"); | |||
str[4] = resultSet.getString("IS_NULLABLE"); | |||
str[5] = ""; | |||
str[6] = resultSet.getString("COLUMN_COMMENT"); | |||
list.add(str); | |||
i++; | |||
} | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
}finally{ | |||
//释放资源 | |||
if(resultSet!=null){ | |||
try { | |||
resultSet.close(); | |||
} catch (SQLException e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
if(preparedStatement!=null){ | |||
try { | |||
preparedStatement.close(); | |||
} catch (SQLException e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
if(connection!=null){ | |||
try { | |||
connection.close(); | |||
} catch (SQLException e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
} | |||
return list; | |||
} | |||
private List<JSONObject> getTables(String schema){ | |||
List<JSONObject> list = new ArrayList<>(); | |||
Connection connection = null; | |||
PreparedStatement preparedStatement = null; | |||
ResultSet resultSet = null; | |||
try { | |||
//加载数据库驱动 | |||
Class.forName("com.mysql.jdbc.Driver"); | |||
//通过驱动管理类获取数据库链接 | |||
connection = DriverManager.getConnection(driverUrl, username, password); | |||
//定义sql语句 ?表示占位符 | |||
StringBuffer sql = new StringBuffer(); | |||
sql.append("select TABLE_NAME,TABLE_COMMENT from information_schema.tables where table_schema= ? "); | |||
if(null != notLike){ | |||
sql.append(" AND table_name NOT LIKE "+notLike); | |||
} | |||
if(null != notTbales){ | |||
sql.append(" AND table_name NOT IN ("+notTbales+")"); | |||
} | |||
//获取预处理statement | |||
preparedStatement = connection.prepareStatement(sql.toString()); | |||
//设置参数,第一个参数为sql语句中参数的序号(从1开始),第二个参数为设置的参数值 | |||
preparedStatement.setString(1, schema); | |||
//向数据库发出sql执行查询,查询出结果集 | |||
resultSet = preparedStatement.executeQuery(); | |||
//遍历查询结果集 | |||
while(resultSet.next()){ | |||
JSONObject j = new JSONObject(); | |||
j.put("name", resultSet.getString("TABLE_NAME")); | |||
j.put("remark", resultSet.getString("TABLE_COMMENT")); | |||
list.add(j); | |||
} | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
}finally{ | |||
//释放资源 | |||
if(resultSet!=null){ | |||
try { | |||
resultSet.close(); | |||
} catch (SQLException e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
if(preparedStatement!=null){ | |||
try { | |||
preparedStatement.close(); | |||
} catch (SQLException e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
if(connection!=null){ | |||
try { | |||
connection.close(); | |||
} catch (SQLException e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
} | |||
return list; | |||
} | |||
private static void addTable(XWPFDocument document,String tableName,String remark, List<String[]> columns){ | |||
//两个表格之间加个换行 | |||
document.createParagraph().createRun().setText("\r"); | |||
// 标题1,1级大纲 | |||
document.createParagraph().createRun().setText(remark+" "+tableName); | |||
//工作经历表格 | |||
XWPFTable ComTable = document.createTable(); | |||
// //列宽自动分割 | |||
// CTTblWidth comTableWidth = ComTable.getCTTbl().addNewTblPr().addNewTblW(); | |||
// comTableWidth.setType(STTblWidth.DXA); | |||
// comTableWidth.setW(BigInteger.valueOf(9072)); | |||
CTTbl ttbl = ComTable.getCTTbl(); | |||
int[] COLUMN_WIDTHS = new int[] {572,2072,1372,872,672,672,2572}; | |||
CTTblGrid tblGrid = ttbl.getTblGrid() != null ? ttbl.getTblGrid() | |||
: ttbl.addNewTblGrid(); | |||
for (int j = 0, len = COLUMN_WIDTHS.length; j < len; j++) { | |||
CTTblGridCol gridCol = tblGrid.addNewGridCol(); | |||
gridCol.setW(new BigInteger(String.valueOf(COLUMN_WIDTHS[j]))); | |||
} | |||
//表格第一行 | |||
XWPFTableRow comTableRowOne = ComTable.getRow(0); | |||
setCellvalue(comTableRowOne.getCell(0), "序号"); | |||
setCellvalue(comTableRowOne.addNewTableCell(),"字段名"); | |||
setCellvalue(comTableRowOne.addNewTableCell(),"类型"); | |||
setCellvalue(comTableRowOne.addNewTableCell(),"默认值"); | |||
setCellvalue(comTableRowOne.addNewTableCell(),"是否可为空"); | |||
setCellvalue(comTableRowOne.addNewTableCell(),"是否主键"); | |||
setCellvalue(comTableRowOne.addNewTableCell(),"注释"); | |||
for (String[] str : columns) { | |||
//表格第二行 | |||
XWPFTableRow comTableRowTwo = ComTable.createRow(); | |||
for (int j = 0; j < str.length; j++) { | |||
if(j==0 || j==3 || j==4 || j==5){ | |||
setCellvalue(comTableRowTwo.getCell(j),str[j]); | |||
}else{ | |||
comTableRowTwo.getCell(j).setText(str[j]); | |||
} | |||
} | |||
} | |||
} | |||
private static void setCellvalue(XWPFTableCell cell, String text){ | |||
cell.setText(text); | |||
//垂直居中 | |||
cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); | |||
CTTc cttc = cell.getCTTc(); | |||
CTP ctp = cttc.getPList().get(0); | |||
CTPPr ctppr = ctp.getPPr(); | |||
if (ctppr == null) { | |||
ctppr = ctp.addNewPPr(); | |||
} | |||
CTJc ctjc = ctppr.getJc(); | |||
if (ctjc == null) { | |||
ctjc = ctppr.addNewJc(); | |||
} | |||
//水平居中 | |||
ctjc.setVal(STJc.CENTER); | |||
} | |||
} |
@@ -0,0 +1,15 @@ | |||
package com.tuoheng.admin.data; | |||
import java.lang.annotation.*; | |||
import static java.lang.annotation.ElementType.*; | |||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | |||
@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE, TYPE}) | |||
@Retention(RetentionPolicy.RUNTIME) | |||
public @interface DataAuthSelect { | |||
//数据类型 data_group_ref表中的 data_type 字段值 | |||
int type() default 0; | |||
} |
@@ -0,0 +1,22 @@ | |||
package com.tuoheng.admin.data; | |||
import java.lang.annotation.Documented; | |||
import java.lang.annotation.Retention; | |||
import java.lang.annotation.Target; | |||
import static java.lang.annotation.ElementType.*; | |||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | |||
/** | |||
* 数据权限验证注解 | |||
*/ | |||
@Documented | |||
@Target({METHOD, ANNOTATION_TYPE, TYPE}) | |||
@Retention(RUNTIME) | |||
public @interface DataPermission { | |||
/** | |||
* 是否要进行数据权限隔离 | |||
*/ | |||
boolean isPermission() default true; | |||
} |
@@ -0,0 +1,182 @@ | |||
package com.tuoheng.admin.data; | |||
import cn.hutool.core.util.ClassUtil; | |||
import com.baomidou.mybatisplus.core.toolkit.PluginUtils; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import net.sf.jsqlparser.JSQLParserException; | |||
import net.sf.jsqlparser.expression.Expression; | |||
import net.sf.jsqlparser.expression.operators.conditional.AndExpression; | |||
import net.sf.jsqlparser.parser.CCJSqlParserUtil; | |||
import net.sf.jsqlparser.statement.select.PlainSelect; | |||
import net.sf.jsqlparser.statement.select.Select; | |||
import org.apache.ibatis.executor.statement.StatementHandler; | |||
import org.apache.ibatis.mapping.MappedStatement; | |||
import org.apache.ibatis.plugin.Interceptor; | |||
import org.apache.ibatis.plugin.Intercepts; | |||
import org.apache.ibatis.plugin.Invocation; | |||
import org.apache.ibatis.plugin.Signature; | |||
import org.apache.ibatis.reflection.MetaObject; | |||
import org.apache.ibatis.reflection.SystemMetaObject; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Component; | |||
import java.lang.reflect.Method; | |||
import java.sql.Connection; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.Set; | |||
import java.util.stream.Collectors; | |||
@Slf4j | |||
//@Component | |||
@Intercepts({@Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})}) | |||
public class DataPermissionInterceptor implements Interceptor { | |||
//扫描的包路径(根据自己的项目路径来),这里是取的配置里的包路径 | |||
// @Value("${permission.package-path}") | |||
// private String packagePath; | |||
private String packagePath = "com.tuoheng.admin.mapper"; | |||
private final static String DEPT_ID = "dept_id"; | |||
private final static String USER_ID = "create_user"; | |||
private static List<String> classNames; | |||
@Override | |||
public Object intercept(Invocation invocation) throws Throwable { | |||
try { | |||
List<String> deptIds = new ArrayList<>(); | |||
deptIds.add("1"); | |||
deptIds.add("2"); | |||
deptIds.add("3"); | |||
//反射扫包会比较慢,这里做了个懒加载 | |||
if (classNames == null) { | |||
synchronized (LazyInit.class) { | |||
if (classNames == null) { | |||
//扫描指定包路径下所有包含指定注解的类 | |||
Set<Class<?>> classSet = ClassUtil.scanPackageByAnnotation(packagePath, DataPermission.class); | |||
if (classSet == null && classSet.size() == 0) { | |||
classNames = new ArrayList<>(); | |||
} else { | |||
//取得类全名 | |||
classNames = classSet.stream().map(Class::getName).collect(Collectors.toList()); | |||
} | |||
} | |||
} | |||
} | |||
// 拿到mybatis的一些对象 | |||
StatementHandler statementHandler = PluginUtils.realTarget(invocation.getTarget()); | |||
MetaObject metaObject = SystemMetaObject.forObject(statementHandler); | |||
MappedStatement mappedStatement = (MappedStatement) metaObject.getValue("delegate.mappedStatement"); | |||
// mappedStatement.getId()为执行的mapper方法的全路径名,newId为执行的mapper方法的类全名 | |||
String newId = mappedStatement.getId().substring(0, mappedStatement.getId().lastIndexOf(".")); | |||
// 如果不是指定的方法,直接结束拦截 | |||
if (!classNames.contains(newId)) { | |||
return invocation.proceed(); | |||
} | |||
String newName = mappedStatement.getId().substring(mappedStatement.getId().lastIndexOf(".") + 1, mappedStatement.getId().length()); | |||
//是否开启数据权限 | |||
boolean isPermi = true; | |||
Class<?> clazz = Class.forName(newId); | |||
//遍历方法 | |||
for (Method method : clazz.getDeclaredMethods()) { | |||
//方法是否含有DataPermission注解,如果含有注解则将数据结果过滤 | |||
if (method.isAnnotationPresent(DataPermission.class) && newName.equals(method.getName())) { | |||
DataPermission dataPermission = method.getAnnotation(DataPermission.class); | |||
if (dataPermission != null) { | |||
//不验证 | |||
if (!dataPermission.isPermission()) { | |||
isPermi = false; | |||
} else { | |||
//开启验证 | |||
isPermi = true; | |||
} | |||
} | |||
} | |||
} | |||
if (isPermi) { | |||
// 获取到原始sql语句 | |||
String sql = statementHandler.getBoundSql().getSql(); | |||
// 解析并返回新的SQL语句,只处理查询sql | |||
if (mappedStatement.getSqlCommandType().toString().equals("SELECT")) { | |||
// String newSql = getNewSql(sql,deptIds,user.getUserId()); | |||
sql = getSql(sql, deptIds, 1L); | |||
} | |||
// 修改sql | |||
metaObject.setValue("delegate.boundSql.sql", sql); | |||
} | |||
return invocation.proceed(); | |||
} catch (Exception e) { | |||
log.error("数据权限隔离异常:", e); | |||
return invocation.proceed(); | |||
} | |||
} | |||
/** | |||
* 解析SQL语句,并返回新的SQL语句 | |||
* 注意,该方法使用了JSqlParser来操作SQL,该依赖包Mybatis-plus已经集成了。如果要单独使用,请先自行导入依赖 | |||
* | |||
* @param sql 原SQL | |||
* @return 新SQL | |||
*/ | |||
private String getSql(String sql, List<String> deptIds, Long userId) { | |||
try { | |||
String condition = ""; | |||
String permissionSql = "("; | |||
if (deptIds.size() > 0) { | |||
for (String deptId : deptIds) { | |||
if ("(".equals(permissionSql)) { | |||
permissionSql = permissionSql + deptId; | |||
} else { | |||
permissionSql = permissionSql + "," + deptId; | |||
} | |||
} | |||
permissionSql = permissionSql + ")"; | |||
// 修改原语句 | |||
condition = DEPT_ID + " in " + permissionSql; | |||
} else { | |||
condition = USER_ID + " = " + userId; | |||
} | |||
if (StringUtils.isBlank(condition)) { | |||
return sql; | |||
} | |||
Select select = (Select) CCJSqlParserUtil.parse(sql); | |||
PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); | |||
//取得原SQL的where条件 | |||
final Expression expression = plainSelect.getWhere(); | |||
//增加新的where条件 | |||
final Expression envCondition = CCJSqlParserUtil.parseCondExpression(condition); | |||
if (expression == null) { | |||
plainSelect.setWhere(envCondition); | |||
} else { | |||
AndExpression andExpression = new AndExpression(expression, envCondition); | |||
plainSelect.setWhere(andExpression); | |||
} | |||
return plainSelect.toString(); | |||
} catch (JSQLParserException e) { | |||
log.error("解析原SQL并构建新SQL错误:" + e); | |||
return sql; | |||
} | |||
} | |||
} |
@@ -0,0 +1,17 @@ | |||
package com.tuoheng.admin.data; | |||
import org.apache.kafka.common.resource.Resource; | |||
public class LazyInit { | |||
public static Resource resource; | |||
public synchronized static Resource getResource() { | |||
if (resource == null) { | |||
resource = new Resource(null, null); | |||
} | |||
return resource; | |||
} | |||
} |
@@ -0,0 +1,85 @@ | |||
package com.tuoheng.admin.mapper; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.tuoheng.admin.entity.Dept; | |||
import com.tuoheng.admin.entity.Section; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.boot.test.context.SpringBootTest; | |||
import org.springframework.test.context.junit4.SpringRunner; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
@Slf4j | |||
@RunWith(SpringRunner.class) | |||
@SpringBootTest | |||
public class DeptMapperTest { | |||
@Autowired | |||
private DeptMapper deptMapper; | |||
@Test | |||
public void testSelectAllChildListByPid() { | |||
String id = "a52c59563756fb96879b54ecb9b173f1"; | |||
String sql = buildSql(); | |||
// List<Dept> deptList = deptMapper.selectAllChildListById(id); | |||
// for (Dept dept : deptList) { | |||
// System.out.println(dept); | |||
// } | |||
List<String> deptIdList = deptMapper.selectAllChildListById(id); | |||
for (String deptId : deptIdList) { | |||
System.out.println(deptId); | |||
} | |||
} | |||
@Test | |||
public void testSelectAllChildListByPid2() { | |||
List<Dept> deptList = new ArrayList<>(); | |||
Dept dept = new Dept(); | |||
dept.setId("32b8cbc4570250b67294f46c76a6c694"); | |||
dept.setPid("0"); | |||
deptList.add(dept); | |||
queryChildDeptList(deptList, dept); | |||
for (Dept d : deptList) { | |||
System.out.println(d.getId() + "-" + d.getPid() + "-" + d.getName()); | |||
} | |||
} | |||
/** | |||
* 递归查询子部门信息 | |||
* 1、递归算法,效率比较低,考虑时间数据量不会太多,后期可优化 | |||
* 2、另一方案,通过数据库查询,根据pid,查询该部门下所有子部门及子子部门数据 | |||
*/ | |||
private void queryChildDeptList(List<Dept> deptList, Dept parentDept) { | |||
List<Dept> childDeptlist = deptMapper.selectList(new LambdaQueryWrapper<Dept>() | |||
.eq(Dept::getTenantId, 0) | |||
.eq(Dept::getPid, parentDept.getId()) | |||
.eq(Dept::getMark, 1)); | |||
for (Dept dept : childDeptlist ) { | |||
queryChildDeptList(deptList, dept); | |||
} | |||
deptList.addAll(childDeptlist); | |||
} | |||
private String buildSql() { | |||
String sql = "select id, tenant_id, name, code, fullname, type, pid, sort, note, create_user, create_time, update_user, update_time, mark\n" + | |||
" from (\n" + | |||
" select t1.id, t1.tenant_id, t1.name, t1.code, t1.fullname, t1.type, t1.pid, t1.sort, t1.note, t1.create_user, t1.create_time, t1.update_user, t1.update_time, t1.mark,\n" + | |||
" IF(FIND_IN_SET(pid, @pids) > 0, @pids <![CDATA[ := ]]> CONCAT(@pids, ',',id), 0) AS ischild\n" + | |||
" from (select id,pid,name from th_dept t where t.mark = 1) t1,\n" + | |||
" (select @pids <![CDATA[ := ]]> '32b8cbc4570250b67294f46c76a6c694') t2\n" + | |||
" ) t3\n" + | |||
" where ischild like CONCAT('%', '32b8cbc4570250b67294f46c76a6c694', '%')"; | |||
return sql; | |||
} | |||
} |
@@ -0,0 +1,27 @@ | |||
package com.tuoheng.admin.mapper; | |||
import com.tuoheng.admin.entity.Section; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.boot.test.context.SpringBootTest; | |||
import org.springframework.test.context.junit4.SpringRunner; | |||
@Slf4j | |||
@RunWith(SpringRunner.class) | |||
@SpringBootTest | |||
public class SectionMapperTest { | |||
@Autowired | |||
private SectionMapper sectionMapper; | |||
@Test | |||
public void testAdd() { | |||
Section section = new Section(); | |||
section.setRoadId("1"); | |||
section.setSectionRange("123-456"); | |||
sectionMapper.insert(section); | |||
} | |||
} |
@@ -0,0 +1,25 @@ | |||
package com.tuoheng.admin.mapper; | |||
import com.tuoheng.admin.entity.Dept; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.boot.test.context.SpringBootTest; | |||
import org.springframework.test.context.junit4.SpringRunner; | |||
import java.util.List; | |||
@Slf4j | |||
@RunWith(SpringRunner.class) | |||
@SpringBootTest | |||
public class UserMapperTest { | |||
@Autowired | |||
private UserMapper userMapper; | |||
@Test | |||
public void testSelectListByCondition() { | |||
} | |||
} |
@@ -0,0 +1,253 @@ | |||
package com.tuoheng.admin.service; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.admin.entity.RoadInformation; | |||
import com.tuoheng.admin.entity.Section; | |||
import com.tuoheng.admin.mapper.RoadInformationMapper; | |||
import com.tuoheng.admin.mapper.SectionMapper; | |||
import com.tuoheng.admin.request.dept.AddDeptRequest; | |||
import com.tuoheng.admin.dto.RoadSectionDto; | |||
import com.tuoheng.admin.request.dept.EditDeptRequest; | |||
import com.tuoheng.admin.service.dept.IDeptService; | |||
import com.tuoheng.admin.service.dept.query.QueryListTreeService; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.beans.factory.annotation.Value; | |||
import org.springframework.boot.test.context.SpringBootTest; | |||
import org.springframework.test.context.junit4.SpringRunner; | |||
import javax.annotation.Resource; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
@Slf4j | |||
@RunWith(SpringRunner.class) | |||
@SpringBootTest | |||
public class DeptServiceTest { | |||
@Autowired | |||
private IDeptService deptService; | |||
@Autowired | |||
private QueryListTreeService queryListTreeService; | |||
@Autowired | |||
private RoadInformationMapper roadInformationMapper; | |||
@Autowired | |||
private SectionMapper sectionMapper; | |||
@Value("${tuoheng.dsp-domain-url:}") | |||
private String dspDomainUrl; | |||
@Value("${tuoheng.dsp-service-inst-id:}") | |||
private String dspServiceInstId; | |||
@Test | |||
public void testGetOneById() { | |||
System.out.println("url = "); | |||
} | |||
@Test | |||
public void testGetListTree() { | |||
JsonResult result = queryListTreeService.getListTree(); | |||
log.info("-----> 获取部门树形列表:{}", result); | |||
} | |||
@Test | |||
public void testAdd() { | |||
AddDeptRequest addDeptRequest = new AddDeptRequest(); | |||
addDeptRequest.setPid("774630400fa782df1c0b38c582a9c468"); | |||
addDeptRequest.setName("拓恒-技术部-测试"); | |||
List<RoadSectionDto> roadSectionDtoList = build(); | |||
addDeptRequest.setRoadSectionDtoList(roadSectionDtoList); | |||
JSONObject json = (JSONObject) JSONObject.toJSON(addDeptRequest); | |||
log.info("-----> 新增部门:json={}", json); | |||
JsonResult result = deptService.insert(addDeptRequest); | |||
log.info("-----> 新增部门:{}", result); | |||
} | |||
private List<RoadSectionDto> build() { | |||
List<RoadSectionDto> roadSectionDtoList = new ArrayList<>(); | |||
List<RoadInformation> roadInformationList = roadInformationMapper.selectList(null); | |||
List<Section> sectionList = sectionMapper.selectList(null); | |||
RoadSectionDto roadSectionDto = null; | |||
List<Section> sectionListTmp; | |||
for (RoadInformation roadInformation : roadInformationList) { | |||
roadSectionDto = new RoadSectionDto(); | |||
sectionListTmp = new ArrayList<>(); | |||
for (Section section : sectionList) { | |||
if (section.getRoadId().equals(roadInformation.getId())) { | |||
sectionListTmp.add(section); | |||
} | |||
} | |||
roadSectionDto.setRoad(roadInformation); | |||
roadSectionDto.setSectionList(sectionListTmp); | |||
roadSectionDtoList.add(roadSectionDto); | |||
} | |||
return roadSectionDtoList; | |||
} | |||
private List<RoadSectionDto> build2() { | |||
List<RoadSectionDto> list = new ArrayList<>(); | |||
RoadSectionDto roadSectionDto = null; | |||
RoadInformation road; | |||
Section section; | |||
List<Section> sectionList; | |||
for (int i = 1; i < 4; i++) { | |||
roadSectionDto = new RoadSectionDto(); | |||
road = new RoadInformation(); | |||
road.setId(i + 1 + ""); | |||
road.setCode("G2" + 1); | |||
sectionList = new ArrayList<>(); | |||
for (int j = 1; j < 4; j++) { | |||
section = new Section(); | |||
section.setId(i + j + ""); | |||
section.setRoadId(j + ""); | |||
section.setSectionRange(road.getCode() + "-" + j); | |||
sectionList.add(section); | |||
} | |||
roadSectionDto.setRoad(road); | |||
roadSectionDto.setSectionList(sectionList); | |||
list.add(roadSectionDto); | |||
} | |||
return list; | |||
} | |||
@Test | |||
public void testEdit() { | |||
EditDeptRequest oldEeditDeptRequest = this.buildOldEditDeptRequest(); | |||
EditDeptRequest newEditDeptRequest = this.buildNewEditDeptRequest(); | |||
JSONObject oldEeditDeptRequestJson = (JSONObject) JSONObject.toJSON(oldEeditDeptRequest); | |||
log.info("-----> 修改部门:json={}", oldEeditDeptRequestJson); | |||
JSONObject newEeditDeptRequestJson = (JSONObject) JSONObject.toJSON(oldEeditDeptRequest); | |||
log.info("-----> 修改部门:json={}", oldEeditDeptRequestJson); | |||
// JsonResult result = deptService.update(oldEeditDeptRequest, newEditDeptRequest); | |||
// log.info("-----> 修改部门:{}", result); | |||
} | |||
private EditDeptRequest buildOldEditDeptRequest() { | |||
EditDeptRequest oldEeditDeptRequest = new EditDeptRequest(); | |||
oldEeditDeptRequest.setId("576f0c83faa8415148c5ee24d7da5fd3"); | |||
oldEeditDeptRequest.setPid("9e7f336d4fe1751fda497ba4cf860f37"); | |||
oldEeditDeptRequest.setName("技术部"); | |||
List<RoadSectionDto> roadSectionDtoList = new ArrayList<>(); | |||
RoadSectionDto roadSectionDto1 = this.buildRoadSectionDto1(); | |||
RoadSectionDto roadSectionDto2 = this.buildRoadSectionDto2(); | |||
roadSectionDtoList.add(roadSectionDto1); | |||
roadSectionDtoList.add(roadSectionDto2); | |||
oldEeditDeptRequest.setRoadSectionDtoList(roadSectionDtoList); | |||
return oldEeditDeptRequest; | |||
} | |||
private EditDeptRequest buildNewEditDeptRequest() { | |||
EditDeptRequest newEditDeptRequest = new EditDeptRequest(); | |||
newEditDeptRequest.setId("576f0c83faa8415148c5ee24d7da5fd3"); | |||
newEditDeptRequest.setPid("9e7f336d4fe1751fda497ba4cf860f37"); | |||
newEditDeptRequest.setName("技术部new"); | |||
List<RoadSectionDto> roadSectionDtoList = new ArrayList<>(); | |||
RoadSectionDto roadSectionDto1 = this.buildRoadSectionDto1(); | |||
RoadSectionDto roadSectionDto3 = this.buildRoadSectionDto3(); | |||
roadSectionDtoList.add(roadSectionDto1); | |||
roadSectionDtoList.add(roadSectionDto3); | |||
newEditDeptRequest.setRoadSectionDtoList(roadSectionDtoList); | |||
return newEditDeptRequest; | |||
} | |||
private RoadSectionDto buildRoadSectionDto1() { | |||
RoadSectionDto roadSectionDto = new RoadSectionDto(); | |||
RoadInformation roadInformation = new RoadInformation(); | |||
roadInformation.setId("1"); | |||
List<Section> sectionList = new ArrayList<>(); | |||
Section section1 = new Section(); | |||
section1.setId("1"); | |||
Section section2 = new Section(); | |||
section2.setId("2"); | |||
Section section3 = new Section(); | |||
section3.setId("3"); | |||
sectionList.add(section1); | |||
sectionList.add(section2); | |||
sectionList.add(section3); | |||
roadSectionDto.setRoad(roadInformation); | |||
roadSectionDto.setSectionList(sectionList); | |||
return roadSectionDto; | |||
} | |||
private RoadSectionDto buildRoadSectionDto2() { | |||
RoadSectionDto roadSectionDto = new RoadSectionDto(); | |||
RoadInformation roadInformation = new RoadInformation(); | |||
roadInformation.setId("2"); | |||
List<Section> sectionList = new ArrayList<>(); | |||
Section section1 = new Section(); | |||
section1.setId("4"); | |||
Section section2 = new Section(); | |||
section2.setId("5"); | |||
Section section3 = new Section(); | |||
section3.setId("6"); | |||
sectionList.add(section1); | |||
sectionList.add(section2); | |||
sectionList.add(section3); | |||
roadSectionDto.setRoad(roadInformation); | |||
roadSectionDto.setSectionList(sectionList); | |||
return roadSectionDto; | |||
} | |||
private RoadSectionDto buildRoadSectionDto3() { | |||
RoadSectionDto roadSectionDto = new RoadSectionDto(); | |||
RoadInformation roadInformation = new RoadInformation(); | |||
roadInformation.setId("4"); | |||
List<Section> sectionList = new ArrayList<>(); | |||
Section section = new Section(); | |||
section.setId("10"); | |||
sectionList.add(section); | |||
roadSectionDto.setRoad(roadInformation); | |||
roadSectionDto.setSectionList(sectionList); | |||
return roadSectionDto; | |||
} | |||
@Test | |||
public void testDelete() { | |||
String id = "1"; | |||
JsonResult result = deptService.deleteById(id); | |||
log.info("-----> 删除部门:{}", result); | |||
} | |||
} |
@@ -0,0 +1,45 @@ | |||
package com.tuoheng.admin.service; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.admin.dto.RoadSectionDto; | |||
import com.tuoheng.admin.entity.RoadInformation; | |||
import com.tuoheng.admin.entity.Section; | |||
import com.tuoheng.admin.mapper.RoadInformationMapper; | |||
import com.tuoheng.admin.mapper.SectionMapper; | |||
import com.tuoheng.admin.request.dept.AddDeptRequest; | |||
import com.tuoheng.admin.request.dept.EditDeptRequest; | |||
import com.tuoheng.admin.request.third.DspCallbackRequest; | |||
import com.tuoheng.admin.service.dept.IDeptService; | |||
import com.tuoheng.admin.service.dept.query.QueryListTreeService; | |||
import com.tuoheng.admin.service.third.dsp.IDspCallbackService; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.beans.factory.annotation.Value; | |||
import org.springframework.boot.test.context.SpringBootTest; | |||
import org.springframework.test.context.junit4.SpringRunner; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.Locale; | |||
@Slf4j | |||
@RunWith(SpringRunner.class) | |||
@SpringBootTest | |||
public class DspCallbackServiceTest { | |||
@Autowired | |||
private IDspCallbackService dspCallbackService; | |||
@Test | |||
public void testGetOneById() { | |||
String requestId = "dc96139337854ae78da7f20e144b3a9f"; | |||
DspCallbackRequest dspCallbackRequest = new DspCallbackRequest(); | |||
dspCallbackRequest.setAnalyseStatus(2); | |||
dspCallbackRequest.setType(1); | |||
dspCallbackService.saveCallbackData(requestId, dspCallbackRequest); | |||
} | |||
} |
@@ -0,0 +1,263 @@ | |||
package com.tuoheng.admin.service; | |||
import cn.hutool.core.util.RandomUtil; | |||
import com.alibaba.excel.EasyExcel; | |||
import com.alibaba.excel.ExcelWriter; | |||
import com.alibaba.excel.write.metadata.WriteSheet; | |||
import com.alibaba.excel.write.metadata.style.WriteCellStyle; | |||
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; | |||
import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.tuoheng.admin.dto.InspectionFileExportExcelDto; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.admin.entity.InspectionFile; | |||
import com.tuoheng.admin.enums.*; | |||
import com.tuoheng.admin.mapper.InspectionFileMapper; | |||
import com.tuoheng.admin.mapper.InspectionMapper; | |||
import com.tuoheng.admin.request.inspectionfile.QueryInspectionFilePageListRequest; | |||
import com.tuoheng.admin.service.inspectionfile.IInspectionFileService; | |||
import com.tuoheng.admin.utils.excel.*; | |||
import com.tuoheng.common.core.config.UploadFileConfig; | |||
import com.tuoheng.common.core.config.common.CommonConfig; | |||
import com.tuoheng.common.core.utils.CommonUtils; | |||
import com.tuoheng.common.core.utils.DateUtils; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.apache.poi.ss.usermodel.BorderStyle; | |||
import org.apache.poi.ss.usermodel.HorizontalAlignment; | |||
import org.apache.poi.ss.usermodel.VerticalAlignment; | |||
import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.boot.test.context.SpringBootTest; | |||
import org.springframework.test.context.junit4.SpringRunner; | |||
import java.io.File; | |||
import java.net.MalformedURLException; | |||
import java.net.URL; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
@Slf4j | |||
@RunWith(SpringRunner.class) | |||
@SpringBootTest | |||
public class InspectionFileServiceTest { | |||
@Autowired | |||
private InspectionMapper inspectionMapper; | |||
@Autowired | |||
private InspectionFileMapper inspectionFileMapper; | |||
@Autowired | |||
private IInspectionFileService iInspectionFileService; | |||
@Test | |||
public void testPageList() { | |||
QueryInspectionFilePageListRequest request = new QueryInspectionFilePageListRequest(); | |||
request.setKey(""); | |||
request.setQuestionCode("1"); | |||
request.setStatus(15); | |||
request.setDeptId(""); | |||
request.setBeginTime(DateUtils.now()); | |||
request.setEndTime(DateUtils.now()); | |||
request.setPage(1); | |||
request.setLimit(2); | |||
JSONObject json = (JSONObject) JSONObject.toJSON(request); | |||
log.info("-----> 获取分页列表请求参数:json={}", json); | |||
JsonResult result = iInspectionFileService.getPageList(request); | |||
System.out.println(">>>>>>>>>>>>>" + result); | |||
} | |||
@Test | |||
public void testAddList() { | |||
List<InspectionFile> thirstyQuestionFiles = new ArrayList<>(); | |||
InspectionFile inspectionFile; | |||
for (int i = 1; i < 2; i++) { | |||
inspectionFile = new InspectionFile(); | |||
inspectionFile.setQuestionCode(i + ""); | |||
inspectionFile.setTenantId("1"); | |||
inspectionFile.setInspectionId("1"); | |||
// 文件类型 | |||
inspectionFile.setFileType(FileTypeEnum.IMAGE.getCode()); | |||
// 文件编码 | |||
inspectionFile.setFileCode(inspectionFile.getFileCode()); | |||
// 文件名称 | |||
inspectionFile.setFileName(inspectionFile.getFileName()); | |||
//图片大小,单位MB,保留两位小数,目前没有获取图片大小的字段 | |||
inspectionFile.setFileSize(0.00); | |||
// 问题图片审核状态 | |||
inspectionFile.setStatus(QuestionEnum.NOTREVIEWED.getCode()); | |||
// 问题图片来源 | |||
inspectionFile.setSource(SourceEnum.AI.getCode()); | |||
inspectionFile.setCreateUser("1"); // 设置默认用户 | |||
inspectionFile.setCreateTime(DateUtils.now()); | |||
if (0 == 1) { | |||
inspectionFile.setMark(MarkEnum.NOTVALID.getCode()); | |||
log.info("修改问题mark值mark={}", inspectionFile.getMark()); | |||
} | |||
thirstyQuestionFiles.add(inspectionFile); | |||
} | |||
String id = RandomUtil.randomString(36); | |||
System.out.println(id); | |||
System.out.println(id.length()); | |||
CommonUtils.batchOperate((x) -> inspectionFileMapper.addBatch(x), thirstyQuestionFiles, 1000); | |||
} | |||
@Test | |||
public void testUpdate() { | |||
//查询当前问题 | |||
InspectionFile entity = inspectionFileMapper.selectOne(new LambdaQueryWrapper<InspectionFile>() | |||
.eq(InspectionFile::getId, "5l7pr9kuhfiuf8opi0h79qy2ghv6kb5093yq") | |||
.eq(InspectionFile::getMark, 1)); | |||
LambdaUpdateWrapper<InspectionFile> qw = new LambdaUpdateWrapper<>(); | |||
qw.eq(InspectionFile::getId, entity.getId()); | |||
qw.eq(InspectionFile::getMark, 1); | |||
qw.set(InspectionFile::getStatus, 15); | |||
qw.set(InspectionFile::getCheckUser, "aa"); | |||
qw.set(InspectionFile::getCheckTime, DateUtils.now()); | |||
int count = inspectionFileMapper.update(entity, qw); | |||
} | |||
@Test | |||
public void tesExport() { | |||
Inspection inspection = inspectionMapper.selectOne(Wrappers.<Inspection>lambdaQuery() | |||
.eq(Inspection::getId, 1) | |||
.eq(Inspection::getMark, MarkEnum.VALID.getCode()) | |||
.last("limit 1")); | |||
List<InspectionFile> inspectionFileList = inspectionFileMapper.selectList(Wrappers.<InspectionFile>lambdaQuery() | |||
.eq(InspectionFile::getInspectionId, 1) | |||
.eq(InspectionFile::getMark, MarkEnum.VALID.getCode()) | |||
.last("limit 1, 10")); | |||
File fd = new File(UploadFileConfig.uploadFolder + "/inspectionFile"); | |||
//目录是否存在 | |||
if(!fd.exists()){ | |||
fd.mkdirs(); | |||
} | |||
String fileName = inspection.getName()+"+"+inspection.getCode()+".xlsx"; | |||
// String filePath = "/data/java/tuoheng_waterway/inspectionFile/"; | |||
String filePath = UploadFileConfig.uploadFolder + "/inspectionFile/" + fileName; | |||
try { | |||
easyExcel(inspection, inspectionFileList, filePath); | |||
} catch (MalformedURLException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
public JsonResult easyExcel(Inspection inspection, List<InspectionFile> inspectionFileList, String filePath) throws MalformedURLException { | |||
log.info("文件输出目录及格式:filePathName={}", filePath); | |||
List<InspectionFileExportExcelDto> inspectionFileExportExcelDtoList = new ArrayList<>(); | |||
InspectionFile inspectionFile; | |||
InspectionFileExportExcelDto inspectionFileExportExcelDto; | |||
for (int i = 0; i < inspectionFileList.size(); i++) { | |||
inspectionFile = inspectionFileList.get(i); | |||
inspectionFileExportExcelDto = new InspectionFileExportExcelDto(); | |||
inspectionFileExportExcelDto.setSequence(i + 1); | |||
inspectionFileExportExcelDto.setQuestionDesc(inspectionFile.getQuestionDesc()); | |||
inspectionFileExportExcelDto.setFileOriginal(new URL(CommonConfig.imageURL + inspectionFile.getFileOriginal())); | |||
inspectionFileExportExcelDto.setFileImage(new URL(CommonConfig.imageURL + inspectionFile.getFileImage())); | |||
inspectionFileExportExcelDto.setLocation(inspectionFile.getLongitude() + "," + inspectionFile.getLatitude()); | |||
inspectionFileExportExcelDto.setSectionName(inspection.getSectionName()); | |||
inspectionFileExportExcelDto.setRoadName(inspection.getRoadName()); | |||
if (InspectionFileStatusEnum.WAIT_CONFIRMED.getCode() == inspectionFile.getStatus()) { | |||
inspectionFileExportExcelDto.setStatus("待确认"); | |||
} else if (InspectionFileStatusEnum.IGNORED.getCode() == inspectionFile.getStatus()) { | |||
inspectionFileExportExcelDto.setStatus("已忽略"); | |||
} else if (InspectionFileStatusEnum.CONFIRMED.getCode() == inspectionFile.getStatus()) { | |||
inspectionFileExportExcelDto.setStatus("已确认"); | |||
} else if (InspectionFileStatusEnum.GENERATE_ORDER.getCode() == inspectionFile.getStatus()) { | |||
inspectionFileExportExcelDto.setStatus("已生成工单"); | |||
} else if (InspectionFileStatusEnum.PROCESSED.getCode() == inspectionFile.getStatus()) { | |||
inspectionFileExportExcelDto.setStatus("已处理"); | |||
} | |||
inspectionFileExportExcelDtoList.add(inspectionFileExportExcelDto); | |||
} | |||
List<List<String>> heads = new ArrayList<>(); | |||
String totalName = "疑似问题清单"; | |||
String totalName2 = "巡检任务:" + inspection.getName() + " 巡检时间:" + inspection.getInspectionTime(); | |||
String[] nameString = {"序号", "问题类型", "问题图片", "标注图片", "位置", "所属路段", "所属高速", "状态"}; | |||
for (String excelName : nameString) { | |||
heads.add(Arrays.asList(totalName, totalName2, excelName)); | |||
} | |||
//需要写出的表格(对应实体类) | |||
try { | |||
HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(StyleUtils.getHeadStyle(), StyleUtils.getContentStyle()); | |||
EasyExcel.write(filePath, InspectionFileExportExcelDto.class).sheet("问题清单数据") | |||
.head(heads) | |||
// .registerWriteHandler(new SimpleColumnWidthStyleStrategy(20)) // 简单的列宽策略,列宽20 | |||
.registerWriteHandler(new CustomCellWriteHandler()) | |||
// .registerWriteHandler(new CustomCellWriteHeightConfig()) | |||
.registerWriteHandler(horizontalCellStyleStrategy) | |||
.registerWriteHandler(new ImageModifyHandler()) | |||
.doWrite(inspectionFileExportExcelDtoList); // 数据源 | |||
// // 内容样式 | |||
// WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); | |||
// contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); // 水平居中 | |||
// contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); // 垂直居中 | |||
// contentWriteCellStyle.setBorderLeft(BorderStyle.THIN);//细实线 | |||
// contentWriteCellStyle.setBorderTop(BorderStyle.THIN); | |||
// contentWriteCellStyle.setBorderRight(BorderStyle.THIN); | |||
// contentWriteCellStyle.setBorderBottom(BorderStyle.THIN); | |||
// | |||
// | |||
// //设计内容居中 | |||
// contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); //设置内容自动换行 | |||
// contentWriteCellStyle.setWrapped(true); | |||
// | |||
// //设置头部样式 | |||
// WriteCellStyle headWriteCellStyle = new WriteCellStyle(); | |||
// //设置头部标题居中 | |||
// headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); | |||
// // 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现 | |||
// HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle); | |||
// | |||
// // 将数据写进流,如果是响应流则写进header对应的文件里 | |||
// ExcelWriter excelWriter = EasyExcel.write(filePath, InspectionFileExportExcelDto.class).build(); | |||
// | |||
// //指定sheet的名字和头信息 | |||
// WriteSheet writeSheet = EasyExcel.writerSheet(0, "日历导出") | |||
// .head(heads) | |||
// .registerWriteHandler(new SimpleColumnWidthStyleStrategy(20)) | |||
// .registerWriteHandler(horizontalCellStyleStrategy) | |||
// .registerWriteHandler(new CustomCellWriteHandler()) | |||
//// .registerWriteHandler(new CustomCellWriteHeightConfig()) | |||
// .registerWriteHandler(new ImageModifyHandler()) | |||
// .build(); | |||
// //将数据真正写入excel中 | |||
// excelWriter.write(inspectionFileExportExcelDtoList, writeSheet); | |||
// //千万别忘记finish 会帮忙关闭流 | |||
// excelWriter.finish(); | |||
} catch (Exception e) { | |||
log.info("生成数据导出excel异常"); | |||
throw new RuntimeException(e); | |||
} | |||
log.info("开始写入表格中"); | |||
return JsonResult.success(); | |||
} | |||
} |
@@ -0,0 +1,148 @@ | |||
package com.tuoheng.admin.service; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.admin.enums.MarkEnum; | |||
import com.tuoheng.admin.mapper.InspectionMapper; | |||
import com.tuoheng.admin.request.inspection.AddInspectionRequest; | |||
import com.tuoheng.admin.request.inspection.EditInspectionRequest; | |||
import com.tuoheng.admin.request.inspection.MissionStatusRequest; | |||
import com.tuoheng.admin.request.inspection.QueryInspectionPageListRequest; | |||
import com.tuoheng.admin.service.inspection.IInspectionService; | |||
import com.tuoheng.admin.service.inspection.update.status.UpdateFlightStatusService; | |||
import com.tuoheng.common.core.utils.DateUtils; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.boot.test.context.SpringBootTest; | |||
import org.springframework.test.context.junit4.SpringRunner; | |||
@Slf4j | |||
@RunWith(SpringRunner.class) | |||
@SpringBootTest | |||
public class InspectionServiceTest { | |||
@Autowired | |||
private InspectionMapper inspectionMapper; | |||
@Autowired | |||
private IInspectionService iInspectionService; | |||
@Autowired | |||
private UpdateFlightStatusService updateFlightStatusService; | |||
@Test | |||
public void testPageList() { | |||
QueryInspectionPageListRequest request = new QueryInspectionPageListRequest(); | |||
// request.setKey("1"); | |||
request.setAirportId(1); // 巡检机场id | |||
request.setInspectionLine(1); // 巡检线路Id | |||
request.setType(1); // 巡检任务类型: 1 临时巡检(目前只有该一种类型) | |||
request.setStatus(5); // 任务状态 5任务待飞行 7飞行失败 10任务飞行中 15任务飞行完成 | |||
request.setInspectionType(1); // 1 无人机 2机场 | |||
request.setDeptId(""); | |||
request.setPage(1); | |||
request.setLimit(2); | |||
JSONObject json = (JSONObject) JSONObject.toJSON(request); | |||
log.info("-----> 获取分页列表请求参数:json={}", json); | |||
JsonResult result = iInspectionService.selectPageList(request); | |||
System.out.println(">>>>>>>>>>>>>" + result); | |||
} | |||
@Test | |||
public void testAdd() { | |||
AddInspectionRequest request = new AddInspectionRequest(); | |||
request.setType(1); | |||
request.setName("test-2022112501-11"); | |||
request.setRoadId("1"); | |||
request.setRoadName("G2"); | |||
request.setSectionId("1"); | |||
request.setSectionName("路段1"); | |||
request.setInspectionType(1); | |||
request.setAirportId(1); | |||
request.setAirportName("禄口-2022112501"); | |||
request.setInspectionLine(1); | |||
request.setInspectionLineName("路线1"); | |||
request.setInspectionTime(DateUtils.now()); | |||
JSONObject json = (JSONObject) JSONObject.toJSON(request); | |||
log.info("-----> 新增任务请求参数:json={}", json); | |||
JsonResult result = iInspectionService.insert(request); | |||
System.out.println(">>>>>>>>>>>>>" + result); | |||
} | |||
@Test | |||
public void testEdit() { | |||
EditInspectionRequest request = new EditInspectionRequest(); | |||
request.setId("54601a9f13236dd3b5151db5ebdb0794"); | |||
request.setType(1); | |||
request.setName("test1"); | |||
request.setRoadId("1"); | |||
request.setSectionId("1"); | |||
request.setInspectionType(1); | |||
request.setAirportId(1); | |||
request.setAirportName("禄口1"); | |||
request.setInspectionLine(1); | |||
request.setInspectionLineName("路线11"); | |||
request.setInspectionTime(DateUtils.now()); | |||
request.setNote("test"); | |||
JsonResult result = iInspectionService.update(request); | |||
System.out.println(">>>>>>>>>>>>>" + result); | |||
} | |||
@Test | |||
public void testDelete() { | |||
String id = "e69b6f5050c9106dfa37fea1a5c3fc15"; | |||
JsonResult result = iInspectionService.deleteById(id); | |||
System.out.println(">>>>>>>>>>>>>" + result); | |||
} | |||
@Test | |||
public void testResubmit() { | |||
EditInspectionRequest request = new EditInspectionRequest(); | |||
request.setId("1f2ed1f784eb36165785d5235350ef7d"); | |||
request.setCode("XJRW20221130092941"); | |||
request.setType(1); | |||
request.setInspectionType(2); | |||
request.setName("test1"); | |||
request.setRoadId("1"); | |||
request.setRoadName("G2"); | |||
request.setSectionId("1"); | |||
request.setSectionName("路段1"); | |||
request.setAirportId(1); | |||
request.setAirportName("禄口1"); | |||
request.setInspectionLine(1); | |||
request.setInspectionLineName("路线11"); | |||
request.setIsLive(1); | |||
request.setStartLatitude("11"); | |||
request.setStartLongitude("11"); | |||
request.setEndLongitude("22"); | |||
request.setEndLatitude("22"); | |||
request.setInspectionTime(DateUtils.now()); | |||
request.setNote("test"); | |||
JSONObject json = (JSONObject) JSONObject.toJSON(request); | |||
log.info("-----> 重新提交请求参数:json={}", json); | |||
JsonResult result = iInspectionService.resubmit(request); | |||
System.out.println(">>>>>>>>>>>>>" + result); | |||
} | |||
@Test | |||
public void test22() { | |||
Inspection inspection = inspectionMapper.selectOne(new LambdaQueryWrapper<Inspection>() | |||
.eq(Inspection::getMark, MarkEnum.VALID.getCode()) | |||
.eq(Inspection::getId, "4fb3d92882b908a760b23f3b6431b32a") | |||
.eq(Inspection::getInspectionLine, 55)); | |||
MissionStatusRequest missionStatusRequest = new MissionStatusRequest(); | |||
missionStatusRequest.setStatus(2); | |||
updateFlightStatusService.updateFlightStatus(inspection, missionStatusRequest); | |||
} | |||
} |
@@ -0,0 +1,80 @@ | |||
package com.tuoheng.admin.service; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.admin.entity.User; | |||
import com.tuoheng.admin.service.user.IUserService; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.boot.test.context.SpringBootTest; | |||
import org.springframework.test.context.junit4.SpringRunner; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
@Slf4j | |||
@RunWith(SpringRunner.class) | |||
@SpringBootTest | |||
public class UserServiceTest { | |||
@Autowired | |||
private IUserService userService; | |||
@Test | |||
public void testAdd() { | |||
User user = User.builder().build() | |||
.setCode("TH1001") | |||
.setUsername("1001") | |||
.setRealname("1001") | |||
.setMobile("13812456325") | |||
.setRoleId(1) | |||
.setDeptId("1") | |||
.setClientId("1") | |||
.setNote("test"); | |||
JSONObject json = (JSONObject) JSONObject.toJSON(user); | |||
log.info("-----> 新增用户:json={}", json); | |||
JsonResult result = userService.add(user); | |||
log.info("-----> 新增用户:{}", result); | |||
} | |||
@Test | |||
public void testEdit() { | |||
User user = User.builder().build() | |||
.setId("4c188b54f5f8fb34f3b71a064f48c8af") | |||
.setCode("TH1001") | |||
.setRealname("1001111") | |||
.setRoleId(2) | |||
.setDeptId("2") | |||
.setClientId("1,2") | |||
.setNote("test1111"); | |||
JSONObject json = (JSONObject) JSONObject.toJSON(user); | |||
log.info("-----> 修改用户:json={}", user); | |||
JsonResult result = userService.edit(user); | |||
log.info("-----> 修改用户:{}", result); | |||
} | |||
@Test | |||
public void testResetPassword() { | |||
String id = ""; | |||
JsonResult result = userService.resetPassword(id); | |||
} | |||
@Test | |||
public void testDelete() { | |||
String id = "1"; | |||
List<String> list = new ArrayList<>(); | |||
list.add("1"); | |||
list.add("1"); | |||
JsonResult result = userService.deleteByIdList(list); | |||
log.info("-----> 删除用户:{}", result); | |||
} | |||
} |
@@ -5,7 +5,6 @@ import com.tuoheng.common.core.config.common.CommonConfig; | |||
import com.tuoheng.common.core.utils.HttpUtils; | |||
import com.tuoheng.common.core.utils.JacksonUtil; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import com.tuoheng.miniprogram.dao.TenantMapper; | |||
import com.tuoheng.miniprogram.entity.Tenant; | |||
import com.tuoheng.miniprogram.enums.AriportCodeEnum; |