|
@@ -1,52 +1,140 @@
|
|
|
package com.tzld.piaoquan.api.service.contentplatform.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.tzld.piaoquan.api.common.enums.ExceptionEnum;
|
|
|
+import com.tzld.piaoquan.api.common.exception.CommonException;
|
|
|
+import com.tzld.piaoquan.api.dao.mapper.contentplatform.ContentPlatformGzhAccountMapper;
|
|
|
+import com.tzld.piaoquan.api.dao.mapper.contentplatform.ext.ContentPlatformGzhAccountMapperExt;
|
|
|
+import com.tzld.piaoquan.api.model.config.LoginUserContext;
|
|
|
import com.tzld.piaoquan.api.model.param.contentplatform.CooperateAccountListParam;
|
|
|
import com.tzld.piaoquan.api.model.param.contentplatform.CooperateAccountSaveParam;
|
|
|
import com.tzld.piaoquan.api.model.param.contentplatform.GzhAuthResultParam;
|
|
|
-import com.tzld.piaoquan.api.model.vo.contentplatform.CooperateAccountItemVO;
|
|
|
-import com.tzld.piaoquan.api.model.vo.contentplatform.GenerateQrcodeVO;
|
|
|
-import com.tzld.piaoquan.api.model.vo.contentplatform.GzhAccountItem;
|
|
|
-import com.tzld.piaoquan.api.model.vo.contentplatform.GzhAuthResultVO;
|
|
|
+import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformAccount;
|
|
|
+import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformGzhAccount;
|
|
|
+import com.tzld.piaoquan.api.model.vo.contentplatform.*;
|
|
|
+import com.tzld.piaoquan.api.remote.AigcApiService;
|
|
|
import com.tzld.piaoquan.api.service.contentplatform.ContentPlatformCooperateAccountService;
|
|
|
+import com.tzld.piaoquan.growth.common.utils.Md5Util;
|
|
|
+import com.tzld.piaoquan.growth.common.utils.RedisUtils;
|
|
|
import com.tzld.piaoquan.growth.common.utils.page.Page;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
public class ContentPlatformCooperateAccountServiceImpl implements ContentPlatformCooperateAccountService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AigcApiService aigcApiService;
|
|
|
+ @Autowired
|
|
|
+ private ContentPlatformGzhAccountMapper gzhAccountMapper;
|
|
|
+ @Autowired
|
|
|
+ private ContentPlatformGzhAccountMapperExt gzhAccountMapperExt;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisUtils redisUtils;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<CooperateAccountItemVO> gzhList(CooperateAccountListParam param) {
|
|
|
- return null;
|
|
|
+ ContentPlatformAccount loginAccount = LoginUserContext.getUser();
|
|
|
+ Page<CooperateAccountItemVO> result = new Page<>(param.getPageNum(), param.getPageSize());
|
|
|
+ int offset = (param.getPageNum() - 1) * param.getPageSize();
|
|
|
+ int count = gzhAccountMapperExt.getCooperateAccountCount(param, loginAccount.getId());
|
|
|
+ result.setTotalSize(count);
|
|
|
+ if (count == 0) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ List<ContentPlatformGzhAccount> accountList = gzhAccountMapperExt.getCooperateAccountList(param,
|
|
|
+ loginAccount.getId(), offset, param.getPageSize());
|
|
|
+ List<CooperateAccountItemVO> list = buildCooperateAccountItemVOList(accountList);
|
|
|
+ result.setObjs(list);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<CooperateAccountItemVO> buildCooperateAccountItemVOList(List<ContentPlatformGzhAccount> accountList) {
|
|
|
+ if (CollectionUtils.isEmpty(accountList)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<CooperateAccountItemVO> result = new ArrayList<>();
|
|
|
+ for (ContentPlatformGzhAccount account : accountList) {
|
|
|
+ CooperateAccountItemVO accountVO = new CooperateAccountItemVO();
|
|
|
+ accountVO.setId(account.getId());
|
|
|
+ accountVO.setName(account.getName());
|
|
|
+ accountVO.setGhId(account.getGhId());
|
|
|
+ accountVO.setContentType(account.getContentType());
|
|
|
+ accountVO.setCreateTimestamp(account.getCreateTimestamp());
|
|
|
+ result.add(accountVO);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void gzhSave(CooperateAccountSaveParam param) {
|
|
|
-
|
|
|
+ ContentPlatformAccount loginAccount = LoginUserContext.getUser();
|
|
|
+ List<ContentPlatformAccount> ghIdExistList = gzhAccountMapperExt.getGhIdExists(loginAccount.getId(), param.getGhId());
|
|
|
+ if (CollectionUtils.isNotEmpty(ghIdExistList)) {
|
|
|
+ throw new CommonException(ExceptionEnum.GZH_EXISTS);
|
|
|
+ }
|
|
|
+ Long now = System.currentTimeMillis();
|
|
|
+ ContentPlatformGzhAccount account = new ContentPlatformGzhAccount();
|
|
|
+ account.setName(param.getName());
|
|
|
+ account.setGhId(param.getGhId());
|
|
|
+ account.setContentType(param.getContentType());
|
|
|
+ account.setUpdateTimestamp(now);
|
|
|
+ if (Objects.isNull(param.getId())) {
|
|
|
+ String externalId = redisUtils.get(param.getGhId());
|
|
|
+ if (StringUtils.hasText(externalId)) {
|
|
|
+ account.setExternalId(externalId);
|
|
|
+ }
|
|
|
+ account.setCreateAccountId(loginAccount.getId());
|
|
|
+ account.setCreateTimestamp(now);
|
|
|
+ gzhAccountMapper.insertSelective(account);
|
|
|
+ } else {
|
|
|
+ account.setId(param.getId());
|
|
|
+ gzhAccountMapper.updateByPrimaryKey(account);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public GenerateQrcodeVO getGzhAuthQrCode(GzhAuthResultParam param) {
|
|
|
- return null;
|
|
|
+ String qrcodeStr = aigcApiService.generateQrcode(param.getCode());
|
|
|
+ return GenerateQrcodeVO.builder().qrcodeStr(qrcodeStr).build();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
- public GzhAuthResultVO sendMessageVerifyCode(GzhAuthResultParam param) {
|
|
|
+ public GzhAuthResultVO getGzhAuthResult(GzhAuthResultParam param) {
|
|
|
+ String publishAccountId = aigcApiService.getAuthResult(param.getCode());
|
|
|
+ if (StringUtils.hasText(publishAccountId)) {
|
|
|
+ JSONObject detail = aigcApiService.getAccountDetail(publishAccountId);
|
|
|
+ String name = detail.getString("name");
|
|
|
+ String ghId = detail.getString("ghId");
|
|
|
+ redisUtils.setValueWithExpire(ghId, publishAccountId, 6 * 60 * 60L);
|
|
|
+ return GzhAuthResultVO.builder().name(name).ghId(ghId).build();
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<String> getGzhContentType() {
|
|
|
- return null;
|
|
|
+ return Arrays.asList("泛历史", "泛兴趣");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<GzhAccountItem> getGzhAccountList() {
|
|
|
- return null;
|
|
|
+ ContentPlatformAccount loginAccount = LoginUserContext.getUser();
|
|
|
+ return gzhAccountMapperExt.getGzhAccountList(loginAccount.getId());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void gzhDelete(Long id) {
|
|
|
-
|
|
|
+ ContentPlatformGzhAccount gzhAccount = new ContentPlatformGzhAccount();
|
|
|
+ gzhAccount.setId(id);
|
|
|
+ gzhAccount.setStatus(0);
|
|
|
+ gzhAccount.setUpdateTimestamp(System.currentTimeMillis());
|
|
|
+ gzhAccountMapper.updateByPrimaryKeySelective(gzhAccount);
|
|
|
}
|
|
|
}
|