Commit 804eb018 by ypenglv

调整配置

1 parent 4738d4c7
......@@ -44,11 +44,12 @@ public class UserController {
}
@ApiOperation( value = "app用户登陆接口",notes = "app用户登陆接口")
@PostMapping("/userLogin")
@PostMapping("/login")
@ResponseBody
public ApiResponse<UserVO> userLogin (@RequestBody @Validated LoginParam loginParam){
ApiResponse<UserVO> login = userService.userLogin(loginParam);
return login;
public ApiResponse<UserVO> login (@RequestBody @Validated LoginParam loginParam){
return new ApiResponse(userService.userLogin(loginParam));
}
@ApiOperation( value = "app手机号登陆接口",notes = "app手机号登陆接口")
......
......@@ -6,6 +6,7 @@ import org.nafmii.common.constant.MessageEnum;
import org.nafmii.common.response.ApiResponse;
import org.springframework.core.annotation.Order;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
......@@ -37,7 +38,7 @@ public class BusinessExceptionHandler {
@ResponseBody
public ApiResponse businessErrorHandler(BusinessException e) {
log.error (e.getMessage (), e);
return new ApiResponse(new Long((long)e.getStatusCode()), e.getMessage());
return new ApiResponse(MessageEnum.FAIL.getCode(), e.getMessage());
}
/**
......
package org.nafmii.common.param;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* @author lvyp
* @date 2021/5/25
*/
@Data
public class IdQuery {
@ApiModelProperty("选中数据主键")
@NotNull(message = "主键不能为空")
private Long id;
}
......@@ -74,8 +74,8 @@ public class JwtUtils {
public static void main(String[] args) {
Map<String,Object> map = new HashMap<>();
map.put("userId",12312321313L);
String token = generateJsonWebToken(map,EXPIRITION);
map.put("userId",1);
String token = generateJsonWebToken(map,1000*60*60*7);
System.out.println(token);
Claims claims = getUserInfo(token);
Map<String,Object> map1 = (Map<String, Object>) claims.get(HttpClientHeaderEnum.USER_VO.getCode());
......
......@@ -36,8 +36,8 @@ public class AccessFilter implements GlobalFilter, Ordered {
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
String url = exchange.getRequest().getURI().getPath();
//相关不需要的接口地址
String skip0 ="/nafmii-app/app/nafmii/user/userLogin";
String skip1 ="/nafmii-admin/nafmii/admin/user/login";
String skip0 ="/nafmii-app-user/app/nafmii/user/login";
String skip1 ="/nafmii-web-center/nafmii/webcenter/user/login";
String skip2 ="/nafmii-app-user/v2/api-docs";
String skip3 ="/nafmii-web-center/v2/api-docs";
String skip4 ="/nafmii-app-business/v2/api-docs";
......
......@@ -10,7 +10,7 @@ import javax.annotation.PostConstruct;
import java.util.Date;
import java.util.TimeZone;
@SpringBootApplication
@SpringBootApplication(scanBasePackages ={"org.nafmii.webcenter","org.nafmii.common"} )
@EnableEurekaClient
@MapperScan(basePackages ={"org.nafmii.webcenter/**/dao"})
@EnableFtpServer
......
package org.nafmii.webcenter.user.service;
import org.nafmii.webcenter.user.param.AddOrUpdateUserParam;
import org.nafmii.webcenter.user.dto.AddCenterUserDto;
import org.nafmii.webcenter.user.dto.ModifyCenterUserDto;
import org.nafmii.webcenter.user.param.LoginParam;
import org.nafmii.webcenter.user.param.QueryUsersParam;
import org.nafmii.webcenter.user.param.SwitchStatusParam;
import org.nafmii.webcenter.user.vo.CenterUserAndRoleVo;
import org.nafmii.webcenter.user.vo.CenterUserVO;
import org.nafmii.common.response.ApiResponse;
import javax.servlet.http.HttpServletRequest;
......@@ -20,12 +20,18 @@ import java.util.List;
* @since 2021-04-27
*/
public interface ICenterUserService {
/**\
* 新建或编辑用户接口
* @param param
/**
* 新建用户接口
* @param dto
* @return
*/
ApiResponse addCenterUser(AddCenterUserDto dto);
/**
* 编辑用户接口
* @param dto
* @return
*/
ApiResponse addOrUpdateUser(AddOrUpdateUserParam param);
ApiResponse modifyCenterUser(ModifyCenterUserDto dto);
/**
* 用户删除接口
......
package org.nafmii.webcenter.user.service.impl;
import cn.hutool.crypto.digest.DigestUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.nafmii.common.constant.WebCenterEnum;
import org.nafmii.common.exception.BusinessException;
import org.nafmii.common.utils.JwtUtils;
import org.nafmii.common.utils.MenuUtil;
import org.nafmii.common.utils.RealIpUtils;
import org.nafmii.common.utils.RedisUtils;
import org.nafmii.webcenter.user.dao.CenterMenuMapper;
import org.nafmii.webcenter.user.dao.CenterUserMapper;
import org.nafmii.webcenter.user.dao.CenterUserRoleMapper;
import org.nafmii.webcenter.user.dto.AddOrUpdateUserDto;
import org.nafmii.webcenter.user.dto.AddCenterUserDto;
import org.nafmii.webcenter.user.dto.LoginDto;
import org.nafmii.webcenter.user.dto.ModifyCenterUserDto;
import org.nafmii.webcenter.user.dto.QueryUsersDto;
import org.nafmii.webcenter.user.dto.SwitchStatusDto;
import org.nafmii.webcenter.user.entity.CenterUserPO;
import org.nafmii.webcenter.user.entity.CenterUserRolePO;
import org.nafmii.webcenter.user.param.AddOrUpdateUserParam;
import org.nafmii.webcenter.user.param.LoginParam;
import org.nafmii.webcenter.user.param.QueryUsersParam;
import org.nafmii.webcenter.user.param.SwitchStatusParam;
import org.nafmii.webcenter.user.service.ICenterUserService;
import org.nafmii.webcenter.user.vo.CenterUserAndRoleVo;
import org.nafmii.webcenter.user.vo.CenterUserVO;
import org.nafmii.common.constant.MessageEnum;
import org.nafmii.common.constant.UserEnum;
import org.nafmii.common.param.BeanTransferUtils;
import org.nafmii.common.response.ApiResponse;
import org.nafmii.common.utils.RequestUtils;
import org.nafmii.common.utils.SnowFlakeUtil;
import org.nafmii.webcenter.user.vo.MenuToUserVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* <p>
......@@ -57,69 +62,52 @@ public class CenterUserServiceImpl implements ICenterUserService {
/**
* 新建或编辑用户接口
* @param param
* @param dto
* @return
*/
@Transactional(rollbackFor = BusinessException.class)
@Override
public ApiResponse addOrUpdateUser(AddOrUpdateUserParam param) {
AddOrUpdateUserDto userDto = BeanTransferUtils.transfer(param, AddOrUpdateUserDto.class);
log.info("===============中心端用户新建或编辑接口参数======》{}",userDto);
//=====================用户参数赋值====================开始
CenterUserPO userPO = new CenterUserPO();
userPO.setCnName(userDto.getCnName());
userPO.setUpdateTime(LocalDateTime.now());
userPO.setUpdateUserId(RequestUtils.getUserId());
userPO.setEnName(userDto.getEnNAme());
userPO.setLoginName(userDto.getLoginName());
userPO.setLoginPwd(DigestUtil.md5Hex(userDto.getLoginPwd().getBytes()));
userPO.setPhone(userDto.getPhone());
userPO.setIsEnable(userDto.getIsEnable());
userPO.setDelFlag(UserEnum.USER.getCode());
//=====================用户参数赋值====================结束
//判断新增功能还是编辑功能
if (null != param.getId()){
userPO.setId(userDto.getId());
int i = centerUserMapper.updateById(userPO);
if (i < 0){
return new ApiResponse(ApiResponse.FAIL,ApiResponse.FAIL_TEXT);
}
}else{
userPO.setId(SnowFlakeUtil.nextId());
userPO.setCreateTime(LocalDateTime.now());
userPO.setCreateUserId(RequestUtils.getUserId());
int i = centerUserMapper.insert(userPO);
if (i < 0){
return new ApiResponse(ApiResponse.FAIL,ApiResponse.FAIL_TEXT);
}
}
log.info("============================用户相关实体赋值数据"+userPO);
//用户操作完后开始同步角色相关数据插入=======================开始
//通过用户id查询相对应的角色数据集合
List<CenterUserRolePO> rolePOS = userRoleMapper.selectByUserId(userPO.getId());
log.info("============================角色用户中间表相关用户数据rolePOS"+rolePOS);
//将该用户全部变为无效用户
if (rolePOS.size() > 0){
for (CenterUserRolePO po:rolePOS) {
po.setIsEnable(UserEnum.NOTENABLE.getCode());
int i = userRoleMapper.updateById(po);
if (i < 0){
return new ApiResponse(ApiResponse.FAIL,ApiResponse.FAIL_TEXT);
}
}
}
//插入数据
public ApiResponse addCenterUser(AddCenterUserDto dto) {
//当前操作人ID
Long oprationId = RequestUtils.getUserId();
CenterUserPO userPO = BeanTransferUtils.transfer(dto,CenterUserPO.class);
Long userId = SnowFlakeUtil.nextId();
userPO.setId(userId);
userPO.setCreateUserId(oprationId);
userPO.setUpdateUserId(oprationId);
Date nowTime = new Date();
userPO.setCreateTime(nowTime);
userPO.setUpdateTime(nowTime);
//添加用户信息
centerUserMapper.insert(userPO);
//添加用户角色关系
CenterUserRolePO userRolePO = new CenterUserRolePO();
userRolePO.setRoleId(userDto.getRoleId());
userRolePO.setUserId(RequestUtils.getUserId());
userRolePO.setIsEnable(UserEnum.ENABLE.getCode());
userRolePO.setId(SnowFlakeUtil.nextId());
log.info("============================角色用户中间表相关参数对象》userRolePO"+userRolePO);
int i = userRoleMapper.insert(userRolePO);
//用户操作完后开始同步角色相关数据插入=======================结束
if (i < 0){
return new ApiResponse(ApiResponse.FAIL,ApiResponse.FAIL_TEXT);
userRolePO.setUserId(userId);
userRolePO.setRoleId(dto.getRoleId());
userRolePO.setCreateTime(nowTime);
userRoleMapper.insert(userRolePO);
return new ApiResponse();
}
return new ApiResponse(ApiResponse.FAIL,ApiResponse.FAIL_TEXT);
@Transactional(rollbackFor = BusinessException.class)
@Override
public ApiResponse modifyCenterUser(ModifyCenterUserDto dto) {
//当前操作人ID
Long oprationId = RequestUtils.getUserId();
Date nowTime = new Date();
CenterUserPO userPO = BeanTransferUtils.transfer(dto,CenterUserPO.class);
userPO.setUpdateUserId(oprationId);
userPO.setUpdateTime(nowTime);
centerUserMapper.updateById(userPO);
//添加用户角色关系
CenterUserRolePO userRolePO = new CenterUserRolePO();
userRolePO.setId(SnowFlakeUtil.nextId());
userRolePO.setUserId(dto.getId());
userRolePO.setRoleId(dto.getRoleId());
userRolePO.setCreateTime(nowTime);
userRoleMapper.updateById(userRolePO);
return new ApiResponse();
}
/**
......@@ -135,7 +123,6 @@ public class CenterUserServiceImpl implements ICenterUserService {
userPO.setId(userDto.getId());
userPO.setDelFlag(UserEnum.DELETE.getCode());
userPO.setUpdateUserId(RequestUtils.getUserId());
userPO.setUpdateTime(LocalDateTime.now());
int i = centerUserMapper.updateById(userPO);
if (i < 0){
return new ApiResponse(ApiResponse.FAIL,ApiResponse.FAIL_TEXT);
......@@ -151,7 +138,6 @@ public class CenterUserServiceImpl implements ICenterUserService {
@Override
public List<CenterUserAndRoleVo> queryUser(QueryUsersParam param) {
QueryUsersDto userDto = BeanTransferUtils.transfer(param, QueryUsersDto.class);
log.info("=========用户列表相关参数==========>userDto");
List<CenterUserAndRoleVo> userAndRoleVos = centerUserMapper.selectUserAndRole(userDto);
return userAndRoleVos;
}
......@@ -169,7 +155,6 @@ public class CenterUserServiceImpl implements ICenterUserService {
userPO.setId(userDto.getId());
userPO.setIsEnable(userDto.getIsEnable());
userPO.setUpdateUserId(RequestUtils.getUserId());
userPO.setUpdateTime(LocalDateTime.now());
int i = centerUserMapper.updateById(userPO);
if (i < 0){
return new ApiResponse(ApiResponse.FAIL,ApiResponse.FAIL_TEXT);
......@@ -184,6 +169,7 @@ public class CenterUserServiceImpl implements ICenterUserService {
*/
@Override
public ApiResponse userLogin(LoginParam param,HttpServletRequest request) {
final long EXPIRITION = 1000 * 60 * 60 * 2 * 1;
String ip = RealIpUtils.getIpAddress(request).replace(".","");
// String captcha = RedisUtils.hGetObject(WebCenterEnum.WEB_CENTER_CAP.getCode(),ip,String.class);
//// if(StringUtils.isBlank(captcha)){
......@@ -201,8 +187,17 @@ public class CenterUserServiceImpl implements ICenterUserService {
if (!"0".equals(userVo.getIsEnable())){
return new ApiResponse(ApiResponse.FAIL,"无效用户");
}
//获取用户权限
userVo.setMenuList(menuMapper.queryMenuByUser(userVo.getId()));
//获取用户权限 tree
List<MenuToUserVO> menuTree = new ArrayList<>();
String jsonStr = JSON.toJSONString(menuMapper.queryMenuByUser(userVo.getId()));
JSONArray jsonArray = JSON.parseArray(jsonStr);
JSONArray deptTree = MenuUtil.listToTree(jsonArray,"menuId","parentId","children");
menuTree = MenuUtil.arrayToList(deptTree,MenuToUserVO.class);
userVo.setMenuList(menuTree);
//生成Authorization
Map<String,Object> map = new HashMap<>();
map.put("userId",userVo.getId());
userVo.setAuthorization(JwtUtils.generateJsonWebToken(map,EXPIRITION));
return new ApiResponse(ApiResponse.SUCCESS,ApiResponse.SUCCESS_TEXT,userVo);
}
}
......@@ -65,6 +65,7 @@ public class CenterUserVO extends Model {
private String isEnable;
@ApiModelProperty(value = "菜单集合")
private List<MenuToUserVO> menuList;
private String authorization;
}
......@@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @author lvyp
* @date 2021/5/24
......@@ -23,4 +25,6 @@ public class MenuToUserVO {
private String menuUrl;
@ApiModelProperty(value = "排序")
private String orderSeq;
@ApiModelProperty(value = "菜单Tree")
private List<MenuToUserVO> children;
}
......@@ -33,15 +33,15 @@ spring:
default-property-inclusion: ALWAYS
time-zone: GMT+8
date-format: yyyy-MM-dd HH:mm:ss
zipkin:
base-url: http://localhost:9411
enabled: true
sleuth:
web:
client:
enabled: true
sampler:
probability: 1.0 #zipkin采集率 0.1表示 10%采集率
# zipkin:
# base-url: http://localhost:9411
# enabled: true
# sleuth:
# web:
# client:
# enabled: true
# sampler:
# probability: 1.0 #zipkin采集率 0.1表示 10%采集率
nafmii:
log-path: D:/NAFMII
dao-uri: org.nafmii.admin
......
......@@ -18,7 +18,7 @@
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
ID, MENU_NAME, MENU_LEVLE, PARENT_ID, ORDER_SEQ, CREATE_TIME, UPDATE_TIME, IS_ENABLE, CREATE_USER_ID, UPDATE_USER_ID
ID, MENU_NAME, MENU_LEVLE,MENU_URL, PARENT_ID, ORDER_SEQ, CREATE_TIME, UPDATE_TIME, IS_ENABLE, CREATE_USER_ID, UPDATE_USER_ID
</sql>
<select id="selectAll" resultType="org.nafmii.webcenter.user.vo.MenuListVo">
......@@ -34,9 +34,9 @@
SELECT DISTINCT
( CM.ID ) AS menuId,
CM.MENU_NAME,
CM.MENU_LEVLE,
CM.MENU_LEVEL,
CM.PARENT_ID,
CM.MENUM_URL,
CM.MENU_URL,
CM.ORDER_SEQ
FROM
CENTER_USER CU
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!