diff --git a/pom.xml b/pom.xml
index 30fc772..6db9e18 100644
--- a/pom.xml
+++ b/pom.xml
@@ -91,6 +91,7 @@
commons-pool2
+
diff --git a/src/main/java/com/yzdx/AiInterviewer/comment/R.java b/src/main/java/com/yzdx/AiInterviewer/comment/R.java
new file mode 100644
index 0000000..504424a
--- /dev/null
+++ b/src/main/java/com/yzdx/AiInterviewer/comment/R.java
@@ -0,0 +1,35 @@
+package com.yzdx.AiInterviewer.comment;
+
+import lombok.Data;
+
+@Data
+public class R{
+ private Integer code;
+ private String message;
+ private Object data;
+
+
+ public static R success(T object){
+ R r= new R<>();
+ r.code=0;
+ r.data=object;
+ r.message="成功";
+ return r;
+ }
+ public static R error(String message){
+ R r=new R<>();
+
+ r.code=1;
+ r.message=message;
+ return r;
+ }
+ public static R error(Integer code,String message){
+ R r=new R<>();
+
+ r.code=code;
+ r.message=message;
+ return r;
+ }
+ public R() {
+ }
+}
diff --git a/src/main/java/com/yzdx/AiInterviewer/config/WebMvcConfig.java b/src/main/java/com/yzdx/AiInterviewer/config/WebMvcConfig.java
index 0f08f6f..c42a09e 100644
--- a/src/main/java/com/yzdx/AiInterviewer/config/WebMvcConfig.java
+++ b/src/main/java/com/yzdx/AiInterviewer/config/WebMvcConfig.java
@@ -19,7 +19,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
// 需要拦截的请求
.addPathPatterns("/**")
// 需要放行的请求
- .excludePathPatterns("/user/login","/user/register","/user/sendCode")
+ .excludePathPatterns("/admin/login")
// 添加swagger-ui的放行路径
.excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**","/doc.html/**")
;
diff --git a/src/main/java/com/yzdx/AiInterviewer/controller/HelloController.java b/src/main/java/com/yzdx/AiInterviewer/controller/HelloController.java
deleted file mode 100644
index c5b9b02..0000000
--- a/src/main/java/com/yzdx/AiInterviewer/controller/HelloController.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.yzdx.AiInterviewer.controller;
-
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import java.util.HashMap;
-import java.util.Map;
-
-@RestController
-@RequestMapping("/hello")
-public class HelloController {
-
- @GetMapping("/hello")
- public String hello(){
- return "hello";
- }
-
- @ApiOperation("用户登录")
- @PostMapping("/test")
- public Map testLogin(@ApiParam("用户名") String username ,@ApiParam("密码")String password){
-
-
- Map result=new HashMap<>();
-
- result.put("code",0);
- result.put("message","登陆成功");
- result.put("data","username:"+username+","+"password:"+password);
-
- return result;
-
- }
-}
diff --git a/src/main/java/com/yzdx/AiInterviewer/controller/UserController.java b/src/main/java/com/yzdx/AiInterviewer/controller/UserController.java
new file mode 100644
index 0000000..7208342
--- /dev/null
+++ b/src/main/java/com/yzdx/AiInterviewer/controller/UserController.java
@@ -0,0 +1,35 @@
+package com.yzdx.AiInterviewer.controller;
+
+import com.yzdx.AiInterviewer.comment.R;
+import com.yzdx.AiInterviewer.service.UserService;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Map;
+
+
+@RestController
+@RequestMapping("/admin")
+public class UserController {
+
+ @Autowired
+ private UserService userService;
+
+@PostMapping("/login")
+ public R adminLogin(@RequestBody @ApiParam("传入的值,phone,encoding,password") Map loginForm){
+ if(loginForm.size()==0){
+ return R.error("传来的数据有误,请检查输入");
+
+ }
+ String phone=(String)loginForm.get("phone");
+ String encoding=(String)loginForm.get("encoding");
+ String password=(String)loginForm.get("password");
+ return userService.adminLogin(phone, encoding, password);
+ }
+
+
+}
diff --git a/src/main/java/com/yzdx/AiInterviewer/entity/BaseEntity.java b/src/main/java/com/yzdx/AiInterviewer/entity/BaseEntity.java
new file mode 100644
index 0000000..176b748
--- /dev/null
+++ b/src/main/java/com/yzdx/AiInterviewer/entity/BaseEntity.java
@@ -0,0 +1,17 @@
+package com.yzdx.AiInterviewer.entity;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+@Data
+public class BaseEntity {
+ @ApiModelProperty("电子邮箱")
+ private Date createTime;
+ @ApiModelProperty("电子邮箱")
+ private Date updateTime;
+ @ApiModelProperty("电子邮箱")
+ private Integer createUser;
+ @ApiModelProperty("电子邮箱")
+ private Integer updateUser;
+}
diff --git a/src/main/java/com/yzdx/AiInterviewer/entity/Company.java b/src/main/java/com/yzdx/AiInterviewer/entity/Company.java
new file mode 100644
index 0000000..351f821
--- /dev/null
+++ b/src/main/java/com/yzdx/AiInterviewer/entity/Company.java
@@ -0,0 +1,45 @@
+package com.yzdx.AiInterviewer.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+@ApiModel("公司主体类")
+@TableName("company")
+public class Company extends BaseEntity{
+ @ApiModelProperty("公司id")
+ @TableId(type = IdType.AUTO)
+ private Integer id;
+ @ApiModelProperty("公司名称")
+ private String companyName;
+ @ApiModelProperty("公司全称")
+ @TableField(value = "company_allname")
+ private String companyAllName;
+ @ApiModelProperty("公司详情")
+ private String companyDetail;
+ @ApiModelProperty("公司类型")
+ private String type;
+ @ApiModelProperty("公司地址")
+ private String address;
+ @ApiModelProperty("公司待遇")
+ private String treatment;
+ @ApiModelProperty("法定代表人")
+ private String legalRepresentative;
+ @ApiModelProperty("注册资本")
+ private String registeredCapital;
+ @ApiModelProperty("成立日期")
+ private Date established;
+ @ApiModelProperty("统一信用编码")
+ private String creditCode;
+ @ApiModelProperty("公司图片")
+ private String images;
+ @ApiModelProperty("公司使用的登陆编码")
+ private String encoding;
+}
diff --git a/src/main/java/com/yzdx/AiInterviewer/entity/User.java b/src/main/java/com/yzdx/AiInterviewer/entity/User.java
index 83ef36f..9a2e06d 100644
--- a/src/main/java/com/yzdx/AiInterviewer/entity/User.java
+++ b/src/main/java/com/yzdx/AiInterviewer/entity/User.java
@@ -1,12 +1,35 @@
package com.yzdx.AiInterviewer.entity;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
@ApiModel("用户实体类")
-public class User {
+@Data
+@TableName("user")
+public class User extends BaseEntity{
+ @ApiModelProperty("用户id")
+ @TableId(type = IdType.AUTO)
+ private Integer id;
@ApiModelProperty("用户名")
- public String username;
+ private String username;
@ApiModelProperty("密码")
- public String password;
+ private String password;
+ @ApiModelProperty("盐值")
+ private String salt;
+ @ApiModelProperty("角色")
+ private String role;
+ @ApiModelProperty("手机号码")
+ private String phone;
+ @ApiModelProperty("性别")
+ private String sex;
+ @ApiModelProperty("年龄")
+ private String age;
+ @ApiModelProperty("头像地址")
+ private String avatar;
+ @ApiModelProperty("电子邮箱")
+ private String email;
}
diff --git a/src/main/java/com/yzdx/AiInterviewer/mapper/CompanyMapper.java b/src/main/java/com/yzdx/AiInterviewer/mapper/CompanyMapper.java
new file mode 100644
index 0000000..7ca5104
--- /dev/null
+++ b/src/main/java/com/yzdx/AiInterviewer/mapper/CompanyMapper.java
@@ -0,0 +1,9 @@
+package com.yzdx.AiInterviewer.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.yzdx.AiInterviewer.entity.Company;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface CompanyMapper extends BaseMapper {
+}
diff --git a/src/main/java/com/yzdx/AiInterviewer/mapper/UserMapper.java b/src/main/java/com/yzdx/AiInterviewer/mapper/UserMapper.java
new file mode 100644
index 0000000..8c6d5f6
--- /dev/null
+++ b/src/main/java/com/yzdx/AiInterviewer/mapper/UserMapper.java
@@ -0,0 +1,9 @@
+package com.yzdx.AiInterviewer.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.yzdx.AiInterviewer.entity.User;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface UserMapper extends BaseMapper {
+}
diff --git a/src/main/java/com/yzdx/AiInterviewer/service/UserService.java b/src/main/java/com/yzdx/AiInterviewer/service/UserService.java
new file mode 100644
index 0000000..aaf591a
--- /dev/null
+++ b/src/main/java/com/yzdx/AiInterviewer/service/UserService.java
@@ -0,0 +1,17 @@
+package com.yzdx.AiInterviewer.service;
+
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.yzdx.AiInterviewer.comment.R;
+import com.yzdx.AiInterviewer.entity.User;
+
+public interface UserService extends IService {
+
+ /** 管理员登录业务
+ * @param phone,encoding,password
+ * @return boolean,ture登陆成功,false:登陆失败
+ *
+ */
+
+ R adminLogin(String phone, String encoding, String password);
+}
diff --git a/src/main/java/com/yzdx/AiInterviewer/service/impl/UserServiceImpl.java b/src/main/java/com/yzdx/AiInterviewer/service/impl/UserServiceImpl.java
new file mode 100644
index 0000000..959a816
--- /dev/null
+++ b/src/main/java/com/yzdx/AiInterviewer/service/impl/UserServiceImpl.java
@@ -0,0 +1,76 @@
+package com.yzdx.AiInterviewer.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.yzdx.AiInterviewer.comment.R;
+import com.yzdx.AiInterviewer.entity.Company;
+import com.yzdx.AiInterviewer.entity.User;
+import com.yzdx.AiInterviewer.mapper.CompanyMapper;
+import com.yzdx.AiInterviewer.mapper.UserMapper;
+import com.yzdx.AiInterviewer.service.UserService;
+import com.yzdx.AiInterviewer.utiles.JWT;
+import com.yzdx.AiInterviewer.utiles.MD5Util;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@Service
+public class UserServiceImpl extends ServiceImpl implements UserService {
+
+ @Autowired
+ private UserMapper userMapper;
+
+ @Autowired
+ private CompanyMapper companyMapper;
+
+ @Override
+ public R adminLogin(String phone, String encoding, String password) {
+
+ LambdaQueryWrapper queryWrapper=new LambdaQueryWrapper();
+
+ queryWrapper.eq(User::getPhone,phone);
+
+ User user = userMapper.selectOne(queryWrapper);
+
+ //若查询用户为空
+ if(user==null){
+ return R.error("账号不存在,请检查输入");
+ }
+ if (user.getRole().equals("3") || user.getRole().equals("4")) {
+ return R.error("输入的账号或密码错误");
+ }
+ //查询的用户存在,检查密码是否正确
+ String salt=user.getSalt();
+
+ String findPassword=user.getPassword();
+
+ password= MD5Util.GetMD5Password(password,salt);
+
+ if(!findPassword.equals(password)){
+ return R.error("输入的账号或密码错误");
+ }
+
+ //密码和账户都输入正确,检查公司编码是否正确
+ LambdaQueryWrapper queryWrapper1=new LambdaQueryWrapper();
+
+ queryWrapper1.eq(Company::getEncoding,encoding);
+
+ Company findCompany= companyMapper.selectOne(queryWrapper1);
+
+ if(findCompany==null){
+
+ return R.error("输入的公司编码有误,请检查输入");
+ }
+
+ //均正确,返回token密钥
+ String token=JWT.getJWToken(user.getId());
+
+ Map data=new HashMap<>();
+
+ data.put("token",token);
+
+ return R.success(data);
+ }
+}
diff --git a/src/main/java/com/yzdx/AiInterviewer/utiles/JWT.java b/src/main/java/com/yzdx/AiInterviewer/utiles/JWT.java
index 56fff0b..434a154 100644
--- a/src/main/java/com/yzdx/AiInterviewer/utiles/JWT.java
+++ b/src/main/java/com/yzdx/AiInterviewer/utiles/JWT.java
@@ -35,7 +35,7 @@ public class JWT {
JWTCreator.Builder builder = com.auth0.jwt.JWT.create();
// 指定标识字段
- builder.withClaim("lawyerId", id);
+ builder.withClaim("userid", id);
// 指定过期时间
token = builder.withExpiresAt(instance.getTime())
@@ -63,6 +63,6 @@ public class JWT {
// 从token中获取用户id
public static int getTokenId(String token){
DecodedJWT verify = com.auth0.jwt.JWT.require(Algorithm.HMAC256(SING)).build().verify(token);
- return verify.getClaim("Id").asInt();
+ return verify.getClaim("userid").asInt();
}
}
\ No newline at end of file
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 6abe02c..c9bff98 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -3,9 +3,9 @@ server:
spring:
datasource:
- url: jdbc:mysql://localhost:3306/shop?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
+ url: jdbc:mysql://101.43.255.47:3306/ai_interviewer?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
username: root
- password: root
+ password: 2002811
jackson:
default-property-inclusion: non_null