|
@ -10,7 +10,7 @@ import com.yihu.ehr.framework.util.operator.StringUtil;
|
|
import com.yihu.ehr.framework.util.sql.RequestParamTransformer;
|
|
import com.yihu.ehr.framework.util.sql.RequestParamTransformer;
|
|
import com.yihu.ehr.framework.util.sql.SqlCreator;
|
|
import com.yihu.ehr.framework.util.sql.SqlCreator;
|
|
import com.yihu.ehr.standard.model.standard.StandardModel;
|
|
import com.yihu.ehr.standard.model.standard.StandardModel;
|
|
import com.yihu.ehr.standard.model.standard.StdPublisherModel;
|
|
|
|
|
|
import com.yihu.ehr.system.model.SystemOrganization;
|
|
import org.hibernate.Query;
|
|
import org.hibernate.Query;
|
|
import org.hibernate.SQLQuery;
|
|
import org.hibernate.SQLQuery;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@ -28,7 +28,7 @@ public class StdPublisherService extends SQLGeneralDAO {
|
|
|
|
|
|
public static final String BEAN_ID = "StdPublisherService";
|
|
public static final String BEAN_ID = "StdPublisherService";
|
|
|
|
|
|
public List<StdPublisherModel> getList(String condition, String order, Integer limit, Integer offset) {
|
|
|
|
|
|
public List<SystemOrganization> getList(String condition, String order, Integer limit, Integer offset) {
|
|
try{
|
|
try{
|
|
Map<String, String> queryMap = RequestParamTransformer.parseJsonToMap(condition);
|
|
Map<String, String> queryMap = RequestParamTransformer.parseJsonToMap(condition);
|
|
Map<String, String> orderMap = RequestParamTransformer.parseJsonToMap(order);
|
|
Map<String, String> orderMap = RequestParamTransformer.parseJsonToMap(order);
|
|
@ -40,17 +40,16 @@ public class StdPublisherService extends SQLGeneralDAO {
|
|
throw new ApiException(ErrorCode.GetPublisherListFaield);
|
|
throw new ApiException(ErrorCode.GetPublisherListFaield);
|
|
}
|
|
}
|
|
|
|
|
|
private List<StdPublisherModel> getList(Map<String, String> query, Map<String, String> order, Integer limit, Integer offset) {
|
|
|
|
SqlCreator sqlCreator = new SqlCreator(StdPublisherModel.class);
|
|
|
|
|
|
private List<SystemOrganization> getList(Map<String, String> query, Map<String, String> order, Integer limit, Integer offset) {
|
|
|
|
SqlCreator sqlCreator = new SqlCreator(SystemOrganization.class);
|
|
for (String key : query.keySet()) {
|
|
for (String key : query.keySet()) {
|
|
sqlCreator.equalCondition(key, query.get(key));
|
|
sqlCreator.equalCondition(key, query.get(key));
|
|
}
|
|
}
|
|
for (String key : order.keySet()) {
|
|
for (String key : order.keySet()) {
|
|
sqlCreator.order(key, order.get(key));
|
|
sqlCreator.order(key, order.get(key));
|
|
}
|
|
}
|
|
sqlCreator.neCondition("code", "jkzl");
|
|
|
|
|
|
|
|
String sql = sqlCreator.selectData(StdPublisherModel.TABLE_NAME);
|
|
|
|
|
|
String sql = sqlCreator.selectData("system_organization");
|
|
|
|
|
|
Query sessionQuery = getQuery(sqlCreator, sql);
|
|
Query sessionQuery = getQuery(sqlCreator, sql);
|
|
if (limit != null) {
|
|
if (limit != null) {
|
|
@ -59,145 +58,36 @@ public class StdPublisherService extends SQLGeneralDAO {
|
|
sessionQuery.setFirstResult(offset);
|
|
sessionQuery.setFirstResult(offset);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return (List<StdPublisherModel>) sessionQuery.list();
|
|
|
|
|
|
return (List<SystemOrganization>) sessionQuery.list();
|
|
}
|
|
}
|
|
|
|
|
|
public StdPublisherModel add(String publisher) {
|
|
|
|
Boolean existFlg = true;
|
|
|
|
try {
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
StdPublisherModel stdPublisherModel = objectMapper.readValue(publisher, StdPublisherModel.class);
|
|
|
|
existFlg = existPublisherValid(stdPublisherModel.getCode(), stdPublisherModel.getName());
|
|
|
|
if (!existFlg) {
|
|
|
|
saveEntity(stdPublisherModel);
|
|
|
|
return stdPublisherModel;
|
|
|
|
}
|
|
|
|
}catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
if (existFlg) {
|
|
|
|
throw new ApiException(ErrorCode.ExistOrgForCreate);
|
|
|
|
} else {
|
|
|
|
throw new ApiException(ErrorCode.SavePublisherFailed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void delete(Integer stdPublisherId) {
|
|
|
|
Boolean existFlg = false;
|
|
|
|
|
|
public SystemOrganization get(Integer stdPublisherId) {
|
|
try {
|
|
try {
|
|
StdPublisherModel publisherModel = getEntity(StdPublisherModel.class, stdPublisherId);
|
|
|
|
existFlg = existStandardValid(publisherModel.getCode());
|
|
|
|
if (!existFlg) {
|
|
|
|
String hql = "delete from StdPublisherModel where id = :id";
|
|
|
|
Query query = getCurrentSession().createQuery(hql);
|
|
|
|
query.setInteger("id", publisherModel.getId());
|
|
|
|
query.executeUpdate();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
if (existFlg) {
|
|
|
|
throw new ApiException(ErrorCode.ExistOrgForStandard);
|
|
|
|
} else {
|
|
|
|
throw new ApiException(ErrorCode.SavePublisherFailed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public StdPublisherModel update(String publisher) {
|
|
|
|
Boolean existFlg;
|
|
|
|
try {
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
StdPublisherModel stdPublisherModel = objectMapper.readValue(publisher, StdPublisherModel.class);
|
|
|
|
StdPublisherModel publisherModel = getEntity(StdPublisherModel.class, stdPublisherModel.getId());
|
|
|
|
existFlg = existPublisherValid(stdPublisherModel.getId(), stdPublisherModel.getCode(), stdPublisherModel.getName());
|
|
|
|
if (!existFlg) {
|
|
|
|
String sql = "update std_info set publisher = :publisher,publisher_org_code = :stdPublisherOrgCode" +
|
|
|
|
" where publisher_org_code = :publisherOrgCode";
|
|
|
|
SQLQuery sqlQuery = getCurrentSession().createSQLQuery(sql);
|
|
|
|
sqlQuery.setParameter("publisher", stdPublisherModel.getName());
|
|
|
|
sqlQuery.setParameter("stdPublisherOrgCode", stdPublisherModel.getCode());
|
|
|
|
sqlQuery.setParameter("publisherOrgCode", publisherModel.getCode());
|
|
|
|
sqlQuery.executeUpdate();
|
|
|
|
publisherModel.setCode(stdPublisherModel.getCode());
|
|
|
|
publisherModel.setName(stdPublisherModel.getName());
|
|
|
|
publisherModel.setDescription(stdPublisherModel.getDescription());
|
|
|
|
updateEntity(publisherModel);
|
|
|
|
return stdPublisherModel;
|
|
|
|
}
|
|
|
|
}catch (Exception e) {
|
|
|
|
throw new ApiException(ErrorCode.UpdatePublisherFailed);
|
|
|
|
}
|
|
|
|
if (existFlg) {
|
|
|
|
throw new ApiException(ErrorCode.ExistOrgForCreate);
|
|
|
|
} else {
|
|
|
|
throw new ApiException(ErrorCode.SavePublisherFailed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public StdPublisherModel get(Integer stdPublisherId) {
|
|
|
|
try {
|
|
|
|
SqlCreator sqlCreator = new SqlCreator(StdPublisherModel.class);
|
|
|
|
|
|
SqlCreator sqlCreator = new SqlCreator(SystemOrganization.class);
|
|
sqlCreator.equalCondition("id", stdPublisherId);
|
|
sqlCreator.equalCondition("id", stdPublisherId);
|
|
String sql = sqlCreator.selectData(StdPublisherModel.TABLE_NAME);
|
|
|
|
|
|
String sql = sqlCreator.selectData("system_organization");
|
|
Query query = getQuery(sqlCreator, sql);
|
|
Query query = getQuery(sqlCreator, sql);
|
|
return (StdPublisherModel) query.uniqueResult();
|
|
|
|
|
|
return (SystemOrganization) query.uniqueResult();
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
throw new ApiException(ErrorCode.GetPublisherFailed);
|
|
throw new ApiException(ErrorCode.GetPublisherFailed);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public StdPublisherModel getStandardPublisher() {
|
|
|
|
|
|
public SystemOrganization getStandardPublisher() {
|
|
try {
|
|
try {
|
|
SqlCreator sqlCreator = new SqlCreator(StdPublisherModel.class);
|
|
|
|
|
|
SqlCreator sqlCreator = new SqlCreator(SystemOrganization.class);
|
|
String paramSql = "select s.org_id from system_param s where s.param_key = '"+ Constants.STANDARD+"'";
|
|
String paramSql = "select s.org_id from system_param s where s.param_key = '"+ Constants.STANDARD+"'";
|
|
Query paramQuery = getCurrentSession().createSQLQuery(paramSql);
|
|
Query paramQuery = getCurrentSession().createSQLQuery(paramSql);
|
|
List list = paramQuery.list();
|
|
List list = paramQuery.list();
|
|
String publisherCode = StringUtil.toString(list.get(0));
|
|
String publisherCode = StringUtil.toString(list.get(0));
|
|
|
|
|
|
sqlCreator.equalCondition("code", publisherCode);
|
|
sqlCreator.equalCondition("code", publisherCode);
|
|
String sql = sqlCreator.selectData(StdPublisherModel.TABLE_NAME);
|
|
|
|
|
|
String sql = sqlCreator.selectData("system_organization");
|
|
Query query = getQuery(sqlCreator, sql);
|
|
Query query = getQuery(sqlCreator, sql);
|
|
return (StdPublisherModel) query.uniqueResult();
|
|
|
|
|
|
return (SystemOrganization) query.uniqueResult();
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
throw new ApiException(ErrorCode.GetPublisherFailed);
|
|
throw new ApiException(ErrorCode.GetPublisherFailed);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public boolean existStandardValid(String code) {
|
|
|
|
String hql="FROM StandardModel WHERE publisherOrgCode = :code";
|
|
|
|
Query query = getCurrentSession().createQuery(hql);
|
|
|
|
query.setParameter("code", code);
|
|
|
|
List<StandardModel> standardModelList = query.list();
|
|
|
|
if (standardModelList.size() > 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean existPublisherValid(Integer publiserId, String code, String name) {
|
|
|
|
String hql="FROM StdPublisherModel WHERE code = :code or name = :name";
|
|
|
|
Query query = getCurrentSession().createQuery(hql);
|
|
|
|
query.setParameter("code", code);
|
|
|
|
query.setParameter("name", name);
|
|
|
|
List<StdPublisherModel> list = query.list();
|
|
|
|
if (!CollectionUtil.isEmpty(list)) {
|
|
|
|
if (list.get(0).getId() != publiserId) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean existPublisherValid(String code, String name) {
|
|
|
|
String hql="FROM StdPublisherModel WHERE code = :code or name = :name";
|
|
|
|
Query query = getCurrentSession().createQuery(hql);
|
|
|
|
query.setParameter("code", code);
|
|
|
|
query.setParameter("name", name);
|
|
|
|
List<StdPublisherModel> list = query.list();
|
|
|
|
if (!CollectionUtil.isEmpty(list)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
}
|