Commit 5334091c authored by 李秀明's avatar 李秀明

Merge remote-tracking branch 'origin/develop_dl' into develop_dl

parents 243e58ac 1f71f1a3
......@@ -82,6 +82,6 @@
FROM
asf_fire_equipment_signal_log
WHERE
FIND_IN_SET(#{mrid,jdbcType=VARCHAR}, system_mrids)
_IN_SET(#{mrid,jdbcType=VARCHAR}, system_mrids)
</select>
</mapper>
package com.yeejoin.equipmanage.controller;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.equipmanage.common.entity.Alarm;
import com.yeejoin.equipmanage.common.utils.NameUtils;
import com.yeejoin.equipmanage.config.PersonIdentify;
import com.yeejoin.equipmanage.service.IAlarmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import liquibase.pro.packaged.O;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
*
......@@ -32,6 +44,9 @@ public class AlarmController {
@Autowired
IAlarmService iAlarmService;
@Autowired
RedisUtils redisUtils;
/**
* 新增
*
......@@ -59,7 +74,7 @@ public class AlarmController {
/**
* 修改
*
*
* @return
*/
@RequestMapping(value = "/updateById", method = RequestMethod.PUT)
......@@ -128,4 +143,45 @@ public class AlarmController {
page = iAlarmService.page(pageBean, alarmQueryWrapper);
return page;
}
/**
* 设备平台告警数量统计,按系统
*
* @return
*/
@PersonIdentify
@RequestMapping(value = "/totalAlarmNum", method = RequestMethod.GET)
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "设备平台告警数量统计,按系统", notes = "设备平台告警数量统计,按系统")
public ResponseModel<Object> totalAlarmNum(String bizOrgCode, String systemId) {
if(StringUtils.isEmpty(bizOrgCode)) {
ReginParams reginParams = JSONObject.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId(), RequestContext.getToken())).toString(), ReginParams.class);
bizOrgCode = reginParams.getPersonIdentity().getBizOrgCode();
}
return ResponseHelper.buildResponse(iAlarmService.totalNum(bizOrgCode, systemId));
}
/**
* 设备告警信息导出
*
* @return
*/
@RequestMapping(value = "/downList", method = RequestMethod.GET)
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "告警信息导出", notes = "告警信息导出")
public void downList(HttpServletResponse response, @RequestParam(required = false) List<String> types,
@RequestParam(required = false) List<String> emergencyLevels,
@RequestParam(required = false) String name,
@RequestParam(required = false) Integer cleanStatus,
@RequestParam(required = false) Integer handleStatus,
@RequestParam(required = false) String bizOrgCode,
@RequestParam(required = false) String systemCode,
@RequestParam(required = false) String createDate,
@RequestParam(required = false) String startDate,
@RequestParam(required = false) String endDate ) {
iAlarmService.downList(response,bizOrgCode, systemCode, types, emergencyLevels, name, cleanStatus, handleStatus, createDate, startDate, endDate);
}
}
......@@ -707,7 +707,9 @@ public class EmergencyController extends AbstractBaseController {
@RequestParam(required = false) Integer handleStatus,
@RequestParam(required = false) String bizOrgCode,
@RequestParam(required = false) String systemCode,
@RequestParam(required = false) String createDate
@RequestParam(required = false) String createDate,
@RequestParam(required = false) String startDate,
@RequestParam(required = false) String endDate
) {
Page<Map<String, Object>> page = new Page<>(pageNumber, pageSize);
if (StringUtils.isEmpty(bizOrgCode)) {
......@@ -720,7 +722,7 @@ public class EmergencyController extends AbstractBaseController {
}
}
}
return CommonResponseUtil.success(iEmergencyService.alarmList(page, bizOrgCode, systemCode, types, emergencyLevels, name, cleanStatus, handleStatus, createDate));
return CommonResponseUtil.success(iEmergencyService.alarmList(page, bizOrgCode, systemCode, types, emergencyLevels, name, cleanStatus, handleStatus, createDate, startDate, endDate));
}
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
......
package com.yeejoin.equipmanage.dto;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
@Data
public class AlarmExportDto {
@ExcelProperty(value = "设备名称", index = 0)
private String equipmentSpecificName;
@ExcelProperty(value = "类型", index = 1)
private String type;
@ExcelProperty(value = "等级", index = 2)
private String emergencyLevelDescribe;
@ExcelProperty(value = "消除状态", index = 3)
private String cleanStatus;
@ExcelProperty(value = "时间", index = 4)
private String createDate;
@ExcelProperty(value = "所在位置", index = 5)
private String location;
@ExcelProperty(value = "告警确认", index = 6)
private String handleStatus;
}
......@@ -2,6 +2,10 @@ package com.yeejoin.equipmanage.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.equipmanage.common.entity.Alarm;
import liquibase.pro.packaged.S;
import java.util.List;
import java.util.Map;
/**
* Mapper 接口
......@@ -11,4 +15,5 @@ import com.yeejoin.equipmanage.common.entity.Alarm;
*/
public interface AlarmMapper extends BaseMapper<Alarm> {
List<Map<String,String>> totalNum(String bizOrgCode, String systemId);
}
......@@ -107,7 +107,9 @@ public interface EmergencyMapper extends BaseMapper{
* @param name 设备名称
* @return
*/
Page<Map<String, Object>> alarmList(@Param("page") Page<Map<String, Object>> page, @Param("bizOrgCode") String bizOrgCode, @Param("systemCode") String systemCode, @Param("types") List<String> types, @Param("emergencyLevels") List<String> emergencyLevels, @Param("name") String name, @Param("cleanStatus") Integer cleanStatus, @Param("handleStatus") Integer handleStatus , @Param("createDate") String createDate);
Page<Map<String, Object>> alarmList(@Param("page") Page<Map<String, Object>> page, @Param("bizOrgCode") String bizOrgCode, @Param("systemCode") String systemCode, @Param("types") List<String> types, @Param("emergencyLevels") List<String> emergencyLevels, @Param("name") String name, @Param("cleanStatus") Integer cleanStatus, @Param("handleStatus") Integer handleStatus , @Param("createDate") String createDate , @Param("startDate") String startDate , @Param("endDate") String endDate);
List<Map<String, Object>> alarmListNoPage( @Param("bizOrgCode") String bizOrgCode, @Param("systemCode") String systemCode, @Param("types") List<String> types, @Param("emergencyLevels") List<String> emergencyLevels, @Param("name") String name, @Param("cleanStatus") Integer cleanStatus, @Param("handleStatus") Integer handleStatus , @Param("createDate") String createDate , @Param("startDate") String startDate , @Param("endDate") String endDate);
IPage<EquipTypeImgAmountVO> getEmergencyEquipList(@Param("page") IPage page, @Param("equipTypeAmountPage") EquipTypeAmountPageDTO equipTypeAmountPage, @Param("list") List<String> list);
......
package com.yeejoin.equipmanage.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yeejoin.equipmanage.common.entity.Alarm;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* 服务类
*
......@@ -11,4 +16,7 @@ import com.yeejoin.equipmanage.common.entity.Alarm;
*/
public interface IAlarmService extends IService<Alarm> {
List<Map<String,String>> totalNum(String bizOrgCode, String systemId);
void downList(HttpServletResponse response, String bizOrgCode, String systemCode, List<String> types, List<String> emergencyLevels, String name, Integer cleanStatus, Integer handleStatus, String createDate, String startDate, String endDate);
}
......@@ -69,7 +69,7 @@ public interface IEmergencyService {
List<Map<String, Object>> getPressurePumpDiagnosticAnalysis(String bizOrgCode);
Page<Map<String, Object>> alarmList(Page<Map<String, Object>> page,String bizOrgCode, String systemCode, List<String> types, List<String> emergencyLevels, String name, Integer cleanStatus, Integer handleStatus,String createDate);
Page<Map<String, Object>> alarmList(Page<Map<String, Object>> page,String bizOrgCode, String systemCode, List<String> types, List<String> emergencyLevels, String name, Integer cleanStatus, Integer handleStatus,String createDate,String startDate,String endDate);
Map<String, List<PressurePumpCountVo>> getPressurePumpDay();
......
package com.yeejoin.equipmanage.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yeejoin.amos.boot.biz.common.excel.ExcelUtil;
import com.yeejoin.equipmanage.common.entity.Alarm;
import com.yeejoin.equipmanage.common.vo.EquipmentAlarmDownloadVO;
import com.yeejoin.equipmanage.dto.AlarmExportDto;
import com.yeejoin.equipmanage.mapper.AlarmMapper;
import com.yeejoin.equipmanage.mapper.EmergencyMapper;
import com.yeejoin.equipmanage.service.IAlarmService;
import liquibase.pro.packaged.L;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 服务实现类
*
......@@ -15,4 +29,30 @@ import org.springframework.stereotype.Service;
@Service
public class AlarmServiceImpl extends ServiceImpl<AlarmMapper, Alarm> implements IAlarmService {
@Autowired
AlarmMapper alarmMapper;
@Autowired
EmergencyMapper emergencyMapper;
@Override
public void downList(HttpServletResponse response, String bizOrgCode, String systemCode, List<String> types, List<String> emergencyLevels, String name, Integer cleanStatus, Integer handleStatus, String createDate, String startDate, String endDate) {
List<Map<String, Object>> list = emergencyMapper.alarmListNoPage(bizOrgCode, systemCode, types, emergencyLevels, name, cleanStatus, handleStatus, createDate, startDate, endDate);
List<AlarmExportDto> alarmExportDtoList = new ArrayList<>();
if(list.size() > 0) {
for (Map m :list
) {
String s = JSONObject.toJSONString(m);
AlarmExportDto dto = JSONObject.parseObject(s, AlarmExportDto.class);
alarmExportDtoList.add(dto);
}
ExcelUtil.createTemplate(response, "设备告警信息", "设备告警信息", alarmExportDtoList, AlarmExportDto.class, null, false);
}
}
@Override
public List<Map<String,String>> totalNum(String bizOrgCode, String systemId) {
return alarmMapper.totalNum(bizOrgCode, systemId);
}
}
......@@ -627,8 +627,8 @@ public class EmergencyServiceImpl implements IEmergencyService {
@Override
public Page<Map<String, Object>> alarmList(Page<Map<String, Object>> page, String bizOrgCode, String systemCode, List<String> types, List<String> emergencyLevels, String name, Integer cleanStatus, Integer handleStatus,String createDate) {
return emergencyMapper.alarmList(page, bizOrgCode, systemCode, types, emergencyLevels, name, cleanStatus, handleStatus, createDate);
public Page<Map<String, Object>> alarmList(Page<Map<String, Object>> page, String bizOrgCode, String systemCode, List<String> types, List<String> emergencyLevels, String name, Integer cleanStatus, Integer handleStatus,String createDate,String startDate,String endDate) {
return emergencyMapper.alarmList(page, bizOrgCode, systemCode, types, emergencyLevels, name, cleanStatus, handleStatus, createDate, startDate, endDate);
}
//稳压泵定时向缓存中存昨日启动次数任务
......
......@@ -2,4 +2,35 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeejoin.equipmanage.mapper.AlarmMapper">
<select id="totalNum" resultType="java.util.Map">
SELECT count(*) num, 'qlgj' as code from wl_equipment_specific_alarm_log a
where a.biz_org_code = #{bizOrgCode}
<if test="systemId != null and systemId !=''">
and FIND_IN_SET(#{systemId},a.system_ids)
</if>
UNION ALL
SELECT count(*) num, 'wfggj' as code from wl_equipment_specific_alarm_log a where a.`status` = 1
and a.biz_org_code = #{bizOrgCode}
<if test="systemId != null and systemId !=''">
and FIND_IN_SET(#{systemId},a.system_ids)
</if>
UNION ALL
SELECT count(*) num, 'hzgj' as code from wl_equipment_specific_alarm_log a where a.`type` = 'FIREALARM'
and a.biz_org_code = #{bizOrgCode}
<if test="systemId != null and systemId !=''">
and FIND_IN_SET(#{systemId},a.system_ids)
</if>
UNION ALL
SELECT count(*) num, 'gzgj' as code from wl_equipment_specific_alarm_log a where a.`type` = 'BREAKDOWN'
and a.biz_org_code = #{bizOrgCode}
<if test="systemId != null and systemId !=''">
and FIND_IN_SET(#{systemId},a.system_ids)
</if>
UNION ALL
SELECT count(*) num, 'pbgj' as code from wl_equipment_specific_alarm_log a where a.`type` = 'SHIELD'
and a.biz_org_code = #{bizOrgCode}
<if test="systemId != null and systemId !=''">
and FIND_IN_SET(#{systemId},a.system_ids)
</if>
</select>
</mapper>
......@@ -1422,6 +1422,7 @@
wlesal.equipment_specific_code AS code,
wlesal.equipment_specific_index_key AS fireEquipmentSpecificIndexKey,
wlesal.equipment_specific_index_name AS fireEquipmentSpecificIndexName,
wlesal.emergency_level_color AS emergencyLevelColor,
CASE wlesal.equipment_specific_index_value
WHEN 'true' THEN '是'
WHEN 'false' THEN '否'
......@@ -1453,6 +1454,12 @@
<if test='createDate != null and createDate == "1"'>
AND wlesal.create_date LIKE CONCAT( DATE_FORMAT( NOW( ), '%Y-%m-%d' ), '%' )
</if>
<if test='startDate != null and startDate == ""'>
AND wlesal.create_date >= DATE_FORMAT( ${startDate}, '%Y-%m-%d %H:%i:%s' )
</if>
<if test='endDate != null and endDate == ""'>
AND DATE_FORMAT( ${endDate}, '%Y-%m-%d %H:%i:%s' ) >= wlesal.create_date
</if>
<if test="systemCode != null and systemCode != ''">
and fs.code = #{systemCode}
</if>
......@@ -1486,6 +1493,86 @@
wlesal.create_date DESC
</select>
<select id="alarmListNoPage" resultType="java.util.Map">
SELECT
wlesal.id,
concat(wlesal.equipment_specific_name, wlesal.equipment_specific_index_name) AS alamContent,
IF (wlesal.confirm_type IS NULL, '未确认', '已确认') handleStatus,
IF (wlesal.clean_time IS NOT NULL, '已消除', '未消除' ) cleanStatus,
wlesal.equipment_index_id AS fireEquipmentIndexId,
wlesal.equipment_specific_code AS code,
wlesal.equipment_specific_index_key AS fireEquipmentSpecificIndexKey,
wlesal.equipment_specific_index_name AS fireEquipmentSpecificIndexName,
CASE wlesal.equipment_specific_index_value
WHEN 'true' THEN '是'
WHEN 'false' THEN '否'
ELSE wlesal.equipment_specific_index_value
END AS fireEquipmentPointValue,
wlesal.type AS typeCode,
(
SELECT
type_name
FROM
wl_signal_classify sc
WHERE
sc.type_code = wlesal.type
LIMIT 1
) AS type,
wlesal.equipment_specific_name AS equipmentSpecificName,
wlesal.location,
date_format(wlesal.create_date, '%Y-%m-%d %H:%i:%s') createDate,
wlesal.emergency_level_describe AS emergencyLevelDescribe,
fs.name AS systemName
FROM
wl_equipment_specific_alarm_log wlesal
LEFT JOIN wl_equipment_specific wes ON wes.id = wlesal.equipment_specific_id
LEFT JOIN f_fire_fighting_system fs ON FIND_IN_SET( fs.id, wlesal.system_ids )
<where>
<if test="bizOrgCode != null and bizOrgCode != ''">
and wlesal.biz_org_code like concat(#{bizOrgCode},'%')
</if>
<if test='createDate != null and createDate == "1"'>
AND wlesal.create_date LIKE CONCAT( DATE_FORMAT( NOW( ), '%Y-%m-%d' ), '%' )
</if>
<if test='startDate != null and startDate == ""'>
AND wlesal.create_date >= DATE_FORMAT( ${startDate}, '%Y-%m-%d %H:%i:%s' )
</if>
<if test='endDate != null and endDate == ""'>
AND DATE_FORMAT( ${endDate}, '%Y-%m-%d %H:%i:%s' ) >= wlesal.create_date
</if>
<if test="systemCode != null and systemCode != ''">
and fs.code = #{systemCode}
</if>
<if test="name != null and name != ''">
and wlesal.equipment_specific_name like concat('%', #{name},'%')
</if>
<if test="cleanStatus != null and cleanStatus != '' and cleanStatus == 2">
and wlesal.clean_time IS NULL
</if>
<if test="cleanStatus != null and cleanStatus != '' and cleanStatus == 1">
and wlesal.clean_time IS NOT NULL
</if>
<if test="handleStatus != null and handleStatus != '' and handleStatus == 2">
and wlesal.confirm_type IS NULL
</if>
<if test="handleStatus != null and handleStatus != '' and handleStatus == 1">
and wlesal.confirm_type IS NOT NULL
</if>
<if test="types != null">
<foreach collection="types" index="index" item="item" open="and (" separator=" OR " close=")">
wlesal.type = #{item}
</foreach>
</if>
<if test="emergencyLevels != null">
<foreach collection="emergencyLevels" index="index" item="item" open="and (" separator=" OR " close=")">
wlesal.emergency_level = #{item}
</foreach>
</if>
</where>
ORDER BY
wlesal.create_date DESC
</select>
<select id="getEmergencyMaterials" resultType="java.util.Map">
SELECT
*
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>amos-boot-utils</artifactId>
<groupId>com.amosframework.boot</groupId>
<version>1.0.0</version>
</parent>
<artifactId>amos-boot-utils-adpter</artifactId>
<properties>
<tyboot.version>1.1.23-SNAPSHOT</tyboot.version>
</properties>
<dependencies>
<dependency>
<groupId>com.amosframework.boot</groupId>
<artifactId>amos-boot-core</artifactId>
<version>${amos-biz-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<artifactId>mysql-connector-java</artifactId>
<groupId>mysql</groupId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.yeejoin.amos;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import java.net.InetAddress;
import java.net.UnknownHostException;
/**
* <pre>
* 服务启动类
* </pre>
*
* @author amos
* @version $Id: AmosBootUtilsAdpterApplication, v 0.1 2024年5月7日 下午4:56:29 amos Exp $
*/
@SpringBootApplication
@EnableConfigurationProperties
@ServletComponentScan
@EnableDiscoveryClient
@EnableFeignClients
@EnableAsync
@EnableEurekaClient
@ComponentScan({"org.typroject","com.yeejoin.amos"})
public class AmosBootUtilsAdpterApplication {
private static final Logger logger = LoggerFactory.getLogger(AmosBootUtilsAdpterApplication.class);
public static void main(String[] args) throws UnknownHostException {
ConfigurableApplicationContext context = SpringApplication.run(AmosBootUtilsAdpterApplication.class, args);
Environment env = context.getEnvironment();
String ip = InetAddress.getLocalHost().getHostAddress();
String port = env.getProperty("server.port");
String path = env.getProperty("server.servlet.context-path");
logger.info("\n----------------------------------------------------------\n\t" +
"Application Amos-Biz-Boot is running! Access URLs:\n\t" +
"Swagger文档: \thttp://" + ip + ":" + port + path + "/doc.html\n" +
"----------------------------------------------------------");
}
}
package com.yeejoin.amos.adpter.controller;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.adpter.service.AdpterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* 同步接口
*
* @author system_generator
* @date 2021-06-29
*/
@RestController
@Slf4j
@Api(tags = "同步接口Api")
@RequestMapping(value = "/adpter")
public class AdpterController {
@Autowired
AdpterService adpterService;
/**
* 同步接口Api
*
* @return
*/
@GetMapping(value = "/tran")
@ApiOperation(httpMethod = "GET", value = "同步接口Api", notes = "同步接口Api")
public Map<String,String> tran() {
Map<String, String> handle = adpterService.handle();
return handle;
}
}
\ No newline at end of file
package com.yeejoin.amos.adpter.service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class AdpterService {
private final static Logger log = LoggerFactory.getLogger(AdpterService.class);
//开始时间
private static Long startTime = 0L;
//结束时间
private static Long endTime =0L;
@Value("${source.jdbc.ip}")
String sourceJdbc;
@Value("${goal.jdbc.ip}")
String goalJdbc;
@Value("${source.jdbc.ip.idx}")
String sourceJdbcIdx;
@Value("${goal.jdbc.ip.idx}")
String goalJdbcIdx;
@Value("${source.jdbc.ip.buss}")
String sourceJdbcBuss;
@Value("${goal.jdbc.ip.buss}")
String goalJdbcBuss;
String driver = "com.mysql.cj.jdbc.Driver";
@Value("${yeejoin.user}")
String userName;
@Value("${yeejoin.pwd}")
String pwd;
public Map<String, String> handle() {
Map<String,String> rMap = new HashMap<>();
// 处理common库
copy(sourceJdbc, goalJdbc, "cb_firefighters", "cb_firefighters", "sequence_nbr", rMap);
copy(sourceJdbc, goalJdbc, "cb_org_usr", "cb_org_usr", "sequence_nbr", rMap);
copy(sourceJdbc, goalJdbc, "cb_water_resource", "cb_water_resource", "sequence_nbr", rMap);
copy(sourceJdbc, goalJdbc, "cb_water_resource_crane", "cb_water_resource_crane", "sequence_nbr", rMap);
copy(sourceJdbc, goalJdbc, "cb_water_resource_hydrant", "cb_water_resource_hydrant", "sequence_nbr", rMap);
copy(sourceJdbc, goalJdbc, "cb_water_resource_index", "cb_water_resource_index", "sequence_nbr", rMap);
copy(sourceJdbc, goalJdbc, "cb_water_resource_iot", "cb_water_resource_iot", "sequence_nbr", rMap);
copy(sourceJdbc, goalJdbc, "cb_water_resource_natural", "cb_water_resource_natural", "sequence_nbr", rMap);
copy(sourceJdbc, goalJdbc, "cb_water_resource_pool", "cb_water_resource_pool", "sequence_nbr", rMap);
// 处理 idx库
copy(sourceJdbcIdx, goalJdbcIdx, "cb_org_usr", "cb_org_usr", "sequence_nbr", rMap);
copy(sourceJdbcIdx, goalJdbcIdx, "idx_biz_unit_person", "idx_biz_unit_person", "SEQUENCE_NBR", rMap);
// 处理business
copy(sourceJdbcBuss, goalJdbcBuss, "f_equipment", "f_equipment", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "cb_org_usr", "cb_org_usr", "sequence_nbr", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "cb_water_resource", "cb_water_resource", "sequence_nbr", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "f_equipment_fire_equipment", "f_equipment_fire_equipment", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "f_fire_fighting_system", "f_fire_fighting_system", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "p_input_item", "p_input_item", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "p_plan", "p_plan", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "p_plan_exec_statistics", "p_plan_exec_statistics", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "p_plan_task", "p_plan_task", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "p_plan_task_detail", "p_plan_task_detail", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "p_point", "p_point", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "p_point_classify", "p_point_classify", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "p_point_inputitem", "p_point_inputitem", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "p_point_photo", "p_point_photo", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "p_route", "p_route", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "p_route_point", "p_route_point", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "p_point_config", "p_point_config", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "p_route_point_item", "p_route_point_item", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "wl_car", "wl_car", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "wl_car_property", "wl_car_property", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "wl_dynamic_form_instance", "wl_dynamic_form_instance", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "wl_equipment_detail", "wl_equipment_detail", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "wl_equipment_specific", "wl_equipment_specific", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "wl_equipment_specific_index", "wl_equipment_specific_index", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "wl_form_instance", "wl_form_instance", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "wl_form_instance_equip", "wl_form_instance_equip", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "wl_warehouse", "wl_warehouse", "id", rMap);
copy(sourceJdbcBuss, goalJdbcBuss, "wl_warehouse_structure", "wl_warehouse_structure", "id", rMap);
log.info("执行结束================");
return rMap;
}
/**
* 获取数据库连接
* @param
* @return
*/
public Connection getConnection(String jdbc) {
//加载驱动
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
String jdbcUrl = jdbc;
String user = userName;
String password = pwd;
//链接数据库
try {
return DriverManager.getConnection(jdbcUrl, user, password);
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException("连接数据库失败");
}
}
/**
* 将查询的数据复制到另一个数据库的表中,要求两张表的字段名,字段类型完全相同。
* @param srcTableName 要查询的表
* @param destTableName 目标表名称
* @return
*/
public int[] copy(String source, String goal, String srcTableName, String destTableName ,String id, Map rMap) {
startTime = System.currentTimeMillis();
Connection conn = null;
PreparedStatement pst = null;
conn = getConnection(goal);
int count[] = new int[0];
List<String> list = new ArrayList<>();
//查询数据
String sql = String.format("select * from %s ", srcTableName);
//查询数据
String sqlGoal = "select count(*) as num from "+ destTableName +" where "+id+" = ";
List<Map<String,Object>> queryOld = query(source, sql);
List<Map<String,Object>> query = new ArrayList<>();
//插入数据
String insertSql = "insert into %s(%s) values(%s)";
StringBuilder key = new StringBuilder();
StringBuilder value = new StringBuilder();
List<String> columns = new ArrayList<>();
List<List<Object>> params = new ArrayList<>();
// 剔除已存在的数据
for (Map map:queryOld
) {
try {
pst = conn.prepareStatement(sqlGoal+map.get(id));
ResultSet resultSet = pst.executeQuery();
while (resultSet.next()) {
int num = resultSet.getInt("num");
if(num < 1) {
query.add(map);
} else {
list.add(map.get(id).toString());
}
}
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
if(query.size() > 0) {
for(String column : query.get(0).keySet()) {
key.append(column).append(",");
value.append("?,");
columns.add(column);
}
insertSql = String.format(insertSql,
destTableName,
key.substring(0, key.length()-1).toString(),
value.substring(0, value.length()-1).toString());
for (Map<String, Object> map : query) {
List<Object> param = new ArrayList<>();
for (String column : columns) {
param.add(map.get(column));
}
params.add(param);
}
count = executeBatch(goal, insertSql, params, destTableName);
endTime = System.currentTimeMillis();
log.debug("复制表"+destTableName+"成功"+"用时"+(endTime-startTime)+"ms");
}
if(list.size()>0) {
rMap.put(destTableName, String.join(",", list));
} else {
rMap.put(destTableName, "复制表"+destTableName+"成功"+"用时"+(endTime-startTime)+"ms");
}
return count;
}
/**
* 批量执行一个 SQL 语句,可以传不同的参数
* @param sql SQL 语句
* @param params 参数列表
* @return
*/
public int[] executeBatch(String goal, String sql, List<List<Object>> params, String destTableName) {
int count[] = new int[0];
Connection conn = null;
PreparedStatement pst = null;
try {
conn = getConnection(goal);
boolean autoCommit = conn.getAutoCommit();
conn.setAutoCommit(false);
pst = conn.prepareStatement(sql);
for (List<Object> list : params) {
for(int i = 0; i < list.size(); i++) {
pst.setObject(i + 1, list.get(i));
}
pst.addBatch();
}
count = pst.executeBatch();
conn.commit();
conn.setAutoCommit(autoCommit);
} catch (Exception e) {
log.error("插入数据失败"+e.getMessage()+"========"+destTableName);
throw new RuntimeException("插入数据失败"+e.getMessage());
} finally {
closeStatement(pst);
closeConnection(conn);
}
return count;
}
/**
* 查询数据并封装到 List 集合中
* @param sql SQL 语句
* @param args 参数列表
* @return List<Map<字段名, 值>>
*/
public List<Map<String, Object>> query(String source, String sql, Object...args) {
List<Map<String, Object>> result = new ArrayList<>();
Connection conn = null;
PreparedStatement pst = null;
ResultSet rs = null;
try {
conn = getConnection(source);
pst = conn.prepareStatement(sql);
for(int i = 0; i < args.length; i++) {
pst.setObject(i + 1, args[i]);
}
rs = pst.executeQuery();
ResultSetMetaData rsmd = rs.getMetaData();
//获取字段数量
int columnCount = rsmd.getColumnCount();
List<String> columns = new ArrayList<>(columnCount);
for(int i = 1; i <= columnCount; i++) {
columns.add(rsmd.getColumnName(i)); // 字段名
}
//封装数据
while(rs.next()) {
Map<String, Object> map = new HashMap<>();
for (String column : columns) {
map.put(column, rs.getObject(column));
}
result.add(map);
}
} catch (Exception e) {
throw new RuntimeException("查询异常"+e.getMessage());
} finally {
closeStatement(pst);
closeConnection(conn);
closeResultSet(rs);
}
return result;
}
/**
* 关闭 Statement
* @param stmt
* @return
*/
public static boolean closeStatement(Statement stmt) {
boolean flag = true;
if(stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
flag = false;
}
}
return flag;
}
/**
* 关闭 ResultSet
* @param rs
* @return
*/
public static boolean closeResultSet(ResultSet rs) {
boolean flag = true;
if(rs != null) {
try {
rs.close();
} catch (SQLException e) {
flag = false;
}
}
return flag;
}
/**
* 关闭 Connection
* @param conn
* @return
*/
public static boolean closeConnection(Connection conn) {
boolean flag = true;
if(conn != null) {
try {
conn.close();
} catch (SQLException e) {
flag = false;
}
}
return flag;
}
}
#\u6CE8\u518C\u4E2D\u5FC3\u5730\u5740
#eureka.client.service-url.defaultZone =http://172.16.11.201:10001/eureka/
eureka.instance.prefer-ip-address=true
management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=*
eureka.instance.health-check-url-path=/actuator/health
eureka.instance.metadata-map.management.context-path=${server.servlet.context-path}/actuator
eureka.instance.status-page-url-path=/actuator/info
eureka.instance.metadata-map.management.api-docs=http://172.16.11.201:${server.port}${server.servlet.context-path}/swagger-ui.html
#服务实例ip地址,若eureka.instance.prefer-ip-address=false,ip-address设置失效,一般情况不用设置。
#eureka.instance.ip-address= 172.16.3.135
#eureka服务ip配置,可填写固定ip地址
eureka.instance.hostname=172.16.11.201
#eureka服务配置的校验账号及密码,配置需和eureka服务后台配置文件中一致
spring.security.user.name=admin
spring.security.user.password=a1234560
eureka.client.serviceUrl.defaultZone=http://${spring.security.user.name}:${spring.security.user.password}@${eureka.instance.hostname}:10001/eureka/
##########eureka配置信息###############
management.health.redis.enabled=false
source.jdbc.ip=jdbc:mysql://172.16.11.201:3306/dl_amos_common_biz?useUnicode=true&allowMultiQueries=true&characterEncoding=utf-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
goal.jdbc.ip=jdbc:mysql://172.16.11.201:3306/dl_amos_common_biz_20230828?useUnicode=true&allowMultiQueries=true&characterEncoding=utf-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
source.jdbc.ip.idx=jdbc:mysql://172.16.11.201:3306/dl_amos_idx_biz?useUnicode=true&allowMultiQueries=true&characterEncoding=utf-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
goal.jdbc.ip.idx=jdbc:mysql://172.16.11.201:3306/dl_amos_idx_biz_bak?useUnicode=true&allowMultiQueries=true&characterEncoding=utf-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
source.jdbc.ip.buss=jdbc:mysql://172.16.11.201:3306/dl_business?useUnicode=true&allowMultiQueries=true&characterEncoding=utf-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
goal.jdbc.ip.buss=jdbc:mysql://172.16.11.201:3306/dl_business_copy?useUnicode=true&allowMultiQueries=true&characterEncoding=utf-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
yeejoin.user=root
yeejoin.pwd=Yeejoin@2020
\ No newline at end of file
spring.application.name=AMOS-ADPTER
server.servlet.context-path=/adpter
server.port=8120
spring.profiles.active=dev
spring.jackson.time-zone=GMT+8
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.serialization.write-dates-as-timestamps=true
##代码中有部分逻辑冲突需要处理 为区分机场和电力逻辑 增加开关 若为true 则为机场逻辑 为false 则为电力逻辑
logic=false
logging.config=classpath:logback-${spring.profiles.active}.xml
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
<property name="LOG_HOME" value="log" />
<!-- 按照每天生成日志文件 -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!--日志文件输出的文件名-->
<FileNamePattern>${LOG_HOME}/jpush.log.%d{yyyy-MM-dd}.%i.log</FileNamePattern>
<!--日志文件保留天数-->
<MaxHistory>30</MaxHistory>
<!--日志文件大小-->
<MaxFileSize>30mb</MaxFileSize>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
</encoder>
</appender>
<!-- 控制台输出 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
</encoder>
</appender>
<!-- show parameters for hibernate sql 专为 Hibernate 定制
<logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="TRACE" />
<logger name="org.hibernate.type.descriptor.sql.BasicExtractor" level="DEBUG" />
<logger name="org.hibernate.SQL" level="DEBUG" />
<logger name="org.hibernate.engine.QueryParameters" level="DEBUG" />
<logger name="org.hibernate.engine.query.HQLQueryPlan" level="DEBUG" />
-->
<!--myibatis log configure-->
<logger name="com.apache.ibatis" level="DEBUG"/>
<logger name="org.mybatis" level="DEBUG" />
<logger name="java.sql.Connection" level="DEBUG"/>
<logger name="java.sql.Statement" level="DEBUG"/>
<logger name="java.sql.PreparedStatement" level="DEBUG"/>
<logger name="org.springframework" level="DEBUG"/>
<!-- 日志输出级别 -->
<root level="DEBUG">
<appender-ref ref="FILE" />
<appender-ref ref="STDOUT" />
</root>
</configuration>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
<property name="LOG_HOME" value="log"/>
<!-- 按照每天生成日志文件 -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--日志文件输出的文件名-->
<FileNamePattern>${LOG_HOME}/jpush.%d{yyyy-MM-dd}.%i.log</FileNamePattern>
<!--日志文件保留天数-->
<MaxHistory>30</MaxHistory>
<!--按大小分割同一天的-->
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
</encoder>
</appender>
<!-- show parameters for hibernate sql 专为 Hibernate 定制
<logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="TRACE" />
<logger name="org.hibernate.type.descriptor.sql.BasicExtractor" level="DEBUG" />
<logger name="org.hibernate.SQL" level="DEBUG" />
<logger name="org.hibernate.engine.QueryParameters" level="DEBUG" />
<logger name="org.hibernate.engine.query.HQLQueryPlan" level="DEBUG" />
-->
<!--myibatis log configure-->
<logger name="com.apache.ibatis" level="INFO"/>
<logger name="org.mybatis" level="INFO"/>
<logger name="java.sql.Connection" level="INFO"/>
<logger name="java.sql.Statement" level="INFO"/>
<logger name="java.sql.PreparedStatement" level="INFO"/>
<logger name="com.baomidou.mybatisplus" level="INFO"/>
<logger name="org.typroject" level="INFO"/>
<logger name="com.yeejoin.amos" level="INFO"/>
<logger name="org.springframework" level="INFO"/>
<!-- 日志输出级别 -->
<root level="INFO">
<appender-ref ref="FILE"/>
</root>
</configuration>
\ No newline at end of file
......@@ -21,5 +21,6 @@
<module>amos-boot-utils-video</module>
<module>amos-boot-utils-speech</module>
<module>amos-boot-utils-message</module>
<module>amos-boot-utils-adpter</module>
</modules>
</project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment