123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- package com.tzld.piaoquan.offline.job;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.tzld.piaoquan.growth.common.common.enums.MessageAttachmentTypeEnum;
- import com.tzld.piaoquan.growth.common.dao.mapper.MomentSendMessageMapper;
- import com.tzld.piaoquan.growth.common.dao.mapper.StaffMapper;
- import com.tzld.piaoquan.growth.common.dao.mapper.UserWithTagMapper;
- import com.tzld.piaoquan.growth.common.model.po.MessageAttachment;
- import com.tzld.piaoquan.growth.common.model.po.MomentSendMessage;
- import com.tzld.piaoquan.growth.common.model.po.MomentSendMessageExample;
- import com.tzld.piaoquan.growth.common.model.po.Staff;
- import com.tzld.piaoquan.growth.common.service.MessageAttachmentService;
- import com.tzld.piaoquan.growth.common.service.MessageService;
- import com.tzld.piaoquan.growth.common.utils.DateUtil;
- import com.xxl.job.core.biz.model.ReturnT;
- import com.xxl.job.core.handler.annotation.XxlJob;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Component;
- import org.springframework.util.CollectionUtils;
- import java.util.List;
- import java.util.Objects;
- @Component
- public class WeComMomentDataJob {
- @Autowired
- private StaffMapper staffMapper;
- @Autowired
- private MessageService messageService;
- @Autowired
- private MessageAttachmentService messageAttachmentService;
- @Autowired
- UserWithTagMapper userWithTagMapper;
- @Autowired
- private MomentSendMessageMapper momentSendMessageMapper;
- @XxlJob("sendMomentMessageJob")
- public ReturnT<String> sendMomentMessage(String param) {
- String thatDayDateString = DateUtil.getThatDayDateString();
- MomentSendMessageExample example = new MomentSendMessageExample();
- example.createCriteria().andPreSendDateEqualTo(thatDayDateString).andIsSendEqualTo(0);
- List<MomentSendMessage> momentSendMessages = momentSendMessageMapper.selectByExample(example);
- for (MomentSendMessage momentSendMessage : momentSendMessages) {
- Staff staff = staffMapper.selectByPrimaryKey(momentSendMessage.getStaffId());
- JSONObject jsonObject = new JSONObject();
- JSONObject text = new JSONObject();
- if (StringUtils.isNotEmpty(momentSendMessage.getContent())) {
- text.put("content", momentSendMessage.getContent());
- jsonObject.put("text", text);
- }
- String attachmentIds = momentSendMessage.getAttachmentIds();
- JSONArray attachments = new JSONArray();
- if (StringUtils.isNotEmpty(attachmentIds)) {
- List<Long> attachmentIdList = JSONArray.parseArray(attachmentIds, Long.class);
- if (!CollectionUtils.isEmpty(attachmentIdList)) {
- List<MessageAttachment> messageAttachments = messageAttachmentService.getMessageAttachment(attachmentIdList);
- if (!CollectionUtils.isEmpty(messageAttachments)) {
- for (MessageAttachment messageAttachment : messageAttachments) {
- Integer type = messageAttachment.getType();
- if (Objects.equals(MessageAttachmentTypeEnum.LINK.getCode(), type)) {
- JSONObject linkAttachment = new JSONObject();
- JSONObject link = new JSONObject();
- link.put("title", messageAttachment.getTitle());
- link.put("media_id", messageAttachment.getMediaId());
- link.put("url", messageAttachment.getUrl());
- linkAttachment.put("msgtype", "link");
- linkAttachment.put("link", link);
- attachments.add(linkAttachment);
- }
- if (Objects.equals(MessageAttachmentTypeEnum.IMAGE.getCode(), type)) {
- JSONObject imageAttachment = new JSONObject();
- JSONObject image = new JSONObject();
- image.put("media_id", messageAttachment.getMediaId());
- imageAttachment.put("msgtype", "image");
- imageAttachment.put("image", image);
- attachments.add(imageAttachment);
- }
- if (Objects.equals(MessageAttachmentTypeEnum.VIDEO.getCode(), type)) {
- JSONObject videoAttachment = new JSONObject();
- JSONObject image = new JSONObject();
- image.put("media_id", messageAttachment.getMediaId());
- videoAttachment.put("msgtype", "video");
- videoAttachment.put("video", image);
- attachments.add(videoAttachment);
- }
- }
- }
- }
- }
- if (!attachments.isEmpty()) {
- jsonObject.put("attachments", attachments);
- }
- JSONObject visibleRange = new JSONObject();
- JSONObject senderList = new JSONObject();
- JSONArray userList = new JSONArray();
- userList.add(staff.getCarrierId());
- senderList.put("user_list", userList);
- visibleRange.put("sender_list", senderList);
- jsonObject.put("visible_range", visibleRange);
- boolean flag = messageService.pushMomentMessage(jsonObject, staff.getCorpId());
- if (flag) {
- momentSendMessage.setIsSend(1);
- momentSendMessageMapper.updateByPrimaryKeySelective(momentSendMessage);
- }
- }
- return ReturnT.SUCCESS;
- }
- }
|