UserController.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. package com.ym.mec.collectfee.controller;
  2. import com.ym.mec.collectfee.common.web.BaseController;
  3. import com.ym.mec.collectfee.entity.*;
  4. import com.ym.mec.collectfee.service.ApplyInfoService;
  5. import com.ym.mec.collectfee.service.CourseGroupInfoService;
  6. import com.ym.mec.collectfee.service.OrderService;
  7. import com.ym.mec.collectfee.service.SchoolService;
  8. import com.ym.mec.collectfee.utils.Constants;
  9. import org.apache.commons.lang3.StringUtils;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.dao.DuplicateKeyException;
  12. import org.springframework.transaction.annotation.Transactional;
  13. import org.springframework.web.bind.annotation.*;
  14. import javax.servlet.http.HttpSession;
  15. import java.util.Date;
  16. import java.util.HashMap;
  17. import java.util.List;
  18. import java.util.Map;
  19. @RestController()
  20. @RequestMapping("user")
  21. //@Api("用户服务")
  22. public class UserController extends BaseController {
  23. @Autowired
  24. private ApplyInfoService applyInfoService;
  25. @Autowired
  26. private SchoolService schoolService;
  27. @Autowired
  28. private OrderService orderService;
  29. @Autowired
  30. private CourseGroupInfoService courseGroupInfoService;
  31. /**
  32. * 查询用户详情
  33. *
  34. * @param phone
  35. * @param clazzId
  36. * @return
  37. */
  38. @GetMapping("/getUserDetailByPhone")
  39. // @ApiOperation(value = "根据乐团编号、用户手机,查询用户详情")
  40. // @ApiImplicitParams({ @ApiImplicitParam(name = "phone", value = "用户手机", required = true, dataType = "String"),
  41. // @ApiImplicitParam(name = "clazzId", value = "乐团编号", required = true, dataType = "Integer")})
  42. public Object getUserDetailByPhone(String phone, Integer clazzId, Integer cityId) {
  43. if (StringUtils.isEmpty(phone) || clazzId == null || cityId == null) {
  44. return failed(Constants.PARAM_VERIFY_ERROR_MSG);
  45. }
  46. ApplyInfo userByPhone = applyInfoService.findUserByPhone(phone, null);
  47. if (userByPhone == null && applyInfoService.mecUserIsExist(phone)!=null) {
  48. return failed(Constants.PARAM_EXIST_ERROR_MSG);
  49. }
  50. if (userByPhone != null && !userByPhone.getClassId().equals(clazzId)) {//如果改用户存在其他团中
  51. return failed(Constants.PARAM_EXIST_ERROR_MSG);
  52. }
  53. School school = schoolService.get(clazzId);
  54. if (school != null) {
  55. if (school.getCityId() == null) {
  56. school.setCityId(cityId);
  57. school.setUpdateTime(new Date());
  58. schoolService.update(school);
  59. }
  60. if (userByPhone != null) {
  61. userByPhone.setPushStatus(school.getStatus());
  62. }
  63. }
  64. return succeed(userByPhone);
  65. }
  66. /**
  67. * 查询用户详情
  68. *
  69. * @param phone
  70. * @param clazzId
  71. * @return
  72. */
  73. @GetMapping("/getMecUser")
  74. public Object getMecUser(String phone) {
  75. if (StringUtils.isEmpty(phone)) {
  76. return failed(Constants.PARAM_VERIFY_ERROR_MSG);
  77. }
  78. MecUserInfo mecUser = applyInfoService.mecUserIsExist(phone);
  79. MecUser user = null;
  80. if(mecUser != null){
  81. user = applyInfoService.findMecUser(mecUser.getUserId());
  82. }
  83. return succeed(user);
  84. }
  85. /**
  86. * 用户报名
  87. *
  88. * @param applyInfo
  89. * @return
  90. */
  91. // @ApiOperation(value = "学生报名乐团")
  92. @PostMapping("/userApply")
  93. public Object userApply(ApplyInfo applyInfo) {
  94. if (applyInfo != null) {
  95. try {
  96. Date date = new Date();
  97. applyInfo.setCreateTime(date);
  98. applyInfo.setUpdateTime(date);
  99. applyInfoService.insert(applyInfo);
  100. School school = schoolService.get(applyInfo.getClassId());
  101. if (school == null) {
  102. return failed("乐团数据不存在");
  103. } else {
  104. school.setSchoolId(applyInfo.getSchoolId());
  105. school.setUpdateTime(date);
  106. schoolService.update(school);
  107. }
  108. return succeed(applyInfo.getId());
  109. } catch (Exception e) {
  110. e.printStackTrace();
  111. if (e instanceof DuplicateKeyException) {
  112. return failed("该用户已存在");
  113. }
  114. return failed("报名失败");
  115. }
  116. }
  117. return failed(Constants.PARAM_VERIFY_ERROR_MSG);
  118. }
  119. /**
  120. * 根据乐团id获取乐团详情,查询乐团状态也通过该接口
  121. *
  122. * @param schoolId
  123. * @return
  124. */
  125. // @ApiOperation(value = "根据乐团编号获取乐团详情,查询乐团状态也通过该接口")
  126. @PostMapping("/getClassDetail")
  127. // @ApiImplicitParams({ @ApiImplicitParam(name = "clazzId", value = "乐团编号", required = true, dataType = "Integer"),
  128. // @ApiImplicitParam(name = "schoolId", value = "学校编号", required = true, dataType = "Integer")})
  129. public Object getSchoolDetail(Integer schoolId) {
  130. if (schoolId == null) {
  131. return failed(Constants.PARAM_VERIFY_ERROR_MSG);
  132. }
  133. return succeed(orderService.getSchoolDetail(schoolId));
  134. }
  135. /**
  136. * 根据学生编号获取乐团注册页面数据
  137. *
  138. * @param stuId
  139. * @return
  140. */
  141. // @ApiOperation(value = "根据学生编号获取乐团注册页面数据")
  142. @PostMapping("/getUserRegisterViewDetail")
  143. public Object getUserRegisterViewDetail(Integer stuId) {
  144. if (stuId == null) {
  145. return failed(Constants.PARAM_VERIFY_ERROR_MSG);
  146. }
  147. return succeed(applyInfoService.getUserRegisterViewDetail(stuId));
  148. }
  149. /**
  150. * 推送用户到mec注册
  151. * @return
  152. */
  153. /*@PostMapping("/userRegister")
  154. public Object userRegister(String phone){
  155. return succeed(applyInfoService.userRegister(phone));
  156. }*/
  157. /**
  158. * 获取乐团课程组列表
  159. *
  160. * @return
  161. */
  162. @PostMapping("/getCourses")
  163. // @ApiOperation(value = "根据乐团编号,获取乐团课程组列表")
  164. // @ApiImplicitParams({ @ApiImplicitParam(name = "clazzId", value = "乐团编号", required = true, dataType = "Integer")})
  165. public Object getCourses(Integer clazzId) {
  166. if (clazzId == null) {
  167. return failed(Constants.PARAM_VERIFY_ERROR_MSG);
  168. }
  169. return succeed(courseGroupInfoService.getCourses(clazzId));
  170. }
  171. // @ApiOperation(value = "获取所有乐团列表")
  172. @PostMapping("/getMusicTeams")
  173. public Object getMusicTeams(MusicTeamsPageInfo pageInfo) {
  174. return succeed(schoolService.queryPage(pageInfo));
  175. }
  176. // @ApiOperation(value = "根据乐团编号,获取学员列表")
  177. @PostMapping("/getMusicTeamStu")
  178. public Object getMusicTeamStu(StudentsQueryInfo queryInfo) {
  179. return succeed(applyInfoService.queryUserPage(queryInfo));
  180. }
  181. // @ApiOperation(value = "获取所有分部列表")
  182. @GetMapping("/getBranches")
  183. public Object getBranches() {
  184. return succeed(applyInfoService.getBranches());
  185. }
  186. // @ApiOperation(value = "获取学校详情")
  187. @GetMapping("/getSchool")
  188. public Object getSchool(Integer schoolId) {
  189. if (schoolId == null) {
  190. return failed(Constants.PARAM_VERIFY_ERROR_MSG);
  191. }
  192. return succeed(applyInfoService.get(schoolId));
  193. }
  194. /**
  195. * 保存学校列表
  196. * @return
  197. */
  198. // @GetMapping("/saveSeminary")
  199. // public Object saveSeminary(){
  200. // applyInfoService.saveSeminary();
  201. // return succeed();
  202. // }
  203. /**
  204. * 修改乐团信息
  205. *
  206. * @return
  207. */
  208. // @ApiOperation(value = "修改乐团信息")
  209. @PostMapping("/updateClass")
  210. public Object updateClass(School school) {
  211. school.setUpdateTime(new Date());
  212. schoolService.update(school);
  213. return succeed();
  214. }
  215. /**
  216. * 开启乐团缴费功能
  217. *
  218. * @return
  219. */
  220. // @ApiOperation(value = "开启乐团缴费功能")
  221. @PostMapping("/openClassPay")
  222. public Object openClassPay(Integer id, String smsMsg, int type, int isSingle, int amountType) {//1是线上 2 线下 amountType 1-800 2-1500
  223. if (id == null || (isSingle > 1 || isSingle < 0) || (type == 2 && StringUtils.isEmpty(smsMsg))) {
  224. return failed(Constants.PARAM_VERIFY_ERROR_MSG);
  225. }
  226. schoolService.openClassPay(id, smsMsg, type, isSingle, amountType);
  227. return succeed();
  228. }
  229. /**
  230. * 关闭乐团缴费
  231. *
  232. * @return
  233. */
  234. // @ApiOperation(value = "关闭乐团缴费功能")
  235. @PostMapping("/closeClassPay")
  236. public Object closeClassPay(Integer id) {
  237. if (id == null) {
  238. return failed(Constants.PARAM_VERIFY_ERROR_MSG);
  239. }
  240. School school = schoolService.get(id);
  241. school.setStatus(5);
  242. return succeed(schoolService.update(school));
  243. }
  244. /**
  245. * 修改学生信息
  246. *
  247. * @return
  248. */
  249. // @ApiOperation(value = "修改学生信息")
  250. @PostMapping("/updateUser")
  251. @Transactional(rollbackFor = Exception.class)
  252. public Object updateUser(@ModelAttribute ApplyInfo applyInfo) throws Exception {
  253. if (applyInfo.getId() == null || applyInfo.getId() <= 0) {
  254. return failed(Constants.PARAM_VERIFY_ERROR_MSG);
  255. }
  256. ApplyInfo oldApplyInfo = applyInfoService.get(applyInfo.getId());
  257. if (applyInfo.getStatus() != null && applyInfo.getStatus() != 1 && !oldApplyInfo.getStatus().equals(applyInfo.getStatus())) {
  258. return failed("不能修改报名成功以外的状态");
  259. }
  260. if (oldApplyInfo == null) {
  261. return failed("报名信息不存在,请核对");
  262. }
  263. boolean flag = false;
  264. if (applyInfo.getStatus().equals(1) && !oldApplyInfo.getStatus().equals(1)) {
  265. flag = true;
  266. }
  267. Date date = new Date();
  268. applyInfo.setUpdateTime(date);
  269. applyInfoService.update(applyInfo);
  270. //改成成功,推送mec
  271. if (flag) {
  272. ApplyInfo newApplyInfo = applyInfoService.get(applyInfo.getId());
  273. // 增加报名人数
  274. CourseGroupInfo courseGroupInfo = courseGroupInfoService.get(newApplyInfo.getCourseId());
  275. courseGroupInfo.setRegNum(courseGroupInfo.getRegNum() + 1);
  276. courseGroupInfoService.upByIdAndVersion(courseGroupInfo);
  277. //推送mec
  278. applyInfoService.userRegister(newApplyInfo.getPatriarchPhone()); //推送mec
  279. }
  280. return succeed("修改成功");
  281. }
  282. /**
  283. * 修改学生信息
  284. *
  285. * @return
  286. */
  287. // @ApiOperation(value = "批量调剂学员专业")
  288. @PostMapping("/updateUserSub")
  289. public Object updateUserSub(String userId, Integer subId, Integer courseId) {
  290. if (StringUtils.isEmpty(userId) || subId == null || courseId == null) {
  291. return failed(Constants.PARAM_VERIFY_ERROR_MSG);
  292. }
  293. applyInfoService.updateUserSub(userId, subId, courseId);
  294. return succeed("修改成功");
  295. }
  296. // @ApiOperation(value = "学员课程班查询,本接口用于查询指定学员报名的课程班(小课或乐团)列表")
  297. @PostMapping("/queryUserCourse")
  298. // @ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户编号", required = true, dataType = "Integer")})
  299. public Object queryUserCourse(Integer userId) {
  300. if (userId == null) {
  301. return failed(Constants.PARAM_VERIFY_ERROR_MSG);
  302. }
  303. List<Branch> branches = applyInfoService.getBranches();
  304. MecUser mecUser = applyInfoService.findMecUser(userId);
  305. Map<String, Object> resultMap = new HashMap<>(2);
  306. if (branches != null && branches.size() > 0 && mecUser != null) {
  307. for (Branch branch : branches) {
  308. if (branch.getBranchId().equals(mecUser.getBranchId())) {
  309. resultMap.put("memo", branch.getMemo());
  310. break;
  311. }
  312. }
  313. }
  314. resultMap.put("courses", applyInfoService.queryUserCourse(userId));
  315. return succeed(resultMap);
  316. }
  317. /**
  318. * 推送学生续费成功的订单数据到mec
  319. * @return
  320. */
  321. // @PostMapping("/pushRenew")
  322. // public Object pushRenew(RenewBean renewBean){
  323. // applyInfoService.pushRenew(renewBean);
  324. // return succeed();
  325. // }
  326. /**
  327. * 查询mec用户信息
  328. *
  329. * @return
  330. */
  331. @PostMapping("/findMecUser")
  332. public Object findMecUser(Integer userId) {
  333. if (userId == null) {
  334. return failed(Constants.PARAM_VERIFY_ERROR_MSG);
  335. }
  336. return succeed(applyInfoService.findMecUser(userId));
  337. }
  338. @PostMapping("/mecUserIsExist")
  339. public Object mecUserIsExist(String phone) {
  340. return succeed(applyInfoService.mecUserIsExist(phone));
  341. }
  342. /**
  343. * 发送短信验证码
  344. *
  345. * @param mobile
  346. * @return
  347. */
  348. @GetMapping("/sendSmsCode")
  349. public Object sendLoginVerifyCode(String mobile, HttpSession session) {
  350. if (StringUtils.isEmpty(mobile)) {
  351. return failed(Constants.PARAM_VERIFY_ERROR_MSG);
  352. }
  353. applyInfoService.sendValidCode(mobile, session);
  354. return succeed();
  355. }
  356. /**
  357. * 验证短信验证码
  358. *
  359. * @param smsCode
  360. * @return
  361. */
  362. @PostMapping("/verifySmsCode")
  363. public Object verifySmsCode(String mobile, String smsCode, HttpSession session) {
  364. if (StringUtils.isEmpty(smsCode)) {
  365. return failed(Constants.PARAM_VERIFY_ERROR_MSG);
  366. }
  367. if (applyInfoService.verifySmsCode(mobile, smsCode, session)) {
  368. return succeed();
  369. }
  370. return failed("验证失败");
  371. }
  372. }