parent
3af22ea7dd
commit
ec33e6fc92
@ -0,0 +1,22 @@
|
|||||||
|
package com.tz.platform.common.core.tools;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.RandomUtil;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class NOUtil {
|
||||||
|
private NOUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Long getOrderNo() {
|
||||||
|
return Long.valueOf(DateUtil.format(new Date(), Constants.DATE.YYYYMMDDHHMMSS) + RandomUtil.randomNumbers(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Long getSerialNumber() {
|
||||||
|
return Long.valueOf(DateUtil.format(new Date(), Constants.DATE.YYYYMMDDHHMMSS) + RandomUtil.randomNumbers(4));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Long getUserNo() {
|
||||||
|
return Long.valueOf(DateUtil.format(new Date(), Constants.DATE.YYYYMMDDHHMMSS) + RandomUtil.randomNumbers(2));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package com.tz.platform.common.core.tools;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class StrUtil {
|
||||||
|
private StrUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getSuffix(String fileName) {
|
||||||
|
return fileName.substring(fileName.lastIndexOf(".") + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getPrefix(String fileName) {
|
||||||
|
return fileName.substring(0, fileName.lastIndexOf("."));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getRandom(int bound) {
|
||||||
|
Random ra = new Random();
|
||||||
|
String result = "";
|
||||||
|
for (int i = 1; i <= bound; i++) {
|
||||||
|
result += ra.nextInt(10);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String get32UUID() {
|
||||||
|
return IdUtil.simpleUUID();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.tz.platform.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Data
|
||||||
|
public class Menu {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy= GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
private String icon;
|
||||||
|
|
||||||
|
private Integer parentId;
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.tz.platform.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Data
|
||||||
|
public class Province {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy= GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
private String name;
|
||||||
|
private Integer regionId;
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.tz.platform.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Data
|
||||||
|
public class Region implements Serializable {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy= GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
private String name;
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.tz.platform.repository;
|
||||||
|
|
||||||
|
import com.tz.platform.entity.Menu;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface MenuDao extends JpaRepository<Menu,Integer> {
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.tz.platform.repository;
|
||||||
|
|
||||||
|
import com.tz.platform.entity.Province;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface ProvinceDao extends JpaRepository<Province,Integer> {
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.tz.platform.repository;
|
||||||
|
|
||||||
|
import com.tz.platform.entity.Region;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface RegionDao extends JpaRepository<Region,Integer> {
|
||||||
|
}
|
@ -1,10 +1,31 @@
|
|||||||
package com.tz.platform.repository;
|
package com.tz.platform.repository;
|
||||||
|
|
||||||
import com.tz.platform.entity.User;
|
import com.tz.platform.entity.User;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface UserDao extends JpaRepository<User,Long> {
|
public interface UserDao extends JpaRepository<User,Long> {
|
||||||
|
/**
|
||||||
|
* 依据手机号获取用户
|
||||||
|
* @param mobile 手机号
|
||||||
|
* @return 用户
|
||||||
|
*/
|
||||||
User findByMobile(String mobile);
|
User findByMobile(String mobile);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 依据用户名获取用户
|
||||||
|
* @param username 用户名
|
||||||
|
* @return 用户
|
||||||
|
*/
|
||||||
|
User getByUsername(String username);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分布获取用户
|
||||||
|
* @param pageable 分页数据
|
||||||
|
* @return 一页用户
|
||||||
|
*/
|
||||||
|
Page<User> findAll(Pageable pageable);
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,45 @@
|
|||||||
package com.tz.platform.user.api;
|
package com.tz.platform.user.api;
|
||||||
|
|
||||||
|
import com.tz.platform.common.core.base.BaseController;
|
||||||
|
import com.tz.platform.common.core.base.Result;
|
||||||
import com.tz.platform.entity.User;
|
import com.tz.platform.entity.User;
|
||||||
import com.tz.platform.repository.UserDao;
|
import com.tz.platform.repository.UserDao;
|
||||||
|
import com.tz.platform.user.api.biz.ApiUserInfoBiz;
|
||||||
|
import com.tz.platform.user.api.bo.UserLoginPasswordBO;
|
||||||
|
import com.tz.platform.user.api.dto.UserInfoDTO;
|
||||||
|
import com.tz.platform.user.api.dto.UserLoginDTO;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(path = "/api/user")
|
@RequestMapping(path = "/api/user")
|
||||||
public class UserInfoController {
|
public class UserInfoController extends BaseController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
UserDao userDao;
|
UserDao userDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ApiUserInfoBiz apiUserInfoBiz;
|
||||||
|
|
||||||
@GetMapping(path = "test")
|
@GetMapping(path = "test")
|
||||||
public String test(){
|
public String test(){
|
||||||
List<User> userList = userDao.findAll();
|
List<User> userList = userDao.findAll();
|
||||||
return "user count:"+userList.size();
|
return "user count:"+userList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping(path = "login")
|
||||||
|
public Result<UserLoginDTO> loginPassword(@RequestBody UserLoginPasswordBO userLoginPasswordBO){
|
||||||
|
log(userLoginPasswordBO);
|
||||||
|
return apiUserInfoBiz.loginPassword(userLoginPasswordBO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(path = "info")
|
||||||
|
public Result<UserInfoDTO> info(){
|
||||||
|
|
||||||
|
UserInfoDTO userInfoDTO = new UserInfoDTO();
|
||||||
|
return Result.success(userInfoDTO);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,130 @@
|
|||||||
|
package com.tz.platform.user.api.biz;
|
||||||
|
|
||||||
|
import cn.hutool.crypto.digest.DigestUtil;
|
||||||
|
import com.tz.platform.common.core.base.Result;
|
||||||
|
import com.tz.platform.common.core.enmus.UserTypeEnum;
|
||||||
|
import com.tz.platform.common.core.tools.JWTUtil;
|
||||||
|
import com.tz.platform.common.core.tools.StrUtil;
|
||||||
|
import com.tz.platform.entity.User;
|
||||||
|
import com.tz.platform.repository.UserDao;
|
||||||
|
import com.tz.platform.user.api.bo.UserLoginPasswordBO;
|
||||||
|
import com.tz.platform.user.api.bo.UserRegisterBO;
|
||||||
|
import com.tz.platform.user.api.dto.UserLoginDTO;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class ApiUserInfoBiz {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserDao userDao;
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate<String, String> redisTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册用户
|
||||||
|
* @param userRegisterBO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public Result<UserLoginDTO> register(UserRegisterBO userRegisterBO) {
|
||||||
|
if (StringUtils.isEmpty(userRegisterBO.getUserName())) {
|
||||||
|
return Result.error("用户名不能为空");
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(userRegisterBO.getPassword())) {
|
||||||
|
return Result.error("密码不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 手机号重复校验
|
||||||
|
User user = userDao.getByUsername(userRegisterBO.getUserName());
|
||||||
|
if (null != user) {
|
||||||
|
return Result.error("该用户已经注册,请更换手用户名");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用户注册
|
||||||
|
|
||||||
|
// 用户基本信息
|
||||||
|
user = reg(userRegisterBO);
|
||||||
|
|
||||||
|
UserLoginDTO dto = new UserLoginDTO();
|
||||||
|
dto.setUserNo(user.getId());
|
||||||
|
dto.setUsername(user.getUsername());
|
||||||
|
dto.setToken(JWTUtil.create(user.getId(), JWTUtil.DATE));
|
||||||
|
return Result.success(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
public User reg(UserRegisterBO bo){
|
||||||
|
User user = new User();
|
||||||
|
user.setUsername(bo.getUserName());
|
||||||
|
user.setStudentNo(bo.getStudentNo());
|
||||||
|
user.setSchool(bo.getSchool());
|
||||||
|
user.setMobileSalt(StrUtil.get32UUID());
|
||||||
|
user.setMobilePsw(DigestUtil.sha1Hex(user.getMobileSalt() + bo.getPassword()));
|
||||||
|
user.setUserType(UserTypeEnum.USER.getCode());
|
||||||
|
user = userDao.save(user);
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量导入用户
|
||||||
|
* @param file
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int batchImportUser(File file){
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账号密码登陆
|
||||||
|
* @param userLoginPasswordBO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Result<UserLoginDTO> loginPassword(UserLoginPasswordBO userLoginPasswordBO){
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(userLoginPasswordBO.getUsername())) {
|
||||||
|
return Result.error("用户名不能为空");
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(userLoginPasswordBO.getPassword())) {
|
||||||
|
return Result.error("密码不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 密码错误次数校验
|
||||||
|
|
||||||
|
// 用户校验
|
||||||
|
User user = userDao.getByUsername(userLoginPasswordBO.getUsername());
|
||||||
|
if (null == user) {
|
||||||
|
return Result.error("账号或者密码不正确");
|
||||||
|
}
|
||||||
|
// 密码校验
|
||||||
|
if (!DigestUtil.sha1Hex(user.getMobileSalt() + userLoginPasswordBO.getPassword()).equals(user.getMobilePsw())) {
|
||||||
|
// 放入缓存,错误次数+1
|
||||||
|
return Result.error("账号或者密码不正确");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 登录日志
|
||||||
|
// loginLog(user.getUserNo(), userLoginPasswordBO.getClientId(), LoginStatusEnum.SUCCESS, userLoginPasswordBO.getIp());
|
||||||
|
|
||||||
|
UserLoginDTO dto = new UserLoginDTO();
|
||||||
|
dto.setUserNo(user.getId());
|
||||||
|
dto.setUsername(user.getUsername());
|
||||||
|
dto.setToken(JWTUtil.create(user.getId(), JWTUtil.DATE));
|
||||||
|
|
||||||
|
// 登录成功,存入缓存,单点登录使用
|
||||||
|
// redisTemplate.opsForValue().set(dto.getUserNo().toString(), dto.getToken(), 1, TimeUnit.DAYS);
|
||||||
|
|
||||||
|
return Result.success(dto);
|
||||||
|
}
|
||||||
|
}
|
@ -1,20 +0,0 @@
|
|||||||
package com.tz.platform.user.api.biz;
|
|
||||||
|
|
||||||
import com.tz.platform.common.core.base.Result;
|
|
||||||
import com.tz.platform.repository.UserDao;
|
|
||||||
import com.tz.platform.user.api.bo.UserLoginPasswordBO;
|
|
||||||
import com.tz.platform.user.api.dto.UserLoginDTO;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class apiUserInfoBiz {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private UserDao userDao;
|
|
||||||
|
|
||||||
public Result<UserLoginDTO> loginPassword(UserLoginPasswordBO userLoginPasswordBO){
|
|
||||||
UserLoginDTO userLoginDTO = new UserLoginDTO();
|
|
||||||
return Result.success(userLoginDTO);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,42 @@
|
|||||||
|
package com.tz.platform.user.api.bo;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class UserRegisterBO implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号码
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "用户名", required = true)
|
||||||
|
private String userName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录密码
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "密码", required = true)
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 学号
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value="学号")
|
||||||
|
private String studentNo;
|
||||||
|
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "学校")
|
||||||
|
private String school;
|
||||||
|
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "ip地址")
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.tz.platform.user.api.dto;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class UserInfoDTO implements Serializable {
|
||||||
|
@ApiModelProperty(value = "姓名")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "头像")
|
||||||
|
private String avatar;
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.tz.platform.user.pc.biz;
|
||||||
|
|
||||||
|
import com.tz.platform.entity.User;
|
||||||
|
import com.tz.platform.repository.UserDao;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class PcUserInfoBiz {
|
||||||
|
@Autowired
|
||||||
|
private UserDao userDao;
|
||||||
|
|
||||||
|
public Page<User> listPage(Integer pageNo){
|
||||||
|
Pageable pageable = PageRequest.of(pageNo,20);
|
||||||
|
Page<User> userPage = userDao.findAll(pageable);
|
||||||
|
return userPage;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.tz.platform.user.api.biz;
|
||||||
|
|
||||||
|
import com.tz.platform.entity.User;
|
||||||
|
import com.tz.platform.user.api.bo.UserRegisterBO;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
public class ApiUserInfoBizTest {
|
||||||
|
@Autowired
|
||||||
|
private ApiUserInfoBiz apiUserInfoBiz;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void singleInsert(){
|
||||||
|
UserRegisterBO userRegisterBO = new UserRegisterBO();
|
||||||
|
userRegisterBO.setPassword("111111");
|
||||||
|
userRegisterBO.setUserName("admin");
|
||||||
|
userRegisterBO.setSchool("BJ");
|
||||||
|
userRegisterBO.setStudentNo("000000");
|
||||||
|
User user = apiUserInfoBiz.reg(userRegisterBO);
|
||||||
|
System.out.println(user.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void batchImport() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue