PageServiceImpl.java 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019
  1. package com.caimei365.commodity.service.impl;
  2. import com.aliyun.oss.OSS;
  3. import com.aliyun.oss.OSSClientBuilder;
  4. import com.caimei365.commodity.components.PriceUtilService;
  5. import com.caimei365.commodity.mapper.*;
  6. import com.caimei365.commodity.model.ResponseJson;
  7. import com.caimei365.commodity.model.po.*;
  8. import com.caimei365.commodity.model.search.ProductListVo;
  9. import com.caimei365.commodity.model.vo.*;
  10. import com.caimei365.commodity.service.PageService;
  11. import com.caimei365.commodity.utils.AppletsLinkUtil;
  12. import com.caimei365.commodity.utils.ImageUtils;
  13. import com.caimei365.commodity.utils.MathUtil;
  14. import com.github.pagehelper.PageHelper;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.apache.commons.lang.StringUtils;
  17. import org.springframework.beans.factory.annotation.Value;
  18. import org.springframework.cache.annotation.Cacheable;
  19. import org.springframework.stereotype.Service;
  20. import org.springframework.util.CollectionUtils;
  21. import javax.annotation.Resource;
  22. import java.text.ParseException;
  23. import java.text.SimpleDateFormat;
  24. import java.util.*;
  25. import java.util.stream.Collectors;
  26. /**
  27. * Description
  28. *
  29. * @author : Charles
  30. * @date : 2021/4/12
  31. */
  32. @Slf4j
  33. @Service
  34. public class PageServiceImpl implements PageService {
  35. @Value("${caimei.wwwDomain}")
  36. private String domain;
  37. @Resource
  38. private UserLikeMapper likeMapper;
  39. @Resource
  40. private PageMapper pageMapper;
  41. @Resource
  42. private ShopMapper shopMapper;
  43. @Resource
  44. private PriceMapper priceMapper;
  45. @Resource
  46. private PriceUtilService priceUtilService;
  47. @Resource
  48. private ProductTypeMapper productTypeMapper;
  49. @Resource
  50. private PageService pageService;
  51. @Resource
  52. private CouponMapper couponMapper;
  53. @Value("${spring.cloud.config.profile}")
  54. private String active;
  55. private String endpoint = "https://oss-cn-shenzhen.aliyuncs.com";
  56. private String accessKeyId = "LTAI4GBL3o4YkWnbKYgf2Xia";
  57. private String accessKeySecret = "dBjAXqbYiEPP6Ukuk2ZsXQeET7FVkK";
  58. private String bucketName = "caimei-oss";
  59. /**
  60. * 获取分类列表
  61. *
  62. * @param typeSort 分类类型:1产品,2仪器,0全部
  63. * @param source 请求来源:www,crm
  64. */
  65. @Override
  66. @Cacheable(value = "getCommodityClassify", key = "#typeSort +'-'+ #source", unless = "#result == null")
  67. public ResponseJson<List<BigTypeVo>> getClassify(Integer typeSort, String source) {
  68. List<BigTypeVo> bigTypeList = productTypeMapper.getBigTypeList(typeSort, source);
  69. bigTypeList.forEach(bigType -> {
  70. String caiMeiImage = ImageUtils.getImageURL("caiMeiImage", null, 0, domain);
  71. bigType.setWwwIcon(StringUtils.isEmpty(bigType.getWwwIcon()) ? caiMeiImage : bigType.getWwwIcon());
  72. bigType.setCrmIcon(StringUtils.isEmpty(bigType.getCrmIcon()) ? caiMeiImage : bigType.getCrmIcon());
  73. List<SmallTypeVo> smallTypeList = productTypeMapper.getSmallTypeList(bigType.getBigTypeId(), source);
  74. if (!CollectionUtils.isEmpty(smallTypeList)) {
  75. smallTypeList.forEach(smallType -> {
  76. smallType.setWwwIcon(StringUtils.isEmpty(smallType.getWwwIcon()) ? caiMeiImage : smallType.getWwwIcon());
  77. smallType.setCrmIcon(StringUtils.isEmpty(smallType.getCrmIcon()) ? caiMeiImage : smallType.getCrmIcon());
  78. List<TinyTypeVo> tinyTypeList = productTypeMapper.getTinyTypeList(smallType.getSmallTypeId(), source);
  79. if (!CollectionUtils.isEmpty(tinyTypeList)) {
  80. tinyTypeList.forEach(tinyType -> {
  81. tinyType.setWwwIcon(StringUtils.isEmpty(tinyType.getWwwIcon()) ? caiMeiImage : tinyType.getWwwIcon());
  82. tinyType.setCrmIcon(StringUtils.isEmpty(tinyType.getCrmIcon()) ? caiMeiImage : tinyType.getCrmIcon());
  83. });
  84. smallType.setTinyTypeList(tinyTypeList);
  85. }
  86. });
  87. bigType.setSmallTypeList(smallTypeList);
  88. }
  89. });
  90. return ResponseJson.success(bigTypeList);
  91. }
  92. /**
  93. * 产品/仪器页面数据
  94. *
  95. * @param pageId 页面信息id
  96. * @param userId 用户id
  97. * @param source 来源:1网站,2小程序
  98. */
  99. @Override
  100. @Cacheable(value = "insCommodityData", key = "#pageId+'-'+#userId+'-'+#source", unless = "#result == null")
  101. public ResponseJson<Map<String, Object>> getClassifyData(Integer pageId, Integer userId, Integer source) {
  102. source = source == null ? 1 : source;
  103. Map<String, Object> map = new HashMap<>(3);
  104. Integer typeSort = pageMapper.getPageTypeSort(pageId);
  105. List<HotSearchVo> hotSearchList = pageMapper.getHotSearchByPageId(pageId, source);
  106. List<PageFloorVo> floorList = pageMapper.getFloorByPageId(pageId, source);
  107. for (PageFloorVo floor : floorList) {
  108. FloorContentVo floorContent = pageMapper.getFloorContentByCentreId(floor.getId());
  109. setFloorLinkType(floorContent);
  110. floor.setFloorContent(floorContent);
  111. List<FloorImageVo> floorImageList = pageMapper.getFloorImageByCentreId(floor.getId(), source);
  112. setFloorImageProduct(userId, floorImageList, source);
  113. floor.setFloorImageList(floorImageList);
  114. }
  115. map.put("typeSort", typeSort);
  116. map.put("hotSearchList", hotSearchList);
  117. map.put("floorList", floorList);
  118. return ResponseJson.success(map);
  119. }
  120. /**
  121. * 首页楼层数据
  122. *
  123. * @param userId 用户id
  124. * @param source 来源:1网站,2小程序
  125. */
  126. @Cacheable(value = "getHomeCommodityData", key = "#userId +'-'+ #source", unless = "#result == null")
  127. @Override
  128. public ResponseJson<Map<String, Object>> getHomeData(Integer userId, Integer source) {
  129. Map<String, Object> map = new HashMap<>(2);
  130. //楼层管理
  131. source = source == null ? 1 : source;
  132. List<PageFloorVo> homePageFloor = pageMapper.getHomePageFloor(source);
  133. Iterator<PageFloorVo> floorIterator = homePageFloor.iterator();
  134. while (floorIterator.hasNext()) {
  135. PageFloorVo floor = floorIterator.next();
  136. FloorContentVo floorContent = pageMapper.getFloorContentById(floor.getId());
  137. setFloorLinkType(floorContent);
  138. floor.setFloorContent(floorContent);
  139. List<FloorImageVo> floorImageList = pageMapper.getFloorImageById(floor.getId(), source);
  140. if (floorImageList == null || floorImageList.size() == 0) {
  141. floorIterator.remove();
  142. continue;
  143. }
  144. setFloorImageProduct(userId, floorImageList, source);
  145. floor.setFloorImageList(floorImageList);
  146. }
  147. map.put("homePageFloor", homePageFloor);
  148. // 优质供应商
  149. ShopFloorVo supplierImage = pageMapper.getSupplierFloorImage();
  150. List<ShopImageVo> supplierList = pageMapper.getSupplierImage(source);
  151. supplierList.forEach(supplier -> {
  152. Integer linkType = AppletsLinkUtil.getLinkType(supplier.getLink());
  153. supplier.setLinkType(linkType);
  154. supplier.setLinkParam(AppletsLinkUtil.getLinkParam(linkType, supplier.getLink()));
  155. });
  156. if (supplierImage != null) {
  157. supplierImage.setQualitySupplierList(supplierList);
  158. if (StringUtils.isNotBlank(supplierImage.getWwwLink())) {
  159. Integer linkType = AppletsLinkUtil.getLinkType(supplierImage.getWwwLink());
  160. supplierImage.setLinkType(linkType);
  161. supplierImage.setLinkParam(AppletsLinkUtil.getLinkParam(linkType, supplierImage.getWwwLink()));
  162. }
  163. }
  164. map.put("supplierImage", supplierImage);
  165. return ResponseJson.success(map);
  166. }
  167. /**
  168. * 首页基础数据(小程序)
  169. *
  170. * @param source 来源 : 1 网站 ; 2 小程序
  171. */
  172. @Override
  173. public ResponseJson<Map<String, Object>> getHomeInit(Integer source) {
  174. Map<String, Object> map = new HashMap<>(4);
  175. // 搜索热门关键字
  176. List<String> searchHotWord = pageMapper.getSearchKeyword();
  177. if (!CollectionUtils.isEmpty(searchHotWord) && searchHotWord.size() > 8) {
  178. searchHotWord.parallelStream()
  179. .filter(str -> !StringUtils.isEmpty(str)).limit(8)
  180. .collect(Collectors.toList());
  181. }
  182. map.put("searchHotWord", searchHotWord);
  183. // 头部菜单
  184. List<TopMenuVo> menuList = pageMapper.getTopMenus(source);
  185. menuList.forEach(item -> {
  186. String link = item.getLink();
  187. if (StringUtils.isNotBlank(link)) {
  188. if (source == 1) {
  189. if (link.contains("?")) {
  190. link = link + "&name=" + item.getName();
  191. } else {
  192. link = link + "?name=" + item.getName();
  193. }
  194. }
  195. item.setLinkType(AppletsLinkUtil.getLinkType(link));
  196. item.setLinkParam(AppletsLinkUtil.getLinkParam(item.getLinkType(), link));
  197. item.setLink(link);
  198. }
  199. });
  200. map.put("topMenuList", menuList);
  201. // 底部帮助页
  202. List<BaseLinkVo> helpPages = pageMapper.getHelpPageTypes();
  203. helpPages.forEach(item -> {
  204. List<BaseLinkVo> pageList = pageMapper.getHelpPagesByType(item.getId());
  205. item.setLinkList(pageList);
  206. });
  207. map.put("helpPages", helpPages);
  208. // 友情链接
  209. List<BaseLinkVo> friendLinks = pageMapper.getFriendLinks();
  210. map.put("friendLinks", friendLinks);
  211. //是否显示领取优惠券入口
  212. List<CouponVo> couponList = couponMapper.findCouponList(null);
  213. if (couponList != null && couponList.size() > 0) {
  214. //展示
  215. map.put("couponEntry", 1);
  216. } else {
  217. //隐藏
  218. map.put("couponEntry", 2);
  219. }
  220. return ResponseJson.success(map);
  221. }
  222. /**
  223. * 活动专题楼层数据(美博会)
  224. *
  225. * @param pageId 页面id
  226. * @param userId 用户id
  227. * @param source 来源 : 1 网站 ; 2 小程序
  228. */
  229. @Cacheable(value = "getPageFloorData", key = "#userId +'-'+ #pageId +'-'+ #source", unless = "#result == null")
  230. @Override
  231. public ResponseJson<Map<String, Object>> getPageData(Integer pageId, Integer userId, Integer source) {
  232. if (pageId == null) {
  233. return ResponseJson.error("参数异常: 页面id不能为空!", null);
  234. }
  235. source = source == null ? 1 : source;
  236. // 页面数据
  237. CmPageVo page = pageMapper.findCmPageById(pageId);
  238. //轮播图设置链接类型
  239. if (StringUtils.isNotBlank(page.getHeadLink())) {
  240. Integer linkType = AppletsLinkUtil.getLinkType(page.getHeadLink());
  241. page.setLinkType(linkType);
  242. page.setLinkParam(AppletsLinkUtil.getLinkParam(linkType, page.getHeadLink()));
  243. }
  244. List<PageFloorVo> floorList = pageMapper.getFloorByPageId(pageId, source);
  245. ListIterator<PageFloorVo> iterator = floorList.listIterator();
  246. while (iterator.hasNext()) {
  247. PageFloorVo floor = iterator.next();
  248. FloorContentVo floorContent = pageMapper.getFloorContentByCentreId(floor.getId());
  249. if (null == floorContent) {
  250. iterator.remove();
  251. } else {
  252. setFloorLinkType(floorContent);
  253. List<FloorImageVo> floorImageList = pageMapper.getFloorImageByCentreId(floor.getId(), source);
  254. setFloorImageProduct(userId, floorImageList, source);
  255. floor.setFloorImageList(floorImageList);
  256. String templateTypeStr = floorContent.getTemplateType();
  257. if (StringUtils.isNotEmpty(templateTypeStr)) {
  258. int templateType = Integer.parseInt(floorContent.getTemplateType());
  259. // 日期切换模板处理
  260. if (templateType == 1 || templateType == 2 || (templateType >= 7 && templateType <= 10)) {
  261. floorContent.setTemplateClassify(1);
  262. } else if (templateType >= 3 && templateType <= 6) {
  263. floorContent.setTemplateClassify(2);
  264. } else if (templateType >= 11 && templateType <= 21) {
  265. floorContent.setTemplateClassify(3);
  266. } else if (templateType >= 22 && templateType <= 25) {
  267. floorContent.setTemplateClassify(1);
  268. List<FloorImageVo> floorImageList1 = new ArrayList<>();
  269. List<FloorImageVo> floorImageList2 = new ArrayList<>();
  270. List<FloorImageVo> floorImageList3 = new ArrayList<>();
  271. floorImageList.forEach(image -> {
  272. // 根据展示日期排序分割进3个列表中
  273. if (1 == image.getDisplaySort()) {
  274. floorImageList1.add(image);
  275. } else if (2 == image.getDisplaySort()) {
  276. floorImageList2.add(image);
  277. } else if (3 == image.getDisplaySort()) {
  278. floorImageList3.add(image);
  279. }
  280. });
  281. floor.setFloorImageList(floorImageList1);
  282. floor.setFloorImageList2(floorImageList2);
  283. floor.setFloorImageList3(floorImageList3);
  284. } else if (templateType >= 26 && templateType <= 29) {
  285. floorContent.setTemplateClassify(4);
  286. }
  287. }
  288. floor.setFloorContent(floorContent);
  289. }
  290. }
  291. Map<String, Object> map = new HashMap<>(2);
  292. map.put("page", page);
  293. map.put("floorList", floorList);
  294. return ResponseJson.success(map);
  295. }
  296. /**
  297. * 楼层详情
  298. *
  299. * @param floorId 楼层id
  300. * @param userId 用户id
  301. * @param source 来源 : 1 网站 ; 2 小程序
  302. */
  303. @Override
  304. public ResponseJson<Map<String, Object>> getPageFloorData(Integer floorId, Integer userId, Integer source) {
  305. if (floorId == null) {
  306. return ResponseJson.error("参数异常: 页面id不能为空!", null);
  307. }
  308. FloorContentVo floorContent = pageMapper.getFloorContentById(floorId);
  309. setFloorLinkType(floorContent);
  310. List<FloorImageVo> floorImageList = pageMapper.getFloorImageById(floorId, source);
  311. setFloorImageProduct(userId, floorImageList, source);
  312. Map<String, Object> map = new HashMap<>(2);
  313. map.put("floorContent", floorContent);
  314. map.put("floorImageList", floorImageList);
  315. return ResponseJson.success(map);
  316. }
  317. /**
  318. * 分页详情楼层详情
  319. *
  320. * @param centreId 分页详情楼层id
  321. * @param userId 用户id
  322. * @param source 来源 : 1 网站 ; 2 小程序
  323. */
  324. @Override
  325. public ResponseJson<Map<String, Object>> getPageCentreData(Integer centreId, Integer userId, Integer source) {
  326. if (centreId == null) {
  327. return ResponseJson.error("参数异常: 分页详情楼层id不能为空!", null);
  328. }
  329. FloorContentVo floorContent = pageMapper.getFloorContentByCentreId(centreId);
  330. setFloorLinkType(floorContent);
  331. String templateTypeStr = floorContent.getTemplateType();
  332. if (StringUtils.isNotEmpty(templateTypeStr)) {
  333. int templateType = Integer.parseInt(floorContent.getTemplateType());
  334. // 日期切换模板处理
  335. if (templateType == 1 || templateType == 2 || (templateType >= 7 && templateType <= 10)) {
  336. floorContent.setTemplateClassify(1);
  337. } else if (templateType >= 3 && templateType <= 6) {
  338. floorContent.setTemplateClassify(2);
  339. } else if (templateType >= 11 && templateType <= 21) {
  340. floorContent.setTemplateClassify(3);
  341. } else if (templateType >= 22 && templateType <= 25) {
  342. floorContent.setTemplateClassify(1);
  343. } else if (templateType >= 26 && templateType <= 29) {
  344. floorContent.setTemplateClassify(4);
  345. }
  346. }
  347. List<FloorImageVo> floorImageList = pageMapper.getFloorImageByCentreId(centreId, source);
  348. setFloorImageProduct(userId, floorImageList, source);
  349. Map<String, Object> map = new HashMap<>(2);
  350. map.put("floorContent", floorContent);
  351. map.put("floorImageList", floorImageList);
  352. return ResponseJson.success(map);
  353. }
  354. /**
  355. * 商品详情页
  356. *
  357. * @param productId 商品Id
  358. * @param userId 用户Id
  359. */
  360. @Override
  361. public ResponseJson<ProductDetailVo> getProductDetails(Integer productId, Integer userId) {
  362. ProductDetailVo product = pageMapper.getProductDetails(productId);
  363. if (product == null) {
  364. //商品不存在
  365. product = new ProductDetailVo();
  366. product.setValidFlag(0);
  367. }
  368. boolean validFlag = 2 != product.getProductCategory() && 2 == product.getValidFlag() && (product.getStock() == null || product.getStock() == 0);
  369. if (validFlag) {
  370. //已上架但库存为0的正常商品,设置为已售罄商品
  371. product.setValidFlag(4);
  372. }
  373. String[] split = null;
  374. // 品牌名称
  375. String brandName = shopMapper.getBrandNameById(product.getBrandId());
  376. product.setBrandName(brandName);
  377. //商品标签
  378. if (product.getTags() != null) {
  379. String tags = product.getTags().replace(" ", ",").replace("、", ",").replace(",", ",");
  380. if (tags.contains(",")) {
  381. List<String> list = new ArrayList<String>();
  382. for (String s : tags.split(",")) {
  383. if (s != null && !"".equals(s)) {
  384. list.add(s);
  385. }
  386. }
  387. split = list.toArray(new String[list.size()]);
  388. }
  389. }
  390. product.setTagsList(split);
  391. // 主图
  392. product.setMainImage(ImageUtils.getImageURL("product", product.getMainImage(), 0, domain));
  393. // 商品图片
  394. List<ProductImagePo> imageList = shopMapper.getProductImages(productId);
  395. for (ProductImagePo image : imageList) {
  396. String imageURL = ImageUtils.getImageURL("product", image.getImage(), 0, domain);
  397. image.setImage(imageURL);
  398. }
  399. product.setImageList(imageList);
  400. // 商品详情
  401. ProductDetailInfoPo productDetail = shopMapper.getProductDetailInfo(productId);
  402. product.setProductDetail(productDetail);
  403. // 相关参数
  404. List<ProductParameterPo> parametersList = shopMapper.getProductParameters(productId);
  405. product.setParametersList(parametersList);
  406. // 分类名称
  407. String typeName = shopMapper.getTypeName(product.getBigTypeId(), product.getSmallTypeId(), product.getTinyTypeId());
  408. product.setTypeName(typeName);
  409. List<String> list = StringUtils.isNotEmpty(typeName) ? Arrays.asList(typeName.split("-")) : new ArrayList<>();
  410. product.setBigTypeName(list.size() > 0 ? list.get(0) : null);
  411. product.setSmallTypeName(list.size() > 1 ? list.get(1) : null);
  412. product.setTinyTypeName(list.size() > 2 ? list.get(2) : null);
  413. //价格等级
  414. product.setPriceGrade(priceUtilService.getPriceGrade(product.getPrice()));
  415. // 商品云上美博会活动状态
  416. Integer pcBeautyStatus = shopMapper.getPcBeautyStatusById(product.getProductId());
  417. Integer appletsBeautyStatus = shopMapper.getAppletsBeautyStatusById(product.getProductId());
  418. product.setPcActType(null != pcBeautyStatus ? 1 : 0);
  419. product.setAppletsActType(null != appletsBeautyStatus ? 1 : 0);
  420. // 商品资料id
  421. Integer archiveId = pageMapper.getArchiveIdById(product.getProductId());
  422. product.setArchiveId(null != archiveId ? archiveId : 0);
  423. //供应商信息
  424. ShopVo shop = shopMapper.getProductShopById(product.getShopId());
  425. if (null != shop) {
  426. Integer normalNum = shopMapper.getProductNumById(product.getShopId());
  427. shop.setNormalNum(null == normalNum ? 0 : normalNum);
  428. if (shop.getBusinessScope() != null && shop.getBusinessScope().contains("/")) {
  429. String[] businessScopeArray = shop.getBusinessScope().split("/");
  430. shop.setBusinessScopeArray(businessScopeArray);
  431. }
  432. shop.setLogo(ImageUtils.getImageURL("shopLogo", shop.getLogo(), 0, domain));
  433. shop.setBusinessLicense(ImageUtils.getImageURL("shopLogo", shop.getBusinessLicense(), 0, domain));
  434. product.setShop(shop);
  435. }
  436. // 商品可见度:3:所有人可见,2:普通机构可见,1:会员机构可见
  437. Integer visibility = product.getVisibility();
  438. if (null != userId && userId > 0) {
  439. // 用户身份:0个人,1协销,2会员机构,3供应商,4普通机构
  440. Integer identity = shopMapper.getUserIdentityById(userId);
  441. // 协销 | 会员机构 | 综合供应商
  442. boolean pass1 = null != identity && (identity == 1 || identity == 2);
  443. // 普通机构
  444. boolean pass2 = null != identity && (identity == 4 && (visibility == 2 || visibility == 3));
  445. // 游客
  446. boolean pass3 = visibility == 3;
  447. if (!(pass1 || pass2 || pass3)) {
  448. return ResponseJson.success(1, "没有权限查看该商品", new ProductDetailVo());
  449. }
  450. } else if (2 == visibility || 1 == visibility) {
  451. return ResponseJson.success(1, "没有权限查看该商品,userId为空", new ProductDetailVo());
  452. }
  453. // 商品不处于已删除/待审核/审核未通过的状态
  454. if (0 != product.getValidFlag()) {
  455. // 数据库获取基本价格信息
  456. PriceVo price = priceMapper.getDetailPrice(productId);
  457. // 根据用户id设置详细价格
  458. priceUtilService.setPriceByUserId(price, userId);
  459. // 设置价格
  460. product.setActStatus(price.getActStatus());
  461. product.setPrice(price.getPrice());
  462. product.setOriginalPrice(price.getOriginalPrice());
  463. product.setNormalPrice(price.getNormalPrice());
  464. product.setLadderPriceFlag(price.getLadderPriceFlag());
  465. product.setPromotions(price.getPromotions());
  466. product.setMinBuyNumber(price.getMinBuyNumber());
  467. product.setUserIdentity(price.getUserIdentity());
  468. product.setRepurchaseFlag(price.getRepurchaseFlag());
  469. product.setMaxBuyNumber(price.getMaxBuyNumber());
  470. // 设置阶梯价格详情
  471. if (1 == price.getLadderPriceFlag()) {
  472. List<LadderPriceVo> ladderPrices = priceMapper.getLadderPricesByProductId(product.getProductId());
  473. TaxVo tax = priceMapper.getTaxByProductId(product.getProductId());
  474. if (!CollectionUtils.isEmpty(ladderPrices)) {
  475. priceUtilService.setLadderPriceList(ladderPrices, tax);
  476. }
  477. product.setLadderPriceList(ladderPrices);
  478. }
  479. //查询商品收藏情况,1未收藏,0未收藏,未收藏过该商品用户是null
  480. Integer like = likeMapper.findLike(userId, productId);
  481. product.setUserLike(like);
  482. }
  483. return ResponseJson.success(product);
  484. }
  485. /**
  486. * 再次购买商品列表
  487. *
  488. * @param userId 用户Id
  489. * @param pageNum
  490. * @param pageSize
  491. */
  492. @Override
  493. public ResponseJson<PaginationVo<ProductItemVo>> getBuyAgainProducts(Integer userId, int pageNum, int pageSize) {
  494. if (null == userId) {
  495. return ResponseJson.error("参数错误:用户Id不能为空!", null);
  496. }
  497. PageHelper.startPage(pageNum, pageSize);
  498. List<ProductItemVo> productList = pageMapper.getBuyAgainProducts(userId);
  499. productList.forEach(product -> {
  500. double price = product.getPrice() != null ? product.getPrice() : 0d;
  501. double costPrice = product.getCostPrice() != null ? product.getCostPrice() : 0d;
  502. double discountPrice = product.getDiscountPrice() != null ? product.getDiscountPrice() : 0d;
  503. Integer costFlag = product.getCostCheckFlag();
  504. // 成本大于等于复购价 或 复购价大于机构价
  505. boolean state = (costFlag == 1 && MathUtil.compare(costPrice, discountPrice) >= 0) || MathUtil.compare(discountPrice, price) > 0;
  506. product.setRepurchasePriceState(state);
  507. // 设置商品主图及价格
  508. priceUtilService.setProductDetails(userId, product);
  509. //优惠券标识
  510. Boolean couponsLogo = pageService.setCouponsLogo(userId, product.getProductId(), 2);
  511. product.setCouponsLogo(couponsLogo);
  512. });
  513. PaginationVo<ProductItemVo> pageData = new PaginationVo<>(productList);
  514. return ResponseJson.success(pageData);
  515. }
  516. /**
  517. * 项目仪器详情页
  518. *
  519. * @param equipmentId 项目仪器Id
  520. */
  521. @Override
  522. public ResponseJson<EquipmentVo> getEquipmentDetails(Integer equipmentId) {
  523. if (equipmentId == null) {
  524. return ResponseJson.error("参数异常:项目仪器Id不能为空!", null);
  525. }
  526. //仪器详情
  527. EquipmentVo equipment = pageMapper.getEquipmentById(equipmentId);
  528. if (null != equipment) {
  529. Map<String, List<EquipmentParameterVo>> pageContentMap = new HashMap<>();
  530. List<EquipmentParameterVo> firstFloorList = pageMapper.getEquipmentParametersByType(equipmentId, 1);
  531. List<EquipmentParameterVo> secondFloorList = pageMapper.getEquipmentParametersByType(equipmentId, 2);
  532. List<EquipmentParameterVo> underSecondFloorList = pageMapper.getEquipmentParametersByType(equipmentId, 4);
  533. List<EquipmentParameterVo> pcDetailList = pageMapper.getEquipmentParametersByType(equipmentId, 3);
  534. List<EquipmentParameterVo> crmDetailList = pageMapper.getEquipmentParametersByType(equipmentId, 5);
  535. pageContentMap.put("firstFloorList", firstFloorList);
  536. pageContentMap.put("secondFloorList", secondFloorList);
  537. pageContentMap.put("underSecondFloorList", underSecondFloorList);
  538. pageContentMap.put("pcDetailList", pcDetailList);
  539. pageContentMap.put("crmDetailList", crmDetailList);
  540. equipment.setPageContentMap(pageContentMap);
  541. } else {
  542. return ResponseJson.error("该仪器不存在", null);
  543. }
  544. List<PageFloorVo> floorList = pageMapper.getFloorByPageId(equipmentId, 1);
  545. if (floorList.size() > 0) {
  546. List<PageFloorVo> tempList = new ArrayList<>();
  547. floorList.forEach(floor -> {
  548. List<ImageLinkVo> imageLinks = pageMapper.getImageLinkByFloorId(floor.getId());
  549. //设置链接类型及参数
  550. if (StringUtils.isNotEmpty(floor.getLink())) {
  551. floor.setLinkType(AppletsLinkUtil.getLinkType(floor.getLink()));
  552. floor.setLinkParam(AppletsLinkUtil.getLinkParam(floor.getLinkType(), floor.getLink()));
  553. }
  554. if (imageLinks.size() > 0) {
  555. imageLinks.forEach(img -> {
  556. img.setImage(ImageUtils.getImageURL("actType", img.getImage(), 0, domain));
  557. //设置链接类型及参数
  558. if (StringUtils.isNotEmpty(img.getLink())) {
  559. img.setLinkType(AppletsLinkUtil.getLinkType(img.getLink()));
  560. img.setLinkParam(AppletsLinkUtil.getLinkParam(img.getLinkType(), img.getLink()));
  561. }
  562. });
  563. floor.setFloorData(imageLinks);
  564. } else {
  565. tempList.add(floor);
  566. }
  567. });
  568. if (tempList.size() > 0) {
  569. floorList.removeAll(tempList);
  570. }
  571. }
  572. equipment.setFloorList(floorList);
  573. return ResponseJson.success(equipment);
  574. }
  575. /**
  576. * 商品详情页-图片
  577. *
  578. * @param productId 商品Id
  579. */
  580. @Override
  581. public ResponseJson<List<String>> getProductDetailImages(Integer productId) {
  582. if (productId == null) {
  583. return ResponseJson.error("参数错误:商品Id不能为空!", null);
  584. }
  585. List<ProductImagePo> imageList = shopMapper.getProductImages(productId);
  586. List<String> newList = new ArrayList<>();
  587. if (imageList.size() > 0) {
  588. // 设置老图片路径
  589. imageList.forEach(image -> {
  590. newList.add(ImageUtils.getImageURL("product", image.getImage(), 0, domain));
  591. });
  592. }
  593. return ResponseJson.success(newList);
  594. }
  595. /**
  596. * 商品详情页-相关参数
  597. *
  598. * @param productId 商品Id
  599. */
  600. @Override
  601. public ResponseJson<List<ProductParameterPo>> getProductParameters(Integer productId) {
  602. if (productId == null) {
  603. return ResponseJson.error("参数错误:商品Id不能为空!", null);
  604. }
  605. List<ProductParameterPo> parametersList = shopMapper.getProductParameters(productId);
  606. return ResponseJson.success(parametersList);
  607. }
  608. /**
  609. * 商品详情页-相关推荐
  610. *
  611. * @param productId 商品Id
  612. * @param recommendType 相关推荐类型: 0自动选择, 1手动推荐
  613. * @param userId 用户Id
  614. */
  615. @Override
  616. public ResponseJson<List<ProductListVo>> getProductDetailRecommends(Integer productId, Integer recommendType, Integer userId) {
  617. if (null == productId) {
  618. return ResponseJson.error("商品Id不能为空!", null);
  619. }
  620. // 根据用户Id查询用户身份
  621. Integer identity = 0;
  622. if (null != userId && userId > 0) {
  623. identity = priceMapper.getIdentityByUserId(userId);
  624. if (null == identity) {
  625. identity = 0;
  626. }
  627. }
  628. List<ProductListVo> list = null;
  629. //相关推荐类型 0自动选择(默认); 1手动推荐
  630. if (null == recommendType || 1 != recommendType) {
  631. list = pageMapper.getAutoProductRecommends(productId);
  632. } else {
  633. list = pageMapper.getProductRecommendsById(productId);
  634. }
  635. if (null != list && list.size() > 0) {
  636. // identity: 0个人,1协销,2会员机构,3供应商,4普通机构
  637. // visibility:3:所有人可见,2:普通机构可见,1:会员机构可见
  638. // boolean passFlag = identity ==1 || identity == 2 || product.getVisibility()==3 || (identity == 4 && product.getVisibility()==2);
  639. try {
  640. Integer finalIdentity = identity;
  641. list.removeIf(product -> (null == product || null == product.getVisibility() || !(finalIdentity == 1 || finalIdentity == 2 || product.getVisibility() == 3 || (finalIdentity == 4 && product.getVisibility() == 2))));
  642. list.forEach(product -> {
  643. // 设置 图片路径
  644. product.setImage(ImageUtils.getImageURL("product", product.getImage(), 0, domain));
  645. });
  646. } catch (Exception e) {
  647. log.error("相关推荐", e);
  648. }
  649. }
  650. return ResponseJson.success(list);
  651. }
  652. /**
  653. * 商品维修(链接分享数据)
  654. *
  655. * @param code 维修code
  656. */
  657. @Override
  658. public ResponseJson<ProductRepairVo> getProductRepair(String code) {
  659. if (StringUtils.isEmpty(code)) {
  660. return ResponseJson.error("维修code不能为空!", null);
  661. }
  662. ProductRepairVo repair = null;
  663. // 仪器维修表ID
  664. Integer maintenanceId = pageMapper.getMaintenanceIdByCode(code);
  665. if (null != maintenanceId) {
  666. // 维修详情
  667. repair = pageMapper.getMaintenanceById(maintenanceId);
  668. }
  669. if (null == repair) {
  670. return ResponseJson.error("无效的链接!", null);
  671. }
  672. List<String> imageList = new ArrayList<>();
  673. if (StringUtils.isNotEmpty(repair.getInstrumentImage1())) {
  674. imageList.add(repair.getInstrumentImage1());
  675. }
  676. if (StringUtils.isNotEmpty(repair.getInstrumentImage2())) {
  677. imageList.add(repair.getInstrumentImage2());
  678. }
  679. if (StringUtils.isNotEmpty(repair.getInstrumentImage3())) {
  680. imageList.add(repair.getInstrumentImage3());
  681. }
  682. if (StringUtils.isNotEmpty(repair.getInstrumentImage4())) {
  683. imageList.add(repair.getInstrumentImage4());
  684. }
  685. if (StringUtils.isNotEmpty(repair.getInstrumentImage5())) {
  686. imageList.add(repair.getInstrumentImage5());
  687. }
  688. String[] images = imageList.toArray(new String[imageList.size()]);
  689. repair.setInstrumentArr(images);
  690. String viewerType = repair.getViewerType();
  691. if ("1".equals(viewerType)) {
  692. // 用户可评价展示详细信息
  693. repair.setCanEvaluation(true);
  694. repair.setOnlyBaseInfo(false);
  695. } else if ("3".equals(viewerType)) {
  696. // 供应商不可评价展示详细信息
  697. repair.setCanEvaluation(false);
  698. repair.setOnlyBaseInfo(false);
  699. } else {
  700. // 供应商不可评价展示基础信息
  701. ProductRepairVo repairTemp = new ProductRepairVo();
  702. repairTemp.setCanEvaluation(false);
  703. repairTemp.setOnlyBaseInfo(true);
  704. repairTemp.setViewerType("2");
  705. repairTemp.setUserAddress(repair.getUserAddress());
  706. repairTemp.setInstrumentName(repair.getInstrumentName());
  707. repairTemp.setManufacturer(repair.getManufacturer());
  708. repairTemp.setInstrumentBrand(repair.getInstrumentBrand());
  709. repairTemp.setProblemDescription(repair.getProblemDescription());
  710. return ResponseJson.success(repairTemp);
  711. }
  712. return ResponseJson.success(repair);
  713. }
  714. /**
  715. * 设置跳转参数
  716. *
  717. * @param floorContent FloorContentVo
  718. */
  719. private void setFloorLinkType(FloorContentVo floorContent) {
  720. if (floorContent != null) {
  721. if (StringUtils.isNotBlank(floorContent.getAdsLink1())) {
  722. Integer linkType1 = AppletsLinkUtil.getLinkType(floorContent.getAdsLink1());
  723. floorContent.setLinkType1(linkType1);
  724. floorContent.setLinkParam1(AppletsLinkUtil.getLinkParam(linkType1, floorContent.getAdsLink1()));
  725. }
  726. if (StringUtils.isNotBlank(floorContent.getAdsLink2())) {
  727. Integer linkType2 = AppletsLinkUtil.getLinkType(floorContent.getAdsLink2());
  728. floorContent.setLinkType2(linkType2);
  729. floorContent.setLinkParam2(AppletsLinkUtil.getLinkParam(linkType2, floorContent.getAdsLink2()));
  730. }
  731. if (StringUtils.isNotBlank(floorContent.getAdsLink3())) {
  732. Integer linkType3 = AppletsLinkUtil.getLinkType(floorContent.getAdsLink3());
  733. floorContent.setLinkType3(linkType3);
  734. floorContent.setLinkParam3(AppletsLinkUtil.getLinkParam(linkType3, floorContent.getAdsLink3()));
  735. }
  736. if (StringUtils.isNotBlank(floorContent.getAdsLink4())) {
  737. Integer linkType4 = AppletsLinkUtil.getLinkType(floorContent.getAdsLink4());
  738. floorContent.setLinkType4(linkType4);
  739. floorContent.setLinkParam4(AppletsLinkUtil.getLinkParam(linkType4, floorContent.getAdsLink4()));
  740. }
  741. if (StringUtils.isNotBlank(floorContent.getAdsLink5())) {
  742. Integer linkType3 = AppletsLinkUtil.getLinkType(floorContent.getAdsLink3());
  743. floorContent.setLinkType3(linkType3);
  744. floorContent.setLinkParam3(AppletsLinkUtil.getLinkParam(linkType3, floorContent.getAdsLink3()));
  745. }
  746. }
  747. }
  748. /**
  749. * 设置楼层相关图片的商品信息
  750. */
  751. private void setFloorImageProduct(Integer userId, List<FloorImageVo> floorImageList, Integer source) {
  752. Iterator<FloorImageVo> iterator = floorImageList.iterator();
  753. while (iterator.hasNext()) {
  754. FloorImageVo image = iterator.next();
  755. Integer linkType = AppletsLinkUtil.getLinkType(image.getLink());
  756. Map<String, Object> linkParam = AppletsLinkUtil.getLinkParam(linkType, image.getLink());
  757. image.setLinkType(linkType);
  758. image.setLinkParam(linkParam);
  759. if (image.getProductId() != null) {
  760. // 获取商品及价格
  761. ProductItemVo product = pageMapper.getProductItemById(image.getProductId());
  762. if (product != null) {
  763. // 商品价格
  764. priceUtilService.setProductDetails(userId, product);
  765. // 设置商品主图
  766. image.setListType(1);
  767. image.setName(product.getName());
  768. image.setImage(ImageUtils.getImageURL("product", product.getImage(), 0, domain));
  769. image.setProduct(product);
  770. if (userId != null) {
  771. if (product.getUserIdentity() > 0) {
  772. if (4 == product.getUserIdentity() && "1".equals(product.getVisibility())) {
  773. iterator.remove();
  774. }
  775. } else {
  776. if ("1".equals(product.getVisibility()) || "2".equals(product.getVisibility())) {
  777. iterator.remove();
  778. }
  779. }
  780. } else {
  781. if ("1".equals(product.getVisibility()) || "2".equals(product.getVisibility())) {
  782. iterator.remove();
  783. }
  784. }
  785. //优惠券标识
  786. Boolean couponsLogo = setCouponsLogo(userId, image.getProductId(), source);
  787. product.setCouponsLogo(couponsLogo);
  788. } else {
  789. iterator.remove();
  790. }
  791. } else {
  792. image.setListType(2);
  793. }
  794. }
  795. }
  796. /**
  797. * 优惠券标识是否显示
  798. *
  799. * @param userId 机构用户id
  800. * @param productId 商品id
  801. * @param source 来源 : 1 网站 ; 2 小程序
  802. * @return
  803. */
  804. @Override
  805. public Boolean setCouponsLogo(Integer userId, Integer productId, Integer source) {
  806. boolean couponsLogo = false;
  807. ProductDetailVo product = pageMapper.getProductDetails(productId);
  808. List<CouponVo> couponList = pageMapper.findAllCoupon(userId);
  809. if (couponList != null && couponList.size() > 0) {
  810. for (CouponVo coupon : couponList) {
  811. if (coupon.getCouponType() == 4 || coupon.getCouponType() == 2) {
  812. //用户券与用户专享券
  813. couponsLogo = true;
  814. break;
  815. }
  816. if (coupon.getCouponType() == 0) {
  817. if (coupon.getProductType() == 1) {
  818. //活动券-全商城商品
  819. couponsLogo = true;
  820. break;
  821. } else {
  822. //活动券-指定商品
  823. List<Integer> productIds = pageMapper.findAllProductId(coupon.getCouponId(), source);
  824. if (productIds.contains(productId)) {
  825. couponsLogo = true;
  826. break;
  827. }
  828. }
  829. }
  830. if (coupon.getCouponType() == 3 && product.getShopId().equals(coupon.getShopId())) {
  831. //店铺券
  832. couponsLogo = true;
  833. break;
  834. }
  835. if (coupon.getCouponType() == 1 && coupon.getCategoryType().equals(product.getCommodityType())) {
  836. //品类券
  837. couponsLogo = true;
  838. break;
  839. }
  840. }
  841. }
  842. return couponsLogo;
  843. }
  844. /**
  845. * 商品资料列表
  846. * @param keyword 搜索关键词
  847. * @param productType 商品属性:1产品,2仪器
  848. * @param pageNum 页码
  849. * @param pageSize 每页数量
  850. * @return
  851. */
  852. @Override
  853. public ResponseJson<PaginationVo<ArchiveVo>> getProductArchive(String keyword, Integer productType, Integer pageNum, Integer pageSize) {
  854. PageHelper.startPage(pageNum, pageSize);
  855. List<ArchiveVo> archiveList = pageMapper.getProductArchiveList(keyword, productType);
  856. archiveList.forEach(archive->{
  857. if (null != archive.getProductId()) {
  858. String imageURL = ImageUtils.getImageURL("product", archive.getProductImage(), 0, domain);
  859. archive.setProductImage(imageURL);
  860. }
  861. });
  862. PaginationVo<ArchiveVo> pageData = new PaginationVo<>(archiveList);
  863. return ResponseJson.success(pageData);
  864. }
  865. /**
  866. * 商品资料内容
  867. * @param archiveId 商品资料id
  868. * @param userId 用户id
  869. * @return
  870. */
  871. @Override
  872. public ResponseJson<ArchiveDetailVo> getArchiveDetail(Integer archiveId, Integer userId) {
  873. ArchivePo archive = pageMapper.getArchiveByArchiveId(archiveId);
  874. if (null == archive) {
  875. return ResponseJson.error("商品资料不存在", null);
  876. }
  877. // 判断该用户是否拥有访问该资料的权限
  878. int permission = checkArchivePermission(archive, userId);
  879. List<ArchiveContentVo> imageArchiveList = pageMapper.getImageArchiveList(archiveId);
  880. List<ArchiveContentVo> videoArchiveList = pageMapper.getVideoArchiveList(archiveId);
  881. List<ArchiveContentVo> fileArchiveList = pageMapper.getFileArchiveList(archiveId);
  882. if (imageArchiveList.size() == 0 && videoArchiveList.size() == 0 && fileArchiveList.size() == 0) {
  883. // 没有文件的时候,用户可查看资料
  884. permission = 0;
  885. }
  886. int finalPermission = permission;
  887. imageArchiveList.forEach(imageArchive->{
  888. List<String> imageList = pageMapper.getArchiveImageList(imageArchive.getArchiveContentId());
  889. if (0 == finalPermission) {
  890. imageArchive.setImageList(imageList);
  891. }
  892. imageArchive.setImageNum(imageList.size());
  893. });
  894. videoArchiveList.forEach(videoArchive->{
  895. ArchiveFilePo archiveFile = pageMapper.getArchiveFile(videoArchive.getArchiveContentId());
  896. if (0 == finalPermission) {
  897. String fileUrl = generateFileUrl(archiveFile);
  898. videoArchive.setFileUrl(fileUrl);
  899. }
  900. });
  901. fileArchiveList.forEach(fileArchive->{
  902. ArchiveFilePo archiveFile = pageMapper.getArchiveFile(fileArchive.getArchiveContentId());
  903. fileArchive.setFileName(archiveFile.getFileName());
  904. if (0 == finalPermission) {
  905. String fileUrl = generateFileUrl(archiveFile);
  906. fileArchive.setFileUrl(fileUrl);
  907. }
  908. });
  909. ArchiveDetailVo archiveDetail = new ArchiveDetailVo();
  910. archiveDetail.setImageArchiveList(imageArchiveList);
  911. archiveDetail.setVideoArchiveList(videoArchiveList);
  912. archiveDetail.setFileArchiveList(fileArchiveList);
  913. archiveDetail.setPermission(permission);
  914. archiveDetail.setProductImage(archive.getProductImage());
  915. archiveDetail.setProductName(archive.getProductName());
  916. archiveDetail.setProductType(archive.getProductType());
  917. archiveDetail.setShopName(archive.getShopName());
  918. return ResponseJson.success(archiveDetail);
  919. }
  920. private Integer checkArchivePermission(ArchivePo archive, Integer userId) {
  921. //资料等级:1一类资料,2二类资料,3三类资料
  922. Integer archiveLevel = archive.getArchiveLevel();
  923. //商品分类:1医美,2生美
  924. Integer productClassify = archive.getProductClassify();
  925. // 根据用户Id查询用户身份
  926. Integer identity = priceMapper.getIdentityByUserId(userId);
  927. // 1生美机构,2医美机构
  928. Integer clubType = pageMapper.getClubTypeByUserId(userId);
  929. // permission:0可查看,1未登录,2需升级会员机构,3需升级医美会员机构,4需要抵扣采美豆,5无权限查看
  930. int permission;
  931. if (null == identity) {
  932. // 未登录
  933. permission = 1;
  934. } else if (1 == identity) {
  935. //协销可查看所有资料
  936. permission = 0;
  937. } else if (4 == identity) {
  938. // 普通机构
  939. if (archiveLevel > 1) {
  940. // 二级资料,普通机构
  941. permission = 2 == productClassify ? 2 : 3;
  942. } else {
  943. permission = 0;
  944. }
  945. } else if (2 == identity) {
  946. // 会员机构
  947. if (2 == archiveLevel && 1 == productClassify && (0 == clubType || 2 == clubType)) {
  948. // 二级医美资料,生美会员机构
  949. permission = 3;
  950. } else if (3 == archiveLevel) {
  951. // 查询用户对该资料的抵扣记录
  952. Integer historyId = pageMapper.findBeansHistoryByArchiveId(userId, archive.getArchiveId());
  953. if (1 == productClassify && (0 == clubType || 2 == clubType)) {
  954. // 三级医美资料,生美会员机构
  955. permission = 3;
  956. } else if (null == historyId){
  957. permission = 4;
  958. } else {
  959. permission = 0;
  960. }
  961. } else {
  962. permission = 0;
  963. }
  964. } else{
  965. permission = 5;
  966. }
  967. return permission;
  968. }
  969. public String generateFileUrl(ArchiveFilePo archiveFile) {
  970. OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
  971. String ossName = archiveFile.getOssName();
  972. // 设置URL过期时间为1个小时
  973. Date expiration = new Date(System.currentTimeMillis() + 3600L * 1000);
  974. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  975. try {
  976. Date dateOne = format.parse("2021-06-01 00:00:00");
  977. Date dateTwo = format.parse("2021-09-17 18:00:00");
  978. if (archiveFile.getUploadTime() != null && archiveFile.getUploadTime().compareTo(dateOne) > 0 && archiveFile.getUploadTime().compareTo(dateTwo) < 0) {
  979. ossName = active + "/" + ossName;
  980. } else if (archiveFile.getUploadTime() != null && archiveFile.getUploadTime().compareTo(dateTwo)>0){
  981. ossName = active + "/archiveFile/" + ossName;
  982. }
  983. } catch (ParseException e) {
  984. log.info("格式化时间错误", e);
  985. }
  986. String url = ossClient.generatePresignedUrl(bucketName, ossName, expiration).toString();
  987. ossClient.shutdown();
  988. return url;
  989. }
  990. }