|
|
@@ -10,6 +10,7 @@ import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+import com.uas.eis.entity.Configs;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.dao.DataAccessException;
|
|
|
import org.springframework.dao.EmptyResultDataAccessException;
|
|
|
@@ -26,10 +27,14 @@ import net.sf.json.JSONObject;
|
|
|
|
|
|
@Repository
|
|
|
public class BaseDao{
|
|
|
-
|
|
|
+
|
|
|
+ static final String CREATE_SEQ = "CREATE SEQUENCE ?" + // 创建序列
|
|
|
+ " MINVALUE 1 MAXVALUE 99999999999 INCREMENT BY 1 START WITH 3000 CACHE 20 NOORDER NOCYCLE ";
|
|
|
+
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
public JdbcTemplate getJdbcTemplate() {
|
|
|
return jdbcTemplate;
|
|
|
}
|
|
|
@@ -579,5 +584,101 @@ public class BaseDao{
|
|
|
}
|
|
|
return datas;
|
|
|
}
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 获取序列号
|
|
|
+ *
|
|
|
+ * @param seq
|
|
|
+ * 指定的序列名
|
|
|
+ */
|
|
|
+ public int getSeqId(String seq) {
|
|
|
+ try {
|
|
|
+ String sql = "select " + seq + ".nextval from dual";
|
|
|
+ SqlRowList rs = queryForRowSet(sql);
|
|
|
+ if (rs.next()) {
|
|
|
+ return rs.getInt(1);
|
|
|
+ } else {// 如果不存在就创建序列
|
|
|
+ int count = getCountByCondition("user_sequences", "Sequence_Name='" + seq.toUpperCase() + "'");
|
|
|
+ if (count == 0)
|
|
|
+ getJdbcTemplate().execute(CREATE_SEQ.replace("?", seq));
|
|
|
+ return getSeqId(seq);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ int count = getCountByCondition("user_sequences", "Sequence_Name='" + seq.toUpperCase() + "'");
|
|
|
+ if (count == 0)
|
|
|
+ getJdbcTemplate().execute(CREATE_SEQ.replace("?", seq));
|
|
|
+ return getSeqId(seq);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取编号序列
|
|
|
+ *
|
|
|
+ * @param myTable
|
|
|
+ * Caller
|
|
|
+ * @param thisType
|
|
|
+ * 2
|
|
|
+ */
|
|
|
+ public synchronized String sGetMaxNumber(String myTable, int thisType) {
|
|
|
+ return callProcedure("Sp_GetMaxNumber", new Object[] { myTable, thisType });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 一个字段,一条结果
|
|
|
+ *
|
|
|
+ * @param tableName
|
|
|
+ * 对应要查询的表
|
|
|
+ * @param field
|
|
|
+ * 要查询的字段
|
|
|
+ * @param condition
|
|
|
+ * 查询条件
|
|
|
+ * @return field对应的数据
|
|
|
+ */
|
|
|
+ public <T> T getFieldValue(String tableName, String field, String condition, Class<T> requiredType) {
|
|
|
+ StringBuffer sql = new StringBuffer("SELECT ");
|
|
|
+ sql.append(field);
|
|
|
+ sql.append(" FROM ");
|
|
|
+ sql.append(tableName);
|
|
|
+ sql.append(" WHERE ");
|
|
|
+ sql.append(condition);
|
|
|
+ SqlRowList srs = queryForRowSet(sql.toString());
|
|
|
+ if (srs.next()) {
|
|
|
+ RowConvert<T> convert = new RowConvert<T>(requiredType);
|
|
|
+ return convert.convert(srs.getObject(1));
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断指定参数是否配置为“是”
|
|
|
+ *
|
|
|
+ * @param caller
|
|
|
+ * @param code
|
|
|
+ * 参数编号
|
|
|
+ */
|
|
|
+ public boolean isDBSetting(String caller, String code) {
|
|
|
+ int count = getCount("select count(1) from configs where caller='" + caller + "' and code='" + code + "'");
|
|
|
+ if (count==0){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Configs configs = jdbcTemplate.queryForObject("select * from configs where caller=? and code=?",
|
|
|
+ new BeanPropertyRowMapper<Configs>(Configs.class), caller, code);
|
|
|
+ if (configs != null) {
|
|
|
+ String data = configs.getData();
|
|
|
+ if ("YN".equals(configs.getData_type())) {
|
|
|
+ return String.valueOf(Constant.YES).equals(data);
|
|
|
+ }
|
|
|
+ return data == null ? false : true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getCount(String sql) {
|
|
|
+ SqlRowList rs = queryForRowSet(sql);
|
|
|
+ if (rs.next()) {
|
|
|
+ return rs.getInt(1);
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
}
|