Showing
7 changed files
with
335 additions
and
1 deletions
@@ -9,7 +9,11 @@ public enum ResultStatus { | @@ -9,7 +9,11 @@ public enum ResultStatus { | ||
9 | USER_NOT_FOUND(-1002, "用户不存在"), | 9 | USER_NOT_FOUND(-1002, "用户不存在"), |
10 | USER_NOT_LOGIN(-1004, "用户未登录"), | 10 | USER_NOT_LOGIN(-1004, "用户未登录"), |
11 | USER_IS_EXIT(-1005, "用户已注册"), | 11 | USER_IS_EXIT(-1005, "用户已注册"), |
12 | - USER_LOGOUT(101,"修改密码成功,退出登录"); | 12 | + |
13 | + USER_LOGOUT(101,"修改密码成功,退出登录"), | ||
14 | + | ||
15 | + // 111开头的都是与amp报告上传软件相关的 | ||
16 | + AMP_KEY_ERROR(-11100, "AMP密钥不匹配"); | ||
13 | 17 | ||
14 | /** | 18 | /** |
15 | * 返回码 | 19 | * 返回码 |
1 | +package com.xkl.controller.uploadsoft; | ||
2 | + | ||
3 | +import com.wordnik.swagger.annotations.ApiImplicitParam; | ||
4 | +import com.wordnik.swagger.annotations.ApiImplicitParams; | ||
5 | +import com.wordnik.swagger.annotations.ApiOperation; | ||
6 | +import com.xkl.authorization.annotation.Authorization; | ||
7 | +import com.xkl.authorization.annotation.CurrentUser; | ||
8 | +import com.xkl.authorization.manager.ITokenManager; | ||
9 | +import com.xkl.authorization.model.TokenModel; | ||
10 | +import com.xkl.config.ResultStatus; | ||
11 | +import com.xkl.domain.AMPMachine; | ||
12 | +import com.xkl.domain.Admin; | ||
13 | +import com.xkl.model.ResultModel; | ||
14 | +import com.xkl.repository.AMPMachineRepository; | ||
15 | +import com.xkl.repository.AdminRepository; | ||
16 | +import org.springframework.beans.factory.annotation.Autowired; | ||
17 | +import org.springframework.http.HttpStatus; | ||
18 | +import org.springframework.http.ResponseEntity; | ||
19 | +import org.springframework.util.Assert; | ||
20 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
21 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
22 | +import org.springframework.web.bind.annotation.RequestParam; | ||
23 | +import org.springframework.web.bind.annotation.RestController; | ||
24 | + | ||
25 | +/** | ||
26 | + * AMP报告上传软件客户端登录及退出接口。 | ||
27 | + * 获取和删除token的请求地址,在Restful设计中其实就对应着登录和退出登录的资源映射 | ||
28 | + */ | ||
29 | +@RestController | ||
30 | +@RequestMapping("/uploadsoftwareaccount") | ||
31 | +public class UploadSoftwareAccountController { | ||
32 | + | ||
33 | + @Autowired | ||
34 | + private AdminRepository adminRepository; | ||
35 | + @Autowired | ||
36 | + private AMPMachineRepository ampMachineRepository; | ||
37 | + @Autowired | ||
38 | + private ITokenManager tokenManager; | ||
39 | + | ||
40 | + @RequestMapping(method = RequestMethod.POST) | ||
41 | + @ApiOperation(value = "报告上传软件登录") | ||
42 | + public ResponseEntity<ResultModel> login(@RequestParam String account, @RequestParam String password | ||
43 | + , @RequestParam String ampserial, @RequestParam String ampkey) { | ||
44 | + Assert.notNull(account, "account can not be empty"); | ||
45 | + Assert.notNull(password, "password can not be empty"); | ||
46 | + Assert.notNull(ampserial, "ampserial can not be empty"); | ||
47 | + Assert.notNull(ampkey, "ampkey can not be empty"); | ||
48 | + | ||
49 | + AMPMachine ampMachine = ampMachineRepository.findBySecretKey(ampkey.trim()); | ||
50 | + if (ampMachine == null ||// 未找到密钥所对应的机器 | ||
51 | + !ampMachine.getAMPSerial().equals(ampserial)) { | ||
52 | + return new ResponseEntity<>(ResultModel.error(ResultStatus.AMP_KEY_ERROR), HttpStatus.NOT_FOUND); | ||
53 | + | ||
54 | + } | ||
55 | + | ||
56 | + Admin admin = adminRepository.findByAccount(account); | ||
57 | + if (admin == null || //未注册 | ||
58 | + !admin.getPwd().equals(password)) { //密码错误 | ||
59 | + //提示用户名或密码错误 | ||
60 | + return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.NOT_FOUND); | ||
61 | + } | ||
62 | + | ||
63 | + //生成一个token,保存用户登录状态 | ||
64 | + TokenModel model = tokenManager.createToken(admin.getId()); | ||
65 | + return new ResponseEntity<>(ResultModel.ok(model), HttpStatus.OK); | ||
66 | + } | ||
67 | + | ||
68 | + @RequestMapping(method = RequestMethod.DELETE) | ||
69 | + @Authorization | ||
70 | + @ApiOperation(value = "退出登录") | ||
71 | + @ApiImplicitParams({ | ||
72 | + @ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"), | ||
73 | + }) | ||
74 | + public ResponseEntity<ResultModel> logout(@CurrentUser Admin admin) { | ||
75 | + tokenManager.deleteToken(admin.getId()); | ||
76 | + return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK); | ||
77 | + } | ||
78 | + | ||
79 | +} |
src/main/java/com/xkl/domain/AMPMachine.java
0 → 100644
1 | +package com.xkl.domain; | ||
2 | + | ||
3 | +import javax.persistence.Column; | ||
4 | +import javax.persistence.Entity; | ||
5 | +import javax.persistence.Id; | ||
6 | +import javax.persistence.Table; | ||
7 | +import java.sql.Timestamp; | ||
8 | + | ||
9 | +/** | ||
10 | + * 用户数据的domain类 | ||
11 | + */ | ||
12 | +@Entity | ||
13 | +@Table(name = "xkl_amp_machine") | ||
14 | +public class AMPMachine { | ||
15 | + | ||
16 | + //machine id | ||
17 | + @Id | ||
18 | + @Column(name = "id") | ||
19 | + private long id; | ||
20 | + | ||
21 | + //AMP序列号或机器硬件码 | ||
22 | + @Column(name = "AMPSerial") | ||
23 | + private String AMPSerial; | ||
24 | + | ||
25 | + //上传软件密钥(明文存储) | ||
26 | + @Column(name = "secret_key") | ||
27 | + private String secretKey; | ||
28 | + | ||
29 | + //所属公司id | ||
30 | + @Column(name = "company_id") | ||
31 | + private int companyId; | ||
32 | + | ||
33 | + | ||
34 | + //创建时间 | ||
35 | + @Column(name = "create_time") | ||
36 | + private Timestamp createTime; | ||
37 | + | ||
38 | + //状态(0,不可用;1可用) | ||
39 | + @Column(name = "status") | ||
40 | + private int status; | ||
41 | + | ||
42 | + public long getId() { | ||
43 | + return id; | ||
44 | + } | ||
45 | + | ||
46 | + public void setId(long id) { | ||
47 | + this.id = id; | ||
48 | + } | ||
49 | + | ||
50 | + public String getAMPSerial() { | ||
51 | + return AMPSerial; | ||
52 | + } | ||
53 | + | ||
54 | + public void setAMPSerial(String AMPSerial) { | ||
55 | + this.AMPSerial = AMPSerial; | ||
56 | + } | ||
57 | + | ||
58 | + public String getSecretKey() { | ||
59 | + return secretKey; | ||
60 | + } | ||
61 | + | ||
62 | + public void setSecretKey(String secretKey) { | ||
63 | + this.secretKey = secretKey; | ||
64 | + } | ||
65 | + | ||
66 | + public int getCompanyId() { | ||
67 | + return companyId; | ||
68 | + } | ||
69 | + | ||
70 | + public void setCompanyId(int companyId) { | ||
71 | + this.companyId = companyId; | ||
72 | + } | ||
73 | + | ||
74 | + public Timestamp getCreateTime() { | ||
75 | + return createTime; | ||
76 | + } | ||
77 | + | ||
78 | + public void setCreateTime(Timestamp createTime) { | ||
79 | + this.createTime = createTime; | ||
80 | + } | ||
81 | + | ||
82 | + public int getStatus() { | ||
83 | + return status; | ||
84 | + } | ||
85 | + | ||
86 | + public void setStatus(int status) { | ||
87 | + this.status = status; | ||
88 | + } | ||
89 | +} |
src/main/java/com/xkl/domain/Admin.java
0 → 100644
1 | +package com.xkl.domain; | ||
2 | + | ||
3 | +import javax.persistence.Column; | ||
4 | +import javax.persistence.Entity; | ||
5 | +import javax.persistence.Id; | ||
6 | +import javax.persistence.Table; | ||
7 | + | ||
8 | +/** | ||
9 | + * 用户数据的domain类 | ||
10 | + */ | ||
11 | +@Entity | ||
12 | +@Table(name = "xkl_admin") | ||
13 | +public class Admin { | ||
14 | + //用户id | ||
15 | + @Id | ||
16 | + @Column(name = "id") | ||
17 | + private long id; | ||
18 | + | ||
19 | + //账号 | ||
20 | + @Column(name = "account") | ||
21 | + private String account; | ||
22 | + | ||
23 | + //密码 | ||
24 | + @Column(name = "pwd") | ||
25 | + private String pwd; | ||
26 | + | ||
27 | + //账号类型 | ||
28 | + @Column(name = "type") | ||
29 | + private int type; | ||
30 | + | ||
31 | + | ||
32 | + //公司id | ||
33 | + @Column(name = "coid") | ||
34 | + private int coid; | ||
35 | + | ||
36 | + //状态 | ||
37 | + @Column(name = "state") | ||
38 | + private int state; | ||
39 | + | ||
40 | + public long getId() { | ||
41 | + return id; | ||
42 | + } | ||
43 | + | ||
44 | + public void setId(long id) { | ||
45 | + this.id = id; | ||
46 | + } | ||
47 | + | ||
48 | + public String getAccount() { | ||
49 | + return account; | ||
50 | + } | ||
51 | + | ||
52 | + public void setAccount(String account) { | ||
53 | + this.account = account; | ||
54 | + } | ||
55 | + | ||
56 | + public String getPwd() { | ||
57 | + return pwd; | ||
58 | + } | ||
59 | + | ||
60 | + public void setPwd(String pwd) { | ||
61 | + this.pwd = pwd; | ||
62 | + } | ||
63 | + | ||
64 | + public int getType() { | ||
65 | + return type; | ||
66 | + } | ||
67 | + | ||
68 | + public void setType(int type) { | ||
69 | + this.type = type; | ||
70 | + } | ||
71 | + | ||
72 | + public int getCoid() { | ||
73 | + return coid; | ||
74 | + } | ||
75 | + | ||
76 | + public void setCoid(int coid) { | ||
77 | + this.coid = coid; | ||
78 | + } | ||
79 | + | ||
80 | + public int getState() { | ||
81 | + return state; | ||
82 | + } | ||
83 | + | ||
84 | + public void setState(int state) { | ||
85 | + this.state = state; | ||
86 | + } | ||
87 | +} |
@@ -35,4 +35,52 @@ public class User { | @@ -35,4 +35,52 @@ public class User { | ||
35 | 35 | ||
36 | @Column(name = "member_id") | 36 | @Column(name = "member_id") |
37 | private String member_id; | 37 | private String member_id; |
38 | + | ||
39 | + public String getUsername() { | ||
40 | + return username; | ||
41 | + } | ||
42 | + | ||
43 | + public void setUsername(String username) { | ||
44 | + this.username = username; | ||
45 | + } | ||
46 | + | ||
47 | + public String getPassword() { | ||
48 | + return password; | ||
49 | + } | ||
50 | + | ||
51 | + public void setPassword(String password) { | ||
52 | + this.password = password; | ||
53 | + } | ||
54 | + | ||
55 | + public long getId() { | ||
56 | + return id; | ||
57 | + } | ||
58 | + | ||
59 | + public void setId(long id) { | ||
60 | + this.id = id; | ||
61 | + } | ||
62 | + | ||
63 | + public String getSalt() { | ||
64 | + return salt; | ||
65 | + } | ||
66 | + | ||
67 | + public void setSalt(String salt) { | ||
68 | + this.salt = salt; | ||
69 | + } | ||
70 | + | ||
71 | + public boolean isState() { | ||
72 | + return state; | ||
73 | + } | ||
74 | + | ||
75 | + public void setState(boolean state) { | ||
76 | + this.state = state; | ||
77 | + } | ||
78 | + | ||
79 | + public String getMember_id() { | ||
80 | + return member_id; | ||
81 | + } | ||
82 | + | ||
83 | + public void setMember_id(String member_id) { | ||
84 | + this.member_id = member_id; | ||
85 | + } | ||
38 | } | 86 | } |
1 | +package com.xkl.repository; | ||
2 | + | ||
3 | +import com.xkl.domain.AMPMachine; | ||
4 | +import org.springframework.data.repository.CrudRepository; | ||
5 | + | ||
6 | +/** | ||
7 | + * AMPMachine 类的CRUD操作 | ||
8 | + * | ||
9 | + * @see AMPMachine | ||
10 | + */ | ||
11 | +public interface AMPMachineRepository extends CrudRepository<AMPMachine, Long> { | ||
12 | + | ||
13 | + public AMPMachine findBySecretKey(String secretKey); | ||
14 | +} |
1 | +package com.xkl.repository; | ||
2 | + | ||
3 | +import com.xkl.domain.Admin; | ||
4 | +import org.springframework.data.repository.CrudRepository; | ||
5 | + | ||
6 | +/** | ||
7 | + * Admin类的CRUD操作 | ||
8 | + * @see Admin | ||
9 | + */ | ||
10 | +public interface AdminRepository extends CrudRepository<Admin, Long> { | ||
11 | + | ||
12 | + public Admin findByAccount(String account); | ||
13 | + } |
-
Please register or login to post a comment