Commit 5ffb6ccf by 阮思源

Merge branches 'master' and 'mymaster' of http://192.168.89.173/rays/pcloud-book into mymaster

parents 6d871d8e 2ac38974
......@@ -432,7 +432,7 @@ public class AdvertisingSpaceBizImpl implements AdvertisingSpaceBiz {
String adTitle = advertisingSpace.getAdTitle();
List<String> linkList = getLinkList(adTitle);//提取文本链接
if (!ListUtils.isEmpty(linkList)) {
adTitle = adTitle.replaceAll("</link><link>","</link> <link>");//连续两个链接之间要有分隔
adTitle = adTitle.replaceAll("</link><link>", "</link> <link>");//连续两个链接之间要有分隔
for (String link : linkList) {
String adLink = "";
String adLinkOld = link.replaceAll("<link>", "").replace("</link>", "");
......@@ -633,9 +633,9 @@ public class AdvertisingSpaceBizImpl implements AdvertisingSpaceBiz {
if (pageBean == null || ListUtils.isEmpty(pageBean.getRecordList())) {
return new PageBean(0, 0, new ArrayList<>());
}
List<Object>objs = pageBean.getRecordList();
List<Object> objs = pageBean.getRecordList();
Object objectlist = (Object) objs;
List<GroupQrcodeVO> groupQrcodeVOList = ( List<GroupQrcodeVO>)objectlist;
List<GroupQrcodeVO> groupQrcodeVOList = (List<GroupQrcodeVO>) objectlist;
List<Long> labelIds = new ArrayList<>();
List<Long> proLabels = groupQrcodeVOList.stream().filter(s->s.getProLabelId()!=null).map(GroupQrcodeVO::getProLabelId).distinct().collect(Collectors.toList());
List<Long> depLabels = groupQrcodeVOList.stream().filter(s->s.getDepLabelId()!=null).map(GroupQrcodeVO::getDepLabelId).distinct().collect(Collectors.toList());
......@@ -643,16 +643,16 @@ public class AdvertisingSpaceBizImpl implements AdvertisingSpaceBiz {
if (!ListUtils.isEmpty(proLabels)){
labelIds.addAll(proLabels);
}
if (!ListUtils.isEmpty(depLabels)){
if (!ListUtils.isEmpty(depLabels)) {
labelIds.addAll(depLabels);
}
if (!ListUtils.isEmpty(purLabels)){
if (!ListUtils.isEmpty(purLabels)) {
labelIds.addAll(purLabels);
}
if (!ListUtils.isEmpty(labelIds)) {
Map<Long, String> labelMap = labelConsr.getLabelName(labelIds);
if (!MapUtils.isEmpty(labelMap)) {
for (Object object:objs){
for (Object object : objs) {
GroupQrcodeVO qrcodeVO = (GroupQrcodeVO) object;
if (null != qrcodeVO.getProLabelId() && labelMap.containsKey(qrcodeVO.getProLabelId())) {
qrcodeVO.setProLabelName(labelMap.get(qrcodeVO.getProLabelId()));
......@@ -905,15 +905,16 @@ public class AdvertisingSpaceBizImpl implements AdvertisingSpaceBiz {
}
/**
* 获取书刊广告位点击读者量
* 获取书刊广告位点击读者量(废弃,读者不走授权,读者信息全为空,没办法聚合,点击量就是读者量)
*/
private Long getClickUserNumByGroupQrcodeId(Long qrcodeId, Long adId, String statisMonth) {
Map<String, Object> paramMap = new HashMap<>();
/*Map<String, Object> paramMap = new HashMap<>();
paramMap.put("qrcodeId", qrcodeId);
paramMap.put("adId", adId);
paramMap.put("statisMonth", statisMonth);
Long clickUserNum = (Long) advertisingClickRecordDao.getBy(paramMap, "getClickUserNumByGroupQrcodeId");
return null == clickUserNum ? 0L : clickUserNum;
return null == clickUserNum ? 0L : clickUserNum;*/
return 0L;
}
/**
......@@ -1283,10 +1284,15 @@ public class AdvertisingSpaceBizImpl implements AdvertisingSpaceBiz {
return new PageBean(0, 0, new ArrayList<>());
}
List<Long> wechatUserIds = new ArrayList<>();
pageBean.getRecordList().forEach(obj -> {
wechatUserIds.add(((WechatGroupClickUserDTO) obj).getWechatUserId());
});
Map<Long, WechatUser> wechatUserMap = readerConsr.getUserList(wechatUserIds);
for (Object object : pageBean.getRecordList()) {
Long wechatUserId = ((WechatGroupClickUserDTO) object).getWechatUserId();
wechatUserIds.add(wechatUserId);
}
Map<Long, WechatUser> wechatUserMap = new HashMap<>();
if (!ListUtils.isEmpty(wechatUserIds)) {
wechatUserIds = new ArrayList<>(new HashSet<>(wechatUserIds));
wechatUserMap = readerConsr.getUserList(wechatUserIds);
}
for (Object object : pageBean.getRecordList()) {
WechatGroupClickUserDTO dto = (WechatGroupClickUserDTO) object;
if (!MapUtils.isEmpty(wechatUserMap) && wechatUserMap.containsKey(dto.getWechatUserId())) {
......@@ -1318,8 +1324,12 @@ public class AdvertisingSpaceBizImpl implements AdvertisingSpaceBiz {
if (ListUtils.isEmpty(list)) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "暂无数据导出!");
}
List<Long> wechatUserIds = list.stream().map(WechatGroupClickUserDTO::getWechatUserId).collect(Collectors.toList());
Map<Long, WechatUser> wechatUserMap = readerConsr.getUserList(wechatUserIds);
List<Long> wechatUserIds = list.stream().filter(dto -> null != dto.getWechatUserId()).map(WechatGroupClickUserDTO::getWechatUserId).collect(Collectors.toList());
Map<Long, WechatUser> wechatUserMap = new HashMap<>();
if (!ListUtils.isEmpty(wechatUserIds)) {
wechatUserIds = new ArrayList<>(new HashSet<>(wechatUserIds));
wechatUserMap = readerConsr.getUserList(wechatUserIds);
}
// 字段名
String[] rowsName = {"序号", "读者信息", "读者标签", "点击时间"};
List<Object[]> dataList = new ArrayList<>();
......@@ -1330,9 +1340,13 @@ public class AdvertisingSpaceBizImpl implements AdvertisingSpaceBiz {
objs[0] = i + 1;
if (!MapUtils.isEmpty(wechatUserMap) && wechatUserMap.containsKey(dto.getWechatUserId())) {
WechatUser wechatUser = wechatUserMap.get(dto.getWechatUserId());
objs[1] = wechatUser.getWechatUserNickname();
String sex = wechatUser.getWechatUserSex().equals(1) ? "男" : (wechatUser.getWechatUserSex().equals(2) ? "女" : "未知");
objs[2] = sex + "," + wechatUser.getWechatUserCity();
objs[1] = null != wechatUser.getWechatUserNickname() ? wechatUser.getWechatUserNickname() : "--";
if (null == wechatUser.getWechatUserSex() && StringUtil.isEmpty(wechatUser.getWechatUserCity())) {
objs[2] = "--";
} else {
String sex = null == wechatUser.getWechatUserSex() ? "--" : (wechatUser.getWechatUserSex().equals(1) ? "男" : (wechatUser.getWechatUserSex().equals(2) ? "女" : "未知"));
objs[2] = sex + "," + (null == wechatUser.getWechatUserCity() ? "--" : wechatUser.getWechatUserCity());
}
} else {
objs[1] = "";
objs[2] = "";
......@@ -1343,10 +1357,10 @@ public class AdvertisingSpaceBizImpl implements AdvertisingSpaceBiz {
GroupQrcode groupQrcode = groupQrcodeDao.getById(qrcodeId);
String[] dateStr = statisMonth.split("-");
String fileName;
if (StringUtil.isEmpty(statisMonth)) {
fileName = (null != groupQrcode ? groupQrcode.getGroupName() : "") + dateStr[0] + "年" + Integer.parseInt(dateStr[1]) + "月" + space.getAdName() + "广告位点击读者明细";
if (!StringUtil.isEmpty(statisMonth)) {
fileName = (null != groupQrcode ? groupQrcode.getGroupName() : "") + dateStr[0] + "年" + Integer.parseInt(dateStr[1]) + "月" + space.getAdName() + "广告位点击明细";
} else {
fileName = space.getAdName() + "广告位" + (null != groupQrcode ? groupQrcode.getGroupName() : "") + "点击读者明细";
fileName = space.getAdName() + "广告位" + (null != groupQrcode ? groupQrcode.getGroupName() : "") + "点击明细";
}
String fileUrl = exportConsr.exportExcel(fileName, rowsName, dataList);
Map<String, Object> result = new HashMap<>();
......
......@@ -371,7 +371,7 @@ public class AdvertisingSpaceFacadeImpl implements AdvertisingSpaceFacade {
Long officialAccountsId = Cookie.getId(userInfo, Cookie._OFFICIAL_ACCOUNTS_ID);
Long wechatUserId = Cookie.getId(userInfo, Cookie._WECHAT_USER_ID);
Long bookGroupId = Cookie.getId(userInfo, Cookie.BOOK_GROUP_ID);
if (null == advertisingClickRecord || null == advertisingClickRecord.getAdId() || null == wechatUserId) {
if (null == advertisingClickRecord || null == advertisingClickRecord.getAdId()) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "参数有误!");
}
if ((null == advertisingClickRecord.getBookId() && !"WECHAT_GROUP".equals(advertisingClickRecord.getFromType()))
......
......@@ -183,6 +183,10 @@ public class BookAuthInfoBizImpl implements BookAuthInfoBiz {
String url = generateExcel(bookAuthCodes, bookDto.getBookName());
String zipUrl = CopyrightTools.generateBar4Zip(bookAuthCodes, bookDto.getBookName(), url);
noticeUrl = zipUrl;
}else if(isHaveBarCode.equals(2)){
String url = generateExcel(bookAuthCodes, bookDto.getBookName());
String zipUrl = CopyrightTools.generateQrcode4Zip(bookAuthCodes, bookDto.getBookName(), url);
noticeUrl = zipUrl;
}else {
String url = generateExcel(bookAuthCodes, bookDto.getBookName());
noticeUrl = url;
......
package com.pcloud.book.copyright.tools;
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 com.pcloud.book.book.constant.BookConstant;
import com.pcloud.book.copyright.dto.DateDTO;
import com.pcloud.book.copyright.entity.BookAuthCode;
......@@ -14,6 +20,7 @@ import com.pcloud.common.utils.LocalDateUtils;
import com.pcloud.common.utils.UUIDUitl;
import com.pcloud.common.utils.aliyun.OssUtils;
import com.pcloud.common.utils.zip.CompressUtils;
import org.jbarcode.JBarcode;
import org.jbarcode.encode.Code128Encoder;
import org.jbarcode.paint.BaseLineTextPainter;
......@@ -23,7 +30,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
......@@ -38,6 +44,8 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
import javax.imageio.ImageIO;
/**
* @author lily
* @date 2018/12/4 16:37
......@@ -66,12 +74,13 @@ public class CopyrightTools {
return shortBuffer.toString().toLowerCase();
}
public static void main(String[] args) {
public static void main(String[] args) {
long time = System.currentTimeMillis();
System.out.println(createShortUuidByCount(100000));
long time1 = System.currentTimeMillis();
System.out.println(time1-time);
System.out.println(time1 - time);
}
/**
* 生成count位非重复的数
*
......@@ -108,6 +117,13 @@ public class CopyrightTools {
}
}
/**
* 生成条形码
* @param bookAuthCodes
* @param fileName
* @param excelUrl
* @return
*/
public static String generateBar4Zip(List<BookAuthCode> bookAuthCodes, String fileName, String excelUrl) {
fileName = FileUtils.formatName(fileName);
String tempZipName = fileName + "_" + LocalDateUtils.getYmdhmss();
......@@ -147,6 +163,66 @@ public class CopyrightTools {
return uploadResultInfo == null ? null : uploadResultInfo.getUrl();
}
/**
* 生成二维码
* @param bookAuthCodes
* @param fileName
* @param excelUrl
* @return
*/
public static String generateQrcode4Zip(List<BookAuthCode> bookAuthCodes, String fileName, String excelUrl) {
fileName = FileUtils.formatName(fileName);
String tempZipName = fileName + "_" + LocalDateUtils.getYmdhmss();
String zipFilePath = ZIP_FILE_PATH + tempZipName + ".zip";
String fileFolderPath = FILE_LOCAL_PATH + tempZipName;
FileUtils.isDir(fileFolderPath);
UploadResultInfo uploadResultInfo;
try {
for (BookAuthCode bookAuthCode : bookAuthCodes) {
LOGGER.info("【二维码】generateQrcode4Zip,<START>.[url]=" + bookAuthCode);
Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(EncodeHintType.MARGIN, 0); // 设置白边
try {
// 生成矩阵
BitMatrix bitMatrix = new MultiFormatWriter().encode(bookAuthCode.getFullCode(), BarcodeFormat.QR_CODE, 55,
55, hints);
int width = bitMatrix.getWidth();
int height = bitMatrix.getHeight();
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for(int x=0;x<width;x++){
for(int y=0;y<height;y++){
bufferedImage.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF);
}
}
// paintQrcodeText(bufferedImage, bookAuthCode.getFullCode());
File file = new File(fileFolderPath + "/" + bookAuthCode.getFullCode() + ".png");
ImageIO.write(bufferedImage, ImageTypeEnum.PNG.value, file);
} catch (Exception e) {
LOGGER.error("【二维码】创建二维码失败,<ERROR>:" + e.getMessage(), e);
throw new FileException(FileException.FILE_UPLOAD_FAILURE, "创建二维码失败");
}
}
String downloadLocalPath = fileFolderPath + "/" + fileName + ".xls";
FileUtils.downloadFileFromUrl(excelUrl, downloadLocalPath);
// 检查压缩包临时文件夹是否存在,不存在就创建
FileUtils.isDir(ZIP_FILE_PATH);
CompressUtils.zip(fileFolderPath, zipFilePath);
// 上传文件到服务器中
uploadResultInfo = OssUtils.uploadLocalFile4CustomName(zipFilePath, fileName);
} catch (Exception e) {
LOGGER.error("【压缩】压缩失败,<ERROR>:" + e.getMessage(), e);
throw new FileException(FileException.ZIP_ERROR, "压缩失败!");
} finally {
// 删除产生的文件
FileUtils.deleteDirectory(fileFolderPath);
FileUtils.deleteFile(zipFilePath);
}
return uploadResultInfo == null ? null : uploadResultInfo.getUrl();
}
public static String uploadImage(BufferedImage image) throws BizException {
UploadResultInfo uploadResultInfo = null;
......@@ -207,6 +283,27 @@ public class CopyrightTools {
// g2d.drawString(text, center, barCodeImage.getHeight() - (height / 10) - 2);
// }
public static void paintQrcodeText(BufferedImage barCodeImage, String text) {
//绘图
Graphics g2d = barCodeImage.getGraphics();
//创建字体
Font font = new Font("console", Font.PLAIN, 5);
g2d.setFont(font);
FontMetrics fm = g2d.getFontMetrics();
int height = fm.getHeight();
// int center = (barCodeImage.getWidth() - fm.stringWidth(text)) / 2;
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, barCodeImage.getWidth(), barCodeImage.getHeight() / 20);
g2d.fillRect(0, barCodeImage.getHeight() - (height * 9 / 10), barCodeImage.getWidth(), (height * 9 / 10));
g2d.setColor(Color.BLACK);
//g2d.drawString(text, center, barCodeImage.getHeight() - (height / 10) - 2);
int start = 17;
int length = (barCodeImage.getWidth() - 2 * start) / text.length();
for (int i = 0; i < text.length(); i++) {
g2d.drawString(text.substring(i, i + 1), start + i * length, barCodeImage.getHeight() - (height / 10) - 2);
}
}
public static void paintText(BufferedImage barCodeImage, String text) {
//绘图
Graphics g2d = barCodeImage.getGraphics();
......
......@@ -122,7 +122,7 @@
from_type fromType,
from_id fromId,
wechat_user_id wechatUserId,
max(create_time) createTime
create_time createTime
FROM
advertising_click_record
WHERE
......@@ -132,9 +132,6 @@
<if test="statisMonth != null">
AND create_month = #{statisMonth}
</if>
AND wechat_user_id IS NOT NULL
GROUP BY
wechat_user_id
ORDER BY
createTime DESC
</select>
......
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