UserController.java 14 KB

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