Commit 718b9614 by guojuxing

Merge remote-tracking branch 'origin/developer' into developer

parents 568e7c9a 2917f24c
......@@ -21,14 +21,12 @@ import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.*;
@Service("customSettingApiService")
public class CustomSettingApiServiceImpl implements CustomSettingApiService {
private static final Logger log = LogManager.getLogger(CustomSettingApiServiceImpl.class);
private static final String DATABASENAME = "gic4_log";
private static final String DATABASENAME = "custom_table";
private static final String PRIMARYKEY = "_id";
@Autowired
private MongoOperApiService mongoOperApiService;
......@@ -53,7 +51,7 @@ public class CustomSettingApiServiceImpl implements CustomSettingApiService {
Criteria criteria = new Criteria(field, MongoOperTypeEnum.EQ, map.get(field));
criteriaList.add(criteria);
}
if(map.get("_id") != null){
if(map.get(PRIMARYKEY) != null){
Criteria criteria = new Criteria(PRIMARYKEY, MongoOperTypeEnum.NIN, map.get(PRIMARYKEY));
criteriaList.add(criteria);
}
......@@ -63,17 +61,35 @@ public class CustomSettingApiServiceImpl implements CustomSettingApiService {
queryDTO.setConllectionName(tableName);
ServiceResponse<List<Map>> query = mongoOperApiService.query(queryDTO);
if(CollectionUtils.isNotEmpty(query.getResult())){
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "存在重复记录");
if(tableSetting.getRepeateOpt() != null && tableSetting.getRepeateOpt() == 1){
//等于1表示重复更新
Map exitMap = query.getResult().get(0);
map.forEach((k, v) -> {
if(k.equals(PRIMARYKEY)){
exitMap.put("ObjectId(\"" +k + "\")", v);
} else {
exitMap.put(k, v);
}
});
map = exitMap;
} else {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "存在重复记录");
}
}
}
log.info("params:{}", JSON.toJSONString(map));
Date date = new Date();
if(map.get(PRIMARYKEY) != null){
//更新
map.put("update_time", date);
MongoUpdateDTO mongoUpdateDTO = new MongoUpdateDTO();
mongoUpdateDTO.setDataBaseAndCollectionName(DATABASENAME, tableName);
mongoUpdateDTO.setData(map);
ServiceResponse<Integer> update = mongoOperApiService.update(mongoUpdateDTO);
log.info("update:{}", JSON.toJSONString(update));
} else {
map.put("update_time", date);
map.put("create_time", date);
MongoSaveDTO mongoSaveDTO = new MongoSaveDTO();
mongoSaveDTO.setDataBaseAndCollectionName(DATABASENAME, tableName);
mongoSaveDTO.setData(map);
......
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