LoginController.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. package com.template.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
  4. import com.google.gson.Gson;
  5. import com.google.gson.reflect.TypeToken;
  6. import com.template.annotation.PassToken;
  7. import com.template.api.LoginControllerAPI;
  8. import com.template.common.utils.*;
  9. import com.template.config.WxAuthorConfig;
  10. import com.template.config.WxOpenidConfig;
  11. import com.template.model.enumModel.eIdentityTypeStatu;
  12. import com.template.model.enumModel.eSchool;
  13. import com.template.model.enumModel.eStatu;
  14. import com.template.model.pojo.*;
  15. import com.template.model.request.*;
  16. import com.template.model.result.CommonResult;
  17. import com.template.model.result.Wx_user;
  18. import com.template.model.vo.*;
  19. import com.template.services.*;
  20. import io.swagger.annotations.ApiModelProperty;
  21. import org.apache.commons.io.IOUtils;
  22. import org.slf4j.Logger;
  23. import org.slf4j.LoggerFactory;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.boot.configurationprocessor.json.JSONObject;
  26. import org.springframework.transaction.annotation.Transactional;
  27. import org.springframework.util.StringUtils;
  28. import org.springframework.validation.BindingResult;
  29. import org.springframework.web.bind.annotation.RequestBody;
  30. import org.springframework.web.bind.annotation.RestController;
  31. import javax.annotation.Resource;
  32. import javax.imageio.ImageIO;
  33. import javax.servlet.ServletOutputStream;
  34. import javax.servlet.http.HttpServletResponse;
  35. import java.awt.image.BufferedImage;
  36. import java.io.IOException;
  37. import java.math.BigDecimal;
  38. import java.math.BigInteger;
  39. import java.net.URLEncoder;
  40. import java.util.*;
  41. /**
  42. * @Author: binguo
  43. * @Date: 2023/7/5 星期三 9:28
  44. * @Description: com.template.controller
  45. * @Version: 1.0
  46. */
  47. @RestController
  48. public class LoginController implements LoginControllerAPI {
  49. @Autowired
  50. private WxOpenidConfig wxOpenidConfig;
  51. @Resource
  52. private WelcomeOrgService welcomeOrgService;
  53. @Resource
  54. private WelcomeFamilyService welcomeFamilyService;
  55. @Resource
  56. private WelcomeStudentService welcomeStudentService;
  57. @Resource
  58. private WelcomeAccountService welcomeAccountService;
  59. @Resource
  60. private WelcomeAccompanyService welcomeAccompanyService;
  61. @Resource
  62. private WelcomePaySettingService welcomePaySettingService;
  63. @Resource
  64. private WelcomeArriveSettingService welcomeArriveSettingService;
  65. private static Logger logger = LoggerFactory.getLogger(LoginController.class);
  66. /**
  67. * 查看系统版本号
  68. *
  69. * @return
  70. */
  71. @Override
  72. @PassToken
  73. public CommonResult queryReduce() {
  74. return CommonResult.ok("当前系统版本为:1V");
  75. }
  76. /**
  77. * 登录接口
  78. *
  79. * @param loginRequest account 账号
  80. * password 密码
  81. * @return
  82. */
  83. @Override
  84. @PassToken
  85. public CommonResult Login(@RequestBody loginRequest loginRequest, BindingResult bindingResult) {
  86. if (loginRequest == null) {
  87. return CommonResult.fail("请传递参数");
  88. }
  89. if (bindingResult.hasErrors()) {
  90. String st = paramUtils.getParamError(bindingResult);
  91. return CommonResult.fail(st);
  92. }
  93. WelcomeAccount result = welcomeAccountService.getDataByAccount(loginRequest.getAccount());
  94. if (result == null) {
  95. return CommonResult.fail("账号不存在");
  96. }
  97. if (result.getStatus()!=1) {
  98. return CommonResult.fail("账号已冻结");
  99. }
  100. String encPassword = AesUtils.encrypt(loginRequest.getPassword());
  101. if (!encPassword.equals(result.getPassword())) {
  102. return CommonResult.fail("密码错误");
  103. }
  104. TokenDateVo tokenDate = JWTUtil.getToken("", result.getId(), null);
  105. String token = tokenDate == null ? "" : tokenDate.getToken();
  106. Date expireTime = tokenDate == null ? new Date() : tokenDate.getExpireTime();
  107. LoginVO login = new LoginVO();
  108. login.setToken(token);
  109. login.setTokenTtl(TimeExchange.DateToString(expireTime, "yyyy-MM-dd HH:mm:ss"));
  110. login.setUserName(result.getName());
  111. login.setAccountId(result.getId());
  112. return CommonResult.ok("200", "登录成功", login);
  113. }
  114. /**
  115. * 修改密码
  116. *
  117. * @param cpr oldPassword 旧密码
  118. * newPassword 新密码
  119. * confirmPassword 确认密码
  120. * @param userId
  121. * @param bindingResult
  122. * @return
  123. */
  124. @Override
  125. @Transactional(rollbackFor = {Exception.class})
  126. public CommonResult ChangePassword(String userId, changePasswordRequest cpr, BindingResult bindingResult) throws Exception {
  127. ChangePasswordVO results = new ChangePasswordVO();
  128. if (bindingResult.hasErrors()) {
  129. String st = paramUtils.getParamError(bindingResult);
  130. return CommonResult.fail(st);
  131. }
  132. WelcomeAccount result = welcomeAccountService.getManageById(userId);
  133. if (result == null) {
  134. return CommonResult.fail("账号不存在");
  135. }
  136. if (!AesUtils.encrypt(cpr.getOldPassword()).equals(result.getPassword())) {
  137. return CommonResult.fail("原密码错误!");
  138. }
  139. result.setPassword(AesUtils.encrypt(cpr.getNewPassword()));
  140. int updateData = welcomeAccountService.updateWelcomeAccount(result);
  141. return updateData > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
  142. }
  143. @Override
  144. @PassToken
  145. @Transactional(rollbackFor = {Exception.class})
  146. public CommonResult Openid(String wxcode, String urlstr, String state, HttpServletResponse response) throws Exception {
  147. logger.info("微校授权:" + wxcode + ";redirect_uri:" + urlstr + ";H5:" + state);
  148. System.out.println("微校授权:" + wxcode);
  149. Gson gson = new Gson();
  150. String tokenUrl = "https://open.wecard.qq.com/connect/oauth2/token";
  151. Map<String, String> tokenParams = new HashMap<>();
  152. tokenParams.put("wxcode", wxcode);
  153. tokenParams.put("app_key", wxOpenidConfig.getAppid());
  154. tokenParams.put("app_secret", wxOpenidConfig.getAppkey());
  155. tokenParams.put("grant_type", wxOpenidConfig.getGranttype());
  156. tokenParams.put("redirect_uri", state); // H5
  157. // wecode换取token
  158. String respon = HttpsClient.post(tokenUrl, tokenParams);
  159. System.out.println("微校授权2:" + respon);
  160. if (!StringUtils.hasText(respon)) {
  161. System.out.println("微校授权异常信息:respon为空" + respon);
  162. return CommonResult.fail("微校授权异常信息");
  163. }
  164. HashMap<String, Object> tokenMap = gson.fromJson(respon, new TypeToken<HashMap<String, Object>>() {
  165. }.getType());
  166. String accessToken = (String) tokenMap.get("access_token");
  167. // token换取用户信息
  168. String userInfoUrl = "https://open.wecard.qq.com/connect/oauth/get-user-info";
  169. Map<String, String> userInfoParam = new HashMap<>();
  170. userInfoParam.put("access_token", accessToken);
  171. String userinfo = HttpsClient.post(userInfoUrl, userInfoParam);
  172. String card_number = null;
  173. String user_name = null;
  174. String phone = null;
  175. String college = null;
  176. int idenType = 0;
  177. int gender = 0;
  178. String profession = null;
  179. String campus = null;
  180. String id_card = null;
  181. String classStr = null;
  182. System.out.println("微校授权获取用户信息:" + userinfo);
  183. Wx_user userinfos = gson.fromJson(userinfo, new TypeToken<Wx_user>() {
  184. }.getType());
  185. System.out.println("微校授权获取用户信息类别:" + userinfos.getIdentity_type());
  186. try {
  187. card_number = userinfos.getCard_number();
  188. user_name = userinfos.getName();
  189. phone = userinfos.getTelephone();
  190. college = userinfos.getCollege();
  191. classStr = userinfos.getClassStr();
  192. idenType = userinfos.getIdentity_type() == 1 || userinfos.getIdentity_type() == 6 ? 1 : 2;//1:学生 2:非学生
  193. gender = userinfos.getGender();
  194. profession = userinfos.getProfession();
  195. campus = userinfos.getCampus();
  196. id_card = userinfos.getId_card();
  197. } catch (Exception e) {
  198. System.out.println("微校授权异常信息:" + e.getMessage());
  199. response.sendRedirect(wxOpenidConfig.getIp() + "/#/pages/404/404/?message=" + URLEncoder.encode("获取用户信息失败", "UTF-8"));
  200. return CommonResult.fail(e.getMessage());
  201. }
  202. if (card_number == null || card_number.equals("")) {
  203. response.sendRedirect(wxOpenidConfig.getIp() + "/#/pages/404/404/?message=" + URLEncoder.encode("获取用户信息失败", "UTF-8"));
  204. return CommonResult.fail("卡号为空,授权失败");
  205. }
  206. //根据卡号查询repair_user表中的用户信息
  207. WelcomeStudent student = welcomeStudentService.getDataByIdcard(id_card);
  208. System.out.println("微校授权获取用户信息"+JSON.toJSON(student));
  209. //取消授权的身份验证 谁都能进
  210. //if (identity_type != 4 && user == null) {
  211. // return CommonResult.fail("非法权限,授权失败");
  212. //}
  213. System.out.println("微校授权校区:" + campus);
  214. Integer studentId = 0;
  215. if (student == null) {
  216. System.out.println("微校授权失败,学生信息新增异常:" + user_name + "" + card_number);
  217. response.sendRedirect(wxOpenidConfig.getIp() + "/#/pages/404/404/?message=" + URLEncoder.encode("用户在系统中不存在,请联系管理员", "UTF-8"));
  218. throw new Exception("微校授权失败!");
  219. // try {
  220. // student = new WelcomeStudent();
  221. // student.setAdmissNum(card_number);
  222. // student.setName(user_name);
  223. // student.setPhone(phone);
  224. // student.setSchool(campus);
  225. // student.setSchoolId(campus == null ? 0 : eSchool.stringOf(campus));
  226. // student.setSex(gender == 1 ? "男" : "女");
  227. // student.setCollege(college);
  228. // student.setMajor(profession);
  229. // student.setIdenType(idenType);
  230. // student.setClassstr(classStr);
  231. // student.setCardId(id_card);//身份证号
  232. // int num = welcomeStudentService.insertWelcomeStudent(student);
  233. // if (num <= 0) {
  234. // System.out.println("微校授权失败,学生信息新增异常:" + user_name + "" + card_number);
  235. // response.sendRedirect(wxOpenidConfig.getIp() + "/#/pages/404/404/?message=" + URLEncoder.encode("用户新增异常", "UTF-8"));
  236. // throw new Exception("微校授权失败!");
  237. // }
  238. // studentId = num;
  239. // } catch (Exception e) {
  240. // System.out.println("微校授权异常信息:" + e.getMessage());
  241. // response.sendRedirect(wxOpenidConfig.getIp() + "/#/pages/404/404/?message=" + URLEncoder.encode("获取用户信息失败", "UTF-8"));
  242. // throw new Exception("微校授权失败!");
  243. // }
  244. } else {
  245. //更新微校获取的年纪信息
  246. // student.setAdmissNum(card_number);
  247. // student.setName(user_name);
  248. // student.setPhone(phone);
  249. // student.setSchool(!StringUtils.hasText(campus) ? "墨轩湖校区" : campus);
  250. // student.setSchoolId(!StringUtils.hasText(campus) ? 1 : eSchool.stringOf(campus));
  251. // student.setSex(gender == 1 ? "男" : "女");
  252. // student.setCollege(college);
  253. // student.setMajor(profession);
  254. student.setIdenType(idenType);
  255. //student.setClassstr(classStr);
  256. //student.setCardId(id_card);//身份证号
  257. if(student.getIdenType().intValue() == 1 && !(student.getIsPay() != null && student.getIsPay().intValue() == 1)){
  258. List<JsonPayVo> payInfos = WelcomePayController.queryStudentPayInfo(card_number,TimeExchange.getYear());
  259. BigDecimal payAmount = new BigDecimal(BigInteger.ZERO);//实缴金额
  260. BigDecimal yjPayAmount = new BigDecimal(BigInteger.ZERO);//应缴金额
  261. for (JsonPayVo pi:payInfos) {
  262. payAmount = payAmount.add(pi.getSJJE());
  263. yjPayAmount = yjPayAmount.add(pi.getYJJE());
  264. }
  265. student.setPayAmount(payAmount);
  266. student.setAmountPayable(yjPayAmount);
  267. if(payInfos != null && payInfos.size() > 0){
  268. List<WelcomePaySetting> paySettings = welcomePaySettingService.queryPaySettings(campus);
  269. if(paySettings != null && paySettings.size() > 0){
  270. for (WelcomePaySetting pay:paySettings) {
  271. BigDecimal money = pay.getPayAmount();
  272. if(pay.getMethod().equals("全部")){
  273. BigDecimal totalSj = new BigDecimal(BigInteger.ZERO);
  274. for (JsonPayVo jpv:payInfos){
  275. totalSj = totalSj.add(jpv.getSJJE());
  276. }
  277. if(totalSj.compareTo(money) >= 0){
  278. student.setIsPay(1);
  279. }
  280. }
  281. Optional<JsonPayVo> ojpv = payInfos.stream().filter(e -> e.getSFXMMC().equals(pay.getMethod())).findFirst();
  282. if(ojpv != null && ojpv.isPresent()){
  283. if(ojpv.get().getSJJE().compareTo(money) >= 0){
  284. student.setIsPay(1);
  285. }
  286. }
  287. }
  288. }else{
  289. student.setIsPay(0);
  290. }
  291. }else{
  292. student.setIsPay(0);
  293. }
  294. }
  295. int num = welcomeStudentService.updateWelcomeStudent(student);
  296. if (num <= 0) {
  297. System.out.println("微校授权失败,用户信息新增异常:" + user_name + "" + card_number);
  298. response.sendRedirect(wxOpenidConfig.getIp() + "/#/pages/404/404/?message=" + URLEncoder.encode("用户更新异常", "UTF-8"));
  299. throw new Exception("微校授权失败!");
  300. }
  301. studentId = student.getId();
  302. }
  303. wxLoginVo wlv = new wxLoginVo();
  304. List<WelcomeOrg> orgs = welcomeOrgService.queryDatas(college, profession, classStr);
  305. if (orgs != null && orgs.size() > 0) {
  306. for (WelcomeOrg org : orgs) {
  307. if (org.getName().equals(college)) {
  308. wlv.setCollegeId(org.getId());
  309. wlv.setCollege(college);
  310. }
  311. if (org.getName().equals(profession)) {
  312. wlv.setMajorId(org.getId());
  313. wlv.setMajor(profession);
  314. }
  315. if (org.getName().equals(classStr)) {
  316. wlv.setClassstrId(org.getId());
  317. wlv.setClassstr(classStr);
  318. }
  319. }
  320. }
  321. wlv.setId(studentId);
  322. wlv.setAdmissNum(card_number);
  323. wlv.setName(user_name);
  324. wlv.setPicture(student.getPicture());
  325. wlv.setCardId(id_card);
  326. if(StringUtils.hasText(id_card)){
  327. if(StringUtils.hasText(student.getSex())){
  328. wlv.setSex(student.getSex());
  329. }else{
  330. String sex = StrUtils.getGender(id_card);
  331. wlv.setSex(sex);
  332. }
  333. //家庭成员
  334. List<FamilyVo> fvs = new ArrayList<>();
  335. List<WelcomeFamily> familys = welcomeFamilyService.getManageByCardId(student.getCardId());
  336. if (familys != null && familys.size() > 0) {
  337. for (WelcomeFamily wf : familys) {
  338. FamilyVo fv = new FamilyVo();
  339. fv.setId(wf.getId());
  340. fv.setFamilyShip(wf.getFamilyShip());
  341. fv.setName(wf.getName());
  342. fv.setPhone(wf.getPhone());
  343. fv.setWorkUnit(wf.getWorkUnit());
  344. fvs.add(fv);
  345. }
  346. }
  347. wlv.setFvs(fvs);
  348. //陪同人员
  349. List<AccompanyVo> avs = new ArrayList<>();
  350. List<WelcomeAccompany> accompanys = welcomeAccompanyService.getManageByCardId(student.getCardId());
  351. if (accompanys != null && accompanys.size() > 0) {
  352. for (WelcomeAccompany ac : accompanys) {
  353. AccompanyVo av = new AccompanyVo();
  354. av.setId(ac.getId());
  355. av.setName(ac.getName());
  356. av.setPhone(ac.getPhone());
  357. avs.add(av);
  358. }
  359. }
  360. wlv.setAvs(avs);
  361. //时间段
  362. List<ArriveTimeVo> atvs = new ArrayList<>();
  363. List<WelcomeArriveSetting> wass = welcomeArriveSettingService.queryCheckDatas();
  364. if (wass != null && wass.size() > 0) {
  365. for (WelcomeArriveSetting was : wass) {
  366. ArriveTimeVo atv = new ArriveTimeVo();
  367. atv.setId(was.getId());
  368. atv.setStartTime(was.getStartTime());
  369. atv.setEndTime(was.getEndTime());
  370. atv.setTimeStr(was.getStartTime() + "-" + was.getEndTime());
  371. atv.setIsCheck((student.getArriveTimeId() != null && was.getId().equals(student.getArriveTimeId())) ? 1 : 0);
  372. atvs.add(atv);
  373. }
  374. }
  375. wlv.setAtvs(atvs);
  376. }
  377. wlv.setSchool(!StringUtils.hasText(campus) ? "墨轩湖校区" : campus);
  378. wlv.setSchoolId(!StringUtils.hasText(campus) ? 1 : eSchool.stringOf(campus));
  379. //籍贯
  380. wlv.setOprovinceId(student.getOprovinceId());
  381. wlv.setOprovince(student.getOprovince());
  382. wlv.setOcityId(student.getOcityId());
  383. wlv.setOcity(student.getOcity());
  384. wlv.setOdistrictId(student.getOdistrictId());
  385. wlv.setOdistrict(student.getOdistrict());
  386. wlv.setProvinceId(student.getProvinceId());
  387. wlv.setProvince(student.getProvince());
  388. wlv.setCityId(student.getCityId());
  389. wlv.setCity(student.getCity());
  390. wlv.setDistrictId(student.getDistrictId());
  391. wlv.setDistrict(student.getDistrict());
  392. wlv.setIsPay(student.getIsPay());
  393. wlv.setPhone(student.getPhone().replace("(+86)", ""));
  394. wlv.setCollege(college == null ? "微校获取不到院校" : college);
  395. long expired = 1000 * 60 * 60 * 24 * 365;
  396. TokenDateVo token = JWTUtil.getToken(id_card, student.getId(), expired);
  397. wlv.setToken(token.getToken());
  398. System.out.println("微校授权成功:" + user_name + "" + card_number);
  399. response.sendRedirect(wxOpenidConfig.getIp() + "/#/pages/index/index/?urlstr=" + urlstr + "&token=" + token.getToken() + "&type=" + idenType);
  400. return CommonResult.ok(wlv);
  401. }
  402. @Override
  403. @PassToken
  404. public CommonResult mobileLogin(mobileLoginRequest mlr, BindingResult bindingResult) {
  405. if (mlr == null) {
  406. return CommonResult.fail("请传递参数");
  407. }
  408. if (bindingResult.hasErrors()) {
  409. String st = paramUtils.getParamError(bindingResult);
  410. return CommonResult.fail(st);
  411. }
  412. WelcomeStudent student = welcomeStudentService.getDataByIdcardOrNum(mlr.getAdmissNum(), mlr.getCardId());
  413. if (student == null) {
  414. return CommonResult.fail("录取号或身份证错误,登录失败!");
  415. }
  416. if(StringUtils.hasText(student.getCardId())){
  417. if(StringUtils.hasText(student.getSex())){
  418. student.setSex(student.getSex());
  419. }else{
  420. String sex =StrUtils.getGender(student.getCardId());
  421. student.setSex(sex);
  422. }
  423. }
  424. //家庭成员
  425. List<FamilyVo> fvs = new ArrayList<>();
  426. List<WelcomeFamily> familys = welcomeFamilyService.getManageByCardId(student.getCardId());
  427. if (familys != null && familys.size() > 0) {
  428. for (WelcomeFamily wf : familys) {
  429. FamilyVo fv = new FamilyVo();
  430. fv.setId(wf.getId());
  431. fv.setFamilyShip(wf.getFamilyShip());
  432. fv.setName(wf.getName());
  433. fv.setPhone(wf.getPhone());
  434. fv.setWorkUnit(wf.getWorkUnit());
  435. fvs.add(fv);
  436. }
  437. }
  438. student.setFvs(fvs);
  439. //陪同人员
  440. List<AccompanyVo> avs = new ArrayList<>();
  441. List<WelcomeAccompany> accompanys = welcomeAccompanyService.getManageByCardId(student.getCardId());
  442. if (accompanys != null && accompanys.size() > 0) {
  443. for (WelcomeAccompany ac : accompanys) {
  444. AccompanyVo av = new AccompanyVo();
  445. av.setId(ac.getId());
  446. av.setName(ac.getName());
  447. av.setPhone(ac.getPhone());
  448. avs.add(av);
  449. }
  450. }
  451. student.setAvs(avs);
  452. //时间段
  453. List<ArriveTimeVo> atvs = new ArrayList<>();
  454. List<WelcomeArriveSetting> wass = welcomeArriveSettingService.queryCheckDatas();
  455. if (wass != null && wass.size() > 0) {
  456. for (WelcomeArriveSetting was : wass) {
  457. ArriveTimeVo atv = new ArriveTimeVo();
  458. atv.setId(was.getId());
  459. atv.setStartTime(was.getStartTime());
  460. atv.setEndTime(was.getEndTime());
  461. atv.setTimeStr(was.getStartTime() + "-" + was.getEndTime());
  462. atv.setIsCheck((student.getArriveTimeId() != null && was.getId().equals(student.getArriveTimeId())) ? 1 : 0);
  463. atvs.add(atv);
  464. }
  465. }
  466. student.setAtvs(atvs);
  467. //region 查询缴费
  468. if(!(student.getIsPay() != null && student.getIsPay().intValue() == 1)){//未缴费的情况下去查
  469. if(StringUtils.hasText(student.getAdmissNum()) && StringUtils.hasText(student.getSchool())){
  470. List<WelcomePaySetting> paySettings = welcomePaySettingService.queryPaySettings(student.getSchool());
  471. if(paySettings != null && paySettings.size() > 0){
  472. String year = TimeExchange.getYear();
  473. String payResult = HtPayUtils.getDataTwo(student.getAdmissNum(),year);
  474. if(StringUtils.hasText(payResult)){
  475. //缴费判定
  476. }else{
  477. student.setIsPay(0);
  478. }
  479. }else{
  480. student.setIsPay(0);
  481. }
  482. }
  483. }
  484. //endregion
  485. if(!(student.getIsPay() != null && student.getIsPay().intValue() == 1)){
  486. System.out.println("进支付比较");
  487. List<JsonPayVo> payInfos = WelcomePayController.queryStudentPayInfo(student.getAdmissNum(),TimeExchange.getYear());
  488. BigDecimal payAmount = new BigDecimal(BigInteger.ZERO);//实缴金额
  489. BigDecimal yjPayAmount = new BigDecimal(BigInteger.ZERO);//应缴金额
  490. for (JsonPayVo pi:payInfos) {
  491. payAmount = payAmount.add(pi.getSJJE());
  492. yjPayAmount = yjPayAmount.add(pi.getYJJE());
  493. }
  494. student.setPayAmount(payAmount);
  495. student.setAmountPayable(yjPayAmount);
  496. System.out.println("进支付比较1"+JSON.toJSON(payInfos));
  497. if(payInfos != null && payInfos.size() > 0){
  498. System.out.println("进支付比较2");
  499. List<WelcomePaySetting> paySettings = welcomePaySettingService.queryPaySettings(student.getSchool());
  500. System.out.println("进支付比较3");
  501. if(paySettings != null && paySettings.size() > 0){
  502. System.out.println("进支付比较4");
  503. for (WelcomePaySetting pay:paySettings) {
  504. System.out.println("进支付比较5");
  505. BigDecimal money = pay.getPayAmount();
  506. if(pay.getMethod().equals("全部")){
  507. BigDecimal totalSj = new BigDecimal(BigInteger.ZERO);
  508. for (JsonPayVo jpv:payInfos){
  509. totalSj = totalSj.add(jpv.getSJJE());
  510. }
  511. if(totalSj.compareTo(money) >= 0){
  512. student.setIsPay(1);
  513. }
  514. }
  515. Optional<JsonPayVo> ojpv = payInfos.stream().filter(e -> e.getSFXMMC().equals(pay.getMethod())).findFirst();
  516. if(ojpv != null && ojpv.isPresent()){
  517. if(ojpv.get().getSJJE().compareTo(money) >= 0){
  518. student.setIsPay(1);
  519. }
  520. }
  521. }
  522. }else{
  523. student.setIsPay(0);
  524. }
  525. }else{
  526. student.setIsPay(0);
  527. }
  528. if(payInfos != null && payInfos.size() > 0){
  529. int update = welcomeStudentService.updateWelcomeStudent(student);
  530. if(update < 0){
  531. logger.error("获取支付信息导致学校信息查询失败");
  532. return CommonResult.fail("查询失败");
  533. }
  534. }
  535. }
  536. long expired = 1000 * 60 * 60 * 24 * 365;
  537. TokenDateVo token = JWTUtil.getToken(student.getCardId(), student.getId(), expired);
  538. student.setToken(token.getToken());
  539. return CommonResult.ok(student);
  540. }
  541. @Override
  542. @PassToken
  543. public CommonResult writeCarInfo() {
  544. com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
  545. String ukey = "6VMZEC5C6HZM7EO8";
  546. com.alibaba.fastjson.JSONObject datas = new com.alibaba.fastjson.JSONObject();
  547. datas.put("car_number", "赣A0AY39");
  548. datas.put("begin_time", "2025-06-16 10:00:00");
  549. datas.put("end_time", "2025-06-16 18:00:00");
  550. datas.put("mobile", "18279193722");
  551. // 生成带签名的字符串并使用MD5生成签名,然后转大写
  552. String sign = datas.toJSONString() + "key=" + ukey;
  553. sign = CreateSign1.MD5(sign).toUpperCase();
  554. json.put("service_name", "visitor_sync");
  555. json.put("sign", sign);
  556. json.put("park_id", "10033845");
  557. json.put("data", datas);
  558. String msg = HttpsClient.sendJson("http://istparking.sciseetech.com/public/visitor/do", json);
  559. return CommonResult.ok(msg);
  560. }
  561. @Override
  562. public CommonResult payResult(payResultRequest mlr) {
  563. logger.info("支付回调信息,mlr参数:" + JSON.toJSON(mlr));
  564. return CommonResult.ok();
  565. }
  566. }