package com.qxueyou.scc.org.service.impl;
|
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.stereotype.Service;
|
|
import com.qxueyou.scc.base.model.Result;
|
import com.qxueyou.scc.base.service.impl.CommonAppService;
|
import com.qxueyou.scc.base.util.CollectionUtils;
|
import com.qxueyou.scc.base.util.TraceUtils;
|
import com.qxueyou.scc.org.model.OrgText;
|
import com.qxueyou.scc.org.service.IOrgTextService;
|
|
@Service
|
public class OrgTextService extends CommonAppService implements IOrgTextService {
|
|
/**
|
* 插入OrgText - 单个
|
*/
|
@Override
|
public Result doInsertOrgText(String key,String tableName,String content){
|
|
if(StringUtils.isBlank(key)){
|
|
return new Result(true);
|
}
|
|
OrgText orgText = new OrgText();
|
orgText = new OrgText();
|
orgText.setKey(key);
|
orgText.setTableName(tableName);
|
orgText.setContent(content);
|
orgText.setDeleteFlag(false);
|
TraceUtils.setCreateTrace(orgText);
|
save(orgText);
|
|
return new Result(true,"",CollectionUtils.newObjectMap("orgTextId",orgText.getOrgTextId()));
|
}
|
|
/**
|
* 保存OrgText - 单个
|
*/
|
@Override
|
public Result doSaveOrgText(String key,String tableName,String content) {
|
|
if(StringUtils.isBlank(key)){
|
return new Result(true);
|
}
|
|
OrgText orgText = getOrgText(key, tableName);
|
if(orgText == null){// 新增
|
orgText = new OrgText();
|
orgText.setKey(key);
|
orgText.setTableName(tableName);
|
orgText.setContent(content);
|
orgText.setDeleteFlag(false);
|
TraceUtils.setCreateTrace(orgText);
|
|
}else{// 编辑
|
orgText.setContent(content);
|
TraceUtils.setUpdateTrace(orgText);
|
}
|
|
return this.save(orgText);
|
}
|
|
/**
|
* 保存OrgText - 多个
|
*/
|
@Override
|
public Result doSaveOrgTexts(List<String> keys,String tableName,String content){
|
|
if(keys.isEmpty()){
|
|
return new Result(true);
|
}
|
|
Map<String,Object> map = getOrgTextMap(keys, tableName);
|
|
for (int i = 0; i < keys.size(); i++) {
|
OrgText orgText = (OrgText) map.get(keys.get(i));
|
if(orgText == null){// 新增
|
orgText = new OrgText();
|
orgText.setKey(keys.get(i));
|
orgText.setTableName(tableName);
|
orgText.setContent(content);
|
orgText.setDeleteFlag(false);
|
TraceUtils.setCreateTrace(orgText);
|
}else{// 编辑
|
orgText.setContent(content);
|
TraceUtils.setUpdateTrace(orgText);
|
}
|
save(orgText);
|
}
|
|
return new Result(true);
|
}
|
|
/**
|
* 获取OrgText - 单个
|
*/
|
@Override
|
public OrgText getOrgText(String key,String tableName){
|
|
String hql = "from OrgText where key=? and tableName=? and deleteFlag is false";
|
return this.findUnique(hql, CollectionUtils.newList(key, tableName), OrgText.class);
|
}
|
|
/**
|
* 获取OrgText —— 多个(组长Map:key-key,value-OrgText)
|
*/
|
@Override
|
public Map<String,Object> getOrgTextMap(List<String> keys,String tableName){
|
|
if(keys.isEmpty()){
|
|
return null;
|
}
|
|
Map<String, Object> orgTextMap = new HashMap<String, Object>();
|
orgTextMap.put("keys", keys);
|
orgTextMap.put("tableName", tableName);
|
|
String hql = "from OrgText where key in (:keys) and tableName=:tableName and deleteFlag is false";
|
List<OrgText> orgTextLst = findByComplexHql(hql, orgTextMap, OrgText.class);
|
Map<String,Object> map = new HashMap<String,Object>(orgTextLst.size());
|
for (OrgText orgText : orgTextLst) {
|
map.put(orgText.getKey(), orgText);
|
}
|
|
return map;
|
}
|
}
|