Commit cffbb1fe authored by 张大伟's avatar 张大伟

增加二维码生成工具

parent 998fe633
...@@ -49,5 +49,10 @@ public class BusDevice implements Serializable{ ...@@ -49,5 +49,10 @@ public class BusDevice implements Serializable{
private Integer errorNum; private Integer errorNum;
/**
* 二维码存放路径
*/
private String qrcodeUrl;
} }
package org.rcisoft.business.device.assets.service.impl; package org.rcisoft.business.device.assets.service.impl;
import com.google.zxing.WriterException;
import org.rcisoft.business.device.assets.dao.BusDeviceRepository; import org.rcisoft.business.device.assets.dao.BusDeviceRepository;
import org.rcisoft.business.device.assets.service.BusDeviceService; import org.rcisoft.business.device.assets.service.BusDeviceService;
import org.rcisoft.business.device.assets.vo.DeviceAssetStatisticVo; import org.rcisoft.business.device.assets.vo.DeviceAssetStatisticVo;
...@@ -13,13 +14,16 @@ import org.rcisoft.core.aop.PageUtil; ...@@ -13,13 +14,16 @@ import org.rcisoft.core.aop.PageUtil;
import org.rcisoft.core.model.PersistModel; import org.rcisoft.core.model.PersistModel;
import org.rcisoft.business.device.assets.entity.BusDevice; import org.rcisoft.business.device.assets.entity.BusDevice;
import org.rcisoft.core.util.QRCodeUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
...@@ -44,6 +48,11 @@ public class BusDeviceServiceImpl implements BusDeviceService { ...@@ -44,6 +48,11 @@ public class BusDeviceServiceImpl implements BusDeviceService {
@Autowired @Autowired
private BusDevicetpParamService busDevicetpParamService; private BusDevicetpParamService busDevicetpParamService;
/**
* 二维码存放路径
*/
@Value("${filepath.qrcode}")
String qrcodePath;
/** /**
* 保存 busDevice * 保存 busDevice
...@@ -57,14 +66,27 @@ public class BusDeviceServiceImpl implements BusDeviceService { ...@@ -57,14 +66,27 @@ public class BusDeviceServiceImpl implements BusDeviceService {
String message = ""; String message = "";
//增加操作 //增加操作
busDevice.setDevId(UUID.randomUUID().toString().replace("-","")); busDevice.setDevId(UUID.randomUUID().toString().replace("-",""));
if(busDeviceRepository.queryDeviceByDevNum(busDevice.getDevNum())!=null && busDeviceRepository.queryDeviceByDevNum(busDevice.getDevNum()).size()>0){ boolean flag = busDeviceRepository.queryDeviceByDevNum(busDevice.getDevNum())!=null && busDeviceRepository.queryDeviceByDevNum(busDevice.getDevNum()).size()>0;
if(flag){
line = 0; line = 0;
message = "设备编号已存在,新增失败"; message = "设备编号已存在,新增失败";
}else{ }else{
// 保存二维码路径(配置的路径+项目编号)
String path = qrcodePath + busDevice.getProId() + "/";
try {
// 生成二维码(第一个参数(二维码数据):设备编号,第二个参数(保存的路径):保存的路径,第三个参数(文件名):设备id)
QRCodeUtils.createQRCodeFile(busDevice.getDevNum(), path, busDevice.getDevId());
} catch (WriterException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// 将二维码路径设置到对象中(项目id/设备id.JPG)
busDevice.setQrcodeUrl(busDevice.getProId() + "/" + busDevice.getDevId() + ".JPG");
line = busDeviceRepository.insertSelective(busDevice); line = busDeviceRepository.insertSelective(busDevice);
} }
return new PersistModel(line,message); return new PersistModel(line, message);
} }
......
...@@ -3,10 +3,16 @@ package org.rcisoft.wechat; ...@@ -3,10 +3,16 @@ package org.rcisoft.wechat;
import me.chanjar.weixin.common.bean.WxJsapiSignature; import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
import me.chanjar.weixin.mp.bean.result.WxMpUser; import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.rcisoft.core.constant.MessageConstant;
import org.rcisoft.core.result.Result;
import org.rcisoft.core.result.ResultCode;
import org.rcisoft.wechat.service.WxPortalService; import org.rcisoft.wechat.service.WxPortalService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
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.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
...@@ -43,7 +49,7 @@ public class WechatRedirectController { ...@@ -43,7 +49,7 @@ public class WechatRedirectController {
} }
} }
@RequestMapping(value = {"/getConfig"}) @GetMapping(value = {"/getConfig"})
@ResponseBody @ResponseBody
public Map<String, Object> getConfig(String url) { public Map<String, Object> getConfig(String url) {
try { try {
...@@ -59,4 +65,30 @@ public class WechatRedirectController { ...@@ -59,4 +65,30 @@ public class WechatRedirectController {
} }
return null; return null;
} }
@PostMapping(value = {"/sendMessage"})
@ResponseBody
public Result sendMessage(String message, String openId) {
Result result = new Result();
WxMpKefuMessage wxMpKefuMessage = WxMpKefuMessage
.TEXT()
.toUser(openId)
.content(message)
.build();
// 设置消息的内容等信息
boolean flag;
try {
flag = service.getKefuService().sendKefuMessage(wxMpKefuMessage);
} catch (WxErrorException e) {
e.printStackTrace();
flag = false;
}
if(flag) {
result.setCode(ResultCode.SUCCESS);
} else {
result.setCode(ResultCode.FAIL);
}
return result;
}
} }
...@@ -11,7 +11,7 @@ server: ...@@ -11,7 +11,7 @@ server:
# org.springframework.web: DEBUG # org.springframework.web: DEBUG
druid: druid:
url: jdbc:mysql://localhost:3306/zhny?useUnicode=true&characterEncoding=UTF-8&useSSL=false&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true url: jdbc:mysql://139.199.98.105:3336/zhny?useUnicode=true&characterEncoding=UTF-8&useSSL=false&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
username: root username: root
password: root password: root
initial-size: 1 initial-size: 1
...@@ -113,5 +113,6 @@ filepath: ...@@ -113,5 +113,6 @@ filepath:
equipment: D:\zhny\filepath\equipment\ equipment: D:\zhny\filepath\equipment\
devicetp: D:\zhny\filepath\devicetp\ devicetp: D:\zhny\filepath\devicetp\
loginimg: D:\zhny\filepath\loginimg\ loginimg: D:\zhny\filepath\loginimg\
qrcode: D:\zhny\filepath\qrcode\
serverimgurl: 127.0.0.1:9000/ serverimgurl: 127.0.0.1:9000/
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment