Commit 6c0122e6 authored by 李驰骋's avatar 李驰骋

用户登录、默认值调整

parent 84153a28
......@@ -51,13 +51,13 @@ public class InvtaCreateParams {
@ApiModelProperty("单据日期")
private String ta014;
@ApiModelProperty("审核者")
private String ta015;
private String ta015="";
@ApiModelProperty("总包装数量")
private BigDecimal ta016;
private BigDecimal ta016=BigDecimal.ZERO;
@ApiModelProperty("签核状态码")
private String ta017="N";
@ApiModelProperty("海关手册")
private String ta018;
private String ta018="";
@ApiModelProperty("审批意见")
private String ta019;
@ApiModelProperty("不合格原因")
......@@ -65,11 +65,11 @@ public class InvtaCreateParams {
@ApiModelProperty("传送次数")
private Integer ta021=0;
@ApiModelProperty("汇入日期")
private String ta022;
private String ta022="";
@ApiModelProperty("门店编号")
private String ta023;
private String ta023="";
@ApiModelProperty("对方汇出日期")
private String ta024;
private String ta024="";
@ApiModelProperty("单据来源")
private String ta025="1";
@ApiModelProperty("批号")
......
......@@ -36,48 +36,48 @@ public class InvtbCreateParams {
@ApiModelProperty("库存数量")
private BigDecimal tb009;
@ApiModelProperty("单位成本")
private BigDecimal tb010;
private BigDecimal tb010=BigDecimal.ZERO;
@ApiModelProperty("金额")
private BigDecimal tb011;
private BigDecimal tb011=BigDecimal.ZERO;
@ApiModelProperty("转出库")
private String tb012;
@ApiModelProperty("转入库")
private String tb013;
private String tb013="";
@ApiModelProperty("批号")
private String tb014="********************";
@ApiModelProperty("有效日期")
private String tb015;
private String tb015="";
@ApiModelProperty("复检日期")
private String tb016;
private String tb016="";
@ApiModelProperty("备注")
private String tb017;
private String tb017="";
@ApiModelProperty("审核码")
private String tb018="N";
@ApiModelProperty("预留字段")
private String tb019;
@ApiModelProperty("小单位")
private String tb020;
private String tb020="";
@ApiModelProperty("项目编号")
private String tb021="********************";
@ApiModelProperty("包装数量")
private BigDecimal tb022=BigDecimal.ZERO;
@ApiModelProperty("包装单位")
private String tb023;
private String tb023="";
@ApiModelProperty("存储位置")
private String tb024;
private String tb024="";
@ApiModelProperty("已销毁数量")
private BigDecimal tb025;
private BigDecimal tb025=BigDecimal.ZERO;
@ApiModelProperty("件装")
private BigDecimal tb026;
private BigDecimal tb026=BigDecimal.ZERO;
@ApiModelProperty("件数")
private BigDecimal tb027;
private BigDecimal tb027=BigDecimal.ZERO;
@ApiModelProperty("批号说明")
private String tb028;
private String tb028="";
@ApiModelProperty("转出库位")
private String tb029;
@ApiModelProperty("转入库位")
private String tb030;
private String tb030="";
@ApiModelProperty("生产日期")
private String tb031;
private String tb031="";
}
package com.topsunit.scanservice.ximai.dto;
import lombok.Data;
/**
* <p>Title: LoginResult</p>
* <p>Description: 登陆结果</p>
......@@ -8,6 +10,7 @@ package com.topsunit.scanservice.ximai.dto;
* @version V1.0
* @date 2021/10/19
*/
@Data
public class LoginResult {
/**
* 员工编号
......@@ -25,36 +28,4 @@ public class LoginResult {
* token
*/
private String token;
public String getMv001() {
return mv001;
}
public void setMv001(String mv001) {
this.mv001 = mv001;
}
public String getMv002() {
return mv002;
}
public void setMv002(String mv002) {
this.mv002 = mv002;
}
public String getMv004() {
return mv004;
}
public void setMv004(String mv004) {
this.mv004 = mv004;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
}
......@@ -21,12 +21,16 @@ import javax.persistence.Table;
@Table(name = "EX_ACCOUNT_INFO")
public class ExAccountInfo {
@Id
String id;
Integer id;
@ApiModelProperty("套账名称")
@Column(name = "ACCOUNT_NAME")
String accountName;
@ApiModelProperty("套账编码")
@Column(name = "ACCOUNT_CODE")
String accountCode;
@ApiModelProperty("接口地睛")
@Column(name = "API_URL")
String apiUrl;
......
......@@ -26,6 +26,9 @@ public class EntityChangeListener implements ApplicationContextAware {
private Cmsmv getCurrentActor(){
return applicationContext.getBean(CurrentActorSetter.class).getActor();
}
private String getCurrentActorStr(){
return applicationContext.getBean(CurrentActorSetter.class).getActorStr();
}
private String getCompany(){
return applicationContext.getBean(CurrentActorSetter.class).getCompany();
}
......@@ -37,8 +40,8 @@ public class EntityChangeListener implements ApplicationContextAware {
Cmsmv currentActor = getCurrentActor();
String company = getCompany();
entity.setCompany(company);
entity.setCreator(getCurrentActorStr());
if(currentActor!=null) {
entity.setCreator(currentActor.getMv001());
entity.setUsr_group(currentActor.getUsr_group());
}
entity.setCreateDate(DateUtil.currentDateTimeString());
......
......@@ -71,11 +71,10 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
if(authorization == null || authorization.isEmpty()) {
throw new RuntimeException("无Authorization,请登录");
}
if(!authorization.startsWith("Bearer ")) {
throw new RuntimeException("不支持的验证方式,请使用Bearer Token");
String token = authorization;
if(authorization.startsWith("Bearer ")) {
token = authorization.substring(7);
}
String token = authorization.substring(7);
TokenAudience tokenAudience = tokenManger.getTokenAudience(token);
CurrentActorSetter currentActorSetter = applicationContext.getBean(CurrentActorSetter.class);
currentActorSetter.setActor(tokenAudience.getActorId());
......
......@@ -20,6 +20,7 @@ public class CurrentActorManager implements CurrentActorSetter {
private Cmsmv cmsmv;
private String company;
private String usr_group;
private String actor;
private final CmsmvDao cmsmvDao;
private final AdmmfDao admmfDao;
......@@ -35,9 +36,15 @@ public class CurrentActorManager implements CurrentActorSetter {
@Override
public void setActor(String id) {
this.actor = id;
cmsmvDao.findById(id).ifPresent(i -> cmsmv = i);
}
@Override
public String getActorStr() {
return actor;
}
@Override
public void setCompany(String company) {
this.company = company;
......
......@@ -13,6 +13,7 @@ import com.topsunit.scanservice.ximai.entity.Cmsmv;
public interface CurrentActorSetter {
void setActor(String id);
Cmsmv getActor();
String getActorStr();
void setCompany(String company);
String getCompany();
......
package com.topsunit.scanservice.ximai.security;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.topsunit.scanservice.ximai.common.AppConfig;
import com.topsunit.scanservice.ximai.common.Constants;
import com.topsunit.scanservice.ximai.common.TopsunitException;
......@@ -12,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
......@@ -27,39 +30,6 @@ public class TokenService
AppConfig appConfig;
/**
* 获取用户身份信息
*
* @return 用户信息
*/
public LoginResult getLoginUser(HttpServletRequest request)
{
LoginResult rst = new LoginResult();
// 获取请求携带的令牌
String token = getToken(request);
if (StringUtils.isNotEmpty(token))
{
try
{
Claims claims = parseToken(token);
// 解析对应的权限以及用户信息
String uuid = (String) claims.get(Constants.LOGIN_USER_KEY);
String userName = (String)claims.get(Constants.JWT_USERNAME);
String userKey = getTokenKey(uuid);
rst.setMv001(userName);
rst.setMv002(userName);
rst.setToken(token);
return rst;
}
catch (Exception e)
{
throw new TopsunitException(e);
}
}
return null;
}
/**
* 从令牌中获取数据声明
*
......@@ -74,6 +44,15 @@ public class TokenService
.getBody();
}
public String generate(String id, String company) {
Date expiresAt = new Date(System.currentTimeMillis() + appConfig.getTokenExpires());
return JWT.create()
.withAudience(id, company)
.withExpiresAt(expiresAt)
.sign(Algorithm.HMAC256((id).toString()));
}
/**
* 从令牌中获取用户名
*
......@@ -119,9 +98,10 @@ public class TokenService
try
{
Claims claims = parseToken(token);
// 解析对应的权限以及用户信息
String uuid = (String) claims.get(Constants.LOGIN_USER_KEY);
String userName = (String)claims.get(Constants.JWT_USERNAME);
String userName = (String) claims.get(Constants.JWT_USERNAME);
String userKey = getTokenKey(uuid);
rst.setMv001(userName);
rst.setMv002(userName);
......
......@@ -5,18 +5,18 @@ import com.topsunit.scanservice.ximai.common.AppConfig;
import com.topsunit.scanservice.ximai.common.StringUtil;
import com.topsunit.scanservice.ximai.common.TopsunitException;
import com.topsunit.scanservice.ximai.dao.CmsmvDao;
import com.topsunit.scanservice.ximai.dao.ExAccountInfoDao;
import com.topsunit.scanservice.ximai.dto.ChangePasswordParams;
import com.topsunit.scanservice.ximai.dto.LoginParams;
import com.topsunit.scanservice.ximai.dto.LoginResult;
import com.topsunit.scanservice.ximai.dto.SetPasswordParams;
import com.topsunit.scanservice.ximai.dto.mapper.LoginMapper;
import com.topsunit.scanservice.ximai.entity.Cmsmv;
import com.topsunit.scanservice.ximai.security.CurrentActor;
import com.topsunit.scanservice.ximai.security.Encryptor;
import com.topsunit.scanservice.ximai.security.TokenManger;
import com.topsunit.scanservice.ximai.security.TokenService;
import com.topsunit.scanservice.ximai.entity.ExAccountInfo;
import com.topsunit.scanservice.ximai.security.*;
import com.topsunit.scanservice.ximai.webapi.MesLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -41,7 +41,11 @@ public class CmsmvService {
private final Encryptor encryptor;
private final AppConfig appConfig;
@Autowired
private ExAccountInfoDao exAccountInfoDao;
@Autowired
private TokenService tokenService;
@Autowired
ApplicationContext applicationContext;
public CmsmvService(CmsmvDao cmsmvDao, LoginMapper loginMapper, TokenManger tokenManger, CurrentActor currentActor, Encryptor encryptor, AppConfig appConfig) {
this.cmsmvDao = cmsmvDao;
......@@ -75,10 +79,15 @@ public class CmsmvService {
public LoginResult loginByMes(LoginParams loginParams) {
com.topsunit.scanservice.ximai.webapi.dto.LoginParams loginParams2 = BeanUtil.copyProperties(loginParams, com.topsunit.scanservice.ximai.webapi.dto.LoginParams.class);
com.topsunit.scanservice.ximai.webapi.dto.LoginResult loginResult2 = mesLoginService.login(loginParams2);
ExAccountInfo exAccountInfo = exAccountInfoDao.findById(Integer.valueOf(loginParams.getCompany())).orElseThrow(()->new TopsunitException("未找到登录账套"));
if(loginResult2.getCode()==500){
throw new TopsunitException(loginResult2.getMsg());
}
return tokenService.getUserByToken(loginResult2.getToken());
//生成扫码自生token
String newToken = tokenManger.generate(loginParams.getUsername(), exAccountInfo.getAccountCode());
LoginResult loginResult = tokenService.getUserByToken(loginResult2.getToken());
loginResult.setToken(newToken);
return loginResult;
}
@Transactional
......
......@@ -103,8 +103,9 @@ public class InvtaService {
}else{
invta.setTa009("11");
}
invta.setTa003(DateUtil.currentDateString());
String currDate = DateUtil.currentDateString();
invta.setTa003(currDate);
invta.setTa014(currDate);
int i=1;
BigDecimal total = BigDecimal.ZERO;
for(StockTransactionParams detail : data){
......@@ -126,6 +127,7 @@ public class InvtaService {
invtb.setTb009(detail.getQuantity());
//盘点仓库、库位
invtb.setTb012(detail.getWarehouse());
invtb.setTb019(currDate);
invtb.setTb029(detail.getLocation());
//判断调拨库位是否与当前一致
if(StringUtils.isNotEmpty(detail.getAllocateWarehouse()) &&
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment