BaseApi.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. package com.caimei365.user.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.aliyuncs.exceptions.ClientException;
  4. import com.caimei365.user.components.WeChatService;
  5. import com.caimei365.user.idempotent.IpSave;
  6. import com.caimei365.user.model.ResponseJson;
  7. import com.caimei365.user.model.dto.MobileDto;
  8. import com.caimei365.user.model.dto.PasswordDto;
  9. import com.caimei365.user.model.po.CmUser;
  10. import com.caimei365.user.model.po.SysDict;
  11. import com.caimei365.user.model.vo.SysDictVO;
  12. import com.caimei365.user.service.BaseService;
  13. import com.caimei365.user.service.SysDictService;
  14. import com.caimei365.user.utils.RequestUtil;
  15. import io.swagger.annotations.*;
  16. import lombok.RequiredArgsConstructor;
  17. import org.apache.ibatis.annotations.Param;
  18. import org.springframework.beans.factory.annotation.Value;
  19. import org.springframework.http.ResponseEntity;
  20. import org.springframework.web.bind.annotation.*;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Map;
  24. /**
  25. * 用户公共API
  26. *
  27. * @author : Charles
  28. * @date : 2021/3/4
  29. */
  30. @Api(tags = "用户公共API")
  31. @RestController
  32. @RequiredArgsConstructor
  33. @RequestMapping("/user")
  34. public class BaseApi {
  35. private final BaseService baseService;
  36. private final WeChatService weChatService;
  37. private final SysDictService sysDictService;
  38. @Value(value = "${swagger.enabled}")
  39. private Boolean swaggerEnabled;
  40. @GetMapping("")
  41. public String welcome() {
  42. if (swaggerEnabled) {
  43. return "欢迎使用!<br><a href='http://47.119.112.46:18011/doc.html'>doc接口文档入口(beta)</a><br><a href='http://47.119.112.46:18011/swagger-ui/index.html'>swagger接口文档入口(beta)</a>";
  44. }
  45. return "欢迎使用!";
  46. }
  47. /**
  48. * Token失效
  49. */
  50. @GetMapping("/unauthorized")
  51. public ResponseJson<Void> unauthorized() {
  52. return ResponseJson.error(-99, "Token失效请重新登录!", null);
  53. }
  54. /**
  55. * 获取图片验证码
  56. * <p>
  57. * spi旧接口:/user/getImgVerifyCode
  58. *
  59. * @param platformType 0:www,1:crm/h5,2:小程序
  60. */
  61. @ApiOperation("获取图片验证码")
  62. @ApiImplicitParam(required = true, name = "platformType", value = "0:www,1:crm/h5,2:小程序")
  63. @IpSave(saveName = "获取图片验证码", saveParams = false)
  64. @GetMapping("/captcha")
  65. public ResponseJson<Map<String, Object>> getCaptchaImage(Integer platformType) {
  66. return baseService.getCaptchaImage(platformType);
  67. }
  68. /**
  69. * 获取短信验证码
  70. * <p>
  71. * spi旧接口:/user/activateCodeByReg
  72. *
  73. * @param mobile 手机号
  74. * @param activateCodeType 1:找回密码,2:注册机构,3:供应商注册,4:修改手机号-旧手机验证码,5:修改手机号-新手机验证码,6.发布二手验证码
  75. * @param platformType 0:www,1:crm/h5,2:小程序
  76. * @param isCheckCaptcha 是否检查图片验证码,0:检查,1:不检查
  77. * @param imgCode 图片验证码
  78. * @param token 图片验证码token
  79. */
  80. @ApiOperation("获取短信验证码")
  81. @ApiImplicitParams({
  82. @ApiImplicitParam(required = true, name = "mobile", value = "手机号"),
  83. @ApiImplicitParam(required = true, name = "activateCodeType", value = "1:找回密码,2:注册机构,3:供应商注册,4:更换联系人手机号-旧手机验证码,5:更换联系人手机号-新手机验证码"),
  84. @ApiImplicitParam(required = false, name = "platformType", value = "0:www,1:crm/h5,2:小程序"),
  85. @ApiImplicitParam(required = false, name = "isCheckCaptcha", value = "是否检查图片验证码,0:检查,1:不检查"),
  86. @ApiImplicitParam(required = false, name = "imgCode", value = "图片验证码"),
  87. @ApiImplicitParam(required = false, name = "token", value = "图片token")
  88. })
  89. @IpSave(saveName = "获取短信验证码", saveParams = true)
  90. @GetMapping("/sms/code")
  91. public ResponseJson getSmsCode(String mobile, Integer activateCodeType, Integer platformType, Integer isCheckCaptcha, String imgCode, String token) {
  92. return baseService.getSmsCode(mobile, activateCodeType, platformType, isCheckCaptcha, imgCode, token);
  93. }
  94. /**
  95. * 绑定账号,发送短信验证
  96. * <p>
  97. * spi旧接口:/user/note
  98. *
  99. * @param mobile 运营人员手机号
  100. * @param bindMobile 机构手机号
  101. * @param userId 机构Id
  102. * @param platformType 0:www,1:crm/h5,2:小程序
  103. * @param isCheckCaptcha 是否检查图片验证码,0:检查,1:不检查
  104. * @param imgCode 图片验证码
  105. * @param token 图片验证码token
  106. */
  107. @ApiOperation("绑定账号,发送短信验证")
  108. @ApiImplicitParams({
  109. @ApiImplicitParam(required = true, name = "mobile", value = "运营人员手机号"),
  110. @ApiImplicitParam(required = false, name = "bindMobile", value = "机构手机号"),
  111. @ApiImplicitParam(required = false, name = "userId", value = "机构Id"),
  112. @ApiImplicitParam(required = false, name = "platformType", value = "0:www,1:crm/h5,2:小程序"),
  113. @ApiImplicitParam(required = false, name = "isCheckCaptcha", value = "是否检查图片验证码,0:检查,1:不检查"),
  114. @ApiImplicitParam(required = false, name = "imgCode", value = "图片验证码"),
  115. @ApiImplicitParam(required = false, name = "token", value = "图片token")
  116. })
  117. @IpSave(saveName = "绑定账号,发送短信验证", saveParams = true)
  118. @GetMapping("/sms/bind")
  119. public ResponseJson getBindSmsCode(String mobile, String bindMobile, Integer userId, Integer platformType, Integer isCheckCaptcha, String imgCode, String token) {
  120. return baseService.getBindSmsCode(mobile, bindMobile, userId, platformType, isCheckCaptcha, imgCode, token);
  121. }
  122. /**
  123. * 获取邮箱验证码
  124. *
  125. * @param email 邮箱
  126. * @param status 1:绑定邮箱,2邮箱注册,3邮箱找回秘密
  127. */
  128. @ApiOperation("获取邮箱验证码(旧:/user/mailbox)")
  129. @ApiImplicitParams({
  130. @ApiImplicitParam(required = true, name = "email", value = "邮箱"),
  131. @ApiImplicitParam(required = true, name = "status", value = "1:绑定邮箱,2邮箱注册,3邮箱找回秘密")
  132. })
  133. @GetMapping("/mail/code")
  134. public ResponseJson sendMail(String email, Integer status) {
  135. return baseService.getEmailCode(email, status);
  136. }
  137. /**
  138. * 获取登录验证码
  139. * @param mobile 输入手机号
  140. * @return
  141. */
  142. @ApiOperation("获取登录验证码")
  143. @GetMapping("/login/code")
  144. public ResponseJson loginSmsCode(String mobile) { return baseService.getLoginCode(mobile);}
  145. /**
  146. * 获取绑定运营人员验证码
  147. * @param mobile 输入手机号
  148. * @return
  149. */
  150. @ApiOperation("获取绑定运营人员验证码")
  151. @GetMapping("/operate/code")
  152. public ResponseJson operateSmsCode(String mobile) { return baseService.operateSmsCode(mobile);}
  153. /**
  154. * 修改密码(找回密码)
  155. *
  156. * @param passwordDto {
  157. * mobileOrEmail 手机号或邮箱
  158. * smsCode 短信验证码(旧:activationCode)
  159. * password 密码
  160. * confirmPwd 确认密码
  161. * status 1:手机号找回,2:邮箱找回
  162. * }
  163. */
  164. @ApiOperation("修改密码(旧:/user/findCompanyPwd)")
  165. @IpSave(saveName = "修改密码", saveParams = true)
  166. @PostMapping("/update/password")
  167. public ResponseJson updatePassword(PasswordDto passwordDto) {
  168. return baseService.updatePassword(passwordDto);
  169. }
  170. /**
  171. * 修改密码(找回密码)-- 组织
  172. *
  173. * @param passwordDto {
  174. * mobileOrEmail 手机号或邮箱
  175. * smsCode 短信验证码(旧:activationCode)
  176. * password 密码
  177. * confirmPwd 确认密码
  178. * status 1:手机号找回,2:邮箱找回
  179. * }
  180. */
  181. @ApiOperation("修改密码--组织")
  182. @PostMapping("/updateOrganize/password")
  183. public ResponseJson updateOrganizePassword(PasswordDto passwordDto) {
  184. return baseService.updateOrganizePassword(passwordDto);
  185. }
  186. /**
  187. * 更换联系人手机号
  188. *
  189. * @param mobileDto {
  190. * mobile 旧手机号(contractMobile)
  191. * smsCode 旧手机短信验证码(mobileCode)
  192. * newMobile 新手机号(contractMobile2)
  193. * newSmsCode 新手机短信验证码(mobileCode)
  194. * userId 用户Id
  195. * }
  196. */
  197. @ApiOperation("更换联系人手机号(旧:/club/changeMobile)")
  198. @PostMapping("/update/mobile")
  199. public ResponseJson changeMobile(MobileDto mobileDto) {
  200. return baseService.updateMobile(mobileDto);
  201. }
  202. @ApiOperation("超级会员购买记录接口")
  203. @GetMapping("/super/history")
  204. public ResponseJson findVipHistory(Integer userId,
  205. @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
  206. @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
  207. if (null == userId) {
  208. return ResponseJson.error("参数异常:用户Id不能为空!", null);
  209. }
  210. return baseService.findVipHistory(userId, pageNum, pageSize);
  211. }
  212. @ApiOperation("超级会员会员中心")
  213. @IpSave(saveName = "超级会员中心", saveParams = true)
  214. @GetMapping("/super/center")
  215. public ResponseJson<Map<String, Object>> superCenter(Integer userId, Integer source) {
  216. if (null == userId) {
  217. return ResponseJson.error("参数异常:用户Id不能为空!", null);
  218. }
  219. return baseService.superCenter(userId, source);
  220. }
  221. @ApiOperation("超级会员套餐详情")
  222. @IpSave(saveName = "超级会员套餐详情", saveParams = false)
  223. @GetMapping("/super/package")
  224. public ResponseJson findPackage() {
  225. return baseService.findPackage();
  226. }
  227. @ApiOperation("获取阿里云token")
  228. @GetMapping("/oss/token")
  229. public ResponseJson<HashMap<String, String>> ossTokenGet() throws ClientException {
  230. return baseService.ossTokenGet();
  231. }
  232. @ApiOperation("获取微信跳转url")
  233. @GetMapping("/wechat/link")
  234. public ResponseJson getWechatLink(String path, String query, String env) {
  235. return weChatService.getOpenLink(path, query, env);
  236. }
  237. @ApiOperation("获取微信跳转url 联合丽格")
  238. @GetMapping("/wechat/link/mcare")
  239. public ResponseJson getWechatLinkMcare(String path, String query, String env) {
  240. return weChatService.getOpenLinkMcare(path, query, env);
  241. }
  242. @ApiOperation("获取Dict")
  243. @GetMapping("/getDict")
  244. public ResponseJson getDict(String type) {
  245. if (null == type) {
  246. return ResponseJson.error("参数异常:type不能为空!", null);
  247. }
  248. return ResponseJson.success(sysDictService.getSysDictList(new SysDict().setType(type)));
  249. }
  250. @ApiOperation("获取userId")
  251. @GetMapping("/getFindUserId")
  252. public ResponseJson getFindUserId(Integer userType, Integer id) {
  253. return baseService.getByUserId(userType, id);
  254. }
  255. @ApiOperation("获取Mobile")
  256. @GetMapping("/getByDistributionClubMobile")
  257. public ResponseJson getByMobile(Integer userId) {
  258. return ResponseJson.success(baseService.getByMobile(8, userId));
  259. }
  260. @ApiOperation("获取user数量")
  261. @GetMapping("/getByUserCount")
  262. public Integer getByUserCount(CmUser user) {
  263. return baseService.getByUserCount(user);
  264. }
  265. }