|
|
@@ -0,0 +1,265 @@
|
|
|
+package com.zhongzheng.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.extension.api.R;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.zhongzheng.bo.*;
|
|
|
+import com.zhongzheng.entity.*;
|
|
|
+import com.zhongzheng.exception.CustomException;
|
|
|
+import com.zhongzheng.service.*;
|
|
|
+import com.zhongzheng.util.DateUtils;
|
|
|
+import com.zhongzheng.util.HttpUtils;
|
|
|
+import com.zhongzheng.util.ToolsUtils;
|
|
|
+import com.zhongzheng.vo.*;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class OfficialApiServiceImpl implements IOfficialApiService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOfficialMenuService officialMenuService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOfficialArticleService officialArticleService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOfficialActivityService officialActivityService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOfficialLinkService officialLinkService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOfficialProblemService officialProblemService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOfficialSuggestService officialSuggestService;
|
|
|
+
|
|
|
+ @Value("${studySys.eduPath}")
|
|
|
+ private String SYS_EDUPATH;
|
|
|
+
|
|
|
+ @Value("${studySys.goodsPath}")
|
|
|
+ private String SYS_GOODSPATH;
|
|
|
+
|
|
|
+ @Value("${studyApi.domain}")
|
|
|
+ private String SYS_DOMAIN;
|
|
|
+
|
|
|
+ @Value("${studyApi.tenantId}")
|
|
|
+ private String SYS_TENANTID;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<OfficialMenuVo> listOfficialMenu(OfficialMenuQuery query) {
|
|
|
+ //获取一级菜单
|
|
|
+ List<OfficialMenu> list = officialMenuService.list(new LambdaQueryWrapper<OfficialMenu>()
|
|
|
+ .eq(OfficialMenu::getParentId, ObjectUtils.isNotNull(query.getParentId())? query.getParentId() : 0)
|
|
|
+ .eq(OfficialMenu::getStatus,1)
|
|
|
+ .orderByAsc(OfficialMenu::getSortNumber));
|
|
|
+ if (CollectionUtils.isEmpty(list)){
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ List<OfficialMenuVo> collect = list.stream().map(item -> {
|
|
|
+ OfficialMenuVo vo = BeanUtil.toBean(item, OfficialMenuVo.class);
|
|
|
+ //递归查询子集
|
|
|
+ getChildren(vo);
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return collect;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<OfficialArticleVo> listArticle(OfficialArticleQuery query) {
|
|
|
+ List<Long> menuIds = new ArrayList<>();
|
|
|
+ if (ObjectUtils.isNotNull(query.getParentId())){
|
|
|
+ //获取所有子集id
|
|
|
+ getChildrenIds(query.getMenuId(),menuIds);
|
|
|
+ }
|
|
|
+ Page<OfficialArticle> list = officialArticleService.page(new Page<>(query.getPageSize(),query.getPageNum()),
|
|
|
+ new LambdaQueryWrapper<OfficialArticle>()
|
|
|
+ .eq(ObjectUtils.isNotNull(query.getMenuId()),OfficialArticle::getMenuId, query.getMenuId())
|
|
|
+ .in(CollectionUtils.isNotEmpty(menuIds),OfficialArticle::getMenuId,menuIds)
|
|
|
+ .eq(ObjectUtils.isNotNull(query.getArticleId()),OfficialArticle::getArticleId, query.getArticleId())
|
|
|
+ .like(StringUtils.isNotBlank(query.getTitle()),OfficialArticle::getTitle, query.getTitle())
|
|
|
+ .eq(OfficialArticle::getStatus, 1)
|
|
|
+ .orderByDesc(OfficialArticle::getTopStatus)
|
|
|
+ .orderByDesc(OfficialArticle::getCreateTime));
|
|
|
+ if (CollectionUtils.isEmpty(list.getRecords())){
|
|
|
+ return new Page<>();
|
|
|
+ }
|
|
|
+ List<OfficialArticleVo> collect = list.getRecords().stream().map(x ->BeanUtil.toBean(x, OfficialArticleVo.class)).collect(Collectors.toList());
|
|
|
+ Page<OfficialArticleVo> result = new Page<>();
|
|
|
+ result.setTotal(list.getTotal());
|
|
|
+ result.setRecords(collect);
|
|
|
+ result.setSize(list.getSize());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getChildrenIds(Long parentId,List<Long> menuIds) {
|
|
|
+ menuIds.add(parentId);
|
|
|
+ List<OfficialMenu> list = officialMenuService.list(new LambdaQueryWrapper<OfficialMenu>().eq(OfficialMenu::getParentId, parentId).eq(OfficialMenu::getStatus, 1));
|
|
|
+ if (CollectionUtils.isNotEmpty(list)){
|
|
|
+ menuIds.addAll(list.stream().map(OfficialMenu::getMenuId).collect(Collectors.toList()));
|
|
|
+ list.forEach(item -> {
|
|
|
+ getChildrenIds(item.getMenuId(),menuIds);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<OfficialActivityVo> listActivity(OfficialActivityQuery query) {
|
|
|
+ List<OfficialActivity> list = officialActivityService.list(new LambdaQueryWrapper<OfficialActivity>()
|
|
|
+ .eq(ObjectUtils.isNotNull(query.getType()), OfficialActivity::getType, query.getType())
|
|
|
+ .eq(OfficialActivity::getStatus, 1)
|
|
|
+ .orderByAsc(OfficialActivity::getSort));
|
|
|
+ if (CollectionUtils.isEmpty(list)){
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ return list.stream().map(x -> BeanUtil.toBean(x, OfficialActivityVo.class)).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<OfficialLinkVo> listLink(OfficialLinkQuery query) {
|
|
|
+ List<OfficialLink> list = officialLinkService.list(new LambdaQueryWrapper<OfficialLink>().eq(OfficialLink::getStatus, 1));
|
|
|
+ if (CollectionUtils.isEmpty(list)){
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ return list.stream().map(x -> BeanUtil.toBean(x, OfficialLinkVo.class)).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<OfficialProblemVo> listProblem(OfficialProblemQuery query) {
|
|
|
+ List<OfficialProblem> list = officialProblemService.list(new LambdaQueryWrapper<OfficialProblem>().eq(OfficialProblem::getStatus, 1));
|
|
|
+ if (CollectionUtils.isEmpty(list)){
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ return list.stream().map(x -> BeanUtil.toBean(x, OfficialProblemVo.class)).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean saveSuggest(OfficialSuggestBo bo) {
|
|
|
+ OfficialSuggest bean = BeanUtil.toBean(bo, OfficialSuggest.class);
|
|
|
+ return officialSuggestService.save(bean);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<EducationVo> getEduList(OfficialOpenBo bo) {
|
|
|
+ CommonOfficialBo studentBo = new CommonOfficialBo();
|
|
|
+ Long nowTime = DateUtils.getNowTime();
|
|
|
+ String sign = ToolsUtils.EncoderByMd5(nowTime.toString() + "pubilc2022");
|
|
|
+ studentBo.setStamp(nowTime);
|
|
|
+ studentBo.setSign(sign);
|
|
|
+ HashMap<String, String> headersMap = new HashMap<>();
|
|
|
+ headersMap.put("TenantId",StringUtils.isNotBlank(bo.getTenantId())?bo.getTenantId():SYS_TENANTID);
|
|
|
+ String respone = "";
|
|
|
+ try {
|
|
|
+ respone = HttpUtils.sendPostHeader(SYS_EDUPATH, JSONObject.parseObject(JSONObject.toJSONString(studentBo)),headersMap);
|
|
|
+ if (!respone.contains("\"code\":200")) {
|
|
|
+ throw new CustomException("云学堂教育类型获取失败");
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(respone);
|
|
|
+ List<EducationVo> educationVos = JSONArray.parseArray(jsonObject.get("data").toString(), EducationVo.class);
|
|
|
+ if (CollectionUtils.isNotEmpty(educationVos)){
|
|
|
+ //填充跳转地址
|
|
|
+ String path = SYS_DOMAIN + "course-list?sortType=1&showStatus=1&goodsStatus=1";
|
|
|
+ educationVos.forEach(item -> {
|
|
|
+ item.setJumpUrl(path+String.format("&educationId=%s",item.getId()));
|
|
|
+ if (CollectionUtils.isNotEmpty(item.getBusinessList())){
|
|
|
+ item.getBusinessList().forEach(x -> {
|
|
|
+ x.setJumpUrl(path+String.format("&educationId=%s&projectId=%s&businessId=%s",item.getId(),x.getProjectId(),x.getId()));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return educationVos;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new CustomException("云学堂教育类型获取失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public OfficialArticleVo detailArticle(Long articleId) {
|
|
|
+ return BeanUtil.toBean(officialArticleService.getById(articleId), OfficialArticleVo.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public OfficialMenuVo detailMenu(Long menuId) {
|
|
|
+ return BeanUtil.toBean(officialMenuService.getById(menuId), OfficialMenuVo.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<OfficialRecommendVo> getEduGoodsList(OfficialOpenBo bo) {
|
|
|
+ CommonOfficialBo studentBo = new CommonOfficialBo();
|
|
|
+ Long nowTime = DateUtils.getNowTime();
|
|
|
+ String sign = ToolsUtils.EncoderByMd5(nowTime.toString() + "pubilc2022");
|
|
|
+ studentBo.setStamp(nowTime);
|
|
|
+ studentBo.setSign(sign);
|
|
|
+ studentBo.setPlatform(2);
|
|
|
+ studentBo.setStatus(1);
|
|
|
+ HashMap<String, String> headersMap = new HashMap<>();
|
|
|
+ headersMap.put("TenantId",StringUtils.isNotBlank(bo.getTenantId())?bo.getTenantId():SYS_TENANTID);
|
|
|
+ String respone = "";
|
|
|
+ try {
|
|
|
+ respone = HttpUtils.sendPostHeader(SYS_GOODSPATH, JSONObject.parseObject(JSONObject.toJSONString(studentBo)),headersMap);
|
|
|
+ if (!respone.contains("\"code\":200")) {
|
|
|
+ throw new CustomException("云学堂推荐商品列表获取失败");
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(respone);
|
|
|
+ List<OfficialRecommendVo> educationVos = JSONArray.parseArray(jsonObject.get("data").toString(), OfficialRecommendVo.class);
|
|
|
+ if (CollectionUtils.isNotEmpty(educationVos)){
|
|
|
+ //填充跳转地址
|
|
|
+ String path = SYS_DOMAIN + "course-detail/";
|
|
|
+ String path1 = SYS_DOMAIN + "course-list?sortType=1&showStatus=1&goodsStatus=1";
|
|
|
+ String path2 = SYS_DOMAIN + "bank-list?sortType=1&showStatus=1&goodsStatus=1";
|
|
|
+ educationVos.forEach(item -> {
|
|
|
+ switch (item.getType()){
|
|
|
+ case 1: item.setJumpUrl(path1);
|
|
|
+ break;
|
|
|
+ case 2: item.setJumpUrl(path2);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(item.getGoodsList())){
|
|
|
+ for (OfficialGoodsVo goodsVo : item.getGoodsList()) {
|
|
|
+ goodsVo.setJumpUrl(path+goodsVo.getGoodsId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return educationVos;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new CustomException("云学堂推荐商品列表获取失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getChildren(OfficialMenuVo parent) {
|
|
|
+ List<OfficialMenu> list = officialMenuService.list(new LambdaQueryWrapper<OfficialMenu>()
|
|
|
+ .eq(OfficialMenu::getParentId, parent.getMenuId())
|
|
|
+ .orderByAsc(OfficialMenu::getSortNumber));
|
|
|
+ if (CollectionUtils.isEmpty(list)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<OfficialMenuVo> collect = list.stream().map(x -> BeanUtil.toBean(x, OfficialMenuVo.class)).collect(Collectors.toList());
|
|
|
+ parent.setChildList(collect);
|
|
|
+ list.forEach(item -> {
|
|
|
+ getChildren(BeanUtil.toBean(item,OfficialMenuVo.class));
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|