提交修改
This commit is contained in:
parent
8bbcff5212
commit
f24deffe00
11
src/main/java/com/lz/common/annotation/TaskHeader.java
Normal file
11
src/main/java/com/lz/common/annotation/TaskHeader.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package com.lz.common.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.TYPE_USE})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface TaskHeader {
|
||||||
|
|
||||||
|
String value ( ) default "";
|
||||||
|
}
|
||||||
24
src/main/java/com/lz/common/utils/Md5Utils.java
Normal file
24
src/main/java/com/lz/common/utils/Md5Utils.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package com.lz.common.utils;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
public class Md5Utils {
|
||||||
|
|
||||||
|
public static String toMD5(String plainText) {
|
||||||
|
byte[] secretBytes = null;
|
||||||
|
try {
|
||||||
|
secretBytes = MessageDigest.getInstance("md5").digest(
|
||||||
|
plainText.getBytes());
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
throw new RuntimeException("没有md5这个算法!");
|
||||||
|
}
|
||||||
|
String md5code = new BigInteger(1, secretBytes).toString(16);// 16进制数字
|
||||||
|
// 如果生成数字未满32位,需要前面补0
|
||||||
|
for (int i = 0; i < 32 - md5code.length(); i++) {
|
||||||
|
md5code = "0" + md5code;
|
||||||
|
}
|
||||||
|
return md5code;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -55,6 +55,7 @@ public class ShiroConfig {
|
|||||||
filterMap.put("/dingding/**", "anon");
|
filterMap.put("/dingding/**", "anon");
|
||||||
filterMap.put("/file/**", "anon");
|
filterMap.put("/file/**", "anon");
|
||||||
filterMap.put("/test/**", "anon");
|
filterMap.put("/test/**", "anon");
|
||||||
|
filterMap.put("/third/**", "anon");
|
||||||
filterMap.put("/druid/**", "anon");
|
filterMap.put("/druid/**", "anon");
|
||||||
filterMap.put("/app/**", "anon");
|
filterMap.put("/app/**", "anon");
|
||||||
filterMap.put("/sys/login", "anon");
|
filterMap.put("/sys/login", "anon");
|
||||||
|
|||||||
@ -49,8 +49,6 @@ public class DepartmentsController {
|
|||||||
return R.ok().put("data", departmentList);
|
return R.ok().put("data", departmentList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 信息
|
* 信息
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -0,0 +1,94 @@
|
|||||||
|
package com.lz.modules.app.controller;
|
||||||
|
|
||||||
|
import com.lz.common.constant.CacheConstants;
|
||||||
|
import com.lz.common.utils.Md5Utils;
|
||||||
|
import com.lz.common.utils.R;
|
||||||
|
import com.lz.common.utils.RedisCacheUtil;
|
||||||
|
import com.lz.common.utils.RedisUtils;
|
||||||
|
import com.lz.modules.app.dto.CommandDto;
|
||||||
|
import com.lz.modules.app.entity.StaffEntity;
|
||||||
|
import com.lz.modules.app.service.StaffService;
|
||||||
|
import com.lz.modules.sys.entity.SysUserEntity;
|
||||||
|
import com.lz.modules.sys.service.SysUserService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.shiro.crypto.hash.Sha256Hash;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("third")
|
||||||
|
@Slf4j
|
||||||
|
public class ThirdTaskController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisCacheUtil redisCacheUtil;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StaffService staffService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysUserService sysUserService;
|
||||||
|
|
||||||
|
@RequestMapping("/handler")
|
||||||
|
public R handler(@RequestBody CommandDto command) {
|
||||||
|
SysUserEntity user = checkLogin(command.getToken());
|
||||||
|
if (user == null) {
|
||||||
|
return R.error(499, "登陆己经过期");
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("command:" + command);
|
||||||
|
List<List<String>> data = new ArrayList<>();
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
List<String> a = new ArrayList<>();
|
||||||
|
for (int j = 0; j < 5; j++) {
|
||||||
|
a.add(j + "");
|
||||||
|
}
|
||||||
|
data.add(a);
|
||||||
|
}
|
||||||
|
List<String> header = new ArrayList<>(Arrays.asList(new String[]{"用户名", "密码", "哈哈", "双", "你是"}));
|
||||||
|
return R.ok().put("header", header).put("data", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SysUserEntity checkLogin(String token) {
|
||||||
|
Object object = redisCacheUtil.getObject(token);
|
||||||
|
if (object != null) {
|
||||||
|
return (SysUserEntity) object;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/login")
|
||||||
|
public R login(@RequestBody CommandDto command) {
|
||||||
|
SysUserEntity user = sysUserService.queryByUserName(command.getUsername());
|
||||||
|
if (user == null) {
|
||||||
|
StaffEntity staffEntity = staffService.selectByPhone(command.getUsername());
|
||||||
|
if (staffEntity != null) {
|
||||||
|
user = new SysUserEntity();
|
||||||
|
user.setPassword(staffEntity.getPassword());
|
||||||
|
user.setMobile(staffEntity.getMobile());
|
||||||
|
user.setUserId(staffEntity.getId());
|
||||||
|
user.setEmail(staffEntity.getEmail());
|
||||||
|
user.setSalt(staffEntity.getSalt());
|
||||||
|
user.setStatus(1);
|
||||||
|
user.setType(1);
|
||||||
|
user.setUsername(staffEntity.getMobile());
|
||||||
|
user.setRealName(staffEntity.getName());
|
||||||
|
user.setUserNo(staffEntity.getMobile());
|
||||||
|
} else {
|
||||||
|
return R.error("username 不存在!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!user.getPassword().equals(new Sha256Hash(command.getPassword(), user.getSalt()).toHex())) {
|
||||||
|
return R.error("password不正确!");
|
||||||
|
}
|
||||||
|
String token = Md5Utils.toMD5(System.currentTimeMillis() + user.getUserId() + "");
|
||||||
|
redisCacheUtil.saveObject(token, user, CacheConstants.SECOND_OF_HALF_HOUR);
|
||||||
|
return R.ok(token);
|
||||||
|
}
|
||||||
|
}
|
||||||
11
src/main/java/com/lz/modules/app/dto/CommandDto.java
Normal file
11
src/main/java/com/lz/modules/app/dto/CommandDto.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package com.lz.modules.app.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CommandDto {
|
||||||
|
private String command;
|
||||||
|
private String username;
|
||||||
|
private String password;
|
||||||
|
private String token;
|
||||||
|
}
|
||||||
15
src/main/java/com/lz/modules/app/dto/RecordDto.java
Normal file
15
src/main/java/com/lz/modules/app/dto/RecordDto.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package com.lz.modules.app.dto;
|
||||||
|
|
||||||
|
import com.lz.common.annotation.TaskHeader;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class RecordDto {
|
||||||
|
@TaskHeader("索引")
|
||||||
|
private int index;
|
||||||
|
@TaskHeader("Id")
|
||||||
|
private Long id;
|
||||||
|
@TaskHeader("内容")
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
}
|
||||||
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<!--<include resource="org/springframework/boot/logging/logback/base.xml"/>-->
|
<!--<include resource="org/springframework/boot/logging/logback/base.xml"/>-->
|
||||||
<!-- 定义log文件的目录 -->
|
<!-- 定义log文件的目录 -->
|
||||||
<property name="LOG_HOME" value="lzmanagement"></property>
|
<property name="LOG_HOME" value="${user.home}/logs/lz_management"></property>
|
||||||
|
|
||||||
|
|
||||||
<conversionRule conversionWord="sampleClass" converterClass="com.lz.common.layouts.SampleClassConverter" />
|
<conversionRule conversionWord="sampleClass" converterClass="com.lz.common.layouts.SampleClassConverter" />
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user