|
@@ -1,9 +1,15 @@
|
|
|
package com.boman.system.common;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.boman.common.core.utils.SpringUtils;
|
|
|
import com.boman.common.core.utils.StringUtils;
|
|
|
+import com.boman.common.core.utils.collection.CollectionUtils;
|
|
|
+import com.boman.common.core.utils.obj.ObjectUtils;
|
|
|
+import com.boman.common.redis.RedisKey;
|
|
|
+import com.boman.common.redis.service.RedisService;
|
|
|
+import com.boman.gen.domain.GenTable;
|
|
|
import com.boman.gen.domain.GenTableColumn;
|
|
|
+import com.boman.system.service.impl.BaseDeleteService;
|
|
|
import com.boman.system.service.impl.BaseSaveService;
|
|
|
import com.boman.system.utils.IdUtils;
|
|
|
import org.slf4j.Logger;
|
|
@@ -11,8 +17,11 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import static com.boman.common.core.utils.obj.ObjectUtils.*;
|
|
|
+
|
|
|
/**
|
|
|
* @author shiqian
|
|
|
* @description
|
|
@@ -22,33 +31,84 @@ import java.util.List;
|
|
|
public class TableServiceCmdService {
|
|
|
|
|
|
@Autowired
|
|
|
- private TableServiceContext tableServiceContext;
|
|
|
+ private BaseDeleteService deleteService;
|
|
|
+ @Autowired
|
|
|
+ private BaseSaveService saveService;
|
|
|
+ @Autowired
|
|
|
+ private RedisService redisService;
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(TableServiceCmdService.class);
|
|
|
|
|
|
- public final ValueHolder execute(BaseTableSaveDTO baseTableSaveDTO, String actionName) throws Exception {
|
|
|
+ private BaseTableDTO packTableDTO(BaseTableSaveDTO baseTableSaveDTO) {
|
|
|
BaseTableDTO baseTableDTO = new BaseTableDTO();
|
|
|
baseTableDTO.setFixedData(baseTableSaveDTO.getFixedData());
|
|
|
baseTableDTO.setObjId(baseTableSaveDTO.getObjId());
|
|
|
baseTableDTO.setTable(baseTableSaveDTO.getTable());
|
|
|
- return execute(baseTableDTO, actionName);
|
|
|
+ return baseTableDTO;
|
|
|
}
|
|
|
|
|
|
- public final ValueHolder execute(BaseTableDTO baseTableDTO, String actionName) {
|
|
|
- TableServiceContext context = TableServiceContext.createFrom(baseTableDTO, actionName);
|
|
|
- BaseSaveService baseSaveService = SpringUtils.getBean(BaseSaveService.class);
|
|
|
+ public final ValueHolder<RowResult> objectSave(BaseTableSaveDTO baseTableSaveDTO) {
|
|
|
+ BaseTableDTO baseTableDTO = packTableDTO(baseTableSaveDTO);
|
|
|
+ TableServiceContext context = TableServiceContext.createFrom(baseTableDTO);
|
|
|
+// BaseSaveService baseSaveService = SpringUtils.getBean(BaseSaveService.class);
|
|
|
// 拿到pkName和maxId
|
|
|
List<GenTableColumn> columns = context.getTable().getColumns();
|
|
|
String pkName = IdUtils.getPkName(columns);
|
|
|
StringUtils.requireNonNull(pkName);
|
|
|
Long maxId = IdUtils.getMaxId(baseTableDTO.getTable(), pkName);
|
|
|
- RowResult rowResult = baseSaveService.insertRow(context.getRealTableName(), pkName, maxId, context.getRows().get(0));
|
|
|
+ RowResult rowResult = saveService.insertRow(context.getRealTableName(), pkName, maxId, context.getRows().get(0));
|
|
|
+ if (RowResult.checkSuccess(rowResult)) {
|
|
|
+ LOGGER.info("保存成功,封装到数据库的数据为: {}", JSON.toJSONString(rowResult.getData()));
|
|
|
+ } else {
|
|
|
+ LOGGER.error("保存失败,保持的原始数据为: {}", JSON.toJSONString(baseTableSaveDTO));
|
|
|
+ }
|
|
|
+
|
|
|
+ return ValueHolder.ok(rowResult);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 功能描述: 通用删除接口 (真的删除)
|
|
|
+ *
|
|
|
+ * @param dto 前台传过来的dto
|
|
|
+ * @return com.boman.system.common.ValueHolder
|
|
|
+ */
|
|
|
+ public ValueHolder<RowResult> objectDelete(BaseTableSaveDTO dto) {
|
|
|
+ requireNonNull(dto.getTable());
|
|
|
+ Long[] idArr = CollectionUtils.listToArray(dto.getIdList());
|
|
|
+ requiredNonNull(idArr);
|
|
|
+ // 拿到pkName
|
|
|
+ GenTable genTable = redisService.getCacheObject(RedisKey.TABLE_INFO + requireNonNull(dto.getTable()));
|
|
|
+ requireNonNull(genTable);
|
|
|
+ String pkName = IdUtils.getPkName(genTable.getColumns());
|
|
|
+
|
|
|
+ RowResult rowResult = deleteService.objectDelete(idArr, dto.getTable(), requireNonNull(pkName));
|
|
|
+ LOGGER.info(rowResult.getMessage() + ", id: {}", Arrays.toString(idArr));
|
|
|
+ return ValueHolder.ok(rowResult);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 功能描述: 通用删除接口 (真的删除)
|
|
|
+ *
|
|
|
+ * @param dto 前台传过来的dto
|
|
|
+ * @return com.boman.system.common.ValueHolder
|
|
|
+ */
|
|
|
+ public ValueHolder<RowResult> objectLogicDelete(BaseTableSaveDTO dto) {
|
|
|
+ requireNonNull(dto.getTable());
|
|
|
+ Long[] idArr = CollectionUtils.listToArray(dto.getIdList());
|
|
|
+ requiredNonNull(idArr);
|
|
|
+
|
|
|
+ // 拿到pkName
|
|
|
+ GenTable genTable = redisService.getCacheObject(RedisKey.TABLE_INFO + requireNonNull(dto.getTable()));
|
|
|
+ requireNonNull(genTable);
|
|
|
+ String pkName = IdUtils.getPkName(genTable.getColumns());
|
|
|
+
|
|
|
+ JSONObject jsonObject= new JSONObject();
|
|
|
+ jsonObject.put(dto.getLogicDelName(), dto.getLogicDelValue());
|
|
|
|
|
|
- ValueHolder valueHolder = new ValueHolder();
|
|
|
- valueHolder.setCode(ResultCode.SUCCESS);
|
|
|
- valueHolder.setMessage("操作成功" + ((JSONObject) rowResult.getData()).getInteger("successCnt") + "条!");
|
|
|
- valueHolder.setData(rowResult);
|
|
|
- return valueHolder;
|
|
|
+ RowResult rowResult = deleteService.objectLogicDelete(idArr, dto.getTable(), requireNonNull(pkName), jsonObject);
|
|
|
+ LOGGER.info(rowResult.getMessage() + ", id: {}", Arrays.toString(idArr));
|
|
|
+ return ValueHolder.ok(rowResult);
|
|
|
}
|
|
|
|
|
|
}
|