Commit 579b5e45 authored by tianbo's avatar tianbo

1、二维码生成工具类;2、水源增加字段

parent bea994cd
......@@ -71,6 +71,12 @@
<artifactId>itext-asian</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.3.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
package com.yeejoin.amos.boot.biz.common.utils;
/**
* tweeter的snowflake 移植到Java:
* (a) id构成: 42位的时间前缀 + 10位的节点标识 + 12位的sequence避免并发的数字(12位不够用时强制得到新的时间前缀)
* 注意这里进行了小改动: snowkflake是5位的datacenter加5位的机器id; 这里变成使用10位的机器id
* (b) 对系统时间的依赖性非常强,需关闭ntp的时间同步功能。当检测到ntp时间调整后,将会拒绝分配id
*/
public class IdWorker {
private final long workerId;
private final long epoch = 1403854494756L; // 时间起始标记点,作为基准,一般取系统的最近时间
private final long workerIdBits = 10L; // 机器标识位数
private final long maxWorkerId = -1L ^ -1L << this.workerIdBits;// 机器ID最大值: 1023
private long sequence = 0L; // 0,并发控制
private final long sequenceBits = 12L; //毫秒内自增位
private final long workerIdShift = this.sequenceBits; // 12
private final long timestampLeftShift = this.sequenceBits + this.workerIdBits;// 22
private final long sequenceMask = -1L ^ -1L << this.sequenceBits; // 4095,111111111111,12位
private long lastTimestamp = -1L;
private IdWorker(long workerId) {
if (workerId > this.maxWorkerId || workerId < 0) {
throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", this.maxWorkerId));
}
this.workerId = workerId;
}
public synchronized long nextId() throws Exception {
long timestamp = this.timeGen();
if (this.lastTimestamp == timestamp) { // 如果上一个timestamp与新产生的相等,则sequence加一(0-4095循环); 对新的timestamp,sequence从0开始
this.sequence = this.sequence + 1 & this.sequenceMask;
if (this.sequence == 0) {
timestamp = this.tilNextMillis(this.lastTimestamp);// 重新生成timestamp
}
} else {
this.sequence = 0;
}
if (timestamp < this.lastTimestamp) {
throw new Exception(String.format("clock moved backwards.Refusing to generate id for %d milliseconds", (this.lastTimestamp - timestamp)));
}
this.lastTimestamp = timestamp;
return timestamp - this.epoch << this.timestampLeftShift | this.workerId << this.workerIdShift | this.sequence;
}
private static IdWorker flowIdWorker = new IdWorker(1);
public static IdWorker getFlowIdWorkerInstance() {
return flowIdWorker;
}
/**
* 等待下一个毫秒的到来, 保证返回的毫秒数在参数lastTimestamp之后
*/
private long tilNextMillis(long lastTimestamp) throws InterruptedException {
long timestamp = this.timeGen();
while (timestamp <= lastTimestamp) {
timestamp = this.timeGen();
}
return timestamp;
}
/**
* 获得系统当前毫秒数
*/
private static long timeGen() throws InterruptedException {
return System.currentTimeMillis();
}
}
\ No newline at end of file
package com.yeejoin.amos.boot.biz.common.utils;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Hashtable;
import java.util.Random;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
* 二维码工具类
*
* @author Administrator
*/
public class QRCodeUtil {
private static final String CHARSET = "utf-8";
private static final int QRCODE_SIZE = 45;
private static Random random = new Random();
private static int randomNumForQrCode;
/**
* <pre>
* 根据当前记录ID生成QRCode
* </pre>
*
* @return
*/
public static String generateQRCode(Date dateCreated, String pointNo) {
return String.valueOf(dateCreated.getTime() + pointNo);
}
/**
* <pre>
* 生成QRCode
* </pre>
*
* @return
*/
public static String generateQRCode() {
String res;
//加锁生成随机数,保证自增后释放
Lock lock = new ReentrantLock();
lock.lock();
randomNumForQrCode += 1;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
try {
res = simpleDateFormat.format(new Date(System.currentTimeMillis())).substring(5, 8) + String.valueOf(IdWorker.getFlowIdWorkerInstance().nextId()).substring(0, 10) + randomNumForQrCode;
} catch (Exception e) {
Random random = new Random(System.currentTimeMillis());
String tmp = "";
for (int i = 0; i < 13; i++) {
tmp += random.nextInt(10);
}
res = simpleDateFormat.format(new Date(System.currentTimeMillis())).substring(2, 8) + tmp.substring(0, 10) + randomNumForQrCode;
} finally {
lock.unlock();
}
return res;
}
/**
* 生成临时的qrCode
*
* @return
*/
public static String temporaryQrCode() {
long qrCode = -1 * System.currentTimeMillis();
qrCode += (long) (random.nextDouble() * 10000000);
return String.valueOf(qrCode);
}
/**
* 根据二维码信息,生成二维码图片 用户excel,word等导出图片
*
* @param content
* @return
*/
public static byte[] generateQRCodeImageByteData(String content) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(EncodeHintType.CHARACTER_SET, CHARSET);
hints.put(EncodeHintType.MARGIN, 1);
BitMatrix bitMatrix = new MultiFormatWriter().encode(
content
, BarcodeFormat.QR_CODE
, QRCODE_SIZE
, QRCODE_SIZE,
hints);
int width = bitMatrix.getWidth();
int height = bitMatrix.getHeight();
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF);
}
}
ImageIO.write(image, "png", out);
return out.toByteArray();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
}
......@@ -2,6 +2,7 @@ package com.yeejoin.amos.boot.module.common.api.dto;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.TableField;
import com.yeejoin.amos.boot.biz.common.dto.BaseDto;
import com.yeejoin.amos.boot.module.common.api.excel.ExplicitConstraint;
import com.yeejoin.amos.boot.module.common.api.excel.RoleNameExplicitConstraint;
......@@ -33,10 +34,6 @@ public class WaterResourceDto extends BaseDto {
@ApiModelProperty(value = "地址")
private String address;
// @ApiModelProperty(value = "经纬度坐标")
// private String latLang;
@ExcelIgnore
@ApiModelProperty(value = "经度")
private Double longitude;
......@@ -308,4 +305,20 @@ public class WaterResourceDto extends BaseDto {
@ExcelIgnore
@ApiModelProperty(value = "物联参数")
private WaterResourceIotDto waterResourceIotDto;
@ApiModelProperty("设施定义名称")
@ExcelProperty(value = "设施定义名称", index = 44)
private String equipName;
@ApiModelProperty("设施分类名称")
@ExcelProperty(value = "设施分类名称", index = 45)
private String equipCategoryName;
@ApiModelProperty("设施编码")
@ExcelProperty(value = "设施编码", index = 46)
private String equipCode;
@ApiModelProperty("维保周期")
@ExcelProperty(value = "维保周期(月)", index = 47)
private String maintenancePeriod;
}
......@@ -36,116 +36,157 @@ public class WaterResource extends BaseEntity {
*/
@TableField("address")
private String address;
/**
* 经纬度坐标
*/
// @TableField("lat_lang")
// private String latLang;
@ApiModelProperty(value = "经度")
private Double longitude;
@ApiModelProperty(value = "纬度")
private Double latitude;
/**
* 资源类型(消火栓、消防水鹤、天然水源、消防水池)
*/
@TableField("resource_type")
private String resourceType;
/**
* 资源类型名称(消火栓、消防水鹤、天然水源、消防水池)
*/
@TableField("resource_type_name")
private String resourceTypeName;
/**
* 所在建筑id
*/
@TableField("belong_building_id")
private Long belongBuildingId;
/**
* 所在建筑
*/
@TableField("belong_building")
private String belongBuilding;
/**
* 所属消防系统id
*/
@TableField("belong_fighting_system_id")
private Long belongFightingSystemId;
/**
* 所属消防系统
*/
@TableField("belong_fighting_system")
private String belongFightingSystem;
/**
* 管理单位id
*/
@TableField("management_unit_id")
private Long managementUnitId;
/**
* 管理单位
*/
@TableField("management_unit")
private String managementUnit;
/**
* 维保单位id
*/
@TableField("maintenance_unit_id")
private Long maintenanceUnitId;
/**
* 维保单位
*/
@TableField("maintenance_unit")
private String maintenanceUnit;
/**
* 建造日期
*/
@TableField("build_date")
private Date buildDate;
/**
* 启用日期
*/
@TableField("enable_date")
private Date enableDate;
/**
* 方位图
*/
@TableField("orientation_img")
private String orientationImg;
/**
* 实景图
*/
@TableField("reality_img")
private String realityImg;
/**
* 联系人姓名
*/
@TableField("contact_user")
private String contactUser;
/**
* 联系人电话
*/
@TableField("contact_phone")
private String contactPhone;
/**
* 是否有物联参数(1有,0没有)
*/
@TableField("is_iot")
private Boolean isIot;
/**
* 消防救援机构_通用唯一识别码
*/
@TableField("rescue_org_code")
private String rescueOrgCode;
/**
* 行政区划代码
*/
@TableField("administrative_code")
private String administrativeCode;
/**
* 组织机构代码
*/
@TableField("org_code")
private String orgCode;
@ApiModelProperty("设施定义")
@TableField("equip_id")
private Long equipId;
@ApiModelProperty("设施定义名称")
@TableField("equip_name")
private String equipName;
@ApiModelProperty("设施分类")
@TableField("equip_category_id")
private Long equipCategoryId;
@ApiModelProperty("设施分类名称")
@TableField("equip_category_name")
private String equipCategoryName;
@ApiModelProperty("设施编码")
@TableField("equip_code")
private String equipCode;
@ApiModelProperty("维保周期")
@TableField("maintenance_period")
private String maintenancePeriod;
}
......@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.constants.BizConstant;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.biz.common.utils.EnumsUtils;
import com.yeejoin.amos.boot.biz.common.utils.QRCodeUtil;
import com.yeejoin.amos.boot.module.common.api.dto.WaterResourceCraneDto;
import com.yeejoin.amos.boot.module.common.api.dto.WaterResourceDto;
import com.yeejoin.amos.boot.module.common.api.dto.WaterResourceHydrantDto;
......@@ -400,4 +401,16 @@ public class WaterResourceController extends BaseController {
public ResponseModel<List<WaterResourceTypeDto>> selectResourceTypeList() {
return ResponseHelper.buildResponse(waterResourceServiceImpl.getWaterResourceTypeList(true));
}
/**
* 生成二维码code
*
* @return string
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(value = "生成二维码code", notes = "生成二维码code")
@GetMapping(value = "/qr/code")
public ResponseModel<String> genQrCode() {
return ResponseHelper.buildResponse(QRCodeUtil.generateQRCode());
}
}
......@@ -7,7 +7,7 @@
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
<changeSet author="guowubin" id="1629430730658-1">
<changeSet author="guowubin" id="1629430730658-1">
<comment>alter table jc_controller</comment>
<sql>
DROP TABLE IF EXISTS `jc_controller`;
......@@ -83,5 +83,19 @@
INSERT INTO `jc_controller_equip` VALUES (1397145718640209921, 1428325285853433857, '103', '4号门', '1', '2021-08-20 09:46:02', 3111584, 'admin_jcs', '0');
</sql>
</changeSet>
<changeSet author="tb" id="2021-08-23-tb-1">
<preConditions onFail="MARK_RAN">
<tableExists tableName="cb_water_resource"/>
</preConditions>
<comment>modify table cb_water_resource add several columns</comment>
<sql>
ALTER TABLE `cb_water_resource` ADD equip_id BIGINT ( 20 ) COMMENT '设施定义',
ADD COLUMN equip_name VARCHAR ( 50 ) COMMENT '设施定义名称',
ADD COLUMN equip_category_id BIGINT ( 20 ) COMMENT '设施分类',
ADD COLUMN equip_category_name VARCHAR ( 50 ) COMMENT '设施分类名称',
ADD COLUMN equip_code VARCHAR ( 20 ) COMMENT '设施编码',
ADD COLUMN maintenance_period VARCHAR ( 10 ) COMMENT '维保周期';
</sql>
</changeSet>
</databaseChangeLog>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment