@ -1,14 +1,26 @@
package com.dsideal.QingLong.Global.Model ;
import com.jfinal.kit.Kv ;
import com.jfinal.plugin.activerecord.Db ;
import com.jfinal.plugin.activerecord.Page ;
import com.jfinal.plugin.activerecord.Record ;
import com.jfinal.plugin.activerecord.SqlPara ;
import java.util.ArrayList ;
import java.util.List ;
public class GlobalModel {
/ * *
* 功 能 : 获 取 当 前 安 装 地 区
*
* @return
* /
public String getInstallArea ( ) {
String sql = "select COALESCE(global_value,'') as global_value from t_base_global where global_code = 'install_area'" ;
return Db . findFirst ( sql ) . getStr ( "global_value" ) ;
}
/ * *
* 功 能 : 根 据 全 局 变 量 的 KEY 获 取 VALUE
*
@ -16,17 +28,13 @@ public class GlobalModel {
* @return
* /
public String getGlobalValueByKey ( String key ) {
String result = "" ;
try {
String sql = Db . getSql ( "global.getGlobalValueByKey" ) ;
List < Record > list = Db . find ( sql , key ) ;
if ( list . size ( ) > 0 ) {
result = list . get ( 0 ) . getStr ( "global_value" ) ;
}
} catch ( Exception e ) {
e . printStackTrace ( ) ;
String install_area = getInstallArea ( ) ;
if ( key . equals ( "install_area" ) ) { //如果是获取安装地区
return install_area ;
}
return result ;
//获取当前安装地区,然后组装出查询条件
String sql = "select global_value from t_base_global where install_area=? and global_code=?" ;
return Db . findFirst ( sql , install_area , key ) . getStr ( "global_value" ) ;
}
/ * *
@ -49,7 +57,10 @@ public class GlobalModel {
* @return
* /
public Page < Record > getGlobalList ( int page , int limit ) {
Page < Record > dataPage = Db . paginate ( page , limit , Db . getSqlPara ( "global.getGlobalList" ) ) ;
String install_area = getInstallArea ( ) ;
Kv kv = Kv . by ( "install_area" , install_area ) ;
SqlPara sqlPara = Db . getSqlPara ( "global.getGlobalList" , kv ) ;
Page < Record > dataPage = Db . paginate ( page , limit , sqlPara ) ;
return dataPage ;
}
@ -62,8 +73,9 @@ public class GlobalModel {
* @return
* /
public int checkGlobalCodeCount ( String global_id , String globalCode ) {
String sql = Db . getSql ( "global.checkGlobalCodeCount" ) ;
Record record = Db . find ( sql , Integer . parseInt ( global_id ) , globalCode ) . get ( 0 ) ;
String install_area = getInstallArea ( ) ;
String sql = "select count(1) as c from t_base_global where global_id<>? and global_code=? and install_area=?" ;
Record record = Db . find ( sql , Integer . parseInt ( global_id ) , globalCode , install_area ) . getFirst ( ) ;
return record . getInt ( "c" ) ;
}
@ -84,7 +96,7 @@ public class GlobalModel {
* /
public void updateGlobalById ( String global_id , String global_type_id , String global_code , String global_value , String global_name , int sort_id ) {
String sql = Db . getSql ( "global.updateGlobalById" ) ;
Db . update ( sql , Integer . parseInt ( global_type_id ) , global_code , global_value , global_name , sort_id , Integer . parseInt ( global_id ) ) ;
Db . update ( sql , Integer . parseInt ( global_type_id ) , global_code , global_value , global_name , sort_id , Integer . parseInt ( global_id ) ) ;
}
/ * *
@ -120,11 +132,16 @@ public class GlobalModel {
* @return
* /
public List < Record > getGlobalByCodes ( String global_codesString ) {
if ( global_codesString . equals ( "install_area" ) ) {
String sql = "select * from t_base_global where global_id=1" ;
return Db . find ( sql ) ;
}
String install_area = getInstallArea ( ) ;
List < Record > returnRecords = new ArrayList < > ( ) ;
String sql = Db . getSql ( "global.getGlobalByCodes" ) ;
String [ ] global_codes = global_codesString . split ( "," ) ;
for ( int i = 0 ; i < global_codes . length ; i + + ) {
List < Record > ilist = Db . find ( sql , global_codes [ i ] ) ;
List < Record > ilist = Db . find ( sql , global_codes [ i ] , install_area );
for ( int j = 0 ; j < ilist . size ( ) ; j + + ) {
returnRecords . add ( ilist . get ( j ) ) ;
}
@ -161,6 +178,73 @@ public class GlobalModel {
public void saveInstallArea ( String area_id ) {
String sql = Db . getSql ( "global.saveInstallArea" ) ;
Db . update ( sql , area_id ) ;
}
//检查是不是存在以下的字段
//1、system_name 2、copy_right 3、sso_system_name 4、sso_copy_right
sql = "select * from t_base_global where install_area=? and global_code=?" ;
Record record = Db . findFirst ( sql , area_id , "system_name" ) ;
if ( record = = null ) {
sql = "select max(global_id)+1 as global_id from t_base_global" ;
int global_id = Db . findFirst ( sql ) . getInt ( "global_id" ) ;
Record r = new Record ( ) ;
r . set ( "global_id" , global_id ) ;
r . set ( "global_type_id" , 1 ) ;
r . set ( "global_code" , "system_name" ) ;
r . set ( "global_value" , "系统名称" ) ;
r . set ( "global_name" , "系统名称" ) ;
r . set ( "sort_id" , 1 ) ;
r . set ( "install_area" , area_id ) ;
Db . save ( "t_base_global" , "global_id" , r ) ;
}
// 2、copy_right
sql = "select * from t_base_global where install_area=? and global_code=?" ;
record = Db . findFirst ( sql , area_id , "copy_right" ) ;
if ( record = = null ) {
sql = "select max(global_id)+1 as global_id from t_base_global" ;
int global_id = Db . findFirst ( sql ) . getInt ( "global_id" ) ;
Record r = new Record ( ) ;
r . set ( "global_id" , global_id ) ;
r . set ( "global_type_id" , 1 ) ;
r . set ( "global_code" , "copy_right" ) ;
r . set ( "global_value" , "版权信息" ) ;
r . set ( "global_name" , "版权信息" ) ;
r . set ( "sort_id" , 1 ) ;
r . set ( "install_area" , area_id ) ;
Db . save ( "t_base_global" , "global_id" , r ) ;
}
//3、sso_system_name
sql = "select * from t_base_global where install_area=? and global_code=?" ;
record = Db . findFirst ( sql , area_id , "sso_system_name" ) ;
if ( record = = null ) {
sql = "select max(global_id)+1 as global_id from t_base_global" ;
int global_id = Db . findFirst ( sql ) . getInt ( "global_id" ) ;
Record r = new Record ( ) ;
r . set ( "global_id" , global_id ) ;
r . set ( "global_type_id" , 1 ) ;
r . set ( "global_code" , "sso_system_name" ) ;
r . set ( "global_value" , "统一认证系统名称" ) ;
r . set ( "global_name" , "统一认证系统名称" ) ;
r . set ( "sort_id" , 1 ) ;
r . set ( "install_area" , area_id ) ;
Db . save ( "t_base_global" , "global_id" , r ) ;
}
// 4、sso_copy_right
sql = "select * from t_base_global where install_area=? and global_code=?" ;
record = Db . findFirst ( sql , area_id , "sso_copy_right" ) ;
if ( record = = null ) {
sql = "select max(global_id)+1 as global_id from t_base_global" ;
int global_id = Db . findFirst ( sql ) . getInt ( "global_id" ) ;
Record r = new Record ( ) ;
r . set ( "global_id" , global_id ) ;
r . set ( "global_type_id" , 1 ) ;
r . set ( "global_code" , "sso_copy_right" ) ;
r . set ( "global_value" , "统一认证版权信息" ) ;
r . set ( "global_name" , "统一认证版权信息" ) ;
r . set ( "sort_id" , 1 ) ;
r . set ( "install_area" , area_id ) ;
Db . save ( "t_base_global" , "global_id" , r ) ;
}
}
}