CommonController.java 14 KB

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