|
@ -1,7 +1,9 @@
|
|
|
package com.yihu.wlyy.service.common;
|
|
|
|
|
|
import com.yihu.wlyy.entity.address.Hospital;
|
|
|
import com.yihu.wlyy.entity.address.Town;
|
|
|
import com.yihu.wlyy.entity.doctor.profile.Doctor;
|
|
|
import com.yihu.wlyy.repository.address.TownDao;
|
|
|
import com.yihu.wlyy.repository.doctor.DoctorDao;
|
|
|
import com.yihu.wlyy.repository.organization.HospitalDao;
|
|
|
import com.yihu.wlyy.service.BaseService;
|
|
@ -30,6 +32,8 @@ public class QrcodeService extends BaseService {
|
|
|
private DoctorDao doctorDao;
|
|
|
@Autowired
|
|
|
private HospitalDao hospitalDao;
|
|
|
@Autowired
|
|
|
private TownDao townDao;
|
|
|
|
|
|
/**
|
|
|
* 所有医生二维码生成
|
|
@ -104,6 +108,39 @@ public class QrcodeService extends BaseService {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 生成区二维码
|
|
|
*
|
|
|
* @param town
|
|
|
* @param token
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public boolean makeTownQrcode(String town,String token) throws Exception{
|
|
|
try{
|
|
|
Town twn = townDao.findByCode(town);
|
|
|
|
|
|
if (twn != null) {
|
|
|
// 二维码内容
|
|
|
String content = "tw_" + twn.getCode() + "_" + twn.getName();
|
|
|
// 二维码图片文件名
|
|
|
String fileName = twn.getCode();
|
|
|
String path = QrcodeService.class.getResource("/").getPath().replace("/WEB-INF/classes/", "")
|
|
|
+ File.separator + "qrcode";
|
|
|
|
|
|
// 通过微信接口生成区二维码
|
|
|
makeQrcodeFromWeiXin(content, fileName.replaceAll("\r\n", ""), path, token);
|
|
|
|
|
|
return true;
|
|
|
} else {
|
|
|
throw new Exception("can not find town info");
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 社区二维码生成打包为zip
|
|
|
*
|
|
@ -250,6 +287,74 @@ public class QrcodeService extends BaseService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 区二维码生成打包为zip
|
|
|
*
|
|
|
* @param city
|
|
|
* @param token
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public File downLoadTownQrcodes(String city,String token) throws Exception{
|
|
|
// 查找所有医生
|
|
|
Iterable<Town> towns = null;
|
|
|
String zipFileName = "town_qrcode";
|
|
|
|
|
|
if (StringUtils.isNotEmpty(city)) {
|
|
|
towns = townDao.findByCity(city);
|
|
|
} else {
|
|
|
towns = townDao.findAll();
|
|
|
}
|
|
|
|
|
|
String path = QrcodeService.class.getResource("/").getPath().replace("/WEB-INF/classes/", "")
|
|
|
+ File.separator + "qrcode_download";
|
|
|
File file = new File(path);
|
|
|
|
|
|
// 删除文件夹、文件
|
|
|
if (file.exists()) {
|
|
|
File[] files = file.listFiles();
|
|
|
if (files != null && files.length > 0) {
|
|
|
for (File f : files) {
|
|
|
f.delete();
|
|
|
}
|
|
|
}
|
|
|
file.delete();
|
|
|
}
|
|
|
|
|
|
if (towns != null) {
|
|
|
for (Town town : towns) {
|
|
|
if (StringUtils.isNotEmpty(city)) {
|
|
|
zipFileName = town.getCity();
|
|
|
}
|
|
|
|
|
|
// 二维码内容
|
|
|
String content = "tw_" + town.getCode() + "_" + town.getName();
|
|
|
|
|
|
// 二维码图片文件名
|
|
|
String fileName = town.getName() + "_" + town.getCode();
|
|
|
if (StringUtils.isEmpty(fileName)) {
|
|
|
continue;
|
|
|
}
|
|
|
// 通过微信接口生成医生二维码
|
|
|
makeQrcodeFromWeiXin(content, fileName.replaceAll("\r\n", ""), path, token);
|
|
|
}
|
|
|
|
|
|
File zipFile = new File(path.replace("qrcode_download", "") + zipFileName + ".zip");
|
|
|
if (zipFile.exists()) {
|
|
|
zipFile.delete();
|
|
|
}
|
|
|
|
|
|
// 打包文件夹
|
|
|
if (fileToZip(path, path.replace("qrcode_download", ""), zipFileName)) {
|
|
|
return new File(path.replace("qrcode_download", "") + zipFileName + ".zip");
|
|
|
} else {
|
|
|
return null;
|
|
|
}
|
|
|
} else {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 打包文件夹
|
|
|
*
|
|
@ -388,4 +493,6 @@ public class QrcodeService extends BaseService {
|
|
|
throw new Exception(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|