From 8c6026959d3006bbf9dce3f3c9311e70a02b80c1 Mon Sep 17 00:00:00 2001 From: 935090232@qq.com <ak473600000> Date: Thu, 24 Feb 2022 23:29:18 +0800 Subject: [PATCH] Merge branch 'developer' --- zq-erp/src/main/java/com/matrix/system/app/action/ApiCommonAction.java | 122 +++++++++++++++++++++++++++++++++++++++- 1 files changed, 117 insertions(+), 5 deletions(-) diff --git a/zq-erp/src/main/java/com/matrix/system/app/action/ApiCommonAction.java b/zq-erp/src/main/java/com/matrix/system/app/action/ApiCommonAction.java index c94ee43..1e8fb3b 100644 --- a/zq-erp/src/main/java/com/matrix/system/app/action/ApiCommonAction.java +++ b/zq-erp/src/main/java/com/matrix/system/app/action/ApiCommonAction.java @@ -1,6 +1,8 @@ package com.matrix.system.app.action; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; +import com.matrix.component.tools.HttpCurlUtil; import com.matrix.core.pojo.AjaxResult; import com.matrix.core.tools.*; import com.matrix.system.app.authority.AppAuthorityManager; @@ -11,8 +13,11 @@ import com.matrix.system.common.authority.strategy.LoginStrategy; import com.matrix.system.common.bean.SysCompany; import com.matrix.system.common.bean.SysUsers; +import com.matrix.system.common.constance.AppConstance; import com.matrix.system.common.dao.BusParameterSettingsDao; import com.matrix.system.common.init.LocalCache; +import com.matrix.system.common.init.UserCacheManager; +import com.matrix.system.common.interceptor.HostInterceptor; import com.matrix.system.common.service.SysCompanyService; import com.matrix.system.common.service.SysUsersService; import com.matrix.system.common.tools.PasswordUtil; @@ -22,10 +27,12 @@ import com.matrix.system.hive.plugin.util.CollectionUtils; import com.matrix.system.hive.plugin.util.ImageUtil; import com.matrix.system.hive.service.SysShopInfoService; +import com.matrix.system.shopXcx.api.WeChatApiTools; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; +import net.sf.json.JSONObject; import org.apache.commons.fileupload.FileUploadException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -52,6 +59,9 @@ @RestController @RequestMapping(value = "/api/common") public class ApiCommonAction { + @Autowired + UploadUtil uploadUtil; + @Autowired private SysUsersService sysUsersService; @@ -66,8 +76,13 @@ private BusParameterSettingsDao busParameterSettingsDao; @Autowired - private SysCompanyService sysCompanyService; + private SysCompanyService sysCompanyService;; + @Autowired + WeChatApiTools weChatApiTools; + + @Autowired + private UserCacheManager userCacheManager; @Value("${file_storage_path}") private String fileStoragePath; @@ -157,11 +172,12 @@ EXT_LIST.add(FileType.PNG); } + @ApiOperation(value = "表单图片上传接口", notes = "表单图片上传接口") @PostMapping(value = "/uploadImg") public AjaxResult uploadImg(HttpServletResponse response, MultipartHttpServletRequest request) throws IOException, FileUploadException, NoSuchAlgorithmException { - Map<String, String> fileMap = UploadUtil.doUpload(request, EXT_LIST, folderType, 1L); + Map<String, String> fileMap = uploadUtil.doUpload(request, EXT_LIST, folderType, 1L); AjaxResult ajaxResult = AjaxResult.buildSuccessInstance("上传成功"); ajaxResult.putInMap("file", fileMap.get("visitPath")); return ajaxResult; @@ -269,14 +285,110 @@ } AjaxResult ajaxResult = new AjaxResult(); + ajaxResult.setStatus(AjaxResult.STATUS_SUCCESS); ajaxResult.putInMap("url", list.get(0).getComWebUrl()); return ajaxResult; } @ApiOperation(value = "管理端小程序登录") - @PostMapping(value = "/wxLogin") - public AjaxResult wxLogin(@RequestBody SettingDto codeDto) { - return null; + @PostMapping(value = "/wxLogin/{code}") + public AjaxResult wxLogin(@PathVariable("code") String code) throws IOException { + if (StrUtil.isBlank(code)) { + return AjaxResult.buildFailInstance("code不存在"); + } + AjaxResult res = new AjaxResult(); + String requrl = weChatApiTools.getManagerXcxLoginUrl(code); + + String resultData = HttpCurlUtil.sendGetHttp(requrl, null); + JSONObject json = JSONObject.fromObject(resultData); + LogUtil.debug("管理端小程序登录获取到登录信息={}", json); + + if (json.containsKey("errcode")) { + res.setStatus(AjaxResult.STATUS_FAIL); + res.setInfo("自动登录失败"); + LogUtil.info("微信登录获取到异常信息errcode"); + return res; + } + + String openId = json.getString("openid"); + res.setStatus(AjaxResult.STATUS_SUCCESS); + res.putInMap("openId", openId); + SysUsers hasBind = sysUsersService.findByOpenId(openId, HostInterceptor.getCompanyId()); + if (hasBind == null) { + res.setInfo("未绑定用户"); + return res; + } + + String token = userCacheManager.saveUserInfo(hasBind); + LogUtil.info("用户token={}", token); + + authorityManager.initUserPower(res, hasBind); + + UserInfoVo userInfoVo = new UserInfoVo(); + if(hasBind.getShopId()!=null){ + SysShopInfo shopInfo = sysShopInfoService.findById(hasBind.getShopId()); + hasBind.setShopName(shopInfo.getShopName()); + userInfoVo.setShopName(shopInfo.getShopShortName()); + } + + userInfoVo.setId(hasBind.getSuId()); + userInfoVo.setName(hasBind.getSuName()); + userInfoVo.setRoleName(hasBind.getRoleName()); + userInfoVo.setPhoto(hasBind.getSuPhoto()); + + res.putInMap("token", token); + res.putInMap("userInfo", userInfoVo); + return res; + } + + @ApiOperation(value = "绑定用户") + @PostMapping(value = "/bindUser") + public AjaxResult bindUser(@RequestBody @Validated LoginDto loginDto) { + SysUsers user = new SysUsers(); + user.setSuAccount(loginDto.getUsername()); + user.setSuPassword(loginDto.getPassword()); + LoginStrategy apLogin = new AccountPasswordLogin(user, sysUsersService); + user = authorityManager.login(apLogin); + user.setSuPassword(null); + user.setOpenIds(null); + String token = userCacheManager.saveUserInfo(user); + + AjaxResult result = AjaxResult.buildSuccessInstance("登陆成功"); + authorityManager.initUserPower(result, user); + + UserInfoVo userInfoVo = new UserInfoVo(); + if(user.getShopId()!=null){ + SysShopInfo shopInfo = sysShopInfoService.findById(user.getShopId()); + user.setShopName(shopInfo.getShopName()); + userInfoVo.setShopName(shopInfo.getShopShortName()); + } + + userInfoVo.setId(user.getSuId()); + userInfoVo.setName(user.getSuName()); + userInfoVo.setRoleName(user.getRoleName()); + userInfoVo.setPhoto(user.getSuPhoto()); + + result.putInMap("token", token); + result.putInMap("userInfo", userInfoVo); + + synchronized (this) { + SysUsers hasBind = sysUsersService.findByOpenId(loginDto.getOpenId(), HostInterceptor.getCompanyId()); + if (hasBind != null) { + if(StrUtil.isNotBlank(hasBind.getOpenIds())) { + List<String> openIds = StrUtil.split(hasBind.getOpenIds(), ','); + openIds.remove(loginDto.getOpenId()); + + sysUsersService.modifyUserOpenId(CollUtil.join(openIds, ","), hasBind.getSuId()); + } + } + + List<String> openIds = StrUtil.split(user.getOpenIds(), ','); + openIds.add(loginDto.getOpenId()); + user.setOpenIds(CollUtil.join(openIds, ",")); + sysUsersService.modifyByModel(user); + } + + return result; } } -- Gitblit v1.9.1