CommonController.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. package com.zhongzheng.controller.cmmon;
  2. import cn.hutool.core.lang.Validator;
  3. import com.alibaba.fastjson.JSON;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.zhongzheng.common.core.controller.BaseController;
  6. import com.zhongzheng.common.core.domain.AjaxResult;
  7. import com.zhongzheng.common.core.page.TableDataInfo;
  8. import com.zhongzheng.common.core.redis.RedisCache;
  9. import com.zhongzheng.common.exception.CustomException;
  10. import com.zhongzheng.common.utils.DateUtils;
  11. import com.zhongzheng.common.utils.ServletUtils;
  12. import com.zhongzheng.common.utils.ToolsUtils;
  13. import com.zhongzheng.framework.web.service.WxLoginService;
  14. import com.zhongzheng.modules.activity.vo.ActivityGoodsPriceVo;
  15. import com.zhongzheng.modules.alisms.bo.SmsAddBo;
  16. import com.zhongzheng.modules.alisms.service.IAliSmsService;
  17. import com.zhongzheng.modules.base.bo.ConfigQueryBo;
  18. import com.zhongzheng.modules.course.bo.CourseQueryBo;
  19. import com.zhongzheng.modules.course.bo.CourseTopicGoodsQueryBo;
  20. import com.zhongzheng.modules.course.service.ICourseService;
  21. import com.zhongzheng.modules.course.service.ICourseTopicService;
  22. import com.zhongzheng.modules.course.vo.CourseTopicGoodsVo;
  23. import com.zhongzheng.modules.course.vo.CourseTopicVo;
  24. import com.zhongzheng.modules.course.vo.CourseUserVo;
  25. import com.zhongzheng.modules.data.domain.DataWxTpClick;
  26. import com.zhongzheng.modules.data.service.IDataWxTpClickService;
  27. import com.zhongzheng.modules.distribution.bo.DistributionActivityGoodsQueryBo;
  28. import com.zhongzheng.modules.distribution.service.IDistributionActivityGoodsService;
  29. import com.zhongzheng.modules.distribution.service.IDistributionSellerService;
  30. import com.zhongzheng.modules.distribution.vo.DistributionSellerVo;
  31. import com.zhongzheng.modules.goods.bo.DistributionGoodsBo;
  32. import com.zhongzheng.modules.goods.service.IGoodsSpecTemplateService;
  33. import com.zhongzheng.modules.goods.vo.GoodsSpecTemplateVo;
  34. import com.zhongzheng.modules.goods.vo.GoodsUserVo;
  35. import com.zhongzheng.modules.goods.vo.GoodsVo;
  36. import com.zhongzheng.modules.order.domain.Printer;
  37. import com.zhongzheng.modules.system.bo.SysTenantQueryBo;
  38. import com.zhongzheng.modules.system.service.ISysConfigService;
  39. import com.zhongzheng.modules.system.service.ISysTenantService;
  40. import com.zhongzheng.modules.user.bo.UserLiveAccountLoginBo;
  41. import com.zhongzheng.modules.user.service.IUserService;
  42. import com.zhongzheng.modules.user.vo.UserLiveAccountLoginVo;
  43. import com.zhongzheng.modules.wx.bo.WxInfoBo;
  44. import com.zhongzheng.modules.wx.bo.WxInfoQuery;
  45. import com.zhongzheng.modules.wx.bo.WxServerBody;
  46. import com.zhongzheng.modules.wx.domain.*;
  47. import io.swagger.annotations.Api;
  48. import io.swagger.annotations.ApiOperation;
  49. import lombok.RequiredArgsConstructor;
  50. import org.springframework.beans.factory.annotation.Autowired;
  51. import org.springframework.web.bind.annotation.*;
  52. import org.springframework.web.multipart.MultipartFile;
  53. import javax.servlet.ServletOutputStream;
  54. import javax.servlet.http.HttpServletResponse;
  55. import java.io.ByteArrayOutputStream;
  56. import java.io.IOException;
  57. import java.io.InputStream;
  58. import java.text.ParseException;
  59. import java.util.HashMap;
  60. import java.util.List;
  61. import java.util.Map;
  62. /**
  63. * 课程Controller
  64. *
  65. * @author hjl
  66. * @date 2021-10-09
  67. */
  68. @Api(value = "游客访问接口", tags = {"游客访问接口"})
  69. @RequiredArgsConstructor(onConstructor_ = @Autowired)
  70. @RestController
  71. @RequestMapping("/app/common/")
  72. public class CommonController extends BaseController {
  73. private final ICourseService iCourseService;
  74. private final WxLoginService wxLoginService;
  75. private final ISysConfigService configService;
  76. private final IDistributionSellerService iDistributionSellerService;
  77. @Autowired
  78. private RedisCache redisCache;
  79. private final ICourseTopicService iCourseTopicService;
  80. private final IGoodsSpecTemplateService iGoodsSpecTemplateService;
  81. private final ISysTenantService iSysTenantService;
  82. private final IDataWxTpClickService iDataWxTpClickService;
  83. private final IDistributionActivityGoodsService iDistributionActivityGoodsService;
  84. private final IUserService iUserService;
  85. private final IAliSmsService iSmsService;
  86. @PostMapping("/returnStream")
  87. public AjaxResult returnStream(MultipartFile file, HttpServletResponse response) throws IOException {
  88. ServletOutputStream out = null;
  89. ByteArrayOutputStream baos = null;
  90. try {
  91. InputStream inStream = file.getInputStream();
  92. byte[] buffer = new byte[1024];
  93. int len;
  94. baos = new ByteArrayOutputStream();
  95. while ((len = inStream.read(buffer)) != -1) {
  96. baos.write(buffer, 0, len);
  97. }
  98. out = response.getOutputStream();
  99. out.write(baos.toByteArray());
  100. } catch (Exception e) {
  101. e.printStackTrace();
  102. } finally {
  103. baos.flush();
  104. baos.close();
  105. // out.flush();
  106. // out.close();
  107. }
  108. return AjaxResult.success();
  109. }
  110. /**
  111. * 获取微信小程序信息(网页跳转小程序)
  112. */
  113. @ApiOperation("获取微信小程序信息(网页跳转小程序)")
  114. @GetMapping("/get/wx/info")
  115. public AjaxResult<WxInfoBo> getWxInfo(WxInfoQuery query) {
  116. return AjaxResult.success(wxLoginService.getWxInfo(query));
  117. }
  118. /**
  119. * 获取小程序首页链接
  120. */
  121. @ApiOperation("获取小程序首页链接")
  122. @GetMapping("/get/small/link")
  123. public AjaxResult<Void> getWxSmallLink() {
  124. return AjaxResult.success(wxLoginService.getWxSmallLink());
  125. }
  126. /**
  127. * 获取商品专题页指定商品信息
  128. */
  129. @ApiOperation("获取商品专题页指定商品信息")
  130. @GetMapping("/get/goodsInfo/{topicId}")
  131. public AjaxResult<CourseTopicVo> getGoodsInfo(@PathVariable("topicId") Integer topicId) {
  132. return AjaxResult.success(iCourseTopicService.getGoodsInfo(topicId));
  133. }
  134. /**
  135. * 获取商品规格模板信息
  136. */
  137. @ApiOperation("获取商品规格模板信息")
  138. @GetMapping("/spec/{specTemplateId}")
  139. public AjaxResult<GoodsSpecTemplateVo> getSpecTemplate(@PathVariable("specTemplateId")Long specTemplateId) {
  140. return AjaxResult.success(iGoodsSpecTemplateService.queryById(specTemplateId));
  141. }
  142. /**
  143. * 获取商品规格模板信息
  144. */
  145. @ApiOperation("获取商品规格模板信息")
  146. @GetMapping("/distribution/spec")
  147. public AjaxResult<GoodsSpecTemplateVo> getDistributionSpec(DistributionGoodsBo bo) {
  148. return AjaxResult.success(iGoodsSpecTemplateService.getDistributionSpec(bo));
  149. }
  150. /**
  151. * 获取规格属性值对应的商品信息
  152. */
  153. @ApiOperation("获取规格属性值对应的商品信息")
  154. @GetMapping("/attr/goods")
  155. public AjaxResult<GoodsVo> getSpecTemplate(@RequestParam("specTemplateId")Long specTemplateId,@RequestParam("specAttrIds")String specAttrIds) {
  156. GoodsVo vo = iGoodsSpecTemplateService.getSpecTemplate(specTemplateId,specAttrIds);
  157. return AjaxResult.success(vo);
  158. }
  159. /**
  160. * 获取专题页组合班级商品
  161. */
  162. @ApiOperation("获取专题页组合班级商品")
  163. @GetMapping("/get/goodsList")
  164. public AjaxResult<List<CourseTopicGoodsVo>> getGoodsList(CourseTopicGoodsQueryBo bo) {
  165. return AjaxResult.success(iCourseTopicService.getGoodsList(bo));
  166. }
  167. /**
  168. * 查询课程列表
  169. */
  170. @ApiOperation("查询商品下的课程列表")
  171. @GetMapping("/courseList")
  172. public TableDataInfo<CourseUserVo> courseList(CourseQueryBo bo) {
  173. startPage();
  174. List<CourseUserVo> list = iCourseService.courseList(bo);
  175. return getDataTable(list);
  176. }
  177. @ApiOperation("获取微信参数")
  178. @GetMapping("/wx/config")
  179. public AjaxResult<Map<String, Object>> wxConfig() {
  180. Map<String, Object> map = new HashMap<>();
  181. String smallAppId = configService.selectConfigByKey("wx.small.appid");
  182. String gzhAppId = configService.selectConfigByKey("wx.gzh.appid");
  183. map.put("smallAppId", smallAppId);
  184. map.put("gzhAppId", gzhAppId);
  185. return AjaxResult.success(map);
  186. }
  187. /**
  188. * 查询课程列表
  189. */
  190. @ApiOperation("查询用户拥有的商品")
  191. @GetMapping("/goodsList")
  192. public TableDataInfo<GoodsUserVo> goodsList(CourseQueryBo bo) {
  193. startPage();
  194. List<GoodsUserVo> list = iCourseService.goodsList(bo);
  195. return getDataTable(list);
  196. }
  197. @ApiOperation("查询用户拥有的商品")
  198. @GetMapping("/test")
  199. public AjaxResult<Integer> test(CourseQueryBo bo) throws InterruptedException, ParseException {
  200. return AjaxResult.success(Printer.num);
  201. }
  202. @ApiOperation("小程序配置")
  203. @GetMapping("/config")
  204. public AjaxResult<Map<String,Object>> config(ConfigQueryBo bo) {
  205. Map<String,Object> map = new HashMap<>();
  206. map.put("hide",false);
  207. if(Validator.isNotEmpty(bo.getVersion())){
  208. String hideVersion = configService.selectConfigByKey("version.hide");
  209. if(bo.getVersion().equals(hideVersion)){
  210. map.put("hide",true);
  211. }
  212. }
  213. return AjaxResult.success(map);
  214. }
  215. @ApiOperation("登录双重验证")
  216. @GetMapping("/dual_auth")
  217. public AjaxResult<String> dual_auth() {
  218. String dualAuth = configService.selectConfigByKey("login.dual.auth");
  219. return AjaxResult.success("成功",dualAuth);
  220. }
  221. /**
  222. * 公众号服务接口
  223. */
  224. @ApiOperation("公众号服务接口")
  225. @GetMapping("/wxGzhServer")
  226. public String wxGzhServer(WxServerBody bo) {
  227. try {
  228. String token = "511A23101c826G90T1";
  229. String EncodingAESKey = "ybzse4DNAMj9oGzZ9kQqOX0F7nKjebGZ3xNesVFInPP";
  230. String echostr = bo.getEchostr();
  231. if (ToolsUtils.checkGzhServerSignature(token,bo.getSignature(), bo.getTimestamp(), bo.getNonce())) {
  232. return echostr;
  233. }
  234. } catch (Exception e) {
  235. //验证公众号token失败
  236. }
  237. return null;
  238. }
  239. @ApiOperation("公众号服务接口")
  240. @PostMapping("/wxGzhServer")
  241. public String wxGzhServer(@RequestBody String xmlData) {
  242. // 将xml格式的数据,转换为 AllMessage 对象
  243. AllMessage allMessage = MessageUtil.xmlToAllMessage(xmlData);
  244. String TenantId = "867735392558919680";
  245. ServletUtils.getRequestAttributes().getResponse().setHeader("TenantId", TenantId);
  246. // 是否是文本消息类型
  247. if (allMessage.getMsgType().equals(MessageTypeEnum.MSG_TEXT.getMsgType())) {
  248. // 自动回复用户所发送的文本消息
  249. // return MessageUtil.autoReply(allMessage, ContentEnum.CONTENT_PREFIX.getContent() + allMessage.getContent());
  250. return "";
  251. }
  252. // 是否是事件推送类型
  253. else if (allMessage.getMsgType().equals(MessageTypeEnum.MSG_EVENT.getMsgType())) {
  254. // 是否为订阅事件,即公众号被关注时所触发的事件
  255. if (EventType.EVENT_SUBSCRIBE.getEventType().equals(allMessage.getEvent())) {
  256. // System.out.println("关注");
  257. String openId = allMessage.getFromUserName();
  258. wxLoginService.subGzh(openId);
  259. // 自动回复欢迎语
  260. return MessageUtil.autoReply(allMessage, ContentEnum.CONTENT_SUBSCRIBE.getContent());
  261. }
  262. else if (EventType.EVENT_UNSUBSCRIBE.getEventType().equals(allMessage.getEvent())) {
  263. String openId = allMessage.getFromUserName();
  264. wxLoginService.unsubGzh(openId);
  265. // System.out.println("取消关注");
  266. }
  267. } else {
  268. // 暂不支持文本以外的消息回复
  269. return MessageUtil.autoReply(allMessage, ContentEnum.CONTENT_NONSUPPORT.getContent());
  270. }
  271. return MessageUtil.autoReply(allMessage, ContentEnum.CONTENT_NONSUPPORT.getContent());
  272. }
  273. /**
  274. * 获取企业ID
  275. */
  276. @ApiOperation("获取企业ID")
  277. @GetMapping("/findTenantId")
  278. public AjaxResult<String> findTenantId(SysTenantQueryBo bo) {
  279. Long tenantId = iSysTenantService.findTenantId(bo);
  280. if(Validator.isNotEmpty(tenantId)){
  281. return AjaxResult.success("成功",tenantId.toString());
  282. }else{
  283. if(Validator.isNotEmpty(bo.getHostH5())&&bo.getHostH5().equals("120.79.166.78:19012")){
  284. return AjaxResult.success("成功","867735392558919680");
  285. }
  286. if(Validator.isNotEmpty(bo.getHostLive())&&bo.getHostLive().equals("120.79.166.78:19012")){
  287. return AjaxResult.success("成功","867735392558919680");
  288. }
  289. if(Validator.isNotEmpty(bo.getHostPc())&&bo.getHostPc().equals("120.79.166.78:19012")){
  290. return AjaxResult.success("成功","867735392558919680");
  291. }
  292. if(Validator.isNotEmpty(bo.getHostH5Seller())&&bo.getHostH5Seller().equals("120.79.166.78:19012")){
  293. return AjaxResult.success("成功","867735392558919680");
  294. }
  295. return AjaxResult.error("失败",null);
  296. }
  297. }
  298. @ApiOperation("移动端配置参数")
  299. @GetMapping("/mobileConfig")
  300. public AjaxResult<Map<String,Object>> mobileConfig(ConfigQueryBo bo) {
  301. Map<String,Object> map = new HashMap<>();
  302. String json = configService.selectConfigByKey("home.mobile");
  303. map.put("mobileConfig",json);
  304. return AjaxResult.success(map);
  305. }
  306. /**
  307. * 领取题库活动校验
  308. */
  309. @ApiOperation("领取题库活动校验")
  310. @GetMapping("/check")
  311. public AjaxResult<Void> checkTime() {
  312. return toAjax(iCourseService.checkTime()? 1 : 0);
  313. }
  314. /**
  315. * 领取题库活动记录
  316. */
  317. @ApiOperation("领取题库活动记录")
  318. @GetMapping("/save/activity/record/{crowdType}")
  319. public AjaxResult<Void> saveActivityRecord(@PathVariable("crowdType") Integer crowdType) {
  320. DataWxTpClick dataWxTpClick = new DataWxTpClick();
  321. dataWxTpClick.setCrowdType(crowdType);
  322. dataWxTpClick.setCreateTime(DateUtils.getNowTime());
  323. dataWxTpClick.setType(2);
  324. dataWxTpClick.setStatus(1);
  325. dataWxTpClick.setInformId(0L);
  326. dataWxTpClick.setUpdateTime(DateUtils.getNowTime());
  327. return toAjax(iDataWxTpClickService.save(dataWxTpClick)? 1 : 0);
  328. }
  329. @ApiOperation("通过分享code查询业务员用户信息")
  330. @GetMapping("/distribution/getInfoByShareCode")
  331. public AjaxResult<DistributionSellerVo> getInfoByShareCode(String shareCode)
  332. {
  333. DistributionSellerVo vo = iDistributionSellerService.queryByShareCode(shareCode);
  334. vo.setNull();
  335. String jsonStr = configService.selectConfigByKey("home.header");
  336. JSONObject objectJson = JSON.parseObject(jsonStr);
  337. vo.setTenantName(String.valueOf(objectJson.get("companyName")));
  338. return AjaxResult.success(vo);
  339. }
  340. @ApiOperation("获取分销活动商品列表")
  341. @GetMapping("/distribution/getGoodsList")
  342. public TableDataInfo<ActivityGoodsPriceVo> distributionGoodsList(DistributionActivityGoodsQueryBo bo)
  343. {
  344. startPage();
  345. List<ActivityGoodsPriceVo> list = iDistributionActivityGoodsService.getGoodsList(bo);
  346. return getDataTable(list);
  347. }
  348. @RequestMapping("/token_offline")
  349. public void loginAuthFailOffLine() {
  350. throw new CustomException("用户验证错误",409);
  351. }
  352. @ApiOperation("直播短信统一登录")
  353. @PostMapping("/live/sms_login")
  354. public AjaxResult<UserLiveAccountLoginVo> sms_login(@RequestBody UserLiveAccountLoginBo bo) {
  355. UserLiveAccountLoginVo vo = iUserService.smsLiveUnifyLogin(bo);
  356. return AjaxResult.success(vo);
  357. }
  358. @ApiOperation("直播账号统一登录")
  359. @PostMapping("/live/account_login")
  360. public AjaxResult<UserLiveAccountLoginVo> account_login(@RequestBody UserLiveAccountLoginBo bo) {
  361. UserLiveAccountLoginVo vo = iUserService.liveUnifyLogin(bo);
  362. return AjaxResult.success(vo);
  363. }
  364. @ApiOperation("直播账号统一登录刷新")
  365. @PostMapping("/live/account_login/refresh")
  366. public AjaxResult<UserLiveAccountLoginVo> account_loginRefresh(@RequestBody UserLiveAccountLoginBo bo) {
  367. UserLiveAccountLoginVo vo = iUserService.liveUnifyLoginRefresh(bo);
  368. return AjaxResult.success(vo);
  369. }
  370. @ApiOperation("获取登录短信")
  371. @PostMapping("/live/sms")
  372. public AjaxResult liveSms(@RequestBody SmsAddBo bo) {
  373. iSmsService.sendLiveSms(bo.getTel());
  374. return AjaxResult.success();
  375. }
  376. @ApiOperation("获取7个工作日后的时间")
  377. @GetMapping("/live/time")
  378. public AjaxResult getLiveTime() {
  379. Long time = iCourseService.getLiveTime();
  380. return AjaxResult.success(time);
  381. }
  382. }