CommonController.java 14 KB

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