feat(可回溯): 多租户
增加从配置取租户ID逻辑
This commit is contained in:
+63
@@ -0,0 +1,63 @@
|
||||
package com.wabestway.recall.trace.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import com.wabestway.recall.trace.dto.RecallApiDTO;
|
||||
import com.wabestway.recall.trace.vo.RecallApiVO;
|
||||
import com.wabestway.recall.trace.service.RecallApiApiService;
|
||||
import com.wabestway.commons.http.Paging;
|
||||
import com.wabestway.commons.http.ResObj;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author wangH
|
||||
* @company 北京华焱坤泰科技有限公司
|
||||
* @Time 2023-05-15 09:59:12
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/trace/recallApi")
|
||||
@Api(tags = {"-接口"}, description = "-接口")
|
||||
public class RecallApiController {
|
||||
@Autowired
|
||||
private RecallApiApiService recallApiApiService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
@ApiOperation(value = "分页列表查询", notes = "条件分页查询列表", httpMethod = "POST")
|
||||
public ResObj<Paging<RecallApiVO>> list(@RequestBody RecallApiDTO paramRequest) {
|
||||
return recallApiApiService.list(paramRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
@GetMapping("/info/{id}")
|
||||
@ApiOperation(value = "根据id查详情", notes = "根据id查详情", httpMethod = "GET")
|
||||
public ResObj<RecallApiVO> info(@PathVariable("id") String id) {
|
||||
return recallApiApiService.getRecallApi(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
@PostMapping("/save")
|
||||
@ApiOperation(value = "保存", notes = "保存", httpMethod = "POST")
|
||||
public ResObj saveRecallApi(@RequestBody RecallApiDTO paramRequest) {
|
||||
return recallApiApiService.saveRecallApi(paramRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
@ApiOperation(value = "修改", notes = "修改", httpMethod = "POST")
|
||||
public ResObj updateRecallApi(@RequestBody RecallApiDTO paramRequest) {
|
||||
return recallApiApiService.updateRecallApi(paramRequest);
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package com.wabestway.recall.trace.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import com.wabestway.recall.trace.dto.RecallProductDTO;
|
||||
import com.wabestway.recall.trace.vo.RecallProductVO;
|
||||
import com.wabestway.recall.trace.service.RecallProductApiService;
|
||||
import com.wabestway.commons.http.Paging;
|
||||
import com.wabestway.commons.http.ResObj;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author wangH
|
||||
* @company 北京华焱坤泰科技有限公司
|
||||
* @Time 2023-05-15 09:59:12
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/trace/recallProduct")
|
||||
@Api(tags = {"-接口"}, description = "-接口")
|
||||
public class RecallProductController {
|
||||
@Autowired
|
||||
private RecallProductApiService recallProductApiService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
@ApiOperation(value = "分页列表查询", notes = "条件分页查询列表", httpMethod = "POST")
|
||||
public ResObj<Paging<RecallProductVO>> list(@RequestBody RecallProductDTO paramRequest) {
|
||||
return recallProductApiService.list(paramRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
@GetMapping("/info/{id}")
|
||||
@ApiOperation(value = "根据id查详情", notes = "根据id查详情", httpMethod = "GET")
|
||||
public ResObj<RecallProductVO> info(@PathVariable("id") String id) {
|
||||
return recallProductApiService.getRecallProduct(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
@PostMapping("/save")
|
||||
@ApiOperation(value = "保存", notes = "保存", httpMethod = "POST")
|
||||
public ResObj saveRecallProduct(@RequestBody RecallProductDTO paramRequest) {
|
||||
return recallProductApiService.saveRecallProduct(paramRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
@ApiOperation(value = "修改", notes = "修改", httpMethod = "POST")
|
||||
public ResObj updateRecallProduct(@RequestBody RecallProductDTO paramRequest) {
|
||||
return recallProductApiService.updateRecallProduct(paramRequest);
|
||||
}
|
||||
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package com.wabestway.recall.trace.service;
|
||||
|
||||
|
||||
import com.wabestway.recall.trace.dto.RecallApiDTO;
|
||||
import com.wabestway.recall.trace.vo.RecallApiVO;
|
||||
import com.wabestway.commons.http.Paging;
|
||||
import com.wabestway.commons.http.ResObj;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author wangH
|
||||
* @company 北京华焱坤泰科技有限公司
|
||||
* @Time 2023-05-15 09:59:12
|
||||
*/
|
||||
public interface RecallApiApiService {
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @param paramReq
|
||||
* @return
|
||||
*/
|
||||
ResObj<Paging<RecallApiVO>> list(RecallApiDTO paramReq);
|
||||
|
||||
/**
|
||||
* 查询详情
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
ResObj<RecallApiVO> getRecallApi(String id);
|
||||
|
||||
/**
|
||||
* 保存
|
||||
* @param paramReq
|
||||
* @return
|
||||
*/
|
||||
ResObj saveRecallApi(RecallApiDTO paramReq);
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param paramReq
|
||||
* @return
|
||||
*/
|
||||
ResObj updateRecallApi(RecallApiDTO paramReq);
|
||||
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package com.wabestway.recall.trace.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.wabestway.recall.trace.dto.RecallProductDTO;
|
||||
import com.wabestway.recall.trace.vo.RecallProductVO;
|
||||
import com.wabestway.commons.http.Paging;
|
||||
import com.wabestway.commons.http.ResObj;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author wangH
|
||||
* @company 北京华焱坤泰科技有限公司
|
||||
* @Time 2023-05-15 09:59:12
|
||||
*/
|
||||
public interface RecallProductApiService {
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @param paramReq
|
||||
* @return
|
||||
*/
|
||||
ResObj<Paging<RecallProductVO>> list(RecallProductDTO paramReq);
|
||||
|
||||
/**
|
||||
* 查询详情
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
ResObj<RecallProductVO> getRecallProduct(String id);
|
||||
|
||||
/**
|
||||
* 保存
|
||||
* @param paramReq
|
||||
* @return
|
||||
*/
|
||||
ResObj saveRecallProduct(RecallProductDTO paramReq);
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param paramReq
|
||||
* @return
|
||||
*/
|
||||
ResObj updateRecallProduct(RecallProductDTO paramReq);
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
package com.wabestway.recall.trace.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.wabestway.commons.http.Paging;
|
||||
import com.wabestway.commons.http.ResObj;
|
||||
import com.wabestway.recall.util.HeaderDataUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import com.wabestway.ins.utils.UUIDUtil;
|
||||
import com.wabestway.recall.trace.entity.RecallApiEntity;
|
||||
import com.wabestway.recall.trace.dto.RecallApiDTO;
|
||||
import com.wabestway.recall.trace.vo.RecallApiVO;
|
||||
import com.wabestway.recall.trace.service.RecallApiApiService;
|
||||
import com.wabestway.recall.trace.service.RecallApiService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* @author wangH
|
||||
* @company 北京华焱坤泰科技有限公司
|
||||
* @Time 2023-05-15 09:59:12
|
||||
*/
|
||||
@Service
|
||||
public class RecallApiApiServiceImpl implements RecallApiApiService {
|
||||
@Autowired
|
||||
private RecallApiService recallApiService;
|
||||
|
||||
@Override
|
||||
public ResObj<Paging<RecallApiVO>> list(RecallApiDTO paramReq) {
|
||||
IPage<RecallApiVO> resultPage = recallApiService.queryRecallApiByCondition(paramReq.getPage(), paramReq.getPageSize(), paramReq);
|
||||
|
||||
Paging<RecallApiVO> paging = new Paging(resultPage.getRecords(), paramReq.getPage(), resultPage.getSize(), resultPage.getTotal());
|
||||
return ResObj.ok(paging);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResObj<RecallApiVO> getRecallApi(String id) {
|
||||
RecallApiVO recallApiVO = recallApiService.queryRecallApiById(id);
|
||||
|
||||
return ResObj.ok(recallApiVO);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public ResObj saveRecallApi(RecallApiDTO paramReq) {
|
||||
RecallApiEntity recallApi = new RecallApiEntity();
|
||||
BeanUtils.copyProperties(paramReq, recallApi);
|
||||
|
||||
recallApi.setId(UUIDUtil.generate());//赋值id
|
||||
recallApi.setTenantId(HeaderDataUtil.getTenantId());
|
||||
recallApi.setCreateBy(HeaderDataUtil.getUserId());//创建人
|
||||
recallApi.setCreateTime(System.currentTimeMillis());//创建时间
|
||||
recallApi.setUpdateBy(HeaderDataUtil.getUserId());//更新人
|
||||
recallApi.setUpdateTime(System.currentTimeMillis());//更新时间
|
||||
|
||||
recallApiService.save(recallApi);
|
||||
return ResObj.ok();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public ResObj updateRecallApi(RecallApiDTO paramReq) {
|
||||
RecallApiEntity recallApi = new RecallApiEntity();
|
||||
BeanUtils.copyProperties(paramReq, recallApi);
|
||||
recallApi.setUpdateBy(HeaderDataUtil.getUserId());//更新人
|
||||
recallApi.setUpdateTime(System.currentTimeMillis());//更新时间
|
||||
recallApiService.updateById(recallApi);
|
||||
return ResObj.ok();
|
||||
}
|
||||
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
package com.wabestway.recall.trace.service.impl;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.wabestway.commons.http.Paging;
|
||||
import com.wabestway.commons.http.ResObj;
|
||||
import com.wabestway.commons.enums.DataValidEnum;
|
||||
import com.wabestway.recall.util.HeaderDataUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import com.wabestway.ins.utils.UUIDUtil;
|
||||
import com.wabestway.recall.trace.entity.RecallProductEntity;
|
||||
import com.wabestway.recall.trace.dto.RecallProductDTO;
|
||||
import com.wabestway.recall.trace.vo.RecallProductVO;
|
||||
import com.wabestway.recall.trace.service.RecallProductApiService;
|
||||
import com.wabestway.recall.trace.service.RecallProductService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
/**
|
||||
* @author wangH
|
||||
* @company 北京华焱坤泰科技有限公司
|
||||
* @Time 2023-05-15 09:59:12
|
||||
*/
|
||||
@Service
|
||||
public class RecallProductApiServiceImpl implements RecallProductApiService {
|
||||
@Autowired
|
||||
private RecallProductService recallProductService;
|
||||
|
||||
@Override
|
||||
public ResObj<Paging<RecallProductVO>> list(RecallProductDTO paramReq) {
|
||||
IPage<RecallProductVO> resultPage = recallProductService.queryRecallProductByCondition(paramReq.getPage(), paramReq.getPageSize(), paramReq);
|
||||
|
||||
Paging<RecallProductVO> paging = new Paging(resultPage.getRecords(), paramReq.getPage(), resultPage.getSize(), resultPage.getTotal());
|
||||
return ResObj.ok(paging);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResObj<RecallProductVO> getRecallProduct(String id) {
|
||||
RecallProductVO recallProductVO = recallProductService.queryRecallProductById(id);
|
||||
|
||||
return ResObj.ok(recallProductVO);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public ResObj saveRecallProduct(RecallProductDTO paramReq) {
|
||||
RecallProductEntity recallProduct = new RecallProductEntity();
|
||||
BeanUtils.copyProperties(paramReq, recallProduct);
|
||||
|
||||
recallProduct.setId(UUIDUtil.generate());//赋值id
|
||||
recallProduct.setCreateBy(HeaderDataUtil.getUserId());//创建人
|
||||
recallProduct.setCreateTime(System.currentTimeMillis());//创建时间
|
||||
recallProduct.setUpdateBy(HeaderDataUtil.getUserId());//更新人
|
||||
recallProduct.setUpdateTime(System.currentTimeMillis());//更新时间
|
||||
|
||||
recallProductService.save(recallProduct);
|
||||
return ResObj.ok();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public ResObj updateRecallProduct(RecallProductDTO paramReq) {
|
||||
RecallProductEntity recallProduct = new RecallProductEntity();
|
||||
BeanUtils.copyProperties(paramReq, recallProduct);
|
||||
recallProduct.setUpdateBy(HeaderDataUtil.getUserId());//更新人
|
||||
recallProduct.setUpdateTime(System.currentTimeMillis());//更新时间
|
||||
recallProductService.updateById(recallProduct);
|
||||
return ResObj.ok();
|
||||
}
|
||||
|
||||
}
|
||||
+7
@@ -7,6 +7,7 @@ import com.wabestway.commons.http.ResObj;
|
||||
import com.wabestway.recall.trace.dto.TraceDTO;
|
||||
import com.wabestway.recall.trace.entity.RecallOrderEntity;
|
||||
import com.wabestway.recall.trace.entity.RecallRecordEntity;
|
||||
import com.wabestway.recall.trace.service.RecallApiService;
|
||||
import com.wabestway.recall.trace.service.RecallOrderService;
|
||||
import com.wabestway.recall.trace.service.RecallRecordService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -32,6 +33,8 @@ public class RecallRecordApiServiceImpl implements RecallRecordApiService {
|
||||
private RecallRecordService recallRecordService;
|
||||
@Autowired
|
||||
private RecallOrderService recallOrderService;
|
||||
@Autowired
|
||||
private RecallApiService recallApiService;
|
||||
|
||||
@Override
|
||||
public ResObj save(TraceDTO record) {
|
||||
@@ -55,6 +58,10 @@ public class RecallRecordApiServiceImpl implements RecallRecordApiService {
|
||||
newOrder.setAppKey(record.getAppKey());
|
||||
newOrder.setArchived("0");
|
||||
newOrder.setComplete(isLastEvent ? "1" : "0");
|
||||
String tenantId = recallApiService.queryApiTenant(record.getAppKey());
|
||||
if (tenantId != null) {
|
||||
newOrder.setTenantId(tenantId);
|
||||
}
|
||||
if (isLastEvent) {
|
||||
newOrder.setCompleteDate(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
package com.wabestway.recall.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.wabestway.auth.api.user.ReqOrgInfo;
|
||||
import com.wabestway.auth.api.user.ReqTenantInfo;
|
||||
import com.wabestway.auth.api.user.ReqUser;
|
||||
import com.wabestway.auth.api.user.TokenObj;
|
||||
import com.wabestway.commons.exception.AlertException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.net.URLDecoder;
|
||||
|
||||
public class HeaderDataUtil {
|
||||
private static Logger logger = LoggerFactory.getLogger(HeaderDataUtil.class);
|
||||
|
||||
public HeaderDataUtil() {
|
||||
}
|
||||
|
||||
public static ReqUser getUserData() {
|
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
|
||||
.getRequest();
|
||||
ReqUser reqUser = null;
|
||||
try {
|
||||
String header = request.getHeader(TokenObj._USER);
|
||||
if (header != null) {
|
||||
String str = URLDecoder.decode(header, "UTF-8");
|
||||
logger.info("用户信息:{}", str);
|
||||
reqUser = new Gson().fromJson(str, ReqUser.class);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("用户信息转化异常", e);
|
||||
throw new AlertException("未获取到header用户信息!");
|
||||
}
|
||||
|
||||
return reqUser;
|
||||
}
|
||||
|
||||
public static ReqOrgInfo getOrgInfoData() {
|
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
|
||||
.getRequest();
|
||||
ReqOrgInfo orgInfo = null;
|
||||
try {
|
||||
String header = request.getHeader(TokenObj._ORG);
|
||||
if (header != null) {
|
||||
String str = URLDecoder.decode(header, "UTF-8");
|
||||
logger.info("机构信息:{}", str);
|
||||
orgInfo = new Gson().fromJson(str, ReqOrgInfo.class);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("机构信息转化异常", e);
|
||||
throw new AlertException("未获取到header机构信息!");
|
||||
}
|
||||
|
||||
return orgInfo;
|
||||
}
|
||||
|
||||
public static ReqTenantInfo getTenantData() {
|
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
|
||||
.getRequest();
|
||||
ReqTenantInfo tenant = null;
|
||||
try {
|
||||
String header = request.getHeader(TokenObj._TENANT);
|
||||
if (header != null) {
|
||||
String str = URLDecoder.decode(header, "UTF-8");
|
||||
logger.info("机构信息:{}", str);
|
||||
tenant = new Gson().fromJson(str, ReqTenantInfo.class);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("租户信息转化异常", e);
|
||||
}
|
||||
|
||||
return tenant;
|
||||
}
|
||||
|
||||
public static String getUserId() {
|
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
|
||||
.getRequest();
|
||||
String userId = null;
|
||||
try {
|
||||
String header = request.getHeader(TokenObj._USERID);
|
||||
if (header != null) {
|
||||
userId = URLDecoder.decode(header, "UTF-8");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("用户ID信息转化异常", e);
|
||||
}
|
||||
|
||||
return userId;
|
||||
}
|
||||
|
||||
public static String getTenantId() {
|
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
|
||||
.getRequest();
|
||||
String tenantId = null;
|
||||
|
||||
try {
|
||||
String header = request.getHeader(TokenObj._TENANTID);
|
||||
if (header != null) {
|
||||
tenantId = URLDecoder.decode(header, "UTF-8");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("租户id信息转化异常", e);
|
||||
}
|
||||
|
||||
return tenantId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user