|
@@ -1,7 +1,12 @@
|
|
package com.boman.web.core.service.save;
|
|
package com.boman.web.core.service.save;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.boman.common.core.constant.CacheConstants;
|
|
|
|
+import com.boman.common.core.utils.SecurityUtils;
|
|
|
|
+import com.boman.common.core.utils.obj.ObjectUtils;
|
|
|
|
+import com.boman.common.redis.service.RedisService;
|
|
import com.boman.gen.domain.GenTableColumn;
|
|
import com.boman.gen.domain.GenTableColumn;
|
|
|
|
+import com.boman.system.api.model.LoginUser;
|
|
import com.boman.web.core.constant.FormDataConstant;
|
|
import com.boman.web.core.constant.FormDataConstant;
|
|
import com.boman.web.core.domain.RowResult;
|
|
import com.boman.web.core.domain.RowResult;
|
|
import com.boman.web.core.domain.TableContext;
|
|
import com.boman.web.core.domain.TableContext;
|
|
@@ -27,6 +32,8 @@ public class BaseSaveServiceImpl implements IBaseSaveService {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private StandardlyMapper mapper;
|
|
private StandardlyMapper mapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisService redisService;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 功能描述: 保存一行
|
|
* 功能描述: 保存一行
|
|
@@ -42,12 +49,18 @@ public class BaseSaveServiceImpl implements IBaseSaveService {
|
|
String pkName = context.getPkName();
|
|
String pkName = context.getPkName();
|
|
String tableName = context.getTableName();
|
|
String tableName = context.getTableName();
|
|
Timestamp currentTime = new Timestamp(System.currentTimeMillis());
|
|
Timestamp currentTime = new Timestamp(System.currentTimeMillis());
|
|
|
|
+ commitData.put(pkName.toUpperCase(), maxId);
|
|
|
|
+
|
|
ColumnUtils.packUpdateByAndTime(columns, commitData, currentTime);
|
|
ColumnUtils.packUpdateByAndTime(columns, commitData, currentTime);
|
|
|
|
+ // 处理默认值
|
|
|
|
+ handlerDefaultValue(commitData, columns);
|
|
|
|
+
|
|
|
|
+ // 默认创建人和创建时间是都有的
|
|
commitData.put(FormDataConstant.CREATE_TIME.toUpperCase(), currentTime);
|
|
commitData.put(FormDataConstant.CREATE_TIME.toUpperCase(), currentTime);
|
|
commitData.put(FormDataConstant.CREATE_BY.toUpperCase(), "张三");
|
|
commitData.put(FormDataConstant.CREATE_BY.toUpperCase(), "张三");
|
|
- commitData.put(pkName.toUpperCase(), maxId);
|
|
|
|
int ret = mapper.insert(tableName, commitData);
|
|
int ret = mapper.insert(tableName, commitData);
|
|
if (ret > 0) {
|
|
if (ret > 0) {
|
|
|
|
+ LOGGER.info("保存成功,保存的数据为:{}", commitData);
|
|
commitData.put(FormDataConstant.SUCCESS_CNT, ret);
|
|
commitData.put(FormDataConstant.SUCCESS_CNT, ret);
|
|
return RowResult.ok("保存成功", commitData);
|
|
return RowResult.ok("保存成功", commitData);
|
|
}
|
|
}
|
|
@@ -55,4 +68,21 @@ public class BaseSaveServiceImpl implements IBaseSaveService {
|
|
return RowResult.error("失败");
|
|
return RowResult.error("失败");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void handlerDefaultValue(JSONObject jsonObject, List<GenTableColumn> columns) {
|
|
|
|
+ String token = SecurityUtils.getToken();
|
|
|
|
+ LoginUser loginUser = redisService.getCacheObject(CacheConstants.LOGIN_TOKEN_KEY + token);
|
|
|
|
+ JSONObject userEnv = loginUser.getUserEnv();
|
|
|
|
+ for (GenTableColumn column : columns) {
|
|
|
|
+ // 有默认值的列, 并且前台传过来的key中不包含
|
|
|
|
+ if (ObjectUtils.isNotEmpty(column.getDefaultValue())
|
|
|
|
+ && !jsonObject.containsKey(column.getColumnName().toLowerCase())
|
|
|
|
+ && !jsonObject.containsKey(column.getColumnName().toUpperCase())) {
|
|
|
|
+ String defaultValue = ColumnUtils.parseVariables(column.getDefaultValue());
|
|
|
|
+ String variables = userEnv.getString(defaultValue);
|
|
|
|
+ jsonObject.put(column.getColumnName(), variables);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|