SystemController.java 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. package com.rf.psychological.user.rest;
  2. import cn.hutool.core.date.DateUnit;
  3. import cn.hutool.core.date.DateUtil;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.rf.psychological.base.rest.BaseController;
  6. import com.rf.psychological.dao.model.AnswerEntity;
  7. import com.rf.psychological.dao.model.DimensionEntity;
  8. import com.rf.psychological.enums.UserRole;
  9. import com.rf.psychological.group.dao.model.GroupEntity;
  10. import com.rf.psychological.group.service.GroupInfoService;
  11. import com.rf.psychological.module.index.service.IndexService;
  12. import com.rf.psychological.scale.dao.model.MBTIResultDetail;
  13. import com.rf.psychological.scale.dao.model.ScaleEntity;
  14. import com.rf.psychological.scale.dao.model.ScaleMarksEntity;
  15. import com.rf.psychological.scale.dao.model.SubjectEntity;
  16. import com.rf.psychological.scale.service.*;
  17. import com.rf.psychological.security.DESede;
  18. import com.rf.psychological.user.dao.model.UserEntity;
  19. import com.rf.psychological.enums.UserStatus;
  20. import com.rf.psychological.institution.model.InstitutionEntity;
  21. import com.rf.psychological.institution.service.InstitutionService;
  22. import com.rf.psychological.opLog.annotation.OperationLogAnnotation;
  23. import com.rf.psychological.security.AesEncryptUtils;
  24. import com.rf.psychological.security.SafetyProcess;
  25. import com.rf.psychological.user.service.SystemService;
  26. import com.rf.psychological.user.service.UserService;
  27. import com.rf.psychological.utils.*;
  28. import io.swagger.annotations.Api;
  29. import io.swagger.annotations.ApiOperation;
  30. import lombok.extern.slf4j.Slf4j;
  31. import org.apache.commons.lang.StringUtils;
  32. import org.springframework.beans.factory.annotation.Autowired;
  33. import org.springframework.beans.factory.annotation.Value;
  34. import org.springframework.boot.context.event.SpringApplicationEvent;
  35. import org.springframework.core.env.Environment;
  36. import org.springframework.data.redis.core.StringRedisTemplate;
  37. import org.springframework.util.DigestUtils;
  38. import org.springframework.web.bind.annotation.*;
  39. import javax.management.relation.RoleStatus;
  40. import javax.servlet.http.HttpServletRequest;
  41. import java.io.File;
  42. import java.io.FileInputStream;
  43. import java.util.List;
  44. import java.util.concurrent.TimeUnit;
  45. import static cn.hutool.core.date.DatePattern.PURE_DATETIME_PATTERN;
  46. /**
  47. * @Description: 后台首页、登录、版本等接口
  48. * @Author: zsf
  49. * @Date: 2022/7/4
  50. */
  51. @Slf4j
  52. @RestController
  53. @RequestMapping("/system")
  54. @Api(tags = "后台首页、登录、版本等接口")
  55. public class SystemController extends BaseController {
  56. @Autowired
  57. private SystemService systemService;
  58. @Autowired
  59. private UserService userService;
  60. @Autowired
  61. private InstitutionService institutionService;
  62. @Autowired
  63. private GroupInfoService groupInfoService;
  64. @Autowired
  65. private ScaleMarksService scaleMarksService;
  66. @Autowired
  67. private AnswerService answerService;
  68. @Autowired
  69. private SubjectService subjectService;
  70. @Autowired
  71. private DimensionService dimensionService;
  72. @Autowired
  73. private ScaleService scaleService;
  74. @Autowired
  75. private MBTIResultDetailService detailService;
  76. @Autowired
  77. private IndexService indexService;
  78. @Value("${spring.profiles.active}")
  79. private String profileValue;
  80. @Autowired
  81. private Environment env;
  82. @Autowired
  83. private StringRedisTemplate redisTemplate;
  84. @GetMapping("/getVersion")
  85. @SafetyProcess
  86. public Result getSystemVersion(){
  87. String value = env.getActiveProfiles()[0];
  88. return success(systemService.getSystemVersion(),profileValue);
  89. }
  90. @GetMapping("/temporaryUser")
  91. @SafetyProcess
  92. public Result temporaryUser(){
  93. try {
  94. //注册
  95. UserEntity userEntity = new UserEntity();
  96. userEntity.setPassword("-");
  97. userEntity.setGId(this.groupInfoService.findGroupByInstitutionNoAndName(Constant.WEB_INSTITUTION_CODE,Constant.DEFAULT_GROUP_NAME).getId());
  98. userEntity.setInstitutionName(Constant.WEB_INSTITUTION_NAME);
  99. userEntity.setInstitutionNo(Constant.WEB_INSTITUTION_CODE);
  100. userEntity.setUserStatus(Constant.USER_STATUS_NORMAL);
  101. userEntity.setBirthday("-");
  102. userEntity.setGender("-");
  103. userEntity.setPetName("游离用户");
  104. userEntity.setProfession("-");
  105. userEntity.setAdditionInfo("游离用户");
  106. userEntity.setPhone(SnowFlakeUtil.getNextId());
  107. userEntity.setRoleType(UserRole.COMMON.getType());
  108. userEntity = this.userService.save(userEntity);
  109. JSONObject resultJson = new JSONObject();
  110. resultJson.put("token", JWTUtil.getTokenByUserInfo(userEntity));
  111. resultJson.put("user",userEntity);
  112. resultJson.put("type",userEntity.getRoleType());
  113. log.info("响应消息:"+resultJson.toJSONString());
  114. return success(resultJson);
  115. }catch (Exception e){
  116. log.error(e.getMessage());
  117. return fail();
  118. }
  119. }
  120. /**
  121. * 注册用户
  122. * @param jsonParam
  123. * @return
  124. */
  125. @PostMapping("/registerUser")
  126. @ApiOperation(value = "用户注册",notes = "json字符串形式传参(加密),data参数包括:data:注册用户基本信息《birthday:生日,gender:性别,password:密码,roleType:角色,institutionNo:机构编号,phone:账号或电话》,authCode:验证码(公网版必填)")
  127. @SafetyProcess
  128. public Result registerUser(@RequestBody String jsonParam){
  129. try {
  130. String data = AesEncryptUtils.decrypt(JSONObject.parseObject(jsonParam).getString("data"));
  131. JSONObject jsonData = JSONObject.parseObject(data);
  132. JSONObject jsonUserEntity =jsonData.getJSONObject("data");
  133. UserEntity userEntity = jsonUserEntity.toJavaObject(UserEntity.class);
  134. userEntity.setModelPhone(Constant.DEFAULT_VALUE_ZERO);
  135. String institutionNo = userEntity.getInstitutionNo();
  136. if (StringUtils.isEmpty(institutionNo)){
  137. return fail("","机构编号不能为空");
  138. }
  139. //判断机构编号是否存在
  140. InstitutionEntity institutionEntity = this.institutionService.findByInstitutionNo(institutionNo);
  141. if (institutionEntity == null) {
  142. return fail("", "机构编号不存在!");
  143. }
  144. //添加校验是否开启注册校验或已达到上限值
  145. String isRegistrantValue = institutionEntity.getIsRegistrantsNum()==null?Constant.DEFAULT_VALUE_ZERO:institutionEntity.getIsRegistrantsNum().toString();
  146. if (Constant.DEFAULT_VALUE_ONE.equals(isRegistrantValue)){
  147. int userCount = this.indexService.findUserCount(institutionNo);
  148. if (userCount >= institutionEntity.getRegistrantsNum()){
  149. return fail(null,"注册人数已达到上限,请联系机构管理员");
  150. }
  151. }
  152. userEntity.setInstitutionName(institutionEntity.getInstitutionName());
  153. if (UserRole.COMMON.getType().equals(userEntity.getRoleType())){
  154. GroupEntity entity =this.groupInfoService.findGroupByInstitutionNoAndName(institutionNo,Constant.DEFAULT_GROUP_NAME);
  155. if (entity == null ){
  156. return fail("", "机构下无默认分组!");
  157. }
  158. userEntity.setGId(entity.getId());
  159. }
  160. //区分是否需要验证码
  161. if (Constant.WEB_INSTITUTION_CODE.equals(userEntity.getInstitutionNo())){
  162. String authCode = jsonData.getString("authCode");
  163. if (StringUtils.isEmpty(authCode)){
  164. return fail("","验证码不能为空");
  165. }
  166. String phone = userEntity.getPhone();
  167. String temp = redisTemplate.opsForValue().get("AUTH_CODE_"+phone);
  168. if(StringUtils.isBlank(temp)){
  169. return fail("请重新获取验证码");
  170. }
  171. if (!temp.equals(authCode)) {
  172. return fail("", "验证码错误");
  173. }
  174. userEntity.setUserStatus(UserStatus.PASS.getType());
  175. }
  176. UserEntity userInfo = this.userService.findPhoneAndInstitutionNoAndRoleType(userEntity.getPhone(), userEntity.getInstitutionNo(),userEntity.getRoleType());
  177. if (userInfo == null) {
  178. if (Constant.LAN_INSTITUTION_CODE.equals(userEntity.getInstitutionNo())){
  179. userEntity.setUserStatus(Constant.USER_STATUS_NORMAL);
  180. }
  181. userEntity.setPassword(DigestUtils.md5DigestAsHex(userEntity.getPassword().getBytes()));
  182. this.userService.save(userEntity);
  183. return success();
  184. } else {
  185. return fail("", "账号已注册");
  186. }
  187. }catch (Exception e){
  188. e.printStackTrace();
  189. return fail();
  190. }
  191. }
  192. @SafetyProcess
  193. @ApiOperation(value = "系统登录接口",notes = "data参数包括:phone:账号, password:密码,institutionNo:机构编号,roleType:用户角色,authCode:密码,verification:验证信息《beginTime:时间,authCode:验证码,phone:电话》")
  194. @PostMapping("/login")
  195. public Result login(HttpServletRequest request, @RequestBody String jsonParams){
  196. try {
  197. JSONObject jsonObject =JSONObject.parseObject( AesEncryptUtils.decrypt(JSONObject.parseObject(jsonParams).getString("data")));
  198. log.info("jsonObject: " + jsonObject.toString());
  199. if (!jsonObject.containsKey("institutionNo") || !jsonObject.containsKey("roleType") || StringUtils.isEmpty(jsonObject.getString("institutionNo")) || StringUtils.isEmpty( jsonObject.getString("roleType") )) {
  200. return fail("", "机构编号和用户角色不能为空");
  201. }
  202. String institutionNo = jsonObject.getString("institutionNo");
  203. String roleType = jsonObject.getString("roleType");
  204. if (!jsonObject.containsKey("phone") || StringUtils.isEmpty(jsonObject.getString("phone")) ) {
  205. return fail("", "账号不能为空");
  206. }
  207. String phone = jsonObject.getString("phone");
  208. log.info("phone: " + phone);
  209. //判断机构编号是否存在
  210. InstitutionEntity institutionEntity = this.institutionService.findByInstitutionNo(institutionNo);
  211. log.info("institutionEntity: " + institutionEntity);
  212. if (institutionEntity == null) {
  213. return fail("", "机构编号不存在!");
  214. }
  215. UserEntity userEntity = this.userService.findPhoneAndInstitutionNoAndRoleType(phone, institutionNo,roleType);
  216. log.info("userEntity: " + userEntity);
  217. //如果是公网版并且验证码登录
  218. if (Constant.WEB_INSTITUTION_CODE.equals(institutionNo) && jsonObject.containsKey("authCode")){
  219. if (userEntity == null) {
  220. return fail(null, "用户不存在");
  221. }
  222. String authCode = jsonObject.getString("authCode");
  223. if (StringUtils.isEmpty(authCode)){
  224. return fail("","验证码不能为空");
  225. }
  226. String temp = redisTemplate.opsForValue().get("AUTH_CODE_" + phone);
  227. if(StringUtils.isBlank(temp)){
  228. return fail("", "验证码已失效");
  229. }
  230. if (temp.equals(authCode)) {
  231. //生成token
  232. userEntity.setPassword(null);
  233. String token = JWTUtil.getTokenByUserInfo(userEntity);
  234. // 创建返回的json对象
  235. JSONObject resultJson = new JSONObject();
  236. resultJson.put("user", userEntity);
  237. resultJson.put("type", userEntity.getRoleType());
  238. resultJson.put("token", token);
  239. request.getSession().setAttribute("user", userEntity);
  240. return success(resultJson);
  241. } else {
  242. return fail("", "验证码错误");
  243. }
  244. }else if ("lan".equals(profileValue)){
  245. if (!jsonObject.containsKey("password") || StringUtils.isEmpty( jsonObject.getString("password") )) {
  246. return fail("", "密码不能为空");
  247. }
  248. String password = jsonObject.getString("password");
  249. if (userEntity == null) {
  250. if (Constant.LAN_INSTITUTION_CODE.equals(institutionNo)){
  251. return fail(null, "账号或密码错误");
  252. }
  253. return fail(null, "账号错误");
  254. }
  255. String userStatus = userEntity.getUserStatus();
  256. if (UserStatus.AUDIT.getType().equals(userStatus)||UserStatus.UPDATE.getType().equals(userStatus)){
  257. return fail(null, "用户未审核,请联系管理员");
  258. }
  259. if (userEntity.getPassword().equals(password)) {
  260. //生成token
  261. userEntity.setPassword(null);
  262. String token = JWTUtil.getTokenByUserInfo(userEntity);
  263. // 创建返回的json对象
  264. JSONObject resultJson = new JSONObject();
  265. resultJson.put("user", userEntity);
  266. resultJson.put("type", userEntity.getRoleType());
  267. resultJson.put("token", token);
  268. request.getSession().setAttribute("user", userEntity);
  269. return success(resultJson);
  270. } else {
  271. return fail(null, "账号或密码错误");
  272. }
  273. }else {
  274. if (!jsonObject.containsKey("password") || StringUtils.isEmpty( jsonObject.getString("password") )) {
  275. return fail("", "密码不能为空");
  276. }
  277. String password = jsonObject.getString("password");
  278. if (userEntity == null) {
  279. if (Constant.LAN_INSTITUTION_CODE.equals(institutionNo)){
  280. return fail(null, "账号或密码错误");
  281. }
  282. return fail(null, "机构编号或账号错误");
  283. }
  284. String userStatus = userEntity.getUserStatus();
  285. if (UserStatus.AUDIT.getType().equals(userStatus)||UserStatus.UPDATE.getType().equals(userStatus)){
  286. return fail(null, "用户未审核,请联系管理员");
  287. }
  288. if (userEntity.getPassword().equals(password)) {
  289. //生成token
  290. userEntity.setPassword(null);
  291. String redisToken = redisTemplate.opsForValue().get("session:"+userEntity.getInstitutionNo()+":"+userEntity.getPhone()+":"+userEntity.getRoleType());
  292. String token = redisToken;
  293. //验证token是否有效
  294. try {
  295. JWTUtil.verify(token);
  296. }catch (Exception e){
  297. e.printStackTrace();
  298. token = JWTUtil.getTokenByUserInfo(userEntity);
  299. redisTemplate.opsForValue().set("session:"+userEntity.getInstitutionNo()+":"+userEntity.getPhone()+":"+userEntity.getRoleType(),token,5, TimeUnit.DAYS);
  300. }
  301. // 创建返回的json对象
  302. JSONObject resultJson = new JSONObject();
  303. resultJson.put("user", userEntity);
  304. resultJson.put("type", userEntity.getRoleType());
  305. resultJson.put("token", token);
  306. request.getSession().setAttribute("user", userEntity);
  307. return success(resultJson);
  308. } else {
  309. return fail(null, "账号或密码错误");
  310. }
  311. }
  312. }catch (Exception e){
  313. e.printStackTrace();
  314. return fail();
  315. }
  316. }
  317. @SafetyProcess
  318. @ApiOperation(value = "系统登录接口",notes = "data参数包括:phone:账号,institutionNo:机构编号,roleType:用户角色,authCode:密码,verification:验证信息《beginTime:时间,authCode:验证码,phone:电话》")
  319. @PostMapping("/loginH5")
  320. public Result loginH5(HttpServletRequest request, @RequestBody String jsonParams){
  321. try {
  322. JSONObject jsonObject =JSONObject.parseObject( AesEncryptUtils.decrypt(JSONObject.parseObject(jsonParams).getString("data")));
  323. log.info("jsonObject: " + jsonObject.toString());
  324. if (!jsonObject.containsKey("institutionNo") || !jsonObject.containsKey("roleType") || StringUtils.isEmpty(jsonObject.getString("institutionNo")) || StringUtils.isEmpty( jsonObject.getString("roleType") )) {
  325. return fail("", "机构编号和用户角色不能为空");
  326. }
  327. String institutionNo = jsonObject.getString("institutionNo");
  328. String roleType = jsonObject.getString("roleType");
  329. if (!jsonObject.containsKey("phone") || StringUtils.isEmpty(jsonObject.getString("phone")) ) {
  330. return fail("", "账号不能为空");
  331. }
  332. String phone = jsonObject.getString("phone");
  333. log.info("phone: " + phone);
  334. //判断机构编号是否存在
  335. InstitutionEntity institutionEntity = this.institutionService.findByInstitutionNo(institutionNo);
  336. log.info("institutionEntity: " + institutionEntity);
  337. if (institutionEntity == null) {
  338. return fail("", "机构编号不存在!");
  339. }
  340. UserEntity userEntity = this.userService.findPhoneAndInstitutionNoAndRoleType(phone, institutionNo,roleType);
  341. log.info("userEntity: " + userEntity);
  342. //如果是公网版并且验证码登录
  343. if (userEntity == null) {
  344. userEntity = new UserEntity();
  345. userEntity.setPassword(DigestUtils.md5DigestAsHex(Constant.DEFAULT_PASSWORD.getBytes()));
  346. userEntity.setGId(this.groupInfoService.findGroupByInstitutionNoAndName(Constant.WEB_INSTITUTION_CODE,Constant.DEFAULT_GROUP_NAME).getId());
  347. userEntity.setInstitutionName(Constant.WEB_INSTITUTION_NAME);
  348. userEntity.setInstitutionNo(Constant.WEB_INSTITUTION_CODE);
  349. userEntity.setUserStatus(Constant.USER_STATUS_NORMAL);
  350. userEntity.setBirthday("-");
  351. userEntity.setGender("-");
  352. userEntity.setPetName(phone);
  353. userEntity.setProfession("-");
  354. userEntity.setPhone(phone);
  355. userEntity.setRoleType(UserRole.COMMON.getType());
  356. userEntity = this.userService.save(userEntity);
  357. }
  358. String authCode = jsonObject.getString("authCode");
  359. if (StringUtils.isEmpty(authCode)){
  360. return fail("","验证码不能为空");
  361. }
  362. String temp = redisTemplate.opsForValue().get("AUTH_CODE_" + phone);
  363. if(StringUtils.isBlank(temp)){
  364. return fail("", "验证码已失效");
  365. }
  366. if (temp.equals(authCode)) {
  367. //生成token
  368. // userEntity.setPassword(null);
  369. // String token = JWTUtil.getTokenByUserInfo(userEntity);
  370. //生成token
  371. userEntity.setPassword(null);
  372. String redisToken = redisTemplate.opsForValue().get("session:"+userEntity.getInstitutionNo()+":"+userEntity.getPhone()+":"+userEntity.getRoleType());
  373. String token = redisToken;
  374. try {
  375. JWTUtil.verify(token);
  376. }catch (Exception e){
  377. e.printStackTrace();
  378. token = JWTUtil.getTokenByUserInfo(userEntity);
  379. redisTemplate.opsForValue().set("session:"+userEntity.getInstitutionNo()+":"+userEntity.getPhone()+":"+userEntity.getRoleType(),token,5, TimeUnit.DAYS);
  380. }
  381. // 创建返回的json对象
  382. JSONObject resultJson = new JSONObject();
  383. resultJson.put("user", userEntity);
  384. resultJson.put("type", userEntity.getRoleType());
  385. resultJson.put("token", token);
  386. request.getSession().setAttribute("user", userEntity);
  387. return success(resultJson);
  388. } else {
  389. return fail("", "验证码错误");
  390. }
  391. }catch (Exception e){
  392. e.printStackTrace();
  393. return fail();
  394. }
  395. }
  396. /**
  397. * 忘记密码
  398. * @param jsonParam 参数
  399. * @desc 局域网和公网版 区别:公网版需要验证码参数
  400. * @return
  401. */
  402. @SafetyProcess
  403. @ApiOperation(value = "忘记密码",notes = "json字符串形式传参(加密),data参数包括:password:新密码,institutionNo:机构编号,phone:账号或电话,roleType:用户角色,authCode:验证码(公网版必填)," +
  404. "verification:验证信息《beginTime:时间,authCode:验证码,phone:电话》")
  405. @PostMapping("/forgotPassword")
  406. public Result forgotPassword(@RequestBody String jsonParam){
  407. try {
  408. JSONObject dataParam = JSONObject.parseObject(AesEncryptUtils.decrypt(JSONObject.parseObject(jsonParam).getString("data")));
  409. String phone = dataParam.getString("phone");
  410. String password = dataParam.getString("password");
  411. String institutionNo = dataParam.getString("institutionNo");
  412. String roleType = dataParam.getString("roleType");
  413. if ( StringUtils.isEmpty( phone) || StringUtils.isEmpty( password ) || StringUtils.isEmpty( institutionNo ) ) {
  414. return fail("", "请按要求填写所需信息");
  415. }
  416. UserEntity userEntity = this.userService.findPhoneAndInstitutionNoAndRoleType(phone,institutionNo,roleType);
  417. if (userEntity == null) {
  418. return fail("", "请先注册");
  419. }
  420. userEntity.setPassword(password);
  421. //区分公网版和非公网版
  422. if (Constant.WEB_INSTITUTION_CODE.equals(institutionNo)){
  423. String authCode = dataParam.getString("authCode");
  424. JSONObject jsonVerification = dataParam.getJSONObject("verification");
  425. String jsonPhone = jsonVerification.getString("phone");
  426. String jsonAuthCode = jsonVerification.getString("authCode");
  427. String jsonBeginTime = jsonVerification.getString("beginTime");
  428. if (StringUtils.isEmpty(jsonBeginTime ) || StringUtils.isEmpty(jsonAuthCode) ) {
  429. return fail("", "请重新获取验证码");
  430. }
  431. //计算时间差---分钟
  432. //int diff = DateUtil.getDistanceByUnit(DateUtil.parseDate(jsonBeginTime), DateUtil.getCurrentDate(), 2);
  433. long diff = DateUtil.between(DateUtil.date(), DateUtil.parse(jsonBeginTime,PURE_DATETIME_PATTERN), DateUnit.MINUTE);
  434. if (diff < 0 || diff > 5) {
  435. return fail("", "验证码已失效");
  436. }
  437. if (jsonAuthCode.equals(authCode) && jsonPhone.equals(phone)) {
  438. // this.userService.updatePassword(phone, password, institutionNo,roleType);
  439. this.userService.save(userEntity);
  440. } else {
  441. return fail("", "验证码错误");
  442. }
  443. }else {
  444. this.userService.save(userEntity);
  445. // this.userService.updatePassword(phone, password, institutionNo,roleType);
  446. }
  447. return success();
  448. }catch (Exception e){
  449. e.printStackTrace();
  450. return fail();
  451. }
  452. }
  453. /**
  454. * 登出
  455. * @param jsonParam 参数
  456. * @desc
  457. * @return
  458. */
  459. @SafetyProcess
  460. @ApiOperation(value = "登出",notes = "json字符串形式传参(加密),data参数包括:institutionNo:机构编号,phone:账号或电话,roleType:用户角色" )
  461. @PostMapping("/logout")
  462. public Result logout(@RequestBody String jsonParam){
  463. try {
  464. JSONObject dataParam = JSONObject.parseObject(AesEncryptUtils.decrypt(JSONObject.parseObject(jsonParam).getString("data")));
  465. String phone = dataParam.getString("phone");
  466. String institutionNo = dataParam.getString("institutionNo");
  467. String roleType = dataParam.getString("roleType");
  468. if ( StringUtils.isEmpty( phone) || StringUtils.isEmpty( institutionNo ) ) {
  469. return fail("", "请按要求填写所需信息");
  470. }
  471. //首先校验用户是否存在
  472. UserEntity userEntity = userService.findPhoneAndInstitutionNoAndRoleType(phone,institutionNo,roleType);
  473. if (userEntity == null){
  474. return fail(null,"用户不存在");
  475. }
  476. if ("lan".equals(profileValue)){
  477. return success();
  478. }
  479. boolean result = redisTemplate.delete("session:"+institutionNo+":"+phone+":"+roleType);
  480. return success(result);
  481. }catch (Exception e){
  482. e.printStackTrace();
  483. return fail();
  484. }
  485. }
  486. /**
  487. * 修改密码
  488. * @param jsonParam 待修改用户密码参数
  489. * @return
  490. */
  491. @SafetyProcess
  492. @ApiOperation(value = "修改密码",notes = "data参数包括:id:用户id,password:新密码,oldPassword:旧密码")
  493. @PostMapping("/updatePassword")
  494. public Result updatePassword(@RequestBody String jsonParam){
  495. try {
  496. JSONObject jsonObject = JSONObject.parseObject(AesEncryptUtils.decrypt(JSONObject.parseObject(jsonParam).getString("data")));
  497. if(!jsonObject.containsKey("id")|| StringUtils.isEmpty(jsonObject.getString("id"))) {
  498. return failBadRequest(null,"用户id不能为空!");
  499. }
  500. if(!jsonObject.containsKey("password")|| StringUtils.isEmpty(jsonObject.getString("password"))) {
  501. return failBadRequest(null,"登录密码不能为空!");
  502. }
  503. String password = jsonObject.getString("password");
  504. String oldPassword = jsonObject.getString("oldPassword");
  505. String id = jsonObject.getString("id");
  506. UserEntity userEntity = userService.findOne(id);
  507. if (userEntity == null) {
  508. return fail("", "请先注册");
  509. }
  510. if (!userEntity.getPassword().equals(oldPassword)) {
  511. return fail("", "旧密码有误");
  512. }
  513. userEntity.setPassword(password);
  514. this.userService.save(userEntity);
  515. return success();
  516. }catch (Exception e){
  517. e.printStackTrace();
  518. return fail();
  519. }
  520. }
  521. @ApiOperation(value = "量表加密操作")
  522. @GetMapping("/update/{flag}")
  523. public String update(@PathVariable String flag){
  524. //根据flag获取全部选项
  525. List<ScaleEntity> scaleEntities = this.scaleService.getScaleByFlag(flag);
  526. //根据flag获取全部答案
  527. List<AnswerEntity> answerEntities = this.answerService.getAnswerByFlag(flag);
  528. //根据flag获取全部评分规则
  529. List<ScaleMarksEntity> scaleMarksEntities = this.scaleMarksService.getScaleMarksByFlag(flag);
  530. //根据flag获取全部维度信息
  531. List<DimensionEntity> dimensionEntities = this.dimensionService.getDimensionByFlag(flag);
  532. //根据flag获取量表名称
  533. List<SubjectEntity> subjectEntities = this.subjectService.getSubjectByFlag(flag);
  534. for (SubjectEntity subjectEntity:subjectEntities){
  535. //String description = DESede.encryptString(subjectEntity.getDescription());
  536. subjectEntity.setDescription(DESede.encryptString(subjectEntity.getDescription()));
  537. this.subjectService.update(subjectEntity);
  538. }
  539. for (AnswerEntity answerEntity:answerEntities){
  540. answerEntity.setName(DESede.encryptString(answerEntity.getName()));
  541. answerEntity.setScore(DESede.encryptString(answerEntity.getScore()));
  542. this.answerService.updateAnswer(answerEntity);
  543. }
  544. for (ScaleEntity scaleEntity:scaleEntities){
  545. scaleEntity.setAnswer(DESede.encryptString(scaleEntity.getAnswer()));
  546. scaleEntity.setCheckItems(DESede.encryptString(scaleEntity.getCheckItems()));
  547. this.scaleService.updateScale(scaleEntity);
  548. }
  549. for (ScaleMarksEntity scaleMarksEntity:scaleMarksEntities){
  550. scaleMarksEntity.setName(DESede.encryptString(scaleMarksEntity.getName()));
  551. scaleMarksEntity.setScoreStart(DESede.encryptString(scaleMarksEntity.getScoreStart()));
  552. scaleMarksEntity.setScoreEnd(DESede.encryptString(scaleMarksEntity.getScoreEnd()));
  553. scaleMarksEntity.setSymptom(DESede.encryptString(scaleMarksEntity.getSymptom()));
  554. scaleMarksEntity.setImprovementSuggestions(DESede.encryptString(scaleMarksEntity.getImprovementSuggestions()));
  555. scaleMarksEntity.setNameExplain(DESede.encryptString(scaleMarksEntity.getImprovementSuggestions()));
  556. scaleMarksEntity.setReference(DESede.encryptString(scaleMarksEntity.getImprovementSuggestions()));
  557. scaleMarksEntity.setSuggestion(DESede.encryptString(scaleMarksEntity.getImprovementSuggestions()));
  558. scaleMarksEntity.setStandardDeviation(DESede.encryptString(scaleMarksEntity.getImprovementSuggestions()));
  559. this.scaleMarksService.updateMark(scaleMarksEntity);
  560. }
  561. for (DimensionEntity dimensionEntity:dimensionEntities){
  562. dimensionEntity.setName(DESede.encryptString(dimensionEntity.getName()));
  563. dimensionEntity.setQuestionNo(DESede.encryptString(dimensionEntity.getQuestionNo()));
  564. this.dimensionService.updateDimension(dimensionEntity);
  565. }
  566. System.out.println("hello");
  567. return "hello";
  568. }
  569. @GetMapping("/updateItem")
  570. public void updateItem(String fileName,String flag){
  571. File file = new File("C:\\Users\\Administrator\\Desktop\\"+fileName+".xlsx");
  572. try {
  573. List<List<List<Object>>> datas = ExcelUtil.getBankListByExcelSheet(new FileInputStream(file.getAbsolutePath()), file.getName());
  574. List<ScaleEntity> scaleEntities = scaleService.getScaleByFlag(flag);
  575. List<List<Object>> an = datas.get(1);
  576. for (ScaleEntity scaleEntity : scaleEntities) {
  577. log.info("------" + scaleEntity.getCheckItems());
  578. String no = scaleEntity.getQuestionNo();
  579. String item = null;
  580. for (List<Object> objects : an) {
  581. if (objects.get(0).equals(no)) {
  582. if (StringUtils.isEmpty(item)) {
  583. item = objects.get(1).toString();
  584. } else {
  585. item = item + ";" + objects.get(1).toString();
  586. }
  587. }
  588. }
  589. scaleEntity.setCheckItems(item);
  590. if (item != null){
  591. //scaleService.saveScale(scaleEntity);
  592. }
  593. log.info("------" + scaleEntity.toString());
  594. }
  595. }catch (Exception e){
  596. e.printStackTrace();
  597. }
  598. }
  599. @GetMapping("/updateAnswer")
  600. public void updateAnswer(String fileName,String flag){
  601. File file = new File("C:\\Users\\Administrator\\Desktop\\"+fileName+".xlsx");
  602. try {
  603. List<List<List<Object>>> datas = ExcelUtil.getBankListByExcelSheet(new FileInputStream(file.getAbsolutePath()), file.getName());
  604. List<AnswerEntity> answerEntities = answerService.getAnswerByFlag(flag);
  605. List<List<Object>> answerObj = datas.get(1);
  606. for (int i =0;i<answerEntities.size();i++){
  607. AnswerEntity answerEntity = answerEntities.get(i);
  608. answerEntity.setName(DESede.encryptString(answerObj.get(i).get(1).toString()));
  609. answerEntity.setScore(DESede.encryptString(answerObj.get(i).get(2).toString()));
  610. log.info(answerEntity.getName());
  611. //answerService.updateAnswer(answerEntity);
  612. }
  613. }catch (Exception e){
  614. e.printStackTrace();
  615. }
  616. }
  617. @GetMapping("updateMarks")
  618. public void updateMarks(String fileName,String flag){
  619. File file = new File("C:\\Users\\Administrator\\Desktop\\"+fileName+".xlsx");
  620. try {
  621. List<List<List<Object>>> datas = ExcelUtil.getBankListByExcelSheet(new FileInputStream(file.getAbsolutePath()), file.getName());
  622. List<ScaleMarksEntity> scaleMarksEntities = scaleMarksService.getScaleMarksByFlag(flag);
  623. List<List<Object>> markObj = datas.get(2);
  624. for (int i =0;i<scaleMarksEntities.size();i++){
  625. ScaleMarksEntity entity = scaleMarksEntities.get(i);
  626. entity.setSymptom(markObj.get(i).get(3).toString());
  627. entity.setImprovementSuggestions(markObj.get(i).get(4).toString());
  628. log.info(entity.toString());
  629. // scaleMarksService.saveScaleMarks(entity);
  630. }
  631. }catch (Exception e){
  632. e.printStackTrace();
  633. }
  634. }
  635. @GetMapping("updateMBTI")
  636. public void updateMBTI(String fileName){
  637. File file = new File("C:\\Users\\Administrator\\Desktop\\"+fileName+".xlsx");
  638. try {
  639. List<List<List<Object>>> datas = ExcelUtil.getBankListByExcelSheet(new FileInputStream(file.getAbsolutePath()), file.getName());
  640. List<List<Object>> markObj = datas.get(1);
  641. for (int i =0;i<markObj.size();i++){
  642. List<Object> objects = markObj.get(i);
  643. MBTIResultDetail detail = new MBTIResultDetail();
  644. detail.setFlag(objects.get(0).toString());
  645. detail.setConclusion(objects.get(1).toString());
  646. detail.setCharacteristic(objects.get(2).toString());
  647. detail.setEvaluate(objects.get(3).toString());
  648. detail.setRepresentative(objects.get(4).toString());
  649. detail.setPursuit(objects.get(5).toString());
  650. detail.setAdvantage(objects.get(6).toString());
  651. detail.setDisadvantages(objects.get(7).toString());
  652. detail.setRecommendation(objects.get(8).toString());
  653. detail.setSuggest(objects.get(9).toString());
  654. detail.setRevered(objects.get(10).toString());
  655. log.info(detail.toString());
  656. //detailService.save(detail);
  657. }
  658. }catch (Exception e){
  659. e.printStackTrace();
  660. }
  661. }
  662. @GetMapping("addMarks")
  663. public void addMarks(String fileName,String flag){
  664. File file = new File("C:\\Users\\Administrator\\Desktop\\"+fileName+".xlsx");
  665. try {
  666. List<List<List<Object>>> datas = ExcelUtil.getBankListByExcelSheet(new FileInputStream(file.getAbsolutePath()), file.getName());
  667. List<ScaleMarksEntity> scaleMarksEntities = scaleMarksService.getScaleMarksByFlag(flag);
  668. List<List<Object>> markObj = datas.get(2);
  669. for (int i =0;i<markObj.size();i++){
  670. List<Object> objects = markObj.get(i);
  671. ScaleMarksEntity entity = new ScaleMarksEntity();
  672. entity.setName(objects.get(0).toString());
  673. entity.setScoreStart(objects.get(1).toString());
  674. entity.setScoreEnd(objects.get(2).toString());
  675. entity.setSymptom(objects.get(3).toString());
  676. entity.setImprovementSuggestions(objects.get(4).toString());
  677. entity.setFlag(flag);
  678. entity.setReference("无");
  679. entity.setStandardDeviation("无");
  680. entity.setNameExplain("无");
  681. entity.setSuggestion("无");
  682. entity.setIsTotalScoreExplain("否");
  683. entity.setScoringType("0");
  684. log.info(entity.toString());
  685. //scaleMarksService.saveScaleMarks(entity);
  686. }
  687. }catch (Exception e){
  688. e.printStackTrace();
  689. }
  690. }
  691. }