Commit 996fbd1f by songyinghui

feat: 素材周报月报

parent 8977734c
package com.gic.haoban.manage.api.dto.content.report;
import java.io.Serializable;
/**
* @Author MUSI
* @Date 2023/3/25 7:18 PM
* @Description
* @Version
**/
public class MaterialReportDTO implements Serializable {
private static final long serialVersionUID = -6373558370216756429L;
/**
* 企业id
*/
private String enterpriseId;
/**
* 成员id
*/
private String staffId;
/**
* 周报类型
*/
private Integer reportType;
public String getEnterpriseId() {
return enterpriseId;
}
public void setEnterpriseId(String enterpriseId) {
this.enterpriseId = enterpriseId;
}
public String getStaffId() {
return staffId;
}
public void setStaffId(String staffId) {
this.staffId = staffId;
}
public Integer getReportType() {
return reportType;
}
public void setReportType(Integer reportType) {
this.reportType = reportType;
}
}
...@@ -59,6 +59,7 @@ public enum NoticeMessageTypeEnum { ...@@ -59,6 +59,7 @@ public enum NoticeMessageTypeEnum {
CUSTOMER_SUCCESS_ORDER_REFUND(4006, "客户成功退单通知", NoticeMessageCategoryTypeEnum.CUSTOMER.getType(), "customer_success_order_refund", "/pages/route/index?pageType=", "hbapp_user_bill_detail"), CUSTOMER_SUCCESS_ORDER_REFUND(4006, "客户成功退单通知", NoticeMessageCategoryTypeEnum.CUSTOMER.getType(), "customer_success_order_refund", "/pages/route/index?pageType=", "hbapp_user_bill_detail"),
MATERIAL_NEW_NOTIFY(6001, "素材上新通知", NoticeMessageCategoryTypeEnum.MATERIAL.getType(), "material_new_notify", "/pages/route/index?pageType=", "hbapp_material_center"), MATERIAL_NEW_NOTIFY(6001, "素材上新通知", NoticeMessageCategoryTypeEnum.MATERIAL.getType(), "material_new_notify", "/pages/route/index?pageType=", "hbapp_material_center"),
MATERIAL_WEEK_REPORT(6002, "素材周报通知", NoticeMessageCategoryTypeEnum.MATERIAL.getType(), "material_week_notify", "/pages/route/index?pageType=", "hbapp_material_report"),
; ;
/** /**
......
package com.gic.haoban.manage.api.enums.content;
/**
* @Author MUSI
* @Date 2023/3/24 10:25 PM
* @Description
* @Version
**/
public enum MaterialReportType {
WEEK(1, "周报"),
MONTH(2, "月报");
MaterialReportType(Integer code, String desc) {
this.code = code;
this.desc = desc;
}
private Integer code;
private String desc;
public Integer getCode() {
return code;
}
public String getDesc() {
return desc;
}
}
...@@ -30,6 +30,9 @@ public interface QywxGroupMsgTaskApiService { ...@@ -30,6 +30,9 @@ public interface QywxGroupMsgTaskApiService {
/** /**
* 素材周报 * 素材周报
* 0 0 10 ? * MON
* 或者 0 0 10 ? * 2
* 每周一 10点
* @param params * @param params
* @return * @return
*/ */
...@@ -37,8 +40,16 @@ public interface QywxGroupMsgTaskApiService { ...@@ -37,8 +40,16 @@ public interface QywxGroupMsgTaskApiService {
/** /**
* 素材月报 * 素材月报
* 0 0 10 1 * ?
* @param params * @param params
* @return * @return
*/ */
ServiceResponse<Void> handlerMaterialMonthReport(String params); ServiceResponse<Void> handlerMaterialMonthReport(String params);
/**
* 处理单成员素材使用周报/月报
* @param params
* @return
*/
ServiceResponse<Void> doHandlerMaterialOneStaffReportMQ(String params);
} }
...@@ -179,4 +179,11 @@ public interface StaffMapper { ...@@ -179,4 +179,11 @@ public interface StaffMapper {
@Param("expireTime")Date expireTime, @Param("expireTime")Date expireTime,
@Param("activeCode")String activeCode); @Param("activeCode")String activeCode);
/**
* 查询企业下所有成员ID
* @param enterpriseId
* @return
*/
List<String> queryStaffIdsWithEnterpriseId(@Param("enterpriseId") String enterpriseId);
} }
\ No newline at end of file
package com.gic.haoban.manage.service.pojo.bo.content.context; package com.gic.haoban.manage.service.pojo.bo.content.context;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.gic.haoban.manage.api.dto.StaffClerkRelationDTO;
import com.gic.haoban.manage.api.enums.content.MaterialReportType;
import com.gic.haoban.manage.service.entity.TabHaobanStaff;
import com.gic.haoban.manage.service.pojo.bo.NoticeMessageBO;
import lombok.Builder;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import static com.gic.haoban.manage.api.enums.NoticeMessageTypeEnum.MATERIAL_WEEK_REPORT;
/** /**
* @Author MUSI * @Author MUSI
* @Date 2023/3/24 4:08 PM * @Date 2023/3/24 4:08 PM
* @Description * @Description
* @Version * @Version 好办 周报/月报 上下文
* 好办 周报/月报 上下文
**/ **/
@Data
@Builder
public class MaterialReportContext { public class MaterialReportContext {
private static final String week_title = "素材使用周报";
private static final String month_title = "素材使用月报";
private static final String week_desc = "%s~%s的素材使用周报已生成,请查收";
private static final String month_desc = "%s~%s的素材使用月报已生成,请查收";
private String enterpriseId; private String enterpriseId;
/**
* 素材周期
*
* @see com.gic.haoban.manage.api.enums.content.MaterialReportType
*/
private Integer reportType;
/**
* 成员id
*/
private String staffId;
/**
* 成员对象
*/
private TabHaobanStaff staffInfo;
/**
* 成员(店长或导购角色)在主门店时的导购id
* 区经时就是导购id
*/
private String clerkId;
/**
* 主门店
*/
private String mainStoreId;
/**
* 使用素材数量
*/
private Integer useMaterialNum;
/**
* 转化金额
*/
private String convertAmount;
/**
* 企业factoryCode
*/
private String factoryCode;
/**
* 导购关联表
*/
private List<StaffClerkRelationDTO> staffClerkRelations;
/**
* 素材报告 图片地址
*/
private String materialReportUrl;
/**
* 构建好办小程序消息
*
* @return
*/
public List<NoticeMessageBO> buildNotifyMessageBos() {
if (CollectionUtils.isEmpty(this.staffClerkRelations)) {
return Collections.emptyList();
}
if (StringUtils.isBlank(this.mainStoreId)) {
return Collections.emptyList();
}
return this.staffClerkRelations
.stream()
.map(item -> {
NoticeMessageBO noticeMessageBO = new NoticeMessageBO();
noticeMessageBO.setCategoryType(MATERIAL_WEEK_REPORT.getCategory());
noticeMessageBO.setMessageType(MATERIAL_WEEK_REPORT.getType());
noticeMessageBO.setClerkId(StringUtils.isNotBlank(item.getClerkId()) ? item.getClerkId() : "-1");
noticeMessageBO.setStoreId(StringUtils.isNotBlank(item.getStoreId()) ? item.getStoreId() : "-1");
noticeMessageBO.setTitle(this.getMessageTitle());
noticeMessageBO.setTemplateCode(MATERIAL_WEEK_REPORT.getTemplateCode());
noticeMessageBO.setDescription(this.getMessageDesc());
noticeMessageBO.setEnterpriseId(this.enterpriseId);
noticeMessageBO.setRelationId(this.clerkId);
noticeMessageBO.setMessageContent(this.extendParams());
return noticeMessageBO;
})
.collect(Collectors.toList());
}
public String getMessageTitle() {
if (MaterialReportType.WEEK.getCode().equals(this.reportType)) {
return week_title;
}
return month_title;
}
public String getMessageDesc() {
if (MaterialReportType.WEEK.getCode().equals(this.reportType)) {
// 获取周报信息
DateTime lastWeek = DateUtil.lastWeek();
String weekBeginStr = DateUtil.beginOfWeek(lastWeek)
.toString("MM月dd日");
String weekEndStr = DateUtil.endOfWeek(lastWeek)
.toString("MM月dd日");
return String.format(week_desc, weekBeginStr, weekEndStr);
}
DateTime lastMonth = DateUtil.lastMonth();
String monthBeginStr = DateUtil.beginOfMonth(lastMonth)
.toString("MM月dd日");
String monthEndStr = DateUtil.endOfMonth(lastMonth)
.toString("MM月dd日");
return String.format(month_desc, monthBeginStr, monthEndStr);
}
public String extendParams() {
JSONObject params = new JSONObject();
params.put("clerkId", this.clerkId);
params.put("storeId", this.mainStoreId);
return params.toJSONString();
}
} }
...@@ -143,4 +143,11 @@ public interface StaffService { ...@@ -143,4 +143,11 @@ public interface StaffService {
* @return * @return
*/ */
List<TabHaobanStaff> listStaffWithIds(List<String> staffIds); List<TabHaobanStaff> listStaffWithIds(List<String> staffIds);
/**
* 查询企业下所有成员id
* @param enterpriseId
* @return
*/
List<String> queryStaffIdsWithEnterpriseId(String enterpriseId);
} }
...@@ -10,8 +10,12 @@ package com.gic.haoban.manage.service.service.content; ...@@ -10,8 +10,12 @@ package com.gic.haoban.manage.service.service.content;
public interface MaterialReportService { public interface MaterialReportService {
/** /**
* 素材周报 * 素材周报/月报
*
* @param enterpriseId * @param enterpriseId
*
* @see com.gic.haoban.manage.api.enums.content.MaterialReportType
* @param reportType
*/ */
void handlerMaterialWeekReport(String enterpriseId); void handlerMaterialReport(String enterpriseId, String staffId, Integer reportType);
} }
package com.gic.haoban.manage.service.service.content.adaptor; package com.gic.haoban.manage.service.service.content.adaptor;
import com.alibaba.fastjson.JSON;
import com.gic.haoban.manage.api.dto.StaffClerkRelationDTO;
import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO;
import com.gic.haoban.manage.api.enums.content.MaterialReportType;
import com.gic.haoban.manage.service.config.Config;
import com.gic.haoban.manage.service.entity.TabHaobanClerkMainStoreRelated;
import com.gic.haoban.manage.service.pojo.bo.content.context.MaterialReportContext;
import com.gic.haoban.manage.service.service.ClerkMainStoreRelatedService;
import com.gic.haoban.manage.service.service.StaffClerkRelationService;
import com.gic.haoban.manage.service.util.DrawImageUtils;
import com.gic.wechat.api.dto.qywx.QywxNewsArticleMessageDTO;
import com.gic.wechat.api.dto.qywx.QywxNewsSendMessageDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
/** /**
* @Author MUSI * @Author MUSI
* @Date 2023/3/24 4:11 PM * @Date 2023/3/24 4:11 PM
* @Description * @Description
* @Version * @Version 素材周报/月报组装
* 素材周报/月报组装
**/ **/
@Slf4j
@Component @Component
public class MaterialReportBuilder { public class MaterialReportBuilder {
@Autowired
private StaffClerkRelationService staffClerkRelationService;
@Autowired
private ClerkMainStoreRelatedService clerkMainStoreRelatedService;
@Autowired
private Config config;
/**
* 周报模板
*/
private static final String week_template_report = "template/week_bkg.png";
/**
* 月报模板
*/
private static final String month_template_report = "template/month_bkg.png";
/**
* 柱状成员绑定的导购信息
*
* @param context
*/
public void buildStaffRelationClerk(MaterialReportContext context) {
if (StringUtils.isAnyBlank(context.getStaffId(), context.getEnterpriseId())) {
log.info("参数异常 staffId:{}, enterpriseId:{}", context.getStaffId(), context.getEnterpriseId());
return;
}
List<StaffClerkRelationDTO> staffClerkRelations =
staffClerkRelationService.listBindCodeByStaffId(Collections.singletonList(context.getEnterpriseId()), context.getStaffId());
if (CollectionUtils.isEmpty(staffClerkRelations)) {
log.info("成员未关联导购 staffId:{}, enterpriseId:{}", context.getStaffId(), context.getEnterpriseId());
return;
}
context.setStaffClerkRelations(staffClerkRelations);
}
/**
* 填充该成员的主门店
* @param context
*/
public void fillMainStore(MaterialReportContext context) {
if (CollectionUtils.isEmpty(context.getStaffClerkRelations())) {
return;
}
StaffClerkRelationDTO staffClerkRelationDTO = context.getStaffClerkRelations().get(0);
String wxEnterpriseId = staffClerkRelationDTO.getWxEnterpriseId();
context.setClerkId(staffClerkRelationDTO.getClerkId());
TabHaobanClerkMainStoreRelated mainStoreInfo = clerkMainStoreRelatedService.getMainStoreByStaffId(context.getStaffId(), wxEnterpriseId);
if (mainStoreInfo != null) {
context.setMainStoreId(mainStoreInfo.getStoreId());
Optional<StaffClerkRelationDTO> mainClerkInfo = context.getStaffClerkRelations()
.stream()
.filter(item -> StringUtils.equals(item.getStoreId(), mainStoreInfo.getStoreId()))
.findFirst();
if (!mainClerkInfo.isPresent()){
log.info("成员{}与主门店{}不存在导购关联关系", context.getStaffId(), context.getMainStoreId());
return;
}
context.setClerkId(mainClerkInfo.get().getClerkId());
}
}
/**
* 周报/月报 数据
* @param context
*/
public void buildMaterialReportData(MaterialReportContext context) {
// 获取该导购 在门店 的周报/月报数据
String templatePath = "";
if (MaterialReportType.WEEK.getCode().equals(context.getReportType())) {
context.setUseMaterialNum(103);
context.setConvertAmount("3.1万");
templatePath = week_template_report;
}else {
context.setUseMaterialNum(1043);
context.setConvertAmount("12.3万");
templatePath = month_template_report;
}
// 生成图片地址
String url = DrawImageUtils.drawImage(context.getFactoryCode(), context.getUseMaterialNum() + "", context.getConvertAmount(), templatePath);
context.setMaterialReportUrl(url);
}
/***
* 构建企业微信消息
*
* @param context
*/
public QywxNewsSendMessageDTO buildQywxNewsMessage(MaterialReportContext context, WxEnterpriseQwDTO wxEnterpriseQwDTO) {
if (context.getStaffInfo() == null) {
log.info("构建企业微信对象, 成员信息不存在 {}", JSON.toJSONString(context));
return null;
}
String wxUserId = context.getStaffInfo().getWxUserId();
if (wxEnterpriseQwDTO.needOpenUserId3th()) {
wxUserId = context.getStaffInfo().getWxOpenUseId();
}
QywxNewsSendMessageDTO newsSendMessage = new QywxNewsSendMessageDTO();
newsSendMessage.setAgentId(Integer.parseInt(wxEnterpriseQwDTO.getAgentId()));
newsSendMessage.setUserIds(Collections.singletonList(wxUserId));
QywxNewsArticleMessageDTO articleInfo = new QywxNewsArticleMessageDTO();
articleInfo.setAppid(config.getAppid());
articleInfo.setTitle(context.getMessageTitle());
articleInfo.setDescription(context.getMessageDesc());
// pagePath 拼接参数?
articleInfo.setPagepath("/monthList");
articleInfo.setPicurl(context.getMaterialReportUrl());
newsSendMessage.setArticleMessages(Collections.singletonList(articleInfo));
return newsSendMessage;
}
} }
package com.gic.haoban.manage.service.service.content.impl; package com.gic.haoban.manage.service.service.content.impl;
import com.gic.api.base.commons.Page; import com.alibaba.fastjson.JSON;
import com.gic.haoban.manage.api.dto.StaffClerkRelationDTO; import com.gic.enterprise.api.dto.EnterpriseDTO;
import com.gic.haoban.manage.api.dto.StaffDTO; import com.gic.enterprise.api.service.EnterpriseService;
import com.gic.haoban.manage.api.service.StaffApiService; import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO;
import com.gic.haoban.manage.service.service.StaffClerkRelationService; import com.gic.haoban.manage.service.config.Config;
import com.gic.haoban.manage.service.entity.TabHaobanStaff;
import com.gic.haoban.manage.service.pojo.bo.NoticeMessageBO;
import com.gic.haoban.manage.service.pojo.bo.content.context.MaterialReportContext;
import com.gic.haoban.manage.service.service.StaffService; import com.gic.haoban.manage.service.service.StaffService;
import com.gic.haoban.manage.service.service.WxEnterpriseService; import com.gic.haoban.manage.service.service.WxEnterpriseService;
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.MaterialReportBuilder;
import com.gic.haoban.manage.service.service.notify.NoticeMessageService; import com.gic.haoban.manage.service.service.notify.NoticeMessageService;
import com.gic.wechat.api.dto.qywx.QywxNewsSendMessageDTO;
import com.gic.wechat.api.service.qywx.QywxSuiteApiService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/** /**
* @Author MUSI * @Author MUSI
...@@ -28,48 +28,71 @@ import java.util.stream.Collectors; ...@@ -28,48 +28,71 @@ import java.util.stream.Collectors;
* @Description * @Description
* @Version * @Version
**/ **/
@Slf4j
@Component @Component
public class MaterialReportServiceImpl implements MaterialReportService { public class MaterialReportServiceImpl implements MaterialReportService {
private static final Logger log = LoggerFactory.getLogger(MaterialReportServiceImpl.class);
@Autowired @Autowired
private NoticeMessageService noticeMessageService; private NoticeMessageService noticeMessageService;
@Autowired @Autowired
private StaffClerkRelationService staffClerkRelationService; private MaterialReportBuilder materialReportBuilder;
@Autowired
private static final Integer MAX_SIZE = 1000; private QywxSuiteApiService qywxSuiteApiService;
@Autowired
private WxEnterpriseService wxEnterpriseService;
@Autowired
private EnterpriseService enterpriseService;
@Autowired
private StaffService staffService;
@Autowired
private Config config;
/** /**
* 素材周报 * 素材周报/月报
* *
* @param enterpriseId * @param enterpriseId
*/ */
@Override @Override
public void handlerMaterialWeekReport(String enterpriseId) { public void handlerMaterialReport(String enterpriseId, String staffId, Integer reportType) {
// 获取企业有绑定关系成员 (分页) EnterpriseDTO enterpriseDTO = enterpriseService.getEnterpriseById(enterpriseId);
List<StaffClerkRelationDTO> staffClerkRelations = staffClerkRelationService.listAllRelationDtosByEnterpriseId(enterpriseId); if (enterpriseDTO == null) {
if (CollectionUtils.isEmpty(staffClerkRelations)) { log.info("企业信息不存在 enterpriseId:{}", enterpriseId);
return; return;
} }
// 获取成员与导购所有的绑定关系 TabHaobanStaff staffInfo = staffService.selectById(staffId);
Map<String, List<StaffClerkRelationDTO>> staffClerkRelationMap = staffClerkRelations if (staffInfo == null) {
.stream() log.info("成员不存在 {}", staffId);
.collect(Collectors.groupingBy(StaffClerkRelationDTO::getStaffId)); return;
// 获取成员 主门店信息 没有就是区经
for (Map.Entry<String, List<StaffClerkRelationDTO>> entry : staffClerkRelationMap.entrySet()) {
String staffId = entry.getKey();
List<StaffClerkRelationDTO> clerkRelations = entry.getValue();
} }
// 获取成员周报/月报数据 MaterialReportContext context = MaterialReportContext.builder()
.enterpriseId(enterpriseId)
// 保存好办小程序内消息 .factoryCode(enterpriseDTO.getFactoryCode())
.staffId(staffId)
// 群发企微应用消息 .staffInfo(staffInfo)
.reportType(reportType)
.build();
// 获取成员关联的导购
materialReportBuilder.buildStaffRelationClerk(context);
// 判断是区经还是 店长/导购 填充主门店
materialReportBuilder.fillMainStore(context);
// 获取素材数据
materialReportBuilder.buildMaterialReportData(context);
// 保存小程序消息
List<NoticeMessageBO> noticeMessageBos = context.buildNotifyMessageBos();
if (CollectionUtils.isNotEmpty(noticeMessageBos)) {
noticeMessageService.addNoticeMessageBatch(noticeMessageBos);
}
// 发送企微消息
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(staffInfo.getWxEnterpriseId());
QywxNewsSendMessageDTO newsSendMessageDTO = materialReportBuilder.buildQywxNewsMessage(context, qwDTO);
if (newsSendMessageDTO == null) {
return;
}
log.info("发送企业图文消息参数{}", JSON.toJSONString(newsSendMessageDTO));
boolean result = qywxSuiteApiService.sendMessage(qwDTO.getThirdCorpid(), config.getWxSuiteid(), newsSendMessageDTO);
log.info("成员{}发送素材企微使用报告结果 {}", staffId, result);
} }
} }
...@@ -264,4 +264,19 @@ public class StaffServiceImpl implements StaffService { ...@@ -264,4 +264,19 @@ public class StaffServiceImpl implements StaffService {
} }
return this.mapper.listByIds(staffIds); return this.mapper.listByIds(staffIds);
} }
/**
* 查询企业下所有成员id
*
* @param enterpriseId
* @return
*/
@Override
public List<String> queryStaffIdsWithEnterpriseId(String enterpriseId) {
if (StringUtils.isBlank(enterpriseId)) {
return Collections.emptyList();
}
return this.mapper.queryStaffIdsWithEnterpriseId(enterpriseId);
}
} }
...@@ -3,18 +3,23 @@ package com.gic.haoban.manage.service.service.out.impl.content.task; ...@@ -3,18 +3,23 @@ package com.gic.haoban.manage.service.service.out.impl.content.task;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.ServiceResponse; import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.util.DateUtil; import com.gic.commons.util.DateUtil;
import com.gic.commons.util.GICMQClientUtil;
import com.gic.haoban.manage.api.dto.content.log.TriggerCustomerDetailLogDTO; import com.gic.haoban.manage.api.dto.content.log.TriggerCustomerDetailLogDTO;
import com.gic.haoban.manage.api.dto.content.report.MaterialReportDTO;
import com.gic.haoban.manage.api.enums.content.MaterialReportType;
import com.gic.haoban.manage.api.enums.content.TriggerCustomerChannelType; import com.gic.haoban.manage.api.enums.content.TriggerCustomerChannelType;
import com.gic.haoban.manage.api.service.content.task.QywxGroupMsgTaskApiService; import com.gic.haoban.manage.api.service.content.task.QywxGroupMsgTaskApiService;
import com.gic.haoban.manage.service.pojo.bo.content.GroupMessageInfoBo; import com.gic.haoban.manage.service.pojo.bo.content.GroupMessageInfoBo;
import com.gic.haoban.manage.service.service.StaffService;
import com.gic.haoban.manage.service.service.content.GroupMessageService; import com.gic.haoban.manage.service.service.content.GroupMessageService;
import com.gic.haoban.manage.service.service.content.MaterialReportService;
import com.gic.haoban.manage.service.task.RouterConstant;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -30,6 +35,10 @@ public class QywxGroupMsgTaskApiServiceImpl implements QywxGroupMsgTaskApiServic ...@@ -30,6 +35,10 @@ public class QywxGroupMsgTaskApiServiceImpl implements QywxGroupMsgTaskApiServic
private static final Logger log = LoggerFactory.getLogger(QywxGroupMsgTaskApiServiceImpl.class); private static final Logger log = LoggerFactory.getLogger(QywxGroupMsgTaskApiServiceImpl.class);
@Autowired @Autowired
private GroupMessageService groupMessageService; private GroupMessageService groupMessageService;
@Autowired
private MaterialReportService materialReportService;
@Autowired
private StaffService staffService;
@Override @Override
public ServiceResponse<Void> groupMsgTaskJob(String params) { public ServiceResponse<Void> groupMsgTaskJob(String params) {
...@@ -84,23 +93,81 @@ public class QywxGroupMsgTaskApiServiceImpl implements QywxGroupMsgTaskApiServic ...@@ -84,23 +93,81 @@ public class QywxGroupMsgTaskApiServiceImpl implements QywxGroupMsgTaskApiServic
*/ */
@Override @Override
public ServiceResponse<Void> handlerMaterialWeekReport(String params) { public ServiceResponse<Void> handlerMaterialWeekReport(String params) {
return doHandlerReportInner(MaterialReportType.WEEK.getCode());
}
/**
* 素材月报
*
* @param params
* @return
*/
@Override
public ServiceResponse<Void> handlerMaterialMonthReport(String params) {
return doHandlerReportInner(MaterialReportType.MONTH.getCode());
}
/**
* 发送企业周报/月报素材
* @param reportType
* @return
*/
private ServiceResponse<Void> doHandlerReportInner(Integer reportType) {
List<String> enterpriseIds = groupMessageService.hasMaterialRightEnterprise(); List<String> enterpriseIds = groupMessageService.hasMaterialRightEnterprise();
if (CollectionUtils.isEmpty(enterpriseIds)) { if (CollectionUtils.isEmpty(enterpriseIds)) {
return ServiceResponse.success(); return ServiceResponse.success();
} }
for (String enterpriseId : enterpriseIds) {
return null; List<String> staffIds = staffService.queryStaffIdsWithEnterpriseId(enterpriseId);
if (CollectionUtils.isEmpty(staffIds)) {
log.info("企业 {} 不存在成员", enterpriseId);
continue;
}
for (String staffId : staffIds) {
MaterialReportDTO temp = new MaterialReportDTO();
temp.setStaffId(staffId);
temp.setEnterpriseId(enterpriseId);
temp.setReportType(reportType);
boolean sendMQResult = this.sendMaterialReportMQ(temp);
log.info("发送企业{}, 成员id: {}, 结果: {}", enterpriseId, staffId, sendMQResult);
}
}
return ServiceResponse.success();
} }
/** /**
* 素材月报 * 处理单成员素材使用周报/月报
* *
* @see RouterConstant#DEAL_ONE_STAFF_MATERIAL_REPORT
* @param params * @param params
* @return * @return
*/ */
@Override @Override
public ServiceResponse<Void> handlerMaterialMonthReport(String params) { public ServiceResponse<Void> doHandlerMaterialOneStaffReportMQ(String params) {
return null; log.info("doHandlerMaterialOneStaffReportMQ 参数: {}", params);
MaterialReportDTO materialReportDTO = JSON.parseObject(params, MaterialReportDTO.class);
if (materialReportDTO == null) {
log.info("参数异常 {}", params);
return ServiceResponse.success();
}
materialReportService.handlerMaterialReport(materialReportDTO.getEnterpriseId(), materialReportDTO.getStaffId(), materialReportDTO.getReportType());
return ServiceResponse.success();
}
/**
* 发送成员使用素材消息MQ
* @param materialReportDTO
* @return
*/
private boolean sendMaterialReportMQ(MaterialReportDTO materialReportDTO) {
try {
GICMQClientUtil.getClientInstance()
.sendMessage(RouterConstant.DEAL_ONE_STAFF_MATERIAL_REPORT, JSON.toJSONString(materialReportDTO));
return true;
}catch (Exception ex){
log.warn("发送成员使用素材周报/月报MQ异常, 参数: {}", JSON.toJSONString(materialReportDTO), ex);
}
return false;
} }
} }
package com.gic.haoban.manage.service.task; package com.gic.haoban.manage.service.task;
import com.gic.haoban.manage.api.service.content.task.QywxGroupMsgTaskApiService;
/** /**
* @author * @author
*/ */
...@@ -28,4 +30,11 @@ public class RouterConstant { ...@@ -28,4 +30,11 @@ public class RouterConstant {
public final static int DEFAULT_STATUS = 1; public final static int DEFAULT_STATUS = 1;
/**
* 素材周报/月报数据
* @see QywxGroupMsgTaskApiService#doHandlerMaterialOneStaffReportMQ(String)
*/
public static final String DEAL_ONE_STAFF_MATERIAL_REPORT = "dealOneStaffMaterialReport";
} }
package com.gic.haoban.manage.service.util; package com.gic.haoban.manage.service.util;
import org.slf4j.Logger; import com.alibaba.fastjson.JSON;
import org.slf4j.LoggerFactory; import com.gic.thirdparty.cloudfile.CloudFileUtil;
import com.gic.thirdparty.cloudfile.enums.CloudFileBusinessOptEnum;
import com.gic.thirdparty.cloudfile.enums.CloudFileTypeEnum;
import com.gic.thirdparty.cloudfile.pojo.CloudFileInfo;
import lombok.extern.slf4j.Slf4j;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.*; import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
/** /**
...@@ -18,32 +19,27 @@ import java.io.InputStream; ...@@ -18,32 +19,27 @@ import java.io.InputStream;
* @Description * @Description
* @Version * @Version
**/ **/
@Slf4j
public class DrawImageUtils { public class DrawImageUtils {
private static final Logger log = LoggerFactory.getLogger(DrawImageUtils.class);
private final
/** /**
* 绘画素材月报海报图 * 绘画素材周报/月报 海报图
* @param fileName *
* @param factoryCode
* @param materialNum * @param materialNum
* @param amountText * @param amountText
* @throws IOException
*/ */
public static void drawImageMonth(String fileName, String materialNum, String amountText) { public static String drawImage(String factoryCode, String materialNum, String amountText, String templatePath) {
try { try {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
InputStream inputStream = DrawImageUtils.class.getClassLoader().getResourceAsStream("template/month_bkg.png"); InputStream inputStream = DrawImageUtils.class.getClassLoader().getResourceAsStream(templatePath);
if (inputStream == null) { if (inputStream == null) {
return; log.info("模板文件不存在 path:{}", templatePath);
return null;
} }
BufferedImage image = ImageIO.read(inputStream); BufferedImage image = ImageIO.read(inputStream);
Graphics2D pen = image.createGraphics(); Graphics2D pen = image.createGraphics();
pen.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); pen.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
pen.setColor(Color.WHITE); pen.setColor(Color.WHITE);
Font font = new Font("微软雅黑", Font.BOLD, 56); Font font = new Font("微软雅黑", Font.BOLD, 56);
pen.setFont(font); pen.setFont(font);
...@@ -52,20 +48,19 @@ public class DrawImageUtils { ...@@ -52,20 +48,19 @@ public class DrawImageUtils {
pen.drawString(materialNum, startX, 250); pen.drawString(materialNum, startX, 250);
int amountX = 320 + (353 - metrics.stringWidth(amountText)) / 2; int amountX = 320 + (353 - metrics.stringWidth(amountText)) / 2;
pen.drawString(amountText, amountX, 250); pen.drawString(amountText, amountX, 250);
File file = new File(fileName); ByteArrayOutputStream bos = new ByteArrayOutputStream();
FileOutputStream fos = new FileOutputStream(file); ImageIO.write(image, "png", bos);
ImageIO.write(image, "png", fos);
pen.dispose(); pen.dispose();
CloudFileInfo cloudFileInfo = CloudFileUtil.uploadFile(bos.toByteArray(), "png", CloudFileTypeEnum.IMAGE, factoryCode, CloudFileBusinessOptEnum.HAOBAN_COMMON);
log.info("上传图片结果:{}", JSON.toJSONString(cloudFileInfo));
long endTime = System.currentTimeMillis(); long endTime = System.currentTimeMillis();
log.info("合成图片耗时 {} ms", (endTime - startTime)); log.info("合成图片耗时 {} ms", (endTime - startTime));
}catch (Exception ex){ if (cloudFileInfo != null) {
log.info("合成月报图片异常", ex); return cloudFileInfo.getOrgFileUrl();
} }
} catch (Exception ex) {
log.info("合成月报图片异常", ex);
} }
return null;
public static void main(String[] args) throws IOException {
DrawImageUtils.drawImageMonth("test2.png", "104", "13,433.33");
DrawImageUtils.drawImageMonth("test3.png", "1", "1.43万");
} }
} }
...@@ -619,4 +619,10 @@ ...@@ -619,4 +619,10 @@
where staff_id= #{staffId} where staff_id= #{staffId}
</update> </update>
<select id="queryStaffIdsWithEnterpriseId" resultType="java.lang.String">
select staff_id
from tab_haoban_staff
where status_flag = 1 and enterprise_id = #{enterpriseId}
</select>
</mapper> </mapper>
\ No newline at end of file
import com.gic.haoban.manage.api.enums.content.MaterialReportType;
import com.gic.haoban.manage.service.service.content.MaterialReportService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @Author MUSI
* @Date 2023/3/25 12:04 AM
* @Description
* @Version
**/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext-conf.xml"})
public class MaterialReportServiceTest {
public MaterialReportServiceTest(){
}
@Autowired
private MaterialReportService materialReportService;
String eid = "ff8080815dacd3a2015dacd3ef5c0000";
String wxEid = "ca66a01b79474c40b3e7c7f93daf1a3b";
String staffId = "e608b51b267e4943b87e222a343b4f25";
@Test
public void handlerMaterialWeekReportTest() {
System.setProperty("gic.module.name", "haoban-manage3-service");
materialReportService.handlerMaterialReport(eid, staffId, MaterialReportType.WEEK.getCode());
materialReportService.handlerMaterialReport(eid, staffId, MaterialReportType.MONTH.getCode());
}
}
...@@ -14,6 +14,7 @@ public class MaterialPersonalUsedQO extends MaterialStatisticsBaseQO { ...@@ -14,6 +14,7 @@ public class MaterialPersonalUsedQO extends MaterialStatisticsBaseQO {
/** /**
* 数据类型 * 数据类型
* 1 周报; 2 月报 * 1 周报; 2 月报
* @see com.gic.haoban.manage.api.enums.content.MaterialReportType
*/ */
private Integer reportType; private Integer reportType;
......
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