|  | @ -9,16 +9,15 @@ import com.yihu.ehr.framework.exception.ApiException;
 | 
												
													
														
															|  | import com.yihu.ehr.framework.util.operator.CollectionUtil;
 |  | import com.yihu.ehr.framework.util.operator.CollectionUtil;
 | 
												
													
														
															|  | import com.yihu.ehr.framework.util.operator.StringUtil;
 |  | 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.standard.model.standard.StandardModel;
 |  | import com.yihu.ehr.standard.model.standard.StandardModel;
 | 
												
													
														
															|  | import com.yihu.ehr.standard.model.standard.StandardVersionModel;
 |  | import com.yihu.ehr.standard.model.standard.StandardVersionModel;
 | 
												
													
														
															|  | import com.yihu.ehr.standard.model.standard.resultModel.StandardResultDetailModel;
 |  | import com.yihu.ehr.standard.model.standard.resultModel.StandardResultDetailModel;
 | 
												
													
														
															|  | import com.yihu.ehr.system.dao.intf.IOrganizationDao;
 |  | 
 | 
												
													
														
															|  | import com.yihu.ehr.system.model.SystemOrganization;
 |  | import com.yihu.ehr.system.model.SystemOrganization;
 | 
												
													
														
															|  | 
 |  | import org.hibernate.Criteria;
 | 
												
													
														
															|  | import org.hibernate.Query;
 |  | import org.hibernate.Query;
 | 
												
													
														
															|  | import org.hibernate.Session;
 |  | import org.hibernate.Session;
 | 
												
													
														
															|  | import org.springframework.beans.factory.annotation.Autowired;
 |  | 
 | 
												
													
														
															|  | import org.springframework.dao.DataAccessException;
 |  | 
 | 
												
													
														
															|  | 
 |  | import org.hibernate.criterion.Order;
 | 
												
													
														
															|  | 
 |  | import org.hibernate.criterion.Restrictions;
 | 
												
													
														
															|  | import org.springframework.stereotype.Service;
 |  | import org.springframework.stereotype.Service;
 | 
												
													
														
															|  | import org.springframework.transaction.annotation.Transactional;
 |  | import org.springframework.transaction.annotation.Transactional;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
											
												
													
														
															|  | @ -61,7 +60,7 @@ public class StandardService extends SQLGeneralDAO {
 | 
												
													
														
															|  |                 this.add(standardModel);
 |  |                 this.add(standardModel);
 | 
												
													
														
															|  |                 return standardModel;
 |  |                 return standardModel;
 | 
												
													
														
															|  |             }
 |  |             }
 | 
												
													
														
															|  |         } catch (IOException e) {
 |  | 
 | 
												
													
														
															|  | 
 |  |         } catch (Exception e) {
 | 
												
													
														
															|  |             e.printStackTrace();
 |  |             e.printStackTrace();
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  |         if (existCodeFlg) {
 |  |         if (existCodeFlg) {
 | 
												
											
												
													
														
															|  | @ -110,11 +109,7 @@ public class StandardService extends SQLGeneralDAO {
 | 
												
													
														
															|  |             }
 |  |             }
 | 
												
													
														
															|  |             existFlg = existStandardVersionValid(standardModel.getId());
 |  |             existFlg = existStandardVersionValid(standardModel.getId());
 | 
												
													
														
															|  |             if (!publishedFlg && !existFlg) {
 |  |             if (!publishedFlg && !existFlg) {
 | 
												
													
														
															|  |                 Session session = getCurrentSession();
 |  | 
 | 
												
													
														
															|  |                 String sql = "delete from " + StandardModel.TABLE_NAME + " where id = :id";
 |  | 
 | 
												
													
														
															|  |                 Query query = session.createSQLQuery(sql);
 |  | 
 | 
												
													
														
															|  |                 query.setLong("id", standardId);
 |  | 
 | 
												
													
														
															|  |                 query.executeUpdate();
 |  | 
 | 
												
													
														
															|  | 
 |  |                 deleteEntity(StandardModel.class, standardId);
 | 
												
													
														
															|  |                 return;
 |  |                 return;
 | 
												
													
														
															|  |             }
 |  |             }
 | 
												
													
														
															|  |         } catch (Exception e) {
 |  |         } catch (Exception e) {
 | 
												
											
												
													
														
															|  | @ -167,7 +162,7 @@ public class StandardService extends SQLGeneralDAO {
 | 
												
													
														
															|  |             }
 |  |             }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |             return standardModel;
 |  |             return standardModel;
 | 
												
													
														
															|  |         } catch (IOException e) {
 |  | 
 | 
												
													
														
															|  | 
 |  |         } catch (Exception e) {
 | 
												
													
														
															|  |             e.printStackTrace();
 |  |             e.printStackTrace();
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  |         if (existCodeFlg) {
 |  |         if (existCodeFlg) {
 | 
												
											
												
													
														
															|  | @ -181,23 +176,19 @@ public class StandardService extends SQLGeneralDAO {
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     public StandardModel get(Integer standardId) {
 |  |     public StandardModel get(Integer standardId) {
 | 
												
													
														
															|  |         try {
 |  |         try {
 | 
												
													
														
															|  |             SqlCreator sqlCreator = new SqlCreator(StandardModel.class);
 |  | 
 | 
												
													
														
															|  |             sqlCreator.equalCondition("id", standardId);
 |  | 
 | 
												
													
														
															|  |             String sql = sqlCreator.selectData(StandardModel.TABLE_NAME);
 |  | 
 | 
												
													
														
															|  |             Query query = getQuery(sqlCreator, sql);
 |  | 
 | 
												
													
														
															|  |             return (StandardModel) query.uniqueResult();
 |  | 
 | 
												
													
														
															|  |         } catch (DataAccessException e) {
 |  | 
 | 
												
													
														
															|  | 
 |  |             return getEntity(StandardModel.class, standardId);
 | 
												
													
														
															|  | 
 |  |         } catch (Exception e) {
 | 
												
													
														
															|  |             e.printStackTrace();
 |  |             e.printStackTrace();
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         throw new ApiException(ErrorCode.StandardGetFailed);
 |  |         throw new ApiException(ErrorCode.StandardGetFailed);
 | 
												
													
														
															|  |     }
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     public List<Object[]> getSysParamList() {
 |  | 
 | 
												
													
														
															|  |         String paramSql = "select s.param_value,s.org_id from system_param s where s.param_key = '"+ Constants.STANDARD+"'";
 |  | 
 | 
												
													
														
															|  | 
 |  |     public String getSysParamList() {
 | 
												
													
														
															|  | 
 |  |         String paramSql = "select s.param_value from system_param s where s.param_key = '"+ Constants.STANDARD +"'";
 | 
												
													
														
															|  |         Query paramQuery = getCurrentSession().createSQLQuery(paramSql);
 |  |         Query paramQuery = getCurrentSession().createSQLQuery(paramSql);
 | 
												
													
														
															|  |         List<Object[]> list = paramQuery.list();
 |  | 
 | 
												
													
														
															|  |         return list;
 |  | 
 | 
												
													
														
															|  | 
 |  |         String code = (String) paramQuery.uniqueResult();
 | 
												
													
														
															|  | 
 |  |         return code;
 | 
												
													
														
															|  |     }
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     public List<StandardResultDetailModel> getStandardListFormat(List<SystemOrganization> publisherModelList,
 |  |     public List<StandardResultDetailModel> getStandardListFormat(List<SystemOrganization> publisherModelList,
 | 
												
											
												
													
														
															|  | @ -296,25 +287,21 @@ public class StandardService extends SQLGeneralDAO {
 | 
												
													
														
															|  |                 e.printStackTrace();
 |  |                 e.printStackTrace();
 | 
												
													
														
															|  |             }
 |  |             }
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  |         List<Object[]> list = getSysParamList();
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         String code = StringUtil.toString(list.get(0)[0]);
 |  | 
 | 
												
													
														
															|  |         String publishOrgCode = StringUtil.toString(list.get(0)[1]);
 |  | 
 | 
												
													
														
															|  | 
 |  |         String code = getSysParamList();
 | 
												
													
														
															|  |         String publisherHql = "FROM SystemOrganization";
 |  |         String publisherHql = "FROM SystemOrganization";
 | 
												
													
														
															|  |         SqlCreator sqlCreator = new SqlCreator(StandardModel.class);
 |  | 
 | 
												
													
														
															|  |         if (type == 0) {
 |  | 
 | 
												
													
														
															|  |             sqlCreator.equalCondition("code", code);
 |  | 
 | 
												
													
														
															|  |             publisherHql = publisherHql + " WHERE code = :code";
 |  | 
 | 
												
													
														
															|  |         } else {
 |  | 
 | 
												
													
														
															|  |             sqlCreator.neCondition("code", code);
 |  | 
 | 
												
													
														
															|  |             publisherHql = publisherHql + " WHERE code != :code";
 |  | 
 | 
												
													
														
															|  |         }
 |  | 
 | 
												
													
														
															|  |         Query query = getCurrentSession().createQuery(publisherHql);
 |  |         Query query = getCurrentSession().createQuery(publisherHql);
 | 
												
													
														
															|  |         query.setParameter("code", publishOrgCode);
 |  | 
 | 
												
													
														
															|  |         List<SystemOrganization> publisherModelList = query.list();
 |  |         List<SystemOrganization> publisherModelList = query.list();
 | 
												
													
														
															|  |         String sql = sqlCreator.selectData(StandardModel.TABLE_NAME);
 |  | 
 | 
												
													
														
															|  |         Query sessionQuery = getQuery(sqlCreator, sql);
 |  | 
 | 
												
													
														
															|  |         List<StandardModel> standardModelList = sessionQuery.list();
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         Session session = getCurrentSession();
 | 
												
													
														
															|  | 
 |  |         Criteria criteria = session.createCriteria(StandardModel.class);
 | 
												
													
														
															|  | 
 |  |         if (type == 0) {
 | 
												
													
														
															|  | 
 |  |             criteria.add(Restrictions.eq("code", code));
 | 
												
													
														
															|  | 
 |  |         } else if (type == 1) {
 | 
												
													
														
															|  | 
 |  |             criteria.add(Restrictions.ne("code", code));
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         List<StandardModel> standardModelList = criteria.list();
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         Map<String, String> codeToIdMap = new HashMap<>();
 |  |         Map<String, String> codeToIdMap = new HashMap<>();
 | 
												
													
														
															|  |         List<Integer> idList = new ArrayList<>();
 |  |         List<Integer> idList = new ArrayList<>();
 | 
												
													
														
															|  |         for (StandardModel standardModel : standardModelList) {
 |  |         for (StandardModel standardModel : standardModelList) {
 | 
												
											
												
													
														
															|  | @ -358,60 +345,47 @@ public class StandardService extends SQLGeneralDAO {
 | 
												
													
														
															|  |         throw new ApiException(ErrorCode.StandardForkFailed);
 |  |         throw new ApiException(ErrorCode.StandardForkFailed);
 | 
												
													
														
															|  |     }
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     private void update(StandardModel standardModel) throws IOException {
 |  | 
 | 
												
													
														
															|  |         ObjectMapper objectMapper = new ObjectMapper();
 |  | 
 | 
												
													
														
															|  |         JsonNode jsonNode = objectMapper.readTree(objectMapper.writeValueAsString(standardModel));
 |  | 
 | 
												
													
														
															|  |         SqlCreator sqlCreator = new SqlCreator(StandardModel.class);
 |  | 
 | 
												
													
														
															|  |         String sql = sqlCreator.updateDataByTableKey(StandardModel.TABLE_NAME, jsonNode);
 |  | 
 | 
												
													
														
															|  |         Query query = getExeuteQuery(sqlCreator, sql);
 |  | 
 | 
												
													
														
															|  |         query.executeUpdate();
 |  | 
 | 
												
													
														
															|  | 
 |  |     private void update(StandardModel standardModel) throws Exception {
 | 
												
													
														
															|  | 
 |  |         updateEntity(standardModel);
 | 
												
													
														
															|  |     }
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     private void add(StandardModel standardModel) throws IOException {
 |  | 
 | 
												
													
														
															|  |         ObjectMapper objectMapper = new ObjectMapper();
 |  | 
 | 
												
													
														
															|  |         Session session = getCurrentSession();
 |  | 
 | 
												
													
														
															|  |         String sql = "select max(id) from " + StandardModel.TABLE_NAME;
 |  | 
 | 
												
													
														
															|  |         Query query = session.createSQLQuery(sql);
 |  | 
 | 
												
													
														
															|  |         Object object = query.uniqueResult();
 |  | 
 | 
												
													
														
															|  |         standardModel.setId(object == null ? 1 : Integer.parseInt(object.toString()) + 1);
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         JsonNode jsonNode = objectMapper.readTree(objectMapper.writeValueAsString(standardModel));
 |  | 
 | 
												
													
														
															|  |         SqlCreator sqlCreator = new SqlCreator(StandardModel.class);
 |  | 
 | 
												
													
														
															|  |         sql = sqlCreator.insertData(StandardModel.TABLE_NAME, jsonNode);
 |  | 
 | 
												
													
														
															|  |         query = getExeuteQuery(sqlCreator, sql);
 |  | 
 | 
												
													
														
															|  |         query.executeUpdate();
 |  | 
 | 
												
													
														
															|  | 
 |  |     private void add(StandardModel standardModel) throws Exception {
 | 
												
													
														
															|  | 
 |  |         saveEntity(standardModel);
 | 
												
													
														
															|  |     }
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     private List<StandardModel> getList(Map<String, String> query, Map<String, String> order, Integer limit, Integer offset) {
 |  |     private List<StandardModel> getList(Map<String, String> query, Map<String, String> order, Integer limit, Integer offset) {
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         SqlCreator sqlCreator = new SqlCreator(StandardModel.class);
 |  | 
 | 
												
													
														
															|  | 
 |  |         Session session = getCurrentSession();
 | 
												
													
														
															|  | 
 |  |         Criteria criteria = session.createCriteria(StandardModel.class);
 | 
												
													
														
															|  |         for (String key : query.keySet()) {
 |  |         for (String key : query.keySet()) {
 | 
												
													
														
															|  |             if (key.equals("type")) {
 |  |             if (key.equals("type")) {
 | 
												
													
														
															|  |                 Integer type = Integer.parseInt(query.get(key));
 |  |                 Integer type = Integer.parseInt(query.get(key));
 | 
												
													
														
															|  |                 List<Object[]> list = getSysParamList();
 |  | 
 | 
												
													
														
															|  |                 String code = StringUtil.toString(list.get(0)[0]);
 |  | 
 | 
												
													
														
															|  | 
 |  |                 String code = getSysParamList();
 | 
												
													
														
															|  |                 if (type == 0) {
 |  |                 if (type == 0) {
 | 
												
													
														
															|  |                     sqlCreator.equalCondition("code", code);
 |  | 
 | 
												
													
														
															|  | 
 |  |                     criteria.add(Restrictions.eq("code", code));
 | 
												
													
														
															|  |                 } else if (type == 1) {
 |  |                 } else if (type == 1) {
 | 
												
													
														
															|  |                     sqlCreator.neCondition("code", code);
 |  | 
 | 
												
													
														
															|  | 
 |  |                     criteria.add(Restrictions.ne("code", code));
 | 
												
													
														
															|  |                 }
 |  |                 }
 | 
												
													
														
															|  |             } else {
 |  |             } else {
 | 
												
													
														
															|  |                 sqlCreator.equalCondition(key, query.get(key));
 |  | 
 | 
												
													
														
															|  | 
 |  |                 criteria.add(Restrictions.eq(key, query.get(key)));
 | 
												
													
														
															|  |             }
 |  |             }
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  |         for (String key : order.keySet()) {
 |  | 
 | 
												
													
														
															|  |             sqlCreator.order(key, order.get(key));
 |  | 
 | 
												
													
														
															|  |         }
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         String sql = sqlCreator.selectData(StandardModel.TABLE_NAME);
 |  | 
 | 
												
													
														
															|  |         Query sessionQuery = getQuery(sqlCreator, sql);
 |  | 
 | 
												
													
														
															|  |         if (limit != null) {
 |  |         if (limit != null) {
 | 
												
													
														
															|  |             sessionQuery.setMaxResults(limit);
 |  | 
 | 
												
													
														
															|  | 
 |  |             criteria.setMaxResults(limit);
 | 
												
													
														
															|  |             if (offset != null) {
 |  |             if (offset != null) {
 | 
												
													
														
															|  |                 sessionQuery.setFirstResult((offset - 1) * limit);
 |  | 
 | 
												
													
														
															|  | 
 |  |                 criteria.setFirstResult((offset - 1) * limit);
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         if (order != null) {
 | 
												
													
														
															|  | 
 |  |             for (String key : order.keySet()) {
 | 
												
													
														
															|  | 
 |  |                 if (order.get(key).equals(Constants.ASC)) {
 | 
												
													
														
															|  | 
 |  |                     criteria.addOrder(Order.asc(key));
 | 
												
													
														
															|  | 
 |  |                 } else if (order.get(key).equals(Constants.DESC)) {
 | 
												
													
														
															|  | 
 |  |                     criteria.addOrder(Order.desc(key));
 | 
												
													
														
															|  | 
 |  |                 }
 | 
												
													
														
															|  |             }
 |  |             }
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  |         return (List<StandardModel>) sessionQuery.list();
 |  | 
 | 
												
													
														
															|  | 
 |  |         return (List<StandardModel>) criteria.list();
 | 
												
													
														
															|  |     }
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     public boolean existStandardVersionValid(Integer standardId) {
 |  |     public boolean existStandardVersionValid(Integer standardId) {
 |