Commit aa80967a by songyinghui

feat: 素材周报数据来源

parent 1c63a19d
...@@ -67,16 +67,6 @@ public class MaterialReportContext { ...@@ -67,16 +67,6 @@ public class MaterialReportContext {
private String mainStoreId; private String mainStoreId;
/** /**
* 使用素材数量
*/
private Integer useMaterialNum;
/**
* 转化金额
*/
private String convertAmount;
/**
* 企业factoryCode * 企业factoryCode
*/ */
private String factoryCode; private String factoryCode;
...@@ -153,7 +143,6 @@ public class MaterialReportContext { ...@@ -153,7 +143,6 @@ public class MaterialReportContext {
public String extendParams(String storeId) { public String extendParams(String storeId) {
JSONObject params = new JSONObject(); JSONObject params = new JSONObject();
// params.put("clerkId", this.clerkId);
// 此处页面链接 最长128个字节 // 此处页面链接 最长128个字节
params.put("s", storeId); params.put("s", storeId);
params.put("t", this.reportType); params.put("t", this.reportType);
......
package com.gic.haoban.manage.service.service.content.adaptor;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gic.haoban.manage.api.enums.content.MaterialReportType;
import com.gic.haoban.manage.service.util.DataTargetHttpUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* @Author MUSI
* @Date 2023/4/5 3:04 PM
* @Description
* @Version 素材数据
**/
@Slf4j
@Component
public class MaterialDataAdaptor {
/**
* 导购/店长 周报
*/
private static final String CLERK_WEEK_DATA = "data_cms_clerk_week_report_list";
/**
* 导购/店长 月报
*/
private static final String CLERK_MONTH_DATA = "data_cms_clerk_month_report_list";
/**
* 区经 月报
*/
private static final String AREA_WEEK_DATA = "data_cms_store_week_report_total";
/**
* 区经 月报
*/
private static final String AREA_MONTH_DATA = "data_cms_store_month_report_total";
@Data
@AllArgsConstructor
public static class MaterialDataResult {
private String firstValue;
private String secondValue;
public static MaterialDataResult buildEmpty() {
return new MaterialDataResult("0", "0");
}
}
/**
* 查询导购/店长的数据
* @param enterpriseId
* @param clerkId
* @param storeId
* @param reportType
* @return
*/
public MaterialDataResult queryClerkReportData(String enterpriseId, String clerkId, String storeId, Integer reportType) {
int bizDate;
String apolloKey = CLERK_WEEK_DATA;
if (MaterialReportType.WEEK.getCode().equals(reportType)) {
// 周报
bizDate = DateUtil.weekOfYear(DateUtil.lastWeek());
} else {
bizDate = DateUtil.month(DateUtil.lastMonth());
apolloKey = CLERK_MONTH_DATA;
}
Map<String, Object> params = new HashMap<>();
Map<String, Object> inlineParams = new HashMap<>();
params.put("inFields", inlineParams);
if (org.apache.commons.lang3.StringUtils.isNotBlank(clerkId)) {
inlineParams.put("clerkId", clerkId);
}
inlineParams.put("enterprsieId", enterpriseId);
inlineParams.put("bizDate", bizDate);
inlineParams.put("storeId", storeId);
Map<String, Object> result = this.doHttp(JSON.toJSONString(params), apolloKey);
if (result.get("data") == null) {
return null;
}
List<JSONObject> jsonObjects = JSON.parseArray(JSON.toJSONString(result.get("data")), JSONObject.class);
JSONObject jsonObject = jsonObjects.get(0);
int useMatlNum = jsonObject.getIntValue("useMatlNum");
BigDecimal convSalesAmt = Optional.ofNullable(jsonObject.getBigDecimal("convSalesAmt")).orElse(BigDecimal.ZERO);
String amountUnit = "";
if (convSalesAmt.compareTo(new BigDecimal(10000)) >= 0) {
convSalesAmt = convSalesAmt.divide(BigDecimal.valueOf(10000), 2, RoundingMode.HALF_UP);
amountUnit = "万";
}
DecimalFormat decimalFormat = new DecimalFormat("#,###,###.##");
String formatAmount = decimalFormat.format(convSalesAmt);
String numFormat = decimalFormat.format(useMatlNum);
return new MaterialDataResult(numFormat, (formatAmount + amountUnit));
}
/**
* 区经
* @param enterpriseId
* @param clerkId
* @param storeIds
* @param reportType
* @return
*/
public MaterialDataResult queryAreaReportData(String enterpriseId, String clerkId, List<String> storeIds, Integer reportType) {
int bizDate = 0;
String apolloKey = AREA_WEEK_DATA;
if (MaterialReportType.WEEK.getCode().equals(reportType)) {
// 周报
bizDate = DateUtil.weekOfYear(DateUtil.lastWeek());
} else {
bizDate = DateUtil.month(DateUtil.lastMonth());
apolloKey = AREA_MONTH_DATA;
}
Map<String, Object> params = new HashMap<>();
Map<String, Object> inlineParams = new HashMap<>();
params.put("inFields", inlineParams);
if (org.apache.commons.lang3.StringUtils.isNotBlank(clerkId)) {
inlineParams.put("clerkId", clerkId);
}
inlineParams.put("enterpriseId", enterpriseId);
inlineParams.put("bizDate", bizDate);
if (CollectionUtils.isNotEmpty(storeIds)) {
inlineParams.put("storeId", StringUtils.join(storeIds, ","));
}
Map<String, Object> result = this.doHttp(JSON.toJSONString(params), apolloKey);
if (result.get("data") == null) {
return null;
}
List<JSONObject> jsonObjects = JSON.parseArray(JSON.toJSONString(result.get("data")), JSONObject.class);
if (CollectionUtils.isEmpty(jsonObjects)) {
return null;
}
JSONObject jsonObject = jsonObjects.get(0);
int dayAvgUseMatlNum = jsonObject.getIntValue("dayAvgUseMatlNum");
BigDecimal convSalesAmt = Optional.ofNullable(jsonObject.getBigDecimal("convSalesAmt")).orElse(BigDecimal.ZERO);
String amountUnit = "";
if (convSalesAmt.compareTo(new BigDecimal(10000)) >= 0) {
convSalesAmt = convSalesAmt.divide(BigDecimal.valueOf(10000), 2, RoundingMode.HALF_UP);
amountUnit = "万";
}
DecimalFormat decimalFormat = new DecimalFormat("#,###,###.##");
String formatAmount = decimalFormat.format(convSalesAmt);
String numFormat = decimalFormat.format(dayAvgUseMatlNum);
return new MaterialDataResult(numFormat, (formatAmount + amountUnit));
}
private Map<String, Object> doHttp(String jsonParam, String apolloKey) {
try {
log.info("调用接口 apolloKey:{}, 参数:{}", apolloKey, jsonParam);
Map<String, Object> result = DataTargetHttpUtils.http(jsonParam, apolloKey);
if (result == null) {
return Collections.emptyMap();
}
return result;
} catch (Exception ex) {
log.info("请求接口失败 apolloKey:{}", apolloKey, ex);
}
return Collections.emptyMap();
}
}
...@@ -5,6 +5,7 @@ import com.gic.haoban.manage.api.dto.StaffClerkRelationDTO; ...@@ -5,6 +5,7 @@ import com.gic.haoban.manage.api.dto.StaffClerkRelationDTO;
import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO; import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO;
import com.gic.haoban.manage.api.enums.NoticeMessageTypeEnum; import com.gic.haoban.manage.api.enums.NoticeMessageTypeEnum;
import com.gic.haoban.manage.api.enums.content.MaterialReportType; import com.gic.haoban.manage.api.enums.content.MaterialReportType;
import com.gic.haoban.manage.api.service.StaffApiService;
import com.gic.haoban.manage.api.util.notify.NoticeMessageUtil; import com.gic.haoban.manage.api.util.notify.NoticeMessageUtil;
import com.gic.haoban.manage.service.config.Config; import com.gic.haoban.manage.service.config.Config;
import com.gic.haoban.manage.service.entity.TabHaobanClerkMainStoreRelated; import com.gic.haoban.manage.service.entity.TabHaobanClerkMainStoreRelated;
...@@ -39,16 +40,12 @@ public class MaterialReportBuilder { ...@@ -39,16 +40,12 @@ public class MaterialReportBuilder {
@Autowired @Autowired
private ClerkMainStoreRelatedService clerkMainStoreRelatedService; private ClerkMainStoreRelatedService clerkMainStoreRelatedService;
@Autowired @Autowired
private MaterialDataAdaptor materialDataAdaptor;
@Autowired
private Config config; private Config config;
@Autowired
private StaffApiService staffApiService;
/**
* 周报模板
*/
private static final String week_template_report = "template/week_bkg.png";
/**
* 月报模板
*/
private static final String month_template_report = "template/month_bkg.png";
/** /**
* 柱状成员绑定的导购信息 * 柱状成员绑定的导购信息
...@@ -109,26 +106,38 @@ public class MaterialReportBuilder { ...@@ -109,26 +106,38 @@ public class MaterialReportBuilder {
* @param context * @param context
*/ */
public void buildMaterialReportData(MaterialReportContext context) { public void buildMaterialReportData(MaterialReportContext context) {
// 获取该导购 在门店 的周报/月报数据 // 获取该导购/店长/区经 的周报/月报数据
String clerkId = context.getClerkId(); String clerkId = context.getClerkId();
String enterpriseId = context.getEnterpriseId();
MaterialDataAdaptor.MaterialDataResult materialDataResult;
if (StringUtils.isBlank(context.getMainStoreId())) { if (StringUtils.isBlank(context.getMainStoreId())) {
// 区经 // 区经
List<String> storeIds = this.queryClerkStoreIds(clerkId, context.getStaffInfo().getWxEnterpriseId());
materialDataResult = materialDataAdaptor.queryAreaReportData(enterpriseId, clerkId, storeIds, context.getReportType());
}else { }else {
String mainStoreId = context.getMainStoreId(); String mainStoreId = context.getMainStoreId();
materialDataResult = materialDataAdaptor.queryClerkReportData(enterpriseId, clerkId, mainStoreId, context.getReportType());
}
log.info("获取成员海报数据 clerkId:{}, data: {}", clerkId, JSON.toJSONString(materialDataResult));
if (materialDataResult == null) {
materialDataResult = MaterialDataAdaptor.MaterialDataResult.buildEmpty();
} }
String templatePath = ""; DrawImageUtils.DrawBkgImg templatePath = null;
if (MaterialReportType.WEEK.getCode().equals(context.getReportType())) { if (MaterialReportType.WEEK.getCode().equals(context.getReportType())) {
context.setUseMaterialNum(103); if (StringUtils.isNotBlank(context.getMainStoreId())) {
context.setConvertAmount("3.1万"); templatePath = DrawImageUtils.DrawBkgImg.AREA_WEEK_BKG;
templatePath = week_template_report; }else {
templatePath = DrawImageUtils.DrawBkgImg.CLERK_WEEK_BKG;
}
}else { }else {
context.setUseMaterialNum(1043); if (StringUtils.isNotBlank(context.getMainStoreId())) {
context.setConvertAmount("12.3万"); templatePath = DrawImageUtils.DrawBkgImg.AREA_MONTH_BKG;
templatePath = month_template_report; }else {
templatePath = DrawImageUtils.DrawBkgImg.CLERK_MONTH_BKG;
}
} }
// 生成图片地址 // 生成图片地址
String url = DrawImageUtils.drawImage(context.getFactoryCode(), context.getUseMaterialNum() + "", context.getConvertAmount(), templatePath); String url = DrawImageUtils.drawImage(context.getFactoryCode(), materialDataResult.getFirstValue(), materialDataResult.getSecondValue(), templatePath);
context.setMaterialReportUrl(url); context.setMaterialReportUrl(url);
} }
...@@ -158,4 +167,27 @@ public class MaterialReportBuilder { ...@@ -158,4 +167,27 @@ public class MaterialReportBuilder {
newsSendMessage.setArticleMessages(Collections.singletonList(articleInfo)); newsSendMessage.setArticleMessages(Collections.singletonList(articleInfo));
return newsSendMessage; return newsSendMessage;
} }
/**
* 查询区经角色下管辖的门店权限
*
* @param clerkId
* @param wxEnterpriseId
* @return
*/
public List<String> queryClerkStoreIds(String clerkId, String wxEnterpriseId) {
List<String> storeIds = staffApiService.getHaoBanStoreIdsRolesByClerkId(clerkId, wxEnterpriseId);
if (CollectionUtils.isEmpty(storeIds)) {
log.info("根据区经id查询管辖的门店为空 {} {}", clerkId, wxEnterpriseId);
return Collections.singletonList("-100");
}
if (storeIds.size() == 1 && StringUtils.equals(storeIds.get(0), "-1")) {
// 全部门店权限
log.info("区经有全部门店权限 {}", clerkId);
return Collections.emptyList();
}
return storeIds;
}
} }
...@@ -89,7 +89,7 @@ public class MaterialReportServiceImpl implements MaterialReportService { ...@@ -89,7 +89,7 @@ public class MaterialReportServiceImpl implements MaterialReportService {
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(staffInfo.getWxEnterpriseId()); WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(staffInfo.getWxEnterpriseId());
QywxNewsSendMessageDTO newsSendMessageDTO = materialReportBuilder.buildQywxNewsMessage(context, qwDTO); QywxNewsSendMessageDTO newsSendMessageDTO = materialReportBuilder.buildQywxNewsMessage(context, qwDTO);
if (newsSendMessageDTO == null) { if (newsSendMessageDTO == null) {
log.info("构建企业应用消息异常 {}"); log.info("构建企业应用消息异常 clerkId:{}m staffId: {}", context.getClerkId(), context.getStaffId());
return; return;
} }
log.info("发送企业图文消息参数{}", JSON.toJSONString(newsSendMessageDTO)); log.info("发送企业图文消息参数{}", JSON.toJSONString(newsSendMessageDTO));
......
package com.gic.haoban.manage.service.util;
import com.alibaba.fastjson.JSONObject;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import com.gic.api.base.commons.Page;
import com.gic.commons.util.HttpClient;
import com.gic.commons.web.qo.PageQo;
import com.gic.commons.webapi.reponse.RestResponse;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 目标配置调用数据组http接口工具类
* @Author guojx
* @Date 2023/1/17 9:51
*/
public class DataTargetHttpUtils {
private static final Logger LOGGER = LogManager.getLogger(DataTargetHttpUtils.class);
public static JSONObject getCommonParam(String enterpriseId, String storeId, String startTime, String endTime) {
JSONObject resJson = new JSONObject();
JSONObject jsonObject = new JSONObject();
jsonObject.put("enterpriseId", enterpriseId);
jsonObject.put("storeId", storeId);
jsonObject.put("startTime", startTime);
jsonObject.put("endTime", endTime);
return resJson;
}
public static boolean isSuccess(Map<String, Object> res) {
return res.get("errorCode").toString().equals("1");
}
public static RestResponse responsePageData(Map<String, Object> res) {
if (res.get("errorCode").toString().equals("1")) {
//成功
Page page = new Page();
List<JSONObject> dataList = (List<JSONObject>) res.get("data");
JSONObject pageJson = (JSONObject) res.get("page");
page.setPageSize(pageJson.getIntValue("pageSize"));
page.setTotalCount(pageJson.getIntValue("totalCount"));
page.setCurrentPage(pageJson.getIntValue("currentPage"));
page.setTotalPage(pageJson.getIntValue("totalPage"));
page.setResult(dataList);
return RestResponse.successResult(page);
}
return RestResponse.failure((String) res.get("errorCode"), (String) res.get("errorInfo"));
}
public static RestResponse response(Map<String, Object> res) {
if (res.get("errorCode").toString().equals("1")) {
//成功
List<JSONObject> dataList = (List<JSONObject>) res.get("data");
return RestResponse.successResult(dataList);
}
return RestResponse.failure((String) res.get("errorCode"), (String) res.get("errorInfo"));
}
public static RestResponse responseOfOne(Map<String, Object> res, JSONObject defaultJson) {
if (res.get("errorCode").toString().equals("1")) {
//成功
List<JSONObject> dataList = (List<JSONObject>) res.get("data");
if (CollectionUtils.isNotEmpty(dataList)) {
return RestResponse.successResult(dataList.get(0));
}
if (defaultJson != null) {
return RestResponse.successResult(defaultJson);
}
return RestResponse.successResult(null);
}
return RestResponse.failure((String) res.get("errorCode"), (String) res.get("errorInfo"));
}
public static List<JSONObject> getDataList(Map<String, Object> res) {
if (res.get("errorCode").toString().equals("1")) {
//成功
List<JSONObject> dataList = (List<JSONObject>) res.get("data");
return dataList;
}
return Collections.EMPTY_LIST;
}
public static JSONObject getData(Map<String, Object> res) {
if (res.get("errorCode").toString().equals("1")) {
//成功
List<JSONObject> dataList = (List<JSONObject>) res.get("data");
if (CollectionUtils.isNotEmpty(dataList)) {
return dataList.get(0);
}
return null;
}
return null;
}
public static Map<String, Object> http(String jsonParam, String apolloKey) {
LOGGER.info("接口的key:{}", apolloKey);
Config config = ConfigService.getConfig("COMMON.data-api-config");
String value = config.getProperty(apolloKey, "");
if (StringUtils.isBlank(value)) {
throw new RuntimeException("数据接口配置有误!");
}
LOGGER.info("{}:Apollo查询的配置信息:{}", apolloKey, value);
String[] split = value.split("\\+\\+\\+\\+");
String url = split[0];
String token = split[1];
Map<String, String> head = new HashMap<>();
head.put("Content-Type", "application/json");
head.put("API-TOKEN", token);
Map<String, Object> res = HttpClient.getWinxinResByJson(url, jsonParam, head);
if (!isSuccess(res)) {
throw new RuntimeException((String) res.get("errorInfo"));
}
LOGGER.info("调用接口{},返回结果:{}", url, res);
return res;
}
public static JSONObject getParam(PageQo pageQo, JSONObject objParam) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("pageNo", pageQo.getPageNum());
jsonObject.put("pageSize", pageQo.getPageSize());
if (objParam != null) {
if (objParam.containsKey("storeId")) {
Object storeId = objParam.get("storeId");
if (storeId == null || StringUtils.isBlank(storeId.toString())) {
objParam.remove("storeId");
}
}
}
jsonObject.put("inFields", objParam);
return jsonObject;
}
public static JSONObject getParamNoPage(JSONObject objParam) {
JSONObject jsonObject = new JSONObject();
if (objParam != null) {
if (objParam.containsKey("storeId")) {
Object storeId = objParam.get("storeId");
if (storeId == null || StringUtils.isBlank(storeId.toString())) {
objParam.remove("storeId");
}
}
}
jsonObject.put("inFields", objParam);
return jsonObject;
}
/**
* 保留2位小数 .元转万元
*
* @param a
* @return by wws
*/
public static Double transferTenThousand(Double a) {
BigDecimal bd = new BigDecimal(a / 10000);
bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
return bd.doubleValue();
}
public static Double transferTenThousand(String a) {
BigDecimal bd = new BigDecimal(a);
bd = bd.divide(new BigDecimal("10000")).setScale(2, BigDecimal.ROUND_HALF_UP);
return bd.doubleValue();
}
public static Double transferTenThousand(Object a) {
if (a == null) {
return 0.00;
}
BigDecimal bd = new BigDecimal(a.toString());
bd = bd.divide(new BigDecimal("10000")).setScale(2, BigDecimal.ROUND_HALF_UP);
return bd.doubleValue();
}
public static Double parseDouble(Object a) {
if (a == null) {
return 0.00;
}
return Double.parseDouble(a.toString());
}
public static Double transferTenThousandNoDivide(Double a) {
if (a == null) {
return 0.00;
}
BigDecimal bd = new BigDecimal(a.toString());
bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
return bd.doubleValue();
}
public static String formatToSepara(Double data) {
DecimalFormat df = new DecimalFormat("#,###.00");
return df.format(data);
}
public static String formatToSepara(Integer data) {
DecimalFormat df = new DecimalFormat("#,###");
return df.format(data);
}
public static String getContrast(String data) {
if ("--".equals(data)) {
return data;
}
Double dataDouble = Double.parseDouble(data);
if (dataDouble > 0) {
return "+" + data + "%";
} else {
return data + "%";
}
}
public static String getJsonOrDefault(Object a, Object object) {
if (a == null) {
return object.toString();
}
return a.toString();
}
public static Object getObjectOrDefault(Object a, Object object) {
if (a == null) {
return object;
}
return a;
}
public static String getContrastOrDefault(Object a, Object object) {
return getContrast(getJsonOrDefault(a, object));
}
public static String getRateOrDefault(Object a, Object object) {
String data = getJsonOrDefault(a, object);
if ("--".equals(data)) {
return data;
}
return data + "%";
}
public static Page getPage(Map<String, Object> detailRes) {
Page page = new Page();
List<JSONObject> dataList = (List<JSONObject>) detailRes.get("data");
JSONObject pageJson = (JSONObject) detailRes.get("page");
page.setPageSize(pageJson.getIntValue("pageSize"));
page.setTotalCount(pageJson.getIntValue("totalCount"));
page.setCurrentPage(pageJson.getIntValue("currentPage"));
page.setTotalPage(pageJson.getIntValue("totalPage"));
page.setResult(dataList);
return page;
}
}
...@@ -5,6 +5,8 @@ import com.gic.thirdparty.cloudfile.CloudFileUtil; ...@@ -5,6 +5,8 @@ import com.gic.thirdparty.cloudfile.CloudFileUtil;
import com.gic.thirdparty.cloudfile.enums.CloudFileBusinessOptEnum; import com.gic.thirdparty.cloudfile.enums.CloudFileBusinessOptEnum;
import com.gic.thirdparty.cloudfile.enums.CloudFileTypeEnum; import com.gic.thirdparty.cloudfile.enums.CloudFileTypeEnum;
import com.gic.thirdparty.cloudfile.pojo.CloudFileInfo; import com.gic.thirdparty.cloudfile.pojo.CloudFileInfo;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
...@@ -22,19 +24,51 @@ import java.util.Random; ...@@ -22,19 +24,51 @@ import java.util.Random;
**/ **/
@Slf4j @Slf4j
public class DrawImageUtils { public class DrawImageUtils {
@Getter
@AllArgsConstructor
public enum DrawBkgImg {
AREA_WEEK_BKG("template/area_week_bkg.png", "区经周报背景图", 352, 416, 320),
AREA_MONTH_BKG("template/area_month_bkg.png", "区经月报背景图", 352, 416, 320),
CLERK_WEEK_BKG("template/week_bkg.png", "导购/店长周报背景图", 260, 320, 353),
CLERK_MONTH_BKG("template/month_bkg.png", "导购/店长月报背景图", 260, 320, 353),
;
private String path;
private String desc;
/**
* 第一个位置宽度
*/
private int numWidth;
/**
* 金额开始位置的左上顶点坐标
*/
private int amountStart;
/**
* 金额宽度
*/
private int amountWidth;
}
/** /**
* 绘画素材周报/月报 海报图 * 绘画素材周报/月报 海报图
* *
* @param factoryCode * @param factoryCode
* @param materialNum * @param firstValue
* @param amountText * @param amountText
*/ */
public static String drawImage(String factoryCode, String materialNum, String amountText, String templatePath) { public static String drawImage(String factoryCode, String firstValue, String amountText, DrawBkgImg drawBkgImg) {
if (drawBkgImg == null) {
log.info("合成图片的背景模板为空 factoryCode:{}", factoryCode);
return null;
}
try { try {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
InputStream inputStream = DrawImageUtils.class.getClassLoader().getResourceAsStream(templatePath); InputStream inputStream = DrawImageUtils.class.getClassLoader().getResourceAsStream(drawBkgImg.getPath());
if (inputStream == null) { if (inputStream == null) {
log.info("模板文件不存在 path:{}", templatePath); log.info("模板文件不存在 path:{}", drawBkgImg.getPath());
return null; return null;
} }
...@@ -45,9 +79,9 @@ public class DrawImageUtils { ...@@ -45,9 +79,9 @@ public class DrawImageUtils {
Font font = new Font("微软雅黑", Font.BOLD, 56); Font font = new Font("微软雅黑", Font.BOLD, 56);
pen.setFont(font); pen.setFont(font);
FontMetrics metrics = pen.getFontMetrics(font); FontMetrics metrics = pen.getFontMetrics(font);
int startX = 40 + (260 - metrics.stringWidth(materialNum)) / 2; int startX = 40 + (drawBkgImg.numWidth - metrics.stringWidth(firstValue)) / 2;
pen.drawString(materialNum, startX, 250); pen.drawString(firstValue, startX, 250);
int amountX = 320 + (353 - metrics.stringWidth(amountText)) / 2; int amountX = drawBkgImg.amountStart + (drawBkgImg.amountWidth - metrics.stringWidth(amountText)) / 2;
pen.drawString(amountText, amountX, 250); pen.drawString(amountText, amountX, 250);
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
ImageIO.write(image, "png", bos); ImageIO.write(image, "png", bos);
...@@ -68,9 +102,12 @@ public class DrawImageUtils { ...@@ -68,9 +102,12 @@ public class DrawImageUtils {
public static void main(String[] args) { public static void main(String[] args) {
System.setProperty("gic.module.name", "haoban-manage3-service"); System.setProperty("gic.module.name", "haoban-manage3-service");
Random random = new Random(); Random random = new Random();
for (int i = 0; i < 50; i++) { String url = DrawImageUtils.drawImage("jhdm", Math.abs(random.nextInt(1000)) + "",
String url = DrawImageUtils.drawImage("jhdm", Math.abs(random.nextInt(1000)) + "", Math.abs(random.nextInt(1000)) + "万", "template/week_bkg.png"); Math.abs(random.nextInt(1000)) + "万", DrawBkgImg.AREA_MONTH_BKG);
System.out.println(url); System.out.println(url);
}
String temp = DrawImageUtils.drawImage("jhdm", Math.abs(random.nextInt(1000)) + "",
Math.abs(random.nextInt(1000)) + "万", DrawBkgImg.CLERK_MONTH_BKG);
System.out.println(temp);
} }
} }
...@@ -8,6 +8,7 @@ import com.gic.haoban.manage.api.util.notify.NoticeMessageUtil; ...@@ -8,6 +8,7 @@ import com.gic.haoban.manage.api.util.notify.NoticeMessageUtil;
import com.gic.haoban.manage.service.dao.mapper.content.TabHaobanInteractRecordMapper; import com.gic.haoban.manage.service.dao.mapper.content.TabHaobanInteractRecordMapper;
import com.gic.haoban.manage.service.entity.content.TabHaobanInteractRecord; import com.gic.haoban.manage.service.entity.content.TabHaobanInteractRecord;
import com.gic.haoban.manage.service.service.content.MaterialReportService; import com.gic.haoban.manage.service.service.content.MaterialReportService;
import com.gic.haoban.manage.service.service.content.adaptor.MaterialDataAdaptor;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -15,6 +16,7 @@ import org.springframework.data.domain.PageRequest; ...@@ -15,6 +16,7 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -38,10 +40,14 @@ public class MaterialReportServiceTest { ...@@ -38,10 +40,14 @@ public class MaterialReportServiceTest {
private QywxGroupMsgTaskApiService qywxGroupMsgTaskApiService; private QywxGroupMsgTaskApiService qywxGroupMsgTaskApiService;
@Autowired @Autowired
private TabHaobanInteractRecordMapper interactRecordMapper; private TabHaobanInteractRecordMapper interactRecordMapper;
@Autowired
private MaterialDataAdaptor materialDataAdaptor;
String eid = "ff8080815dacd3a2015dacd3ef5c0000"; String eid = "ff8080815dacd3a2015dacd3ef5c0000";
String wxEid = "ca66a01b79474c40b3e7c7f93daf1a3b"; String wxEid = "ca66a01b79474c40b3e7c7f93daf1a3b";
String staffId = "e608b51b267e4943b87e222a343b4f25"; String staffId = "e608b51b267e4943b87e222a343b4f25";
String storeId = "ff8080816e216c04016e34294282004a";
String clerkId = "300b60c7f8874ca2b9cc696ad6b6a480";
@Test @Test
public void handlerMaterialWeekReportTest() { public void handlerMaterialWeekReportTest() {
...@@ -92,4 +98,10 @@ public class MaterialReportServiceTest { ...@@ -92,4 +98,10 @@ public class MaterialReportServiceTest {
System.out.println(s1); System.out.println(s1);
System.out.println(s1.length()); System.out.println(s1.length());
} }
@Test
public void queryData(){
MaterialDataAdaptor.MaterialDataResult materialDataResult = materialDataAdaptor.queryAreaReportData(eid, clerkId, Collections.singletonList(storeId), MaterialReportType.MONTH.getCode());
System.out.println(JSON.toJSONString(materialDataResult));
}
} }
...@@ -252,7 +252,7 @@ public class MaterialDataAdaptor { ...@@ -252,7 +252,7 @@ public class MaterialDataAdaptor {
if (StringUtils.isNotBlank(clerkId)) { if (StringUtils.isNotBlank(clerkId)) {
inlineParams.put("clerkId", clerkId); inlineParams.put("clerkId", clerkId);
} }
inlineParams.put("enterprsieId", enterpriseId); inlineParams.put("enterpriseId", enterpriseId);
inlineParams.put("bizDate", bizDate); inlineParams.put("bizDate", bizDate);
if (CollectionUtil.isNotEmpty(storeIds)) { if (CollectionUtil.isNotEmpty(storeIds)) {
inlineParams.put("storeId", StringUtils.join(storeIds, ",")); inlineParams.put("storeId", StringUtils.join(storeIds, ","));
...@@ -318,7 +318,7 @@ public class MaterialDataAdaptor { ...@@ -318,7 +318,7 @@ public class MaterialDataAdaptor {
if (StringUtils.isNotBlank(clerkId)) { if (StringUtils.isNotBlank(clerkId)) {
inlineParams.put("clerkId", clerkId); inlineParams.put("clerkId", clerkId);
} }
inlineParams.put("enterprsieId", enterpriseId); inlineParams.put("enterpriseId", enterpriseId);
inlineParams.put("bizDate", bizDate); inlineParams.put("bizDate", bizDate);
if (CollectionUtil.isNotEmpty(storeIds)) { if (CollectionUtil.isNotEmpty(storeIds)) {
inlineParams.put("storeId", StringUtils.join(storeIds, ",")); inlineParams.put("storeId", StringUtils.join(storeIds, ","));
...@@ -376,7 +376,7 @@ public class MaterialDataAdaptor { ...@@ -376,7 +376,7 @@ public class MaterialDataAdaptor {
if (StringUtils.isNotBlank(clerkId)) { if (StringUtils.isNotBlank(clerkId)) {
inlineParams.put("clerkId", clerkId); inlineParams.put("clerkId", clerkId);
} }
inlineParams.put("enterprsieId", enterpriseId); inlineParams.put("enterpriseId", enterpriseId);
inlineParams.put("bizDate", bizDate); inlineParams.put("bizDate", bizDate);
if (CollectionUtil.isNotEmpty(storeIds)) { if (CollectionUtil.isNotEmpty(storeIds)) {
inlineParams.put("storeId", StringUtils.join(storeIds, ",")); inlineParams.put("storeId", StringUtils.join(storeIds, ","));
...@@ -423,7 +423,7 @@ public class MaterialDataAdaptor { ...@@ -423,7 +423,7 @@ public class MaterialDataAdaptor {
if (StringUtils.isNotBlank(clerkId)) { if (StringUtils.isNotBlank(clerkId)) {
inlineParams.put("clerkId", clerkId); inlineParams.put("clerkId", clerkId);
} }
inlineParams.put("enterprsieId", enterpriseId); inlineParams.put("enterpriseId", enterpriseId);
inlineParams.put("customerId", StringUtils.join(memberIds, ",")); inlineParams.put("customerId", StringUtils.join(memberIds, ","));
Map<String, Object> result = this.doHttp(JSON.toJSONString(params), MEMBER_RECENTLY_30_DAY_VISIT); Map<String, Object> result = this.doHttp(JSON.toJSONString(params), MEMBER_RECENTLY_30_DAY_VISIT);
if (result.get("data") == null) { if (result.get("data") == null) {
......
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