AdminApiController.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. package com.goafanti.admin.controller;
  2. import java.text.ParseException;
  3. import java.util.Calendar;
  4. import java.util.UUID;
  5. import javax.annotation.Resource;
  6. import javax.servlet.http.HttpServletRequest;
  7. import javax.validation.Valid;
  8. import org.springframework.beans.BeanUtils;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Controller;
  11. import org.springframework.validation.BindingResult;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RequestMethod;
  14. import com.goafanti.admin.bo.InputAdmin;
  15. import com.goafanti.admin.service.AdminService;
  16. import com.goafanti.common.bo.Result;
  17. import com.goafanti.common.constant.AFTConstants;
  18. import com.goafanti.common.constant.ErrorConstants;
  19. import com.goafanti.common.controller.CertifyApiController;
  20. import com.goafanti.common.enums.AchievementAuditStatus;
  21. import com.goafanti.common.enums.AdminFields;
  22. import com.goafanti.common.enums.AttachmentType;
  23. import com.goafanti.common.enums.CertifySubmitType;
  24. import com.goafanti.common.enums.IdentityAuditStatus;
  25. import com.goafanti.common.enums.IdentityProcess;
  26. import com.goafanti.common.enums.OrganizationIdentityFields;
  27. import com.goafanti.common.enums.UserFields;
  28. import com.goafanti.common.enums.UserIdentityFields;
  29. import com.goafanti.common.enums.UserLevel;
  30. import com.goafanti.common.model.Admin;
  31. import com.goafanti.common.model.OrganizationIdentity;
  32. import com.goafanti.common.model.User;
  33. import com.goafanti.common.model.UserIdentity;
  34. import com.goafanti.common.utils.DateUtils;
  35. import com.goafanti.common.utils.PasswordUtil;
  36. import com.goafanti.common.utils.StringUtils;
  37. import com.goafanti.core.shiro.token.TokenManager;
  38. import com.goafanti.easemob.EasemobUtils;
  39. import com.goafanti.user.bo.InputOrganizationIdentity;
  40. import com.goafanti.user.bo.InputUser;
  41. import com.goafanti.user.bo.InputUserIdentity;
  42. import com.goafanti.user.service.JpushEasemobAccountService;
  43. import com.goafanti.user.service.OrganizationIdentityService;
  44. import com.goafanti.user.service.UserIdentityService;
  45. import com.goafanti.user.service.UserService;
  46. @Controller
  47. @RequestMapping(value = "/api/admin")
  48. public class AdminApiController extends CertifyApiController {
  49. @Resource
  50. private UserService userService;
  51. @Resource
  52. private UserIdentityService userIdentityService;
  53. @Resource
  54. private OrganizationIdentityService organizationIdentityService;
  55. @Resource(name = "passwordUtil")
  56. private PasswordUtil passwordUtil;
  57. @Resource
  58. private AdminService adminService;
  59. @Resource
  60. private JpushEasemobAccountService jpushEasemobAccountService;
  61. // @Autowired
  62. // EasemobUtils easemobUtils;
  63. /**
  64. * 获取营销员及营销经理下拉
  65. */
  66. @RequestMapping(value = "/salesman", method = RequestMethod.GET)
  67. public Result getSalesMan() {
  68. Result res = new Result();
  69. res.setData(adminService.selectSalesman());
  70. return res;
  71. }
  72. /**
  73. * 管理员角色
  74. */
  75. @RequestMapping(value = "/role", method = RequestMethod.GET)
  76. public Result getRole(String uid) {
  77. Result res = new Result();
  78. if (StringUtils.isBlank(uid)) {
  79. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "管理员ID"));
  80. return res;
  81. }
  82. res.setData(adminService.selectRoleByPrimaryKey(uid));
  83. return res;
  84. }
  85. /**
  86. * 管理员本人信息详情
  87. */
  88. @RequestMapping(value = "/adminInfo", method = RequestMethod.GET)
  89. public Result adminInfo() {
  90. Result res = new Result();
  91. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)) {
  92. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "超级管理员"));
  93. return res;
  94. }
  95. res.setData(adminService.selectByPrimaryKey(TokenManager.getAdminId()));
  96. return res;
  97. }
  98. /**
  99. * 管理员修改本人信息
  100. */
  101. @RequestMapping(value = "/updateAdminInfo", method = RequestMethod.POST)
  102. public Result updateAdminInfo(@Valid InputAdmin admin, String pwd, BindingResult bindingResult) {
  103. Result res = new Result();
  104. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)) {
  105. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "超级管理员"));
  106. return res;
  107. }
  108. if (bindingResult.hasErrors()) {
  109. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  110. AdminFields.getFieldDesc(bindingResult.getFieldError().getField())));
  111. return res;
  112. }
  113. if (StringUtils.isBlank(admin.getId())) {
  114. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "用户id"));
  115. return res;
  116. }
  117. if (StringUtils.isBlank(admin.getMobile())) {
  118. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "登录帐号为空", "登录帐号"));
  119. return res;
  120. }
  121. if (StringUtils.isBlank(admin.getName())) {
  122. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "用户名为空", "用户名"));
  123. return res;
  124. }
  125. Admin a = adminService.selectByMobile(admin.getMobile().trim(),null);
  126. if (!TokenManager.getAdminId().equals(a.getId())) {
  127. res.getError().add(buildError(ErrorConstants.USER_ALREADY_EXIST, "当前用户已注册!"));
  128. return res;
  129. }
  130. Admin ad = new Admin();
  131. BeanUtils.copyProperties(admin, ad);
  132. Admin aa = adminService.selectByPrimaryKey(TokenManager.getAdminId());
  133. ad.setMobile(ad.getMobile().trim());
  134. ad.setCreateTime(aa.getCreateTime());
  135. if (!StringUtils.isBlank(ad.getPassword())) {
  136. if (StringUtils.isBlank(pwd)) {
  137. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "原密码"));
  138. return res;
  139. }
  140. if (!aa.getPassword().equals(passwordUtil.getEncryptPwd(pwd, aa.getCreateTime()))) {
  141. res.getError().add(buildError(ErrorConstants.PWD_NOT_MATCH_ERROR, "", "原密码"));
  142. return res;
  143. }
  144. } else {
  145. ad.setPassword(aa.getPassword());
  146. }
  147. ad.setPassword(passwordUtil.getEncryptPwd(ad));
  148. res.setData(adminService.updateByPrimaryKey(ad));
  149. return res;
  150. }
  151. /**
  152. * 新增用户
  153. */
  154. @RequestMapping(value = "/addNewUser", method = RequestMethod.POST)
  155. public Result addNewUser(@Valid InputUser inputUser, BindingResult bindingResult) {
  156. Result res = new Result();
  157. if (bindingResult.hasErrors()) {
  158. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  159. UserFields.getFieldDesc(bindingResult.getFieldError().getField())));
  160. return res;
  161. }
  162. if (StringUtils.isBlank(inputUser.getMobile())) {
  163. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "mobile", "mobile"));
  164. return res;
  165. }
  166. User user = userService.selectByMobieAndType(inputUser.getMobile().trim(), null);
  167. if (null != user) {
  168. res.getError().add(buildError(ErrorConstants.USER_ALREADY_EXIST, "当前用户已注册!"));
  169. return res;
  170. }
  171. User u = new User();
  172. u.setId(UUID.randomUUID().toString());
  173. u.setMobile(inputUser.getMobile().trim());
  174. u.setPassword(inputUser.getMobile().trim());
  175. Calendar now = Calendar.getInstance();
  176. now.set(Calendar.MILLISECOND, 0);
  177. u.setCreateTime(now.getTime());
  178. u.setPassword(passwordUtil.getEncryptPwd(u));
  179. u.setLvl(UserLevel.GENERAL.getCode());
  180. u.setAid(TokenManager.getAdminId());
  181. userService.insertRegister(u,inputUser.getUnitName(), inputUser.getUsername());
  182. return res;
  183. }
  184. /**
  185. * 个人用户信息明细
  186. */
  187. @RequestMapping(value = "/userDetail", method = RequestMethod.POST)
  188. public Result userDetail(String uid) {
  189. Result res = new Result();
  190. if (StringUtils.isBlank(uid)) {
  191. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到用户", "用户"));
  192. return res;
  193. }
  194. res.setData(userIdentityService.selectUserIdentityByUserIdAdmin(uid));
  195. return res;
  196. }
  197. /**
  198. * 修改个人用户信息
  199. */
  200. @RequestMapping(value = "/updateUserDetail", method = RequestMethod.POST)
  201. public Result updateUserDetail(@Valid InputUserIdentity userIdentity, BindingResult bindingResult,
  202. String paymentDateFormattedDate, String saveSign) {
  203. Result res = new Result();
  204. if (bindingResult.hasErrors()) {
  205. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  206. UserIdentityFields.getFieldDesc(bindingResult.getFieldError().getField())));
  207. return res;
  208. }
  209. if (StringUtils.isBlank(userIdentity.getId())) {
  210. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到认证ID", "认证ID"));
  211. return res;
  212. }
  213. if (StringUtils.isBlank(userIdentity.getUid())) {
  214. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到用户", "用户"));
  215. return res;
  216. }
  217. if (StringUtils.isBlank(saveSign)) {
  218. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到保存提交方式", "保存提交方式"));
  219. return res;
  220. }
  221. UserIdentity idd = userIdentityService.selectUserIdentityByUserId(userIdentity.getUid());
  222. if (IdentityAuditStatus.COMMITTED.getCode().equals(idd.getAuditStatus())) {
  223. res.getError().add(buildError("", "审核中,无法保存或提交!"));
  224. return res;
  225. }
  226. Integer level = userIdentity.getLevel();
  227. if (!UserLevel.GENERAL.getCode().equals(level)) {
  228. User u = userService.selectByPrimaryKey(userIdentity.getUid());
  229. if (UserLevel.GENERAL.getCode().equals(u.getLvl())) {
  230. res.getError().add(buildError(ErrorConstants.NON_CERTIFIED, "未通过实名认证,无法操作!"));
  231. return res;
  232. }
  233. }
  234. if (!saveSign.equals(CertifySubmitType.SAVE.getCode())
  235. && !saveSign.equals(CertifySubmitType.SUBMIT.getCode())) {
  236. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "保存提交方式"));
  237. return res;
  238. }
  239. if (!StringUtils.isBlank(paymentDateFormattedDate)) {
  240. try {
  241. userIdentity.setPaymentDate(DateUtils.parseDate(paymentDateFormattedDate, AFTConstants.YYYYMMDD));
  242. } catch (ParseException e) {
  243. }
  244. }
  245. UserIdentity ui = new UserIdentity();
  246. BeanUtils.copyProperties(userIdentity, ui);
  247. if (CertifySubmitType.SUBMIT.getCode().equals(saveSign)) {
  248. User u = userService.selectByPrimaryKey(userIdentity.getUid());
  249. if (!UserLevel.GENERAL.getCode().equals(u.getLvl())) {
  250. res.getError().add(buildError("", "已通过实名认证,无法操作!"));
  251. return res;
  252. }
  253. ui.setProcess(IdentityProcess.COMMITTED.getCode());
  254. ui.setAuditStatus(IdentityAuditStatus.COMMITTED.getCode());
  255. }
  256. res.setData(userIdentityService.updateUserDetail(ui, saveSign, level));
  257. return res;
  258. }
  259. /**
  260. * 团体用户明细
  261. */
  262. @RequestMapping(value = "/orgDetail", method = RequestMethod.POST)
  263. public Result orgDetail(String uid) {
  264. Result res = new Result();
  265. if (StringUtils.isBlank(uid)) {
  266. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到用户", "用户"));
  267. return res;
  268. }
  269. //res.setData(organizationIdentityService.selectOrgIdentityDetailByUserIdAdmin(uid));
  270. return res;
  271. }
  272. /**
  273. * 修改团体用户信息
  274. */
  275. @RequestMapping(value = "/updateOrgDetail", method = RequestMethod.POST)
  276. public Result updateOrgDetail(@Valid InputOrganizationIdentity orgIdentity, BindingResult bindingResult,
  277. String paymentDateFormattedDate, String saveSign) {
  278. Result res = new Result();
  279. if (bindingResult.hasErrors()) {
  280. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  281. OrganizationIdentityFields.getFieldDesc(bindingResult.getFieldError().getField())));
  282. return res;
  283. }
  284. if (StringUtils.isBlank(orgIdentity.getUid())) {
  285. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到用户", "用户"));
  286. return res;
  287. }
  288. if (StringUtils.isBlank(saveSign)) {
  289. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到保存提交方式", "保存提交方式"));
  290. return res;
  291. }
  292. if (!saveSign.equals(CertifySubmitType.SAVE.getCode())
  293. && !saveSign.equals(CertifySubmitType.SUBMIT.getCode())) {
  294. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "保存提交方式"));
  295. return res;
  296. }
  297. OrganizationIdentity idd = organizationIdentityService.selectOrgIdentityByUserId(orgIdentity.getUid());
  298. if (IdentityAuditStatus.COMMITTED.getCode().equals(idd.getAuditStatus())) {
  299. res.getError().add(buildError("", "审核中,无法保存或提交!"));
  300. return res;
  301. }
  302. Integer level = orgIdentity.getLevel();
  303. if (!UserLevel.GENERAL.getCode().equals(level)) {
  304. User u = userService.selectByPrimaryKey(orgIdentity.getUid());
  305. if (UserLevel.GENERAL.getCode().equals(u.getLvl())) {
  306. res.getError().add(buildError(ErrorConstants.NON_CERTIFIED, "未通过实名认证,无法操作!"));
  307. return res;
  308. }
  309. }
  310. if (!StringUtils.isBlank(paymentDateFormattedDate)) {
  311. try {
  312. orgIdentity.setPaymentDate(DateUtils.parseDate(paymentDateFormattedDate, AFTConstants.YYYYMMDD));
  313. } catch (ParseException e) {
  314. }
  315. }
  316. OrganizationIdentity oi = new OrganizationIdentity();
  317. BeanUtils.copyProperties(orgIdentity, oi);
  318. if (orgIdentity.getRegisteredCapital() != null) {
  319. oi.setRegisteredCapital(orgIdentity.getRegisteredCapital());
  320. }
  321. if (CertifySubmitType.SUBMIT.getCode().equals(saveSign)) {
  322. User u = userService.selectByPrimaryKey(oi.getUid());
  323. if (!UserLevel.GENERAL.getCode().equals(u.getLvl())) {
  324. res.getError().add(buildError("", "已通过实名认证,无法操作!"));
  325. return res;
  326. }
  327. oi.setProcess(IdentityProcess.COMMITTED.getCode());
  328. oi.setAuditStatus(IdentityAuditStatus.COMMITTED.getCode());
  329. }
  330. //res.setData(organizationIdentityService.updateOrgDetail(oi, saveSign, level));
  331. return res;
  332. }
  333. /**
  334. * 团体用户明细
  335. *
  336. * type 0-个人 1-单位
  337. */
  338. @RequestMapping(value = "/listJpushUser", method = RequestMethod.GET)
  339. public Result getJpushUser(Integer type,Integer pageNo,Integer pageSize) {
  340. Result res = new Result();
  341. if(type==null ||(type!=0 && type !=1)) {
  342. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","类型错误"));
  343. return res;
  344. }
  345. res.setData(jpushEasemobAccountService.findJpushClientsByType(type, pageNo, pageSize));
  346. return res;
  347. }
  348. //获得专家顾问审核数据
  349. @RequestMapping(value="/getExpertAuditList", method = RequestMethod.GET )
  350. public Result getExpertAuditList(InputUserIdentity identity, Integer pageNo, Integer pageSize){
  351. Result res = new Result();
  352. res.setData(userIdentityService.getExpertAuditList(identity, pageNo, pageSize));
  353. return res;
  354. }
  355. //获得某个人认证的详情信息
  356. @RequestMapping(value="/getUserIdentityByUid" , method = RequestMethod.GET)
  357. public Result getUserIdentityByUid(String uid){
  358. Result res = new Result();
  359. res.setData(userIdentityService.getUserIdentityByUid(uid));
  360. return res;
  361. }
  362. //管理员更改审核状态
  363. @RequestMapping(value="/auditing", method = RequestMethod.POST)
  364. public Result auditing(UserIdentity identity){
  365. Result res = new Result();
  366. if(AchievementAuditStatus.UNAUDITED.getCode().intValue() == identity.getAuditStatus() && null == identity.getAuditInfo()){
  367. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","审核不通过时必须填写原因"));
  368. }
  369. res.setData(userIdentityService.updateAuditing(identity));
  370. return res;
  371. }
  372. //管理员打回专家顾问
  373. @RequestMapping(value="/annul", method = RequestMethod.POST)
  374. public Result annul(UserIdentity identity){
  375. Result res = new Result();
  376. if (StringUtils.isBlank(identity.getId())) {
  377. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","撤销"));
  378. return res;
  379. }
  380. identity.setAuditStatus(3);
  381. identity.setAuditInfo("");
  382. res.setData(userIdentityService.updateAuditing(identity));
  383. return res;
  384. }
  385. //获得注册用户信息
  386. @RequestMapping(value="/user/info", method = RequestMethod.GET)
  387. public Result userInfo(User user, Integer pageNo, Integer pageSize){
  388. Result res = new Result();
  389. //默认注册的正常用户
  390. if(null == user.getSource()) user.setSource(0);
  391. if(null == user.getStatus()) user.setStatus(0);
  392. res.setData(userService.getUserInfo(user, pageNo, pageSize));
  393. return res;
  394. }
  395. //管理员修改用户图片
  396. @RequestMapping(value="/updatePictureUrl", method = RequestMethod.GET)
  397. public Result updatePictureUrl(String uid,String url){
  398. Result res = new Result();
  399. if (StringUtils.isBlank(uid)||StringUtils.isBlank(url)) {
  400. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,"",""));
  401. return res;
  402. }
  403. res.setData(userService.updatePictureUrl(uid, url));
  404. return res;
  405. }
  406. /**
  407. * 管理员上传用户图片
  408. * @param req
  409. * @param sign
  410. * @return
  411. */
  412. @RequestMapping(value = "/uploadPicture", method = RequestMethod.POST)
  413. public Result uploadPicture(HttpServletRequest req, String sign,String aid) {
  414. Result res = new Result();
  415. AttachmentType attachmentType = AttachmentType.getField(sign);
  416. if (attachmentType == AttachmentType.USER_PICTURE) {
  417. res.setData(handleFiles(res, "/user/", false, req, sign, aid));
  418. } else {
  419. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
  420. }
  421. return res;
  422. }
  423. }