Merge remote-tracking branch 'origin/master'
# Conflicts:
# ruoyi-modules/ruoyi-company/pom.xml
# ruoyi-modules/ruoyi-company/src/main/java/com/ruoyi/company/service/impl/CompanyServiceImpl.java
New file |
| | |
| | | { |
| | | "headers": { |
| | | "access-control-allow-origin": "*", |
| | | "date": "Tue, 21 Jan 2025 07:22:51 GMT", |
| | | "keep-alive": "timeout=25", |
| | | "transfer-encoding": "chunked", |
| | | "vary": "Accept-Encoding", |
| | | "x-acs-request-id": "4545720F-58C2-579E-A1CE-08FDDFDF3296", |
| | | "connection": "keep-alive", |
| | | "content-type": "application/json;charset=utf-8", |
| | | "access-control-expose-headers": "*", |
| | | "x-acs-trace-id": "2a95d25064c13621b98f3883185aadc1" |
| | | }, |
| | | "body": { |
| | | "RequestId": "4545720F-58C2-579E-A1CE-08FDDFDF3296", |
| | | "Data": { |
| | | "SubImages": [ |
| | | { |
| | | "FigureInfo": { |
| | | "face": { |
| | | "FigureCount": 1, |
| | | "FigureDetails": [ |
| | | { |
| | | "FigurePoints": [ |
| | | { |
| | | "X": 672, |
| | | "Y": 289 |
| | | }, |
| | | { |
| | | "X": 949, |
| | | "Y": 288 |
| | | }, |
| | | { |
| | | "X": 950, |
| | | "Y": 624 |
| | | }, |
| | | { |
| | | "X": 672, |
| | | "Y": 624 |
| | | } |
| | | ], |
| | | "FigureAngle": 0 |
| | | } |
| | | ] |
| | | } |
| | | }, |
| | | "SubImageId": 0, |
| | | "KvInfo": { |
| | | "KvCount": 6, |
| | | "Data": { |
| | | "address": "黑龙江省宁安市渤海镇玄武大街35号", |
| | | "ethnicity": "汉", |
| | | "sex": "女", |
| | | "name": "陆佳欣", |
| | | "idNumber": "231084200002060822", |
| | | "birthDate": "2000年2月6日" |
| | | }, |
| | | "KvDetails": { |
| | | "address": { |
| | | "KeyName": "address", |
| | | "ValueAngle": 1, |
| | | "Value": "黑龙江省宁安市渤海镇玄武大街35号", |
| | | "KeyConfidence": 100, |
| | | "ValueConfidence": 100 |
| | | }, |
| | | "ethnicity": { |
| | | "KeyName": "ethnicity", |
| | | "ValueAngle": 0, |
| | | "Value": "汉", |
| | | "KeyConfidence": 100, |
| | | "ValueConfidence": 100 |
| | | }, |
| | | "sex": { |
| | | "KeyName": "sex", |
| | | "ValueAngle": 0, |
| | | "Value": "女", |
| | | "KeyConfidence": 100, |
| | | "ValueConfidence": 100 |
| | | }, |
| | | "name": { |
| | | "KeyName": "name", |
| | | "ValueAngle": 0, |
| | | "Value": "陆佳欣", |
| | | "KeyConfidence": 100, |
| | | "ValueConfidence": 100 |
| | | }, |
| | | "idNumber": { |
| | | "KeyName": "idNumber", |
| | | "ValueAngle": 1, |
| | | "Value": "231084200002060822", |
| | | "KeyConfidence": 100, |
| | | "ValueConfidence": 100 |
| | | }, |
| | | "birthDate": { |
| | | "KeyName": "birthDate", |
| | | "ValueAngle": 0, |
| | | "Value": "2000年2月6日", |
| | | "KeyConfidence": 100, |
| | | "ValueConfidence": 100 |
| | | } |
| | | } |
| | | }, |
| | | "QualityInfo": { |
| | | "IsCopy": false |
| | | }, |
| | | "Type": "身份证正面", |
| | | "Angle": 0 |
| | | } |
| | | ], |
| | | "Height": 852, |
| | | "SubImageCount": 1, |
| | | "Width": 1136 |
| | | } |
| | | }, |
| | | "statusCode": 200 |
| | | } |
| | |
| | | <artifactId>ocr_api20210707</artifactId> |
| | | <version>3.1.2</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.aliyun</groupId> |
| | | <artifactId>darabonba-stream</artifactId> |
| | | <version>0.0.1</version> |
| | | </dependency> |
| | | <!--aliyun-oss--> |
| | | <dependency> |
| | | <groupId>com.aliyun.oss</groupId> |
| | |
| | | import com.ruoyi.common.core.constant.ServiceNameConstants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.company.api.domain.User; |
| | | import com.ruoyi.company.api.domain.dto.MgtCompanyDTO; |
| | | import com.ruoyi.company.api.factory.RemoteCompanyUserServiceFallbackFactory; |
| | | import com.ruoyi.company.api.model.RegisterUser; |
| | | import org.springframework.cloud.openfeign.FeignClient; |
| | |
| | | @FeignClient(contextId = "remoteCompanyUserService", value = ServiceNameConstants.COMPANY_SERVICE, fallbackFactory = RemoteCompanyUserServiceFallbackFactory.class) |
| | | public interface RemoteCompanyUserService { |
| | | @PostMapping("/front/user/register") |
| | | R<Boolean> registerUser(@RequestBody RegisterUser registerUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); |
| | | R<Boolean> registerUser(@RequestBody MgtCompanyDTO registerUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); |
| | | |
| | | @GetMapping("/front/user/getUserByAccountName") |
| | | R<User> getUserByAccountName(@RequestParam("accountName") String accountName, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); |
| | |
| | | /** 手机号 */ |
| | | private String phone; |
| | | |
| | | /** 头像 */ |
| | | private String avatar; |
| | | |
| | | /** 状态:1-激活 2-禁用 */ |
| | | private Integer status; |
| | | |
| | |
| | | private String phone; |
| | | |
| | | @Schema(description = "登录密码") |
| | | @NotBlank(message = "登录密码不能为空") |
| | | private String password; |
| | | |
| | | private String smsCode; |
| | | |
| | | } |
| | |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.company.api.RemoteCompanyUserService; |
| | | import com.ruoyi.company.api.domain.User; |
| | | import com.ruoyi.company.api.domain.dto.MgtCompanyDTO; |
| | | import com.ruoyi.company.api.model.RegisterUser; |
| | | import lombok.extern.log4j.Log4j2; |
| | | import org.springframework.cloud.openfeign.FallbackFactory; |
| | |
| | | return new RemoteCompanyUserService() { |
| | | |
| | | @Override |
| | | public R<Boolean> registerUser(RegisterUser registerUser, String source) { |
| | | public R<Boolean> registerUser(MgtCompanyDTO registerUser, String source) { |
| | | return R.fail("用户注册失败:"+cause.getMessage()); |
| | | } |
| | | |
New file |
| | |
| | | package com.ruoyi.company.api.model; |
| | | |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class UpdatePassword { |
| | | private String oldPassword; |
| | | private String newPassword; |
| | | private String confirmPassword; |
| | | } |
New file |
| | |
| | | package com.ruoyi.company.api.model; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | @Schema(name = "修改手机号参数") |
| | | public class UpdatePhone { |
| | | |
| | | @Schema(description = "旧手机号", example = "13800138000") |
| | | private String oldPhone; |
| | | |
| | | @Schema(description = "新手机号", example = "13800138000") |
| | | private String newPhone; |
| | | |
| | | @Schema(description = "验证码", example = "123456") |
| | | private String code; |
| | | |
| | | @Schema(description = "登录密码", example = "123456") |
| | | private String password; |
| | | } |
| | |
| | | @Schema(description = "用户名称") |
| | | private String userName; |
| | | |
| | | /** 头像 */ |
| | | @Schema(description = "头像") |
| | | private String avatar; |
| | | |
| | | /** 注册时间 */ |
| | | @Schema(description = "注册时间") |
| | | private LocalDateTime registerTime; |
| | |
| | | public R<SysUser> getUserById(Long userId, String source) { |
| | | return R.fail("获取用户信息失败:" + throwable.getMessage()); |
| | | } |
| | | |
| | | @Override |
| | | public R<?> updateUser(SysUser sysUser, String source) { |
| | | return R.fail("更新用户信息"); |
| | | } |
| | | }; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ruoyi.system.api.model; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | | import java.time.LocalDate; |
| | | |
| | | @Data |
| | | @Schema(description = "身份证信息") |
| | | public class IdCard { |
| | | @Schema(description = "姓名") |
| | | private String name; |
| | | |
| | | @Schema(description = "性别") |
| | | private String sex; |
| | | |
| | | @Schema(description = "身份证号码") |
| | | private String idNumber; |
| | | |
| | | @Schema(description = "出生日期") |
| | | private LocalDate birthDate; |
| | | |
| | | @Schema(description = "民族") |
| | | private String ethnicity; |
| | | |
| | | @Schema(description = "地址") |
| | | private String address; |
| | | } |
| | |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.company.api.RemoteCompanyUserService; |
| | | import com.ruoyi.company.api.domain.User; |
| | | import com.ruoyi.company.api.domain.dto.MgtCompanyDTO; |
| | | import com.ruoyi.company.api.model.RegisterUser; |
| | | import com.ruoyi.system.api.model.AppUser; |
| | | import com.ruoyi.system.api.model.LoginUser; |
| | |
| | | |
| | | @PostMapping("companyRegister") |
| | | @Operation(summary = "用户注册接口",description = "用户注册接口") |
| | | public R<?> companyRegister(@RequestBody RegisterUser registerUser) |
| | | public R<?> companyRegister(@RequestBody MgtCompanyDTO registerUser) |
| | | { |
| | | // 用户注册 |
| | | sysLoginService.companyRegister(registerUser); |
| | |
| | | import com.ruoyi.company.api.RemoteCompanyUserService; |
| | | import com.ruoyi.company.api.domain.Company; |
| | | import com.ruoyi.company.api.domain.User; |
| | | import com.ruoyi.company.api.domain.dto.MgtCompanyDTO; |
| | | import com.ruoyi.company.api.model.RegisterUser; |
| | | import com.ruoyi.system.api.RemoteUserService; |
| | | import com.ruoyi.system.api.domain.SysUser; |
| | |
| | | recordLogService.recordLogininfor(username, Constants.REGISTER, "注册成功"); |
| | | } |
| | | |
| | | public void companyRegister(RegisterUser registerUser) { |
| | | public void companyRegister(MgtCompanyDTO registerUser) { |
| | | String accountName = registerUser.getAccountName(); |
| | | String password = registerUser.getPassword(); |
| | | // 用户名或密码为空 错误 |
| | |
| | | if (r.getData() == null) { |
| | | throw new ServiceException("账号不存在"); |
| | | } |
| | | if (!SecurityUtils.matchesPassword(password, r.getData().getPassword())) { |
| | | if (!SecurityUtils.matchesPassword(r.getData().getPassword(), password)) { |
| | | throw new ServiceException("密码错误"); |
| | | } |
| | | return r.getData(); |
| | |
| | | <groupId>org.projectlombok</groupId> |
| | | <artifactId>lombok</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.aliyun</groupId> |
| | | <artifactId>ocr_api20210707</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.aliyun</groupId> |
| | | <artifactId>darabonba-stream</artifactId> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | </project> |
New file |
| | |
| | | package com.ruoyi.common.core.utils; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | |
| | | public class UrlDownloader { |
| | | |
| | | /** |
| | | * 将指定的URL内容下载为输入流 |
| | | * |
| | | * @param urlString 要下载的URL |
| | | * @return 包含URL内容的输入流 |
| | | * @throws IOException 如果发生I/O错误 |
| | | */ |
| | | public static InputStream downloadAsStream(String urlString) throws IOException { |
| | | URL url = new URL(urlString); |
| | | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); |
| | | connection.setRequestMethod("GET"); |
| | | connection.connect(); |
| | | |
| | | // 检查HTTP响应码 |
| | | int responseCode = connection.getResponseCode(); |
| | | if (responseCode != HttpURLConnection.HTTP_OK) { |
| | | throw new IOException("HTTP response code: " + responseCode); |
| | | } |
| | | |
| | | return connection.getInputStream(); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String urlString = "https://example.com/file.txt"; // 替换为你要下载的URL |
| | | |
| | | try (InputStream inputStream = downloadAsStream(urlString)) { |
| | | // 这里你可以处理输入流,例如将其写入文件或进行其他操作 |
| | | byte[] buffer = new byte[1024]; |
| | | int bytesRead; |
| | | while ((bytesRead = inputStream.read(buffer)) != -1) { |
| | | // 处理读取的数据,例如写入文件或打印到控制台 |
| | | System.out.write(buffer, 0, bytesRead); |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ruoyi.common.core.utils.orc; |
| | | |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.aliyun.ocr_api20210707.models.RecognizeAllTextRequest; |
| | | import com.aliyun.ocr_api20210707.models.RecognizeAllTextResponse; |
| | | import com.aliyun.tea.TeaException; |
| | | import com.aliyun.tea.TeaModel; |
| | | import com.aliyun.teautil.Common; |
| | | import com.aliyun.teautil.models.RuntimeOptions; |
| | | import com.ruoyi.common.core.utils.UrlDownloader; |
| | | |
| | | import java.io.InputStream; |
| | | import java.util.Map; |
| | | |
| | | public class OcrUtils { |
| | | |
| | | /** |
| | | * <b>description</b> : |
| | | * <p>使用AK&SK初始化账号Client</p> |
| | | * |
| | | * @return Client |
| | | * @throws Exception |
| | | */ |
| | | public static com.aliyun.ocr_api20210707.Client createClient() throws Exception { |
| | | // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。 |
| | | // 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html。 |
| | | com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config() |
| | | // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。 |
| | | .setAccessKeyId("LTAI5tFSeci96NRF6p6UN69G") |
| | | // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。 |
| | | .setAccessKeySecret("25t5zmWkueoQd81Zka70uPKRPgaMiV"); |
| | | // Endpoint 请参考 https://api.aliyun.com/product/ocr-api |
| | | config.endpoint = "ocr-api.cn-hangzhou.aliyuncs.com"; |
| | | return new com.aliyun.ocr_api20210707.Client(config); |
| | | } |
| | | |
| | | /** |
| | | * 证件识别 |
| | | */ |
| | | public static JSONObject idCard(InputStream bodyStream) throws Exception { |
| | | com.aliyun.ocr_api20210707.Client client = createClient(); |
| | | // 需要安装额外的依赖库,直接点击下载完整工程即可看到所有依赖。 |
| | | RecognizeAllTextRequest recognizeAllTextRequest = new RecognizeAllTextRequest() |
| | | .setBody(bodyStream) |
| | | .setType("IdCard") |
| | | .setOutputFigure(true); |
| | | RuntimeOptions runtime = new RuntimeOptions(); |
| | | try { |
| | | // 复制代码运行请自行打印 API 的返回值 |
| | | RecognizeAllTextResponse recognizeAllTextResponse = client.recognizeAllTextWithOptions(recognizeAllTextRequest, runtime); |
| | | String jsonString = Common.toJSONString(TeaModel.buildMap(recognizeAllTextResponse)); |
| | | JSONObject jsonObject = JSONObject.parseObject(jsonString); |
| | | Integer statusCode = jsonObject.getInteger("statusCode"); |
| | | if (statusCode != 200) { |
| | | throw new RuntimeException("识别失败"); |
| | | } |
| | | JSONObject body = jsonObject.getJSONObject("body"); |
| | | JSONObject data = body.getJSONObject("Data"); |
| | | JSONArray subImages = body.getJSONArray("SubImages"); |
| | | if (subImages != null && !subImages.isEmpty()){ |
| | | JSONObject subImage = subImages.getJSONObject(0); |
| | | JSONObject kvInfo = subImage.getJSONObject("KvInfo"); |
| | | return kvInfo.getJSONObject("Data"); |
| | | } |
| | | return null; |
| | | } catch (TeaException error) { |
| | | // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。 |
| | | // 错误 message |
| | | System.out.println(error.getMessage()); |
| | | // 诊断地址 |
| | | System.out.println(error.getData().get("Recommend")); |
| | | com.aliyun.teautil.Common.assertAsString(error.message); |
| | | } catch (Exception _error) { |
| | | TeaException error = new TeaException(_error.getMessage(), _error); |
| | | // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。 |
| | | // 错误 message |
| | | System.out.println(error.getMessage()); |
| | | // 诊断地址 |
| | | System.out.println(error.getData().get("Recommend")); |
| | | com.aliyun.teautil.Common.assertAsString(error.message); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | try { |
| | | InputStream inputStream = UrlDownloader.downloadAsStream("https://ai.bdstatic.com/file/3C8C5B451BB4445697730217EC8648E3"); |
| | | idCard(inputStream); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); |
| | | return passwordEncoder.matches(rawPassword, encodedPassword); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String password1 = "$2a$10$qB8arbbFx4mevJzCOoChhebLS/ULjY7BCBNMNk9CoSJHAUM/Ixr2K"; |
| | | for (int i = 0; i < 5; i++) { |
| | | String password = encryptPassword("123"); |
| | | System.out.println(matchesPassword("123",password1)); |
| | | } |
| | | } |
| | | } |
| | |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | |
| | | .eq(Company::getUserId, userId)); |
| | | return R.ok(company); |
| | | } |
| | | |
| | | /** |
| | | * 修改企业信息 |
| | | */ |
| | | @Operation(summary = "修改企业信息", tags = {"企业端"}) |
| | | @PutMapping("/updateCompany") |
| | | public R<Void> updateCompany(Company company){ |
| | | Long userId = SecurityUtils.getAppLoginUser().getUserId(); |
| | | Company companyDb = companyService.getOne(new LambdaQueryWrapper<Company>() |
| | | .eq(Company::getUserId, userId)); |
| | | company.setId(companyDb.getId()); |
| | | companyService.updateById(company); |
| | | return R.ok(); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ruoyi.company.controller.front; |
| | | |
| | | import com.aliyun.ocr_api20210707.models.RecognizeAllTextResponse; |
| | | import com.aliyun.tea.*; |
| | | |
| | | public class Sample { |
| | | |
| | | |
| | | |
| | | public static void main(String[] args_) throws Exception { |
| | | |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.company.controller.front; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.common.core.constant.CacheConstants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.exception.CaptchaException; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.common.security.annotation.InnerAuth; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.company.api.domain.Company; |
| | | import com.ruoyi.company.api.domain.User; |
| | | import com.ruoyi.company.api.domain.dto.MgtCompanyDTO; |
| | | import com.ruoyi.company.api.model.RegisterUser; |
| | | import com.ruoyi.company.api.model.UpdatePassword; |
| | | import com.ruoyi.company.api.model.UpdatePhone; |
| | | import com.ruoyi.company.api.model.UserDetail; |
| | | import com.ruoyi.company.service.CompanyService; |
| | | import com.ruoyi.company.service.UserService; |
| | |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.experimental.StandardException; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | public class UserController { |
| | | private final UserService userService; |
| | | private final CompanyService companyService; |
| | | private final RedisService redisService; |
| | | |
| | | @PostMapping("/register") |
| | | public R register(@RequestBody MgtCompanyDTO mgtCompanyDTO) { |
| | |
| | | public R<UserDetail> getUserDetail() { |
| | | AppUser appLoginUser = SecurityUtils.getAppLoginUser(); |
| | | User user = userService.getById(appLoginUser.getUserId()); |
| | | Company company = companyService.getOne(new LambdaQueryWrapper<Company>() |
| | | .eq(Company::getUserId, user.getUserId())); |
| | | UserDetail userDetail = new UserDetail(); |
| | | BeanUtils.copyProperties(user, userDetail); |
| | | BeanUtils.copyProperties(company, userDetail); |
| | | return R.ok(userDetail); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @PutMapping("/updateUser") |
| | | @InnerAuth |
| | | public R<Void> updateUser(@RequestBody User user){ |
| | | user.setUpdateTime(LocalDateTime.now()); |
| | | userService.updateById(user); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 编辑联系人信息 |
| | | */ |
| | | @PutMapping("/updateUserDetail") |
| | | @Operation(summary = "编辑联系人信息",tags = {"企业端"}) |
| | | public R<Void> updateUserDetail(@RequestBody UserDetail userDetail) { |
| | | User user = userService.getById(userDetail.getUserId()); |
| | | BeanUtils.copyProperties(userDetail, user); |
| | | userService.updateById(user); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 修改手机号 |
| | | */ |
| | | @PutMapping("/updatePhone") |
| | | @Operation(summary = "修改手机号",tags = {"企业端"}) |
| | | public R<Void> updatePhone(@RequestBody UpdatePhone updatePhone) { |
| | | AppUser appLoginUser = SecurityUtils.getAppLoginUser(); |
| | | User user = userService.getById(appLoginUser.getUserId()); |
| | | if (!user.getPhone().equals(updatePhone.getOldPhone())) { |
| | | return R.fail("旧手机号错误"); |
| | | } |
| | | String verifyKey = CacheConstants.PHONE_CODE_KEY + StringUtils.nvl(user.getPhone(), ""); |
| | | String captcha = redisService.getCacheObject(verifyKey); |
| | | if (captcha == null) { |
| | | throw new CaptchaException("验证码已失效"); |
| | | } |
| | | redisService.deleteObject(verifyKey); |
| | | if (!updatePhone.getCode().equalsIgnoreCase(captcha)) { |
| | | throw new CaptchaException("验证码错误"); |
| | | } |
| | | |
| | | String password = SecurityUtils.encryptPassword(updatePhone.getPassword()); |
| | | if (!user.getPassword().equals(password)) { |
| | | return R.fail("密码错误"); |
| | | } |
| | | user.setPhone(updatePhone.getNewPhone()); |
| | | userService.updateById(user); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 修改密码 |
| | | */ |
| | | @PutMapping("/updatePassword") |
| | | @Operation(summary = "修改密码",tags = {"企业端"}) |
| | | public R<Void> updatePassword(@RequestBody UpdatePassword updatePassword) { |
| | | AppUser appLoginUser = SecurityUtils.getAppLoginUser(); |
| | | User user = userService.getById(appLoginUser.getUserId()); |
| | | if (!SecurityUtils.matchesPassword(updatePassword.getOldPassword(), user.getPassword())) { |
| | | return R.fail("旧密码错误"); |
| | | } |
| | | if (!updatePassword.getNewPassword().equals(updatePassword.getConfirmPassword())){ |
| | | return R.fail("两次密码不一致"); |
| | | } |
| | | user.setPassword(SecurityUtils.encryptPassword(updatePassword.getNewPassword())); |
| | | userService.updateById(user); |
| | | return R.ok(); |
| | | } |
| | | } |
| | |
| | | public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> implements CompanyService { |
| | | private final UserService userService; |
| | | private final HttpServletResponse response; |
| | | |
| | | private final AliyunCloudAuthUtil aliyunCloudAuthUtil; |
| | | /** |
| | | * 获取企业列表 |
| | | * |
| | | * @param query |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 获取企业详情 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 新增企业 |
| | | * |
| | | * @param dto |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 编辑企业 |
| | | * |
| | | * @param dto |
| | | */ |
| | | @Override |
| | | public void editCompany(MgtCompanyDTO dto) { |
| | | if (Objects.isNull(dto.getId())){ |
| | | if (Objects.isNull(dto.getId())) { |
| | | throw new ServiceException("企业id不能为空"); |
| | | } |
| | | //查询企业 |
| | |
| | | } |
| | | //用户信息 |
| | | User userUpd = BeanUtils.copyBean(dto, User.class); |
| | | userUpd.setPassword(SecurityUtils.encryptPassword(dto.getPassword())); |
| | | if (StringUtils.isNotBlank(dto.getPassword())) { |
| | | userUpd.setPassword(SecurityUtils.encryptPassword(dto.getPassword())); |
| | | } |
| | | userUpd.setUserId(user.getUserId()); |
| | | userUpd.setUpdateBy(SecurityUtils.getUserId()); |
| | | userService.updateById(userUpd); |
| | | //根据公司名称查询数据库 |
| | | Long count = this.lambdaQuery().ne(Company::getId,dto.getId()).eq(Company::getCompanyName, company.getCompanyName()).count(); |
| | | Long count = this.lambdaQuery().ne(Company::getId, dto.getId()).eq(Company::getCompanyName, company.getCompanyName()).count(); |
| | | if (count > 0) { |
| | | throw new ServiceException("该公司账号已存在"); |
| | | } |
| | |
| | | |
| | | /** |
| | | * 删除企业 |
| | | * |
| | | * @param id |
| | | */ |
| | | @Override |
| | |
| | | throw new ServiceException("删除失败,该企业不存在"); |
| | | } |
| | | //删除企业账号 |
| | | userService.removeById(company.getUserId()); |
| | | userService.removeById(company.getUserId()); |
| | | |
| | | //删除企业信息 |
| | | this.removeById(id); |
New file |
| | |
| | | package com.ruoyi.system.controller; |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.UrlDownloader; |
| | | import com.ruoyi.common.core.utils.orc.OcrUtils; |
| | | import com.ruoyi.system.api.model.IdCard; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.io.InputStream; |
| | | |
| | | @RestController |
| | | @RequestMapping("/common") |
| | | public class CommonController { |
| | | |
| | | /** |
| | | * ocr提取身份证信息 |
| | | */ |
| | | @GetMapping("/idCard") |
| | | public R<IdCard> idCard(@Parameter(name = "url", description = "图片地址") String url) { |
| | | InputStream inputStream; |
| | | try { |
| | | inputStream = UrlDownloader.downloadAsStream(url); |
| | | JSONObject jsonObject = OcrUtils.idCard(inputStream); |
| | | IdCard idCard = JSONObject.parseObject(jsonObject.toJSONString(), IdCard.class); |
| | | return R.ok(idCard); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | } |