|
@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.TypeReference;
|
|
import com.alibaba.fastjson.TypeReference;
|
|
|
import com.tzld.piaoquan.api.common.Constant;
|
|
import com.tzld.piaoquan.api.common.Constant;
|
|
|
import com.tzld.piaoquan.api.common.enums.ExceptionEnum;
|
|
import com.tzld.piaoquan.api.common.enums.ExceptionEnum;
|
|
|
|
|
+import com.tzld.piaoquan.api.common.enums.wecom.ConfigSyncEnum;
|
|
|
|
|
+import com.tzld.piaoquan.api.common.enums.wecom.ConfigTaskContentTypeEnum;
|
|
|
import com.tzld.piaoquan.api.common.enums.wecom.ThirdPartWeComStaffStatusEnum;
|
|
import com.tzld.piaoquan.api.common.enums.wecom.ThirdPartWeComStaffStatusEnum;
|
|
|
import com.tzld.piaoquan.api.common.exception.CommonException;
|
|
import com.tzld.piaoquan.api.common.exception.CommonException;
|
|
|
import com.tzld.piaoquan.api.component.WeComThirdPartyApiClient;
|
|
import com.tzld.piaoquan.api.component.WeComThirdPartyApiClient;
|
|
@@ -21,11 +23,14 @@ import com.tzld.piaoquan.api.model.vo.wecom.thirdpart.ThirdPartyAccountConfigTas
|
|
|
import com.tzld.piaoquan.api.model.vo.wecom.thirdpart.ThirdPartyAccountConfigVO;
|
|
import com.tzld.piaoquan.api.model.vo.wecom.thirdpart.ThirdPartyAccountConfigVO;
|
|
|
import com.tzld.piaoquan.api.model.vo.wecom.thirdpart.ThirdPartyAccountVO;
|
|
import com.tzld.piaoquan.api.model.vo.wecom.thirdpart.ThirdPartyAccountVO;
|
|
|
import com.tzld.piaoquan.api.service.wecom.thirdparty.WeComThirdPartyAccountService;
|
|
import com.tzld.piaoquan.api.service.wecom.thirdparty.WeComThirdPartyAccountService;
|
|
|
|
|
+import com.tzld.piaoquan.api.service.wecom.thirdparty.WeComThirdPartyRoomService;
|
|
|
import com.tzld.piaoquan.api.service.wecom.thirdparty.WeComThirdPartyService;
|
|
import com.tzld.piaoquan.api.service.wecom.thirdparty.WeComThirdPartyService;
|
|
|
import com.tzld.piaoquan.growth.common.utils.DistributedIdGenerator;
|
|
import com.tzld.piaoquan.growth.common.utils.DistributedIdGenerator;
|
|
|
import com.tzld.piaoquan.growth.common.utils.RedisUtils;
|
|
import com.tzld.piaoquan.growth.common.utils.RedisUtils;
|
|
|
import com.tzld.piaoquan.growth.common.utils.page.Page;
|
|
import com.tzld.piaoquan.growth.common.utils.page.Page;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -42,6 +47,8 @@ public class WeComThirdPartyAccountServiceImpl implements WeComThirdPartyAccount
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private WeComThirdPartyService weComThirdPartyService;
|
|
private WeComThirdPartyService weComThirdPartyService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
|
|
+ private WeComThirdPartyRoomService roomService;
|
|
|
|
|
+ @Autowired
|
|
|
private ThirdPartWeComStaffMapper staffMapper;
|
|
private ThirdPartWeComStaffMapper staffMapper;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ThirdPartWeComStaffConfigMapper staffConfigMapper;
|
|
private ThirdPartWeComStaffConfigMapper staffConfigMapper;
|
|
@@ -229,7 +236,8 @@ public class WeComThirdPartyAccountServiceImpl implements WeComThirdPartyAccount
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void saveAccountConfig(ThirdPartyAccountConfigParam param) {
|
|
public void saveAccountConfig(ThirdPartyAccountConfigParam param) {
|
|
|
- // todo check param
|
|
|
|
|
|
|
+ // check param
|
|
|
|
|
+ checkAccountConfigParam(param);
|
|
|
ThirdPartWeComStaffConfig config = getStaffConfig(param.getAccountId());
|
|
ThirdPartWeComStaffConfig config = getStaffConfig(param.getAccountId());
|
|
|
if (Objects.nonNull(config)) {
|
|
if (Objects.nonNull(config)) {
|
|
|
config.setStatus(0);
|
|
config.setStatus(0);
|
|
@@ -271,8 +279,77 @@ public class WeComThirdPartyAccountServiceImpl implements WeComThirdPartyAccount
|
|
|
newContent.setUpdateTime(new Date());
|
|
newContent.setUpdateTime(new Date());
|
|
|
staffConfigTaskContentMapper.insert(newContent);
|
|
staffConfigTaskContentMapper.insert(newContent);
|
|
|
}
|
|
}
|
|
|
|
|
+ // 任务开关关闭,账号下的群,任务同步关闭
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ // 配置同步
|
|
|
|
|
+ new Thread(() -> syncStaffConfigToRoom(param)).start();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void syncStaffConfigToRoom(ThirdPartyAccountConfigParam param) {
|
|
|
|
|
+ List<ThirdPartWeComRoom> roomList;
|
|
|
|
|
+ if (param.getConfigSync() == ConfigSyncEnum.ALL.getVal()) {
|
|
|
|
|
+ // 所有群
|
|
|
|
|
+ roomList = weComThirdPartyService.getStaffRoomList(param.getAccountId());
|
|
|
|
|
+ } else if (param.getConfigSync() == ConfigSyncEnum.SPECIFY.getVal()) {
|
|
|
|
|
+ // 指定群生效
|
|
|
|
|
+ roomList = weComThirdPartyService.getRoomByRoomIds(param.getConfigSyncRoomIdList());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ roomList = new ArrayList<>();
|
|
|
}
|
|
}
|
|
|
- // todo 配置同步
|
|
|
|
|
|
|
+ syncConfig(param, roomList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void syncConfig(ThirdPartyAccountConfigParam param, List<ThirdPartWeComRoom> roomList) {
|
|
|
|
|
+ if (CollectionUtils.isEmpty(roomList)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (ThirdPartWeComRoom room : roomList) {
|
|
|
|
|
+ roomService.saveRoomConfig(room, param);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void checkAccountConfigParam(ThirdPartyAccountConfigParam param) {
|
|
|
|
|
+ if (Objects.isNull(param.getAccountId())) {
|
|
|
|
|
+ throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "账号id不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(param.getPutScene())) {
|
|
|
|
|
+ throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "推送场景不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (Objects.isNull(param.getPrimaryThirdStaffId())) {
|
|
|
|
|
+ throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "主推送人员不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (CollectionUtils.isEmpty(param.getTaskList())) {
|
|
|
|
|
+ throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "任务列表不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (param.getConfigSync() == ConfigSyncEnum.SPECIFY.getVal() && CollectionUtils.isEmpty(param.getConfigSyncRoomIdList())) {
|
|
|
|
|
+ throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "指定群生效时,选定群列表不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ for (ThirdPartyAccountConfigTaskParam task : param.getTaskList()) {
|
|
|
|
|
+ if (Objects.nonNull(task.getRandomMin())) {
|
|
|
|
|
+ if (task.getRandomMin() < 0) {
|
|
|
|
|
+ throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "随机浮动分钟不能小于0");
|
|
|
|
|
+ } else if (task.getRandomMin() > 30) {
|
|
|
|
|
+ throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "随机浮动分钟不能大于30");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (CollectionUtils.isEmpty(task.getContentList()) || task.getContentList().size() > 3) {
|
|
|
|
|
+ throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "任务内容不能为空,最多3条");
|
|
|
|
|
+ }
|
|
|
|
|
+ for (ThirdPartyAccountConfigTaskContentParam content : task.getContentList()) {
|
|
|
|
|
+ if (Objects.isNull(content.getType())) {
|
|
|
|
|
+ throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "任务内容类型不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (content.getType() == ConfigTaskContentTypeEnum.TEXT.getVal()
|
|
|
|
|
+ && StringUtils.isBlank(content.getContent())) {
|
|
|
|
|
+ throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "文案不能为空");
|
|
|
|
|
+ } else if (content.getType() == ConfigTaskContentTypeEnum.MINI_PROGRAM.getVal()
|
|
|
|
|
+ && Objects.isNull(content.getSource())) {
|
|
|
|
|
+ throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "小程序来源不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|