| | |
| | | import com.aliyun.openservices.ons.api.Message;
|
| | | import com.aliyun.openservices.ons.api.Producer;
|
| | | import com.yeshi.fanli.dao.mybatis.user.cloud.UserCloudMapper;
|
| | | import com.yeshi.fanli.dto.aitaoker.RobotInfoDTO;
|
| | | import com.yeshi.fanli.dto.aitaoker.WeiXinGroupDTO;
|
| | | import com.yeshi.fanli.dto.jd.JDCouponInfo;
|
| | | import com.yeshi.fanli.dto.jd.JDPingouInfo;
|
| | |
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.ImageToBase64;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | | import com.yeshi.fanli.util.RedisKeyEnum;
|
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.aitaoker.AitaokerApiUtil;
|
| | |
| | | List<WeiXinGroupDTO> list = AitaokerApiUtil.getContract(robotId);
|
| | | if (list == null || list.size() == 0)
|
| | | throw new UserCloudException(1, "未检索到对应群");
|
| | |
|
| | | |
| | | String wxId = userCloud.getWxId();
|
| | | for (WeiXinGroupDTO dto : list) {
|
| | | userCloudGroupService.addGroup(uid, dto.getGroupId(), dto.getGroupName(), userCloud.getGroupNum());
|
| | | String groupId = dto.getGroupId();
|
| | | // 检测是否匹配群
|
| | | String key = RedisKeyEnum.cloudMatchGroup.getKey() + StringUtil.Md5(wxId + "_" + groupId);
|
| | | String result = redisManager.getCommonString(key);
|
| | | if (!StringUtil.isNullOrEmpty(result)) {
|
| | | userCloudGroupService.addGroup(uid, dto.getGroupId(), dto.getGroupName(), userCloud.getGroupNum());
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void cacheMatchGroup(String wxId, String groupId) {
|
| | | if (StringUtil.isNullOrEmpty(wxId) || StringUtil.isNullOrEmpty(groupId))
|
| | | return;
|
| | | String key = RedisKeyEnum.cloudMatchGroup.getKey() + StringUtil.Md5(wxId + "_" + groupId);
|
| | | redisManager.cacheCommonString(key , "true" , 60*20);
|
| | | }
|
| | | |
| | | @Override
|
| | | public void sendByDynamic(Long uid, String id) throws UserCloudException{
|
| | | sendCircleByDynamic(uid, id, UserCloudSendRecord.SEND_WAY_MANUAL);
|
| | |
| | | String wxId = userCloud.getWxId();
|
| | | if (StringUtil.isNullOrEmpty(wxId))
|
| | | throw new UserCloudException(1003, "微信号不存在,请先微信登录");
|
| | | |
| | | if (!AitaokerApiUtil.onlineCheck(robotId)) {
|
| | | throw new UserCloudException(1003, "微信已掉线,请先重新登录微信");
|
| | | }
|
| | |
|
| | | // 验证开启状态
|
| | | List<UserCloudGroup> listGroup = userCloudGroupService.listByUid(uid);
|
| | |
| | | sendRecord.setWxId(wxId);
|
| | | sendRecord.setRobotId(robotId);
|
| | | sendRecord.setSendTime(new Date());
|
| | | sendRecord.setSendOrigin(UserCloudSendRecord.ORIGIN_STORE);
|
| | | sendRecord.setSendOrigin(UserCloudSendRecord.ORIGIN_EVALUATE);
|
| | | UserCloudSendRecord result = userCloudSendRecordService.save(sendRecord);
|
| | | String pid = result.getId();
|
| | |
|
| | |
| | | @Override
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void sendCustomGoods(Long uid, Long goodsId, Integer goodsType, Long sellerId) throws UserCloudException{
|
| | | sendCircleByGoods(uid, goodsId, goodsType, null, sellerId);
|
| | | sendCircleByGoods(uid, goodsId, goodsType, null, sellerId, UserCloudSendRecord.SEND_WAY_MANUAL);
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | |
|
| | | try {
|
| | | // 发送商品
|
| | | sendCircleByGoods(uid, cgoods.getGoodsId(), cgoods.getGoodsType(), id, cgoods.getSellerId());
|
| | | sendCircleByGoods(uid, cgoods.getGoodsId(), cgoods.getGoodsType(), id, cgoods.getSellerId(), UserCloudSendRecord.SEND_WAY_AUTO);
|
| | | } catch (UserCloudException e) {
|
| | | LogHelper.cloudInfo("autoSendCustomGoods - [uid:" +uid + " 库id:"+ id + "]原因:"+ e.getMsg());
|
| | | }
|
| | | }
|
| | |
|
| | | private void sendCircleByGoods(Long uid, Long goodsId, Integer goodsType, Long storeId, Long sellerId) throws UserCloudException {
|
| | | private void sendCircleByGoods(Long uid, Long goodsId, Integer goodsType, Long storeId,
|
| | | Long sellerId, int way) throws UserCloudException {
|
| | | // 验证是否授权
|
| | | UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
|
| | | if (user == null)
|
| | |
| | | custom = cloudManage.getCustom();
|
| | | }
|
| | | if (!custom) {
|
| | | throw new UserCloudException(0, "成功加入云发单库");
|
| | | return;
|
| | | }
|
| | |
|
| | | Integer robotId = userCloud.getRobotId();
|
| | |
| | | String wxId = userCloud.getWxId();
|
| | | if (StringUtil.isNullOrEmpty(wxId))
|
| | | throw new UserCloudException(1002, "请先登录微信");
|
| | | |
| | | if (!AitaokerApiUtil.onlineCheck(robotId)) {
|
| | | throw new UserCloudException(1003, "微信已掉线,请先重新登录微信");
|
| | | }
|
| | | |
| | |
|
| | | // 验证开启状态
|
| | | List<UserCloudGroup> listGroup = userCloudGroupService.listByUid(uid);
|
| | |
| | | }
|
| | | UserCloudSendRecord result = userCloudSendRecordService.save(sendRecord);
|
| | |
|
| | | if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
|
| | | sendTaoBaoGoods(user, robotId, wxId, goodsId, relationId, listOpen, result.getId());
|
| | | } else if (goodsType == Constant.SOURCE_TYPE_JD) {
|
| | | sendJDGoods(user, robotId, wxId, goodsId, relationId, listOpen, result.getId());
|
| | | } else if (goodsType == Constant.SOURCE_TYPE_PDD) {
|
| | | sendPDDGoods(user, robotId, wxId, goodsId, relationId, listOpen, result.getId());
|
| | | } else if (goodsType == Constant.SOURCE_TYPE_VIP) {
|
| | | sendVIPGoods(user, robotId, wxId, goodsId, relationId, listOpen, result.getId());
|
| | | } else if (goodsType == Constant.SOURCE_TYPE_SUNING) {
|
| | | sendSuNingGoods(user, robotId, wxId, goodsId, sellerId, relationId, listOpen, result.getId());
|
| | | try {
|
| | | if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
|
| | | sendTaoBaoGoods(user, robotId, wxId, goodsId, relationId, listOpen, result.getId());
|
| | | } else if (goodsType == Constant.SOURCE_TYPE_JD) {
|
| | | sendJDGoods(user, robotId, wxId, goodsId, relationId, listOpen, result.getId());
|
| | | } else if (goodsType == Constant.SOURCE_TYPE_PDD) {
|
| | | sendPDDGoods(user, robotId, wxId, goodsId, relationId, listOpen, result.getId());
|
| | | } else if (goodsType == Constant.SOURCE_TYPE_VIP) {
|
| | | sendVIPGoods(user, robotId, wxId, goodsId, relationId, listOpen, result.getId());
|
| | | } else if (goodsType == Constant.SOURCE_TYPE_SUNING) {
|
| | | sendSuNingGoods(user, robotId, wxId, goodsId, sellerId, relationId, listOpen, result.getId());
|
| | | }
|
| | | // 更新发单记录
|
| | | if (storeId != null) {
|
| | | UserCloudGoods record = new UserCloudGoods();
|
| | | record.setId(storeId);
|
| | | record.setState(UserCloudGoods.STATE_SHARED);
|
| | | record.setSendTime(new Date());
|
| | | record.setUpdateTime(new Date());
|
| | | userCloudGoodsService.updateByPrimaryKeySelective(record);
|
| | | }
|
| | | |
| | | } catch (UserCloudException e) {
|
| | | LogHelper.cloudInfo("autoSendCustomGoods - [uid:" +uid + " 库id:"+ storeId + "]原因:"+ e.getMsg());
|
| | | // 更新发单记录
|
| | | if (storeId != null) {
|
| | | UserCloudGoods record = new UserCloudGoods();
|
| | | record.setId(storeId);
|
| | | record.setState(UserCloudGoods.STATE_INVALID);
|
| | | record.setSendTime(new Date());
|
| | | record.setUpdateTime(new Date());
|
| | | userCloudGoodsService.updateByPrimaryKeySelective(record);
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | // 更新发单记录
|
| | | if (storeId != null) {
|
| | | UserCloudGoods record = new UserCloudGoods();
|
| | | record.setId(storeId);
|
| | | record.setState(UserCloudGoods.STATE_SHARED);
|
| | | record.setSendTime(new Date());
|
| | | record.setUpdateTime(new Date());
|
| | | userCloudGoodsService.updateByPrimaryKeySelective(record);
|
| | | }
|
| | | |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | Date lastTime = new Date(time);
|
| | |
|
| | | for (int i = 0; i < 1000; i ++) {
|
| | | List<Long> list = userCloudMapper.listValidUid((i-1)*1000, 1000);
|
| | | // 查询哪些用户开通
|
| | | List<Long> list = userCloudMapper.listValidUid(i*1000, 1000);
|
| | | if (list == null || list.size() == 0) {
|
| | | break;
|
| | | }
|
| | |
|
| | | for (Long uid: list) {
|
| | | try {
|
| | | // 判断是否该 内容已发
|
| | | UserCloudSendRecord record = userCloudSendRecordService.getByUidAndSendId(uid, id);
|
| | | if (record != null)
|
| | | continue;
|
| | |
|
| | | // 是否在一个小时内已发送过
|
| | | UserCloudSendRecord last = userCloudSendRecordService.getLastByUid(uid, lastTime);
|
| | | if (last != null)
|
| | | continue;
|