提交 1cb3b1b2 作者: 17607474349

Merge branch 'merge_dev' into dev_lijing

......@@ -7,5 +7,5 @@ indent_style = space
end_of_line = lf
insert_final_newline = true
[**.yml]
[*.{yml,yaml}]
indent_size = 2
......@@ -36,3 +36,5 @@ out/
### VS Code ###
.vscode/
node_modules
logs/
......@@ -33,3 +33,9 @@
- [ ] XXL-JOB 定时任务模块
- [x] @Convert 处理 Raw JSON 数据格式转换
- [ ] 扩展 PostgresDialect 实现时序查询函数
---
> 引用
1. [JTS](https://github.com/locationtech/jts)
2. [GeoTools](http://docs.geotools.org/)
......@@ -9,8 +9,13 @@ dependencies {
// 本地依赖
implementation fileTree(dir: project.rootDir.getPath() + '\\libs', includes: ['*jar'])
// 文档及参数校验
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation "io.swagger:swagger-annotations:${swaggerAnnotationsVersion}"
// hutool-core
implementation "cn.hutool:hutool-core:${hutoolVersion}"
implementation "cn.hutool:hutool-http:${hutoolVersion}"
// fastjson
implementation "com.alibaba:fastjson:${fastJsonVersion}"
......@@ -19,4 +24,15 @@ dependencies {
// hibernate-types-55
implementation "com.vladmihalcea:hibernate-types-55:${hibernateTypesVersion}"
// ======================= 推送相关 =======================
// 个推 SDK(App 推送)
// https://mvnrepository.com/artifact/com.getui.push/restful-sdk
implementation 'com.getui.push:restful-sdk:1.0.0.6'
// 阿里云短信 SDK(SMS 推送)
// https://mvnrepository.com/artifact/com.aliyun/dysmsapi20170525
implementation 'com.aliyun:dysmsapi20170525:2.0.9'
// 邮件 SDK(EMAIL 推送)
implementation 'org.springframework.boot:spring-boot-starter-mail'
// ======================================================
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.push.domain;
import com.alibaba.fastjson.JSON;
import com.vladmihalcea.hibernate.type.json.JsonType;
import com.alibaba.fastjson.JSONObject;
import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
import com.yiring.common.domain.BasicEntity;
import java.io.Serial;
import java.io.Serializable;
......@@ -34,7 +34,7 @@ import org.hibernate.annotations.TypeDef;
@FieldNameConstants
@FieldDefaults(level = AccessLevel.PRIVATE)
@Entity
@TypeDef(name = "json", typeClass = JsonType.class)
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
@Table(
name = "SYS_PUSH_MESSAGE",
indexes = {
......@@ -73,18 +73,18 @@ public class PushMessage extends BasicEntity implements Serializable {
String content;
@Comment("扩展数据")
@org.hibernate.annotations.Type(type = "json")
@Column(columnDefinition = "json")
JSON extra;
@org.hibernate.annotations.Type(type = "jsonb")
@Column(columnDefinition = "jsonb")
JSONObject extra;
@Comment("消息状态")
@Enumerated(EnumType.STRING)
Status status;
@Comment("推送反馈结果")
@org.hibernate.annotations.Type(type = "json")
@Column(columnDefinition = "json")
JSON result;
@org.hibernate.annotations.Type(type = "jsonb")
@Column(columnDefinition = "jsonb")
JSONObject result;
@Comment("重试次数")
Integer retryCount;
......@@ -94,7 +94,7 @@ public class PushMessage extends BasicEntity implements Serializable {
@SuppressWarnings({ "unused" })
public enum Type {
WS("STOMP WebSocket 消息"),
WEBHOOK("webhook"),
APP("APP 消息"),
SMS("短信消息"),
EMAIL("邮件消息"),
......@@ -113,7 +113,7 @@ public class PushMessage extends BasicEntity implements Serializable {
}
public String queue() {
return String.format("push.%s.queue", this.name());
return String.format("push.%s.queue", this.name().toLowerCase());
}
}
......
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.push.param;
import io.swagger.annotations.ApiModel;
import lombok.*;
import lombok.experimental.FieldDefaults;
/**
* App 推送参数
*
* @author Jim
* @version 0.1
* 2022/4/21 10:27
*/
@ApiModel("A")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
public class PushAppParam {
String webhook;
}
......@@ -20,14 +20,37 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class PushRabbitConfig {
/**
* 消息交换机
*/
public static final String PUSH_TOPIC_EXCHANGE = "push.topic.exchange";
/**
* WebHook 推送队列
*/
public static final String PUSH_WEBHOOK_QUEUE = "push.webhook.queue";
/**
* App 消息推送队列
*/
public static final String PUSH_APP_QUEUE = "push.app.queue";
public static final String PUSH_WS_QUEUE = "push.ws.queue";
/**
* 短信推送队列
*/
public static final String PUSH_SMS_QUEUE = "push.sms.queue";
public static final String PUSH_EMAIL_QUEUE = "push.email.queue";
/**
* 邮箱推送队列
*/
public static final String PUSH_MAIL_QUEUE = "push.mail.queue";
/**
* TTS 语音电话队列
*/
public static final String PUSH_CALL_TTS_QUEUE = "push.call.tts.queue";
/**
* 语音电话推送队列
*/
public static final String PUSH_CALL_AUDIO_QUEUE = "push.call.audio.queue";
/**
* 设备广播推送队列
*/
public static final String PUSH_DEVICE_TONE_QUEUE = "push.device.tone.queue";
/**
......@@ -52,16 +75,16 @@ public class PushRabbitConfig {
return BindingBuilder.bind(queue).to(exchange).with(PUSH_APP_QUEUE);
}
@Bean(PUSH_WS_QUEUE)
public Queue pushWebSocketQueue() {
@Bean(PUSH_WEBHOOK_QUEUE)
public Queue pushWebHookQueue() {
Map<String, Object> args = new HashMap<>(1);
args.put("x-message-ttl", 30 * 1000);
return new Queue(PUSH_WS_QUEUE, true, false, false, args);
return new Queue(PUSH_WEBHOOK_QUEUE, true, false, false, args);
}
@Bean
Binding bindingExchangeWs(@Qualifier(PUSH_WS_QUEUE) Queue queue, TopicExchange exchange) {
return BindingBuilder.bind(queue).to(exchange).with(PUSH_WS_QUEUE);
Binding bindingExchangeWebHook(@Qualifier(PUSH_WEBHOOK_QUEUE) Queue queue, TopicExchange exchange) {
return BindingBuilder.bind(queue).to(exchange).with(PUSH_WEBHOOK_QUEUE);
}
@Bean(PUSH_SMS_QUEUE)
......@@ -76,16 +99,16 @@ public class PushRabbitConfig {
return BindingBuilder.bind(queue).to(exchange).with(PUSH_SMS_QUEUE);
}
@Bean(PUSH_EMAIL_QUEUE)
public Queue pushEmailQueue() {
@Bean(PUSH_MAIL_QUEUE)
public Queue pushMailQueue() {
Map<String, Object> args = new HashMap<>(1);
args.put("x-message-ttl", 60 * 1000);
return new Queue(PUSH_EMAIL_QUEUE, true, false, false, args);
return new Queue(PUSH_MAIL_QUEUE, true, false, false, args);
}
@Bean
Binding bindingExchangeEmail(@Qualifier(PUSH_EMAIL_QUEUE) Queue queue, TopicExchange exchange) {
return BindingBuilder.bind(queue).to(exchange).with(PUSH_EMAIL_QUEUE);
Binding bindingExchangeMail(@Qualifier(PUSH_MAIL_QUEUE) Queue queue, TopicExchange exchange) {
return BindingBuilder.bind(queue).to(exchange).with(PUSH_MAIL_QUEUE);
}
@Bean(PUSH_CALL_TTS_QUEUE)
......
......@@ -26,10 +26,61 @@ public class PushRabbitReceiver {
PushMessageRepository repository;
@RabbitHandler
@RabbitListener(queues = PushRabbitConfig.PUSH_WS_QUEUE)
public void receiverWebSocketMessage(Long id) {
log.info("接收到消息: " + id);
@RabbitListener(queues = PushRabbitConfig.PUSH_WEBHOOK_QUEUE)
public void receiverWebHookMessage(Long id) {
log.info("[WebHook] Message: " + id);
repository.findById(id).ifPresent(message -> log.info("{}", message));
// TODO
// 实现调用 WebHook,基于 WebHook API 发起 HTTPs 请求
}
@RabbitHandler
@RabbitListener(queues = PushRabbitConfig.PUSH_APP_QUEUE)
public void receiverAppMessage(Long id) {
log.info("[App] Message: " + id);
// TODO
// 实现推送消息到 App,基于个推 API
// https://github.com/GetuiLaboratory/getui-pushapi-java-client-v2
}
@RabbitHandler
@RabbitListener(queues = PushRabbitConfig.PUSH_SMS_QUEUE)
public void receiverSmsMessage(Long id) {
log.info("[SMS] Message: " + id);
// TODO
// 实现发送短信,基于阿里云短信平台 API
}
@RabbitHandler
@RabbitListener(queues = PushRabbitConfig.PUSH_MAIL_QUEUE)
public void receiverMailMessage(Long id) {
log.info("[Mail] Message: " + id);
// TODO
// 实现发送邮件,基于邮件配置
}
@RabbitHandler
@RabbitListener(queues = PushRabbitConfig.PUSH_CALL_TTS_QUEUE)
public void receiverTtsMessage(Long id) {
log.info("[Phone TTS] Message: " + id);
// TODO
// 实现拨打电话播放 TTS 转语音,基于壹润外呼系统 API
}
@RabbitHandler
@RabbitListener(queues = PushRabbitConfig.PUSH_CALL_AUDIO_QUEUE)
public void receiverAudioMessage(Long id) {
log.info("[Phone Audio] Message: " + id);
// TODO
// 实现拨打电话播放音频文件,基于壹润外呼系统 API
}
@RabbitHandler
@RabbitListener(queues = PushRabbitConfig.PUSH_DEVICE_TONE_QUEUE)
public void receiverToneMessage(Long id) {
log.info("[Device Tone] Message: " + id);
// TODO
// 实现播放设备铃声,基于音柱广播设备 API
// SDK 暂未拿到,设备未采购,未进行联调
}
}
......@@ -3,6 +3,7 @@ package com.yiring.app.push.service;
import com.alibaba.fastjson.JSONObject;
import com.yiring.app.push.domain.PushMessage;
import com.yiring.app.push.param.PushAppParam;
/**
* 推送服务
......@@ -13,4 +14,10 @@ import com.yiring.app.push.domain.PushMessage;
*/
public interface PushService {
void push(PushMessage.Type type, JSONObject raw);
/**
* 推送到 App
* @param param 参数
*/
void app(PushAppParam param);
}
......@@ -4,12 +4,13 @@ package com.yiring.app.push.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.yiring.app.push.domain.PushMessage;
import com.yiring.app.push.domain.PushMessageRepository;
import com.yiring.app.push.param.PushAppParam;
import com.yiring.app.push.rabbitmq.PushRabbitConfig;
import com.yiring.app.push.service.PushService;
import javax.annotation.Resource;
import javax.transaction.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;
/**
......@@ -29,7 +30,7 @@ public class PushServiceImpl implements PushService {
PushMessageRepository repository;
@Resource
AmqpTemplate amqpTemplate;
RabbitTemplate rabbitTemplate;
@Override
public void push(PushMessage.Type type, JSONObject raw) {
......@@ -37,6 +38,10 @@ public class PushServiceImpl implements PushService {
message.setType(type);
message.setExtra(raw);
repository.saveAndFlush(message);
amqpTemplate.convertAndSend(PushRabbitConfig.PUSH_TOPIC_EXCHANGE, type.queue(), message.getId());
rabbitTemplate.convertAndSend(PushRabbitConfig.PUSH_TOPIC_EXCHANGE, type.queue(), message.getId());
}
@Override
public void app(PushAppParam param) {}
}
......@@ -53,6 +53,7 @@ dependencies {
implementation "cn.hutool:hutool-extra:${hutoolVersion}"
implementation "cn.hutool:hutool-http:${hutoolVersion}"
implementation "cn.hutool:hutool-json:${hutoolVersion}"
// JPA 增加空间字段支持
// https://blog.wuwii.com/jpa-spatial.html
implementation("org.hibernate:hibernate-spatial:${hibernateSpatialVersion}") {
......@@ -69,4 +70,7 @@ dependencies {
// myexcel
implementation "com.github.liaochong:myexcel:${myexcelVersion}"
// https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-openfeign
implementation "org.springframework.cloud:spring-cloud-starter-openfeign:${openfeignVersion}"
}
......@@ -4,6 +4,7 @@ package com.yiring.app;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
......@@ -12,6 +13,7 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
basePackageClasses = { Application.class, Jsr310JpaConverters.class },
basePackages = Application.BASE_PACKAGES
)
@EnableFeignClients
@SpringBootApplication(scanBasePackages = Application.BASE_PACKAGES)
public class Application {
......
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.domain.alarm;
/**
* 标签报警
*
* @author Jim
* @version 0.1
* 2022/4/25 15:38
*/
public class TagAlarm {}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.domain.appletUser;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import javax.persistence.*;
import lombok.*;
import lombok.experimental.FieldDefaults;
import org.hibernate.annotations.Comment;
@Data
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Comment("小程序用户表")
@FieldDefaults(level = AccessLevel.PRIVATE)
@Entity
@Table(name = "BS_APPLET_USER")
public class AppletUser implements Serializable {
@Serial
private static final long serialVersionUID = 5188008300684723724L;
@Id
@Comment("用户唯一标识")
String openid;
@Comment("用户电话")
String mobile;
@Comment("最后登录时间")
LocalDateTime LastLoginTime;
@Comment("创建时间")
LocalDateTime createTime;
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.domain.appletUser;
import java.io.Serializable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
/**
* @author tzl
* 2022/4/22 13:55
*/
@Repository
public interface AppletUserRepository
extends JpaRepository<AppletUser, Serializable>, JpaSpecificationExecutor<AppletUser> {
@Query("SELECT COUNT(id) FROM AppletUser WHERE mobile=?1")
Integer countMobile(String mobile);
}
......@@ -2,10 +2,13 @@
package com.yiring.app.domain.car;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yiring.common.annotation.Excel;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.*;
import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants;
......@@ -30,6 +33,9 @@ import org.hibernate.snowflake.SnowflakeId;
@Comment("车辆")
public class Car implements Serializable {
@Serial
private static final long serialVersionUID = 8775607064296075463L;
@Id
@Comment("主键id")
@GeneratedValue(generator = SnowflakeId.GENERATOR)
......@@ -37,48 +43,34 @@ public class Car implements Serializable {
Long id;
@Comment("车牌号")
@Excel(name = "车牌", sort = 1)
String carNum;
@Comment("车辆类型")
@Excel(name = "车辆类型", sort = 2, dictType = "car_type")
String carType;
@Comment("司机名称")
@Excel(name = "司机", sort = 3)
String driverName;
@Comment("司机电话")
@Excel(name = "联系电话", sort = 4)
String driverMobile;
@Comment("标签卡")
@Excel(name = "标签卡", sort = 9)
String labelCard;
@Comment("标签卡状态")
@Excel(name = "标签卡状态", sort = 10, dictType = "car_label_status")
String labelCardStatus;
@Comment("所属单位id")
@Excel(name = "所属单位", sort = 5)
String orgId;
@Comment("被访人id")
@Excel(name = "被访人", sort = 7)
String intervieweeId;
@Comment("来访原因")
@Excel(name = "来访原因", sort = 6)
String reason;
@Comment("收卡时间")
@Excel(name = "收卡时间", sort = 11, dateFormat = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
LocalDateTime cardRecTime;
@Comment("创建时间")
@Excel(name = "到访时间", sort = 8, dateFormat = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
LocalDateTime createTime;
......
......@@ -2,20 +2,21 @@
package com.yiring.app.domain.location;
import com.yiring.common.annotation.FieldMapping;
import com.yiring.common.domain.BasicEntity;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import javax.persistence.*;
import lombok.*;
import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants;
import lombok.experimental.SuperBuilder;
import org.hibernate.Hibernate;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import org.hibernate.snowflake.SnowflakeId;
import org.locationtech.jts.geom.Point;
/**
......@@ -32,7 +33,7 @@ import org.locationtech.jts.geom.Point;
@Getter
@Setter
@ToString
@Builder
@SuperBuilder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
......@@ -43,17 +44,11 @@ import org.locationtech.jts.geom.Point;
indexes = { @Index(columnList = "linkId"), @Index(columnList = "code", unique = true) }
)
@Comment("定位信标")
public class LocationBeacon implements Serializable {
public class LocationBeacon extends BasicEntity implements Serializable {
@Serial
private static final long serialVersionUID = 5419734189897829250L;
@Comment("主键")
@Id
@GeneratedValue(generator = SnowflakeId.GENERATOR)
@GenericGenerator(name = SnowflakeId.GENERATOR, strategy = SnowflakeId.Strategy.LONG)
Long id;
/**
* 数据来源于【真源人员定位系统 - 定位信标】
* 作用: 用于双向联动进行数据同步
......@@ -99,19 +94,18 @@ public class LocationBeacon implements Serializable {
@Comment("电量单位")
String voltUnit;
@FieldMapping(value = "time", desc = "更新时间戳", type = Long.class)
@Comment("更新时间")
LocalDateTime updateTime;
@Comment("创建时间")
LocalDateTime createTime;
@Comment("围栏集合")
@Builder.Default
@ManyToMany
@ToString.Exclude
Set<LocationFence> fences = new HashSet<>(0);
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
LocationBeacon that = (LocationBeacon) o;
return id != null && Objects.equals(id, that.id);
return getId() != null && Objects.equals(getId(), that.getId());
}
@Override
......
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.domain.location;
import java.io.Serializable;
import java.util.Set;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;
/**
* @author Jim
* @version 0.1
* 2022/4/24 14:19
*/
@Repository
public interface LocationBeaconRepository
extends JpaRepository<LocationBeacon, Serializable>, JpaSpecificationExecutor<LocationBeacon> {
/**
* 根据编号集合查询
* @param codes 编号集合
* @return 查询结果
*/
Set<LocationBeacon> findByCodeIn(Set<String> codes);
}
......@@ -2,19 +2,18 @@
package com.yiring.app.domain.location;
import com.yiring.common.annotation.FieldMapping;
import com.yiring.common.domain.BasicEntity;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.*;
import lombok.*;
import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import org.hibernate.snowflake.SnowflakeId;
import org.locationtech.jts.geom.Geometry;
/**
......@@ -29,33 +28,19 @@ import org.locationtech.jts.geom.Geometry;
@Getter
@Setter
@ToString
@Builder
@SuperBuilder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
@FieldDefaults(level = AccessLevel.PRIVATE)
@Entity
@Table(name = "BS_LOCATION_FENCE", indexes = { @Index(columnList = "linkId"), @Index(columnList = "mode") })
@Table(name = "BS_LOCATION_FENCE", indexes = { @Index(columnList = "mode") })
@Comment("围栏")
public class LocationFence implements Serializable {
public class LocationFence extends BasicEntity implements Serializable {
@Serial
private static final long serialVersionUID = 4155868702188991300L;
@Comment("主键")
@Id
@GeneratedValue(generator = SnowflakeId.GENERATOR)
@GenericGenerator(name = SnowflakeId.GENERATOR, strategy = SnowflakeId.Strategy.LONG)
Long id;
/**
* 数据来源于【真源人员定位系统 - 电子围栏】
* 作用: 用于双向联动进行数据同步
*/
@FieldMapping("id")
@Comment("外链主键")
Long linkId;
@Comment("地图 ID")
Long areaId;
......@@ -64,21 +49,11 @@ public class LocationFence implements Serializable {
@Enumerated(EnumType.STRING)
Mode mode;
@Comment("坐标信息(x,y,r)")
@Column(columnDefinition = "JSON")
String shape;
@Comment("形状信息(circle: 圆形, polygon: 多边形)")
String shapeType;
@Comment("空间信息")
@Type(type = "jts_geometry")
@Column(columnDefinition = "geometry")
Geometry geometry;
@Comment("半径,米/单位(圆形围栏)")
Double radius;
@Comment("超时时间(秒)")
Integer overtime;
......@@ -91,13 +66,16 @@ public class LocationFence implements Serializable {
@ToString.Exclude
Set<LocationBeacon> beacons = new HashSet<>(0);
@Comment("创建时间")
LocalDateTime createTime;
@Comment("围栏规则集合")
@Builder.Default
@OneToMany(mappedBy = "fence")
@ToString.Exclude
Set<LocationFenceRule> rules = new HashSet<>(0);
@SuppressWarnings({ "unused" })
public enum Mode {
NORMAL("标准"),
DANGER("危险区域");
NORMAL("常规区域"),
DANGER("危险区域");
@Getter
final String text;
......
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.domain.location;
import com.yiring.auth.domain.user.User;
import com.yiring.common.annotation.FieldMapping;
import com.yiring.common.domain.BasicEntity;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalTime;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import lombok.*;
import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.snowflake.SnowflakeId;
/**
* 围栏规则
......@@ -36,67 +33,18 @@ import org.hibernate.snowflake.SnowflakeId;
@Entity
@Table(name = "BS_LOCATION_FENCE_RULE")
@Comment("围栏规则")
public class LocationFenceRule implements Serializable {
public class LocationFenceRule extends BasicEntity implements Serializable {
@Serial
private static final long serialVersionUID = -6683465582430417205L;
@Comment("主键")
@Id
@GeneratedValue(generator = SnowflakeId.GENERATOR)
@GenericGenerator(name = SnowflakeId.GENERATOR, strategy = SnowflakeId.Strategy.LONG)
Long id;
@Comment("围栏")
@ManyToOne
@JoinColumn(name = "fence_id")
LocationFence fence;
// TODO
// 字段补充
// 关联表补充(报警规则)
// 关联表配置值补充
@FieldMapping("entityTypes")
@Comment("规则模型")
@Enumerated(EnumType.STRING)
Mode mode;
@Comment("规则名称")
String name;
@Comment("规则描述")
String describe;
@Comment("最小值(人数)")
Integer minValue;
@Comment("最大值(人数)")
Integer maxValue;
@Comment("规则生效开始时间")
LocalTime minTime;
@Comment("规则生效结束时间")
LocalTime maxTime;
@Comment("允许的用户(人员)")
@OneToMany
@Builder.Default
@ToString.Exclude
Set<User> includes = new HashSet<>(0);
@Comment("不允许的用户(人员)")
@OneToMany
@Builder.Default
@ToString.Exclude
Set<User> excludes = new HashSet<>(0);
@SuppressWarnings({ "unused" })
public enum Mode {
STAFF("人员"),
NUMBER("数量");
@Getter
final String text;
Mode(String text) {
this.text = text;
}
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.domain.location;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.vladmihalcea.hibernate.type.json.JsonType;
import com.yiring.auth.domain.user.User;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import javax.persistence.*;
import lombok.*;
import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants;
import org.hibernate.Hibernate;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.snowflake.SnowflakeId;
import org.locationtech.jts.geom.Point;
/**
* 定位数据
* 引用: 定位平台接口规范V3.0.1 #6
* TODO:
* 1. 实时数据日志的存储结构 TimeScale: 时间粒度,每天一个分区
* eg: SELECT create_hypertable('BS_LOCATION_LOG', 'time', chunk_time_interval => INTERVAL '1 day')
*
* @author Jim
* @version 0.1
......@@ -42,18 +41,24 @@ import org.locationtech.jts.geom.Point;
@FieldDefaults(level = AccessLevel.PRIVATE)
@Entity
@TypeDef(name = "json", typeClass = JsonType.class)
@Table(name = "BS_LOCATION_LOG", indexes = { @Index(columnList = "time"), @Index(columnList = "silent") })
@Table(name = "BS_LOCATION_LOG")
@Comment("定位数据")
public class LocationLog implements Serializable {
@Serial
private static final long serialVersionUID = 3467455881020691989L;
@Comment("主键")
@Id
@GeneratedValue(generator = SnowflakeId.GENERATOR)
@GenericGenerator(name = SnowflakeId.GENERATOR, strategy = SnowflakeId.Strategy.LONG)
Long id;
@Comment("时间")
@Column(nullable = false, columnDefinition = "timestamp without time zone")
@CreationTimestamp
LocalDateTime time;
@Comment("地图 ID")
Long areaId;
@Comment("楼层")
String floor;
/**
* 来源于定位数据产生时刻标签所属的人员
......@@ -74,19 +79,6 @@ public class LocationLog implements Serializable {
@JoinColumn(name = "tag_id")
LocationTag tag;
@Comment("时间")
@Column(nullable = false)
LocalDateTime time;
@Comment("经度")
BigDecimal lon;
@Comment("纬度")
BigDecimal lat;
@Comment("海拔高度(m)")
BigDecimal altitude;
@Comment("坐标点信息")
@Type(type = "jts_geometry")
@Column(columnDefinition = "point")
......@@ -94,13 +86,13 @@ public class LocationLog implements Serializable {
@Comment("信标集合")
@Builder.Default
@ManyToMany
@OneToMany
@ToString.Exclude
Set<LocationBeacon> beacons = new HashSet<>(0);
@Comment("围栏集合")
@Builder.Default
@ManyToMany
@OneToMany
@ToString.Exclude
Set<LocationFence> fences = new HashSet<>(0);
......@@ -116,21 +108,8 @@ public class LocationLog implements Serializable {
@Comment("原始数据")
@org.hibernate.annotations.Type(type = "json")
@Column(columnDefinition = "json")
JSON raw;
@Comment("创建时间")
LocalDateTime createTime;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
LocationLog locationLog = (LocationLog) o;
return id != null && Objects.equals(id, locationLog.id);
}
@Override
public int hashCode() {
return getClass().hashCode();
}
JSONObject raw;
@Comment("定位时间")
LocalDateTime locationTime;
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.domain.location;
import java.io.Serializable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;
/**
* @author Jim
* @version 0.1
* 2022/4/24 18:03
*/
@Repository
public interface LocationLogRepository
extends JpaRepository<LocationLog, Serializable>, JpaSpecificationExecutor<LocationLog> {}
......@@ -3,16 +3,18 @@ package com.yiring.app.domain.location;
import com.yiring.auth.domain.user.User;
import com.yiring.common.annotation.FieldMapping;
import com.yiring.common.domain.BasicEntity;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Objects;
import javax.persistence.*;
import lombok.*;
import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants;
import lombok.experimental.SuperBuilder;
import org.hibernate.Hibernate;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.snowflake.SnowflakeId;
/**
* 定位标签
......@@ -28,7 +30,7 @@ import org.hibernate.snowflake.SnowflakeId;
@Getter
@Setter
@ToString
@Builder
@SuperBuilder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
......@@ -45,17 +47,11 @@ import org.hibernate.snowflake.SnowflakeId;
}
)
@Comment("定位标签")
public class LocationTag implements Serializable {
public class LocationTag extends BasicEntity implements Serializable {
@Serial
private static final long serialVersionUID = 5419734189897829250L;
@Comment("主键")
@Id
@GeneratedValue(generator = SnowflakeId.GENERATOR)
@GenericGenerator(name = SnowflakeId.GENERATOR, strategy = SnowflakeId.Strategy.LONG)
Long id;
/**
* 数据来源于【真源人员定位系统 - 定位标签】
* 作用: 用于双向联动进行数据同步
......@@ -127,6 +123,14 @@ public class LocationTag implements Serializable {
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
LocationTag that = (LocationTag) o;
return getId() != null && Objects.equals(getId(), that.getId());
}
@Override
public int hashCode() {
return getClass().hashCode();
}
......
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.domain.log;
import com.alibaba.fastjson.JSONObject;
import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import javax.persistence.*;
import lombok.*;
import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.TypeDef;
/**
* 真源定位系统实时数据日志
* TODO:
* 1. 实时数据日志的存储结构 TimeScale: 时间粒度,每小时一个分区
* eg: SELECT create_hypertable('ZY_REALTIME_LOG', 'time', chunk_time_interval => INTERVAL '1 hour')
* 2. 数据分区压缩
* 3. 定时删除过期分区数据
* 参考:<a href="https://blog.csdn.net/yang_z_1/article/details/111560747">文档</a>
*
* @author Jim
* @version 0.1
* 2022/4/25 15:52
*/
@Getter
@Setter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
@FieldDefaults(level = AccessLevel.PRIVATE)
@Entity
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
@Table(name = "ZY_REALTIME_LOG", indexes = { @Index(columnList = "method") })
@Comment("真源定位系统实时数据日志")
public class ZyRealtimeLog implements Serializable {
@Serial
private static final long serialVersionUID = 5545864821082386L;
@Id
@Comment("时间")
@Column(nullable = false, columnDefinition = "timestamp without time zone")
@CreationTimestamp
LocalDateTime time;
@Comment("类型")
@Column(nullable = false)
String method;
@Comment("内容")
@org.hibernate.annotations.Type(type = "jsonb")
@Column(nullable = false, columnDefinition = "jsonb")
JSONObject raw;
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.domain.log;
import java.io.Serializable;
import org.springframework.data.jpa.repository.JpaRepository;
/**
* @author Jim
* @version 0.1
* 2022/4/25 16:02
*/
public interface ZyRealtimeLogRepository extends JpaRepository<ZyRealtimeLog, Serializable> {}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.domain.visitor;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import javax.persistence.*;
import lombok.*;
import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.snowflake.SnowflakeId;
/**
* @author tzl
* 2022/4/19 11:41
*/
@Getter
@Setter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
@FieldDefaults(level = AccessLevel.PRIVATE)
@Entity
@Table(name = "BS_VISITOR")
@Comment("访客信息")
public class Visitor implements Serializable {
@Serial
private static final long serialVersionUID = -7367226565168197562L;
@Id
@Comment("主键")
@GeneratedValue(generator = SnowflakeId.GENERATOR)
@GenericGenerator(name = SnowflakeId.GENERATOR, strategy = SnowflakeId.Strategy.LONG)
Long id;
@Comment("到访人姓名")
String visitorName;
@Comment("到访人电话")
String visitorMobile;
@Comment("到访人身份证")
String visitorCarNum;
@Comment("是否特殊作业")
boolean taskType;
@Comment("邀请人数")
Integer numOfVisitor;
@Comment("访客来源")
String visitorSource;
@Comment("标签卡")
String labelCard;
@Comment("标签卡状态")
String labelCardStatus;
@Comment("所属单位id")
String orgId;
@Comment("被访人id")
String intervieweeId;
@Comment("来访原因")
String reason;
@Comment("收卡时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
LocalDateTime cardRecTime;
@Comment("预约到访时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
LocalDateTime appOfVisitTime;
@Comment("创建时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
LocalDateTime createTime;
@Comment("发卡时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
LocalDateTime cardSendTime;
@Comment("备用字段")
String reserve1;
@Comment("备用字段")
String reserve2;
@Comment("备用字段")
String reserve3;
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.domain.visitor;
import java.io.Serializable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;
/**
* @author tzl
* 2022/4/19 14:06
*/
@Repository
public interface VisitorRepository extends JpaRepository<Visitor, Serializable>, JpaSpecificationExecutor<Visitor> {}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.excel.car;
import com.github.liaochong.myexcel.core.annotation.ExcelColumn;
import com.github.liaochong.myexcel.core.annotation.ExcelModel;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.*;
import lombok.experimental.FieldDefaults;
/**
* @author tzl
* 2022/4/20 10:35
*/
@ExcelModel
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@FieldDefaults(level = AccessLevel.PRIVATE)
public class CarExportExcel implements Serializable {
@Serial
private static final long serialVersionUID = -4019303809667111441L;
@ExcelColumn(title = "车牌")
String carNum;
@ExcelColumn(title = "车辆类型")
String carType;
@ExcelColumn(title = "司机")
String driverName;
@ExcelColumn(title = "联系电话")
String driverMobile;
@ExcelColumn(title = "所属单位")
String orgId;
@ExcelColumn(title = "来访原因", width = 15)
String reason;
@ExcelColumn(title = "被访人")
String intervieweeId;
@ExcelColumn(title = "到访时间", format = "yyyy-MM-dd HH:mm:ss", width = 15)
LocalDateTime cardSendTime;
@ExcelColumn(title = "标签卡")
String labelCard;
@ExcelColumn(title = "收卡时间", format = "yyyy-MM-dd HH:mm:ss", width = 15)
LocalDateTime cardRecTime;
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.excel.video;
import com.github.liaochong.myexcel.core.annotation.ExcelColumn;
import com.github.liaochong.myexcel.core.annotation.ExcelModel;
import java.io.Serial;
import java.io.Serializable;
import lombok.*;
import lombok.experimental.FieldDefaults;
import org.locationtech.jts.geom.Point;
/**
* @author tzl
* 2022/4/20 16:21
*/
@ExcelModel
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@FieldDefaults(level = AccessLevel.PRIVATE)
public class VideoExportExcel implements Serializable {
@Serial
private static final long serialVersionUID = 5422685189135254189L;
@ExcelColumn(title = "编号", width = 10)
String uuid;
@ExcelColumn(title = "摄像头名称", width = 10)
String videoName;
@ExcelColumn(title = "坐标点信息(经度,纬度)", width = 10)
Point point;
@ExcelColumn(title = "m3u8 地址", width = 10)
String m3u8;
@ExcelColumn(title = "备注", width = 15)
String remark;
//
// String status;
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.excel.video;
import com.github.liaochong.myexcel.core.annotation.ExcelColumn;
import com.github.liaochong.myexcel.core.annotation.ExcelModel;
import java.io.Serial;
import java.io.Serializable;
import lombok.*;
import lombok.experimental.FieldDefaults;
/**
* @author tzl
* 2022/4/20 16:21
*/
@ExcelModel
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@FieldDefaults(level = AccessLevel.PRIVATE)
public class VideoImportExcel implements Serializable {
@Serial
private static final long serialVersionUID = 5422685189135254189L;
@ExcelColumn(title = "编号")
String uuid;
@ExcelColumn(title = "摄像头名称")
String videoName;
@ExcelColumn(title = "m3u8 地址")
String m3u8;
@ExcelColumn(title = "备注")
String remark;
@ExcelColumn(title = "经度")
double lon;
@ExcelColumn(title = "纬度")
double lat;
// String status;
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.excel.visitor;
import com.github.liaochong.myexcel.core.annotation.ExcelColumn;
import com.github.liaochong.myexcel.core.annotation.ExcelModel;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.*;
import lombok.experimental.FieldDefaults;
/**
* @author tzl
* 2022/4/21 9:37
*/
@ExcelModel
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@FieldDefaults(level = AccessLevel.PRIVATE)
public class VisitorExportExcel implements Serializable {
@Serial
private static final long serialVersionUID = -5732379257900745806L;
@ExcelColumn(title = "到访人姓名")
String visitorName;
@ExcelColumn(title = "到访人姓名")
String visitorMobile;
@ExcelColumn(title = "到访人身份证")
String visitorCarNum;
@ExcelColumn(title = "是否特殊作业")
boolean taskType;
@ExcelColumn(title = "邀请人数")
Integer numOfVisitor;
@ExcelColumn(title = "访客来源")
String visitorSource;
@ExcelColumn(title = "标签卡")
String labelCard;
@ExcelColumn(title = "标签卡状态", mapping = "1:未发卡,2:使用中,3:已收卡")
String labelCardStatus;
@ExcelColumn(title = "所属单位")
String orgId;
@ExcelColumn(title = "被访人")
String intervieweeId;
@ExcelColumn(title = "来访原因")
String reason;
@ExcelColumn(title = "收卡时间")
LocalDateTime cardRecTime;
@ExcelColumn(title = "预约到访时间")
LocalDateTime appOfVisitTime;
@ExcelColumn(title = "发卡时间")
LocalDateTime cardSendTime;
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.feign;
import com.alibaba.fastjson.JSONObject;
import com.yiring.app.param.video.StreamProxyItem;
import feign.Response;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
/**
* @author tzl
* 2022/4/18 14:22
*/
@FeignClient(url = "${env.host}:3008", name = "gb")
public interface GbClient {
/**
* 国标登录接口
* @param username 用户名
* @param password 密码
* @return Response
*/
@RequestMapping(value = "/api/user/login", method = RequestMethod.GET)
Response userLogin(
@RequestParam(name = "username") String username,
@RequestParam(name = "password") String password
);
/**
* 拉流数据同步接口
* @param streamProxyItem 拉流对象
* @param cookie cookie
* @return 是否成功
*/
@RequestMapping(value = "/api/proxy/save", method = RequestMethod.POST)
JSONObject proxySave(@RequestBody StreamProxyItem streamProxyItem, @RequestHeader("Cookie") String cookie);
/**
* 拉流删除接口
* @param app 流应用名
* @param stream 流编号
* @param cookie cookie
* @return 是否成功
*/
@RequestMapping(value = "/api/proxy/del", method = RequestMethod.DELETE)
JSONObject proxyDel(
@RequestParam(name = "app") String app,
@RequestParam(name = "stream") String stream,
@RequestHeader("Cookie") String cookie
);
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.feign;
import com.alibaba.fastjson.JSONObject;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
@FeignClient(url = "http://project.yz-online.com:789", name = "mapClient")
public interface MapClient {
/**
* 地图层数据
* @author tzl
* @date 2022/4/25 10:51
* @param orgId 单位id
* @param token 认证参数
* @return com.alibaba.fastjson.JSONObject
*/
@RequestMapping(value = "/positionApi/api/area/allList/{orgId}", method = RequestMethod.GET)
JSONObject selectMap(@PathVariable("orgId") String orgId, @RequestHeader("Authorization") String token);
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.feign;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@FeignClient(url = "api.weixin.qq.com", name = "wxclient")
public interface WxClient {
/**
* 获取微信用户唯一标识
*
* @param appid String
* @param secret String
* @param js_code String
* @param grant_type String
* @return com.alibaba.fastjson.JSONObject
* @author tzl
* @date 15:20
*/
@RequestMapping(value = "/sns/jscode2session", method = RequestMethod.GET)
@ApiImplicitParams(
{
@ApiImplicitParam(value = "appid", required = true, name = "appid"),
@ApiImplicitParam(value = "secret", required = true, name = "secret"),
@ApiImplicitParam(value = "js_code", required = true, name = "js_code"),
@ApiImplicitParam(value = "grant_type", required = true, name = "grant_type"),
}
)
JSONObject getOpenid(String appid, String secret, String js_code, String grant_type);
}
......@@ -4,6 +4,8 @@ package com.yiring.app.param.car;
import com.yiring.common.constant.RegEx;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serial;
import java.io.Serializable;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
......@@ -20,7 +22,10 @@ import lombok.experimental.FieldDefaults;
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
public class CarParam {
public class CarParam implements Serializable {
@Serial
private static final long serialVersionUID = 521351582969232371L;
@ApiModelProperty(value = "车牌号码", example = "湘A99999", required = true)
@NotEmpty(message = "车牌号码不能为空")
......@@ -39,12 +44,6 @@ public class CarParam {
@Pattern(regexp = RegEx.MOBILE, message = "手机号码格式不正确")
String driverMobile;
// @ApiModelProperty(value = "标签卡", example = "DW24515512")
// String labelCard;
//
// @ApiModelProperty(value = "标签卡状态", example = "使用中")
// String labelCardStatus;
@ApiModelProperty(value = "所属单位id", example = "1", required = true)
@NotEmpty(message = "所属单位id不能为空")
String orgId;
......@@ -57,11 +56,4 @@ public class CarParam {
@NotEmpty(message = "来访原因不能为空")
@Size(min = 1, max = 20, message = "来访原因超出范围")
String reason;
// @ApiModelProperty(value = "收卡时间", example = "2022-04-11 17:25:33")
// LocalDateTime cardRecTime;
//
// @ApiModelProperty(value = "发卡时间", example = "2022-04-11 17:25:33")
// LocalDateTime cardSendTime;
// @ApiModelProperty(value = "创建时间", example = "")
// LocalDateTime createTime;
}
......@@ -3,6 +3,8 @@ package com.yiring.app.param.car;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.*;
import lombok.experimental.FieldDefaults;
......@@ -17,14 +19,15 @@ import lombok.experimental.FieldDefaults;
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
public class CarQueryParam {
public class CarQueryParam implements Serializable {
@Serial
private static final long serialVersionUID = -2107446950936463302L;
@ApiModelProperty(value = "每页记录数", example = "10")
// @DecimalMin(value = "1", message = "分页条数不能小于1")
Integer pageSize;
@ApiModelProperty(value = "页码", example = "1")
// @DecimalMin(value = "1", message = "页码不能小于1")
Integer pageNo;
@ApiModelProperty(value = "车牌号码", example = "湘A12345")
......@@ -42,9 +45,6 @@ public class CarQueryParam {
@ApiModelProperty(value = "标签卡", example = "DW24515512")
String labelCard;
@ApiModelProperty(value = "标签卡状态", example = "2")
String labelCardStatus;
@ApiModelProperty(value = "所属单位id", example = "1")
String orgId;
......@@ -60,6 +60,9 @@ public class CarQueryParam {
@ApiModelProperty(value = "收卡时间(结束)", example = "2022-04-11 17:26:33")
LocalDateTime cardRecTimeEnd;
/**
* 来访时间参数字段名用错 应该时 cardSendTimeStart
*/
@ApiModelProperty(value = "来访时间(开始)", example = "2022-04-11 17:25:33")
LocalDateTime createTimeStart;
......
......@@ -3,6 +3,7 @@ package com.yiring.app.param.dict;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import javax.validation.constraints.NotEmpty;
import lombok.*;
import lombok.experimental.FieldDefaults;
......@@ -17,7 +18,9 @@ import lombok.experimental.FieldDefaults;
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
public class DictParam {
public class DictParam implements Serializable {
private static final long serialVersionUID = -6297680882890239905L;
@ApiModelProperty(value = "排序", example = "1", required = true)
Integer dictSort;
......
......@@ -3,6 +3,7 @@ package com.yiring.app.param.dict;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import lombok.*;
import lombok.experimental.FieldDefaults;
......@@ -16,7 +17,9 @@ import lombok.experimental.FieldDefaults;
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
public class DictQueryParam {
public class DictQueryParam implements Serializable {
private static final long serialVersionUID = 558672306975530791L;
@ApiModelProperty(value = "字典标签", example = "男")
String dictLabel;
......
......@@ -3,6 +3,7 @@ package com.yiring.app.param.dict;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import javax.validation.constraints.NotEmpty;
import lombok.*;
import lombok.experimental.FieldDefaults;
......@@ -17,7 +18,9 @@ import lombok.experimental.FieldDefaults;
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
public class DictTypeParam {
public class DictTypeParam implements Serializable {
private static final long serialVersionUID = -4725073029525910806L;
@ApiModelProperty(value = "字典名称", example = "性别", required = true)
@NotEmpty(message = "字典名称不能为空")
......
......@@ -3,6 +3,7 @@ package com.yiring.app.param.dict;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import lombok.*;
import lombok.experimental.FieldDefaults;
......@@ -16,7 +17,9 @@ import lombok.experimental.FieldDefaults;
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
public class DictTypeQueryParam {
public class DictTypeQueryParam implements Serializable {
private static final long serialVersionUID = -2940949823473695962L;
@ApiModelProperty(value = "字典名称", example = "性别")
String dictName;
......
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.param.video;
import io.swagger.annotations.ApiModel;
import java.io.Serializable;
import lombok.*;
import lombok.experimental.FieldDefaults;
/**
* @author tzl
* 2022/4/18 15:21
*/
@ApiModel("StreamProxyItem")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
public class StreamProxyItem implements Serializable {
private static final long serialVersionUID = -7345369573992941431L;
//名称
String name;
//流应用名称
String app;
//流id
String stream;
//拉流地址
String url;
//类型,根据地址是否有关键字判断
String type;
//节点选择
String mediaServerId;
//是否启用
boolean enable;
//是否转HLS
boolean enable_hls;
Integer timeout_ms;
}
......@@ -3,8 +3,10 @@ package com.yiring.app.param.video;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serial;
import java.io.Serializable;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import lombok.*;
import lombok.experimental.FieldDefaults;
......@@ -23,11 +25,14 @@ import lombok.experimental.FieldDefaults;
@FieldDefaults(level = AccessLevel.PRIVATE)
public class VideoParam implements Serializable {
@Serial
private static final long serialVersionUID = 6031274771790265507L;
@ApiModelProperty(value = "编号", example = "88888888", required = true)
@NotEmpty(message = "标识不能为空")
String uuid;
@ApiModelProperty(value = "m3u8 媒体地址", example = "", required = true)
@ApiModelProperty(value = "m3u8 媒体地址", example = "m3u8 媒体地址", required = true)
@NotEmpty(message = "m3u8 媒体地址不能为空")
String m3u8;
......@@ -35,13 +40,13 @@ public class VideoParam implements Serializable {
@NotEmpty(message = "摄像头名称不能为空")
String videoName;
@ApiModelProperty(value = "经度", example = "1", required = true)
@NotEmpty(message = "经度")
double lon;
@ApiModelProperty(value = "经度", example = "1.00", required = true)
@NotNull(message = "经度")
Double lon;
@ApiModelProperty(value = "纬度", example = "1", required = true)
@NotEmpty(message = "纬度")
double lat;
@ApiModelProperty(value = "纬度", example = "1.00", required = true)
@NotNull(message = "纬度")
Double lat;
@ApiModelProperty(value = "备注", example = "厂区摄像头")
@Size(max = 100, message = "备注不能超过100字")
......
......@@ -21,6 +21,8 @@ import lombok.experimental.FieldDefaults;
@FieldDefaults(level = AccessLevel.PRIVATE)
public class VideoQueryParam implements Serializable {
private static final long serialVersionUID = -330684070308585411L;
@ApiModelProperty(value = "编号", example = "88888888")
String uuid;
......@@ -29,6 +31,12 @@ public class VideoQueryParam implements Serializable {
@ApiModelProperty(value = "状态", example = "1")
String status;
@ApiModelProperty(value = "分页条数", example = "10")
Integer pageSize;
@ApiModelProperty(value = "当前页数", example = "1")
Integer pageNo;
// @ApiModelProperty(value = "m3u8 地址", example = "")
// @NotEmpty(message = "m3u8 地址不能为空")
// String m3u8;
......
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.param.visitor;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serial;
import java.io.Serializable;
import javax.validation.constraints.NotEmpty;
import lombok.*;
import lombok.experimental.FieldDefaults;
/**
* @author tzl
* 2022/4/21 14:04
*/
@ApiModel("VisitorInfo")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
public class VisitorInfoParam implements Serializable {
@Serial
private static final long serialVersionUID = 3419577080791245488L;
@ApiModelProperty(value = "到访人姓名", example = "张三", required = true)
@NotEmpty(message = "到访人姓名不能为空")
String visitorName;
@ApiModelProperty(value = "到访人电话", example = "17688888888", required = true)
@NotEmpty(message = "到访人电话不能为空")
String visitorMobile;
@ApiModelProperty(value = "到访人身份证", example = "430441190001255417", required = true)
@NotEmpty(message = "到访人身份证不能为空")
String visitorCarNum;
@ApiModelProperty(value = "是否特殊作业", example = "fasle", required = true)
boolean taskType;
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.param.visitor;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
import lombok.*;
import lombok.experimental.FieldDefaults;
/**
* @author tzl
* 2022/4/21 13:51
*/
@ApiModel("VisitorParam")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
public class VisitorListParam implements Serializable {
@Serial
private static final long serialVersionUID = 6356324790945367160L;
@ApiModelProperty(value = "访客来源", example = "内部邀请", required = true)
String visitorSource;
@ApiModelProperty(value = "来访原因", example = "2022-04-19 14:28:00")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
LocalDateTime appOfVisitTime;
@ApiModelProperty(value = "被访人id", example = "1", required = true)
String intervieweeId;
@ApiModelProperty(value = "来访原因", example = "看看", required = true)
String reason;
@ApiModelProperty(value = "访客所属公司", example = "壹润科技", required = true)
String orgId;
@ApiModelProperty(value = "邀请人数", example = "1", required = true)
Integer numOfVisitor;
List<VisitorInfoParam> visitorInfos;
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.param.visitor;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.time.LocalDateTime;
import javax.validation.constraints.NotEmpty;
import lombok.*;
import lombok.experimental.FieldDefaults;
/**
* @author tzl
* 2022/4/19 14:15
*/
@ApiModel("VisitorParam")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
public class VisitorParam implements Serializable {
private static final long serialVersionUID = 1444009404727514785L;
@ApiModelProperty(value = "到访人姓名", example = "张三", required = true)
@NotEmpty(message = "到访人姓名不能为空")
String visitorName;
@ApiModelProperty(value = "到访人电话", example = "17688888888", required = true)
@NotEmpty(message = "到访人电话不能为空")
String visitorMobile;
@ApiModelProperty(value = "到访人身份证", example = "430441190001255417", required = true)
@NotEmpty(message = "到访人身份证不能为空")
String visitorCarNum;
@ApiModelProperty(value = "是否特殊作业", example = "fasle", required = true)
boolean taskType;
// @Comment("邀请人数")
// Integer numOfVisitor;
@ApiModelProperty(value = "访客来源", example = "外部邀请", required = true)
String visitorSource;
// @Comment("标签卡")
// String labelCard;
//
// @Comment("标签卡状态")
// String labelCardStatus;
@ApiModelProperty(value = "访客所属公司", example = "壹润科技")
String orgId;
@ApiModelProperty(value = "被访人id", example = "1", required = true)
String intervieweeId;
@ApiModelProperty(value = "来访原因", example = "看看", required = true)
String reason;
// @ApiModelProperty(value = "发卡时间", example = "看看", required = true)
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
// LocalDateTime cardRecTime;
@ApiModelProperty(value = "来访原因", example = "2022-04-19 14:28:00")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
LocalDateTime appOfVisitTime;
// @Comment("创建时间")
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
// LocalDateTime createTime;
//
// @Comment("发卡时间")
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
// LocalDateTime cardSendTime;
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.param.visitor;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.*;
import lombok.experimental.FieldDefaults;
/**
* @author tzl
* 2022/4/19 14:15
*/
@ApiModel("VisitorQueryParam")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
public class VisitorQueryParam implements Serializable {
private static final long serialVersionUID = -4314254785949101573L;
@ApiModelProperty(value = "访客姓名", example = "张三")
String visitorName;
@ApiModelProperty(value = "访客电话", example = "17688888888")
String visitorMobile;
@ApiModelProperty(value = "访客身份证", example = "430441190001255417")
String visitorCarNum;
@ApiModelProperty(value = "是否特殊作业", example = "fasle")
String taskType;
@ApiModelProperty(value = "所属公司", example = "壹润科技")
String orgId;
@ApiModelProperty(value = "访客来源", example = "外部邀请")
String visitorSource;
@ApiModelProperty(value = "被访人id", example = "1")
String intervieweeId;
@ApiModelProperty(value = "标签卡", example = "DS41234231")
String labelCard;
@ApiModelProperty(value = "标签卡状态", example = "1")
String labelCardStatus;
@ApiModelProperty(value = "预约到访时间(开始)", example = "2022-04-19 14:28:00")
LocalDateTime appOfVisitTimeStart;
@ApiModelProperty(value = "预约到访时间(结束)", example = "2022-04-19 14:28:00")
LocalDateTime appOfVisitTimeEnd;
@ApiModelProperty(value = "实际到访时间(开始)", example = "2022-04-19 14:28:00")
LocalDateTime cardSendTimeStart;
@ApiModelProperty(value = "实际到访时间(结束)", example = "2022-04-19 14:28:00")
LocalDateTime cardSendTimeEnd;
@ApiModelProperty(value = "收卡时间(开始)", example = "2022-04-11 17:25:33")
LocalDateTime cardRecTimeStart;
@ApiModelProperty(value = "收卡时间(结束)", example = "2022-04-11 17:26:33")
LocalDateTime cardRecTimeEnd;
@ApiModelProperty(value = "分页条数", example = "10")
Integer pageSize;
@ApiModelProperty(value = "当前页数", example = "1")
Integer pageNo;
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.rabbit.config;
import javax.annotation.Resource;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.amqp.RabbitProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
/**
* rabbitmq配置
*
* @author ifzm
* 2019/8/21 15:44
*/
@Configuration
public class RabbitConfig {
@Resource
RabbitProperties rabbitProperties;
private static final String CONNECTION_FACTORY_NAME = "rabbitConnectionFactory";
@Bean(CONNECTION_FACTORY_NAME)
@Primary
public ConnectionFactory connectionFactory() {
return RabbitConfig.connectionFactory(
rabbitProperties.getHost(),
rabbitProperties.getPort(),
rabbitProperties.getUsername(),
rabbitProperties.getPassword(),
rabbitProperties.getVirtualHost()
);
}
@Bean
@Primary
public RabbitListenerContainerFactory<?> rabbitListenerContainerFactory(
@Qualifier(CONNECTION_FACTORY_NAME) ConnectionFactory connectionFactory
) {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
return factory;
}
@Bean
@Primary
public RabbitTemplate rabbitTemplate(@Qualifier(CONNECTION_FACTORY_NAME) ConnectionFactory connectionFactory) {
return new RabbitTemplate(connectionFactory);
}
/**
* 创建连接工厂
*
* @param host 主机
* @param port 端口
* @param username 用户名
* @param password 密码
* @param virtualHost 虚拟主机
* @return 连接工厂
*/
public static CachingConnectionFactory connectionFactory(
String host,
int port,
String username,
String password,
String virtualHost
) {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
connectionFactory.setHost(host);
connectionFactory.setPort(port);
connectionFactory.setUsername(username);
connectionFactory.setPassword(password);
connectionFactory.setVirtualHost(virtualHost);
return connectionFactory;
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.config.zy;
package com.yiring.app.rabbit.config;
import javax.annotation.Resource;
import lombok.AccessLevel;
......
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.config.zy;
package com.yiring.app.rabbit.config;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
......@@ -43,8 +44,8 @@ public class ZyRabbitConfig {
public static final String MESSAGE_QUEUES_NAME = "tenant_msg_12A14FDC_sc21080400";
@Bean(CONNECTION_FACTORY_NAME)
public CachingConnectionFactory zyConnectionFactory() {
return connectionFactory(
public ConnectionFactory zyConnectionFactory() {
return RabbitConfig.connectionFactory(
rabbitmq.getHost(),
rabbitmq.getPort(),
rabbitmq.getUsername(),
......@@ -54,9 +55,9 @@ public class ZyRabbitConfig {
}
@Bean(LISTENER_FACTORY_NAME)
public SimpleRabbitListenerContainerFactory secondFactory(
public RabbitListenerContainerFactory<?> rabbitListenerContainerFactory(
SimpleRabbitListenerContainerFactoryConfigurer configurer,
@Qualifier(CONNECTION_FACTORY_NAME) CachingConnectionFactory connectionFactory
@Qualifier(CONNECTION_FACTORY_NAME) ConnectionFactory connectionFactory
) {
// 检查队列名称是否与配置文件一致,避免监听错误
if (!MESSAGE_QUEUES_NAME.equals(rabbitmq.getQueueName())) {
......@@ -66,31 +67,9 @@ public class ZyRabbitConfig {
}
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
// 最小消费者数量
factory.setConcurrentConsumers(1);
// 最大消费者数量
factory.setMaxConcurrentConsumers(1);
// 预读取一条消息
factory.setPrefetchCount(1);
// 手动确认消息模式
factory.setAcknowledgeMode(AcknowledgeMode.MANUAL);
configurer.configure(factory, connectionFactory);
return factory;
}
public CachingConnectionFactory connectionFactory(
String host,
int port,
String username,
String password,
String virtualHost
) {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
connectionFactory.setHost(host);
connectionFactory.setPort(port);
connectionFactory.setUsername(username);
connectionFactory.setPassword(password);
connectionFactory.setVirtualHost(virtualHost);
return connectionFactory;
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.rabbitmq;
package com.yiring.app.rabbit.receiver;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
......
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.rabbitmq.zy;
package com.yiring.app.rabbit.receiver;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.rabbitmq.client.Channel;
import com.yiring.app.config.zy.ZyRabbitConfig;
import com.yiring.app.push.domain.PushMessage;
import com.yiring.app.push.service.PushService;
import com.yiring.app.domain.location.*;
import com.yiring.app.domain.log.ZyRealtimeLog;
import com.yiring.app.domain.log.ZyRealtimeLogRepository;
import com.yiring.app.rabbit.config.ZyRabbitConfig;
import com.yiring.app.util.GeoUtils;
import java.io.IOException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.locationtech.jts.geom.Point;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.Example;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
......@@ -30,7 +40,7 @@ import org.springframework.transaction.annotation.Transactional;
@Component
@Configuration
@ConditionalOnProperty(prefix = "zy-config.rabbitmq", value = "enabled", havingValue = "true")
public class ZyRabbitmqReceiver {
public class ZyRabbitReceiver {
// TODO
// 1. 新增消息订阅定时任务,检查是否正常订阅了真源定位系统的消息
......@@ -38,7 +48,19 @@ public class ZyRabbitmqReceiver {
// 3. 订阅 position(定位数据)、lowPower(低电量报警)、deviceStatus(设备状态)、keyWarning(按键报警)
@Resource
PushService pushService;
LocationTagRepository locationTagRepository;
@Resource
LocationBeaconRepository locationBeaconRepository;
@Resource
LocationLogRepository locationLogRepository;
@Resource
SimpMessagingTemplate simpMessagingTemplate;
@Resource
ZyRealtimeLogRepository zyRealtimeLogRepository;
/**
* 订阅真源定位系统 RabbitMQ 推送过来的消息(主动订阅的一些消息类别)
......@@ -65,6 +87,12 @@ public class ZyRabbitmqReceiver {
// 解构消息内容
JSONObject data = info.getJSONObject("params");
String method = info.getString("method");
// 记录日志
ZyRealtimeLog realtimeLog = ZyRealtimeLog.builder().method(method).raw(info).build();
zyRealtimeLogRepository.save(realtimeLog);
// 业务处理
switch (method) {
// 实时定位
case "position" -> processPositionMessage(data);
......@@ -74,6 +102,8 @@ public class ZyRabbitmqReceiver {
case "deviceStatus" -> processDeviceStatusMessage(data);
// 按键报警
case "keyWarning" -> processKeyWarningMessage(data);
// 围栏报警
case "enclosure" -> log.warn("Ignore Message Type [enclosure]: {}", info);
default -> log.warn("Unknown Message Type: {}", info);
}
} catch (Exception e) {
......@@ -95,9 +125,74 @@ public class ZyRabbitmqReceiver {
// 1. 解析消息内容,进行围栏、出入标识判断等处理,将定位记录录入数据库
// 2. 创建一条需要进行消息推送的记录
// 3. 将记录推送的消息推送模块
// 4. 检查是否触发围栏告警,记录告警数据,并推送消息
// 定位时间
Instant instant = Instant.ofEpochMilli(data.getLongValue("locationTime"));
LocalDateTime time = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
// 定位的基本信息
LocationLog locationLog = LocationLog
.builder()
.raw(data)
.locationTime(time)
.silent(data.getBoolean("silent"))
.volt(data.getInteger("volt"))
.voltUnit(data.getString("voltUnit"))
.build();
// WebSocket 消息推送
pushService.push(PushMessage.Type.WS, data);
// 设置空间点位信息
Point point = GeoUtils.createPoint(
data.getDoubleValue("longitude"),
data.getDoubleValue("latitude"),
data.getDoubleValue("altitude")
);
locationLog.setPoint(point);
// 查询定位标签
Example<LocationTag> example = Example.of(LocationTag.builder().code(data.getString("tagId")).build());
Optional<LocationTag> optional = locationTagRepository.findOne(example);
if (optional.isPresent()) {
LocationTag tag = optional.get();
// 设置定位标签
locationLog.setTag(tag);
// 定位标签当时所属的用户
locationLog.setUser(tag.getUser());
// 查询当前用户的状态
// TODO
}
// 查询定位信标
Set<String> codes = Arrays
.stream(data.getString("beacons").split(","))
.map(beacon -> beacon.replaceAll("\\(.*\\)", ""))
.collect(Collectors.toSet());
Set<LocationBeacon> beacons = locationBeaconRepository.findByCodeIn(codes);
locationLog.setBeacons(beacons);
// 查询定位所在围栏信息
Set<LocationFence> fences = locationLog
.getBeacons()
.stream()
.map(LocationBeacon::getFences)
.flatMap(Set::stream)
.collect(Collectors.toSet());
locationLog.setFences(fences);
// TODO
// 并计算出入标记(围栏、区域)
// 写入数据
locationLogRepository.saveAndFlush(locationLog);
// 更新定位标签卡电量信息
// TODO
// WebSocket 推送定位消息
// 消息内容需要确定 TODO
simpMessagingTemplate.convertAndSend("/topic/position", "{}");
// TODO
// 判断围栏告警是否触发,触发写入告警记录,并推送消息
}
/**
......
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.rabbitmq;
import org.springframework.context.annotation.Configuration;
/**
* rabbitmq配置
*
* @author ifzm
* 2019/8/21 15:44
*/
@Configuration
public class RabbitConfig {}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.service.appletUser;
import com.yiring.common.core.Result;
/**
* @author Administrator
* @version 1.0
* @description: 微信小程序用户
* @date 2022/4/24 9:22
*/
public interface AppletUserService {
/**
* 根据用户唯一标识获取手机号码,通过手机号码查询用户来访信息分页
* @author tzl
* @date 2022/4/24 9:34
* @param appid String
* @param secret String
* @param js_code String
* @param grant_type String
* @return com.yiring.common.core.Result<java.lang.String>
*/
Result<String> selectMobile(String appid, String secret, String js_code, String grant_type);
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.service.appletUser.impl;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.yiring.app.domain.appletUser.AppletUser;
import com.yiring.app.domain.appletUser.AppletUserRepository;
import com.yiring.app.feign.WxClient;
import com.yiring.app.service.appletUser.AppletUserService;
import com.yiring.common.core.Result;
import java.util.Optional;
import javax.annotation.Resource;
/**
* @author Administrator
* @version 1.0
* @description: TODO
* @date 2022/4/24 9:25
*/
public class AppletUserServiceImpl implements AppletUserService {
@Resource
AppletUserRepository appletUserRepository;
@Resource
WxClient wxClient;
@Override
public Result<String> selectMobile(String appid, String secret, String js_code, String grant_type) {
JSONObject jsonObject = wxClient.getOpenid(appid, secret, js_code, grant_type);
Object openid = jsonObject.get("openid");
if (StrUtil.isNotBlank(openid.toString())) {
Optional<AppletUser> optional = appletUserRepository.findById(openid.toString());
//如果该微信为第一次登录小程序
if (optional.isEmpty()) {
return Result.ok("绑定手机号码");
}
AppletUser appletUser = optional.get();
return Result.ok(appletUser.getMobile());
}
return null;
}
}
......@@ -8,7 +8,7 @@ import com.yiring.app.vo.car.CarVo;
import com.yiring.common.core.Result;
import com.yiring.common.param.IdParam;
import com.yiring.common.vo.PageVo;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.data.jpa.domain.Specification;
/**
......@@ -28,6 +28,7 @@ public interface CarService {
* 修改车辆来访信息
*
* @param carParam CarParam
* @param idParam IdParam
* @return 修改的车辆来访信息id
*/
Result<Long> updateCarInfo(CarParam carParam, IdParam idParam);
......@@ -44,6 +45,7 @@ public interface CarService {
* 发卡
*
* @param idParam IdParam
* @param labelCard String
* @return 发卡信息id
*/
Result<Long> cardSend(IdParam idParam, String labelCard);
......@@ -73,9 +75,11 @@ public interface CarService {
Result<PageVo<CarVo>> pageCarInfo(CarQueryParam carParam);
/**
* 导出excel
* 导出接口
* @param carParam CarQueryParam
* @param response HttpServletResponse
*/
List<Car> export(CarQueryParam carParam);
void export(CarQueryParam carParam, HttpServletResponse response);
/**
* 检查是否存在相同车牌号登记
......@@ -94,6 +98,7 @@ public interface CarService {
boolean hasCarInfoByMobile(String param);
/**
* 筛选条件
* @param carParam CarQueryParam
* @return Specification
*/
......
......@@ -2,8 +2,10 @@
package com.yiring.app.service.car.impl;
import cn.hutool.core.util.StrUtil;
import com.github.liaochong.myexcel.core.DefaultStreamExcelBuilder;
import com.yiring.app.domain.car.Car;
import com.yiring.app.domain.car.CarRepository;
import com.yiring.app.excel.car.CarExportExcel;
import com.yiring.app.param.car.CarParam;
import com.yiring.app.param.car.CarQueryParam;
import com.yiring.app.service.car.CarService;
......@@ -13,23 +15,33 @@ import com.yiring.common.core.Result;
import com.yiring.common.core.Status;
import com.yiring.common.param.IdParam;
import com.yiring.common.vo.PageVo;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.persistence.criteria.Predicate;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.*;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* @author tzl
* 2022/4/11 13:58
*/
@Slf4j
@Transactional(rollbackFor = RuntimeException.class)
@Service
public class CarServiceImpl implements CarService {
......@@ -40,15 +52,14 @@ public class CarServiceImpl implements CarService {
public Result<Long> saveCarInfo(CarParam carParam) {
// 检查车牌号是否已存在
if (hasCarInfoByCarNum(carParam.getCarNum())) {
return Result.no(Status.BAD_REQUEST, "您的车牌号已预约登记");
return Result.no(Status.BAD_REQUEST, "您的车牌号已存在");
}
// 检查司机手机号码号是否已存在
if (hasCarInfoByMobile(carParam.getDriverMobile())) {
return Result.no(Status.BAD_REQUEST, "您的联系方式已预约登记");
return Result.no(Status.BAD_REQUEST, "您的联系方式已存在");
}
Car car = Car
.builder()
.labelCardStatus("1")
.carNum(carParam.getCarNum())
.carType(carParam.getCarType())
.driverMobile(carParam.getDriverMobile())
......@@ -69,20 +80,16 @@ public class CarServiceImpl implements CarService {
return Result.no(Status.NOT_FOUND);
}
Car car = optional.get();
//如果标签卡在使用中无法修改
if (StrUtil.isNotBlank(car.getLabelCardStatus()) && "2".equals(car.getLabelCardStatus())) {
return Result.no(Status.BAD_REQUEST, "标签卡使用中,信息无法修改");
}
if (!car.getCarNum().equals(carParam.getCarNum())) {
// 当修改车牌号时才检查重复
if (hasCarInfoByCarNum(carParam.getCarNum())) {
return Result.no(Status.BAD_REQUEST, "您的车牌号已预约登记");
return Result.no(Status.BAD_REQUEST, "您的车牌号信息已存在");
}
}
if (!car.getDriverMobile().equals(carParam.getDriverMobile())) {
// 当修改联系方式时才检查重复
if (hasCarInfoByMobile(carParam.getDriverMobile())) {
return Result.no(Status.BAD_REQUEST, "您的联系方式已预约登记");
return Result.no(Status.BAD_REQUEST, "您的联系方式已存在");
}
}
BeanUtils.copyProperties(carParam, car);
......@@ -97,7 +104,6 @@ public class CarServiceImpl implements CarService {
return Result.no(Status.NOT_FOUND);
}
Car car = optional.get();
car.setLabelCardStatus("3");
car.setCardRecTime(LocalDateTime.now());
Car carReuslt = carRepository.saveAndFlush(car);
return Result.ok(carReuslt.getId());
......@@ -110,7 +116,6 @@ public class CarServiceImpl implements CarService {
return Result.no(Status.NOT_FOUND);
}
Car car = optional.get();
car.setLabelCardStatus("2");
car.setCardSendTime(LocalDateTime.now());
car.setLabelCard(labelCard);
Car carReuslt = carRepository.saveAndFlush(car);
......@@ -123,12 +128,7 @@ public class CarServiceImpl implements CarService {
if (optional.isEmpty()) {
return Result.no(Status.NOT_FOUND);
}
//正在使用中的信息无法删除
Car entity = optional.get();
if ("2".equals(entity.getLabelCardStatus())) {
return Result.no(Status.BAD_REQUEST, "标签卡使用中,信息无法删除");
}
carRepository.delete(entity);
return Result.ok();
}
......@@ -148,7 +148,7 @@ public class CarServiceImpl implements CarService {
@Override
public Result<PageVo<CarVo>> pageCarInfo(CarQueryParam carParam) {
PageVo<CarVo> resultVo = null;
PageVo<CarVo> resultVo;
//排序
Sort sort = Sort.by(Sort.Order.desc(Car.Fields.createTime));
//如果传分页参数则分页,否查全部数据
......@@ -181,26 +181,60 @@ public class CarServiceImpl implements CarService {
}
@Override
public List<Car> export(CarQueryParam carParam) {
return carRepository.findAll(condition(carParam));
public void export(CarQueryParam carParam, HttpServletResponse response) {
Specification<Car> specification = condition(carParam);
List<Car> all = carRepository.findAll(specification);
List<CarExportExcel> data = all
.stream()
.map(car -> {
CarExportExcel carExportExcel = new CarExportExcel();
BeanUtils.copyProperties(car, carExportExcel);
return carExportExcel;
})
.collect(Collectors.toList());
try (
DefaultStreamExcelBuilder<CarExportExcel> streamExcelBuilder = DefaultStreamExcelBuilder
.of(CarExportExcel.class)
.threadPool(Executors.newFixedThreadPool(2))
.rowHeight(14)
.titleRowHeight(14)
.style(
"cell->vertical-align:center;text-align:center",
"title->vertical-align:center;text-align:center;font-weight:bold;font-family:等线"
)
.start()
) {
streamExcelBuilder.append(data);
String fileName = URLEncoder.encode("车辆来访信息.xlsx", StandardCharsets.UTF_8);
response.setContentType("application/octet-stream");
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
OutputStream out = response.getOutputStream();
Workbook workbook = streamExcelBuilder.fixedTitles().build();
workbook.write(out);
workbook.close();
out.flush();
out.close();
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new RuntimeException("导出车辆来访信息失败: " + e.getMessage());
}
}
@Override
public boolean hasCarInfoByCarNum(String param) {
Car entity = Car.builder().carNum(param).labelCardStatus("1").build();
Car entity = Car.builder().carNum(param).build();
long count = carRepository.count(Example.of(entity));
entity = Car.builder().carNum(param).labelCardStatus("2").build();
long count1 = carRepository.count(Example.of(entity));
return count + count1 > 0;
return count > 0;
}
@Override
public boolean hasCarInfoByMobile(String param) {
Car entity = Car.builder().driverMobile(param).labelCardStatus("1").build();
Car entity = Car.builder().driverMobile(param).build();
long count = carRepository.count(Example.of(entity));
entity = Car.builder().driverMobile(param).labelCardStatus("2").build();
long count1 = carRepository.count(Example.of(entity));
return count + count1 > 0;
return count > 0;
}
@Override
......@@ -249,7 +283,7 @@ public class CarServiceImpl implements CarService {
//来访时间区间段查询
list.add(
criteriaBuilder.between(
root.get(Car.Fields.createTime),
root.get(Car.Fields.cardSendTime),
carParam.getCreateTimeStart(),
carParam.getCreateTimeEnd()
)
......@@ -263,15 +297,15 @@ public class CarServiceImpl implements CarService {
);
}
if (StrUtil.isNotBlank(carParam.getLabelCardStatus())) {
//标签卡状态查询
list.add(
criteriaBuilder.equal(root.get("labelCardStatus").as(String.class), carParam.getLabelCardStatus())
);
}
// if (StrUtil.isNotBlank(carParam.getLabelCardStatus())) {
// //标签卡状态查询
// list.add(
// criteriaBuilder.equal(root.get("labelCardStatus").as(String.class), carParam.getLabelCardStatus())
// );
// }
if (Objects.nonNull(carParam.getCardRecTimeStart()) && Objects.nonNull(carParam.getCardRecTimeEnd())) {
//来访时间区间段查询
//收卡时间区间段查询
list.add(
criteriaBuilder.between(
root.get(Car.Fields.cardRecTime),
......
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.service.video;
import com.yiring.app.domain.video.Video;
import com.yiring.app.param.video.VideoParam;
import com.yiring.app.param.video.VideoQueryParam;
import com.yiring.app.vo.video.VideoVo;
import com.yiring.common.core.Result;
import com.yiring.common.param.IdParam;
import com.yiring.common.param.PageParam;
import com.yiring.common.vo.PageVo;
import java.awt.*;
import javax.servlet.http.HttpServletResponse;
import org.locationtech.jts.geom.Point;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.web.multipart.MultipartFile;
/**
* @author tzl
......@@ -57,10 +60,32 @@ public interface VideoService {
/**
* 分页查询
* @param videoQueryParam 筛选条件
* @param param 分页参数
* @return Result<PageVo<VideoVo>> 分页结果集
* @author tzl
* @date 2022/4/15 14:35
*/
Result<PageVo<VideoVo>> pageVideo(VideoQueryParam videoQueryParam, PageParam param);
Result<PageVo<VideoVo>> pageVideo(VideoQueryParam videoQueryParam);
/**
* 查询条件
* @param videoQueryParam 查询条件
* @return Specification<Video>
* @author tzl
* @date 2022/4/15 14:57
*/
Specification<Video> condition(VideoQueryParam videoQueryParam);
/**
* 条件查询数据导出
* @param videoQueryParam 查询条件
* @param response HttpServletResponse
*/
void exportVideo(VideoQueryParam videoQueryParam, HttpServletResponse response);
/**
* 导入视频监控点位信息
* @param file 上传的excel文件
* @return 是否成功
*/
Result<String> importVideo(MultipartFile file);
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.service.video.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.github.liaochong.myexcel.core.DefaultStreamExcelBuilder;
import com.github.liaochong.myexcel.core.SaxExcelReader;
import com.yiring.app.domain.video.Video;
import com.yiring.app.domain.video.VideoRepository;
import com.yiring.app.excel.video.VideoExportExcel;
import com.yiring.app.excel.video.VideoImportExcel;
import com.yiring.app.feign.GbClient;
import com.yiring.app.param.video.StreamProxyItem;
import com.yiring.app.param.video.VideoParam;
import com.yiring.app.param.video.VideoQueryParam;
import com.yiring.app.service.video.VideoService;
......@@ -12,32 +20,50 @@ import com.yiring.app.vo.video.VideoVo;
import com.yiring.common.core.Result;
import com.yiring.common.core.Status;
import com.yiring.common.param.IdParam;
import com.yiring.common.param.PageParam;
import com.yiring.common.vo.PageVo;
import feign.Response;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.persistence.criteria.Predicate;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;
import org.locationtech.jts.geom.Point;
import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.*;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
/**
* @author tzl
* 2022/4/8 15:28
*/
@Slf4j
@Transactional(rollbackFor = RuntimeException.class)
@Service
public class VideoServiceImpl implements VideoService {
@Resource
VideoRepository videoRepository;
@Resource
GbClient gbClient;
@Resource
RedisTemplate<String, Object> redisTemplate;
@Override
public Result<String> saveVideo(VideoParam videoParam) {
if (has(videoParam.getUuid())) {
......@@ -47,13 +73,8 @@ public class VideoServiceImpl implements VideoService {
Video video = Video
.builder()
.createTime(LocalDateTime.now())
// .enable(videoParam.getEnable())
// .m3u8(videoParam.getM3u8())
// .point(videoParam.getPoint())
.m3u8(videoParam.getM3u8())
.point(GeoUtils.createPoint(videoParam.getLon(), videoParam.getLat()))
// .online(videoParam.getOnline())
// .type(videoParam.getType())
//默认正常
.videoName(videoParam.getVideoName())
.status("1")
......@@ -63,7 +84,22 @@ public class VideoServiceImpl implements VideoService {
videoRepository.saveAndFlush(video);
//还需要同步添加国标28181中对应的摄像头信息
//标识uuid对应流id,m3u8对应拉流地址,如m3u8中有标注 则将类型切换为FFmpeg,摄像头名称videoName对应名称,流名称默认"stream",超时时间默认60
StreamProxyItem streamProxyItem = StreamProxyItem
.builder()
.name(video.getVideoName())
.app("stream")
.stream(video.getUuid())
.url(video.getM3u8())
.mediaServerId("ZbnQN5csqxrPix7a")
.enable(true)
.enable_hls(true)
.type(video.getM3u8().contains("sss") ? "ffmpeg" : "default")
.timeout_ms(video.getM3u8().contains("sss") ? 60 : null)
.build();
JSONObject jsonObject = gbClient.proxySave(streamProxyItem, gbCookie());
if (!jsonObject.get("code").equals(0)) {
throw new RuntimeException(jsonObject.get("msg").toString());
}
return Result.ok();
}
......@@ -74,8 +110,12 @@ public class VideoServiceImpl implements VideoService {
return Result.no(Status.NOT_FOUND);
}
Video video = optional.get();
videoRepository.delete(video);
//还需要同步删除国标28181中对应的摄像头信息
JSONObject jsonObject = gbClient.proxyDel("stream", video.getUuid(), gbCookie());
if (!jsonObject.get("code").equals(0)) {
throw new RuntimeException(jsonObject.get("msg").toString());
}
videoRepository.delete(video);
return Result.ok();
}
......@@ -92,11 +132,39 @@ public class VideoServiceImpl implements VideoService {
if (has(videoParam.getUuid())) {
return Result.no(Status.BAD_REQUEST, "您输入的编号已存在");
}
//当修改跟国标相关联的信息时同步更新国标数据
// if (
// !video.getVideoName().equals(videoParam.getVideoName()) && !video.getM3u8().equals(videoParam.getM3u8())
// ) {
JSONObject jsonObject = gbClient.proxyDel("stream", video.getUuid(), gbCookie());
if (!jsonObject.get("code").equals(0)) {
throw new RuntimeException(jsonObject.get("msg").toString());
}
}
// }
BeanUtils.copyProperties(videoParam, video);
video.setPoint(GeoUtils.createPoint(videoParam.getLon(), videoParam.getLat()));
videoRepository.saveAndFlush(video);
//还需要同步修改国标28181中对应的摄像头信息
//将信息发送到队列,等待同步至国标
// new Thread(() -> {
StreamProxyItem streamProxyItem = StreamProxyItem
.builder()
.name(video.getVideoName())
.app("stream")
.stream(video.getUuid())
.url(video.getM3u8())
.mediaServerId("ZbnQN5csqxrPix7a")
.enable(true)
.enable_hls(true)
.type(video.getM3u8().contains("sss") ? "ffmpeg" : "default")
.timeout_ms(video.getM3u8().contains("sss") ? 60 : null)
.build();
JSONObject jsonObject = gbClient.proxySave(streamProxyItem, gbCookie());
if (!jsonObject.get("code").equals(0)) {
throw new RuntimeException(jsonObject.get("msg").toString());
}
// })
// .start();
return Result.ok();
}
......@@ -111,25 +179,47 @@ public class VideoServiceImpl implements VideoService {
}
@Override
public Result<PageVo<VideoVo>> pageVideo(VideoQueryParam videoQueryParam, PageParam param) {
Page<Video> all = videoRepository.findAll(condition(videoQueryParam), PageParam.toPageable(param));
List<VideoVo> data = all
.get()
.map(video -> {
VideoVo vo = new VideoVo();
BeanUtils.copyProperties(video, vo);
return vo;
})
.collect(Collectors.toList());
PageVo<VideoVo> vo = PageVo.build(data, all.getTotalElements());
return Result.ok(vo);
public Result<PageVo<VideoVo>> pageVideo(VideoQueryParam videoQueryParam) {
PageVo<VideoVo> resultVo;
//排序
Sort sort = Sort.by(Sort.Order.desc(Video.Fields.createTime));
//如果传分页参数则分页,否查全部数据
if (Objects.nonNull(videoQueryParam.getPageNo()) && Objects.nonNull(videoQueryParam.getPageSize())) {
//分页
Pageable pageable = PageRequest.of(videoQueryParam.getPageNo() - 1, videoQueryParam.getPageSize());
Page<Video> all = videoRepository.findAll(condition(videoQueryParam), pageable);
List<VideoVo> data = all
.get()
.map(car -> {
VideoVo vo = new VideoVo();
BeanUtils.copyProperties(car, vo);
return vo;
})
.collect(Collectors.toList());
resultVo = PageVo.build(data, all.getTotalElements());
} else {
List<Video> all = videoRepository.findAll(condition(videoQueryParam), sort);
List<VideoVo> data = all
.stream()
.map(video -> {
VideoVo vo = new VideoVo();
BeanUtils.copyProperties(video, vo);
// vo.setPoint(video.getPoint());
return vo;
})
.collect(Collectors.toList());
resultVo = PageVo.build(data, data.size());
}
return Result.ok(resultVo);
}
/**
* 条件查询
*
* @param videoQueryParam 筛选条件
* @return Specification
*/
@Override
public Specification<Video> condition(VideoQueryParam videoQueryParam) {
return (root, query, criteriaBuilder) -> {
List<Predicate> list = new ArrayList<>();
......@@ -157,8 +247,136 @@ public class VideoServiceImpl implements VideoService {
};
}
@Override
public void exportVideo(VideoQueryParam videoQueryParam, HttpServletResponse response) {
Specification<Video> specification = condition(videoQueryParam);
List<Video> all = videoRepository.findAll(specification);
List<VideoExportExcel> data = all
.stream()
.map(video -> {
VideoExportExcel videoExportExcel = new VideoExportExcel();
BeanUtils.copyProperties(video, videoExportExcel);
return videoExportExcel;
})
.collect(Collectors.toList());
try (
DefaultStreamExcelBuilder<VideoExportExcel> streamExcelBuilder = DefaultStreamExcelBuilder
.of(VideoExportExcel.class)
.threadPool(Executors.newFixedThreadPool(2))
.rowHeight(14)
.titleRowHeight(14)
.style(
"cell->vertical-align:center;text-align:center",
"title->vertical-align:center;text-align:center;font-weight:bold;font-family:等线"
)
.start()
) {
streamExcelBuilder.append(data);
String fileName = URLEncoder.encode("监控点位来访信息.xlsx", StandardCharsets.UTF_8);
response.setContentType("application/octet-stream");
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
OutputStream out = response.getOutputStream();
Workbook workbook = streamExcelBuilder.fixedTitles().build();
workbook.write(out);
workbook.close();
out.flush();
out.close();
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new RuntimeException("导出监控点位来访信息失败: " + e.getMessage());
}
}
@Override
public Result<String> importVideo(MultipartFile file) {
if (file.isEmpty()) {
throw new RuntimeException("请选择文件");
}
List<VideoImportExcel> videoImportExcels;
try (InputStream inputStream = file.getInputStream()) {
videoImportExcels =
SaxExcelReader
.of(VideoImportExcel.class)
.rowFilter(row -> row.getRowNum() > 0)
.ignoreBlankRow()
.read(inputStream);
} catch (IOException e) {
log.info(e.getMessage());
throw new RuntimeException("文件导入异常");
}
List<Video> videos = videoImportExcels
.stream()
.map(videoImportExcel -> {
Video video = new Video();
BeanUtils.copyProperties(videoImportExcel, video);
video.setPoint(GeoUtils.createPoint(videoImportExcel.getLon(), videoImportExcel.getLat()));
video.setCreateTime(LocalDateTime.now());
return video;
})
.toList();
if (videos != null) {
videos.forEach(video -> {
videoRepository
.findOne((root, cq, cb) -> {
List<Predicate> predicates = new ArrayList<>();
if (StrUtil.isNotBlank(video.getUuid())) {
predicates.add(cb.equal(root.get("uuid").as(String.class), video.getUuid()));
}
return cq.where(predicates.toArray(new Predicate[0])).getRestriction();
})
.ifPresent(one -> {
//如果存在则操作修改
video.setId(one.getId());
//删除国标关联监控信息
gbClient.proxyDel("stream", video.getUuid(), gbCookie());
});
videoRepository.saveAndFlush(video);
//导入监控点位后,还需要同步数据到国标28181
StreamProxyItem streamProxyItem = StreamProxyItem
.builder()
.name(video.getVideoName())
.app("stream")
.stream(video.getUuid())
.url(video.getM3u8())
.mediaServerId("ZbnQN5csqxrPix7a")
.enable(true)
.enable_hls(true)
.type(video.getM3u8().contains("sss") ? "default" : "ffmpeg")
.timeout_ms(video.getM3u8().contains("sss") ? 60 : null)
.build();
JSONObject jsonObject = gbClient.proxySave(streamProxyItem, gbCookie());
if (!jsonObject.get("code").equals(0)) {
throw new RuntimeException(jsonObject.get("msg").toString());
}
});
}
return Result.ok();
}
boolean has(String uuid) {
Video video = Video.builder().uuid(uuid).build();
return videoRepository.count(Example.of(video)) > 0;
}
/**
* 获取国标系统登录cookie
*
* @return cookie
*/
String gbCookie() {
Object gbCookie = redisTemplate.opsForValue().get("gb_cookie");
if (ObjectUtil.isNotEmpty(gbCookie)) {
return String.valueOf(gbCookie);
}
Response response = gbClient.userLogin("admin", "21232f297a57a5a743894a0e4a801fc3");
Collection<String> strings = response.headers().get("Set-Cookie");
String jsessionid = strings.stream().filter(a -> a.contains("JSESSIONID")).collect(Collectors.joining(", "));
redisTemplate.opsForValue().set("gb_cookie", jsessionid, 30, TimeUnit.MINUTES);
return jsessionid;
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.service.visitor;
import com.yiring.app.param.visitor.VisitorListParam;
import com.yiring.app.param.visitor.VisitorParam;
import com.yiring.app.param.visitor.VisitorQueryParam;
import com.yiring.app.vo.visitor.VisitorVo;
import com.yiring.common.core.Result;
import com.yiring.common.param.IdParam;
import com.yiring.common.vo.PageVo;
import javax.servlet.http.HttpServletResponse;
/**
* @author tzl
* 2022/4/19 14:12
*/
public interface VisitorService {
/**
* 访客新增
* @param visitorParam 新增访客入参
* @return 是否成功
*/
Result<String> saveVisitor(VisitorParam visitorParam);
/**
* 访客批量新增
* @param visitorListParam 批量访客新增入参
* @return 是否成功
*/
Result<String> saveVisitor(VisitorListParam visitorListParam);
/**
* 访客删除
* @param idParam 主键id
* @return 是否成功
*/
Result<String> deleteVisitor(IdParam idParam);
/**
* 修改访客信息
* @param visitorParam 修改访客入参
* @param idParam 修改访客的主键id
* @return 是否成功
*/
Result<String> updateVisitor(VisitorParam visitorParam, IdParam idParam);
/**
* 查询访客详情
* @param idParam 主键id
* @return 访客信息
*/
Result<VisitorVo> selectVisitor(IdParam idParam);
/**
* 分页查询
* @param visitorQueryParam 访客查询参数
* @return 访客分页信息
*/
Result<PageVo<VisitorVo>> pageVisitor(VisitorQueryParam visitorQueryParam);
/**
* 导出访客信息
* @param visitorQueryParam 访客筛选条件
* @param response HttpServletResponse
*/
void exportVisitor(VisitorQueryParam visitorQueryParam, HttpServletResponse response);
/**
* 发卡
* @param labelCard 标签卡号
* @param idParam 主键id
* @return 是否成功
*/
Result<String> cardSend(String labelCard, IdParam idParam);
/**
* 收卡
* @param idParam 主键id
* @return 是否成功
*/
Result<String> cardRec(IdParam idParam);
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.service.visitor.impl;
import cn.hutool.core.util.StrUtil;
import com.github.liaochong.myexcel.core.DefaultStreamExcelBuilder;
import com.yiring.app.domain.appletUser.AppletUserRepository;
import com.yiring.app.domain.visitor.Visitor;
import com.yiring.app.domain.visitor.VisitorRepository;
import com.yiring.app.excel.visitor.VisitorExportExcel;
import com.yiring.app.param.visitor.VisitorInfoParam;
import com.yiring.app.param.visitor.VisitorListParam;
import com.yiring.app.param.visitor.VisitorParam;
import com.yiring.app.param.visitor.VisitorQueryParam;
import com.yiring.app.service.visitor.VisitorService;
import com.yiring.app.vo.visitor.VisitorVo;
import com.yiring.common.core.Result;
import com.yiring.common.core.Status;
import com.yiring.common.param.IdParam;
import com.yiring.common.vo.PageVo;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.persistence.criteria.Predicate;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.*;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* @author tzl
* 2022/4/19 14:12
*/
@Slf4j
@Transactional(rollbackFor = RuntimeException.class)
@Service
public class VisitorServiceImpl implements VisitorService {
@Resource
VisitorRepository visitorRepository;
@Resource
AppletUserRepository appletUserRepository;
@Override
public Result<String> saveVisitor(VisitorParam visitorParam) {
if (hasVisitorMobile(visitorParam.getVisitorMobile())) {
return Result.no(Status.BAD_REQUEST, "您输入的手机号码已经预约");
}
if (hasCarNum(visitorParam.getVisitorCarNum())) {
return Result.no(Status.BAD_REQUEST, "您输入的身份证号码已经预约");
}
//设置创建时间和默认状态
Visitor visitor = Visitor.builder().createTime(LocalDateTime.now()).build();
BeanUtils.copyProperties(visitorParam, visitor);
visitorRepository.saveAndFlush(visitor);
return Result.ok();
}
@Override
public Result<String> saveVisitor(VisitorListParam visitorListParam) {
List<VisitorInfoParam> visitorInfos = visitorListParam.getVisitorInfos();
List<String> mobileList = new ArrayList<>();
List<String> carList = new ArrayList<>();
//如果存在重复身份证,电话号码,将其信息装入集合
visitorInfos.forEach(visitorInfoParam -> {
if (hasVisitorMobile(visitorInfoParam.getVisitorMobile())) {
mobileList.add(visitorInfoParam.getVisitorMobile());
}
if (hasCarNum(visitorInfoParam.getVisitorCarNum())) {
carList.add(visitorInfoParam.getVisitorCarNum());
}
});
if (mobileList.size() > 0) {
return Result.no(Status.BAD_REQUEST, mobileList + "手机号已经预约,请勿重复预约");
}
if (carList.size() > 0) {
return Result.no(Status.BAD_REQUEST, carList + "身份证已经预约,请勿重复预约");
}
List<Visitor> visitorList = new ArrayList<>();
//补全访客其他信息
visitorInfos.forEach(visitorInfoParam -> {
Visitor visitor = new Visitor();
BeanUtils.copyProperties(visitorInfoParam, visitor);
visitor.setOrgId(visitorListParam.getOrgId());
visitor.setNumOfVisitor(visitorListParam.getNumOfVisitor());
visitor.setReason(visitorListParam.getReason());
visitor.setIntervieweeId(visitorListParam.getIntervieweeId());
visitorList.add(visitor);
});
visitorRepository.saveAll(visitorList);
//通知用户登录微信小程序查看
//查看该手机是否已注册小程序
// visitorInfos.forEach(visitorInfoParam -> {
// if(appletUserRepository.countMobile(visitorInfoParam.getVisitorMobile())<1){
// 没有的情况下为qi
// }
// });
return Result.ok();
}
@Override
public Result<String> deleteVisitor(IdParam idParam) {
Optional<Visitor> optional = visitorRepository.findById(idParam.getId());
if (optional.isEmpty()) {
return Result.no(Status.NOT_FOUND);
}
visitorRepository.delete(optional.get());
return Result.ok();
}
@Override
public Result<String> updateVisitor(VisitorParam visitorParam, IdParam idParam) {
Optional<Visitor> optional = visitorRepository.findById(idParam.getId());
if (optional.isEmpty()) {
return Result.no(Status.NOT_FOUND);
}
Visitor visitor = optional.get();
if (!visitor.getVisitorCarNum().equals(visitorParam.getVisitorCarNum())) {
//当修改身份证时
if (hasCarNum(visitorParam.getVisitorCarNum())) {
return Result.no(Status.BAD_REQUEST, "您输入的身份证号码已经预约");
}
}
if (!visitor.getVisitorMobile().equals(visitorParam.getVisitorMobile())) {
//当修改手机号码时
if (hasVisitorMobile(visitorParam.getVisitorMobile())) {
return Result.no(Status.BAD_REQUEST, "您输入的手机号码已经预约");
}
}
BeanUtils.copyProperties(visitorParam, visitor);
visitorRepository.saveAndFlush(visitor);
return Result.ok();
}
@Override
public Result<VisitorVo> selectVisitor(IdParam idParam) {
Optional<Visitor> optional = visitorRepository.findById(idParam.getId());
if (optional.isEmpty()) {
return Result.no(Status.NOT_FOUND);
}
Visitor visitor = optional.get();
VisitorVo vo = new VisitorVo();
BeanUtils.copyProperties(visitor, vo);
return Result.ok(vo);
}
@Override
public Result<PageVo<VisitorVo>> pageVisitor(VisitorQueryParam visitorQueryParam) {
PageVo<VisitorVo> resultVo;
//排序
Sort sort = Sort.by(Sort.Order.desc(Visitor.Fields.createTime));
if (Objects.nonNull(visitorQueryParam.getPageNo()) && Objects.nonNull(visitorQueryParam.getPageSize())) {
//分页
Pageable pageable = PageRequest.of(visitorQueryParam.getPageNo() - 1, visitorQueryParam.getPageSize());
Page<Visitor> all = visitorRepository.findAll(condition(visitorQueryParam), pageable);
List<VisitorVo> data = all
.get()
.map(visitor -> {
VisitorVo vo = new VisitorVo();
BeanUtils.copyProperties(visitor, vo);
return vo;
})
.collect(Collectors.toList());
resultVo = PageVo.build(data, all.getTotalElements());
} else {
List<Visitor> all = visitorRepository.findAll(condition(visitorQueryParam), sort);
List<VisitorVo> data = all
.stream()
.map(visitor -> {
VisitorVo vo = new VisitorVo();
BeanUtils.copyProperties(visitor, vo);
return vo;
})
.collect(Collectors.toList());
resultVo = PageVo.build(data, data.size());
}
return Result.ok(resultVo);
}
@Override
public void exportVisitor(VisitorQueryParam visitorQueryParam, HttpServletResponse response) {
List<Visitor> visitors = visitorRepository.findAll(condition(visitorQueryParam));
List<VisitorExportExcel> visitorExportExcels = visitors
.stream()
.map(visitor -> {
VisitorExportExcel visitorExportExcel = new VisitorExportExcel();
BeanUtils.copyProperties(visitor, visitorExportExcel);
return visitorExportExcel;
})
.toList();
try (
DefaultStreamExcelBuilder<VisitorExportExcel> defaultStreamExcelBuilder = DefaultStreamExcelBuilder
.of(VisitorExportExcel.class)
.threadPool(Executors.newFixedThreadPool(2))
.rowHeight(14)
.titleRowHeight(14)
.widths(8)
.style(
"cell->vertical-align:center;text-align:center",
"title->vertical-align:center;text-align:center;font-weight:bold;font-family:等线"
)
.start()
) {
defaultStreamExcelBuilder.append(visitorExportExcels);
String fileName = URLEncoder.encode("访客信息.xlsx", StandardCharsets.UTF_8);
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
OutputStream out = response.getOutputStream();
Workbook workbook = defaultStreamExcelBuilder.fixedTitles().build();
workbook.write(out);
workbook.close();
out.flush();
out.close();
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new RuntimeException("导出访客信息失败: " + e.getMessage());
}
}
@Override
public Result<String> cardSend(String labelCard, IdParam idParam) {
Optional<Visitor> optional = visitorRepository.findById(idParam.getId());
if (optional.isEmpty()) {
return Result.no(Status.NOT_FOUND);
}
Visitor visitor = optional.get();
//状态变更为使用中
visitor.setLabelCardStatus("2");
visitor.setCardSendTime(LocalDateTime.now());
visitor.setLabelCard(labelCard);
visitorRepository.saveAndFlush(visitor);
return Result.ok();
}
@Override
public Result<String> cardRec(IdParam idParam) {
Optional<Visitor> optional = visitorRepository.findById(idParam.getId());
if (optional.isEmpty()) {
return Result.no(Status.NOT_FOUND);
}
Visitor visitor = optional.get();
visitor.setLabelCardStatus("3");
visitor.setCardRecTime(LocalDateTime.now());
visitorRepository.saveAndFlush(visitor);
return Result.ok();
}
public boolean hasCarNum(String carNum) {
Visitor visitor = Visitor.builder().visitorCarNum(carNum).labelCardStatus("1").build();
long count = visitorRepository.count(Example.of(visitor));
Visitor visitor1 = Visitor.builder().visitorCarNum(carNum).labelCardStatus("2").build();
long count1 = visitorRepository.count(Example.of(visitor1));
return count + count1 > 0;
}
public boolean hasVisitorMobile(String mobile) {
Visitor visitor = Visitor.builder().visitorMobile(mobile).labelCardStatus("1").build();
long count = visitorRepository.count(Example.of(visitor));
Visitor visitor1 = Visitor.builder().visitorMobile(mobile).labelCardStatus("1").build();
long count1 = visitorRepository.count(Example.of(visitor1));
return count + count1 > 0;
}
public Specification<Visitor> condition(VisitorQueryParam visitorQueryParam) {
return (root, query, criteriaBuilder) -> {
List<Predicate> list = new ArrayList<>();
//查询条件
if (StrUtil.isNotBlank(visitorQueryParam.getVisitorName())) {
//访客姓名
list.add(
criteriaBuilder.like(
root.get(Visitor.Fields.visitorName),
"%" + visitorQueryParam.getVisitorName() + "%"
)
);
}
if (StrUtil.isNotBlank(visitorQueryParam.getVisitorMobile())) {
//访客电话
list.add(
criteriaBuilder.like(
root.get(Visitor.Fields.visitorMobile),
"%" + visitorQueryParam.getVisitorMobile() + "%"
)
);
}
if (StrUtil.isNotBlank(visitorQueryParam.getVisitorCarNum())) {
//访客身份证
list.add(
criteriaBuilder.like(
root.get(Visitor.Fields.visitorCarNum),
"%" + visitorQueryParam.getVisitorCarNum() + "%"
)
);
}
if (StrUtil.isNotBlank(visitorQueryParam.getTaskType())) {
//是否特殊作业
list.add(
criteriaBuilder.like(root.get(Visitor.Fields.taskType), "%" + visitorQueryParam.getTaskType() + "%")
);
}
if (StrUtil.isNotBlank(visitorQueryParam.getOrgId())) {
//所属单位查询
list.add(
criteriaBuilder.like(root.get(Visitor.Fields.orgId), "%" + visitorQueryParam.getOrgId() + "%")
);
}
if (StrUtil.isNotBlank(visitorQueryParam.getVisitorSource())) {
//访客来源
list.add(
criteriaBuilder.like(
root.get(Visitor.Fields.visitorSource),
"%" + visitorQueryParam.getVisitorSource() + "%"
)
);
}
if (StrUtil.isNotBlank(visitorQueryParam.getIntervieweeId())) {
//被访人
list.add(
criteriaBuilder.equal(root.get(Visitor.Fields.intervieweeId), visitorQueryParam.getIntervieweeId())
);
}
if (StrUtil.isNotBlank(visitorQueryParam.getLabelCard())) {
//标签卡号查询
list.add(
criteriaBuilder.like(
root.get(Visitor.Fields.labelCard),
"%" + visitorQueryParam.getLabelCard() + "%"
)
);
}
if (StrUtil.isNotBlank(visitorQueryParam.getLabelCardStatus())) {
//标签卡状态
list.add(
criteriaBuilder.like(
root.get(Visitor.Fields.labelCardStatus),
"%" + visitorQueryParam.getLabelCardStatus() + "%"
)
);
}
if (
Objects.nonNull(visitorQueryParam.getAppOfVisitTimeStart()) &&
Objects.nonNull(visitorQueryParam.getAppOfVisitTimeEnd())
) {
//预约到访时间区间段查询
list.add(
criteriaBuilder.between(
root.get(Visitor.Fields.appOfVisitTime),
visitorQueryParam.getAppOfVisitTimeStart(),
visitorQueryParam.getAppOfVisitTimeEnd()
)
);
}
if (
Objects.nonNull(visitorQueryParam.getCardSendTimeStart()) &&
Objects.nonNull(visitorQueryParam.getCardSendTimeEnd())
) {
//实际到访时间区间段查询
list.add(
criteriaBuilder.between(
root.get(Visitor.Fields.cardSendTime),
visitorQueryParam.getCardSendTimeStart(),
visitorQueryParam.getCardSendTimeEnd()
)
);
}
if (
Objects.nonNull(visitorQueryParam.getCardRecTimeStart()) &&
Objects.nonNull(visitorQueryParam.getCardRecTimeEnd())
) {
//收卡时间区间段查询
list.add(
criteriaBuilder.between(
root.get(Visitor.Fields.cardRecTime),
visitorQueryParam.getCardRecTimeStart(),
visitorQueryParam.getCardRecTimeEnd()
)
);
}
Predicate[] predicates = new Predicate[list.size()];
query.where(list.toArray(predicates));
return criteriaBuilder.and(list.toArray(predicates));
};
}
}
......@@ -5,6 +5,7 @@ import com.yiring.app.constant.RedisKey;
import com.yiring.common.core.Redis;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.amqp.RabbitProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.ChannelRegistration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
......@@ -32,7 +33,7 @@ public class WebSocketStompConfig implements WebSocketMessageBrokerConfigurer {
Redis redis;
@Resource
RabbitmqProperties rabbitmqProperties;
RabbitProperties rabbitProperties;
@Resource
ClientInboundChannelInterceptor clientInboundChannelInterceptor;
......@@ -61,11 +62,11 @@ public class WebSocketStompConfig implements WebSocketMessageBrokerConfigurer {
registry.setApplicationDestinationPrefixes("/app");
registry
.enableStompBrokerRelay("/topic", "/queue")
.setRelayHost(rabbitmqProperties.getHost())
.setClientLogin(rabbitmqProperties.getUsername())
.setClientPasscode(rabbitmqProperties.getPassword())
.setSystemLogin(rabbitmqProperties.getUsername())
.setSystemPasscode(rabbitmqProperties.getPassword());
.setRelayHost(rabbitProperties.getHost())
.setClientLogin(rabbitProperties.getUsername())
.setClientPasscode(rabbitProperties.getPassword())
.setSystemLogin(rabbitProperties.getUsername())
.setSystemPasscode(rabbitProperties.getPassword());
log.info("Init RabbitMQ STOMP MessageBroker Success.");
}
......
......@@ -18,7 +18,7 @@ import org.locationtech.jts.geom.Point;
@UtilityClass
public class GeoUtils {
private final GeometryFactory factory = new GeometryFactory();
public final GeometryFactory factory = new GeometryFactory();
/**
* 创建点
......@@ -30,4 +30,29 @@ public class GeoUtils {
public Point createPoint(double lon, double lat) {
return factory.createPoint(new Coordinate(lon, lat));
}
/**
* 创建一个三维点
* @param lon 经度
* @param lat 纬度
* @param alt 高度
* @return 点
*/
public Point createPoint(double lon, double lat, double alt) {
return factory.createPoint(new Coordinate(lon, lat, alt));
}
/**
* 相对坐标转换为经纬度
* @param x x 坐标值
* @param y y 坐标值
* @param z z 坐标值
* @return 经纬度点
*/
public Point xyzToPoint(double x, double y, double z) {
// TODO
// 根据真源定位系统设置的坐标系,转换为经纬度
// 根据北向的地图左下角坐标点,矩形长宽距离,结合二维图片的像素比,计算经纬度
return factory.createPoint(new Coordinate(x, y, z));
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.vo.car;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.yiring.common.util.DictUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.*;
......@@ -25,6 +24,9 @@ import lombok.experimental.FieldDefaults;
@FieldDefaults(level = AccessLevel.PRIVATE)
public class CarVo implements Serializable {
@Serial
private static final long serialVersionUID = -1778680629828674385L;
@JsonSerialize(using = ToStringSerializer.class)
@ApiModelProperty(value = "主键id", example = "1458555485552")
Long id;
......@@ -41,12 +43,12 @@ public class CarVo implements Serializable {
@ApiModelProperty(value = "车辆类型(字典翻译)", example = "货车")
String carTypeName;
public String getCarTypeName() {
if (StrUtil.isNotBlank(carType)) {
return DictUtils.getDictLabel("car_type", carType);
}
return null;
}
// public String getCarTypeName() {
// if (StrUtil.isNotBlank(carType)) {
// return DictUtils.getDictLabel("car_type", carType);
// }
// return null;
// }
@ApiModelProperty(value = "司机名称", example = "张三")
String driverName;
......@@ -66,12 +68,12 @@ public class CarVo implements Serializable {
@ApiModelProperty(value = "标签卡状态", example = "未发卡")
String labelCardStatusName;
public String getLabelCardStatusName() {
if (StrUtil.isNotBlank(carType)) {
return DictUtils.getDictLabel("car_label_status", labelCardStatus);
}
return null;
}
// public String getLabelCardStatusName() {
// if (StrUtil.isNotBlank(carType)) {
// return DictUtils.getDictLabel("car_label_status", labelCardStatus);
// }
// return null;
// }
@ApiModelProperty(value = "单位id", example = "湖南壹润科技")
String orgId;
......
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.vo.video;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serial;
import java.io.Serializable;
import lombok.*;
import lombok.experimental.FieldDefaults;
......@@ -20,16 +23,23 @@ import org.locationtech.jts.geom.Point;
@FieldDefaults(level = AccessLevel.PRIVATE)
public class VideoVo implements Serializable {
@ApiModelProperty(value = "坐标点信息", example = "")
@Serial
private static final long serialVersionUID = 3968078657827350557L;
@JsonSerialize(using = ToStringSerializer.class)
@ApiModelProperty(value = "id", example = "1548548545755")
Long id;
@ApiModelProperty(value = "坐标点", example = "坐标点")
Point point;
@ApiModelProperty(value = "编号", example = "88888888")
String uuid;
@ApiModelProperty(value = "m3u8地址", example = "")
@ApiModelProperty(value = "m3u8地址", example = "m3u8地址")
String m3u8;
@ApiModelProperty(value = "备注", example = "摄像头")
@ApiModelProperty(value = "备注", example = "备注")
String remark;
@ApiModelProperty(value = "摄像头名称", example = "摄像头1")
......
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.vo.visitor;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.*;
import lombok.experimental.FieldDefaults;
/**
* @author tzl
* 2022/4/19 14:16
*/
@ApiModel("VisitorVo")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
public class VisitorVo implements Serializable {
private static final long serialVersionUID = 9004209982164273860L;
@JsonSerialize(using = ToStringSerializer.class)
@ApiModelProperty(value = "id", example = "1548548545755")
Long id;
@ApiModelProperty(value = "到访人姓名", example = "张三")
String visitorName;
@ApiModelProperty(value = "到访人电话", example = "17688888888")
String visitorMobile;
@ApiModelProperty(value = "到访人身份证", example = "430441190001255417")
String visitorCarNum;
@ApiModelProperty(value = "是否特殊作业", example = "true")
boolean taskType;
@ApiModelProperty(value = "邀请人数", example = "1")
Integer numOfVisitor;
@ApiModelProperty(value = "访客来源", example = "内部邀请")
String visitorSource;
@ApiModelProperty(value = "标签卡", example = "WE34421231")
String labelCard;
@ApiModelProperty(value = "标签卡状态", example = "使用中")
String labelCardStatus;
@ApiModelProperty(value = "所属单位id", example = "壹润科技")
String orgId;
@ApiModelProperty(value = "被访人id", example = "1")
String intervieweeId;
@ApiModelProperty(value = "来访原因", example = "来访原因")
String reason;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "收卡时间", example = "2022-04-19 14:28:00")
LocalDateTime cardRecTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "预约到访时间", example = "2022-04-19 14:28:00")
LocalDateTime appOfVisitTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建时间", example = "2022-04-19 14:28:00")
LocalDateTime createTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "发卡时间", example = "2022-04-19 14:28:00")
LocalDateTime cardSendTime;
}
/* (C) 2021 YiRing, Inc. */
package com.yiring.app.web;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSONObject;
import com.yiring.app.constant.Code;
import com.yiring.app.exception.CodeException;
import com.yiring.app.push.domain.PushMessage;
import com.yiring.app.push.service.PushService;
import com.yiring.app.util.GeoUtils;
import com.yiring.common.core.Result;
import com.yiring.common.param.PageParam;
import com.yiring.common.vo.PageVo;
......@@ -16,7 +11,6 @@ import java.util.Arrays;
import java.util.List;
import javax.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.locationtech.jts.geom.Point;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -52,12 +46,4 @@ public class HelloController {
PageVo<String> vo = PageVo.build(data, data.size());
return Result.ok(vo);
}
@GetMapping("test")
public Result<Point> test() {
PushService service = SpringUtil.getBean(PushService.class);
service.push(PushMessage.Type.WS, new JSONObject().fluentPut("msg", "hello"));
Point point = GeoUtils.createPoint(112.1, 23.56);
return Result.ok(point);
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.web.car;
import com.yiring.app.domain.car.Car;
import com.yiring.app.param.car.CarParam;
import com.yiring.app.param.car.CarQueryParam;
import com.yiring.app.service.car.CarService;
import com.yiring.app.vo.car.CarVo;
import com.yiring.common.core.Result;
import com.yiring.common.param.IdParam;
import com.yiring.common.util.poi.ExcelUtils;
import com.yiring.common.vo.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 车辆来访信息控制器
......@@ -28,7 +29,7 @@ import org.springframework.web.bind.annotation.*;
* 2022/4/11 17:02
*/
@Slf4j
@Api(tags = "Car")
@Api(tags = "Car(车辆)")
@Validated
@RestController
@RequestMapping("/Car/")
......@@ -80,15 +81,9 @@ public class CarController {
return carService.pageCarInfo(carParam);
}
@ApiOperation(value = "导出车辆来访信息")
@ApiOperation(value = "导出车辆来访信息", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@PostMapping("exportCarInfo")
public void exportCarInfo(HttpServletResponse response, @Valid CarQueryParam carParam) {
List<Car> export = carService.export(carParam);
ExcelUtils<Car> util = new ExcelUtils<>(Car.class);
// String fileName = URLEncoder.encode("车辆来访信息.xlsx", StandardCharsets.UTF_8);
response.setContentType("application/octet-stream");
// response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
// response.setCharacterEncoding("utf-8");
util.exportExcel(response, export, "车辆来访信息");
carService.export(carParam, response);
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.web.map;
import com.alibaba.fastjson.JSONObject;
import com.yiring.app.feign.MapClient;
import com.yiring.auth.util.ZyUtil;
import com.yiring.common.core.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import java.io.Serializable;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 地图控制器
* @author Administrator
* @version 1.0
* @description: TODO
* @date 2022/4/24 13:48
*/
@Slf4j
@Validated
@Api(tags = "Map(地图)")
@RestController
@RequestMapping("/map/")
public class MapController {
@Resource
MapClient mapClient;
@GetMapping("/mapSelect")
@ApiImplicitParams({ @ApiImplicitParam(value = "orgId", required = true, name = "orgId") })
public Result<Serializable> fail(String orgId) {
String login = ZyUtil.login();
JSONObject jsonObject = mapClient.selectMap(orgId, "bearer " + login);
return Result.ok(jsonObject.get("data").toString());
}
}
......@@ -7,27 +7,33 @@ import com.yiring.app.service.video.VideoService;
import com.yiring.app.vo.video.VideoVo;
import com.yiring.common.core.Result;
import com.yiring.common.param.IdParam;
import com.yiring.common.param.PageParam;
import com.yiring.common.vo.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.locationtech.jts.geom.Point;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
/**
* 监控点位控制器
*
* @author tzl
* 2022/4/8 16:51
*/
@Slf4j
@Validated
@Api(tags = "Video")
@Api(tags = "Video(监控设备)")
@RestController
@RequestMapping("/video/")
public class VideoController {
......@@ -54,14 +60,27 @@ public class VideoController {
}
@ApiOperation(value = "查看监控点位位置")
@PostMapping("selectPoint")
@GetMapping("selectPoint")
public Result<Point> selectPoint(@Valid IdParam idParam) {
return videoService.selectPoint(idParam);
}
@ApiOperation(value = "分页查询监控点位信息")
@PostMapping("pageVideo")
public Result<PageVo<VideoVo>> pageVideo(@Valid VideoQueryParam videoQueryParam, @Valid PageParam param) {
return videoService.pageVideo(videoQueryParam, param);
@GetMapping("pageVideo")
public Result<PageVo<VideoVo>> pageVideo(@Valid VideoQueryParam videoQueryParam) {
return videoService.pageVideo(videoQueryParam);
}
@ApiOperation(value = "导出", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@PostMapping("exportVideo")
public void exportVideo(HttpServletResponse response, @Valid VideoQueryParam videoQueryParam) {
videoService.exportVideo(videoQueryParam, response);
}
@ApiOperation(value = "导入")
@ApiImplicitParams({ @ApiImplicitParam(value = "文件", required = true, name = "file") })
@PostMapping("importVideo")
public Result<String> importVideo(MultipartFile file) {
return videoService.importVideo(file);
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.web.visitor;
import com.yiring.app.param.visitor.VisitorParam;
import com.yiring.app.param.visitor.VisitorQueryParam;
import com.yiring.app.service.visitor.VisitorService;
import com.yiring.app.vo.visitor.VisitorVo;
import com.yiring.common.core.Result;
import com.yiring.common.param.IdParam;
import com.yiring.common.vo.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author tzl
* 2022/4/21 9:50
*/
@Slf4j
@Validated
@Api(tags = "Visitor(访客)")
@RestController
@RequestMapping("/visitor/")
public class VisitorController {
@Resource
VisitorService visitorService;
@ApiOperation(value = "新增访客信息")
@PostMapping("saveVisitor")
public Result<String> saveVisitor(@Valid VisitorParam visitorParam) {
return visitorService.saveVisitor(visitorParam);
}
@ApiOperation(value = "修改访客信息")
@PostMapping("updateVisitor")
public Result<String> updateVisitor(@Valid VisitorParam visitorParam, @Valid IdParam idParam) {
return visitorService.updateVisitor(visitorParam, idParam);
}
@ApiOperation(value = "收卡")
@PostMapping("cardRec")
public Result<String> cardRec(@Valid IdParam idParam) {
return visitorService.cardRec(idParam);
}
@ApiOperation(value = "发卡")
@ApiImplicitParam(value = "标签卡", example = "DW8544568", required = true, name = "labelCard")
@PostMapping("cardSend")
public Result<String> cardSend(@Valid IdParam idParam, String labelCard) {
return visitorService.cardSend(labelCard, idParam);
}
@ApiOperation(value = "删除访客信息")
@PostMapping("deleteVisitor")
public Result<String> deleteVisitor(@Valid IdParam idParam) {
return visitorService.deleteVisitor(idParam);
}
@ApiOperation(value = "查看访客信息详情")
@GetMapping("selectVisitor")
public Result<VisitorVo> selectVisitor(@Valid IdParam idParam) {
return visitorService.selectVisitor(idParam);
}
@ApiOperation(value = "查看访客信息(分页)")
@GetMapping("pageVisitor")
public Result<PageVo<VisitorVo>> pageVisitor(@Valid VisitorQueryParam visitorQueryParam) {
return visitorService.pageVisitor(visitorQueryParam);
}
@ApiOperation(value = "导出访客信息", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@PostMapping("exportVisitor")
public void exportVisitor(HttpServletResponse response, @Valid VisitorQueryParam visitorQueryParam) {
visitorService.exportVisitor(visitorQueryParam, response);
}
}
spring:
mvc:
pathmatch:
# 修复 swagger 插件在 2.6.x 接口路径匹配问题
matching-strategy: ant_path_matcher
logging:
level:
# 关闭接口扫描 CachingOperationNameGenerator 日志
springfox.documentation.spring.web.readers.operation.CachingOperationNameGenerator: WARN
......@@ -16,6 +16,7 @@ spring:
properties:
hibernate:
format_sql: true
types.print.banner: false
redis:
database: 5
host: ${env.host}
......@@ -24,7 +25,18 @@ spring:
port: 5672
username: admin
password: 123456
virtual-host: /
# 开启发送端确认
publisher-confirm-type: correlated
# 开启接收端确认
publisher-returns: true
template:
# 消息抵达队列,异步回调 confirm
mandatory: true
listener:
simple:
# 手动确认消息
acknowledge-mode: manual
# knife4j
knife4j:
......@@ -49,3 +61,35 @@ logging:
level:
# sql bind parameter
org.hibernate.type.descriptor.sql.BasicBinder: trace
# 真源定位系统相关配置
zy-config:
host: project.yz-online.com
# RabbitMQ 订阅配置
rabbitmq:
enabled: true
host: ${zy-config.host}
port: 672
username: admin
password: admin
virtual-host: /
queue-name: tenant_msg_${zy-config.open.client-secret}_${zy-config.open.client-id}
# 开放接口信息配置
open:
api: http://${zy-config.host}:789/positionApi
client-id: sc21080400
grant-type: client_credentials
client-secret: 12A14FDC
tenant: sc21080400
# 代理接口信息配置
proxy:
api: https://nl.yz-cloud.com
tenant: ts00000006
# 应用平台账户信息
client:
username: test1234
password: 123456
# 管理后台账户信息
manage:
username: test123
password: test123
......@@ -16,6 +16,7 @@ spring:
properties:
hibernate:
format_sql: true
types.print.banner: false
h2:
console:
enabled: true
......
......@@ -7,7 +7,7 @@ spring:
application:
name: "kshg-api"
profiles:
include: auth
include: auth, conf-patch
active: dev
# DEBUG
......
dependencies {
implementation project(':basic-common:core')
implementation project(':basic-common:util')
implementation project(':basic-common:redis')
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
......@@ -17,6 +18,7 @@ dependencies {
// hutool
implementation "cn.hutool:hutool-core:${hutoolVersion}"
implementation "cn.hutool:hutool-json:${hutoolVersion}"
implementation "cn.hutool:hutool-http:${hutoolVersion}"
implementation "cn.hutool:hutool-extra:${hutoolVersion}"
......@@ -26,5 +28,4 @@ dependencies {
// myexcel
implementation "com.github.liaochong:myexcel:${myexcelVersion}"
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.common.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
/**
* 跨域设置
* @author tzl
* 2022/4/18 10:29
*/
@Configuration
public class CorsConfig {
@Bean
public CorsFilter corsFilter() {
final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
final CorsConfiguration corsConfiguration = new CorsConfiguration();
// corsConfiguration.setAllowCredentials(true);
corsConfiguration.addAllowedOrigin("*");
corsConfiguration.addAllowedHeader("*");
corsConfiguration.addAllowedMethod("*");
urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
return new CorsFilter(urlBasedCorsConfigurationSource);
}
}
......@@ -25,4 +25,12 @@ public class EnvConfig {
* host,用来共享一些资源(如:数据库、文件存储等相关的依赖源)
*/
String host;
/**
* 国标平台账号
*/
String gbUsername;
/**
* 国标平台密码
*/
String gbPassword;
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.common.dict;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import javax.persistence.Entity;
......@@ -33,6 +34,9 @@ import org.hibernate.snowflake.SnowflakeId;
@Comment("字典")
public class Dict implements Serializable {
@Serial
private static final long serialVersionUID = 2124350188949761567L;
@Id
@Comment("主键id")
@GeneratedValue(generator = SnowflakeId.GENERATOR)
......
/* (C) 2022 YiRing, Inc. */
package com.yiring.common.dict;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import javax.persistence.Entity;
......@@ -31,6 +32,9 @@ import org.hibernate.snowflake.SnowflakeId;
@Comment("字典类型")
public class DictType implements Serializable {
@Serial
private static final long serialVersionUID = -6302980159147541047L;
@Id
@Comment("主键id")
@GeneratedValue(generator = SnowflakeId.GENERATOR)
......
......@@ -8,8 +8,4 @@ dependencies {
implementation "cn.hutool:hutool-extra:${hutoolVersion}"
// fastjson
implementation "com.alibaba:fastjson:${fastJsonVersion}"
implementation group: 'org.apache.poi', name: 'poi', version: '5.2.2'
implementation group: 'org.apache.poi', name: 'poi-ooxml', version: '5.2.2'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.common.annotation;
import com.yiring.common.util.poi.ExcelHandlerAdapter;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.math.BigDecimal;
/**
* 自定义导出Excel数据注解
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Excel {
/**
* 导出时在excel中排序
*/
int sort() default Integer.MAX_VALUE;
/**
* 导出到Excel中的名字.
*/
String name() default "";
/**
* 日期格式, 如: yyyy-MM-dd
*/
String dateFormat() default "";
/**
* 如果是字典类型,请设置字典的type值 (如: user_sex)
*/
String dictType() default "";
/**
* 读取内容转表达式 (如: 0=男,1=女,2=未知)
*/
String readConverterExp() default "";
/**
* 分隔符,读取字符串组内容
*/
String separator() default ",";
/**
* BigDecimal 精度 默认:-1(默认不开启BigDecimal格式化)
*/
int scale() default -1;
/**
* BigDecimal 舍入规则 默认:BigDecimal.ROUND_HALF_EVEN
*/
int roundingMode() default BigDecimal.ROUND_HALF_EVEN;
/**
* 导出类型(0数字 1字符串)
*/
ColumnType cellType() default ColumnType.STRING;
/**
* 导出时在excel中每个列的高度 单位为字符
*/
double height() default 14;
/**
* 导出时在excel中每个列的宽 单位为字符
*/
double width() default 16;
/**
* 文字后缀,如% 90 变成90%
*/
String suffix() default "";
/**
* 当值为空时,字段的默认值
*/
String defaultValue() default "";
/**
* 提示信息
*/
String prompt() default "";
/**
* 设置只能选择不能输入的列内容.
*/
String[] combo() default {};
/**
* 是否导出数据,应对需求:有时我们需要导出一份模板,这是标题需要但内容需要用户手工填写.
*/
boolean isExport() default true;
/**
* 另一个类中的属性名称,支持多级获取,以小数点隔开
*/
String targetAttr() default "";
/**
* 是否自动统计数据,在最后追加一行统计数据总和
*/
boolean isStatistics() default false;
/**
* 导出字段对齐方式(0:默认;1:靠左;2:居中;3:靠右)
*/
Align align() default Align.AUTO;
/**
* 自定义数据处理器
*/
Class<?> handler() default ExcelHandlerAdapter.class;
/**
* 自定义数据处理器参数
*/
String[] args() default {};
enum Align {
AUTO(0),
LEFT(1),
CENTER(2),
RIGHT(3);
private final int value;
Align(int value) {
this.value = value;
}
public int value() {
return this.value;
}
}
/**
* 字段类型(0:导出导入;1:仅导出;2:仅导入)
*/
Type type() default Type.ALL;
enum Type {
ALL(0),
EXPORT(1),
IMPORT(2);
private final int value;
Type(int value) {
this.value = value;
}
int value() {
return this.value;
}
}
enum ColumnType {
NUMERIC(0),
STRING(1),
IMAGE(2);
private final int value;
ColumnType(int value) {
this.value = value;
}
int value() {
return this.value;
}
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.common.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Excel注解集
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Excels {
Excel[] value();
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.common.text;
import com.yiring.common.util.StrUtils;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.text.NumberFormat;
import java.util.Set;
/**
* 类型转换器
*/
public class Convert {
/**
* 转换为字符串<br>
* 如果给定的值为null,或者转换失败,返回默认值<br>
* 转换失败不会报错
*
* @param value 被转换的值
* @param defaultValue 转换错误时的默认值
* @return 结果
*/
public static String toStr(Object value, String defaultValue) {
if (null == value) {
return defaultValue;
}
if (value instanceof String) {
return (String) value;
}
return value.toString();
}
/**
* 转换为字符串<br>
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br>
* 转换失败不会报错
*
* @param value 被转换的值
* @return 结果
*/
public static String toStr(Object value) {
return toStr(value, null);
}
/**
* 转换为字符<br>
* 如果给定的值为null,或者转换失败,返回默认值<br>
* 转换失败不会报错
*
* @param value 被转换的值
* @param defaultValue 转换错误时的默认值
* @return 结果
*/
public static Character toChar(Object value, Character defaultValue) {
if (null == value) {
return defaultValue;
}
if (value instanceof Character) {
return (Character) value;
}
final String valueStr = toStr(value, null);
return StrUtils.isEmpty(valueStr) ? defaultValue : valueStr.charAt(0);
}
/**
* 转换为字符<br>
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br>
* 转换失败不会报错
*
* @param value 被转换的值
* @return 结果
*/
public static Character toChar(Object value) {
return toChar(value, null);
}
/**
* 转换为byte<br>
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值<br>
* 转换失败不会报错
*
* @param value 被转换的值
* @param defaultValue 转换错误时的默认值
* @return 结果
*/
public static Byte toByte(Object value, Byte defaultValue) {
if (value == null) {
return defaultValue;
}
if (value instanceof Byte) {
return (Byte) value;
}
if (value instanceof Number) {
return ((Number) value).byteValue();
}
final String valueStr = toStr(value, null);
if (StrUtils.isEmpty(valueStr)) {
return defaultValue;
}
try {
return Byte.parseByte(valueStr);
} catch (Exception e) {
return defaultValue;
}
}
/**
* 转换为byte<br>
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br>
* 转换失败不会报错
*
* @param value 被转换的值
* @return 结果
*/
public static Byte toByte(Object value) {
return toByte(value, null);
}
/**
* 转换为Short<br>
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值<br>
* 转换失败不会报错
*
* @param value 被转换的值
* @param defaultValue 转换错误时的默认值
* @return 结果
*/
public static Short toShort(Object value, Short defaultValue) {
if (value == null) {
return defaultValue;
}
if (value instanceof Short) {
return (Short) value;
}
if (value instanceof Number) {
return ((Number) value).shortValue();
}
final String valueStr = toStr(value, null);
if (StrUtils.isEmpty(valueStr)) {
return defaultValue;
}
try {
return Short.parseShort(valueStr.trim());
} catch (Exception e) {
return defaultValue;
}
}
/**
* 转换为Short<br>
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br>
* 转换失败不会报错
*
* @param value 被转换的值
* @return 结果
*/
public static Short toShort(Object value) {
return toShort(value, null);
}
/**
* 转换为Number<br>
* 如果给定的值为空,或者转换失败,返回默认值<br>
* 转换失败不会报错
*
* @param value 被转换的值
* @param defaultValue 转换错误时的默认值
* @return 结果
*/
public static Number toNumber(Object value, Number defaultValue) {
if (value == null) {
return defaultValue;
}
if (value instanceof Number) {
return (Number) value;
}
final String valueStr = toStr(value, null);
if (StrUtils.isEmpty(valueStr)) {
return defaultValue;
}
try {
return NumberFormat.getInstance().parse(valueStr);
} catch (Exception e) {
return defaultValue;
}
}
/**
* 转换为Number<br>
* 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br>
* 转换失败不会报错
*
* @param value 被转换的值
* @return 结果
*/
public static Number toNumber(Object value) {
return toNumber(value, null);
}
/**
* 转换为int<br>
* 如果给定的值为空,或者转换失败,返回默认值<br>
* 转换失败不会报错
*
* @param value 被转换的值
* @param defaultValue 转换错误时的默认值
* @return 结果
*/
public static Integer toInt(Object value, Integer defaultValue) {
if (value == null) {
return defaultValue;
}
if (value instanceof Integer) {
return (Integer) value;
}
if (value instanceof Number) {
return ((Number) value).intValue();
}
final String valueStr = toStr(value, null);
if (StrUtils.isEmpty(valueStr)) {
return defaultValue;
}
try {
return Integer.parseInt(valueStr.trim());
} catch (Exception e) {
return defaultValue;
}
}
/**
* 转换为int<br>
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br>
* 转换失败不会报错
*
* @param value 被转换的值
* @return 结果
*/
public static Integer toInt(Object value) {
return toInt(value, null);
}
/**
* 转换为Integer数组<br>
*
* @param str 被转换的值
* @return 结果
*/
public static Integer[] toIntArray(String str) {
return toIntArray(",", str);
}
/**
* 转换为Long数组<br>
*
* @param str 被转换的值
* @return 结果
*/
public static Long[] toLongArray(String str) {
return toLongArray(",", str);
}
/**
* 转换为Integer数组<br>
*
* @param split 分隔符
* @param split 被转换的值
* @return 结果
*/
public static Integer[] toIntArray(String split, String str) {
if (StrUtils.isEmpty(str)) {
return new Integer[] {};
}
String[] arr = str.split(split);
final Integer[] ints = new Integer[arr.length];
for (int i = 0; i < arr.length; i++) {
final Integer v = toInt(arr[i], 0);
ints[i] = v;
}
return ints;
}
/**
* 转换为Long数组<br>
*
* @param split 分隔符
* @param str 被转换的值
* @return 结果
*/
public static Long[] toLongArray(String split, String str) {
if (StrUtils.isEmpty(str)) {
return new Long[] {};
}
String[] arr = str.split(split);
final Long[] longs = new Long[arr.length];
for (int i = 0; i < arr.length; i++) {
final Long v = toLong(arr[i], null);
longs[i] = v;
}
return longs;
}
/**
* 转换为String数组<br>
*
* @param str 被转换的值
* @return 结果
*/
public static String[] toStrArray(String str) {
return toStrArray(",", str);
}
/**
* 转换为String数组<br>
*
* @param split 分隔符
* @param split 被转换的值
* @return 结果
*/
public static String[] toStrArray(String split, String str) {
return str.split(split);
}
/**
* 转换为long<br>
* 如果给定的值为空,或者转换失败,返回默认值<br>
* 转换失败不会报错
*
* @param value 被转换的值
* @param defaultValue 转换错误时的默认值
* @return 结果
*/
public static Long toLong(Object value, Long defaultValue) {
if (value == null) {
return defaultValue;
}
if (value instanceof Long) {
return (Long) value;
}
if (value instanceof Number) {
return ((Number) value).longValue();
}
final String valueStr = toStr(value, null);
if (StrUtils.isEmpty(valueStr)) {
return defaultValue;
}
try {
// 支持科学计数法
return new BigDecimal(valueStr.trim()).longValue();
} catch (Exception e) {
return defaultValue;
}
}
/**
* 转换为long<br>
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br>
* 转换失败不会报错
*
* @param value 被转换的值
* @return 结果
*/
public static Long toLong(Object value) {
return toLong(value, null);
}
/**
* 转换为double<br>
* 如果给定的值为空,或者转换失败,返回默认值<br>
* 转换失败不会报错
*
* @param value 被转换的值
* @param defaultValue 转换错误时的默认值
* @return 结果
*/
public static Double toDouble(Object value, Double defaultValue) {
if (value == null) {
return defaultValue;
}
if (value instanceof Double) {
return (Double) value;
}
if (value instanceof Number) {
return ((Number) value).doubleValue();
}
final String valueStr = toStr(value, null);
if (StrUtils.isEmpty(valueStr)) {
return defaultValue;
}
try {
// 支持科学计数法
return new BigDecimal(valueStr.trim()).doubleValue();
} catch (Exception e) {
return defaultValue;
}
}
/**
* 转换为double<br>
* 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br>
* 转换失败不会报错
*
* @param value 被转换的值
* @return 结果
*/
public static Double toDouble(Object value) {
return toDouble(value, null);
}
/**
* 转换为Float<br>
* 如果给定的值为空,或者转换失败,返回默认值<br>
* 转换失败不会报错
*
* @param value 被转换的值
* @param defaultValue 转换错误时的默认值
* @return 结果
*/
public static Float toFloat(Object value, Float defaultValue) {
if (value == null) {
return defaultValue;
}
if (value instanceof Float) {
return (Float) value;
}
if (value instanceof Number) {
return ((Number) value).floatValue();
}
final String valueStr = toStr(value, null);
if (StrUtils.isEmpty(valueStr)) {
return defaultValue;
}
try {
return Float.parseFloat(valueStr.trim());
} catch (Exception e) {
return defaultValue;
}
}
/**
* 转换为Float<br>
* 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br>
* 转换失败不会报错
*
* @param value 被转换的值
* @return 结果
*/
public static Float toFloat(Object value) {
return toFloat(value, null);
}
/**
* 转换为boolean<br>
* String支持的值为:true、false、yes、ok、no,1,0 如果给定的值为空,或者转换失败,返回默认值<br>
* 转换失败不会报错
*
* @param value 被转换的值
* @param defaultValue 转换错误时的默认值
* @return 结果
*/
public static Boolean toBool(Object value, Boolean defaultValue) {
if (value == null) {
return defaultValue;
}
if (value instanceof Boolean) {
return (Boolean) value;
}
String valueStr = toStr(value, null);
if (StrUtils.isEmpty(valueStr)) {
return defaultValue;
}
valueStr = valueStr.trim().toLowerCase();
switch (valueStr) {
case "true":
return true;
case "false":
return false;
case "yes":
return true;
case "ok":
return true;
case "no":
return false;
case "1":
return true;
case "0":
return false;
default:
return defaultValue;
}
}
/**
* 转换为boolean<br>
* 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br>
* 转换失败不会报错
*
* @param value 被转换的值
* @return 结果
*/
public static Boolean toBool(Object value) {
return toBool(value, null);
}
/**
* 转换为Enum对象<br>
* 如果给定的值为空,或者转换失败,返回默认值<br>
*
* @param clazz Enum的Class
* @param value 值
* @param defaultValue 默认值
* @return Enum
*/
public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value, E defaultValue) {
if (value == null) {
return defaultValue;
}
if (clazz.isAssignableFrom(value.getClass())) {
@SuppressWarnings("unchecked")
E myE = (E) value;
return myE;
}
final String valueStr = toStr(value, null);
if (StrUtils.isEmpty(valueStr)) {
return defaultValue;
}
try {
return Enum.valueOf(clazz, valueStr);
} catch (Exception e) {
return defaultValue;
}
}
/**
* 转换为Enum对象<br>
* 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br>
*
* @param clazz Enum的Class
* @param value 值
* @return Enum
*/
public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value) {
return toEnum(clazz, value, null);
}
/**
* 转换为BigInteger<br>
* 如果给定的值为空,或者转换失败,返回默认值<br>
* 转换失败不会报错
*
* @param value 被转换的值
* @param defaultValue 转换错误时的默认值
* @return 结果
*/
public static BigInteger toBigInteger(Object value, BigInteger defaultValue) {
if (value == null) {
return defaultValue;
}
if (value instanceof BigInteger) {
return (BigInteger) value;
}
if (value instanceof Long) {
return BigInteger.valueOf((Long) value);
}
final String valueStr = toStr(value, null);
if (StrUtils.isEmpty(valueStr)) {
return defaultValue;
}
try {
return new BigInteger(valueStr);
} catch (Exception e) {
return defaultValue;
}
}
/**
* 转换为BigInteger<br>
* 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br>
* 转换失败不会报错
*
* @param value 被转换的值
* @return 结果
*/
public static BigInteger toBigInteger(Object value) {
return toBigInteger(value, null);
}
/**
* 转换为BigDecimal<br>
* 如果给定的值为空,或者转换失败,返回默认值<br>
* 转换失败不会报错
*
* @param value 被转换的值
* @param defaultValue 转换错误时的默认值
* @return 结果
*/
public static BigDecimal toBigDecimal(Object value, BigDecimal defaultValue) {
if (value == null) {
return defaultValue;
}
if (value instanceof BigDecimal) {
return (BigDecimal) value;
}
if (value instanceof Long) {
return new BigDecimal((Long) value);
}
if (value instanceof Double) {
return new BigDecimal((Double) value);
}
if (value instanceof Integer) {
return new BigDecimal((Integer) value);
}
final String valueStr = toStr(value, null);
if (StrUtils.isEmpty(valueStr)) {
return defaultValue;
}
try {
return new BigDecimal(valueStr);
} catch (Exception e) {
return defaultValue;
}
}
/**
* 转换为BigDecimal<br>
* 如果给定的值为空,或者转换失败,返回默认值<br>
* 转换失败不会报错
*
* @param value 被转换的值
* @return 结果
*/
public static BigDecimal toBigDecimal(Object value) {
return toBigDecimal(value, null);
}
// /**
// * 将对象转为字符串<br>
// * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法
// *
// * @param obj 对象
// * @return 字符串
// */
// public static String utf8Str(Object obj)
// {
// return str(obj, CharsetKit.CHARSET_UTF_8);
// }
/**
* 将对象转为字符串<br>
* 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法
*
* @param obj 对象
* @param charsetName 字符集
* @return 字符串
*/
public static String str(Object obj, String charsetName) {
return str(obj, Charset.forName(charsetName));
}
/**
* 将对象转为字符串<br>
* 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法
*
* @param obj 对象
* @param charset 字符集
* @return 字符串
*/
public static String str(Object obj, Charset charset) {
if (null == obj) {
return null;
}
if (obj instanceof String) {
return (String) obj;
} else if (obj instanceof byte[] || obj instanceof Byte[]) {
if (obj instanceof byte[]) {
return str((byte[]) obj, charset);
} else {
Byte[] bytes = (Byte[]) obj;
int length = bytes.length;
byte[] dest = new byte[length];
for (int i = 0; i < length; i++) {
dest[i] = bytes[i];
}
return str(dest, charset);
}
} else if (obj instanceof ByteBuffer) {
return str((ByteBuffer) obj, charset);
}
return obj.toString();
}
/**
* 将byte数组转为字符串
*
* @param bytes byte数组
* @param charset 字符集
* @return 字符串
*/
public static String str(byte[] bytes, String charset) {
return str(bytes, StrUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset));
}
/**
* 解码字节码
*
* @param data 字符串
* @param charset 字符集,如果此字段为空,则解码的结果取决于平台
* @return 解码后的字符串
*/
public static String str(byte[] data, Charset charset) {
if (data == null) {
return null;
}
if (null == charset) {
return new String(data);
}
return new String(data, charset);
}
/**
* 将编码的byteBuffer数据转换为字符串
*
* @param data 数据
* @param charset 字符集,如果为空使用当前系统字符集
* @return 字符串
*/
public static String str(ByteBuffer data, String charset) {
if (data == null) {
return null;
}
return str(data, Charset.forName(charset));
}
/**
* 将编码的byteBuffer数据转换为字符串
*
* @param data 数据
* @param charset 字符集,如果为空使用当前系统字符集
* @return 字符串
*/
public static String str(ByteBuffer data, Charset charset) {
if (null == charset) {
charset = Charset.defaultCharset();
}
return charset.decode(data).toString();
}
// ----------------------------------------------------------------------- 全角半角转换
/**
* 半角转全角
*
* @param input String.
* @return 全角字符串.
*/
public static String toSBC(String input) {
return toSBC(input, null);
}
/**
* 半角转全角
*
* @param input String
* @param notConvertSet 不替换的字符集合
* @return 全角字符串.
*/
public static String toSBC(String input, Set<Character> notConvertSet) {
char c[] = input.toCharArray();
for (int i = 0; i < c.length; i++) {
if (null != notConvertSet && notConvertSet.contains(c[i])) {
// 跳过不替换的字符
continue;
}
if (c[i] == ' ') {
c[i] = '\u3000';
} else if (c[i] < '\177') {
c[i] = (char) (c[i] + 65248);
}
}
return new String(c);
}
/**
* 全角转半角
*
* @param input String.
* @return 半角字符串
*/
public static String toDBC(String input) {
return toDBC(input, null);
}
/**
* 替换全角为半角
*
* @param text 文本
* @param notConvertSet 不替换的字符集合
* @return 替换后的字符
*/
public static String toDBC(String text, Set<Character> notConvertSet) {
char c[] = text.toCharArray();
for (int i = 0; i < c.length; i++) {
if (null != notConvertSet && notConvertSet.contains(c[i])) {
// 跳过不替换的字符
continue;
}
if (c[i] == '\u3000') {
c[i] = ' ';
} else if (c[i] > '\uFF00' && c[i] < '\uFF5F') {
c[i] = (char) (c[i] - 65248);
}
}
String returnString = new String(c);
return returnString;
}
/**
* 数字金额大写转换 先写个完整的然后将如零拾替换成零
*
* @param n 数字
* @return 中文大写数字
*/
public static String digitUppercase(double n) {
String[] fraction = { "角", "分" };
String[] digit = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
String[][] unit = { { "元", "万", "亿" }, { "", "拾", "佰", "仟" } };
String head = n < 0 ? "负" : "";
n = Math.abs(n);
String s = "";
for (int i = 0; i < fraction.length; i++) {
s += (digit[(int) (Math.floor(n * 10 * Math.pow(10, i)) % 10)] + fraction[i]).replaceAll("(零.)+", "");
}
if (s.length() < 1) {
s = "整";
}
int integerPart = (int) Math.floor(n);
for (int i = 0; i < unit[0].length && integerPart > 0; i++) {
String p = "";
for (int j = 0; j < unit[1].length && n > 0; j++) {
p = digit[integerPart % 10] + unit[1][j] + p;
integerPart = integerPart / 10;
}
s = p.replaceAll("(零.)*零$", "").replaceAll("^$", "零") + unit[0][i] + s;
}
return (
head +
s
.replaceAll("(零.)*零元", "元")
.replaceFirst("(零.)+", "")
.replaceAll("(零.)+", "零")
.replaceAll("^整$", "零元整")
);
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.common.util;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.yiring.common.core.Redis;
import com.yiring.common.dict.Dict;
......@@ -37,12 +39,17 @@ public class DictUtils {
*/
public static List<Dict> getDictCache(String key) {
Object cacheObj = SpringUtil.getBean(Redis.class).get(getCacheKey(key));
if (StrUtils.isNotNull(cacheObj)) {
return StrUtils.cast(cacheObj);
if (ObjectUtil.isNotNull(cacheObj)) {
return cast(cacheObj);
}
return null;
}
@SuppressWarnings("unchecked")
public static <T> T cast(Object obj) {
return (T) obj;
}
/**
* 根据字典类型和字典值获取字典标签
*
......@@ -77,14 +84,12 @@ public class DictUtils {
StringBuilder propertyString = new StringBuilder();
List<Dict> datas = getDictCache(dictType);
if (StrUtils.containsAny(separator, dictValue) && StrUtils.isNotEmpty(datas)) {
if (datas != null) {
for (Dict dict : datas) {
for (String value : dictValue.split(separator)) {
if (value.equals(dict.getDictValue())) {
propertyString.append(dict.getDictLabel()).append(separator);
break;
}
if (StrUtil.containsAny(separator, dictValue) && datas != null) {
for (Dict dict : datas) {
for (String value : dictValue.split(separator)) {
if (value.equals(dict.getDictValue())) {
propertyString.append(dict.getDictLabel()).append(separator);
break;
}
}
}
......@@ -97,7 +102,8 @@ public class DictUtils {
}
}
}
return StrUtils.stripEnd(propertyString.toString(), separator);
// StrUtil.stripEnd(propertyString.toString(), separator);
return null;
}
/**
......@@ -112,14 +118,12 @@ public class DictUtils {
StringBuilder propertyString = new StringBuilder();
List<Dict> datas = getDictCache(dictType);
if (StrUtils.containsAny(separator, dictLabel) && StrUtils.isNotEmpty(datas)) {
if (datas != null) {
for (Dict dict : datas) {
for (String label : dictLabel.split(separator)) {
if (label.equals(dict.getDictLabel())) {
propertyString.append(dict.getDictValue()).append(separator);
break;
}
if (StrUtil.containsAny(separator, dictLabel) && datas != null) {
for (Dict dict : datas) {
for (String label : dictLabel.split(separator)) {
if (label.equals(dict.getDictLabel())) {
propertyString.append(dict.getDictValue()).append(separator);
break;
}
}
}
......@@ -132,7 +136,8 @@ public class DictUtils {
}
}
}
return StrUtils.stripEnd(propertyString.toString(), separator);
// StrUtils.stripEnd(propertyString.toString(), separator)
return null;
}
/**
......
/* (C) 2022 YiRing, Inc. */
package com.yiring.common.util;
import cn.hutool.core.util.StrUtil;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.springframework.util.AntPathMatcher;
/**
* 字符串工具类
* @author Administrator
* @version 1.0
* @description: TODO
* @date 2022/4/22 17:19
*/
public class StrUtils extends org.apache.commons.lang3.StringUtils {
public class StrUtils extends StrUtil {
/**
* 空字符串
......@@ -390,7 +394,7 @@ public class StrUtils extends org.apache.commons.lang3.StringUtils {
* @param size 字符串指定长度
* @return 返回数字的字符串格式,该字符串为指定长度。
*/
public static final String padl(final Number num, final int size) {
public static String padl(final Number num, final int size) {
return padl(num.toString(), size, '0');
}
......@@ -402,22 +406,18 @@ public class StrUtils extends org.apache.commons.lang3.StringUtils {
* @param c 用于补齐的字符
* @return 返回指定长度的字符串,由原字符串左补齐或截取得到。
*/
public static final String padl(final String s, final int size, final char c) {
public static String padl(final String s, final int size, final char c) {
final StringBuilder sb = new StringBuilder(size);
if (s != null) {
final int len = s.length();
if (s.length() <= size) {
for (int i = size - len; i > 0; i--) {
sb.append(c);
}
sb.append(String.valueOf(c).repeat(size - len));
sb.append(s);
} else {
return s.substring(len - size, len);
}
} else {
for (int i = size; i > 0; i--) {
sb.append(c);
}
sb.append(String.valueOf(c).repeat(Math.max(0, size)));
}
return sb.toString();
}
......
/* (C) 2022 YiRing, Inc. */
package com.yiring.common.util.date;
import java.lang.management.ManagementFactory;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
import org.apache.commons.lang3.time.DateFormatUtils;
/**
* 时间工具类
*/
public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
public static String YYYY = "yyyy";
public static String YYYY_MM = "yyyy-MM";
public static String YYYY_MM_DD = "yyyy-MM-dd";
public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
private static final String[] parsePatterns = {
"yyyy-MM-dd",
"yyyy-MM-dd HH:mm:ss",
"yyyy-MM-dd HH:mm",
"yyyy-MM",
"yyyy/MM/dd",
"yyyy/MM/dd HH:mm:ss",
"yyyy/MM/dd HH:mm",
"yyyy/MM",
"yyyy.MM.dd",
"yyyy.MM.dd HH:mm:ss",
"yyyy.MM.dd HH:mm",
"yyyy.MM",
};
/**
* 获取当前Date型日期
*
* @return Date() 当前日期
*/
public static Date getNowDate() {
return new Date();
}
/**
* 获取当前日期, 默认格式为yyyy-MM-dd
*
* @return String
*/
public static String getDate() {
return dateTimeNow(YYYY_MM_DD);
}
public static String getTime() {
return dateTimeNow(YYYY_MM_DD_HH_MM_SS);
}
public static String dateTimeNow() {
return dateTimeNow(YYYYMMDDHHMMSS);
}
public static String dateTimeNow(final String format) {
return parseDateToStr(format, new Date());
}
public static String dateTime(final Date date) {
return parseDateToStr(YYYY_MM_DD, date);
}
public static String parseDateToStr(final String format, final Date date) {
return new SimpleDateFormat(format).format(date);
}
public static Date dateTime(final String format, final String ts) {
try {
return new SimpleDateFormat(format).parse(ts);
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
/**
* 日期路径 即年/月/日 如2018/08/08
*/
public static String datePath() {
Date now = new Date();
return DateFormatUtils.format(now, "yyyy/MM/dd");
}
/**
* 日期路径 即年/月/日 如20180808
*/
public static String dateTime() {
Date now = new Date();
return DateFormatUtils.format(now, "yyyyMMdd");
}
/**
* 日期型字符串转化为日期 格式
*/
public static Date parseDate(Object str) {
if (str == null) {
return null;
}
try {
return parseDate(str.toString(), parsePatterns);
} catch (ParseException e) {
return null;
}
}
/**
* 获取服务器启动时间
*/
public static Date getServerStartDate() {
long time = ManagementFactory.getRuntimeMXBean().getStartTime();
return new Date(time);
}
/**
* 计算两个时间差
*/
public static String getDatePoor(Date endDate, Date nowDate) {
long nd = 1000 * 24 * 60 * 60;
long nh = 1000 * 60 * 60;
long nm = 1000 * 60;
// long ns = 1000;
// 获得两个时间的毫秒时间差异
long diff = endDate.getTime() - nowDate.getTime();
// 计算差多少天
long day = diff / nd;
// 计算差多少小时
long hour = diff % nd / nh;
// 计算差多少分钟
long min = diff % nd % nh / nm;
// 计算差多少秒//输出结果
// long sec = diff % nd % nh % nm / ns;
return day + "天" + hour + "小时" + min + "分钟";
}
/**
* 增加 LocalDateTime ==> Date
*/
public static Date toDate(LocalDateTime temporalAccessor) {
ZonedDateTime zdt = temporalAccessor.atZone(ZoneId.systemDefault());
return Date.from(zdt.toInstant());
}
/**
* 增加 LocalDate ==> Date
*/
public static Date toDate(LocalDate temporalAccessor) {
LocalDateTime localDateTime = LocalDateTime.of(temporalAccessor, LocalTime.of(0, 0, 0));
ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault());
return Date.from(zdt.toInstant());
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.common.util.file;
import java.io.File;
import org.apache.commons.lang3.StringUtils;
/**
* 文件类型工具类
*/
public class FileTypeUtils {
/**
* 获取文件类型
* <p>
* 例如: ruoyi.txt, 返回: txt
*
* @param file 文件名
* @return 后缀(不含".")
*/
public static String getFileType(File file) {
if (null == file) {
return StringUtils.EMPTY;
}
return getFileType(file.getName());
}
/**
* 获取文件类型
* <p>
* 例如: ruoyi.txt, 返回: txt
*
* @param fileName 文件名
* @return 后缀(不含".")
*/
public static String getFileType(String fileName) {
int separatorIndex = fileName.lastIndexOf(".");
if (separatorIndex < 0) {
return "";
}
return fileName.substring(separatorIndex + 1).toLowerCase();
}
/**
* 获取文件类型
*
* @param photoByte 文件字节码
* @return 后缀(不含".")
*/
public static String getFileExtendName(byte[] photoByte) {
String strFileExtendName = "JPG";
if (
(photoByte[0] == 71) &&
(photoByte[1] == 73) &&
(photoByte[2] == 70) &&
(photoByte[3] == 56) &&
((photoByte[4] == 55) || (photoByte[4] == 57)) &&
(photoByte[5] == 97)
) {
strFileExtendName = "GIF";
} else if ((photoByte[6] == 74) && (photoByte[7] == 70) && (photoByte[8] == 73) && (photoByte[9] == 70)) {
strFileExtendName = "JPG";
} else if ((photoByte[0] == 66) && (photoByte[1] == 77)) {
strFileExtendName = "BMP";
} else if ((photoByte[1] == 80) && (photoByte[2] == 78) && (photoByte[3] == 71)) {
strFileExtendName = "PNG";
}
return strFileExtendName;
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.common.util.file;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Arrays;
import org.apache.poi.util.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 图片处理工具类
*/
public class ImageUtils {
private static final Logger log = LoggerFactory.getLogger(ImageUtils.class);
public static byte[] getImage(String imagePath) {
InputStream is = getFile(imagePath);
try {
return IOUtils.toByteArray(is);
} catch (Exception e) {
log.error("图片加载异常 {}", e);
return null;
} finally {
IOUtils.closeQuietly(is);
}
}
public static InputStream getFile(String imagePath) {
try {
byte[] result = readFile(imagePath);
result = Arrays.copyOf(result, result.length);
return new ByteArrayInputStream(result);
} catch (Exception e) {
log.error("获取图片异常 {}", e);
}
return null;
}
/**
* 读取文件为字节数据
*
* @param url 地址
* @return 字节数据
*/
public static byte[] readFile(String url) {
InputStream in = null;
try {
// 网络地址
URL urlObj = new URL(url);
URLConnection urlConnection = urlObj.openConnection();
urlConnection.setConnectTimeout(30 * 1000);
urlConnection.setReadTimeout(60 * 1000);
urlConnection.setDoInput(true);
in = urlConnection.getInputStream();
return IOUtils.toByteArray(in);
} catch (Exception e) {
log.error("访问文件异常 {}", e);
return null;
} finally {
IOUtils.closeQuietly(in);
}
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.common.util.poi;
/**
* Excel数据格式处理适配器
*/
public interface ExcelHandlerAdapter {
/**
* 格式化
*
* @param value 单元格数据值
* @param args excel注解args参数组
* @return 处理后的值
*/
Object format(Object value, String[] args);
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.common.util.poi;
import com.yiring.common.annotation.Excel;
import com.yiring.common.annotation.Excel.ColumnType;
import com.yiring.common.annotation.Excel.Type;
import com.yiring.common.annotation.Excels;
import com.yiring.common.text.Convert;
import com.yiring.common.util.DictUtils;
import com.yiring.common.util.StrUtils;
import com.yiring.common.util.date.DateUtils;
import com.yiring.common.util.file.FileTypeUtils;
import com.yiring.common.util.file.ImageUtils;
import com.yiring.common.util.reflect.ReflectUtils;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.RegExUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFDataValidation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Excel相关处理
*
* @author ruoyi
*/
public class ExcelUtils<T> {
private static final Logger log = LoggerFactory.getLogger(ExcelUtils.class);
public static final String FORMULA_REGEX_STR = "=|-|\\+|@";
public static final String[] FORMULA_STR = { "=", "-", "+", "@" };
/**
* Excel sheet最大行数,默认65536
*/
public static final int sheetSize = 65536;
/**
* 工作表名称
*/
private String sheetName;
/**
* 导出类型(EXPORT:导出数据;IMPORT:导入模板)
*/
private Type type;
/**
* 工作薄对象
*/
private Workbook wb;
/**
* 工作表对象
*/
private Sheet sheet;
/**
* 样式列表
*/
private Map<String, CellStyle> styles;
/**
* 导入导出数据列表
*/
private List<T> list;
/**
* 注解列表
*/
private List<Object[]> fields;
/**
* 当前行号
*/
private int rownum;
/**
* 标题
*/
private String title;
/**
* 最大高度
*/
private short maxHeight;
/**
* 统计列表
*/
private Map<Integer, Double> statistics = new HashMap<Integer, Double>();
/**
* 数字格式
*/
private static final DecimalFormat DOUBLE_FORMAT = new DecimalFormat("######0.00");
/**
* 实体对象
*/
public Class<T> clazz;
public ExcelUtils(Class<T> clazz) {
this.clazz = clazz;
}
public void init(List<T> list, String sheetName, String title, Type type) {
if (list == null) {
list = new ArrayList<T>();
}
this.list = list;
this.sheetName = sheetName;
this.type = type;
this.title = title;
createExcelField();
createWorkbook();
createTitle();
}
/**
* 创建excel第一行标题
*/
public void createTitle() {
if (StrUtils.isNotEmpty(title)) {
Row titleRow = sheet.createRow(rownum == 0 ? rownum++ : 0);
titleRow.setHeightInPoints(30);
Cell titleCell = titleRow.createCell(0);
titleCell.setCellStyle(styles.get("title"));
titleCell.setCellValue(title);
sheet.addMergedRegion(
new CellRangeAddress(
titleRow.getRowNum(),
titleRow.getRowNum(),
titleRow.getRowNum(),
this.fields.size() - 1
)
);
}
}
/**
* 对excel表单默认第一个索引名转换成list
*
* @param is 输入流
* @return 转换后集合
*/
public List<T> importExcel(InputStream is) throws Exception {
return importExcel(is, 0);
}
/**
* 对excel表单默认第一个索引名转换成list
*
* @param is 输入流
* @param titleNum 标题占用行数
* @return 转换后集合
*/
public List<T> importExcel(InputStream is, int titleNum) throws Exception {
return importExcel(StrUtils.EMPTY, is, titleNum);
}
/**
* 对excel表单指定表格索引名转换成list
*
* @param sheetName 表格索引名
* @param titleNum 标题占用第几行数
* @param is 输入流
* @return 转换后集合
*/
public List<T> importExcel(String sheetName, InputStream is, int titleNum) throws Exception {
this.type = Type.IMPORT;
this.wb = WorkbookFactory.create(is);
List<T> list = new ArrayList<T>();
// 如果指定sheet名,则取指定sheet中的内容 否则默认指向第1个sheet
Sheet sheet = StrUtils.isNotEmpty(sheetName) ? wb.getSheet(sheetName) : wb.getSheetAt(0);
if (sheet == null) {
throw new IOException("文件sheet不存在");
}
// 获取最后一个非空行的行下标,比如总行数为n,则返回的为n-1
int rows = sheet.getLastRowNum();
if (rows > 0) {
// 定义一个map用于存放excel列的序号和field.
Map<String, Integer> cellMap = new HashMap<String, Integer>();
// 获取表头
Row heard = sheet.getRow(titleNum);
for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++) {
Cell cell = heard.getCell(i);
if (StrUtils.isNotNull(cell)) {
String value = this.getCellValue(heard, i).toString();
cellMap.put(value, i);
} else {
cellMap.put(null, i);
}
}
// 有数据时才处理 得到类的所有field.
List<Object[]> fields = this.getFields();
Map<Integer, Object[]> fieldsMap = new HashMap<Integer, Object[]>();
for (Object[] objects : fields) {
Excel attr = (Excel) objects[1];
Integer column = cellMap.get(attr.name());
if (column != null) {
fieldsMap.put(column, objects);
}
}
for (int i = titleNum + 1; i <= rows; i++) {
// 从第2行开始取数据,默认第一行是表头.
Row row = sheet.getRow(i);
// 判断当前行是否是空行
if (isRowEmpty(row)) {
continue;
}
T entity = null;
for (Map.Entry<Integer, Object[]> entry : fieldsMap.entrySet()) {
Object val = this.getCellValue(row, entry.getKey());
// 如果不存在实例则新建.
entity = (entity == null ? clazz.newInstance() : entity);
// 从map中得到对应列的field.
Field field = (Field) entry.getValue()[0];
Excel attr = (Excel) entry.getValue()[1];
// 取得类型,并根据对象类型设置值.
Class<?> fieldType = field.getType();
if (String.class == fieldType) {
String s = Convert.toStr(val);
if (StrUtils.endsWith(s, ".0")) {
val = StrUtils.substringBefore(s, ".0");
} else {
String dateFormat = field.getAnnotation(Excel.class).dateFormat();
if (StrUtils.isNotEmpty(dateFormat)) {
val = parseDateToStr(dateFormat, val);
} else {
val = Convert.toStr(val);
}
}
} else if (
(Integer.TYPE == fieldType || Integer.class == fieldType) &&
StrUtils.isNumeric(Convert.toStr(val))
) {
val = Convert.toInt(val);
} else if (
(Long.TYPE == fieldType || Long.class == fieldType) && StrUtils.isNumeric(Convert.toStr(val))
) {
val = Convert.toLong(val);
} else if (Double.TYPE == fieldType || Double.class == fieldType) {
val = Convert.toDouble(val);
} else if (Float.TYPE == fieldType || Float.class == fieldType) {
val = Convert.toFloat(val);
} else if (BigDecimal.class == fieldType) {
val = Convert.toBigDecimal(val);
} else if (Date.class == fieldType) {
if (val instanceof String) {
val = DateUtils.parseDate(val);
} else if (val instanceof Double) {
val = DateUtil.getJavaDate((Double) val);
}
} else if (Boolean.TYPE == fieldType || Boolean.class == fieldType) {
val = Convert.toBool(val, false);
}
if (StrUtils.isNotNull(fieldType)) {
String propertyName = field.getName();
if (StrUtils.isNotEmpty(attr.targetAttr())) {
propertyName = field.getName() + "." + attr.targetAttr();
} else if (StrUtils.isNotEmpty(attr.readConverterExp())) {
val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator());
} else if (!attr.handler().equals(ExcelHandlerAdapter.class)) {
val = dataFormatHandlerAdapter(val, attr);
}
ReflectUtils.invokeSetter(entity, propertyName, val);
}
}
list.add(entity);
}
}
return list;
}
/**
* 对list数据源将其里面的数据导入到excel表单
*
* @param response 返回数据
* @param list 导出数据集合
* @param sheetName 工作表的名称
* @return 结果
* @throws IOException
*/
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName) {
exportExcel(response, list, sheetName, StrUtils.EMPTY);
}
/**
* 对list数据源将其里面的数据导入到excel表单
*
* @param response 返回数据
* @param list 导出数据集合
* @param sheetName 工作表的名称
* @param title 标题
* @return 结果
* @throws IOException
*/
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName, String title) {
// response.setContentType("application/octet-stream");
// response.setCharacterEncoding("utf-8");
this.init(list, sheetName, title, Type.EXPORT);
exportExcel(response);
}
/**
* 对list数据源将其里面的数据导入到excel表单
*
* @param sheetName 工作表的名称
* @return 结果
*/
/**
* 对list数据源将其里面的数据导入到excel表单
*
* @param sheetName 工作表的名称
* @return 结果
*/
public void importTemplateExcel(HttpServletResponse response, String sheetName) {
importTemplateExcel(response, sheetName, StrUtils.EMPTY);
}
/**
* 对list数据源将其里面的数据导入到excel表单
*
* @param sheetName 工作表的名称
* @param title 标题
* @return 结果
*/
public void importTemplateExcel(HttpServletResponse response, String sheetName, String title) {
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
this.init(null, sheetName, title, Type.IMPORT);
exportExcel(response);
}
/**
* 对list数据源将其里面的数据导入到excel表单
*
* @return 结果
*/
public void exportExcel(HttpServletResponse response) {
try {
writeSheet();
wb.write(response.getOutputStream());
// FileOutputStream fos = new FileOutputStream("D:/a.xls");
// wb.write(fos);
// fos.close();
} catch (Exception e) {
log.error("导出Excel异常{}", e.getMessage());
} finally {
IOUtils.closeQuietly(wb);
}
}
/**
* 创建写入数据到Sheet
*/
public void writeSheet() {
// 取出一共有多少个sheet.
int sheetNo = Math.max(1, (int) Math.ceil(list.size() * 1.0 / sheetSize));
for (int index = 0; index < sheetNo; index++) {
createSheet(sheetNo, index);
// 产生一行
Row row = sheet.createRow(rownum);
int column = 0;
// 写入各个字段的列头名称
for (Object[] os : fields) {
Excel excel = (Excel) os[1];
this.createCell(excel, row, column++);
}
if (Type.EXPORT.equals(type)) {
fillExcelData(index, row);
addStatisticsRow();
}
}
}
/**
* 填充excel数据
*
* @param index 序号
* @param row 单元格行
*/
public void fillExcelData(int index, Row row) {
int startNo = index * sheetSize;
int endNo = Math.min(startNo + sheetSize, list.size());
for (int i = startNo; i < endNo; i++) {
row = sheet.createRow(i + 1 + rownum - startNo);
// 得到导出对象.
T vo = (T) list.get(i);
int column = 0;
for (Object[] os : fields) {
Field field = (Field) os[0];
Excel excel = (Excel) os[1];
this.addCell(excel, row, vo, field, column++);
}
}
}
/**
* 创建表格样式
*
* @param wb 工作薄对象
* @return 样式列表
*/
private Map<String, CellStyle> createStyles(Workbook wb) {
// 写入各条记录,每条记录对应excel表中的一行
Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
CellStyle style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
Font titleFont = wb.createFont();
titleFont.setFontName("Arial");
titleFont.setFontHeightInPoints((short) 16);
titleFont.setBold(true);
style.setFont(titleFont);
styles.put("title", style);
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setBorderRight(BorderStyle.THIN);
style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderLeft(BorderStyle.THIN);
style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderTop(BorderStyle.THIN);
style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderBottom(BorderStyle.THIN);
style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
Font dataFont = wb.createFont();
dataFont.setFontName("Arial");
dataFont.setFontHeightInPoints((short) 10);
style.setFont(dataFont);
styles.put("data", style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
Font headerFont = wb.createFont();
headerFont.setFontName("Arial");
headerFont.setFontHeightInPoints((short) 10);
headerFont.setBold(true);
headerFont.setColor(IndexedColors.WHITE.getIndex());
style.setFont(headerFont);
styles.put("header", style);
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
Font totalFont = wb.createFont();
totalFont.setFontName("Arial");
totalFont.setFontHeightInPoints((short) 10);
style.setFont(totalFont);
styles.put("total", style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(HorizontalAlignment.LEFT);
styles.put("data1", style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(HorizontalAlignment.CENTER);
styles.put("data2", style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(HorizontalAlignment.RIGHT);
styles.put("data3", style);
return styles;
}
/**
* 创建单元格
*/
public Cell createCell(Excel attr, Row row, int column) {
// 创建列
Cell cell = row.createCell(column);
// 写入列信息
cell.setCellValue(attr.name());
setDataValidation(attr, row, column);
cell.setCellStyle(styles.get("header"));
return cell;
}
/**
* 设置单元格信息
*
* @param value 单元格值
* @param attr 注解相关
* @param cell 单元格信息
*/
public void setCellVo(Object value, Excel attr, Cell cell) {
if (ColumnType.STRING == attr.cellType()) {
String cellValue = Convert.toStr(value);
// 对于任何以表达式触发字符 =-+@开头的单元格,直接使用tab字符作为前缀,防止CSV注入。
if (StrUtils.startsWithAny(cellValue, FORMULA_STR)) {
cellValue = RegExUtils.replaceFirst(cellValue, FORMULA_REGEX_STR, "\t$0");
}
cell.setCellValue(StrUtils.isNull(cellValue) ? attr.defaultValue() : cellValue + attr.suffix());
} else if (ColumnType.NUMERIC == attr.cellType()) {
if (StrUtils.isNotNull(value)) {
cell.setCellValue(
StrUtils.contains(Convert.toStr(value), ".") ? Convert.toDouble(value) : Convert.toInt(value)
);
}
} else if (ColumnType.IMAGE == attr.cellType()) {
ClientAnchor anchor = new XSSFClientAnchor(
0,
0,
0,
0,
(short) cell.getColumnIndex(),
cell.getRow().getRowNum(),
(short) (cell.getColumnIndex() + 1),
cell.getRow().getRowNum() + 1
);
String imagePath = Convert.toStr(value);
if (StrUtils.isNotEmpty(imagePath)) {
byte[] data = ImageUtils.getImage(imagePath);
getDrawingPatriarch(cell.getSheet())
.createPicture(anchor, cell.getSheet().getWorkbook().addPicture(data, getImageType(data)));
}
}
}
/**
* 获取画布
*/
public static Drawing<?> getDrawingPatriarch(Sheet sheet) {
if (sheet.getDrawingPatriarch() == null) {
sheet.createDrawingPatriarch();
}
return sheet.getDrawingPatriarch();
}
/**
* 获取图片类型,设置图片插入类型
*/
public int getImageType(byte[] value) {
String type = FileTypeUtils.getFileExtendName(value);
if ("JPG".equalsIgnoreCase(type)) {
return Workbook.PICTURE_TYPE_JPEG;
} else if ("PNG".equalsIgnoreCase(type)) {
return Workbook.PICTURE_TYPE_PNG;
}
return Workbook.PICTURE_TYPE_JPEG;
}
/**
* 创建表格样式
*/
public void setDataValidation(Excel attr, Row row, int column) {
if (attr.name().indexOf("注:") >= 0) {
sheet.setColumnWidth(column, 6000);
} else {
// 设置列宽
sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 256));
}
if (StrUtils.isNotEmpty(attr.prompt()) || attr.combo().length > 0) {
// 提示信息或只能选择不能输入的列内容.
setPromptOrValidation(sheet, attr.combo(), attr.prompt(), 1, 100, column, column);
}
}
/**
* 添加单元格
*/
public Cell addCell(Excel attr, Row row, T vo, Field field, int column) {
Cell cell = null;
try {
// 设置行高
row.setHeight(maxHeight);
// 根据Excel中设置情况决定是否导出,有些情况需要保持为空,希望用户填写这一列.
if (attr.isExport()) {
// 创建cell
cell = row.createCell(column);
int align = attr.align().value();
cell.setCellStyle(styles.get("data" + (align >= 1 && align <= 3 ? align : "")));
// 用于读取对象中的属性
Object value = getTargetValue(vo, field, attr);
String dateFormat = attr.dateFormat();
String readConverterExp = attr.readConverterExp();
String separator = attr.separator();
String dictType = attr.dictType();
if (StrUtils.isNotEmpty(dateFormat) && StrUtils.isNotNull(value)) {
cell.setCellValue(parseDateToStr(dateFormat, value));
} else if (StrUtils.isNotEmpty(readConverterExp) && StrUtils.isNotNull(value)) {
cell.setCellValue(convertByExp(Convert.toStr(value), readConverterExp, separator));
} else if (StrUtils.isNotEmpty(dictType) && StrUtils.isNotNull(value)) {
cell.setCellValue(convertDictByExp(Convert.toStr(value), dictType, separator));
} else if (value instanceof BigDecimal && -1 != attr.scale()) {
cell.setCellValue((((BigDecimal) value).setScale(attr.scale(), attr.roundingMode())).toString());
} else if (!attr.handler().equals(ExcelHandlerAdapter.class)) {
cell.setCellValue(dataFormatHandlerAdapter(value, attr));
} else {
// 设置列类型
setCellVo(value, attr, cell);
}
addStatisticsData(column, Convert.toStr(value), attr);
}
} catch (Exception e) {
log.error("导出Excel失败{}", e);
}
return cell;
}
/**
* 设置 POI XSSFSheet 单元格提示或选择框
*
* @param sheet 表单
* @param textlist 下拉框显示的内容
* @param promptContent 提示内容
* @param firstRow 开始行
* @param endRow 结束行
* @param firstCol 开始列
* @param endCol 结束列
*/
public void setPromptOrValidation(
Sheet sheet,
String[] textlist,
String promptContent,
int firstRow,
int endRow,
int firstCol,
int endCol
) {
DataValidationHelper helper = sheet.getDataValidationHelper();
DataValidationConstraint constraint = textlist.length > 0
? helper.createExplicitListConstraint(textlist)
: helper.createCustomConstraint("DD1");
CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
DataValidation dataValidation = helper.createValidation(constraint, regions);
if (StrUtils.isNotEmpty(promptContent)) {
// 如果设置了提示信息则鼠标放上去提示
dataValidation.createPromptBox("", promptContent);
dataValidation.setShowPromptBox(true);
}
// 处理Excel兼容性问题
if (dataValidation instanceof XSSFDataValidation) {
dataValidation.setSuppressDropDownArrow(true);
dataValidation.setShowErrorBox(true);
} else {
dataValidation.setSuppressDropDownArrow(false);
}
sheet.addValidationData(dataValidation);
}
/**
* 解析导出值 0=男,1=女,2=未知
*
* @param propertyValue 参数值
* @param converterExp 翻译注解
* @param separator 分隔符
* @return 解析后值
*/
public static String convertByExp(String propertyValue, String converterExp, String separator) {
StringBuilder propertyString = new StringBuilder();
String[] convertSource = converterExp.split(",");
for (String item : convertSource) {
String[] itemArray = item.split("=");
if (StrUtils.containsAny(separator, propertyValue)) {
for (String value : propertyValue.split(separator)) {
if (itemArray[0].equals(value)) {
propertyString.append(itemArray[1] + separator);
break;
}
}
} else {
if (itemArray[0].equals(propertyValue)) {
return itemArray[1];
}
}
}
return StrUtils.stripEnd(propertyString.toString(), separator);
}
/**
* 反向解析值 男=0,女=1,未知=2
*
* @param propertyValue 参数值
* @param converterExp 翻译注解
* @param separator 分隔符
* @return 解析后值
*/
public static String reverseByExp(String propertyValue, String converterExp, String separator) {
StringBuilder propertyString = new StringBuilder();
String[] convertSource = converterExp.split(",");
for (String item : convertSource) {
String[] itemArray = item.split("=");
if (StrUtils.containsAny(separator, propertyValue)) {
for (String value : propertyValue.split(separator)) {
if (itemArray[1].equals(value)) {
propertyString.append(itemArray[0] + separator);
break;
}
}
} else {
if (itemArray[1].equals(propertyValue)) {
return itemArray[0];
}
}
}
return StrUtils.stripEnd(propertyString.toString(), separator);
}
/**
* 解析字典值
*
* @param dictValue 字典值
* @param dictType 字典类型
* @param separator 分隔符
* @return 字典标签
*/
public static String convertDictByExp(String dictValue, String dictType, String separator) {
return DictUtils.getDictLabel(dictType, dictValue, separator);
}
/**
* 反向解析值字典值
*
* @param dictLabel 字典标签
* @param dictType 字典类型
* @param separator 分隔符
* @return 字典值
*/
public static String reverseDictByExp(String dictLabel, String dictType, String separator) {
return DictUtils.getDictValue(dictType, dictLabel, separator);
}
/**
* 数据处理器
*
* @param value 数据值
* @param excel 数据注解
* @return
*/
public String dataFormatHandlerAdapter(Object value, Excel excel) {
try {
Object instance = excel.handler().newInstance();
Method formatMethod = excel.handler().getMethod("format", new Class[] { Object.class, String[].class });
value = formatMethod.invoke(instance, value, excel.args());
} catch (Exception e) {
log.error("不能格式化数据 " + excel.handler(), e.getMessage());
}
return Convert.toStr(value);
}
/**
* 合计统计信息
*/
private void addStatisticsData(Integer index, String text, Excel entity) {
if (entity != null && entity.isStatistics()) {
Double temp = 0D;
if (!statistics.containsKey(index)) {
statistics.put(index, temp);
}
try {
temp = Double.valueOf(text);
} catch (NumberFormatException e) {}
statistics.put(index, statistics.get(index) + temp);
}
}
/**
* 创建统计行
*/
public void addStatisticsRow() {
if (statistics.size() > 0) {
Row row = sheet.createRow(sheet.getLastRowNum() + 1);
Set<Integer> keys = statistics.keySet();
Cell cell = row.createCell(0);
cell.setCellStyle(styles.get("total"));
cell.setCellValue("合计");
for (Integer key : keys) {
cell = row.createCell(key);
cell.setCellStyle(styles.get("total"));
cell.setCellValue(DOUBLE_FORMAT.format(statistics.get(key)));
}
statistics.clear();
}
}
/**
* 获取bean中的属性值
*
* @param vo 实体对象
* @param field 字段
* @param excel 注解
* @return 最终的属性值
* @throws Exception
*/
private Object getTargetValue(T vo, Field field, Excel excel) throws Exception {
Object o = field.get(vo);
if (StrUtils.isNotEmpty(excel.targetAttr())) {
String target = excel.targetAttr();
if (target.contains(".")) {
String[] targets = target.split("[.]");
for (String name : targets) {
o = getValue(o, name);
}
} else {
o = getValue(o, target);
}
}
return o;
}
/**
* 以类的属性的get方法方法形式获取值
*
* @param o
* @param name
* @return value
* @throws Exception
*/
private Object getValue(Object o, String name) throws Exception {
if (StrUtils.isNotNull(o) && StrUtils.isNotEmpty(name)) {
Class<?> clazz = o.getClass();
Field field = clazz.getDeclaredField(name);
field.setAccessible(true);
o = field.get(o);
}
return o;
}
/**
* 得到所有定义字段
*/
private void createExcelField() {
this.fields = getFields();
this.fields =
this.fields.stream()
.sorted(Comparator.comparing(objects -> ((Excel) objects[1]).sort()))
.collect(Collectors.toList());
this.maxHeight = getRowHeight();
}
/**
* 获取字段注解信息
*/
public List<Object[]> getFields() {
List<Object[]> fields = new ArrayList<Object[]>();
List<Field> tempFields = new ArrayList<>();
tempFields.addAll(Arrays.asList(clazz.getSuperclass().getDeclaredFields()));
tempFields.addAll(Arrays.asList(clazz.getDeclaredFields()));
for (Field field : tempFields) {
// 单注解
if (field.isAnnotationPresent(Excel.class)) {
Excel attr = field.getAnnotation(Excel.class);
if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) {
field.setAccessible(true);
fields.add(new Object[] { field, attr });
}
}
// 多注解
if (field.isAnnotationPresent(Excels.class)) {
Excels attrs = field.getAnnotation(Excels.class);
Excel[] excels = attrs.value();
for (Excel attr : excels) {
if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) {
field.setAccessible(true);
fields.add(new Object[] { field, attr });
}
}
}
}
return fields;
}
/**
* 根据注解获取最大行高
*/
public short getRowHeight() {
double maxHeight = 0;
for (Object[] os : this.fields) {
Excel excel = (Excel) os[1];
maxHeight = Math.max(maxHeight, excel.height());
}
return (short) (maxHeight * 20);
}
/**
* 创建一个工作簿
*/
public void createWorkbook() {
this.wb = new SXSSFWorkbook(500);
this.sheet = wb.createSheet();
wb.setSheetName(0, sheetName);
this.styles = createStyles(wb);
}
/**
* 创建工作表
*
* @param sheetNo sheet数量
* @param index 序号
*/
public void createSheet(int sheetNo, int index) {
// 设置工作表的名称.
if (sheetNo > 1 && index > 0) {
this.sheet = wb.createSheet();
this.createTitle();
wb.setSheetName(index, sheetName + index);
}
}
/**
* 获取单元格值
*
* @param row 获取的行
* @param column 获取单元格列号
* @return 单元格值
*/
public Object getCellValue(Row row, int column) {
if (row == null) {
return row;
}
Object val = "";
try {
Cell cell = row.getCell(column);
if (StrUtils.isNotNull(cell)) {
if (cell.getCellType() == CellType.NUMERIC || cell.getCellType() == CellType.FORMULA) {
val = cell.getNumericCellValue();
if (DateUtil.isCellDateFormatted(cell)) {
val = DateUtil.getJavaDate((Double) val); // POI Excel 日期格式转换
} else {
if ((Double) val % 1 != 0) {
val = new BigDecimal(val.toString());
} else {
val = new DecimalFormat("0").format(val);
}
}
} else if (cell.getCellType() == CellType.STRING) {
val = cell.getStringCellValue();
} else if (cell.getCellType() == CellType.BOOLEAN) {
val = cell.getBooleanCellValue();
} else if (cell.getCellType() == CellType.ERROR) {
val = cell.getErrorCellValue();
}
}
} catch (Exception e) {
return val;
}
return val;
}
/**
* 判断是否是空行
*
* @param row 判断的行
* @return
*/
private boolean isRowEmpty(Row row) {
if (row == null) {
return true;
}
for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) {
Cell cell = row.getCell(i);
if (cell != null && cell.getCellType() != CellType.BLANK) {
return false;
}
}
return true;
}
/**
* 格式化不同类型的日期对象
*
* @param dateFormat 日期格式
* @param val 被格式化的日期对象
* @return 格式化后的日期字符
*/
public String parseDateToStr(String dateFormat, Object val) {
if (val == null) {
return "";
}
String str;
if (val instanceof Date) {
str = DateUtils.parseDateToStr(dateFormat, (Date) val);
} else if (val instanceof LocalDateTime) {
str = DateUtils.parseDateToStr(dateFormat, DateUtils.toDate((LocalDateTime) val));
} else if (val instanceof LocalDate) {
str = DateUtils.parseDateToStr(dateFormat, DateUtils.toDate((LocalDate) val));
} else {
str = val.toString();
}
return str;
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.common.util.reflect;
import com.yiring.common.text.Convert;
import com.yiring.common.util.date.DateUtils;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Date;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.apache.poi.ss.usermodel.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 反射工具类. 提供调用getter/setter方法, 访问私有变量, 调用私有方法, 获取泛型类型Class, 被AOP过的真实类等工具函数.
*/
@SuppressWarnings("rawtypes")
public class ReflectUtils {
private static final String SETTER_PREFIX = "set";
private static final String GETTER_PREFIX = "get";
private static final String CGLIB_CLASS_SEPARATOR = "$$";
private static Logger logger = LoggerFactory.getLogger(ReflectUtils.class);
/**
* 调用Getter方法.
* 支持多级,如:对象名.对象名.方法
*/
@SuppressWarnings("unchecked")
public static <E> E invokeGetter(Object obj, String propertyName) {
Object object = obj;
for (String name : StringUtils.split(propertyName, ".")) {
String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(name);
object = invokeMethod(object, getterMethodName, new Class[] {}, new Object[] {});
}
return (E) object;
}
/**
* 调用Setter方法, 仅匹配方法名。
* 支持多级,如:对象名.对象名.方法
*/
public static <E> void invokeSetter(Object obj, String propertyName, E value) {
Object object = obj;
String[] names = StringUtils.split(propertyName, ".");
for (int i = 0; i < names.length; i++) {
if (i < names.length - 1) {
String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(names[i]);
object = invokeMethod(object, getterMethodName, new Class[] {}, new Object[] {});
} else {
String setterMethodName = SETTER_PREFIX + StringUtils.capitalize(names[i]);
invokeMethodByName(object, setterMethodName, new Object[] { value });
}
}
}
/**
* 直接读取对象属性值, 无视private/protected修饰符, 不经过getter函数.
*/
@SuppressWarnings("unchecked")
public static <E> E getFieldValue(final Object obj, final String fieldName) {
Field field = getAccessibleField(obj, fieldName);
if (field == null) {
logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 ");
return null;
}
E result = null;
try {
result = (E) field.get(obj);
} catch (IllegalAccessException e) {
logger.error("不可能抛出的异常{}", e.getMessage());
}
return result;
}
/**
* 直接设置对象属性值, 无视private/protected修饰符, 不经过setter函数.
*/
public static <E> void setFieldValue(final Object obj, final String fieldName, final E value) {
Field field = getAccessibleField(obj, fieldName);
if (field == null) {
// throw new IllegalArgumentException("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 ");
logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 ");
return;
}
try {
field.set(obj, value);
} catch (IllegalAccessException e) {
logger.error("不可能抛出的异常: {}", e.getMessage());
}
}
/**
* 直接调用对象方法, 无视private/protected修饰符.
* 用于一次性调用的情况,否则应使用getAccessibleMethod()函数获得Method后反复调用.
* 同时匹配方法名+参数类型,
*/
@SuppressWarnings("unchecked")
public static <E> E invokeMethod(
final Object obj,
final String methodName,
final Class<?>[] parameterTypes,
final Object[] args
) {
if (obj == null || methodName == null) {
return null;
}
Method method = getAccessibleMethod(obj, methodName, parameterTypes);
if (method == null) {
logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + methodName + "] 方法 ");
return null;
}
try {
return (E) method.invoke(obj, args);
} catch (Exception e) {
String msg = "method: " + method + ", obj: " + obj + ", args: " + args + "";
throw convertReflectionExceptionToUnchecked(msg, e);
}
}
/**
* 直接调用对象方法, 无视private/protected修饰符,
* 用于一次性调用的情况,否则应使用getAccessibleMethodByName()函数获得Method后反复调用.
* 只匹配函数名,如果有多个同名函数调用第一个。
*/
@SuppressWarnings("unchecked")
public static <E> E invokeMethodByName(final Object obj, final String methodName, final Object[] args) {
Method method = getAccessibleMethodByName(obj, methodName, args.length);
if (method == null) {
// 如果为空不报错,直接返回空。
logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + methodName + "] 方法 ");
return null;
}
try {
// 类型转换(将参数数据类型转换为目标方法参数类型)
Class<?>[] cs = method.getParameterTypes();
for (int i = 0; i < cs.length; i++) {
if (args[i] != null && !args[i].getClass().equals(cs[i])) {
if (cs[i] == String.class) {
args[i] = Convert.toStr(args[i]);
if (StringUtils.endsWith((String) args[i], ".0")) {
args[i] = StringUtils.substringBefore((String) args[i], ".0");
}
} else if (cs[i] == Integer.class) {
args[i] = Convert.toInt(args[i]);
} else if (cs[i] == Long.class) {
args[i] = Convert.toLong(args[i]);
} else if (cs[i] == Double.class) {
args[i] = Convert.toDouble(args[i]);
} else if (cs[i] == Float.class) {
args[i] = Convert.toFloat(args[i]);
} else if (cs[i] == Date.class) {
if (args[i] instanceof String) {
args[i] = DateUtils.parseDate(args[i]);
} else {
args[i] = DateUtil.getJavaDate((Double) args[i]);
}
} else if (cs[i] == boolean.class || cs[i] == Boolean.class) {
args[i] = Convert.toBool(args[i]);
}
}
}
return (E) method.invoke(obj, args);
} catch (Exception e) {
String msg = "method: " + method + ", obj: " + obj + ", args: " + args + "";
throw convertReflectionExceptionToUnchecked(msg, e);
}
}
/**
* 循环向上转型, 获取对象的DeclaredField, 并强制设置为可访问.
* 如向上转型到Object仍无法找到, 返回null.
*/
public static Field getAccessibleField(final Object obj, final String fieldName) {
// 为空不报错。直接返回 null
if (obj == null) {
return null;
}
Validate.notBlank(fieldName, "fieldName can't be blank");
for (
Class<?> superClass = obj.getClass();
superClass != Object.class;
superClass = superClass.getSuperclass()
) {
try {
Field field = superClass.getDeclaredField(fieldName);
makeAccessible(field);
return field;
} catch (NoSuchFieldException e) {
continue;
}
}
return null;
}
/**
* 循环向上转型, 获取对象的DeclaredMethod,并强制设置为可访问.
* 如向上转型到Object仍无法找到, 返回null.
* 匹配函数名+参数类型。
* 用于方法需要被多次调用的情况. 先使用本函数先取得Method,然后调用Method.invoke(Object obj, Object... args)
*/
public static Method getAccessibleMethod(
final Object obj,
final String methodName,
final Class<?>... parameterTypes
) {
// 为空不报错。直接返回 null
if (obj == null) {
return null;
}
Validate.notBlank(methodName, "methodName can't be blank");
for (
Class<?> searchType = obj.getClass();
searchType != Object.class;
searchType = searchType.getSuperclass()
) {
try {
Method method = searchType.getDeclaredMethod(methodName, parameterTypes);
makeAccessible(method);
return method;
} catch (NoSuchMethodException e) {
continue;
}
}
return null;
}
/**
* 循环向上转型, 获取对象的DeclaredMethod,并强制设置为可访问.
* 如向上转型到Object仍无法找到, 返回null.
* 只匹配函数名。
* 用于方法需要被多次调用的情况. 先使用本函数先取得Method,然后调用Method.invoke(Object obj, Object... args)
*/
public static Method getAccessibleMethodByName(final Object obj, final String methodName, int argsNum) {
// 为空不报错。直接返回 null
if (obj == null) {
return null;
}
Validate.notBlank(methodName, "methodName can't be blank");
for (
Class<?> searchType = obj.getClass();
searchType != Object.class;
searchType = searchType.getSuperclass()
) {
Method[] methods = searchType.getDeclaredMethods();
for (Method method : methods) {
if (method.getName().equals(methodName) && method.getParameterTypes().length == argsNum) {
makeAccessible(method);
return method;
}
}
}
return null;
}
/**
* 改变private/protected的方法为public,尽量不调用实际改动的语句,避免JDK的SecurityManager抱怨。
*/
public static void makeAccessible(Method method) {
if (
(
!Modifier.isPublic(method.getModifiers()) ||
!Modifier.isPublic(method.getDeclaringClass().getModifiers())
) &&
!method.isAccessible()
) {
method.setAccessible(true);
}
}
/**
* 改变private/protected的成员变量为public,尽量不调用实际改动的语句,避免JDK的SecurityManager抱怨。
*/
public static void makeAccessible(Field field) {
if (
(
!Modifier.isPublic(field.getModifiers()) ||
!Modifier.isPublic(field.getDeclaringClass().getModifiers()) ||
Modifier.isFinal(field.getModifiers())
) &&
!field.isAccessible()
) {
field.setAccessible(true);
}
}
/**
* 通过反射, 获得Class定义中声明的泛型参数的类型, 注意泛型必须定义在父类处
* 如无法找到, 返回Object.class.
*/
@SuppressWarnings("unchecked")
public static <T> Class<T> getClassGenricType(final Class clazz) {
return getClassGenricType(clazz, 0);
}
/**
* 通过反射, 获得Class定义中声明的父类的泛型参数的类型.
* 如无法找到, 返回Object.class.
*/
public static Class getClassGenricType(final Class clazz, final int index) {
Type genType = clazz.getGenericSuperclass();
if (!(genType instanceof ParameterizedType)) {
logger.debug(clazz.getSimpleName() + "'s superclass not ParameterizedType");
return Object.class;
}
Type[] params = ((ParameterizedType) genType).getActualTypeArguments();
if (index >= params.length || index < 0) {
logger.debug(
"Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: " + params.length
);
return Object.class;
}
if (!(params[index] instanceof Class)) {
logger.debug(clazz.getSimpleName() + " not set the actual class on superclass generic parameter");
return Object.class;
}
return (Class) params[index];
}
public static Class<?> getUserClass(Object instance) {
if (instance == null) {
throw new RuntimeException("Instance must not be null");
}
Class clazz = instance.getClass();
if (clazz != null && clazz.getName().contains(CGLIB_CLASS_SEPARATOR)) {
Class<?> superClass = clazz.getSuperclass();
if (superClass != null && !Object.class.equals(superClass)) {
return superClass;
}
}
return clazz;
}
/**
* 将反射时的checked exception转换为unchecked exception.
*/
public static RuntimeException convertReflectionExceptionToUnchecked(String msg, Exception e) {
if (
e instanceof IllegalAccessException ||
e instanceof IllegalArgumentException ||
e instanceof NoSuchMethodException
) {
return new IllegalArgumentException(msg, e);
} else if (e instanceof InvocationTargetException) {
return new RuntimeException(msg, ((InvocationTargetException) e).getTargetException());
}
return new RuntimeException(msg, e);
}
}
......@@ -29,6 +29,8 @@ buildscript {
hibernateTypesVersion = '2.16.1'
// https://mvnrepository.com/artifact/com.github.liaochong/myexcel
myexcelVersion = '4.1.1'
// https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-openfeign
openfeignVersion = '3.1.1'
}
}
......@@ -77,7 +79,7 @@ subprojects {
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
}
[compileJava,compileTestJava,javadoc]*.options*.encoding ='UTF-8'
[compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论