AuthServiceImpl.java 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176
  1. package com.caimei.service.auth.impl;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.caimei.annotation.CurrentUser;
  6. import com.caimei.components.RedisService;
  7. import com.caimei.config.FastDfsClient;
  8. import com.caimei.mapper.cmMapper.AuthMapper;
  9. import com.caimei.mapper.cmMapper.AuthProductMapper;
  10. import com.caimei.mapper.cmMapper.ClubMapper;
  11. import com.caimei.mapper.ldmMapper.LdmMapper;
  12. import com.caimei.model.ResponseJson;
  13. import com.caimei.model.po.*;
  14. import com.caimei.model.vo.*;
  15. import com.caimei.service.auth.AuthProductService;
  16. import com.caimei.service.auth.AuthService;
  17. import com.caimei.service.auth.ShopService;
  18. import com.caimei.service.auth.UploadService;
  19. import com.caimei.utils.*;
  20. import com.github.pagehelper.PageHelper;
  21. import com.github.pagehelper.PageInfo;
  22. import lombok.extern.slf4j.Slf4j;
  23. import lombok.val;
  24. import org.apache.commons.lang3.ObjectUtils;
  25. import org.apache.commons.lang3.StringUtils;
  26. import org.apache.http.Consts;
  27. import org.apache.http.HttpEntity;
  28. import org.apache.http.NameValuePair;
  29. import org.apache.http.client.entity.UrlEncodedFormEntity;
  30. import org.apache.http.client.methods.CloseableHttpResponse;
  31. import org.apache.http.client.methods.HttpGet;
  32. import org.apache.http.client.methods.HttpPost;
  33. import org.apache.http.client.utils.URIBuilder;
  34. import org.apache.http.entity.ContentType;
  35. import org.apache.http.entity.StringEntity;
  36. import org.apache.http.entity.mime.MultipartEntityBuilder;
  37. import org.apache.http.impl.client.CloseableHttpClient;
  38. import org.apache.http.impl.client.HttpClients;
  39. import org.apache.http.message.BasicNameValuePair;
  40. import org.apache.http.util.EntityUtils;
  41. import org.apache.ibatis.annotations.Param;
  42. import org.apache.poi.ss.usermodel.*;
  43. import org.apache.poi.xssf.usermodel.*;
  44. import org.springframework.beans.factory.annotation.Autowired;
  45. import org.springframework.beans.factory.annotation.Value;
  46. import org.springframework.core.io.ClassPathResource;
  47. import org.springframework.stereotype.Service;
  48. import org.springframework.transaction.annotation.Transactional;
  49. import org.springframework.transaction.interceptor.TransactionAspectSupport;
  50. import org.springframework.util.Assert;
  51. import org.springframework.web.bind.annotation.*;
  52. import org.springframework.web.multipart.MultipartFile;
  53. import javax.annotation.Resource;
  54. import javax.imageio.ImageIO;
  55. import javax.servlet.ServletOutputStream;
  56. import javax.servlet.http.HttpServletRequest;
  57. import javax.servlet.http.HttpServletResponse;
  58. import javax.swing.*;
  59. import java.awt.*;
  60. import java.awt.Font;
  61. import java.io.*;
  62. import java.math.BigDecimal;
  63. import java.net.URISyntaxException;
  64. import java.net.URL;
  65. import java.nio.charset.StandardCharsets;
  66. import java.text.SimpleDateFormat;
  67. import java.util.*;
  68. import java.util.List;
  69. import java.util.regex.Matcher;
  70. import java.util.regex.Pattern;
  71. import java.util.stream.Collectors;
  72. import java.util.stream.Stream;
  73. /**
  74. * Description
  75. *
  76. * @author : Aslee
  77. * @date : 2021/5/11
  78. */
  79. @Slf4j
  80. @Service
  81. public class AuthServiceImpl implements AuthService {
  82. @Resource
  83. private AuthMapper authMapper;
  84. @Resource
  85. private LdmMapper ldmMapper;
  86. @Value("${caimei.zpapi}")
  87. private String zpServer;
  88. private AuthProductService authProductService;
  89. @Autowired
  90. public void setAuthProductService(AuthProductService authProductService) {
  91. this.authProductService = authProductService;
  92. }
  93. private ShopService shopService;
  94. @Autowired
  95. public void setShopService(ShopService shopService) {
  96. this.shopService = shopService;
  97. }
  98. private UploadService uploadService;
  99. @Autowired
  100. public void setUploadService(UploadService uploadService) {
  101. this.uploadService = uploadService;
  102. }
  103. @Value("${spring.profiles.active}")
  104. private String active;
  105. @Autowired
  106. private FastDfsClient client;
  107. @Value("${caimei.imageDomain}")
  108. private String imageDomain;
  109. @Resource
  110. private RedisService redisService;
  111. @Resource
  112. private ClubMapper clubMapper;
  113. @Override
  114. public ResponseJson<PageInfo<AuthVo>> getAuthList(Integer listType, Integer authUserId, String authParty,
  115. String mobile, Integer status, Integer starFlag, Integer auditStatus,
  116. Integer lowerAuditStatus, Integer shopAuditStatus, Integer sendStatus,String authCode, Integer pageNum, Integer pageSize) {
  117. listType = null == listType ? 1 : listType;
  118. PageHelper.startPage(pageNum, pageSize);
  119. List<AuthVo> authList = authMapper.getAuthList(listType, authUserId, authParty, mobile, status, starFlag, auditStatus, lowerAuditStatus, shopAuditStatus, sendStatus,authCode);
  120. PageInfo<AuthVo> pageData = new PageInfo<>(authList);
  121. return ResponseJson.success(pageData);
  122. }
  123. @Override
  124. public ResponseJson<PageInfo<AuthVo>> getAuthListAll(Integer listType, Integer authUserId, String authParty,
  125. String mobile, Integer status, Integer starFlag, Integer auditStatus,
  126. Integer lowerAuditStatus, Integer shopAuditStatus, Integer sendStatus, String name, String snCode, Integer pageNum, Integer pageSize) {
  127. listType = null == listType ? 1 : listType;
  128. PageHelper.startPage(pageNum, pageSize);
  129. List<AuthVo> authList = authMapper.getAuthListAll(listType, authUserId, authParty, mobile, status, starFlag, auditStatus, lowerAuditStatus, shopAuditStatus, sendStatus, name, snCode);
  130. PageInfo<AuthVo> pageData = new PageInfo<>(authList);
  131. return ResponseJson.success(pageData);
  132. }
  133. @Override
  134. public ResponseJson updateAuthStatus(Integer authId, Integer status) {
  135. if (null == authId) {
  136. return ResponseJson.error("请输入授权id");
  137. }
  138. if (null == status) {
  139. return ResponseJson.error("请输入要更新的状态值");
  140. }
  141. authMapper.updateAuthStatusByAuthId(authId, status);
  142. if (0 == status) {
  143. return ResponseJson.success("下线品牌授权成功");
  144. } else {
  145. return ResponseJson.success("上线品牌授权成功");
  146. }
  147. }
  148. @Override
  149. public ResponseJson deleteAuth(Integer authId) {
  150. if (null == authId) {
  151. return ResponseJson.error("参数异常,请输入授权id");
  152. }
  153. // 删除品牌授权
  154. authMapper.deleteAuthByAuthId(authId);
  155. // 删除轮播图
  156. authMapper.deleteBanner(authId);
  157. // 删除商品及商品参数
  158. List<Integer> productIdList = authProductService.getProductIdsByAuthId(authId);
  159. productIdList.forEach(productId -> {
  160. if (null != productId) {
  161. authProductService.deleteProduct(productId);
  162. }
  163. });
  164. return ResponseJson.success("删除品牌授权成功");
  165. }
  166. @Override
  167. public ResponseJson<AuthFormVo> getAuthFormData(Integer authId) {
  168. if (null == authId) {
  169. return ResponseJson.error("参数异常,机构id不能为空", null);
  170. }
  171. AuthFormVo authFormVo = authMapper.getAuthFormById(authId);
  172. //该机构关联机构用集合形式返回便于前端赋值
  173. if (null != authFormVo.getRelationId() && !"".equals(authFormVo.getRelationId())) {
  174. String[] relationIdList = authFormVo.getRelationId().split(",");
  175. List<AuthFormVo> authIdList = authMapper.getAuthIdList(relationIdList);
  176. authFormVo.setReleationClubList(authIdList);
  177. }
  178. if (null != authFormVo.getLng()) {
  179. authFormVo.setLngAndLat(authFormVo.getLng() + "," + authFormVo.getLat());
  180. }
  181. List<String> bannerList = authMapper.getBannerList(authId);
  182. authFormVo.setBannerList(bannerList);
  183. return ResponseJson.success(authFormVo);
  184. }
  185. @Override
  186. public ResponseJson<List<AuthVo>> getAuthSelectList(Integer authUserId) {
  187. List<AuthVo> authList = authMapper.getAuthList(1, authUserId, null, null, null, null, null, null, null, null,null);
  188. return ResponseJson.success(authList);
  189. }
  190. @Override
  191. public ResponseJson importLdmImage(Integer authUserId) {
  192. List<LdmDataPo> ldmClubData = ldmMapper.getLdmClubData(null, 0);
  193. ldmClubData.forEach(ldmClub -> {
  194. String pic2 = ldmClub.getPic2();
  195. String pic3 = ldmClub.getPic3();
  196. String pic4 = ldmClub.getPic4();
  197. List<AuthVo> authList = authMapper.getAuthByNameAndAddress(ldmClub.getAuthParty(), ldmClub.getAddress());
  198. if (null != authList && authList.size() > 0) {
  199. if (authList.size() > 1) {
  200. log.info(">>>>>>>>>>>>>>>>>>>>>导入ldm门店图错误:对应门店过多,门店名称:" + ldmClub.getAuthParty());
  201. } else {
  202. AuthVo auth = authList.get(0);
  203. Integer authId = auth.getAuthId();
  204. if (StringUtils.isNotEmpty(pic2) || StringUtils.isNotEmpty(pic3) || StringUtils.isNotEmpty(pic4)) {
  205. authMapper.deleteBanner(authId);
  206. insertBanner(pic2, authId);
  207. insertBanner(pic3, authId);
  208. insertBanner(pic4, authId);
  209. }
  210. if (StringUtils.isNotEmpty(ldmClub.getRemarks())) {
  211. authMapper.updateRemarks(authId, ldmClub.getRemarks());
  212. }
  213. }
  214. } else {
  215. log.info(">>>>>>>>>>>>>>>>>>>>>导入ldm门店图错误:找不到对应门店,门店名称:" + ldmClub.getAuthParty());
  216. }
  217. });
  218. return ResponseJson.success();
  219. }
  220. @Override
  221. public ResponseJson checkAuth(Integer authId) {
  222. authMapper.checkAuth(authId);
  223. return ResponseJson.success();
  224. }
  225. @Override
  226. public ResponseJson starAuth(Integer authId, Integer starFlag, String starNum) {
  227. authMapper.starAuth(authId, starFlag, starNum);
  228. return ResponseJson.success();
  229. }
  230. private void insertBanner(String pic, Integer authId) {
  231. if (StringUtils.isNotEmpty(pic)) {
  232. String imagePath = "https://wangdian.skinovachina.com" + pic;
  233. String fileName = imagePath.substring(imagePath.lastIndexOf("/") + 1);
  234. try {
  235. String banner = uploadService.saveFileByUrl(imagePath, fileName);
  236. authMapper.insertBanner(authId, banner);
  237. } catch (Exception e) {
  238. e.printStackTrace();
  239. }
  240. }
  241. }
  242. @Override
  243. public ResponseJson saveAuth(CmBrandAuthPo auth, List<String> bannerList, boolean importFlag, Integer source) {
  244. Integer authId = auth.getId();
  245. boolean insertFlag = null == authId;
  246. AuthVo dbAuth = null;
  247. if (!insertFlag) {
  248. dbAuth = authMapper.getAuthById(authId);
  249. }
  250. String authParty = auth.getAuthParty();
  251. if (StringUtils.isBlank(authParty)) {
  252. return ResponseJson.error("参数异常,请输入授权机构名称");
  253. }
  254. if (null == auth.getFirstClubType()) {
  255. return ResponseJson.error("请勾选机构类型");
  256. }
  257. if ((1 == auth.getFirstClubType() || 2 == auth.getFirstClubType()) && null == auth.getSecondClubType()) {
  258. return ResponseJson.error("请勾选二级机构类型");
  259. }
  260. if (1 == auth.getFirstClubType() && StringUtils.isEmpty(auth.getMedicalLicenseImage())) {
  261. return ResponseJson.error("请上传医疗许可证");
  262. }
  263. if (null == auth.getEmpNum()) {
  264. return ResponseJson.error("请输入员工人数");
  265. }
  266. if (1 == source) {
  267. if (null == auth.getCreateBy()) {
  268. return ResponseJson.error("参数异常,请输入创建人id");
  269. }
  270. /*if (1 == auth.getAuthImageType() && StringUtils.isEmpty(auth.getAuthImageLogo())) {
  271. return ResponseJson.error("授权牌logo不能为空");
  272. }*/
  273. if (2 == auth.getAuthImageType() && StringUtils.isEmpty(auth.getAuthImage())) {
  274. return ResponseJson.error("授权牌不能为空");
  275. }
  276. } else {
  277. // 机构添加默认模板库生成
  278. auth.setAuthImageType(1);
  279. }
  280. if (!importFlag) {
  281. if (null == auth.getProvinceId() || null == auth.getCityId() || null == auth.getTownId() || StringUtils.isEmpty(auth.getAddress()) || null == auth.getLng() || null == auth.getLat()) {
  282. return ResponseJson.error("参数异常,地址信息异常");
  283. }
  284. if (StringUtils.isEmpty(auth.getLogo())) {
  285. return ResponseJson.error("参数异常,请上传机构logo");
  286. }
  287. if (null == bannerList || bannerList.size() <= 0) {
  288. return ResponseJson.error("参数异常,请上传轮播图");
  289. }
  290. }
  291. // 供应商保存,直接上线;机构保存,需要供应商审核通过后才上线
  292. if (null != dbAuth && 1 != dbAuth.getAuditStatus()) {
  293. // 被驳回的数据,编辑变为待审核状态
  294. auth.setStatus(2);
  295. auth.setAuditStatus(2);
  296. } else {
  297. auth.setStatus(1 == source ? 1 : 2);
  298. auth.setAuditStatus(1 == source ? 1 : 2);
  299. }
  300. Integer adminUserId = authMapper.getAdminUserId();
  301. auth.setAuditBy(adminUserId);
  302. auth.setAuditTime(new Date());
  303. if (1 == source) {
  304. auth.setShopAuditBy(auth.getCreateBy());
  305. auth.setShopAuditTime(new Date());
  306. }
  307. auth.setDelFlag(0);
  308. auth.setCheckFlag(0);
  309. auth.setShopAuditStatus(1 == source ? 1 : 2);
  310. /*
  311. 保存授权
  312. */
  313. if (insertFlag) {
  314. authMapper.insertAuth(auth);
  315. } else {
  316. //机构互关
  317. relaMech(auth);
  318. authMapper.updateAuthByAuthId(auth);
  319. // 删除原有的轮播图
  320. authMapper.deleteBanner(auth.getId());
  321. }
  322. // 保存之后生成授权牌和水印授权牌
  323. String authImage = null;
  324. if (1 == auth.getAuthImageType()) {
  325. // 模板库生成
  326. // 获取对应模板
  327. TemplateVo authTemplate = authMapper.getAuthTemplate(auth.getId(), null, 1);
  328. authImage = generateAuthImage(authTemplate, auth);
  329. auth.setAuthImage(authImage);
  330. }
  331. // 添加水印
  332. if (StringUtils.isNotEmpty(auth.getAuthImage())) {
  333. auth.setPcAuthImage(addWaterMark(auth.getAuthImage(), 1));
  334. auth.setAppletsAuthImage(addWaterMark(auth.getAuthImage(), 2));
  335. authMapper.updateAuthImage(auth);
  336. }
  337. // 保存轮播图
  338. if (null != bannerList) {
  339. bannerList.forEach(banner -> authMapper.insertBanner(auth.getId(), banner));
  340. }
  341. return ResponseJson.success("保存品牌授权成功", auth);
  342. }
  343. /**
  344. * 机构互关
  345. * @param auth
  346. */
  347. public void relaMech(CmBrandAuthPo auth){
  348. if(null!=auth&&StringUtils.isNotEmpty(auth.getRelationId())&&StringUtils.isNotEmpty(auth.getRelationName())){
  349. String[] relaIdArr = auth.getRelationId().split(",");
  350. for(int i=0;i<relaIdArr.length;i++){
  351. String relaId=auth.getId().toString();
  352. String relaName=auth.getAuthParty();
  353. Integer id = Integer.valueOf(relaIdArr[i]);
  354. //先获取该机构是否与其他机构关联,有则合并
  355. CmBrandAuthPo relationInfo = authMapper.getRelationInfo(id);
  356. if(null!=relationInfo&&StringUtils.isNotEmpty(relationInfo.getRelationId())&&StringUtils.isNotEmpty(relationInfo.getRelationName())){
  357. //避免保存一样的数据
  358. if(!relationInfo.getRelationId().contains(relaId)&&!relationInfo.getRelationName().contains(relaName)){
  359. relaId=relaId+","+relationInfo.getRelationId();
  360. relaName=relaName+","+relationInfo.getRelationName();
  361. authMapper.updateRelaByAuthId(id,relaId,relaName);
  362. }
  363. }else {
  364. authMapper.updateRelaByAuthId(id,relaId,relaName);
  365. }
  366. }
  367. }
  368. }
  369. @Override
  370. public String addWaterMark(String image, Integer type) {
  371. try {
  372. //type:1pc,2applets
  373. ClassPathResource classPathResource = new ClassPathResource("/images/newPcWaterMark.png");
  374. InputStream inputStreamImg = classPathResource.getInputStream();
  375. Image pcWaterMarkImg = ImageIO.read(inputStreamImg);
  376. classPathResource = new ClassPathResource("/images/newAppletsWaterMark.png");
  377. inputStreamImg = classPathResource.getInputStream();
  378. Image appletsWaterMarkImg = ImageIO.read(inputStreamImg);
  379. String img = ImageUtils.markImageByIcon(type == 1 ? pcWaterMarkImg : appletsWaterMarkImg, image, null);
  380. String imagePath = null;
  381. if (StringUtils.isNotEmpty(img)) {
  382. MultipartFile imgFile = Base64Util.base64ToMultipart(img);
  383. if (null != imgFile) {
  384. imagePath = uploadService.saveFile(imgFile);
  385. }
  386. log.info(">>>>>>>>>>>>>>>>水印图片上传成功:" + imagePath);
  387. } else {
  388. log.info(">>>>>>>>>>>>>>>>水印图片上传失败");
  389. }
  390. return imagePath;
  391. } catch (Exception e) {
  392. e.printStackTrace();
  393. }
  394. return null;
  395. }
  396. @Override
  397. public String generateAuthImage(TemplateVo authTemplate, CmBrandAuthPo auth) {
  398. if (null != authTemplate) {
  399. // 根据模板id设置相关数据
  400. Map<String, Object> templateInfo = getTemplateInfo(authTemplate, auth);
  401. Object templateImage = templateInfo.get("templateImage");
  402. if (null != templateImage) {
  403. String authImage = ImageUtils.generateAuthImage(templateInfo);
  404. log.info("【图片上传】>>>>>>>>>>>>>>>>图片临时路径:" + authImage);
  405. // 临时图片
  406. File tempFile = new File(authImage);
  407. String imageUrl = null;
  408. try {
  409. imageUrl = imageDomain + "/" + client.uploadFile(authImage);
  410. } catch (Exception e) {
  411. e.printStackTrace();
  412. }
  413. // 删除临时图片
  414. boolean delete = tempFile.delete();
  415. log.info("【图片上传】>>>>>>>>>>>>>>>>删除临时图片:" + delete);
  416. return imageUrl;
  417. } else {
  418. return null;
  419. }
  420. }
  421. return null;
  422. }
  423. private Map<String, Object> getTemplateInfo(TemplateVo template, CmBrandAuthPo auth) {
  424. HashMap<String, Object> map = new HashMap<>();
  425. Integer templateId = template.getTemplateId();
  426. if (1 == templateId) {
  427. map.put("templateImage", template.getTemplateImage());
  428. double rate = 0.15;
  429. if (StringUtils.isNotEmpty(auth.getAuthImageLogo())) {
  430. // 获取授权牌logo位置
  431. try {
  432. ImageIcon imageIcon = new ImageIcon(new URL(template.getTemplateImage()));
  433. Image srcImg = imageIcon.getImage();
  434. int srcWidth = srcImg.getWidth(null);
  435. ImageIcon authImageLogo = new ImageIcon(new URL(auth.getAuthImageLogo()));
  436. Image authLogo = authImageLogo.getImage();
  437. int authLogoWidth = authLogo.getWidth(null);
  438. int x = (srcWidth - (int) Math.round(238 * rate) - authLogoWidth) / 2 + (int) Math.round(238 * rate);
  439. int y = (int) Math.round(1230 * rate);
  440. map.put("addImage1_x", x);
  441. map.put("addImage1_y", y);
  442. map.put("addImage1_image", auth.getAuthImageLogo());
  443. } catch (Exception e) {
  444. e.printStackTrace();
  445. }
  446. }
  447. // 添加认证编号信息
  448. if (StringUtils.isNotEmpty(auth.getAuthCode())) {
  449. map.put("addWord1_content", auth.getAuthCode());
  450. map.put("addWord1_color", "218,185,107");
  451. map.put("addWord1_type", "思源宋体");
  452. map.put("addWord1_style", Font.BOLD);
  453. map.put("addWord1_size", (int) Math.round(90 * rate));
  454. map.put("addWord1_x", (int) Math.round(2168 * rate));
  455. map.put("addWord1_y", (int) Math.round(3157 * rate));
  456. }
  457. // 添加认证日期信息
  458. if (null != auth.getAuthDate()) {
  459. SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
  460. map.put("addWord2_content", format.format(auth.getAuthDate()));
  461. map.put("addWord2_color", "218,185,107");
  462. map.put("addWord2_type", "思源宋体");
  463. map.put("addWord2_style", Font.PLAIN);
  464. map.put("addWord2_size", (int) Math.round(90 * rate));
  465. map.put("addWord2_x", (int) Math.round(2085 * rate));
  466. map.put("addWord2_y", (int) Math.round(3289 * rate));
  467. }
  468. // 添加二维码信息
  469. if (StringUtils.isNotEmpty(template.getQrPosition())) {
  470. String qrCodeLink = zpServer + "/" + auth.getAuthUserId() + "/" + authMapper.getPrefix(auth.getAuthUserId()) + "/approve/club/detail?id=" + auth.getId();
  471. map.put("addQr1_link", qrCodeLink);
  472. map.put("addQr1_size", template.getQrSize());
  473. String[] split = template.getQrPosition().split(",");
  474. if (split.length == 2) {
  475. map.put("addQr1_x", Integer.parseInt(split[0]));
  476. map.put("addQr1_y", Integer.parseInt(split[1]));
  477. }
  478. }
  479. }
  480. return map;
  481. }
  482. @Override
  483. public ResponseJson auditAuth(Integer authId, Integer auditStatus, String invalidReason, Integer auditBy, Integer source) {
  484. if (authId == null) {
  485. return ResponseJson.error("请输入授权id");
  486. }
  487. if (auditStatus == null) {
  488. return ResponseJson.error("请输入审核结果");
  489. }
  490. if (auditStatus == 0 && StringUtils.isEmpty(invalidReason)) {
  491. return ResponseJson.error("请输入审核不通过的原因");
  492. }
  493. source = null == source ? 1 : source;
  494. Date auditTime = new Date();
  495. // 授权状态更新
  496. Integer status = null;
  497. if (auditStatus == 0) {
  498. // 审核不通过,下线授权
  499. status = 0;
  500. } else {
  501. // 审核通过,上线授权
  502. status = 1;
  503. //更新authid到V1.7.7ross挑战赛机构信息表
  504. //获取clubruserid
  505. Integer clubUserId = authMapper.getClubUserIdByAuthId(authId);
  506. //1.7.7ross挑战赛新加逻辑:更新机构信息到挑战赛表
  507. clubMapper.upAuthByid(clubUserId,authId);
  508. clubMapper.upVideoAuthByid(clubUserId,authId);
  509. }
  510. if (1 == source) {
  511. authMapper.updateAuthAuditStatus(authId, status, auditStatus, invalidReason, auditBy, auditTime);
  512. }
  513. if (2 == source) {
  514. authMapper.updateAuthShopAuditStatus(authId, status, auditStatus, invalidReason, auditBy, auditTime);
  515. }
  516. return ResponseJson.success("审核机构认证成功");
  517. }
  518. @Override
  519. @Transactional(rollbackFor = Exception.class)
  520. public ResponseJson importDataByExcel(MultipartFile file, Integer authUserId, Integer createBy) {
  521. String originalFilename = file.getOriginalFilename();
  522. String randomStr = UUID.randomUUID().toString();
  523. assert originalFilename != null;
  524. int index = originalFilename.lastIndexOf(".");
  525. String extName = originalFilename.substring(index);
  526. String filePath = "/mnt/newdatadrive/data/runtime/jar-instance/zplma/tempFile/";
  527. if ("dev".equals(active)) {
  528. filePath = "D:\\WorkSpace\\file\\tempImport\\";
  529. }
  530. filePath += randomStr + extName;
  531. try {
  532. File tempFile = new File(filePath);
  533. if (!tempFile.exists()) {
  534. tempFile.mkdirs();
  535. }
  536. file.transferTo(tempFile);
  537. return saveExcelData(filePath, authUserId, createBy);
  538. } catch (IOException e) {
  539. e.printStackTrace();
  540. }
  541. log.info(">>>>>>>>>>>>>>>>文件临时路径:" + filePath);
  542. return null;
  543. }
  544. private ResponseJson saveExcelData(String filePath, Integer authUserId, Integer createBy) {
  545. //判断是否为excel类型文件
  546. if (!filePath.endsWith(".xls") && !filePath.endsWith(".xlsx")) {
  547. System.out.println("文件不是excel类型");
  548. }
  549. // 获取供应商品牌
  550. List<String> shopBrands = shopService.getShopBrands(authUserId);
  551. // 授权列表
  552. List<CmBrandAuthPo> authImportList = new ArrayList<>();
  553. try {
  554. FileInputStream fis = new FileInputStream(filePath);
  555. // 得到表格数据
  556. XSSFWorkbook workbook = new XSSFWorkbook(fis);
  557. //得到第一个工作表(机构表)
  558. XSSFSheet authPartySheet = workbook.getSheetAt(0);
  559. //获得表头
  560. Row rowHead = authPartySheet.getRow(0);
  561. //判断表头是否正确
  562. if (9 != rowHead.getLastCellNum() || !"机构名称".equals(rowHead.getCell(0).getStringCellValue())) {
  563. return ResponseJson.error("授权机构表格式错误");
  564. }
  565. // 获得数据的总行数
  566. int authPartyRowNum = authPartySheet.getLastRowNum();
  567. //获得所有数据
  568. for (int i = 1; i <= authPartyRowNum; i++) {
  569. //获得第i行对象
  570. Row authPartyRow = authPartySheet.getRow(i);
  571. if (null == authPartyRow) {
  572. break;
  573. }
  574. Cell cell = null;
  575. // 校验机构名称
  576. cell = authPartyRow.getCell(0);
  577. String authParty = null;
  578. if(null != cell){
  579. cell.setCellType(CellType.STRING);
  580. authParty = cell.getStringCellValue();
  581. }
  582. if (StringUtils.isBlank(authParty)) {
  583. return ResponseJson.error("第" + i + 1 + "行机构名称不能为空");
  584. }
  585. // 校验省市区
  586. cell = authPartyRow.getCell(1);
  587. cell.setCellType(CellType.STRING);
  588. String area = cell.getStringCellValue();
  589. if (StringUtils.isBlank(area)) {
  590. return ResponseJson.error("第" + i + 1 + "行所在地区不能为空");
  591. }
  592. String[] areaSplit = area.split("/");
  593. if (areaSplit.length < 2 || areaSplit.length > 3) {
  594. return ResponseJson.error("第" + i + 1 + "行所在地区格式错误");
  595. }
  596. // 省份
  597. String provinceName = areaSplit[0];
  598. if (StringUtils.isBlank(provinceName)) {
  599. return ResponseJson.error("第" + i + 1 + "行省份不能为空");
  600. }
  601. if (provinceName.length() > 2) {
  602. provinceName = provinceName.substring(0, provinceName.length() - 1).trim();
  603. }
  604. Integer provinceId = authMapper.getProvinceId(provinceName);
  605. // 市名
  606. String cityName = areaSplit[1];
  607. if (StringUtils.isBlank(cityName)) {
  608. return ResponseJson.error("第" + i + 1 + "行市名不能为空");
  609. }
  610. if (cityName.length() > 2) {
  611. cityName = cityName.substring(0, cityName.length() - 1).trim();
  612. }
  613. Integer cityId = authMapper.getCityId(cityName);
  614. Integer townId = null;
  615. if (areaSplit.length > 2) {
  616. // 区名
  617. String townName = areaSplit[2];
  618. if (StringUtils.isNotEmpty(townName) && townName.length() > 2) {
  619. townName = townName.substring(0, townName.length() - 1).trim();
  620. }
  621. List<TownPo> townList = authMapper.getTownList(townName);
  622. for (int j = 0; j < townList.size(); j++) {
  623. TownPo town = townList.get(j);
  624. if (null == townId) {
  625. if (null != cityId) {
  626. if (town.getCityId().equals(cityId)) {
  627. townId = town.getTownId();
  628. }
  629. } else {
  630. Integer checkCityId = authMapper.getCityIdByTownId(town.getTownId());
  631. if (null != provinceId && null != checkCityId) {
  632. Integer checkProvinceId = authMapper.getProvinceIdByCityId(cityId);
  633. if (provinceId.equals(checkProvinceId)) {
  634. cityId = checkCityId;
  635. townId = town.getTownId();
  636. }
  637. }
  638. }
  639. }
  640. }
  641. }
  642. // 校验详细地址
  643. cell = authPartyRow.getCell(2);
  644. cell.setCellType(CellType.STRING);
  645. String address = cell.getStringCellValue();
  646. if (StringUtils.isBlank(address)) {
  647. return ResponseJson.error("第" + i + 1 + "行详细地址不能为空");
  648. }
  649. // 校验经纬度
  650. cell = authPartyRow.getCell(3);
  651. String lngAndLat = null;
  652. BigDecimal lng = null;
  653. BigDecimal lat = null;
  654. if(null != cell){
  655. cell.setCellType(CellType.STRING);
  656. lngAndLat = cell.getStringCellValue();
  657. // String[] split = lngAndLat.split(",");
  658. // lng = new BigDecimal(split[0]);
  659. // lat = new BigDecimal(split[1]);
  660. }
  661. // if (StringUtils.isBlank(lngAndLat)) {
  662. // return ResponseJson.error("第" + i + 1 + "行经纬度不能为空");
  663. // }
  664. // if (2 != split.length) {
  665. // return ResponseJson.error("第" + i + 1 + "行经纬度格式错误");
  666. // }
  667. // 校验联系电话
  668. cell = authPartyRow.getCell(4);
  669. cell.setCellType(CellType.STRING);
  670. String mobile = cell.getStringCellValue();
  671. if (StringUtils.isBlank(mobile)) {
  672. return ResponseJson.error("第" + i + 1 + "行联系电话不能为空");
  673. }
  674. // 认证编号
  675. cell = authPartyRow.getCell(5);
  676. String authCode = null;
  677. if(null != cell){
  678. cell.setCellType(CellType.STRING);
  679. authCode = cell.getStringCellValue();
  680. }
  681. // 认证日期
  682. Date authDate = null;
  683. cell = authPartyRow.getCell(6);
  684. String authDateStr= null;
  685. if(null != cell){
  686. cell.setCellType(CellType.STRING);
  687. authCode = cell.getStringCellValue();
  688. }
  689. if (StringUtils.isNotBlank(authDateStr)) {
  690. SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
  691. authDate = format.parse(authDateStr);
  692. }
  693. // 校验员工人数
  694. Integer empNum = null;
  695. cell = authPartyRow.getCell(7);
  696. cell.setCellType(CellType.STRING);
  697. String empNumStr = cell.getStringCellValue();
  698. if (StringUtils.isBlank(empNumStr)) {
  699. return ResponseJson.error("第" + i + 1 + "行员工人数不能为空");
  700. }
  701. try {
  702. empNum = Integer.parseInt(empNumStr);
  703. } catch (Exception e) {
  704. return ResponseJson.error("第" + i + 1 + "行员工人数格式错误");
  705. }
  706. // 校验店铺备注
  707. cell = authPartyRow.getCell(8);
  708. String remarks =null;
  709. if(null != cell){
  710. cell.setCellType(CellType.STRING);
  711. remarks = cell.getStringCellValue();
  712. }
  713. Integer customFlag = 0;
  714. if (StringUtils.isNotEmpty(remarks)) {
  715. customFlag = 1;
  716. }
  717. CmBrandAuthPo authPo = new CmBrandAuthPo();
  718. authPo.setAuthParty(authParty);
  719. authPo.setProvinceId(provinceId);
  720. authPo.setCityId(cityId);
  721. authPo.setTownId(townId);
  722. authPo.setAddress(address);
  723. authPo.setLng(lng);
  724. authPo.setLat(lat);
  725. authPo.setMobile(mobile);
  726. authPo.setAuthCode(authCode);
  727. authPo.setAuthDate(authDate);
  728. authPo.setAuthImageType(1);
  729. authPo.setEmpNum(empNum);
  730. authPo.setCustomFlag(customFlag);
  731. authPo.setRemarks(remarks);
  732. authImportList.add(authPo);
  733. }
  734. } catch (Exception e) {
  735. e.printStackTrace();
  736. return ResponseJson.error("导入失败,请检查表格数据");
  737. } finally {
  738. // 删除临时数据
  739. File tempFile = new File(filePath);
  740. boolean delete = tempFile.delete();
  741. log.info("【图片上传】>>>>>>>>>>>>>>>>删除临时表格:" + delete);
  742. }
  743. // 保存授权数据
  744. for (int i = 0; i < authImportList.size(); i++) {
  745. CmBrandAuthPo authPo = authImportList.get(i);
  746. // 保存授权机构
  747. authPo.setAuthUserId(authUserId);
  748. authPo.setCreateBy(createBy);
  749. authPo.setCreateSource(1);
  750. authPo.setFirstClubType(5);
  751. // 导入数据
  752. ResponseJson result = saveAuth(authPo, null, true, 1);
  753. if (result.getCode() != 0) {
  754. // 设置手动回滚事务
  755. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  756. return ResponseJson.error("导入失败");
  757. }
  758. }
  759. return ResponseJson.success("导入成功");
  760. }
  761. /**
  762. * 获取机构关联的机构信息
  763. * 1.7.4版本:
  764. */
  765. @Override
  766. public ResponseJson<List<AuthFormVo>> getRelationgInfo(String snCode, Integer authUserId) {
  767. //根据sn码获取关联这个产品的机构列表
  768. List<ProductFormVo> relationgList = authMapper.getRelationgList(snCode);
  769. String relationgInfo = null;
  770. List<AuthFormVo> authIdList = null;
  771. if (relationgList.size() > 0) {
  772. for (int i = 0; i < relationgList.size(); i++) {
  773. if (null != relationgInfo) {
  774. relationgInfo += ",";
  775. }
  776. relationgInfo += relationgList.get(i).getRelationId();
  777. }
  778. if (null != relationgInfo) {
  779. String[] relationIdList = relationgInfo.split(",");
  780. authIdList = authMapper.getAuthIdList(relationIdList);
  781. }
  782. }
  783. return ResponseJson.success(authIdList);
  784. }
  785. /**
  786. * 1.7.4版本
  787. * 获取可绑定机构机构信息
  788. **/
  789. @Override
  790. public ResponseJson<List<AuthFormVo>> getClubBindAuth(Integer authUserId) {
  791. List<AuthFormVo> clubBindAuth = authMapper.getClubBindAuth(authUserId);
  792. return ResponseJson.success(clubBindAuth);
  793. }
  794. //------------------------------------------v1.7.5上传视频至抖音---------------------------------------------------------------------------------------
  795. ///用户授权(用于获取数据)
  796. /**
  797. * 用户扫码授权,获取code值
  798. * @param response
  799. * @return true :token没过期 false:token过期需重新授权
  800. * @throws IOException
  801. */
  802. @Override
  803. public ResponseJson getDouYingCode(HttpServletResponse response) throws IOException {
  804. //验证是否是第一次登录(根据redis缓存中的token验证)
  805. // long dYaccessTok = redisService.getExpireTime("DYaccessToken");
  806. // boolean s=redisService.exists("DYaccessToken");
  807. // String s1= redisService.get("DyopenId").toString();
  808. //// if(!redisService.exists("DYaccessToken")){
  809. // //验证token是否过期
  810. // long dYaccessToken = redisService.getExpireTime("DYaccessToken");
  811. // if(dYaccessToken<=0){ //tonken过期
  812. // //判断refreshToken是否过期
  813. // long DyrefreshToken = redisService.getExpireTime("DyrefreshToken");
  814. // if(DyrefreshToken>=0){ //refreshToken
  815. // //根据refreshToken刷新token,重新缓存token
  816. // String refreshToken=redisService.get("DyrefreshToken").toString();
  817. // String accessToken = refreshAccessToken(refreshToken);
  818. // redisService.set("DYaccessToken",accessToken , 60L * 60 * 24 * 15);
  819. // boolean flag= redisService.exists("DYaccessToken");
  820. // return ResponseJson.success(true);
  821. // }else{ //根据refreshToken刷新refreshToken(总共可以刷新3次,次数完后需重新扫码授权)
  822. // String refreshToken=redisService.get("DyrefreshToken").toString();
  823. // String newRefreshToken = resetRefreshAccessToken(refreshToken);
  824. // if(StringUtils.isNotEmpty(newRefreshToken)){
  825. // String accessToken = refreshAccessToken(newRefreshToken);
  826. // redisService.set("DYaccessToken",accessToken,60L * 60 * 24 * 15);
  827. // return ResponseJson.success(true);
  828. // }
  829. // }
  830. // }else {
  831. // return ResponseJson.success(true);
  832. // }
  833. // }
  834. //验证token是否过期
  835. // long dYaccessToken = redisService.getExpireTime("DYaccessToken");
  836. return redisService.getExpireTime("DYaccessToken")<0 ? ResponseJson.success(false): ResponseJson.success(true);
  837. // String clintKey = "awwwvh9tsnvo54w1";//应用唯一标识
  838. // String responestype = "code";//写死为'code'即可
  839. // String scope = "video.data,video.list,trial.whitelist,data.external.item";//应用授权作用域,多个授权作用域以英文逗号(,)分隔
  840. // String redirectUrl = "https://www.caimei365.com";//回调地址,应用中配置
  841. // String state = "false";//用于保持请求和回调的状态
  842. // String code = "https://open.douyin.com/platform/oauth/connect/?client_key=" + clintKey
  843. // + "&response_type=" + responestype + "&scope=" + scope + "&redirect_uri=" + redirectUrl + "&state=" + state;
  844. // response.sendRedirect(code);
  845. }
  846. /**
  847. * 清除抖音授权token缓存
  848. * @return
  849. */
  850. @GetMapping("/clean/douyin/redis")
  851. public ResponseJson cleanDYRedis(){
  852. redisService.remove("DYaccessToken");
  853. redisService.remove("DyrefreshToken");
  854. redisService.remove("DyopenId");
  855. return ResponseJson.success();
  856. }
  857. /**
  858. * 根据用户的code值获取AcessToken
  859. * ccode 用户授权登录code
  860. **/
  861. @Override
  862. public ResponseJson getDouYingAcessToken(String code) throws IOException {
  863. String clintKey = "awwwvh9tsnvo54w1";//应用唯一标识
  864. String clintSecret = "1dd7446d29e16738787447b771ced2df";//应用唯一标识对应的密钥
  865. String grantType = "authorization_code";//固定值
  866. String requestUrl = "https://open.douyin.com/oauth/access_token/";//请求地址
  867. CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
  868. //创建httppost对象
  869. HttpPost hp = new HttpPost(requestUrl);
  870. hp.addHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
  871. // hp.setHeader("Content-Type","application/x-www-form-urlencoded");
  872. //拼接请求参数
  873. List<NameValuePair> list = new ArrayList();
  874. list.add(new BasicNameValuePair("client_key", clintKey));
  875. list.add(new BasicNameValuePair("client_secret", clintSecret));
  876. list.add(new BasicNameValuePair("code", code));
  877. list.add(new BasicNameValuePair("grant_type", grantType));
  878. UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, StandardCharsets.UTF_8);
  879. hp.setEntity(entity);
  880. //发送请求
  881. CloseableHttpResponse execute = closeableHttpClient.execute(hp);
  882. HttpEntity he = execute.getEntity();
  883. String result = EntityUtils.toString(he, StandardCharsets.UTF_8);
  884. //获取access_token,open_id(用于获取视频数据),refresh_token(刷新token)
  885. JSONObject jsonObject =JSONObject.parseObject(result);
  886. String data = jsonObject.getString("data");
  887. JSONObject params =JSONObject.parseObject(data);
  888. String accessToken = params.getString("access_token");
  889. String openId = params.getString("open_id");
  890. String refreshToken = params.getString("refresh_token");
  891. String errorCode = params.getString("error_code");
  892. if(Integer.valueOf(errorCode)>0){return ResponseJson.success("tonken缓存失败",null);}
  893. //用redis缓存access_token,refresh_token
  894. redisService.set("DYaccessToken",accessToken , 60L * 60 * 24 * 15);// * 60 * 24 * 15
  895. redisService.set("DyrefreshToken",refreshToken,60L * 60 * 24 * 30);
  896. redisService.set("DyopenId",openId,60L * 60 * 24 * 30);
  897. EntityUtils.consume(he);
  898. String DYaccessToken=redisService.get("DYaccessToken").toString();
  899. String DyrefreshToken=redisService.get("DyrefreshToken").toString();
  900. String DyopenId=redisService.get("DyopenId").toString();
  901. if (StringUtils.isNotEmpty(DYaccessToken)&&StringUtils.isNotEmpty(DyrefreshToken)&&StringUtils.isNotEmpty(DyopenId)){
  902. return ResponseJson.success();
  903. }else {
  904. return ResponseJson.success("tonken缓存失败",null);
  905. }
  906. }
  907. /**
  908. * 刷新tonken
  909. * @param refreshToken
  910. */
  911. public String refreshAccessToken(String refreshToken){
  912. String requestUrl="https://open.douyin.com/oauth/refresh_token/";
  913. String clintKey = "awwwvh9tsnvo54w1";//应用唯一标识
  914. String grantType = "refresh_token";//固定值
  915. String accessToken=null;
  916. //创建httppost对象
  917. CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
  918. HttpPost hp = new HttpPost(requestUrl);
  919. hp.addHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
  920. // hp.setHeader("Content-Type","application/x-www-form-urlencoded");
  921. //拼接请求参数
  922. List<NameValuePair> list = new ArrayList();
  923. list.add(new BasicNameValuePair("client_key", clintKey));
  924. list.add(new BasicNameValuePair("grant_type", grantType));
  925. list.add(new BasicNameValuePair("refresh_token", refreshToken));
  926. UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, StandardCharsets.UTF_8);
  927. hp.setEntity(entity);
  928. try {
  929. CloseableHttpResponse execute = closeableHttpClient.execute(hp);
  930. HttpEntity he = execute.getEntity();
  931. String result = EntityUtils.toString(he, StandardCharsets.UTF_8);
  932. JSONObject params=JSONObject.parseObject(result);
  933. String data=params.getString("data");
  934. JSONObject datalist=JSONObject.parseObject(data);
  935. accessToken=datalist.getString("access_token");
  936. EntityUtils.consume(he);
  937. } catch (IOException e) {
  938. e.printStackTrace();
  939. }
  940. hp.setEntity(entity);
  941. return accessToken;
  942. }
  943. /**
  944. * 刷新refreshAccessToken
  945. * @param refreshToken
  946. */
  947. public String resetRefreshAccessToken(String refreshToken){
  948. String requestUrl="https://open.douyin.com/oauth/renew_refresh_token/";
  949. String clintKey = "awwwvh9tsnvo54w1";//应用唯一标识
  950. String renewRefreshAccessToken=null;
  951. //创建httppost对象
  952. CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
  953. HttpPost hp = new HttpPost(requestUrl);
  954. List<NameValuePair> list = new ArrayList();
  955. list.add(new BasicNameValuePair("client_key", clintKey));
  956. list.add(new BasicNameValuePair("refresh_token", refreshToken));
  957. list.add(new BasicNameValuePair("Content-Type", "multipart/form-data"));
  958. UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, StandardCharsets.UTF_8);
  959. hp.setEntity(entity);
  960. try {
  961. CloseableHttpResponse execute = closeableHttpClient.execute(hp);
  962. HttpEntity he = execute.getEntity();
  963. String result = EntityUtils.toString(he, StandardCharsets.UTF_8);
  964. JSONObject jsonObject=JSONObject.parseObject(result);
  965. String data = jsonObject.getString("data");
  966. JSONObject params=JSONObject.parseObject(data);
  967. renewRefreshAccessToken = params.getString("refresh_token");
  968. EntityUtils.consume(he);
  969. } catch (IOException e) {
  970. e.printStackTrace();
  971. }
  972. hp.setEntity(entity);
  973. return renewRefreshAccessToken;
  974. }
  975. //----------------------------------------------------h5的方式上传视频------------------------------------------------
  976. /**
  977. * h5的方式上传视频
  978. * @return
  979. * @throws IOException
  980. */
  981. @Override
  982. public ResponseJson getclientToken(String title,String videoPath,Integer authId) throws IOException {
  983. //获取accessToken
  984. String client_key = "awwwvh9tsnvo54w1";
  985. String client_secret = "1dd7446d29e16738787447b771ced2df";
  986. String grant_type = "client_credential";
  987. String url = "https://open.douyin.com/oauth/client_token/?client_key=" + client_key
  988. + "&client_secret=" + client_secret
  989. + "&grant_type=" + grant_type;
  990. CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
  991. //创建httppost对象
  992. HttpPost hp = new HttpPost(url);
  993. MultipartEntityBuilder builder = MultipartEntityBuilder.create();
  994. builder.setCharset(Consts.UTF_8);
  995. builder.setContentType(ContentType.MULTIPART_FORM_DATA);
  996. //构建参数
  997. HttpEntity entity = builder.build();
  998. hp.setEntity(entity);
  999. CloseableHttpResponse response = null;
  1000. String schema=null;
  1001. try {
  1002. response = closeableHttpClient.execute(hp);
  1003. HttpEntity he = response.getEntity();
  1004. String result = EntityUtils.toString(he, StandardCharsets.UTF_8);
  1005. //把返回结果转json获取access_token
  1006. JSONObject jsonObject=JSONObject.parseObject(result);
  1007. String data=jsonObject.getString("data");
  1008. JSONObject params=JSONObject.parseObject(data);
  1009. String accessToken=params.getString("access_token");
  1010. //根据accesstoken获取tiket
  1011. schema = getDouYingTicket(accessToken, title,videoPath,authId);
  1012. EntityUtils.consume(he);
  1013. } catch (IOException e) {
  1014. e.printStackTrace();
  1015. }
  1016. return ResponseJson.success(schema);
  1017. }
  1018. /**
  1019. * 根据token获取ticket
  1020. **/
  1021. @RequestMapping("/getDouYingTicket")
  1022. public String getDouYingTicket(String clientToken,String title,String videoPath,Integer authId) throws IOException {
  1023. //时间戳
  1024. long l = System.currentTimeMillis();
  1025. String timestamp = String.valueOf(l);
  1026. //随机数
  1027. String noncestr = randomGen(16);
  1028. String uri = "https://open.douyin.com/open/getticket/";
  1029. CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
  1030. HttpGet httpGet = new HttpGet(uri);
  1031. httpGet.setHeader("access-token", clientToken);
  1032. httpGet.setHeader("Content-Type","application/json");
  1033. CloseableHttpResponse response = null;
  1034. String schema=null;
  1035. try {
  1036. response = closeableHttpClient.execute(httpGet);
  1037. HttpEntity he = response.getEntity();
  1038. String result = EntityUtils.toString(he, StandardCharsets.UTF_8);
  1039. //获取ticket
  1040. JSONObject jsonObject=JSONObject.parseObject(result);
  1041. String data = jsonObject.getString("data");
  1042. JSONObject params=JSONObject.parseObject(data);
  1043. String ticket = params.getString("ticket");
  1044. //getDouYingshareId
  1045. String shareId = getDouYingshareId(clientToken);
  1046. //保存shareId用于回调时存储item_id
  1047. authMapper.savaShareIdByAuthId(authId,shareId);
  1048. //获取签名 并且用md5加密
  1049. String signature = signatureAlgorithm(ticket, timestamp,noncestr);
  1050. //获取schema(返回前端用于生成二维码发布视频)
  1051. schema = appendSchema(signature, shareId, timestamp,noncestr, title, videoPath);
  1052. EntityUtils.consume(he);
  1053. } catch (IOException e) {
  1054. e.printStackTrace();
  1055. }
  1056. return schema;
  1057. }
  1058. /**
  1059. * 获取签名 并且用md5加密
  1060. * ticket
  1061. **/
  1062. @RequestMapping("/signatureAlgorithm")
  1063. public String signatureAlgorithm(String ticket, String timestamp,String noncestr) {
  1064. TreeMap<String, String> treeMap = new TreeMap<>();
  1065. treeMap.put("nonce_str", noncestr);
  1066. treeMap.put("ticket", ticket);
  1067. treeMap.put("timestamp", timestamp);
  1068. StringBuffer stringBuffer = new StringBuffer();
  1069. Iterator<Map.Entry<String, String>> it = treeMap.entrySet().iterator();
  1070. while (it.hasNext()) {
  1071. Map.Entry<String, String> entry = it.next();
  1072. stringBuffer.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
  1073. }
  1074. String result = stringBuffer.substring(0, stringBuffer.length() - 1);
  1075. //进行md5签名
  1076. String signature = Md5Util.md5(result).toLowerCase();
  1077. return signature;
  1078. }
  1079. /**
  1080. * Schema 生成
  1081. **/
  1082. public String appendSchema(String signature, String shareId, String timestamp,String noncestr,String title,String videoPath) {
  1083. URIBuilder uri = null;
  1084. String schema = null;
  1085. try {
  1086. uri = new URIBuilder("snssdk1128://openplatform/share");// snssdk1128://openplatform/share snssdk1128://deeplink/openplatform
  1087. uri.addParameter("share_type", "h5");//固定h5
  1088. uri.addParameter("client_key", "awwwvh9tsnvo54w1");//应用唯一标识
  1089. uri.addParameter("nonce_str", noncestr);//随机数(必须和签名时的nonce_str一致)
  1090. uri.addParameter("timestamp", timestamp);//时间戳(必须和签名时的timestamp一致)
  1091. uri.addParameter("signature", signature);//签名
  1092. uri.addParameter("state", shareId);//通过方法获取(基于webhook,获取视频发布回调信息,不传则收不到回调信息)
  1093. //https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4
  1094. //视频地址(必须为网络地址,本地地址无法发布)单视频上传
  1095. uri.addParameter("video_path",videoPath);//"https://caimei-oss.oss-cn-shenzhen.aliyuncs.com/beta/authFile/5c7bfb6e-9919-48b1-a905-88a888f22a11.mp4");//https://caimei-oss.oss-cn-shenzhen.aliyuncs.com/beta/authFile/5c7bfb6e-9919-48b1-a905-88a888f22a11.mp4
  1096. uri.addParameter("share_to_publish", "1");//为1则直接发布视频至抖音
  1097. uri.addParameter("title",title);//"给大佐都整emo了");//视频标题
  1098. schema = uri.toString();
  1099. } catch (URISyntaxException e) {
  1100. e.printStackTrace();
  1101. }
  1102. return schema;
  1103. }
  1104. /**
  1105. * 获取shareId 用于生成schema
  1106. **/
  1107. @RequestMapping("/getDouYingshareId")
  1108. public String getDouYingshareId(String clientToken) throws IOException {
  1109. String uri = "https://open.douyin.com/share-id/?need_callback=true&default_hashtag=hashtag";
  1110. CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
  1111. HttpGet httpGet = new HttpGet(uri);
  1112. httpGet.setHeader("access-token", clientToken);
  1113. CloseableHttpResponse response = null;
  1114. String shareId = "";
  1115. try {
  1116. response = closeableHttpClient.execute(httpGet);
  1117. HttpEntity he = response.getEntity();
  1118. String result = EntityUtils.toString(he, StandardCharsets.UTF_8);
  1119. JSONObject jsonObject=JSONObject.parseObject(result);
  1120. String data = jsonObject.getString("data");
  1121. JSONObject params=JSONObject.parseObject(data);
  1122. shareId = params.getString("share_id");
  1123. EntityUtils.consume(he);
  1124. } catch (IOException e) {
  1125. e.printStackTrace();
  1126. }
  1127. return shareId;
  1128. }
  1129. /**
  1130. * 获取已发布视频列表
  1131. * @param openId 用户唯一标志
  1132. * @param cursor 分页游标, 第一页请求cursor是0, response中会返回下一页请求用到的cursor, 同时response还会返回has_more来表明是否有更多的数据。
  1133. * @param count 每页数量 10
  1134. */
  1135. public String getVideoList(String openId,Long cursor,Integer count,String accessToken){
  1136. String requestUrl="https://open.douyin.com/video/list/?open_id="+openId+"&cursor="+cursor+"&count="+count;
  1137. //创建httppost对象
  1138. CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
  1139. HttpGet hg = new HttpGet(requestUrl);
  1140. hg.setHeader("Content-Type","application/json");
  1141. hg.addHeader("access-token",accessToken);
  1142. String resultList=null;
  1143. try {
  1144. CloseableHttpResponse execute = closeableHttpClient.execute(hg);
  1145. HttpEntity entity = execute.getEntity();
  1146. String result=EntityUtils.toString(entity,StandardCharsets.UTF_8);
  1147. JSONObject jsonObject = JSONObject.parseObject(result);
  1148. resultList = jsonObject.getString("data");
  1149. // resultList = JSONArray.parseArray(itemIdlist);
  1150. // String itemId = params.getJSONObject(0).get("item_id").toString();
  1151. //根据itemid获取视频的数据(点赞,播放,评论量)
  1152. EntityUtils.consume(entity);
  1153. } catch (IOException e) {
  1154. e.printStackTrace();
  1155. }
  1156. return resultList;
  1157. }
  1158. /**
  1159. * 根据item_id获取单个(多个)视频信息
  1160. * @param openId
  1161. * @param accessToken
  1162. * itemId 多个用,隔开
  1163. * @return
  1164. */
  1165. public String getVideoDataByItemId(String openId, String accessToken,String itemId) {
  1166. String requestUrl = "https://open.douyin.com/video/data/?open_id="+openId;
  1167. CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
  1168. HttpPost hp = new HttpPost(requestUrl);
  1169. hp.addHeader("access-token", accessToken);
  1170. hp.addHeader("Content-Type", "application/json");
  1171. // List<NameValuePair> list = new ArrayList<>();
  1172. // list.add(new BasicNameValuePair("item_ids",jsonArray.toString()));
  1173. // JSONObject json = new JSONObject();
  1174. // json.put("item_ids",itemId);
  1175. // json.put("item_ids",itemid1);
  1176. // "{\"item_ids\":[\"@9VwTweWaBd0jMWGuNYwqEc791GHuNf6KPZx5qgiiLVQbbvf860zdRmYqig357zEBpu0x/J8bThza3PQPj7FY1Q==\"]}"
  1177. String s="{\"item_ids\":["+"\""+itemId+"\""+"]}";
  1178. hp.setEntity(new StringEntity(s,"UTF-8"));
  1179. String datastr=null;
  1180. try {
  1181. CloseableHttpResponse execute = closeableHttpClient.execute(hp);
  1182. HttpEntity entity = execute.getEntity();
  1183. String result = EntityUtils.toString(entity, StandardCharsets.UTF_8);
  1184. JSONObject params=JSONObject.parseObject(result);
  1185. datastr=params.getString("data");
  1186. // JSONObject data=JSONObject.parseObject(datastr);
  1187. // String list=data.getString("list");
  1188. // System.out.println(list);
  1189. EntityUtils.consume(entity);
  1190. } catch (IOException e) {
  1191. e.printStackTrace();
  1192. }
  1193. return datastr;
  1194. }
  1195. /**
  1196. * 生成随机数
  1197. *
  1198. * @param place
  1199. * @return
  1200. */
  1201. public String randomGen(int place) {
  1202. String base = "wqetryuioplkjhgfdsazxcvbmnABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  1203. StringBuffer sb = new StringBuffer();
  1204. Random rd = new Random();
  1205. for (int i = 0; i < place; i++) {
  1206. sb.append(base.charAt(rd.nextInt(base.length())));
  1207. }
  1208. return sb.toString();
  1209. }
  1210. /**
  1211. * 保存视频信息
  1212. * @return
  1213. */
  1214. @Override
  1215. public ResponseJson saveVideoInfo(ChallengeRoundVo cr){
  1216. Date date=new Date();
  1217. SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1218. String releaseTime = sf.format(date).replace("T", "");
  1219. authMapper.saveVideoInfo(cr.getUserName(),cr.getCover(),cr.getOssUrl(),cr.getOssName(),cr.getTitle(),releaseTime,cr.getAuthId(),cr.getAuthUserId());
  1220. return ResponseJson.success("保存成功",null);
  1221. }
  1222. /**
  1223. * 1.7.7保存视频信息
  1224. * @return
  1225. */
  1226. @Override
  1227. public ResponseJson saveVideo(RossChallengeVideo ross){
  1228. Date date=new Date();
  1229. SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1230. String releaseTime = sf.format(date).replace("T", "");
  1231. //根据手机号获取clubuserid
  1232. Integer clubUserId = authMapper.getClubUserId(ross.getUserName());
  1233. authMapper.saveVideo(ross.getUserName(),ross.getCover(),ross.getOssUrl(),ross.getOssName(),ross.getTitle(),releaseTime,ross.getAuthId(),ross.getLinked(),ross.getAuthUserId(),clubUserId);
  1234. return ResponseJson.success("保存成功",null);
  1235. }
  1236. /**
  1237. * 根据authid获取authUserId
  1238. * @param authId
  1239. * @return
  1240. */
  1241. @Override
  1242. public boolean getauthUserId(Integer authId){
  1243. String authUserId= authMapper.getauthUserId(authId);
  1244. return StringUtils.isEmpty(authUserId);
  1245. }
  1246. /**
  1247. * 判断是否存在userName
  1248. * @param userName
  1249. * @return
  1250. */
  1251. @Override
  1252. public boolean getuserName(String userName){
  1253. String name= authMapper.getuserName(userName);
  1254. return StringUtils.isEmpty(name);
  1255. }
  1256. /**
  1257. * 验证是否在活动时间内
  1258. * @param releaseTime 发布时间
  1259. * @return
  1260. */
  1261. @Override
  1262. public boolean checkActivityTime(String releaseTime){
  1263. Integer id= authMapper.checkActivityTime(releaseTime);
  1264. return id==null?true:false;
  1265. }
  1266. /**
  1267. * 获取已发布视频列表(前端)
  1268. * @param clubUserName 手机号或者机构名
  1269. * @param status 用户发布状态
  1270. * @param cursor 页码
  1271. * @param count 条数
  1272. * @return
  1273. */
  1274. @Override
  1275. public ResponseJson<PageInfo<ChallengeRoundVo>> getPublishedVideoList(String clubUserName,Integer status,Integer cursor,Integer count,Integer pageNum,Integer pageSize,Integer authUserId){
  1276. PageHelper.startPage(pageNum, pageSize);
  1277. ChallengeActivityVo activityTime = authMapper.getActivityTime(authUserId);
  1278. List<ChallengeRoundVo> listChallengeRoundVo=authMapper.getPublishedVideoList(clubUserName,status,authUserId,activityTime.getStartTime(),activityTime.getEndTime());
  1279. PageInfo<ChallengeRoundVo> pageData = new PageInfo<>(listChallengeRoundVo);
  1280. //调用抖音api获取视频数据
  1281. String dyopenId=null;
  1282. String DYaccessToken=null;
  1283. if(redisService.getExpireTime("DyopenId")>0&&redisService.getExpireTime("DYaccessToken")>0){
  1284. dyopenId=redisService.get("DyopenId").toString();
  1285. DYaccessToken=redisService.get("DYaccessToken").toString();
  1286. }
  1287. Long flag=1l;
  1288. List<DyVideoInfoVo> list=new ArrayList<>();
  1289. //递归获取抖音账号下所有视频数据
  1290. while (flag!=0){
  1291. if (flag==1){flag=0l;}
  1292. String data = getVideoList(dyopenId, flag, count, DYaccessToken);
  1293. JSONObject paramslist = JSONObject.parseObject(data);
  1294. Integer error_code = Integer.valueOf(paramslist.getString("error_code"));
  1295. if(error_code>0){
  1296. //抖音视频数据全部获取完,终止循环
  1297. break;
  1298. }
  1299. String resultList = paramslist.getString("list");
  1300. String cor = paramslist.getString("cursor");
  1301. flag=Long.parseLong(cor);
  1302. List<DyVideoInfoVo> listDyVideoInfoVo= JSONArray.parseArray(resultList, DyVideoInfoVo.class);
  1303. if(listDyVideoInfoVo!=null&&listDyVideoInfoVo.size()>0){
  1304. for (DyVideoInfoVo dv:listDyVideoInfoVo) {
  1305. list.add(dv);
  1306. }
  1307. }
  1308. }
  1309. //根据itemId给对应视频赋值(点赞量,播放量)
  1310. if(listChallengeRoundVo!=null&&listChallengeRoundVo.size()>0){
  1311. for (ChallengeRoundVo ChallengeRoundVo:listChallengeRoundVo) {
  1312. if(StringUtils.isEmpty(ChallengeRoundVo.getDiggCount())){
  1313. ChallengeRoundVo.setDiggCount("0");
  1314. }
  1315. if(StringUtils.isEmpty(ChallengeRoundVo.getPlayCount())){
  1316. ChallengeRoundVo.setPlayCount("0");
  1317. }
  1318. if(list!=null&&list.size()>0){
  1319. for (DyVideoInfoVo dyVideoInfoVo:list) {
  1320. if(dyVideoInfoVo.getItem_id().equals(ChallengeRoundVo.getItemId())){
  1321. StatisticsVo StatisticsVo= JSONObject.parseObject(dyVideoInfoVo.getStatistics(), StatisticsVo.class);
  1322. ChallengeRoundVo.setDiggCount(StatisticsVo.getDigg_count());
  1323. ChallengeRoundVo.setPlayCount(StatisticsVo.getPlay_count());
  1324. break;
  1325. }
  1326. }
  1327. }
  1328. }
  1329. }
  1330. //根据点赞量降序排序
  1331. // PageHelper.startPage(pageNum, pageSize);
  1332. List<ChallengeRoundVo> collect = listChallengeRoundVo.stream().sorted(Comparator.comparing(ChallengeRoundVo::getDiggCount).reversed().thenComparing(ChallengeRoundVo::getPlayCount, Comparator.reverseOrder())).collect(Collectors.toList());//先以属性一升序,升序结果进行属性一降序,再进行属性二降序
  1333. //获取排名数据
  1334. for (ChallengeRoundVo chall:collect) {
  1335. chall.setRankingStatus(1);
  1336. }
  1337. List<ChallengeRoundVo> publishedVideoListNoRanking = authMapper.getPublishedVideoListNoRanking(clubUserName, status, authUserId, activityTime.getStartTime(), activityTime.getEndTime());
  1338. //获取不排名的数据
  1339. if(publishedVideoListNoRanking.size()>0&&listChallengeRoundVo.size()>0){
  1340. for (ChallengeRoundVo noRanking:publishedVideoListNoRanking) {
  1341. noRanking.setRankingStatus(0);
  1342. if(StringUtils.isEmpty(noRanking.getDiggCount())){
  1343. noRanking.setDiggCount("0");
  1344. }
  1345. if(StringUtils.isEmpty(noRanking.getPlayCount())){
  1346. noRanking.setPlayCount("0");
  1347. }
  1348. collect.add(noRanking);
  1349. }
  1350. }else{
  1351. for (ChallengeRoundVo noRanking:publishedVideoListNoRanking) {
  1352. noRanking.setRankingStatus(1);
  1353. if(StringUtils.isEmpty(noRanking.getDiggCount())){
  1354. noRanking.setDiggCount("0");
  1355. }
  1356. if(StringUtils.isEmpty(noRanking.getPlayCount())){
  1357. noRanking.setPlayCount("0");
  1358. }
  1359. collect.add(noRanking);
  1360. }
  1361. }
  1362. PageInfo<ChallengeRoundVo> pageDa = new PageInfo<>(collect);
  1363. return ResponseJson.success(pageDa);
  1364. }
  1365. /**
  1366. * 获取已发布视频列表(后端)
  1367. * @param mobile
  1368. * @param authParty
  1369. * @param status
  1370. * @param cursor
  1371. * @param count
  1372. * @param authUserId
  1373. * @return
  1374. */
  1375. @Override
  1376. public ResponseJson<PageInfo<ChallengeRoundVo>> getPublishedVideo(String mobile,String authParty,Integer status,Integer cursor,Integer count,Integer authUserId,Integer pageNum,Integer pageSize,String startTIme,String endTime){
  1377. PageHelper.startPage(pageNum, pageSize);
  1378. List<ChallengeRoundVo> listChallengeRoundVo=null;
  1379. ChallengeActivityVo activityTime = authMapper.getActivityTime(authUserId);
  1380. if(StringUtils.isNotEmpty(startTIme)&&StringUtils.isNotEmpty(endTime)){
  1381. listChallengeRoundVo=authMapper.getPublishedVideo(mobile,authParty,status,authUserId,startTIme,endTime);
  1382. }else{
  1383. if(activityTime!=null){
  1384. listChallengeRoundVo=authMapper.getPublishedVideo(mobile,authParty,status,authUserId,activityTime.getStartTime(),activityTime.getEndTime());
  1385. }else{
  1386. listChallengeRoundVo=authMapper.getPublishedVideo(mobile,authParty,status,authUserId,null,null);
  1387. }
  1388. }
  1389. PageInfo<ChallengeRoundVo> pageData = new PageInfo<>(listChallengeRoundVo);
  1390. //调用抖音api获取视频数据
  1391. String dyopenId=null;
  1392. String DYaccessToken=null;
  1393. if(redisService.getExpireTime("DyopenId")>0&&redisService.getExpireTime("DYaccessToken")>0){
  1394. dyopenId=redisService.get("DyopenId").toString();
  1395. DYaccessToken=redisService.get("DYaccessToken").toString();
  1396. }
  1397. Long flag=1l;
  1398. List<DyVideoInfoVo> list=new ArrayList<>();
  1399. //递归获取抖音账号下所有视频数据
  1400. while (flag!=0){
  1401. if (flag==1){flag=0l;}
  1402. String data = getVideoList(dyopenId, flag, count, DYaccessToken);
  1403. JSONObject paramslist = JSONObject.parseObject(data);
  1404. Integer error_code = Integer.valueOf(paramslist.getString("error_code"));
  1405. if(error_code>0){
  1406. //视频数据获取完,终止循环
  1407. break;
  1408. }
  1409. String resultList = paramslist.getString("list");
  1410. String cor = paramslist.getString("cursor");
  1411. flag=Long.parseLong(cor);
  1412. List<DyVideoInfoVo> listDyVideoInfoVo= JSONArray.parseArray(resultList, DyVideoInfoVo.class);
  1413. if(listDyVideoInfoVo!=null&&listDyVideoInfoVo.size()>0){
  1414. for (DyVideoInfoVo dv:listDyVideoInfoVo) {
  1415. list.add(dv);
  1416. }
  1417. }
  1418. }
  1419. //根据itemId给对应视频赋值(点赞量,播放量)
  1420. if(listChallengeRoundVo!=null&&listChallengeRoundVo.size()>0){
  1421. for (ChallengeRoundVo ChallengeRoundVo:listChallengeRoundVo) {
  1422. if(StringUtils.isEmpty(ChallengeRoundVo.getDiggCount())){
  1423. ChallengeRoundVo.setDiggCount("0");
  1424. }
  1425. if(StringUtils.isEmpty(ChallengeRoundVo.getPlayCount())){
  1426. ChallengeRoundVo.setPlayCount("0");
  1427. }
  1428. if(list!=null&&list.size()>0){
  1429. for (DyVideoInfoVo dyVideoInfoVo:list) {
  1430. if(dyVideoInfoVo.getItem_id().equals(ChallengeRoundVo.getItemId())){
  1431. StatisticsVo StatisticsVo= JSONObject.parseObject(dyVideoInfoVo.getStatistics(), StatisticsVo.class);
  1432. ChallengeRoundVo.setDiggCount(StatisticsVo.getDigg_count());
  1433. ChallengeRoundVo.setPlayCount(StatisticsVo.getPlay_count());
  1434. break;
  1435. }
  1436. }
  1437. }
  1438. }
  1439. }
  1440. //根据点赞量降序排序
  1441. // PageHelper.startPage(pageNum, pageSize);
  1442. List<ChallengeRoundVo> collect = listChallengeRoundVo.stream().sorted(Comparator.comparing(ChallengeRoundVo::getDiggCount).reversed().thenComparing(ChallengeRoundVo::getPlayCount, Comparator.reverseOrder())).collect(Collectors.toList());//先以属性一升序,升序结果进行属性一降序,再进行属性二降序
  1443. //获取排名数据
  1444. for (ChallengeRoundVo chall:collect) {
  1445. chall.setRankingStatus(1);
  1446. }
  1447. PageInfo<ChallengeRoundVo> pageDa = new PageInfo<>(collect);
  1448. //获取不排名的数据
  1449. List<ChallengeRoundVo> publishedVideoListNoRanking=null;
  1450. if(StringUtils.isNotEmpty(startTIme)&&StringUtils.isNotEmpty(endTime)){
  1451. publishedVideoListNoRanking = authMapper.getPublishedVideoNoRanking(mobile,authParty,status,authUserId,startTIme,endTime);
  1452. }else{
  1453. if(activityTime!=null){
  1454. publishedVideoListNoRanking = authMapper.getPublishedVideoNoRanking(mobile,authParty,status,authUserId,activityTime.getStartTime(),activityTime.getEndTime());
  1455. }else{
  1456. publishedVideoListNoRanking = authMapper.getPublishedVideoNoRanking(mobile,authParty,status,authUserId,null,null);
  1457. }
  1458. }
  1459. //获取不排名的数据
  1460. if(publishedVideoListNoRanking.size()>0&&listChallengeRoundVo.size()>0){
  1461. for (ChallengeRoundVo noRanking:publishedVideoListNoRanking) {
  1462. noRanking.setRankingStatus(0);
  1463. if(StringUtils.isEmpty(noRanking.getDiggCount())){
  1464. noRanking.setDiggCount("0");
  1465. }
  1466. if(StringUtils.isEmpty(noRanking.getPlayCount())){
  1467. noRanking.setPlayCount("0");
  1468. }
  1469. collect.add(noRanking);
  1470. }
  1471. }else{
  1472. for (ChallengeRoundVo noRanking:publishedVideoListNoRanking) {
  1473. noRanking.setRankingStatus(1);
  1474. if(StringUtils.isEmpty(noRanking.getDiggCount())){
  1475. noRanking.setDiggCount("0");
  1476. }
  1477. if(StringUtils.isEmpty(noRanking.getPlayCount())){
  1478. noRanking.setPlayCount("0");
  1479. }
  1480. collect.add(noRanking);
  1481. }
  1482. }
  1483. return ResponseJson.success(pageDa);
  1484. }
  1485. /**
  1486. * 获取机构已发布视频的机构下拉列表
  1487. * @param authUserId
  1488. * @return
  1489. */
  1490. @Override
  1491. public ResponseJson<List<ChallengeRoundVo>> getAuthPartylist(Integer authUserId){
  1492. return ResponseJson.success(authMapper.getAuthPartylist(authUserId));
  1493. }
  1494. /**
  1495. * 保存活动信息
  1496. * @param startTime
  1497. * @param endTime
  1498. * @param status
  1499. * @return
  1500. */
  1501. @Override
  1502. public ResponseJson saveActivityTime(String startTime,String endTime,Integer status,Integer authUserId){
  1503. //如果数据库有值则修改,没值则新增
  1504. List<ChallengeActivityVo> challengeList = authMapper.checkActivityId();
  1505. List<Integer> authUserIdList=new ArrayList<>();
  1506. for (ChallengeActivityVo ac:challengeList) {
  1507. authUserIdList.add(ac.getAuthUserId());
  1508. }
  1509. if(challengeList.size()<0||!authUserIdList.contains(authUserId)){
  1510. authMapper.saveActivityInfo(startTime,endTime,status,authUserId);
  1511. //1.7.7ross挑战赛新加逻辑
  1512. //活动开启后给供应商下所有机构手机号码发送短信
  1513. // if(status==1){
  1514. // smsSend(authUserId);
  1515. // }
  1516. }else {
  1517. authMapper.upActivityInfo(startTime,endTime,status,authUserId);
  1518. //1.7.7ross挑战赛新加逻辑
  1519. //活动开启后给供应商下所有机构手机号码发送短信
  1520. // if(status==1){
  1521. // smsSend(authUserId);
  1522. // }
  1523. }
  1524. return ResponseJson.success();
  1525. }
  1526. /**
  1527. * 获取活动信息
  1528. * @return
  1529. */
  1530. @Override
  1531. public ResponseJson<ChallengeActivityVo> getActivityTime(Integer authUserId){
  1532. Date date=new Date();
  1533. SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1534. String releaseTime = sf.format(date).replace("T", "");
  1535. ChallengeActivityVo activityTime = authMapper.getActivityTime(authUserId);
  1536. //如果当前时间大于结束时间则活动状态置为未开启状态
  1537. if(activityTime!=null&&StringUtils.isNotEmpty(activityTime.getEndTime())){
  1538. if(activityTime.getEndTime().compareTo(releaseTime)<0){
  1539. activityTime.setStatus(0);
  1540. authMapper.upStatusById(activityTime.getId());
  1541. //
  1542. }
  1543. }
  1544. return ResponseJson.success(activityTime);
  1545. }
  1546. /**
  1547. * 判断shareId是否存在
  1548. * @param shareId
  1549. * @return
  1550. */
  1551. @Override
  1552. public boolean getShareId(String shareId){
  1553. return StringUtils.isNotEmpty(authMapper.getShareId(shareId));
  1554. }
  1555. /**
  1556. * 根据ShareId保存itemId (webhook触发时调用)
  1557. * @param shareId
  1558. * @param itemId
  1559. */
  1560. @Override
  1561. public void savaItemIdByShareId(String shareId,String itemId){
  1562. authMapper.savaItemIdByShareId(shareId,itemId);
  1563. }
  1564. @Override
  1565. public ResponseJson<ChallengeActivityVo> getActivitty(Integer authUserId){
  1566. ChallengeActivityVo activityTime = authMapper.getActivityTime(authUserId);
  1567. Date date=new Date();
  1568. SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1569. String releaseTime = sf.format(date).replace("T", "");
  1570. if(activityTime!=null){
  1571. //当按钮关闭时,状态皆为已结束,开始时根据时间判断
  1572. if(activityTime.getStatus()==0){
  1573. activityTime.setActivityState(0);
  1574. }else{
  1575. if(activityTime.getStartTime().compareTo(releaseTime)>0){
  1576. activityTime.setActivityState(0);
  1577. }else if(activityTime.getStartTime().compareTo(releaseTime)<0&&activityTime.getEndTime().compareTo(releaseTime)>0){
  1578. activityTime.setActivityState(1);
  1579. }else {
  1580. activityTime.setActivityState(2);
  1581. }
  1582. }
  1583. }
  1584. return ResponseJson.success(activityTime);
  1585. }
  1586. /**
  1587. * 根据authId获取手机号
  1588. * @param authId
  1589. * @return
  1590. */
  1591. @Override
  1592. public String getMobileByAuthId(Integer authId){
  1593. return authMapper.getMobileByAuthId(authId);
  1594. }
  1595. /**
  1596. * 根据authId获取手机号
  1597. * @param authId
  1598. * @return
  1599. */
  1600. @Override
  1601. public String getAuthUserName(Integer authId){
  1602. return authMapper.getAuthUserName(authId);
  1603. }
  1604. /**
  1605. * 保存抖音口令
  1606. * @param authId
  1607. * @return
  1608. */
  1609. @Override
  1610. public void savaDyCommand(Integer authId,String content){
  1611. authMapper.savaDyCommand(authId,content);
  1612. }
  1613. /**
  1614. * 根据authId获取ossName
  1615. * @param videoID
  1616. * @return
  1617. */
  1618. @Override
  1619. public String getOssNameAuthId(Integer videoID){
  1620. return authMapper.getOssNameId(videoID);
  1621. }
  1622. /**
  1623. * 根据authId删除视频
  1624. * @param videoID
  1625. * @return
  1626. */
  1627. @Override
  1628. public void deleteVideoByAuthId(Integer videoID){
  1629. authMapper.deleteVideoById(videoID);
  1630. }
  1631. /**
  1632. * 根据手机号获取发布时间
  1633. * @param userName
  1634. * @return
  1635. */
  1636. @Override
  1637. public String getReleaseTime(String userName){
  1638. return authMapper.getReleaseTime(userName);
  1639. }
  1640. @Override
  1641. public ResponseJson downLoadChoseZip(String fileId,HttpServletResponse response){
  1642. if (fileId.contains(",")) {
  1643. String[] split = fileId.split(",");
  1644. ArrayList<RossChallengeVideo> fileTreeVos = new ArrayList<>();
  1645. for (String s : split) {
  1646. RossChallengeVideo file = authMapper.getChallengeVideoInfo(Integer.valueOf(s));
  1647. fileTreeVos.add(file);
  1648. }
  1649. //有package则在服务器固定路径new file.mkdir
  1650. UUID uuid = UUID.randomUUID();
  1651. String zipPath = "/mnt/newdatadrive/data/runtime/jar-instance/zplma/tempFile/" + uuid;
  1652. String filePath = zipPath;
  1653. if ("dev".equals(active)) {
  1654. zipPath = "D:\\caimei-workSpace\\file\\" + uuid;
  1655. filePath = zipPath;
  1656. }
  1657. boolean mkdirs = new File(filePath).mkdirs();
  1658. Assert.isTrue(mkdirs, "文件夹创建失败");
  1659. for (RossChallengeVideo challengeRoundVo : fileTreeVos) {
  1660. //普通文件直接下载到临时文件夹uuid下
  1661. String fileName = "";
  1662. String ossurl = challengeRoundVo.getOssUrl();
  1663. ossurl.indexOf(".");
  1664. String title=challengeRoundVo.getTitle();
  1665. Pattern pattern = Pattern.compile("[\\s\\\\/:\\*\\?\\\"<>\\|]");
  1666. Matcher matcher = pattern.matcher(title);
  1667. title= matcher.replaceAll("");
  1668. if(title.length()>50){
  1669. title= title.substring(0,50);
  1670. }
  1671. if ("dev".equals(active)) {
  1672. fileName = zipPath + "\\"+title + ossurl.substring(ossurl.lastIndexOf("."));
  1673. } else {
  1674. fileName = zipPath + "/"+title + ossurl.substring(ossurl.lastIndexOf("."));
  1675. }
  1676. OSSUtils.downFileByFilePath("authFile/", challengeRoundVo.getOssName(), fileName);
  1677. // else {
  1678. // //文件夹在uuid文件夹下创建自己包名的文件夹
  1679. // String param = fileTreeVo.getId() + "," + authUserId;
  1680. // String myPath = "";
  1681. // myPath = filePath + "/" + fileTreeVo.getFileName();
  1682. // if ("dev".equals(active)) {
  1683. // myPath = filePath + "\\" + fileTreeVo.getFileName();
  1684. // }
  1685. // boolean dirs = new File(myPath).mkdirs();
  1686. // Assert.isTrue(dirs, "文件夹创建失败");
  1687. // recursion(param, myPath);
  1688. // }
  1689. }
  1690. //压缩
  1691. FileZipUtils.compress(zipPath, "", true);
  1692. String s = zipPath + ".zip";
  1693. String fileName = uuid + ".zip";
  1694. File file = new File(s);
  1695. try {
  1696. if (file.exists()) {
  1697. FileInputStream fileInputStream = new FileInputStream(file);
  1698. ServletOutputStream outputStream = response.getOutputStream();
  1699. // 设置下载文件的mineType,告诉浏览器下载文件类型
  1700. // int i = fileName.lastIndexOf(".");
  1701. // String substring = fileName.substring(i + 1, filePath.length());
  1702. response.setContentType("application/zip");
  1703. // 设置一个响应头,无论是否被浏览器解析,都下载
  1704. response.setHeader("Content-disposition", "attachment; filename=" + fileName);
  1705. byte[] bytes = new byte[1024];
  1706. int len;
  1707. while ((len = fileInputStream.read(bytes)) != -1) {
  1708. outputStream.write(bytes, 0, len);
  1709. }
  1710. fileInputStream.close();
  1711. outputStream.close();
  1712. }
  1713. } catch (IOException e) {
  1714. e.printStackTrace();
  1715. }
  1716. file.delete();
  1717. FileZipUtils.deleteFile(new File(zipPath));
  1718. }else {
  1719. ArrayList<RossChallengeVideo> fileTreeVos = new ArrayList<>();
  1720. RossChallengeVideo f = authMapper.getChallengeVideoInfo(Integer.valueOf(fileId));
  1721. fileTreeVos.add(f);
  1722. //有package则在服务器固定路径new file.mkdir
  1723. UUID uuid = UUID.randomUUID();
  1724. String zipPath = "/mnt/newdatadrive/data/runtime/jar-instance/zplma/tempFile/" + uuid;
  1725. String filePath = zipPath;
  1726. if ("dev".equals(active)) {
  1727. zipPath = "D:\\caimei-workSpace\\file\\" + uuid;
  1728. filePath = zipPath;
  1729. }
  1730. boolean mkdirs = new File(filePath).mkdirs();
  1731. Assert.isTrue(mkdirs, "文件夹创建失败");
  1732. for (RossChallengeVideo challengeRoundVo : fileTreeVos) {
  1733. //普通文件直接下载到临时文件夹uuid下
  1734. String fileName = "";
  1735. String ossurl = challengeRoundVo.getOssUrl();
  1736. String title=challengeRoundVo.getTitle();
  1737. Pattern pattern = Pattern.compile("[\\s\\\\/:\\*\\?\\\"<>\\|]");
  1738. Matcher matcher = pattern.matcher(title);
  1739. title= matcher.replaceAll("");
  1740. if(title.length()>50){
  1741. title= title.substring(0,50);
  1742. }
  1743. if ("dev".equals(active)) {
  1744. fileName = zipPath + "\\"+title +ossurl.substring(ossurl.lastIndexOf("."));
  1745. } else {
  1746. fileName = zipPath + "/"+title + ossurl.substring(ossurl.lastIndexOf("."));
  1747. }
  1748. OSSUtils.downFileByFilePath("authFile/", challengeRoundVo.getOssName(), fileName);
  1749. // else {
  1750. // //文件夹在uuid文件夹下创建自己包名的文件夹
  1751. // String param = fileTreeVo.getId() + "," + authUserId;
  1752. // String myPath = "";
  1753. // myPath = filePath + "/" + fileTreeVo.getFileName();
  1754. // if ("dev".equals(active)) {
  1755. // myPath = filePath + "\\" + fileTreeVo.getFileName();
  1756. // }
  1757. // boolean dirs = new File(myPath).mkdirs();
  1758. // Assert.isTrue(dirs, "文件夹创建失败");
  1759. // recursion(param, myPath);
  1760. // }
  1761. }
  1762. //压缩
  1763. FileZipUtils.compress(zipPath, "", true);
  1764. String s = zipPath + ".zip";
  1765. String fileName = uuid + ".zip";
  1766. File file = new File(s);
  1767. try {
  1768. if (file.exists()) {
  1769. FileInputStream fileInputStream = new FileInputStream(file);
  1770. ServletOutputStream outputStream = response.getOutputStream();
  1771. // 设置下载文件的mineType,告诉浏览器下载文件类型
  1772. // int i = fileName.lastIndexOf(".");
  1773. // String substring = fileName.substring(i + 1, filePath.length());
  1774. response.setContentType("application/zip");
  1775. // 设置一个响应头,无论是否被浏览器解析,都下载
  1776. response.setHeader("Content-disposition", "attachment; filename=" + fileName);
  1777. byte[] bytes = new byte[1024];
  1778. int len;
  1779. while ((len = fileInputStream.read(bytes)) != -1) {
  1780. outputStream.write(bytes, 0, len);
  1781. }
  1782. fileInputStream.close();
  1783. outputStream.close();
  1784. }
  1785. } catch (IOException e) {
  1786. e.printStackTrace();
  1787. }
  1788. file.delete();
  1789. FileZipUtils.deleteFile(new File(zipPath));
  1790. }
  1791. return null;
  1792. }
  1793. /**
  1794. * 根据id获取信息
  1795. *
  1796. */
  1797. public ResponseJson<ChallengeRoundVo> getInfoById(Integer videoId) {
  1798. return ResponseJson.success(authMapper.getChallengeRoundInfo(videoId));
  1799. }
  1800. @Override
  1801. public ResponseJson getDyVidoInfo(Integer authUserId){
  1802. // 获取供应商用户id
  1803. // Integer userIdentity = sysUser.getUserIdentity();
  1804. // Integer authUserId = 2 == userIdentity ? sysUser.getId() : 3 == userIdentity ? sysUser.getParentId() : null;
  1805. String dyopenId=null;
  1806. String DYaccessToken=null;
  1807. Date date=new Date();
  1808. SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1809. String now = sf.format(date).replace("T", "");
  1810. if(redisService.getExpireTime("DyopenId")>0&&redisService.getExpireTime("DYaccessToken")>0){
  1811. dyopenId=redisService.get("DyopenId").toString();
  1812. DYaccessToken=redisService.get("DYaccessToken").toString();
  1813. }
  1814. //获取供应商下面所有机构发的视频
  1815. List<ChallengeRoundVo> roundlist = authMapper.getRoundlist();
  1816. if(null !=roundlist && roundlist.size()>0){
  1817. //根据item_id更新视频数据(点赞量,播放量)
  1818. for (ChallengeRoundVo chall:roundlist) {
  1819. //如果当前时间大于活动结束时间则不再统计
  1820. ChallengeActivityVo activityTime = authMapper.getActivityTime(chall.getAuthUserId());
  1821. if(null !=activityTime && now.compareTo(activityTime.getEndTime())<0){
  1822. String data = getVideoDataByItemId(dyopenId, DYaccessToken, chall.getItemId());
  1823. JSONObject paramslist = JSONObject.parseObject(data);
  1824. String resultList=paramslist.getString("list");
  1825. List<DyVideoInfoVo> listDyVideoInfoVo= JSONArray.parseArray(resultList, DyVideoInfoVo.class);
  1826. if(listDyVideoInfoVo!=null&&listDyVideoInfoVo.size()>0){
  1827. StatisticsVo StatisticsVo= JSONObject.parseObject(listDyVideoInfoVo.get(0).getStatistics(), StatisticsVo.class);
  1828. //更新视频数据到数据库
  1829. authMapper.upVidoInfoById(chall.getId(),StatisticsVo.getDigg_count(),StatisticsVo.getPlay_count());
  1830. }
  1831. }
  1832. }
  1833. }
  1834. return ResponseJson.success();
  1835. }
  1836. /**
  1837. * 新增参赛机构信息
  1838. * @param rossChallengeRoundVo
  1839. * @return
  1840. */
  1841. @Override
  1842. public ResponseJson saveRossInfo(RossChallengeRoundVo rossChallengeRoundVo){
  1843. //根据手机号获取clubuserid
  1844. Integer clubUserId = authMapper.getClubUserId(rossChallengeRoundVo.getUserName());
  1845. rossChallengeRoundVo.setClubUserId(clubUserId);
  1846. authMapper.saveRossInfo(rossChallengeRoundVo);
  1847. return ResponseJson.success();
  1848. }
  1849. /**
  1850. * 根据手机号码获取信息
  1851. * @param userName
  1852. * @return
  1853. */
  1854. @Override
  1855. public List<RossChallengeRoundVo> getInfoByUserName(String userName){
  1856. return authMapper.getInfoByUserName(userName);
  1857. }
  1858. /**
  1859. * 验证用户是否已经报名
  1860. * @param mobile
  1861. * @return
  1862. */
  1863. public ResponseJson<RossChallengeRoundVo> checkContestedInfo(String mobile,Integer authUserId){
  1864. //获取活动时间
  1865. ChallengeActivityVo activityTime = authMapper.getActivityTime(authUserId);
  1866. //活动时间内用户是否参与比赛
  1867. RossChallengeRoundVo ross=new RossChallengeRoundVo();
  1868. if(null!=activityTime&&StringUtils.isNotEmpty(activityTime.getStartTime())&&StringUtils.isNotEmpty(activityTime.getEndTime())){
  1869. RossChallengeRoundVo rossChallengeRoundVo = authMapper.getcontestedInfoByUserName(mobile,activityTime.getStartTime(),activityTime.getEndTime());
  1870. if(null!=rossChallengeRoundVo&&null!=rossChallengeRoundVo.getContestStatus()){
  1871. ross.setContestStatus(rossChallengeRoundVo.getContestStatus());
  1872. }else{
  1873. ross.setContestStatus(0);
  1874. }
  1875. }else{
  1876. ross.setContestStatus(0);
  1877. }
  1878. return ResponseJson.success(ross);
  1879. }
  1880. /**
  1881. * 获取已报名信息列表
  1882. * @return
  1883. */
  1884. @Override
  1885. public ResponseJson<List<RossChallengeRoundVo>> getcontestedInfo(Integer authUserId){
  1886. List<RossChallengeRoundVo> rossChallengeRoundVos = authMapper.getcontestedInfo(authUserId);
  1887. return ResponseJson.success(rossChallengeRoundVos);
  1888. }
  1889. /**
  1890. * 查询视频列表
  1891. * @param mobileOrAuthpart 电话号码或者机构名称
  1892. * @return
  1893. */
  1894. @Override
  1895. public ResponseJson<PageInfo<RossChallengeVideo>> getVideoAll(String mobileOrAuthpart,Integer clubUserId,Integer authUserId,Integer pageNum,Integer pageSize){
  1896. ChallengeActivityVo activityTime = authMapper.getActivityTime(authUserId);
  1897. if(null==activityTime&&StringUtils.isEmpty(activityTime.getStartTime())&&StringUtils.isEmpty(activityTime.getEndTime())){
  1898. return ResponseJson.success();
  1899. }
  1900. PageHelper.startPage(pageNum, pageSize);
  1901. List<RossChallengeVideo> videoAll = authMapper.getVideoAll(mobileOrAuthpart,authUserId,activityTime.getStartTime(),activityTime.getEndTime());
  1902. PageInfo<RossChallengeVideo> pageData = new PageInfo<>(videoAll);
  1903. //获取该用户点赞过的视频
  1904. //如果clubUserId为空,用户不能点赞,直接返回所有视频
  1905. if(null!=clubUserId){
  1906. if(null!=videoAll&& videoAll.size()>0){
  1907. for(RossChallengeVideo video:videoAll){
  1908. if (StringUtils.isNotEmpty(video.getClubUserIds())) {
  1909. if (video.getClubUserIds().contains(clubUserId.toString())) {
  1910. video.setDiggStatus(1);
  1911. } else {
  1912. video.setDiggStatus(0);
  1913. }
  1914. } else {
  1915. video.setDiggStatus(0);
  1916. }
  1917. };
  1918. }
  1919. }
  1920. return ResponseJson.success(pageData);
  1921. }
  1922. /**
  1923. * 根据手机号码查询该机构视频列表
  1924. * @param mobile 登录账号
  1925. * @return
  1926. */
  1927. @Override
  1928. public ResponseJson<List<RossChallengeVideo>> getVideoByUsername(String mobile,Integer clubUserId,Integer authUserId){
  1929. //获取活动时间内的机构列表信息
  1930. ChallengeActivityVo activityTime = authMapper.getActivityTime(authUserId);
  1931. if(null==activityTime&&StringUtils.isEmpty(activityTime.getStartTime())&&StringUtils.isEmpty(activityTime.getEndTime())){
  1932. return ResponseJson.success();
  1933. }
  1934. List<RossChallengeVideo> videoByUsername = authMapper.getVideoByUsername(mobile,activityTime.getStartTime(),activityTime.getEndTime());
  1935. //获取该用户点赞过的视频
  1936. if(null!=clubUserId){
  1937. if(null!=videoByUsername&& videoByUsername.size()>0){
  1938. for(RossChallengeVideo video:videoByUsername){
  1939. if (StringUtils.isNotEmpty(video.getClubUserIds())) {
  1940. if (video.getClubUserIds().contains(clubUserId.toString())) {
  1941. video.setDiggStatus(1);
  1942. } else {
  1943. video.setDiggStatus(0);
  1944. }
  1945. } else {
  1946. video.setDiggStatus(0);
  1947. }
  1948. };
  1949. }
  1950. }
  1951. return ResponseJson.success(videoByUsername);
  1952. }
  1953. /**
  1954. * 验证机构是否已经上传了3个视频
  1955. * @param mobile 登录账号
  1956. * @return
  1957. */
  1958. @Override
  1959. public ResponseJson<List<RossChallengeVideo>> checkVideoByUsername(String mobile,Integer authUserId){
  1960. //获取活动时间
  1961. ChallengeActivityVo activityTime = authMapper.getActivityTime(authUserId);
  1962. if(null!=activityTime&&StringUtils.isNotEmpty(activityTime.getStartTime())&&StringUtils.isNotEmpty(activityTime.getEndTime())){
  1963. //活动时间内用户是否参与比赛
  1964. List<RossChallengeVideo> rossChallengeVideos = authMapper.checkVideoByUsername(mobile,activityTime.getStartTime(),activityTime.getEndTime());
  1965. if(null!=rossChallengeVideos&&rossChallengeVideos.size()>=3){
  1966. return ResponseJson.success(-1,"抱歉,最多只能上传3个视频!!!",null);
  1967. }else{
  1968. return ResponseJson.success();
  1969. }
  1970. }else{
  1971. return ResponseJson.success();
  1972. }
  1973. }
  1974. /**
  1975. * 点赞与取消点赞
  1976. * @param id
  1977. * @return
  1978. */
  1979. @Override
  1980. public ResponseJson upVideoDiggCount(Integer id,Integer diggFlag,Integer clubUserId,String clubUserIds){
  1981. if(diggFlag==0){
  1982. //取消点赞
  1983. if(StringUtils.isNotEmpty(clubUserIds)){
  1984. if(clubUserIds.contains(clubUserId.toString())){
  1985. clubUserIds=clubUserIds.replace(clubUserId.toString(),"");
  1986. clubUserIds=clubUserIds.replace(",,",",");
  1987. if(clubUserIds.lastIndexOf(",")==clubUserIds.length()-1){
  1988. clubUserIds=clubUserIds.substring(0,clubUserIds.length()-1);
  1989. }
  1990. if(clubUserIds.indexOf(",")==0){
  1991. clubUserIds=clubUserIds.substring(1,clubUserIds.length());
  1992. }
  1993. }
  1994. }
  1995. }else if(diggFlag==1){
  1996. //点赞
  1997. if(StringUtils.isEmpty(clubUserIds)){
  1998. clubUserIds=clubUserIds+clubUserId;
  1999. }else{
  2000. clubUserIds=clubUserIds+","+clubUserId;
  2001. }
  2002. }
  2003. authMapper.upVideoDiggCount(id,diggFlag,clubUserIds);
  2004. return ResponseJson.success();
  2005. }
  2006. /**
  2007. * 查询机构信息(后端)
  2008. * @param mobile
  2009. * @return
  2010. */
  2011. @Override
  2012. public ResponseJson<PageInfo<RossChallengeRoundVo>> getAuthInfo(String mobile,Integer pageNum,Integer pageSize,Integer authUserId){
  2013. //获取活动时间内的机构列表信息
  2014. ChallengeActivityVo activityTime = authMapper.getActivityTime(authUserId);
  2015. PageHelper.startPage(pageNum, pageSize);
  2016. List<RossChallengeRoundVo> authInfo = authMapper.getAuthInfo(mobile,authUserId,activityTime.getStartTime(),activityTime.getEndTime());
  2017. PageInfo<RossChallengeRoundVo> pageData = new PageInfo<>(authInfo);
  2018. if(null!=authInfo&&authInfo.size()>0){
  2019. for (RossChallengeRoundVo search:authInfo) {
  2020. if(null != search.getContestTime()){
  2021. SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  2022. Date da=new Date(search.getContestTime().getTime());
  2023. String date = fmt.format(da);
  2024. search.setContestDate(date);
  2025. }
  2026. }
  2027. }
  2028. return ResponseJson.success(pageData);
  2029. }
  2030. /**
  2031. * 根据id删除机构信息
  2032. * @param id
  2033. * @return
  2034. */
  2035. @Override
  2036. public ResponseJson delAuthInfoById(Integer id){
  2037. //先删除机构对应的视频信息
  2038. RossChallengeRoundVo round = authMapper.getRoundById(id);
  2039. if(null!=round && StringUtils.isNotEmpty(round.getUserName())){
  2040. authMapper.delVideoInfoByUserName(round.getUserName());
  2041. }
  2042. //再删除机构信息
  2043. authMapper.delAuthInfoById(id);
  2044. return ResponseJson.success();
  2045. }
  2046. /**
  2047. * 根据id删除视频信息
  2048. * @param id
  2049. * @return
  2050. */
  2051. @Override
  2052. public ResponseJson delVideoInfoById(Integer id){
  2053. authMapper.delVideoInfoById(id);
  2054. return ResponseJson.success();
  2055. }
  2056. public void smsSend(Integer authUserId){
  2057. //获取手机号码
  2058. // List<RossChallengeRoundVo> roundByAuthUserID = authMapper.getRoundByAuthUserID(authUserId);
  2059. List<ClubUserVo> clubUserList = clubMapper.getmobile(authUserId);
  2060. //获取供应商名称
  2061. String authParty=authMapper.getAuthparty(authUserId);
  2062. if(authUserId==12){
  2063. authParty="西班牙ROSS";
  2064. }
  2065. //短信类型:1通知短信,2验证码短信,3营销短信
  2066. Integer type=3;
  2067. //[s{20}]尊敬的会员,ROSS视频挑战赛报名通道已开启,点此【http://f6d.cn/Fgp6r】进入ROSS认证通,了解详情。
  2068. String conn="[" + authParty + "]尊敬的会员,ROSS视频挑战赛报名通道已开启,点此https://zp.caimei365.com/12/ross/activity/challenge进入ROSS认证通,了解详情。";
  2069. if(null!=clubUserList&& clubUserList.size()>0){
  2070. clubUserList.stream().forEach(round ->{
  2071. if(StringUtils.isNotEmpty(round.getMobile())){
  2072. Boolean aBoolean = SmsUtils.sendSms(type, round.getMobile(), conn);
  2073. if(aBoolean){
  2074. log.info("挑战赛短信发送成功"+round.getMobile());
  2075. }else{
  2076. log.info("挑战赛短信发送失败"+round.getMobile());
  2077. }
  2078. }
  2079. });
  2080. }
  2081. }
  2082. }