Commit 2ab6cb74 by guojuxing

新增门店选择器更改权限范围接口

parent 273f17a9
...@@ -130,11 +130,36 @@ public class StoreController { ...@@ -130,11 +130,36 @@ public class StoreController {
return RestResponse.success(response.getResult()); return RestResponse.success(response.getResult());
} }
/**
* 更新权限范围
* @param storeWidgetId
* @param authSearchParam
* @return
*/
@RequestMapping("update-auth-search-param")
public RestResponse updateAuth(Integer storeWidgetId, String authSearchParam) {
StoreWidgetDTO storeWidgetDTO = new StoreWidgetDTO();
storeWidgetDTO.setStoreWidgetId(storeWidgetId);
storeWidgetDTO.setAuthSearchParam(authSearchParam);
ServiceResponse<Integer> response = storeWidgetApiService.updateAuth(storeWidgetDTO);
if (response.isSuccess()) {
//写日志
storeWidgetLogUtils.saveStoreWidgetWhenEditAuth(storeWidgetId, authSearchParam);
return RestResponse.success();
}
return RestResponse.failure(response.getCode(), response.getMessage());
}
@RequestMapping("save-store-widget") @RequestMapping("save-store-widget")
public RestResponse saveStoreWidget(@RequestBody StoreWidgetQO storeWidgetQO){ public RestResponse saveStoreWidget(@RequestBody StoreWidgetQO storeWidgetQO){
//参数组装 //参数组装
StoreWidgetDTO storeWidgetDTO = new StoreWidgetDTO(); StoreWidgetDTO storeWidgetDTO = new StoreWidgetDTO();
storeWidgetDTO.setAuthSearchParam(storeWidgetQO.getAuthSearchParam()); //前端约定了,该字段不会传值
//问题:跟下面写日志接口有重合调用查询旧纪录接口
storeWidgetDTO.setAuthSearchParam(storeWidgetLogUtils.getAuthSearchParamData(
storeWidgetQO.getStoreWidgetId(),
storeWidgetQO.getAuthSearchParam()));
storeWidgetDTO.setSearchParam(storeWidgetQO.getSearchParam()); storeWidgetDTO.setSearchParam(storeWidgetQO.getSearchParam());
storeWidgetDTO.setStoreWidgetId(storeWidgetQO.getStoreWidgetId()); storeWidgetDTO.setStoreWidgetId(storeWidgetQO.getStoreWidgetId());
storeWidgetDTO.setStoreWidgetId(null); storeWidgetDTO.setStoreWidgetId(null);
......
package com.gic.plug.web.utils; package com.gic.plug.web.utils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -21,6 +23,7 @@ import com.gic.store.service.StoreWidgetLogApiService; ...@@ -21,6 +23,7 @@ import com.gic.store.service.StoreWidgetLogApiService;
*/ */
@Component @Component
public class StoreWidgetLogUtils { public class StoreWidgetLogUtils {
private static Logger logger = LogManager.getLogger(StoreWidgetLogUtils.class);
@Autowired @Autowired
private StoreWidgetLogApiService storeWidgetLogApiService; private StoreWidgetLogApiService storeWidgetLogApiService;
@Autowired @Autowired
...@@ -34,15 +37,7 @@ public class StoreWidgetLogUtils { ...@@ -34,15 +37,7 @@ public class StoreWidgetLogUtils {
public void saveStoreWidgetLog(StoreWidgetQO storeWidgetQO, Integer newStoreWidgetId) { public void saveStoreWidgetLog(StoreWidgetQO storeWidgetQO, Integer newStoreWidgetId) {
Integer storeWidgetId = storeWidgetQO.getStoreWidgetId(); Integer storeWidgetId = storeWidgetQO.getStoreWidgetId();
//如果是编辑,则会有值,用于判断创建还是编辑 //如果是编辑,则会有值,用于判断创建还是编辑
StoreWidgetDTO oldStoreWidget = null; StoreWidgetDTO oldStoreWidget = getOldStoreWidget(storeWidgetId);
if (storeWidgetId != null) {
ServiceResponse<StoreWidgetDTO> oldStoreWidgetResponse = storeWidgetApiService.getStoreWidget(storeWidgetId);
if (!oldStoreWidgetResponse.isSuccess()) {
return;
}
oldStoreWidget = oldStoreWidgetResponse.getResult();
}
//操作日志对象组装 //操作日志对象组装
StoreWidgetLogSaveDTO logSaveDTO; StoreWidgetLogSaveDTO logSaveDTO;
...@@ -58,6 +53,52 @@ public class StoreWidgetLogUtils { ...@@ -58,6 +53,52 @@ public class StoreWidgetLogUtils {
} }
/** /**
* 因为该字段和其他数据分离开来,需要根据ID查询旧记录数据
* @param storeWidgetId
* @param authSearchParam
* @return
*/
public String getAuthSearchParamData(Integer storeWidgetId, String authSearchParam) {
if (StringUtils.isBlank(authSearchParam)) {
StoreWidgetDTO oldStoreWidget = getOldStoreWidget(storeWidgetId);
if (oldStoreWidget != null) {
return oldStoreWidget.getAuthSearchParam();
}
}
return authSearchParam;
}
/**
* 只更新权限范围数据的日志
* @param storeWidgetId
* @param authSearchParam
*/
public void saveStoreWidgetWhenEditAuth(Integer storeWidgetId, String authSearchParam) {
StoreWidgetDTO oldStoreWidget = getOldStoreWidget(storeWidgetId);
if (oldStoreWidget != null) {
//操作日志对象组装
StoreWidgetQO storeWidgetQO = new StoreWidgetQO();
storeWidgetQO.setAuthSearchParam(authSearchParam);
StoreWidgetLogSaveDTO logSaveDTO = buildStoreWidgetLogWhenUpdate(oldStoreWidget, storeWidgetQO, storeWidgetId);
//写日志
storeWidgetLogApiService.saveStoreWidgetLog(logSaveDTO);
}
}
private StoreWidgetDTO getOldStoreWidget(Integer storeWidgetId) {
if (storeWidgetId == null) {
return null;
}
ServiceResponse<StoreWidgetDTO> oldStoreWidgetResponse = storeWidgetApiService.getStoreWidget(storeWidgetId);
if (!oldStoreWidgetResponse.isSuccess()) {
logger.info("根据门店选择器ID:{},查询不到记录", storeWidgetId);
return null;
}
return oldStoreWidgetResponse.getResult();
}
/**
* 组装日志对象-编辑场景 * 组装日志对象-编辑场景
* @param oldStoreWidget 老数据 * @param oldStoreWidget 老数据
* @param storeWidgetQO 前端传入的参数 * @param storeWidgetQO 前端传入的参数
...@@ -66,9 +107,6 @@ public class StoreWidgetLogUtils { ...@@ -66,9 +107,6 @@ public class StoreWidgetLogUtils {
*/ */
private static StoreWidgetLogSaveDTO buildStoreWidgetLogWhenUpdate(StoreWidgetDTO oldStoreWidget, StoreWidgetQO storeWidgetQO, private static StoreWidgetLogSaveDTO buildStoreWidgetLogWhenUpdate(StoreWidgetDTO oldStoreWidget, StoreWidgetQO storeWidgetQO,
Integer newStoreWidgetId) { Integer newStoreWidgetId) {
if (oldStoreWidget == null) {
return null;
}
String authSearchParam = storeWidgetQO.getAuthSearchParam(); String authSearchParam = storeWidgetQO.getAuthSearchParam();
String searchParam = storeWidgetQO.getSearchParam(); String searchParam = storeWidgetQO.getSearchParam();
...@@ -91,9 +129,10 @@ public class StoreWidgetLogUtils { ...@@ -91,9 +129,10 @@ public class StoreWidgetLogUtils {
} else { } else {
//权限变更范围类型 //权限变更范围类型
logSaveDTO.setLogType(1); logSaveDTO.setLogType(1);
//记录变更前的权限范围数据
logSaveDTO.setSearchParamBefore(oldStoreWidget.getAuthSearchParam()); logSaveDTO.setSearchParamBefore(oldStoreWidget.getAuthSearchParam());
if (StringUtils.isNotBlank(authSearchParam)) { if (StringUtils.isNotBlank(authSearchParam)) {
//记录变更后的权限范围数据
logSaveDTO.setSearchParamAfter(authSearchParam); logSaveDTO.setSearchParamAfter(authSearchParam);
} }
} }
......
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