/**
public class CellChangeLog implements ChangeLog {
/**
* 保存操作日志
*
* @param invocation 目标方法
* @throws Throwable
*/
@Override
public void saveOperateLog(Invocation invocation) throws Throwable {
Executor executor = (Executor) invocation.getTarget();
Object[] args = invocation.getArgs();
MappedStatement ms = (MappedStatement) args[0];
Object obj = args[1];
MappedStatement mappedStatement;
if (obj instanceof WimsCellBatchOper) {
//针对仓位信息页面启用、禁用、删除操作
WimsCellBatchOper wimsCellBatchOper = (WimsCellBatchOper) obj;
mappedStatement = ms.getConfiguration().getMappedStatement("com.fpx.wims.mapper.IWimsCellMapper.getList");
List<WimsCell> resultList = executor.query(mappedStatement, args[1], RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
if (CollectionUtils.isNotEmpty(resultList)) {
List<WimsChangeLog> logList = new ArrayList<>();
String targetStatus = wimsCellBatchOper.getStatus();
String desc = EnumOperateType.getOperateType(targetStatus);
for (WimsCell wimsCell : resultList) {
WimsChangeLog wimsChangeLog = new WimsChangeLog();
wimsChangeLog.setTableName("wims_cell");
wimsChangeLog.setColumnId(wimsCell.getId());
wimsChangeLog.setColumnValue(wimsCell.getCellCode());
wimsChangeLog.setOperateNo(UserUtils.getUserName());
wimsChangeLog.setOperator("");
wimsChangeLog.setType(targetStatus);
wimsChangeLog.setContent(String.format("%s了(%s)仓位", desc, wimsCell.getCellCode()));
logList.add(wimsChangeLog);
}
DefaultSqlSession.StrictMap<Object> changeMap = new DefaultSqlSession.StrictMap<>();
changeMap.put("collection", logList);
changeMap.put("list", logList);
MappedStatement statement = ms.getConfiguration().getMappedStatement("com.fpx.wims.entity.base.saveBatchLog");
executor.update(statement, changeMap);
}
} else if (obj instanceof WimsCell) {
//编辑和批量导入更新操作
WimsCell targetInfo = (WimsCell) obj;
mappedStatement = ms.getConfiguration().getMappedStatement("com.fpx.wims.mapper.IWimsCellMapper.getWimsCellByCondition");
if (targetInfo.getId() != null) {
WimsCell query = new WimsCell();
query.setId(targetInfo.getId());
obj = query;
}
List<WimsCell> resultList = executor.query(mappedStatement, obj, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
execute(resultList, executor, mappedStatement, targetInfo);
} else if (obj instanceof WimsCellStatusBatchOper) {
//批量启用禁用操作
WimsCellStatusBatchOper wimsCellStatusBatchOper = (WimsCellStatusBatchOper) obj;
List<WimsCell> targetInfoList = wimsCellStatusBatchOper.getWimsCellList();
mappedStatement = ms.getConfiguration().getMappedStatement("com.fpx.wims.mapper.IWimsCellMapper.getWimsCell");
List<WimsCell> resultList = executor.query(mappedStatement, wimsCellStatusBatchOper, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
if (CollectionUtils.isNotEmpty(resultList) && (resultList.size() == targetInfoList.size())) {
List<WimsChangeLog> logList = new ArrayList<>();
for (int i = 0; i < resultList.size(); i++) {
WimsChangeLog wimsChangeLog = compareAndSetData(targetInfoList.get(i), resultList.get(i));
if (wimsChangeLog != null) {
logList.add(wimsChangeLog);
}
}
saveLog(logList, executor, mappedStatement);
}
}
}
private void execute(List<WimsCell> resultList, Executor executor, MappedStatement mappedStatement, WimsCell targetInfo) throws Throwable {
if (CollectionUtils.isNotEmpty(resultList)) {
List<WimsChangeLog> logList = new ArrayList<>();
for (WimsCell sourceInfo : resultList) {
WimsChangeLog wimsChangeLog = compareAndSetData(targetInfo, sourceInfo);
if (wimsChangeLog != null) {
logList.add(wimsChangeLog);
}
}
saveLog(logList, executor, mappedStatement);
}
}
private void saveLog(List<WimsChangeLog> logList, Executor executor, MappedStatement mappedStatement) throws SQLException {
if (CollectionUtils.isNotEmpty(logList)) {
DefaultSqlSession.StrictMap<Object> changeMap = new DefaultSqlSession.StrictMap<>();
changeMap.put("collection", logList);
changeMap.put("list", logList);
MappedStatement statement = mappedStatement.getConfiguration().getMappedStatement("com.fpx.wims.entity.base.saveBatchLog");
executor.update(statement, changeMap);
}
}
/**
* 组装日志对象
*
* @param targetInfo 页面传过来的对象
* @param sourceInfo 数据查询出来的对象
* @return 日志对象
*/
private WimsChangeLog compareAndSetData(WimsCell targetInfo, WimsCell sourceInfo) {
WimsChangeLog wimsChangeLog = new WimsChangeLog();
List<String> builder = new ArrayList<>(13);
if (targetInfo.getRegionName() != null && !targetInfo.getRegionName().equals(sourceInfo.getRegionName())) {
builder.add(String.format("将库区名称由(%s)改为(%s)", sourceInfo.getRegionName(), targetInfo.getRegionName()));
}
if (targetInfo.getCellLenght() != null && !targetInfo.getCellLenght().equals(sourceInfo.getCellLenght())) {
builder.add(String.format("将库位长度由(%s)改为(%s)", sourceInfo.getCellLenght(), targetInfo.getCellLenght()));
}
if (targetInfo.getCellBreadth() != null && !targetInfo.getCellBreadth().equals(sourceInfo.getCellBreadth())) {
builder.add(String.format("将库位宽度由(%s)改为(%s)", sourceInfo.getCellBreadth(), targetInfo.getCellBreadth()));
}
if (targetInfo.getCellHeight() != null && !targetInfo.getCellHeight().equals(sourceInfo.getCellHeight())) {
builder.add(String.format("将库位高度由(%s)改为(%s)", sourceInfo.getCellHeight(), targetInfo.getCellHeight()));
}
if (targetInfo.getWeightMax() != null && !targetInfo.getWeightMax().equals(sourceInfo.getWeightMax())) {
builder.add(String.format("将可支持重量由(%s)改为(%s)", sourceInfo.getWeightMax(), targetInfo.getWeightMax()));
}
if (targetInfo.getVolumeMax() != null && !targetInfo.getVolumeMax().equals(sourceInfo.getVolumeMax())) {
builder.add(String.format("将可支持体积由(%s)改为(%s)", sourceInfo.getVolumeMax(), targetInfo.getVolumeMax()));
}
if (targetInfo.getOnShelfPriority() != null && !targetInfo.getOnShelfPriority().equals(sourceInfo.getOnShelfPriority())) {
builder.add(String.format("将上架优先级由(%s)改为(%s)", sourceInfo.getOnShelfPriority(), targetInfo.getOnShelfPriority()));
}
if (targetInfo.getOffShelfPriority() != null && !targetInfo.getOffShelfPriority().equals(sourceInfo.getOffShelfPriority())) {
builder.add(String.format("将下架优先级由(%s)改为(%s)", sourceInfo.getOffShelfPriority(), targetInfo.getOffShelfPriority()));
}
if (targetInfo.getPickingSerial() != null && !targetInfo.getPickingSerial().equals(sourceInfo.getPickingSerial())) {
builder.add(String.format("将拣货序号由(%s)改为(%s)", sourceInfo.getPickingSerial(), targetInfo.getPickingSerial()));
}
if (targetInfo.getCellTypeCode() != null && !targetInfo.getCellTypeCode().equals(sourceInfo.getCellTypeCode())) {
builder.add(String.format("将仓位类型由(%s)改为(%s)", sourceInfo.getCellTypeCode(), targetInfo.getCellTypeCode()));
}
if (targetInfo.getCellStoragePropertyCode() != null && !targetInfo.getCellStoragePropertyCode().equals(sourceInfo.getCellStoragePropertyCode())) {
builder.add(String.format("将仓位存储属性由(%s)改为(%s)", sourceInfo.getCellStoragePropertyCode(), targetInfo.getCellStoragePropertyCode()));
}
if (targetInfo.getSupportSalver() != null && !targetInfo.getSupportSalver().equals(sourceInfo.getSupportSalver())) {
builder.add(String.format("将是否支持托盘由(%s)改为(%s)", sourceInfo.getSupportSalver(), targetInfo.getSupportSalver()));
}
if (targetInfo.getStatus() != null && !targetInfo.getStatus().equals(sourceInfo.getStatus())) {
String targetStatus = targetInfo.getStatus();
String desc = EnumOperateType.getOperateType(targetStatus);
builder.add(String.format("批量%s了(%s)仓位", desc, sourceInfo.getCellCode()));
}
if (targetInfo.getSalesLevel() != null && !targetInfo.getSalesLevel().equals(sourceInfo.getSalesLevel())){
builder.add(String.format("将库位的动销等级由(%s)改为(%s)", sourceInfo.getSalesLevel(), targetInfo.getSalesLevel()));
}
if (CollectionUtils.isEmpty(builder)) {
return null;
}
wimsChangeLog.setTableName("wims_cell");
wimsChangeLog.setType(EnumOperateType.Edit.getCode());
wimsChangeLog.setColumnId(sourceInfo.getId());
wimsChangeLog.setColumnValue(sourceInfo.getCellCode());
wimsChangeLog.setOperateNo(UserUtils.getUserName());
wimsChangeLog.setOperator("");
wimsChangeLog.setContent(Joiner.on(";").join(builder));
return wimsChangeLog;
}
}
随笔
最新推荐文章于 2024-09-16 21:37:07 发布