Compare commits
10 Commits
c759c8bc55
...
6f072b97c9
| Author | SHA1 | Date |
|---|---|---|
|
|
6f072b97c9 | |
|
|
ab03f70fd6 | |
|
|
6776fe3f0d | |
|
|
3951ef325d | |
|
|
e1643a6331 | |
|
|
b3e5568216 | |
|
|
cc29006013 | |
|
|
db343353cc | |
|
|
01cd03213e | |
|
|
7a6abccf2f |
|
|
@ -9,42 +9,87 @@ import org.apache.shiro.subject.SimplePrincipalCollection;
|
|||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.utils.bean.BeanUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* shiro 工具类
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class ShiroUtils
|
||||
{
|
||||
public static Subject getSubject()
|
||||
{
|
||||
public class ShiroUtils {
|
||||
|
||||
public static final String NEX_API_KEY = "user_101_eaeff0d63a104271";
|
||||
public static Subject getSubject() {
|
||||
return SecurityUtils.getSubject();
|
||||
}
|
||||
|
||||
public static Session getSession()
|
||||
{
|
||||
public static Session getSession() {
|
||||
return SecurityUtils.getSubject().getSession();
|
||||
}
|
||||
|
||||
public static void logout()
|
||||
{
|
||||
public static void logout() {
|
||||
getSubject().logout();
|
||||
}
|
||||
|
||||
public static SysUser getSysUser()
|
||||
{
|
||||
public static SysUser getSysUser() {
|
||||
Subject subject = getSubject();
|
||||
|
||||
// 检查是否是API Key认证
|
||||
Object principal = subject.getPrincipal();
|
||||
|
||||
// 传统方式获取用户
|
||||
SysUser user = null;
|
||||
Object obj = getSubject().getPrincipal();
|
||||
if (StringUtils.isNotNull(obj))
|
||||
{
|
||||
if (StringUtils.isNotNull(principal)) {
|
||||
user = new SysUser();
|
||||
BeanUtils.copyBeanProp(user, obj);
|
||||
BeanUtils.copyBeanProp(user, principal);
|
||||
return user;
|
||||
}
|
||||
// 检查是否是API Key请求
|
||||
HttpServletRequest request = ServletUtils.getRequest();
|
||||
String apiKey = request.getHeader("X-API-Key");
|
||||
if (StringUtils.isNotEmpty(apiKey)&& NEX_API_KEY.equals(apiKey)) {
|
||||
return loadUserById();
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
public static void setSysUser(SysUser user)
|
||||
{
|
||||
/**
|
||||
* 验证API Key并返回对应的用户ID
|
||||
*/
|
||||
private static Long validateApiKey(String apiKey) {
|
||||
// 查询数据库验证API Key,并返回对应的用户ID
|
||||
// 这里应该查询API Key表,获取关联的用户ID
|
||||
// 例如: select user_id from sys_api_key where api_key = ? and status = 'A'
|
||||
return 101L;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID加载用户信息
|
||||
*/
|
||||
private static SysUser loadUserById() {
|
||||
// 从数据库加载用户信息
|
||||
// 例如: select * from sys_user where user_id = ?
|
||||
SysUser user = new SysUser();
|
||||
user.setUserId(101L);
|
||||
user.setUserName("乐喽ch");
|
||||
user.setLoginName("leoloch");
|
||||
return user;
|
||||
}
|
||||
|
||||
// public static SysUser getSysUser()
|
||||
// {
|
||||
// SysUser user = null;
|
||||
// Object obj = getSubject().getPrincipal();
|
||||
// if (StringUtils.isNotNull(obj))
|
||||
// {
|
||||
// user = new SysUser();
|
||||
// BeanUtils.copyBeanProp(user, obj);
|
||||
// }
|
||||
// return user;
|
||||
// }
|
||||
|
||||
public static void setSysUser(SysUser user) {
|
||||
Subject subject = getSubject();
|
||||
PrincipalCollection principalCollection = subject.getPrincipals();
|
||||
String realmName = principalCollection.getRealmNames().iterator().next();
|
||||
|
|
@ -53,34 +98,45 @@ public class ShiroUtils
|
|||
subject.runAs(newPrincipalCollection);
|
||||
}
|
||||
|
||||
public static Long getUserId()
|
||||
{
|
||||
public static Long getUserId() {
|
||||
return getSysUser().getUserId().longValue();
|
||||
}
|
||||
|
||||
public static String getLoginName()
|
||||
{
|
||||
public static String getLoginName() {
|
||||
return getSysUser().getLoginName();
|
||||
}
|
||||
|
||||
public static String getIp()
|
||||
{
|
||||
public static String getIp() {
|
||||
return StringUtils.substring(getSubject().getSession().getHost(), 0, 128);
|
||||
}
|
||||
|
||||
public static String getSessionId()
|
||||
{
|
||||
public static String getSessionId() {
|
||||
return String.valueOf(getSubject().getSession().getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成随机盐
|
||||
*/
|
||||
public static String randomSalt()
|
||||
{
|
||||
public static String randomSalt() {
|
||||
// 一个Byte占两个字节,此处生成的3字节,字符串长度为6
|
||||
SecureRandomNumberGenerator secureRandom = new SecureRandomNumberGenerator();
|
||||
String hex = secureRandom.nextBytes(3).toHex();
|
||||
return hex;
|
||||
}
|
||||
|
||||
public static void genApiKey() {
|
||||
// 为用户ID 101 生成的 API Key
|
||||
String apiKey = "user_101_" + UUID.randomUUID().toString().replace("-", "").substring(0, 16);
|
||||
String apiSecret = UUID.randomUUID().toString().replace("-", "");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 为用户ID 101 生成的 API Key
|
||||
String apiKey = "user_101_" + UUID.randomUUID().toString().replace("-", "").substring(0, 16);
|
||||
String apiSecret = UUID.randomUUID().toString().replace("-", "");
|
||||
System.out.println("apiKey");
|
||||
System.out.println(apiKey);
|
||||
System.out.println("apiSecret");
|
||||
System.out.println(apiSecret);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
|
|||
import com.ruoyi.common.enums.ApproveStatusEnum;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.sip.domain.AddToNexReq;
|
||||
import com.ruoyi.sip.domain.OmsPurchaseOrder;
|
||||
import com.ruoyi.sip.domain.VendorInfo;
|
||||
import com.ruoyi.sip.dto.inventory.OmsPurchaseOrderItemDto;
|
||||
|
|
@ -251,10 +252,32 @@ public class OmsPurchaseOrderController extends BaseController
|
|||
return toAjax(omsPurchaseOrderService.deleteOmsPurchaseOrderByIds(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加到下一个采购单
|
||||
*/
|
||||
@Anonymous
|
||||
@Log(title = "采购单主表", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/addToNex")
|
||||
public AjaxResult addToNex(@RequestBody AddToNexReq addToNexReq) {
|
||||
return success(omsPurchaseOrderService.addToNex(addToNexReq));
|
||||
}
|
||||
|
||||
@Anonymous
|
||||
@GetMapping("/approveStatus")
|
||||
public AjaxResult getApproveStatus(@RequestParam Long id)
|
||||
{
|
||||
OmsPurchaseOrder order = omsPurchaseOrderService.selectOmsPurchaseOrderById(id);
|
||||
if (order != null) {
|
||||
return success(order.getApproveStatus());
|
||||
} else {
|
||||
return error("未找到对应的采购单信息");
|
||||
}
|
||||
}
|
||||
|
||||
@Anonymous
|
||||
@GetMapping("/test")
|
||||
public String test(HttpServletResponse response)
|
||||
{
|
||||
public String test() {
|
||||
return "ok";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
package com.ruoyi.sip.domain;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 添加到下一个采购单请求对象
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Data
|
||||
public class AddToNexReq {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 产品类型 */
|
||||
private String productType;
|
||||
|
||||
/** 产品编码 */
|
||||
private String productCode;
|
||||
|
||||
/** 数量 */
|
||||
@NotNull(message = "数量不能为空")
|
||||
private Integer quantity;
|
||||
|
||||
/** 价格 */
|
||||
private BigDecimal price;
|
||||
|
||||
/** 税率 */
|
||||
private BigDecimal taxRate;
|
||||
|
||||
/** 税额 */
|
||||
private BigDecimal taxTotal;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package com.ruoyi.sip.domain;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 添加到下一个采购单请求对象
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Data
|
||||
public class AddToNexRes {
|
||||
|
||||
|
||||
/** 采购单id */
|
||||
private Long PurchaseId;
|
||||
|
||||
/** 采购单号(系统生成) */
|
||||
private String purchaseNo;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
package com.ruoyi.sip.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.sip.domain.AddToNexReq;
|
||||
import com.ruoyi.sip.domain.AddToNexRes;
|
||||
import com.ruoyi.sip.domain.OmsPurchaseOrder;
|
||||
import com.ruoyi.sip.domain.OmsPurchaseOrderItem;
|
||||
import com.ruoyi.sip.dto.inventory.OmsPurchaseOrderItemDto;
|
||||
|
|
@ -97,4 +100,6 @@ public interface IOmsPurchaseOrderService
|
|||
void cancelInnerItem(List<OmsPurchaseOrderItem> omsPurchaseOrderItems);
|
||||
|
||||
OmsPurchaseOrder selectOmsPurchaseOrderByNo(String purchaseNo);
|
||||
|
||||
AddToNexRes addToNex(AddToNexReq addToNexReq);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import java.util.stream.Collectors;
|
|||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.enums.ApproveStatusEnum;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
|
|
@ -21,7 +22,9 @@ import com.ruoyi.sip.flowable.service.TodoCommonTemplate;
|
|||
import com.ruoyi.sip.flowable.service.TodoService;
|
||||
import com.ruoyi.sip.mapper.OmsPurchaseOrderItemHistoryMapper;
|
||||
import com.ruoyi.sip.mapper.OmsPurchaseOrderHistoryMapper;
|
||||
import com.ruoyi.sip.mapper.VendorInfoMapper;
|
||||
import com.ruoyi.sip.service.*;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.flowable.engine.ManagementService;
|
||||
|
|
@ -60,6 +63,12 @@ public class OmsPurchaseOrderServiceImpl implements IOmsPurchaseOrderService, To
|
|||
@Resource
|
||||
private OmsPurchaseOrderItemHistoryMapper omsPurchaseOrderItemHistoryMapper;
|
||||
|
||||
@Resource
|
||||
private VendorInfoMapper vendorInfoMapper;
|
||||
|
||||
@Resource
|
||||
private SysUserMapper userMapper;
|
||||
|
||||
@Autowired
|
||||
private ICnareaService cnareaService;
|
||||
@Autowired
|
||||
|
|
@ -566,5 +575,72 @@ public class OmsPurchaseOrderServiceImpl implements IOmsPurchaseOrderService, To
|
|||
|
||||
return omsPurchaseOrder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AddToNexRes addToNex(AddToNexReq addToNexReq) {
|
||||
SysUser sysUser = getSysUser();
|
||||
// 新增采购
|
||||
OmsPurchaseOrder omsPurchaseOrder = new OmsPurchaseOrder();
|
||||
// 设置采购订单基本信息
|
||||
omsPurchaseOrder.setBuyerName("紫光汇智信息技术有限公司");
|
||||
omsPurchaseOrder.setBuyerAddress("重庆市两江新区云杉南路6号涉外商务区B6栋7楼");
|
||||
omsPurchaseOrder.setRemark("nex授权申请流程");
|
||||
// 查询制造商id, 制造商编码P008
|
||||
VendorInfo vendorInfo = vendorInfoMapper.selectVendorInfoByVendorCode("P002");
|
||||
omsPurchaseOrder.setVendorId(vendorInfo == null ? null :vendorInfo.getVendorId());
|
||||
omsPurchaseOrder.setCurrency("RMB");
|
||||
// 采购员:userName=徐心钰
|
||||
SysUser user = userMapper.selectUserByLoginName("xuxinyu");
|
||||
if(user == null){
|
||||
user = userMapper.selectUserById(1L);
|
||||
}
|
||||
omsPurchaseOrder.setPurchaserId(user.getUserId());
|
||||
omsPurchaseOrder.setPurchaserName(user.getUserName());
|
||||
omsPurchaseOrder.setPurchaserMobile("");
|
||||
omsPurchaseOrder.setPurchaserEmail("");
|
||||
// 入库仓id
|
||||
omsPurchaseOrder.setWarehouseId(3L);
|
||||
omsPurchaseOrder.setPayMethod("1");
|
||||
omsPurchaseOrder.setOwnerId(102L);
|
||||
omsPurchaseOrder.setOwnerName("叶宇豪");
|
||||
omsPurchaseOrder.setTotalAmount(new BigDecimal("1000"));
|
||||
omsPurchaseOrder.setStatus(OmsPurchaseOrder.StatusEnum.WAIT_COMPLETED.getCode()); // 0
|
||||
omsPurchaseOrder.setApproveStatus(ApproveStatusEnum.WAIT_COMMIT.getCode()); // 0
|
||||
|
||||
// 创建采购订单明细项
|
||||
OmsPurchaseOrderItem orderItem = new OmsPurchaseOrderItem();
|
||||
orderItem.setProductType(addToNexReq.getProductType());
|
||||
orderItem.setProductCode(addToNexReq.getProductCode());
|
||||
orderItem.setQuantity(new BigDecimal(addToNexReq.getQuantity()));
|
||||
orderItem.setPrice(addToNexReq.getPrice());
|
||||
orderItem.setTaxRate(addToNexReq.getTaxRate());
|
||||
orderItem.setTaxTotal(addToNexReq.getTaxTotal());
|
||||
|
||||
// 根据传入的参数计算金额
|
||||
BigDecimal amountTotal = addToNexReq.getPrice() != null && addToNexReq.getQuantity() != null
|
||||
? addToNexReq.getPrice().multiply(new BigDecimal(addToNexReq.getQuantity()))
|
||||
: BigDecimal.ZERO;
|
||||
orderItem.setAmountTotal(amountTotal);
|
||||
|
||||
// 设置明细项到订单中
|
||||
List<OmsPurchaseOrderItem> orderItemList = new ArrayList<>();
|
||||
orderItemList.add(orderItem);
|
||||
omsPurchaseOrder.setOmsPurchaseOrderItemList(orderItemList);
|
||||
|
||||
// 插入采购订单
|
||||
int insertResult = insertOmsPurchaseOrder(omsPurchaseOrder);
|
||||
if(insertResult != 1){
|
||||
throw new ServiceException("新增采购失败");
|
||||
}
|
||||
// 触发线上流程
|
||||
omsPurchaseOrder.setFlowType(OmsPurchaseOrder.FlowTypeEnum.ONLINE.getCode());
|
||||
omsPurchaseOrder.setApproveStatus("1");
|
||||
applyForPurchaseOrder(omsPurchaseOrder);
|
||||
|
||||
AddToNexRes res = new AddToNexRes();
|
||||
res.setPurchaseId(omsPurchaseOrder.getId());
|
||||
res.setPurchaseNo(omsPurchaseOrder.getPurchaseNo());
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue