AuthServiceImpl.java 92 KB

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