| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590 |
- package com.template.controller;
- import com.alibaba.fastjson.JSON;
- import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
- import com.google.gson.Gson;
- import com.google.gson.reflect.TypeToken;
- import com.template.annotation.PassToken;
- import com.template.api.LoginControllerAPI;
- import com.template.common.utils.*;
- import com.template.config.WxAuthorConfig;
- import com.template.config.WxOpenidConfig;
- import com.template.model.enumModel.eIdentityTypeStatu;
- import com.template.model.enumModel.eSchool;
- import com.template.model.enumModel.eStatu;
- import com.template.model.pojo.*;
- import com.template.model.request.*;
- import com.template.model.result.CommonResult;
- import com.template.model.result.Wx_user;
- import com.template.model.vo.*;
- import com.template.services.*;
- import io.swagger.annotations.ApiModelProperty;
- import org.apache.commons.io.IOUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.boot.configurationprocessor.json.JSONObject;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.util.StringUtils;
- import org.springframework.validation.BindingResult;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RestController;
- import javax.annotation.Resource;
- import javax.imageio.ImageIO;
- import javax.servlet.ServletOutputStream;
- import javax.servlet.http.HttpServletResponse;
- import java.awt.image.BufferedImage;
- import java.io.IOException;
- import java.math.BigDecimal;
- import java.math.BigInteger;
- import java.net.URLEncoder;
- import java.util.*;
- /**
- * @Author: binguo
- * @Date: 2023/7/5 星期三 9:28
- * @Description: com.template.controller
- * @Version: 1.0
- */
- @RestController
- public class LoginController implements LoginControllerAPI {
- @Autowired
- private WxOpenidConfig wxOpenidConfig;
- @Resource
- private WelcomeOrgService welcomeOrgService;
- @Resource
- private WelcomeFamilyService welcomeFamilyService;
- @Resource
- private WelcomeStudentService welcomeStudentService;
- @Resource
- private WelcomeAccountService welcomeAccountService;
- @Resource
- private WelcomeAccompanyService welcomeAccompanyService;
- @Resource
- private WelcomePaySettingService welcomePaySettingService;
- @Resource
- private WelcomeArriveSettingService welcomeArriveSettingService;
- private static Logger logger = LoggerFactory.getLogger(LoginController.class);
- /**
- * 查看系统版本号
- *
- * @return
- */
- @Override
- @PassToken
- public CommonResult queryReduce() {
- return CommonResult.ok("当前系统版本为:1V");
- }
- /**
- * 登录接口
- *
- * @param loginRequest account 账号
- * password 密码
- * @return
- */
- @Override
- @PassToken
- public CommonResult Login(@RequestBody loginRequest loginRequest, BindingResult bindingResult) {
- if (loginRequest == null) {
- return CommonResult.fail("请传递参数");
- }
- if (bindingResult.hasErrors()) {
- String st = paramUtils.getParamError(bindingResult);
- return CommonResult.fail(st);
- }
- WelcomeAccount result = welcomeAccountService.getDataByAccount(loginRequest.getAccount());
- if (result == null) {
- return CommonResult.fail("账号不存在");
- }
- if (result.getStatus()!=1) {
- return CommonResult.fail("账号已冻结");
- }
- String encPassword = AesUtils.encrypt(loginRequest.getPassword());
- if (!encPassword.equals(result.getPassword())) {
- return CommonResult.fail("密码错误");
- }
- TokenDateVo tokenDate = JWTUtil.getToken("", result.getId(), null);
- String token = tokenDate == null ? "" : tokenDate.getToken();
- Date expireTime = tokenDate == null ? new Date() : tokenDate.getExpireTime();
- LoginVO login = new LoginVO();
- login.setToken(token);
- login.setTokenTtl(TimeExchange.DateToString(expireTime, "yyyy-MM-dd HH:mm:ss"));
- login.setUserName(result.getName());
- login.setAccountId(result.getId());
- return CommonResult.ok("200", "登录成功", login);
- }
- /**
- * 修改密码
- *
- * @param cpr oldPassword 旧密码
- * newPassword 新密码
- * confirmPassword 确认密码
- * @param userId
- * @param bindingResult
- * @return
- */
- @Override
- @Transactional(rollbackFor = {Exception.class})
- public CommonResult ChangePassword(String userId, changePasswordRequest cpr, BindingResult bindingResult) throws Exception {
- ChangePasswordVO results = new ChangePasswordVO();
- if (bindingResult.hasErrors()) {
- String st = paramUtils.getParamError(bindingResult);
- return CommonResult.fail(st);
- }
- WelcomeAccount result = welcomeAccountService.getManageById(userId);
- if (result == null) {
- return CommonResult.fail("账号不存在");
- }
- if (!AesUtils.encrypt(cpr.getOldPassword()).equals(result.getPassword())) {
- return CommonResult.fail("原密码错误!");
- }
- result.setPassword(AesUtils.encrypt(cpr.getNewPassword()));
- int updateData = welcomeAccountService.updateWelcomeAccount(result);
- return updateData > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
- }
- @Override
- @PassToken
- @Transactional(rollbackFor = {Exception.class})
- public CommonResult Openid(String wxcode, String urlstr, String state, HttpServletResponse response) throws Exception {
- logger.info("微校授权:" + wxcode + ";redirect_uri:" + urlstr + ";H5:" + state);
- System.out.println("微校授权:" + wxcode);
- Gson gson = new Gson();
- String tokenUrl = "https://open.wecard.qq.com/connect/oauth2/token";
- Map<String, String> tokenParams = new HashMap<>();
- tokenParams.put("wxcode", wxcode);
- tokenParams.put("app_key", wxOpenidConfig.getAppid());
- tokenParams.put("app_secret", wxOpenidConfig.getAppkey());
- tokenParams.put("grant_type", wxOpenidConfig.getGranttype());
- tokenParams.put("redirect_uri", state); // H5
- // wecode换取token
- String respon = HttpsClient.post(tokenUrl, tokenParams);
- System.out.println("微校授权2:" + respon);
- if (!StringUtils.hasText(respon)) {
- System.out.println("微校授权异常信息:respon为空" + respon);
- return CommonResult.fail("微校授权异常信息");
- }
- HashMap<String, Object> tokenMap = gson.fromJson(respon, new TypeToken<HashMap<String, Object>>() {
- }.getType());
- String accessToken = (String) tokenMap.get("access_token");
- // token换取用户信息
- String userInfoUrl = "https://open.wecard.qq.com/connect/oauth/get-user-info";
- Map<String, String> userInfoParam = new HashMap<>();
- userInfoParam.put("access_token", accessToken);
- String userinfo = HttpsClient.post(userInfoUrl, userInfoParam);
- String card_number = null;
- String user_name = null;
- String phone = null;
- String college = null;
- int idenType = 0;
- int gender = 0;
- String profession = null;
- String campus = null;
- String id_card = null;
- String classStr = null;
- System.out.println("微校授权获取用户信息:" + userinfo);
- Wx_user userinfos = gson.fromJson(userinfo, new TypeToken<Wx_user>() {
- }.getType());
- System.out.println("微校授权获取用户信息类别:" + userinfos.getIdentity_type());
- try {
- card_number = userinfos.getCard_number();
- user_name = userinfos.getName();
- phone = userinfos.getTelephone();
- college = userinfos.getCollege();
- classStr = userinfos.getClassStr();
- idenType = userinfos.getIdentity_type() == 1 || userinfos.getIdentity_type() == 6 ? 1 : 2;//1:学生 2:非学生
- gender = userinfos.getGender();
- profession = userinfos.getProfession();
- campus = userinfos.getCampus();
- id_card = userinfos.getId_card();
- } catch (Exception e) {
- System.out.println("微校授权异常信息:" + e.getMessage());
- response.sendRedirect(wxOpenidConfig.getIp() + "/#/pages/404/404/?message=" + URLEncoder.encode("获取用户信息失败", "UTF-8"));
- return CommonResult.fail(e.getMessage());
- }
- if (card_number == null || card_number.equals("")) {
- response.sendRedirect(wxOpenidConfig.getIp() + "/#/pages/404/404/?message=" + URLEncoder.encode("获取用户信息失败", "UTF-8"));
- return CommonResult.fail("卡号为空,授权失败");
- }
- //根据卡号查询repair_user表中的用户信息
- WelcomeStudent student = welcomeStudentService.getDataByIdcard(id_card);
- //取消授权的身份验证 谁都能进
- //if (identity_type != 4 && user == null) {
- // return CommonResult.fail("非法权限,授权失败");
- //}
- System.out.println("微校授权校区:" + campus);
- Integer studentId = 0;
- if (student == null) {
- System.out.println("微校授权失败,学生信息新增异常:" + user_name + "" + card_number);
- response.sendRedirect(wxOpenidConfig.getIp() + "/#/pages/404/404/?message=" + URLEncoder.encode("用户在系统中不存在,请联系管理员", "UTF-8"));
- throw new Exception("微校授权失败!");
- // try {
- // student = new WelcomeStudent();
- // student.setAdmissNum(card_number);
- // student.setName(user_name);
- // student.setPhone(phone);
- // student.setSchool(campus);
- // student.setSchoolId(campus == null ? 0 : eSchool.stringOf(campus));
- // student.setSex(gender == 1 ? "男" : "女");
- // student.setCollege(college);
- // student.setMajor(profession);
- // student.setIdenType(idenType);
- // student.setClassstr(classStr);
- // student.setCardId(id_card);//身份证号
- // int num = welcomeStudentService.insertWelcomeStudent(student);
- // if (num <= 0) {
- // System.out.println("微校授权失败,学生信息新增异常:" + user_name + "" + card_number);
- // response.sendRedirect(wxOpenidConfig.getIp() + "/#/pages/404/404/?message=" + URLEncoder.encode("用户新增异常", "UTF-8"));
- // throw new Exception("微校授权失败!");
- // }
- // studentId = num;
- // } catch (Exception e) {
- // System.out.println("微校授权异常信息:" + e.getMessage());
- // response.sendRedirect(wxOpenidConfig.getIp() + "/#/pages/404/404/?message=" + URLEncoder.encode("获取用户信息失败", "UTF-8"));
- // throw new Exception("微校授权失败!");
- // }
- } else {
- //更新微校获取的年纪信息
- student.setAdmissNum(card_number);
- student.setName(user_name);
- student.setPhone(phone);
- student.setSchool(campus);
- student.setSchoolId(campus == null ? 0 : eSchool.stringOf(campus));
- student.setSex(gender == 1 ? "男" : "女");
- // student.setCollege(college);
- // student.setMajor(profession);
- student.setIdenType(idenType);
- //student.setClassstr(classStr);
- student.setCardId(id_card);//身份证号
- if(!(student.getIsPay() != null && student.getIsPay().intValue() == 1)){
- List<JsonPayVo> payInfos = WelcomePayController.queryStudentPayInfo(card_number,TimeExchange.getYear());
- if(payInfos != null && payInfos.size() > 0){
- List<WelcomePaySetting> paySettings = welcomePaySettingService.queryPaySettings(campus);
- if(paySettings != null && paySettings.size() > 0){
- for (WelcomePaySetting pay:paySettings) {
- BigDecimal money = pay.getPayAmount();
- if(pay.getMethod().equals("全部")){
- BigDecimal totalSj = new BigDecimal(BigInteger.ZERO);
- for (JsonPayVo jpv:payInfos){
- totalSj = totalSj.add(jpv.getSJJE());
- }
- if(totalSj.compareTo(money) >= 0){
- student.setIsPay(1);
- }
- }
- Optional<JsonPayVo> ojpv = payInfos.stream().filter(e -> e.getSFXMMC().equals(pay.getMethod())).findFirst();
- if(ojpv != null && ojpv.isPresent()){
- if(ojpv.get().getSJJE().compareTo(money) >= 0){
- student.setIsPay(1);
- }
- }
- }
- }else{
- student.setIsPay(0);
- }
- }else{
- student.setIsPay(0);
- }
- }
- int num = welcomeStudentService.updateWelcomeStudent(student);
- if (num <= 0) {
- System.out.println("微校授权失败,用户信息新增异常:" + user_name + "" + card_number);
- response.sendRedirect(wxOpenidConfig.getIp() + "/#/pages/404/404/?message=" + URLEncoder.encode("用户更新异常", "UTF-8"));
- throw new Exception("微校授权失败!");
- }
- studentId = student.getId();
- }
- wxLoginVo wlv = new wxLoginVo();
- List<WelcomeOrg> orgs = welcomeOrgService.queryDatas(college, profession, classStr);
- if (orgs != null && orgs.size() > 0) {
- for (WelcomeOrg org : orgs) {
- if (org.getName().equals(college)) {
- wlv.setCollegeId(org.getId());
- wlv.setCollege(college);
- }
- if (org.getName().equals(profession)) {
- wlv.setMajorId(org.getId());
- wlv.setMajor(profession);
- }
- if (org.getName().equals(classStr)) {
- wlv.setClassstrId(org.getId());
- wlv.setClassstr(classStr);
- }
- }
- }
- wlv.setId(studentId);
- wlv.setAdmissNum(card_number);
- wlv.setName(user_name);
- wlv.setPicture(student.getPicture());
- wlv.setCardId(id_card);
- if(StringUtils.hasText(id_card)){
- if(StringUtils.hasText(student.getSex())){
- wlv.setSex(student.getSex());
- }else{
- String sex = StrUtils.getGender(id_card);
- wlv.setSex(sex);
- }
- //家庭成员
- List<FamilyVo> fvs = new ArrayList<>();
- List<WelcomeFamily> familys = welcomeFamilyService.getManageByCardId(student.getCardId());
- if (familys != null && familys.size() > 0) {
- for (WelcomeFamily wf : familys) {
- FamilyVo fv = new FamilyVo();
- fv.setId(wf.getId());
- fv.setFamilyShip(wf.getFamilyShip());
- fv.setName(wf.getName());
- fv.setPhone(wf.getPhone());
- fv.setWorkUnit(wf.getWorkUnit());
- fvs.add(fv);
- }
- }
- wlv.setFvs(fvs);
- //陪同人员
- List<AccompanyVo> avs = new ArrayList<>();
- List<WelcomeAccompany> accompanys = welcomeAccompanyService.getManageByCardId(student.getCardId());
- if (accompanys != null && accompanys.size() > 0) {
- for (WelcomeAccompany ac : accompanys) {
- AccompanyVo av = new AccompanyVo();
- av.setId(ac.getId());
- av.setName(ac.getName());
- av.setPhone(ac.getPhone());
- avs.add(av);
- }
- }
- wlv.setAvs(avs);
- //时间段
- List<ArriveTimeVo> atvs = new ArrayList<>();
- List<WelcomeArriveSetting> wass = welcomeArriveSettingService.queryCheckDatas();
- if (wass != null && wass.size() > 0) {
- for (WelcomeArriveSetting was : wass) {
- ArriveTimeVo atv = new ArriveTimeVo();
- atv.setId(was.getId());
- atv.setStartTime(was.getStartTime());
- atv.setEndTime(was.getEndTime());
- atv.setTimeStr(was.getStartTime() + "-" + was.getEndTime());
- atv.setIsCheck((student.getArriveTimeId() != null && was.getId().equals(student.getArriveTimeId())) ? 1 : 0);
- atvs.add(atv);
- }
- }
- wlv.setAtvs(atvs);
- }
- wlv.setSchool(campus);
- wlv.setSchoolId(campus == null ? 0 : eSchool.stringOf(campus));
- //籍贯
- wlv.setOprovinceId(student.getOprovinceId());
- wlv.setOprovince(student.getOprovince());
- wlv.setOcityId(student.getOcityId());
- wlv.setOcity(student.getOcity());
- wlv.setOdistrictId(student.getOdistrictId());
- wlv.setOdistrict(student.getOdistrict());
- wlv.setProvinceId(student.getProvinceId());
- wlv.setProvince(student.getProvince());
- wlv.setCityId(student.getCityId());
- wlv.setCity(student.getCity());
- wlv.setDistrictId(student.getDistrictId());
- wlv.setDistrict(student.getDistrict());
- wlv.setIsPay(student.getIsPay());
- wlv.setPhone(student.getPhone().replace("(+86)", ""));
- wlv.setCollege(college == null ? "微校获取不到院校" : college);
- long expired = 1000 * 60 * 60 * 24 * 365;
- TokenDateVo token = JWTUtil.getToken(id_card, student.getId(), expired);
- wlv.setToken(token.getToken());
- System.out.println("微校授权成功:" + user_name + "" + card_number);
- response.sendRedirect(wxOpenidConfig.getIp() + "/#/pages/index/index/?urlstr=" + urlstr + "&token=" + token.getToken() + "&type=" + idenType);
- return CommonResult.ok(wlv);
- }
- @Override
- @PassToken
- public CommonResult mobileLogin(mobileLoginRequest mlr, BindingResult bindingResult) {
- if (mlr == null) {
- return CommonResult.fail("请传递参数");
- }
- if (bindingResult.hasErrors()) {
- String st = paramUtils.getParamError(bindingResult);
- return CommonResult.fail(st);
- }
- WelcomeStudent student = welcomeStudentService.getDataByIdcardOrNum(mlr.getAdmissNum(), mlr.getCardId());
- if (student == null) {
- return CommonResult.fail("录取号或身份证错误,登录失败!");
- }
- if(StringUtils.hasText(student.getCardId())){
- if(StringUtils.hasText(student.getSex())){
- student.setSex(student.getSex());
- }else{
- String sex =StrUtils.getGender(student.getCardId());
- student.setSex(sex);
- }
- }
- //家庭成员
- List<FamilyVo> fvs = new ArrayList<>();
- List<WelcomeFamily> familys = welcomeFamilyService.getManageByCardId(student.getCardId());
- if (familys != null && familys.size() > 0) {
- for (WelcomeFamily wf : familys) {
- FamilyVo fv = new FamilyVo();
- fv.setId(wf.getId());
- fv.setFamilyShip(wf.getFamilyShip());
- fv.setName(wf.getName());
- fv.setPhone(wf.getPhone());
- fv.setWorkUnit(wf.getWorkUnit());
- fvs.add(fv);
- }
- }
- student.setFvs(fvs);
- //陪同人员
- List<AccompanyVo> avs = new ArrayList<>();
- List<WelcomeAccompany> accompanys = welcomeAccompanyService.getManageByCardId(student.getCardId());
- if (accompanys != null && accompanys.size() > 0) {
- for (WelcomeAccompany ac : accompanys) {
- AccompanyVo av = new AccompanyVo();
- av.setId(ac.getId());
- av.setName(ac.getName());
- av.setPhone(ac.getPhone());
- avs.add(av);
- }
- }
- student.setAvs(avs);
- //时间段
- List<ArriveTimeVo> atvs = new ArrayList<>();
- List<WelcomeArriveSetting> wass = welcomeArriveSettingService.queryCheckDatas();
- if (wass != null && wass.size() > 0) {
- for (WelcomeArriveSetting was : wass) {
- ArriveTimeVo atv = new ArriveTimeVo();
- atv.setId(was.getId());
- atv.setStartTime(was.getStartTime());
- atv.setEndTime(was.getEndTime());
- atv.setTimeStr(was.getStartTime() + "-" + was.getEndTime());
- atv.setIsCheck((student.getArriveTimeId() != null && was.getId().equals(student.getArriveTimeId())) ? 1 : 0);
- atvs.add(atv);
- }
- }
- student.setAtvs(atvs);
- //region 查询缴费
- if(!(student.getIsPay() != null && student.getIsPay().intValue() == 1)){//未缴费的情况下去查
- if(StringUtils.hasText(student.getAdmissNum()) && StringUtils.hasText(student.getSchool())){
- List<WelcomePaySetting> paySettings = welcomePaySettingService.queryPaySettings(student.getSchool());
- if(paySettings != null && paySettings.size() > 0){
- String year = TimeExchange.getYear();
- String payResult = HtPayUtils.getDataTwo(student.getAdmissNum(),year);
- if(StringUtils.hasText(payResult)){
- //缴费判定
- }else{
- student.setIsPay(0);
- }
- }else{
- student.setIsPay(0);
- }
- }
- }
- //endregion
- if(!(student.getIsPay() != null && student.getIsPay().intValue() == 1)){
- List<JsonPayVo> payInfos = WelcomePayController.queryStudentPayInfo(student.getAdmissNum(),TimeExchange.getYear());
- if(payInfos != null && payInfos.size() > 0){
- List<WelcomePaySetting> paySettings = welcomePaySettingService.queryPaySettings(student.getSchool());
- if(paySettings != null && paySettings.size() > 0){
- for (WelcomePaySetting pay:paySettings) {
- BigDecimal money = pay.getPayAmount();
- if(pay.getMethod().equals("全部")){
- BigDecimal totalSj = new BigDecimal(BigInteger.ZERO);
- for (JsonPayVo jpv:payInfos){
- totalSj = totalSj.add(jpv.getSJJE());
- }
- if(totalSj.compareTo(money) >= 0){
- student.setIsPay(1);
- }
- }
- Optional<JsonPayVo> ojpv = payInfos.stream().filter(e -> e.getSFXMMC().equals(pay.getMethod())).findFirst();
- if(ojpv != null && ojpv.isPresent()){
- if(ojpv.get().getSJJE().compareTo(money) >= 0){
- student.setIsPay(1);
- }
- }
- }
- }else{
- student.setIsPay(0);
- }
- }else{
- student.setIsPay(0);
- }
- }
- long expired = 1000 * 60 * 60 * 24 * 365;
- TokenDateVo token = JWTUtil.getToken(student.getCardId(), student.getId(), expired);
- student.setToken(token.getToken());
- return CommonResult.ok(student);
- }
- @Override
- @PassToken
- public CommonResult writeCarInfo() {
- com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
- String ukey = "6VMZEC5C6HZM7EO8";
- com.alibaba.fastjson.JSONObject datas = new com.alibaba.fastjson.JSONObject();
- datas.put("car_number", "赣A0AY39");
- datas.put("begin_time", "2025-06-16 10:00:00");
- datas.put("end_time", "2025-06-16 18:00:00");
- datas.put("mobile", "18279193722");
- // 生成带签名的字符串并使用MD5生成签名,然后转大写
- String sign = datas.toJSONString() + "key=" + ukey;
- sign = CreateSign1.MD5(sign).toUpperCase();
- json.put("service_name", "visitor_sync");
- json.put("sign", sign);
- json.put("park_id", "10033845");
- json.put("data", datas);
- String msg = HttpsClient.sendJson("http://istparking.sciseetech.com/public/visitor/do", json);
- return CommonResult.ok(msg);
- }
- @Override
- public CommonResult payResult(payResultRequest mlr) {
- logger.info("支付回调信息,mlr参数:" + JSON.toJSON(mlr));
- return CommonResult.ok();
- }
- }
|