pioneer
2 years ago
commit
d200a18d34
18 changed files with 2217 additions and 0 deletions
@ -0,0 +1,6 @@
|
||||
# open-JSD-9940 |
||||
|
||||
JSD-9940 平台用户同步\ |
||||
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系【pioneer】处理。 |
Binary file not shown.
Binary file not shown.
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin> |
||||
<id>com.eco.plugin.xx.hqctb</id> |
||||
<name><![CDATA[数据同步]]></name> |
||||
<active>yes</active> |
||||
<version>1.0.4</version> |
||||
<env-version>10.0</env-version> |
||||
<jartime>2018-07-31</jartime> |
||||
<vendor>fr.open</vendor> |
||||
<description><![CDATA[数据同步]]></description> |
||||
<change-notes><![CDATA[ |
||||
]]></change-notes> |
||||
<main-package>com.eco.plugin.xx.hqctb</main-package> |
||||
<lifecycle-monitor class="com.eco.plugin.xx.hqctb.config.InitializeMonitor"/> |
||||
|
||||
<extra-core> |
||||
<FunctionDefineProvider class="com.eco.plugin.xx.hqctb.function.AuthFunction" name="syncData" description="数据同步"/> |
||||
<!-- <DBAccessProvider class="com.eco.plugin.xx.hqctb.db.controller.DBController"/>--> |
||||
</extra-core> |
||||
<function-recorder class="com.eco.plugin.xx.hqctb.config.PluginSimpleConfig"/> |
||||
</plugin> |
@ -0,0 +1,21 @@
|
||||
package com.eco.plugin.xx.hqctb.config; |
||||
|
||||
import com.fr.plugin.context.PluginContext; |
||||
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor; |
||||
|
||||
/** |
||||
* @author xx |
||||
* @version 10.0 |
||||
* Created by xx on 2021-12-03 |
||||
*/ |
||||
public class InitializeMonitor extends AbstractPluginLifecycleMonitor { |
||||
@Override |
||||
public void afterRun(PluginContext pluginContext) { |
||||
PluginSimpleConfig.getInstance(); |
||||
} |
||||
|
||||
@Override |
||||
public void beforeStop(PluginContext pluginContext) { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,65 @@
|
||||
package com.eco.plugin.xx.hqctb.config; |
||||
|
||||
import com.fr.config.*; |
||||
import com.fr.config.holder.Conf; |
||||
import com.fr.config.holder.factory.Holders; |
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.intelli.record.Original; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
|
||||
@Visualization(category = "数据同步配置") |
||||
@EnableMetrics |
||||
public class PluginSimpleConfig extends DefaultConfiguration { |
||||
|
||||
private static volatile PluginSimpleConfig config = null; |
||||
|
||||
@Focus(id="com.eco.plugin.xx.hqctb.config", text = "数据同步配置", source = Original.PLUGIN) |
||||
public static PluginSimpleConfig getInstance() { |
||||
if (config == null) { |
||||
config = ConfigContext.getConfigInstance(PluginSimpleConfig.class); |
||||
} |
||||
return config; |
||||
} |
||||
|
||||
@Identifier(value = "apiurl", name = "api前缀", description = "api前缀", status = Status.SHOW) |
||||
private Conf<String> apiurl = Holders.simple(""); |
||||
|
||||
@Identifier(value = "systemcode", name = "systemcode", description = "systemcode", status = Status.SHOW) |
||||
private Conf<String> systemcode = Holders.simple(""); |
||||
|
||||
@Identifier(value = "integrationKey", name = "integrationKey", description = "integrationKey", status = Status.SHOW) |
||||
private Conf<String> integrationKey = Holders.simple(""); |
||||
|
||||
public String getApiurl() { |
||||
return apiurl.get(); |
||||
} |
||||
|
||||
public void setApiurl(String url) { |
||||
this.apiurl.set(url); |
||||
} |
||||
|
||||
public String getSystemcode() { |
||||
return systemcode.get(); |
||||
} |
||||
|
||||
public void setSystemcode(String url) { |
||||
this.systemcode.set(url); |
||||
} |
||||
|
||||
public String getIntegrationKey() { |
||||
return integrationKey.get(); |
||||
} |
||||
|
||||
public void setIntegrationKey(String url) { |
||||
this.integrationKey.set(url); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public Object clone() throws CloneNotSupportedException { |
||||
PluginSimpleConfig cloned = (PluginSimpleConfig) super.clone(); |
||||
|
||||
return cloned; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,171 @@
|
||||
package com.eco.plugin.xx.hqctb.db.bean; |
||||
|
||||
import com.fr.stable.db.entity.BaseEntity; |
||||
import com.fr.stable.db.entity.TableAssociation; |
||||
import com.fr.third.javax.persistence.Column; |
||||
import com.fr.third.javax.persistence.Entity; |
||||
import com.fr.third.javax.persistence.Table; |
||||
|
||||
/** |
||||
* @author xx |
||||
* @version 10.0 |
||||
* Created by xx on 2021-07-29 |
||||
**/ |
||||
@Entity |
||||
@Table(name = "dept_info") |
||||
@TableAssociation(associated = true) |
||||
public class DeptEntity extends BaseEntity { |
||||
@Column(name = "_PARENT") |
||||
private String _PARENT = null; |
||||
|
||||
@Column(name = "_ORGANIZATION") |
||||
private String _ORGANIZATION = null; |
||||
|
||||
@Column(name = "CODE") |
||||
private String CODE = null; |
||||
|
||||
@Column(name = "NAME") |
||||
private String NAME = null; |
||||
|
||||
@Column(name = "FULLNAME") |
||||
private String FULLNAME = null; |
||||
|
||||
@Column(name = "DESCRIPTION") |
||||
private String DESCRIPTION = null; |
||||
|
||||
@Column(name = "SEQUENCE") |
||||
private String SEQUENCE = null; |
||||
|
||||
@Column(name = "IS_DISABLED") |
||||
private String IS_DISABLED = null; |
||||
|
||||
@Column(name = "CREATE_AT") |
||||
private String CREATE_AT = null; |
||||
|
||||
@Column(name = "UPDATE_AT") |
||||
private String UPDATE_AT = null; |
||||
|
||||
@Column(name = "COMPANY_CODE") |
||||
private String COMPANY_CODE = null; |
||||
|
||||
@Column(name = "EFFECT_SIGN") |
||||
private String EFFECT_SIGN = null; |
||||
|
||||
@Column(name = "ORG_TYPE") |
||||
private String ORG_TYPE = null; |
||||
|
||||
@Column(name = "PARENT_CODE") |
||||
private String PARENT_CODE = null; |
||||
|
||||
public String get_PARENT() { |
||||
return _PARENT; |
||||
} |
||||
|
||||
public void set_PARENT(String _PARENT) { |
||||
this._PARENT = _PARENT; |
||||
} |
||||
|
||||
public String get_ORGANIZATION() { |
||||
return _ORGANIZATION; |
||||
} |
||||
|
||||
public void set_ORGANIZATION(String _ORGANIZATION) { |
||||
this._ORGANIZATION = _ORGANIZATION; |
||||
} |
||||
|
||||
public String getCODE() { |
||||
return CODE; |
||||
} |
||||
|
||||
public void setCODE(String CODE) { |
||||
this.CODE = CODE; |
||||
} |
||||
|
||||
public String getNAME() { |
||||
return NAME; |
||||
} |
||||
|
||||
public void setNAME(String NAME) { |
||||
this.NAME = NAME; |
||||
} |
||||
|
||||
public String getFULLNAME() { |
||||
return FULLNAME; |
||||
} |
||||
|
||||
public void setFULLNAME(String FULLNAME) { |
||||
this.FULLNAME = FULLNAME; |
||||
} |
||||
|
||||
public String getDESCRIPTION() { |
||||
return DESCRIPTION; |
||||
} |
||||
|
||||
public void setDESCRIPTION(String DESCRIPTION) { |
||||
this.DESCRIPTION = DESCRIPTION; |
||||
} |
||||
|
||||
public String getSEQUENCE() { |
||||
return SEQUENCE; |
||||
} |
||||
|
||||
public void setSEQUENCE(String SEQUENCE) { |
||||
this.SEQUENCE = SEQUENCE; |
||||
} |
||||
|
||||
public String getIS_DISABLED() { |
||||
return IS_DISABLED; |
||||
} |
||||
|
||||
public void setIS_DISABLED(String IS_DISABLED) { |
||||
this.IS_DISABLED = IS_DISABLED; |
||||
} |
||||
|
||||
public String getCREATE_AT() { |
||||
return CREATE_AT; |
||||
} |
||||
|
||||
public void setCREATE_AT(String CREATE_AT) { |
||||
this.CREATE_AT = CREATE_AT; |
||||
} |
||||
|
||||
public String getUPDATE_AT() { |
||||
return UPDATE_AT; |
||||
} |
||||
|
||||
public void setUPDATE_AT(String UPDATE_AT) { |
||||
this.UPDATE_AT = UPDATE_AT; |
||||
} |
||||
|
||||
public String getCOMPANY_CODE() { |
||||
return COMPANY_CODE; |
||||
} |
||||
|
||||
public void setCOMPANY_CODE(String COMPANY_CODE) { |
||||
this.COMPANY_CODE = COMPANY_CODE; |
||||
} |
||||
|
||||
public String getEFFECT_SIGN() { |
||||
return EFFECT_SIGN; |
||||
} |
||||
|
||||
public void setEFFECT_SIGN(String EFFECT_SIGN) { |
||||
this.EFFECT_SIGN = EFFECT_SIGN; |
||||
} |
||||
|
||||
public String getORG_TYPE() { |
||||
return ORG_TYPE; |
||||
} |
||||
|
||||
public void setORG_TYPE(String ORG_TYPE) { |
||||
this.ORG_TYPE = ORG_TYPE; |
||||
} |
||||
|
||||
public String getPARENT_CODE() { |
||||
return PARENT_CODE; |
||||
} |
||||
|
||||
public void setPARENT_CODE(String PARENT_CODE) { |
||||
this.PARENT_CODE = PARENT_CODE; |
||||
} |
||||
} |
@ -0,0 +1,259 @@
|
||||
package com.eco.plugin.xx.hqctb.db.bean; |
||||
|
||||
import com.fr.stable.db.entity.BaseEntity; |
||||
import com.fr.stable.db.entity.TableAssociation; |
||||
import com.fr.third.javax.persistence.Column; |
||||
import com.fr.third.javax.persistence.Entity; |
||||
import com.fr.third.javax.persistence.Table; |
||||
|
||||
/** |
||||
* @author xx |
||||
* @version 10.0 |
||||
* Created by xx on 2021-07-29 |
||||
**/ |
||||
@Entity |
||||
@Table(name = "user_info") |
||||
@TableAssociation(associated = true) |
||||
public class UserEntity extends BaseEntity { |
||||
@Column(name = "_USER") |
||||
private String _USER = null; |
||||
|
||||
@Column(name = "_ORGANIZATION") |
||||
private String _ORGANIZATION = null; |
||||
|
||||
@Column(name = "USERNAME") |
||||
private String USERNAME = null; |
||||
|
||||
@Column(name = "PASSWORD") |
||||
private String PASSWORD = null; |
||||
|
||||
@Column(name = "FULLNAME") |
||||
private String FULLNAME = null; |
||||
|
||||
@Column(name = "IS_DISABLED") |
||||
private String IS_DISABLED = null; |
||||
|
||||
@Column(name = "IS_LOCKED") |
||||
private String IS_LOCKED = null; |
||||
|
||||
@Column(name = "CREATE_AT") |
||||
private String CREATE_AT = null; |
||||
|
||||
@Column(name = "UPDATE_AT") |
||||
private String UPDATE_AT = null; |
||||
|
||||
@Column(name = "IS_SYSTEM") |
||||
private String IS_SYSTEM = null; |
||||
|
||||
@Column(name = "IS_PUBLIC") |
||||
private String IS_PUBLIC = null; |
||||
|
||||
@Column(name = "IS_MASTER") |
||||
private String IS_MASTER = null; |
||||
|
||||
@Column(name = "EMAIL") |
||||
private String EMAIL = null; |
||||
|
||||
@Column(name = "CERT_NO") |
||||
private String CERT_NO = null; |
||||
|
||||
@Column(name = "COMPANY_CODE") |
||||
private String COMPANY_CODE = null; |
||||
|
||||
@Column(name = "DEPART_CODE") |
||||
private String DEPART_CODE = null; |
||||
|
||||
@Column(name = "EFFECT_SIGN") |
||||
private String EFFECT_SIGN = null; |
||||
|
||||
@Column(name = "EMPLOYEE_NO") |
||||
private String EMPLOYEE_NO = null; |
||||
|
||||
@Column(name = "GENDER") |
||||
private String GENDER = null; |
||||
|
||||
@Column(name = "JOB_NAME") |
||||
private String JOB_NAME = null; |
||||
|
||||
@Column(name = "WS_TYPE") |
||||
private String WS_TYPE = null; |
||||
|
||||
@Column(name = "mobile") |
||||
private String mobile = null; |
||||
|
||||
public String getMobile() { |
||||
return mobile; |
||||
} |
||||
|
||||
public void setMobile(String mobile) { |
||||
this.mobile = mobile; |
||||
} |
||||
|
||||
public String get_USER() { |
||||
return _USER; |
||||
} |
||||
|
||||
public void set_USER(String _USER) { |
||||
this._USER = _USER; |
||||
} |
||||
|
||||
public String get_ORGANIZATION() { |
||||
return _ORGANIZATION; |
||||
} |
||||
|
||||
public void set_ORGANIZATION(String _ORGANIZATION) { |
||||
this._ORGANIZATION = _ORGANIZATION; |
||||
} |
||||
|
||||
public String getUSERNAME() { |
||||
return USERNAME; |
||||
} |
||||
|
||||
public void setUSERNAME(String USERNAME) { |
||||
this.USERNAME = USERNAME; |
||||
} |
||||
|
||||
public String getPASSWORD() { |
||||
return PASSWORD; |
||||
} |
||||
|
||||
public void setPASSWORD(String PASSWORD) { |
||||
this.PASSWORD = PASSWORD; |
||||
} |
||||
|
||||
public String getFULLNAME() { |
||||
return FULLNAME; |
||||
} |
||||
|
||||
public void setFULLNAME(String FULLNAME) { |
||||
this.FULLNAME = FULLNAME; |
||||
} |
||||
|
||||
public String getIS_DISABLED() { |
||||
return IS_DISABLED; |
||||
} |
||||
|
||||
public void setIS_DISABLED(String IS_DISABLED) { |
||||
this.IS_DISABLED = IS_DISABLED; |
||||
} |
||||
|
||||
public String getIS_LOCKED() { |
||||
return IS_LOCKED; |
||||
} |
||||
|
||||
public void setIS_LOCKED(String IS_LOCKED) { |
||||
this.IS_LOCKED = IS_LOCKED; |
||||
} |
||||
|
||||
public String getCREATE_AT() { |
||||
return CREATE_AT; |
||||
} |
||||
|
||||
public void setCREATE_AT(String CREATE_AT) { |
||||
this.CREATE_AT = CREATE_AT; |
||||
} |
||||
|
||||
public String getUPDATE_AT() { |
||||
return UPDATE_AT; |
||||
} |
||||
|
||||
public void setUPDATE_AT(String UPDATE_AT) { |
||||
this.UPDATE_AT = UPDATE_AT; |
||||
} |
||||
|
||||
public String getIS_SYSTEM() { |
||||
return IS_SYSTEM; |
||||
} |
||||
|
||||
public void setIS_SYSTEM(String IS_SYSTEM) { |
||||
this.IS_SYSTEM = IS_SYSTEM; |
||||
} |
||||
|
||||
public String getIS_PUBLIC() { |
||||
return IS_PUBLIC; |
||||
} |
||||
|
||||
public void setIS_PUBLIC(String IS_PUBLIC) { |
||||
this.IS_PUBLIC = IS_PUBLIC; |
||||
} |
||||
|
||||
public String getIS_MASTER() { |
||||
return IS_MASTER; |
||||
} |
||||
|
||||
public void setIS_MASTER(String IS_MASTER) { |
||||
this.IS_MASTER = IS_MASTER; |
||||
} |
||||
|
||||
public String getEMAIL() { |
||||
return EMAIL; |
||||
} |
||||
|
||||
public void setEMAIL(String EMAIL) { |
||||
this.EMAIL = EMAIL; |
||||
} |
||||
|
||||
public String getCERT_NO() { |
||||
return CERT_NO; |
||||
} |
||||
|
||||
public void setCERT_NO(String CERT_NO) { |
||||
this.CERT_NO = CERT_NO; |
||||
} |
||||
|
||||
public String getCOMPANY_CODE() { |
||||
return COMPANY_CODE; |
||||
} |
||||
|
||||
public void setCOMPANY_CODE(String COMPANY_CODE) { |
||||
this.COMPANY_CODE = COMPANY_CODE; |
||||
} |
||||
|
||||
public String getDEPART_CODE() { |
||||
return DEPART_CODE; |
||||
} |
||||
|
||||
public void setDEPART_CODE(String DEPART_CODE) { |
||||
this.DEPART_CODE = DEPART_CODE; |
||||
} |
||||
|
||||
public String getEFFECT_SIGN() { |
||||
return EFFECT_SIGN; |
||||
} |
||||
|
||||
public void setEFFECT_SIGN(String EFFECT_SIGN) { |
||||
this.EFFECT_SIGN = EFFECT_SIGN; |
||||
} |
||||
|
||||
public String getEMPLOYEE_NO() { |
||||
return EMPLOYEE_NO; |
||||
} |
||||
|
||||
public void setEMPLOYEE_NO(String EMPLOYEE_NO) { |
||||
this.EMPLOYEE_NO = EMPLOYEE_NO; |
||||
} |
||||
|
||||
public String getGENDER() { |
||||
return GENDER; |
||||
} |
||||
|
||||
public void setGENDER(String GENDER) { |
||||
this.GENDER = GENDER; |
||||
} |
||||
|
||||
public String getJOB_NAME() { |
||||
return JOB_NAME; |
||||
} |
||||
|
||||
public void setJOB_NAME(String JOB_NAME) { |
||||
this.JOB_NAME = JOB_NAME; |
||||
} |
||||
|
||||
public String getWS_TYPE() { |
||||
return WS_TYPE; |
||||
} |
||||
|
||||
public void setWS_TYPE(String WS_TYPE) { |
||||
this.WS_TYPE = WS_TYPE; |
||||
} |
||||
} |
@ -0,0 +1,185 @@
|
||||
package com.eco.plugin.xx.hqctb.db.controller; |
||||
|
||||
import com.eco.plugin.xx.hqctb.db.bean.DeptEntity; |
||||
import com.eco.plugin.xx.hqctb.db.bean.UserEntity; |
||||
import com.eco.plugin.xx.hqctb.db.dao.DeptDao; |
||||
import com.eco.plugin.xx.hqctb.db.dao.UserDao; |
||||
import com.eco.plugin.xx.hqctb.utils.FRUtils; |
||||
import com.fr.db.fun.impl.AbstractDBAccessProvider; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.stable.db.accessor.DBAccessor; |
||||
import com.fr.stable.db.action.DBAction; |
||||
import com.fr.stable.db.dao.DAOContext; |
||||
import com.fr.stable.db.dao.DAOProvider; |
||||
import com.fr.third.jgroups.util.UUID; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author xx |
||||
* @version 10.0 |
||||
* Created by xx on 2021-07-29 |
||||
**/ |
||||
@EnableMetrics |
||||
@FunctionRecorder |
||||
public class DBController extends AbstractDBAccessProvider { |
||||
|
||||
private static DBAccessor accessor; |
||||
|
||||
public static DBAccessor getAccessor() { |
||||
return accessor; |
||||
} |
||||
|
||||
@Override |
||||
public DAOProvider[] registerDAO() { |
||||
return new DAOProvider[]{ |
||||
UserDao.DAO, DeptDao.DAO |
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
public void onDBAvailable(DBAccessor accessor) { |
||||
DBController.accessor = accessor; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 批量操作 |
||||
* @param addOrUpdate |
||||
* @param delete |
||||
* @return |
||||
*/ |
||||
public static boolean batch(List<UserEntity> addOrUpdate, List<UserEntity> delete){ |
||||
//新增或者删除
|
||||
if(addOrUpdate != null && addOrUpdate.size() > 0){ |
||||
for(final UserEntity dbe : addOrUpdate){ |
||||
|
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
UserEntity ae =context.getDAO(UserDao.class).getByUsername(dbe.getUSERNAME()); |
||||
if(ae != null ){ |
||||
dbe.setId(ae.getId()); |
||||
context.getDAO(UserDao.class).update(dbe); |
||||
}else{ |
||||
context.getDAO(UserDao.class).add(dbe); |
||||
} |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("batch addOrUpdate exception ->"+e.getMessage() + dbe.toString()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
if(delete != null && delete.size() > 0){ |
||||
for(final UserEntity dbe : delete){ |
||||
|
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
context.getDAO(UserDao.class).remove(dbe.getId()); |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("batch delete exception ->"+e.getMessage() + dbe.toString()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 单个操作 |
||||
* @param addOrUpdate |
||||
* @param delete |
||||
* @return |
||||
*/ |
||||
public static boolean singleUser(UserEntity addOrUpdate,UserEntity delete) throws Exception { |
||||
//新增或者删除
|
||||
if(addOrUpdate != null ){ |
||||
|
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
UserEntity ae =context.getDAO(UserDao.class).getByUsername(addOrUpdate.getUSERNAME()); |
||||
if(ae != null ){ |
||||
addOrUpdate.setId(ae.getId()); |
||||
context.getDAO(UserDao.class).update(addOrUpdate); |
||||
}else{ |
||||
addOrUpdate.setId(UUID.randomUUID().toString()); |
||||
context.getDAO(UserDao.class).add(addOrUpdate); |
||||
} |
||||
return true; |
||||
} |
||||
}); |
||||
|
||||
} |
||||
|
||||
if(delete != null ){ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
UserEntity ae =context.getDAO(UserDao.class).getByUsername(addOrUpdate.getUSERNAME()); |
||||
context.getDAO(UserDao.class).remove(ae.getId()); |
||||
return true; |
||||
} |
||||
}); |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
|
||||
|
||||
/** |
||||
* 单个操作 |
||||
* @param addOrUpdate |
||||
* @param delete |
||||
* @return |
||||
*/ |
||||
public static boolean singleDept(DeptEntity addOrUpdate,DeptEntity delete) throws Exception { |
||||
//新增或者删除
|
||||
if(addOrUpdate != null ){ |
||||
|
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
DeptEntity ae =context.getDAO(DeptDao.class).getByCode(addOrUpdate.getCODE()); |
||||
if(ae != null ){ |
||||
addOrUpdate.setId(ae.getId()); |
||||
context.getDAO(DeptDao.class).update(addOrUpdate); |
||||
}else{ |
||||
addOrUpdate.setId(UUID.randomUUID().toString()); |
||||
context.getDAO(DeptDao.class).add(addOrUpdate); |
||||
} |
||||
return true; |
||||
} |
||||
}); |
||||
|
||||
} |
||||
|
||||
if(delete != null ){ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
DeptEntity ae =context.getDAO(DeptDao.class).getByCode(delete.getCODE()); |
||||
|
||||
context.getDAO(DeptDao.class).remove(ae.getId()); |
||||
return true; |
||||
} |
||||
}); |
||||
|
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,68 @@
|
||||
package com.eco.plugin.xx.hqctb.db.dao; |
||||
|
||||
import com.eco.plugin.xx.hqctb.db.bean.DeptEntity; |
||||
import com.fr.stable.db.dao.BaseDAO; |
||||
import com.fr.stable.db.dao.DAOProvider; |
||||
import com.fr.stable.db.session.DAOSession; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.condition.QueryCondition; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author xx |
||||
* @version 10.0 |
||||
* Created by xx on 2021-12-03 |
||||
**/ |
||||
public class DeptDao extends BaseDAO<DeptEntity> { |
||||
|
||||
public DeptDao(DAOSession session) { |
||||
super(session); |
||||
} |
||||
|
||||
@Override |
||||
protected Class<DeptEntity> getEntityClass() { |
||||
return DeptEntity.class; |
||||
} |
||||
|
||||
public final static DAOProvider DAO = new DAOProvider() { |
||||
@Override |
||||
public Class getEntityClass() { |
||||
return DeptEntity.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends BaseDAO> getDAOClass() { |
||||
return DeptDao.class; |
||||
} |
||||
}; |
||||
|
||||
public void add(DeptEntity entity) throws Exception { |
||||
getSession().persist(entity); |
||||
} |
||||
|
||||
public void remove(String id) throws Exception { |
||||
getSession().remove(QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.eq("id", id)), |
||||
this.getEntityClass()); |
||||
} |
||||
|
||||
public void update(DeptEntity entity) throws Exception { |
||||
getSession().merge(entity); |
||||
} |
||||
|
||||
|
||||
public DeptEntity getByCode(String username) throws Exception { |
||||
QueryCondition condition = QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.eq("CODE", username)); |
||||
|
||||
return findOne(condition); |
||||
} |
||||
|
||||
|
||||
public List<DeptEntity> like(String pid, String type)throws Exception{ |
||||
QueryCondition condition = QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.like("", pid)).addRestriction(RestrictionFactory.like(DeptEntity.COLUMN_ID,type)); |
||||
return find(condition); |
||||
} |
||||
} |
@ -0,0 +1,69 @@
|
||||
package com.eco.plugin.xx.hqctb.db.dao; |
||||
|
||||
import com.eco.plugin.xx.hqctb.db.bean.UserEntity; |
||||
import com.fr.stable.db.dao.BaseDAO; |
||||
import com.fr.stable.db.dao.DAOProvider; |
||||
import com.fr.stable.db.session.DAOSession; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.condition.QueryCondition; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author xx |
||||
* @version 10.0 |
||||
* Created by xx on 2021-12-03 |
||||
**/ |
||||
public class UserDao extends BaseDAO<UserEntity> { |
||||
|
||||
public UserDao(DAOSession session) { |
||||
super(session); |
||||
} |
||||
|
||||
@Override |
||||
protected Class<UserEntity> getEntityClass() { |
||||
return UserEntity.class; |
||||
} |
||||
|
||||
public final static DAOProvider DAO = new DAOProvider() { |
||||
@Override |
||||
public Class getEntityClass() { |
||||
return UserEntity.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends BaseDAO> getDAOClass() { |
||||
return UserDao.class; |
||||
} |
||||
}; |
||||
|
||||
public void add(UserEntity entity) throws Exception { |
||||
getSession().persist(entity); |
||||
} |
||||
|
||||
public void remove(String id) throws Exception { |
||||
getSession().remove(QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.eq("id", id)), |
||||
this.getEntityClass()); |
||||
} |
||||
|
||||
public void update(UserEntity entity) throws Exception { |
||||
getSession().merge(entity); |
||||
} |
||||
|
||||
|
||||
public UserEntity getByUsername(String username) throws Exception { |
||||
QueryCondition condition = QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.eq("USERNAME", username)); |
||||
|
||||
return findOne(condition); |
||||
} |
||||
|
||||
|
||||
public List<UserEntity> like(String pid, String type)throws Exception{ |
||||
QueryCondition condition = QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.like("", pid)).addRestriction(RestrictionFactory.like(UserEntity.COLUMN_ID,type)); |
||||
return find(condition); |
||||
} |
||||
} |
@ -0,0 +1,284 @@
|
||||
package com.eco.plugin.xx.hqctb.function; |
||||
|
||||
import com.eco.plugin.xx.hqctb.config.PluginSimpleConfig; |
||||
import com.eco.plugin.xx.hqctb.utils.FRUtils; |
||||
import com.eco.plugin.xx.hqctb.utils.HttpUtils; |
||||
import com.eco.plugin.xx.hqctb.utils.JDBCUtils; |
||||
import com.eco.plugin.xx.hqctb.utils.Utils; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.script.AbstractFunction; |
||||
import java.io.UnsupportedEncodingException; |
||||
import java.net.URLEncoder; |
||||
import java.sql.Connection; |
||||
import java.sql.PreparedStatement; |
||||
import java.sql.SQLException; |
||||
|
||||
public class AuthFunction extends AbstractFunction { |
||||
|
||||
|
||||
@Override |
||||
public Object run(Object[] objects) { |
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
String tokenid = login(psc); |
||||
|
||||
if(Utils.isNullStr(tokenid)){ |
||||
FRUtils.FRLogError("登陆失败"); |
||||
return "FAIL"; |
||||
} |
||||
|
||||
JSONObject pullJsonObj = new JSONObject(); |
||||
pullJsonObj.put("tokenId", tokenid); |
||||
|
||||
pullTaskAndFinishForJsonObj(psc,pullJsonObj,tokenid); |
||||
logout(psc,pullJsonObj); |
||||
return "SUCCESS"; |
||||
} |
||||
|
||||
//获取token
|
||||
private static String login(PluginSimpleConfig psc) { |
||||
JSONObject loginJsonObj = new JSONObject(); |
||||
loginJsonObj.put("systemCode", psc.getSystemcode()); |
||||
loginJsonObj.put("integrationKey", psc.getIntegrationKey()); |
||||
loginJsonObj.put("force", true); |
||||
loginJsonObj.put("timestamp", Integer.valueOf(Long.toString(System.currentTimeMillis() / 1000L))); |
||||
|
||||
String url = null; |
||||
try { |
||||
url = psc.getApiurl()+"?method=login&request="+ URLEncoder.encode(loginJsonObj.toString(),"Utf-8"); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FRUtils.FRLogError("url编码异常"); |
||||
return ""; |
||||
} |
||||
String result = HttpUtils.httpGet(url,null,null); |
||||
|
||||
if(Utils.isNullStr(result)){ |
||||
return ""; |
||||
} |
||||
|
||||
JSONObject json = new JSONObject(result); |
||||
Boolean isLoginSuccess = json.getBoolean("success"); |
||||
|
||||
if(isLoginSuccess){ |
||||
return json.getString("tokenId"); |
||||
} |
||||
|
||||
return ""; |
||||
} |
||||
|
||||
//获取token
|
||||
private static void logout(PluginSimpleConfig psc,JSONObject param) { |
||||
param.put("timestamp", Integer.valueOf(Long.toString(System.currentTimeMillis() / 1000L))); |
||||
String url = null; |
||||
try { |
||||
url = psc.getApiurl()+"?method=logout&request="+ URLEncoder.encode(param.toString(),"Utf-8"); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FRUtils.FRLogError("url编码异常"); |
||||
return ; |
||||
} |
||||
String result = HttpUtils.httpGet(url,null,null); |
||||
if(Utils.isNullStr(result)){ |
||||
FRUtils.FRLogError("登出异常:"); |
||||
return ; |
||||
} |
||||
|
||||
JSONObject json = new JSONObject(result); |
||||
Boolean isLoginSuccess = json.getBoolean("success"); |
||||
|
||||
if (!isLoginSuccess) { |
||||
FRUtils.FRLogInfo("登出失败!"); |
||||
} |
||||
} |
||||
|
||||
|
||||
//操作用户
|
||||
private static void operateUser(JSONObject pullResObject) throws Exception { |
||||
Connection conn = null; |
||||
PreparedStatement ps = null; |
||||
String effectOn = pullResObject.getString("effectOn"); |
||||
JSONObject orgJsonObj = pullResObject.getJSONObject("data"); |
||||
StringBuilder deleteSQL; |
||||
|
||||
if ("DELETED".equals(effectOn)) { |
||||
conn = JDBCUtils.getConnect(); |
||||
conn.setAutoCommit(false); |
||||
deleteSQL = new StringBuilder(); |
||||
deleteSQL.append("delete from user_info where username = ?"); |
||||
ps = conn.prepareStatement(deleteSQL.toString()); |
||||
ps.setString(1, orgJsonObj.getString("username")); |
||||
ps.executeUpdate(); |
||||
conn.commit(); |
||||
} else { |
||||
conn = JDBCUtils.getConnect(); |
||||
conn.setAutoCommit(false); |
||||
deleteSQL = new StringBuilder(); |
||||
deleteSQL.append("replace into user_info "); |
||||
deleteSQL.append("(_user, _organization, username, password, fullname, "); |
||||
deleteSQL.append(" is_disabled, is_locked, create_at, update_at, is_system, "); |
||||
deleteSQL.append(" is_public, is_master, email, company_code, "); |
||||
deleteSQL.append(" depart_code, effect_sign, job_name, mobile) "); |
||||
deleteSQL.append(" values "); |
||||
deleteSQL.append("(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); |
||||
ps = conn.prepareStatement(deleteSQL.toString()); |
||||
ps.setString(1, orgJsonObj.getString("_user")); |
||||
ps.setString(2, orgJsonObj.getString("_organization")); |
||||
ps.setString(3, orgJsonObj.getString("username")); |
||||
ps.setString(4, orgJsonObj.getString("password")); |
||||
ps.setString(5, orgJsonObj.getString("fullname")); |
||||
ps.setString(6, orgJsonObj.getString("isDisabled")); |
||||
ps.setString(7, orgJsonObj.getString("isLocked")); |
||||
ps.setString(8, orgJsonObj.getString("createAt")); |
||||
ps.setString(9, orgJsonObj.getString("updateAt")); |
||||
ps.setString(10, orgJsonObj.getString("isSystem")); |
||||
ps.setString(11, orgJsonObj.getString("isPublic")); |
||||
ps.setString(12, orgJsonObj.getString("isMaster")); |
||||
ps.setString(13, orgJsonObj.getString("email")); |
||||
ps.setString(14, orgJsonObj.getString("companyCode")); |
||||
ps.setString(15, orgJsonObj.getString("departCode")); |
||||
ps.setString(16, orgJsonObj.getString("effectSign")); |
||||
ps.setString(17, orgJsonObj.getString("jobName")); |
||||
ps.setString(18, orgJsonObj.getString("mobile")); |
||||
ps.executeUpdate(); |
||||
conn.commit(); |
||||
} |
||||
|
||||
release(conn,ps); |
||||
} |
||||
|
||||
|
||||
|
||||
//操作机构
|
||||
private static void operateDept(JSONObject pullResObject) throws Exception { |
||||
Connection conn = null; |
||||
PreparedStatement ps = null; |
||||
String effectOn = pullResObject.getString("effectOn"); |
||||
JSONObject orgJsonObj = pullResObject.getJSONObject("data"); |
||||
StringBuilder deleteSQL; |
||||
|
||||
if ("DELETED".equals(effectOn)) { |
||||
conn = JDBCUtils.getConnect(); |
||||
conn.setAutoCommit(false); |
||||
deleteSQL = new StringBuilder(); |
||||
deleteSQL.append("delete from dept_info where code = ?"); |
||||
ps = conn.prepareStatement(deleteSQL.toString()); |
||||
ps.setString(1, orgJsonObj.getString("code")); |
||||
ps.executeUpdate(); |
||||
conn.commit(); |
||||
} else { |
||||
conn = JDBCUtils.getConnect(); |
||||
conn.setAutoCommit(false); |
||||
deleteSQL = new StringBuilder(); |
||||
deleteSQL.append("replace into dept_info "); |
||||
deleteSQL.append("(_parent, _organization, code, name, fullname, "); |
||||
deleteSQL.append(" description, sequence, is_disabled, create_at, update_at, "); |
||||
deleteSQL.append(" company_code, effect_sign, org_type, parent_code) "); |
||||
deleteSQL.append(" values "); |
||||
deleteSQL.append("(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); |
||||
ps = conn.prepareStatement(deleteSQL.toString()); |
||||
ps.setString(1, orgJsonObj.getString("_parent")); |
||||
ps.setString(2, orgJsonObj.getString("_organization")); |
||||
ps.setString(3, orgJsonObj.getString("code")); |
||||
ps.setString(4, orgJsonObj.getString("name")); |
||||
ps.setString(5, orgJsonObj.getString("fullname")); |
||||
ps.setString(6, orgJsonObj.getString("description")); |
||||
ps.setString(7, orgJsonObj.getString("sequence")); |
||||
ps.setString(8, orgJsonObj.getString("isDisabled")); |
||||
ps.setString(9, orgJsonObj.getString("createAt")); |
||||
ps.setString(10, orgJsonObj.getString("updateAt")); |
||||
ps.setString(11, orgJsonObj.getString("companyCode")); |
||||
ps.setString(12, orgJsonObj.getString("effectSign")); |
||||
ps.setString(13, orgJsonObj.getString("orgType")); |
||||
ps.setString(14, orgJsonObj.getString("parentCode")); |
||||
ps.executeUpdate(); |
||||
conn.commit(); |
||||
} |
||||
|
||||
release(conn,ps); |
||||
} |
||||
|
||||
public static void pullTaskAndFinishForJsonObj(PluginSimpleConfig psc, JSONObject param, String tokenId) { |
||||
param.put("timestamp", Integer.valueOf(Long.toString(System.currentTimeMillis() / 1000L))); |
||||
String url = null; |
||||
try { |
||||
url = psc.getApiurl()+"?method=pullTask&request="+ URLEncoder.encode(param.toString(),"Utf-8"); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FRUtils.FRLogError("url编码异常"); |
||||
return ; |
||||
} |
||||
|
||||
String pullRes = HttpUtils.httpGet(url,null,null); |
||||
|
||||
if(Utils.isNullStr(pullRes)){ |
||||
return ; |
||||
} |
||||
|
||||
JSONObject pullResObject = new JSONObject(pullRes); |
||||
boolean isPullSuccess = pullResObject.getBoolean("success"); |
||||
|
||||
if(!isPullSuccess){ |
||||
return ; |
||||
} |
||||
|
||||
|
||||
String taskId = pullResObject.getString("taskId"); |
||||
String objectType = pullResObject.getString("objectType"); |
||||
String guid = pullResObject.getString("id"); |
||||
JSONObject orgJsonObj; |
||||
try{ |
||||
if ("TARGET_ACCOUNT".equals(objectType)) { |
||||
operateUser(pullResObject); |
||||
|
||||
} else if ("TARGET_ORGANIZATION".equals(objectType)) { |
||||
operateDept(pullResObject); |
||||
} |
||||
}catch (Exception e){ |
||||
FRUtils.FRLogError("操作数据库异常"+e.getMessage()); |
||||
return ; |
||||
} |
||||
|
||||
orgJsonObj = new JSONObject(); |
||||
orgJsonObj.put("tokenId", tokenId); |
||||
orgJsonObj.put("taskId", taskId); |
||||
orgJsonObj.put("guid", guid); |
||||
orgJsonObj.put("success", true); |
||||
orgJsonObj.put("timestamp", Integer.valueOf(Long.toString(System.currentTimeMillis() / 1000L))); |
||||
String finishUrl = null; |
||||
try { |
||||
finishUrl = psc.getApiurl()+"?method=pullFinish&request="+ URLEncoder.encode(orgJsonObj.toString(),"Utf-8"); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FRUtils.FRLogError("url编码异常"); |
||||
return ; |
||||
} |
||||
String pullFinishRes = HttpUtils.httpGet(finishUrl,null,null); |
||||
JSONObject pullFinishResObject = new JSONObject(pullFinishRes); |
||||
|
||||
boolean isPullFinish = pullFinishResObject.getBoolean("success"); |
||||
|
||||
if (isPullFinish) { |
||||
pullTaskAndFinishForJsonObj(psc,param,tokenId); |
||||
} |
||||
|
||||
return ; |
||||
} |
||||
|
||||
private static void release(Connection conn, PreparedStatement ps) { |
||||
try { |
||||
if(ps!=null) { |
||||
ps.close(); |
||||
} |
||||
} catch (SQLException e) { |
||||
FRUtils.FRLogError("关闭ps异常"); |
||||
} finally { |
||||
ps=null; |
||||
} |
||||
|
||||
try { |
||||
if(conn!=null) { |
||||
conn.close(); |
||||
} |
||||
} catch (SQLException e) { |
||||
FRUtils.FRLogError("关闭conn异常"); |
||||
} finally { |
||||
conn=null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,280 @@
|
||||
package com.eco.plugin.xx.hqctb.utils; |
||||
|
||||
import com.fr.base.ServerConfig; |
||||
import com.fr.base.TableData; |
||||
import com.fr.base.TemplateUtils; |
||||
import com.fr.decision.authority.AuthorityContext; |
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.webservice.bean.authentication.OriginUrlResponseBean; |
||||
import com.fr.decision.webservice.interceptor.handler.ReportTemplateRequestChecker; |
||||
import com.fr.decision.webservice.login.LogInOutResultInfo; |
||||
import com.fr.decision.webservice.utils.DecisionServiceConstants; |
||||
import com.fr.decision.webservice.utils.DecisionStatusService; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import com.fr.decision.webservice.v10.login.event.LogInOutEvent; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
import com.fr.event.EventDispatcher; |
||||
import com.fr.file.TableDataConfig; |
||||
import com.fr.general.data.DataModel; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.script.Calculator; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
import com.fr.third.springframework.web.method.HandlerMethod; |
||||
import com.fr.web.controller.ReportRequestService; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.Cookie; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import javax.servlet.http.HttpSession; |
||||
import java.io.IOException; |
||||
import java.util.List; |
||||
|
||||
public class FRUtils { |
||||
/** |
||||
* 判断用户是否存在 |
||||
* @param userName |
||||
* @return |
||||
*/ |
||||
public static boolean isUserExist(String userName){ |
||||
if (StringUtils.isEmpty(userName)) { |
||||
return false; |
||||
} else { |
||||
try { |
||||
List var1 = AuthorityContext.getInstance().getUserController().find(QueryFactory.create().addRestriction(RestrictionFactory.eq("userName", userName))); |
||||
return var1 != null && !var1.isEmpty(); |
||||
} catch (Exception var2) { |
||||
FineLoggerFactory.getLogger().error(var2.getMessage()); |
||||
return false; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 判断是否登录FR |
||||
* @param req |
||||
* @return |
||||
*/ |
||||
public static boolean isLogin(HttpServletRequest req){ |
||||
return LoginService.getInstance().isLogged(req); |
||||
} |
||||
|
||||
/** |
||||
* 帆软登录 |
||||
* @param httpServletRequest |
||||
* @param httpServletResponse |
||||
* @param userName |
||||
* @param url |
||||
*/ |
||||
public static void login(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String userName,String url){ |
||||
|
||||
FineLoggerFactory.getLogger().info("FRLOG:用户名:"+userName); |
||||
FineLoggerFactory.getLogger().info("FRLOG:跳转链接:"+url); |
||||
|
||||
|
||||
//判断用户名是否为空
|
||||
if(!Utils.isNullStr(userName)){ |
||||
if(isUserExist(userName)){ |
||||
String FRToken = ""; |
||||
|
||||
try { |
||||
|
||||
FRToken = LoginService.getInstance().login(httpServletRequest, httpServletResponse, userName); |
||||
|
||||
EventDispatcher.fire(LogInOutEvent.LOGIN,new LogInOutResultInfo(httpServletRequest,httpServletResponse,userName,true)); |
||||
FineLoggerFactory.getLogger().info("FRLOG:登陆成功!"); |
||||
|
||||
if(!Utils.isNullStr(url)){ |
||||
httpServletResponse.sendRedirect(url); |
||||
} |
||||
} catch (Exception e) { |
||||
ResponseUtils.failedResponse(httpServletResponse,"登录异常,请联系管理员!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:登录异常,请联系管理员!"); |
||||
FineLoggerFactory.getLogger().info("FRLOGException:"+e.getMessage()); |
||||
} |
||||
}else{ |
||||
ResponseUtils.failedResponse(httpServletResponse,"用户在报表系统中不存在!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:用户在报表系统中不存在!"); |
||||
} |
||||
}else{ |
||||
ResponseUtils.failedResponse(httpServletResponse,"用户名不能为空!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:用户名不能为空!"); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 帆软登录 |
||||
* @param httpServletRequest |
||||
* @param httpServletResponse |
||||
* @param token |
||||
* @param url |
||||
*/ |
||||
public static void loginByToken(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String token,String url){ |
||||
|
||||
FineLoggerFactory.getLogger().info("FRLOG:token:"+token); |
||||
FineLoggerFactory.getLogger().info("FRLOG:跳转链接:"+url); |
||||
|
||||
|
||||
//判断用户名是否为空
|
||||
if(!Utils.isNullStr(token)){ |
||||
writeToken2Cookie(httpServletResponse,token,-1); |
||||
|
||||
HttpSession session = httpServletRequest.getSession(true); |
||||
|
||||
httpServletRequest.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME,token); |
||||
|
||||
session.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME, token); |
||||
|
||||
if(!Utils.isNullStr(url)){ |
||||
try { |
||||
httpServletResponse.sendRedirect(url); |
||||
} catch (IOException e) { |
||||
ResponseUtils.failedResponse(httpServletResponse,"跳转异常!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:跳转异常!"); |
||||
} |
||||
} |
||||
}else{ |
||||
ResponseUtils.failedResponse(httpServletResponse,"token不能为空!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:token不能为空!"); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取token |
||||
* @param httpServletRequest |
||||
* @param httpServletResponse |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
public static String getToken(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String username){ |
||||
String token = ""; |
||||
try { |
||||
token = LoginService.getInstance().login(httpServletRequest, httpServletResponse, username); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:获取token失败"+e.getMessage()); |
||||
} |
||||
|
||||
return token; |
||||
} |
||||
|
||||
private static void writeToken2Cookie(HttpServletResponse var1, String var2, int var3) { |
||||
try { |
||||
if (StringUtils.isNotEmpty(var2)) { |
||||
Cookie var4 = new Cookie("fine_auth_token", var2); |
||||
long var5 = var3 == -2 ? 1209600000L : (long)var3; |
||||
var4.setMaxAge((int)var5); |
||||
var4.setPath(ServerConfig.getInstance().getCookiePath()); |
||||
var1.addCookie(var4); |
||||
Cookie var7 = new Cookie("fine_remember_login", String.valueOf(var3 == -2 ? -2 : -1)); |
||||
var7.setMaxAge((int)var5); |
||||
var7.setPath(ServerConfig.getInstance().getCookiePath()); |
||||
var1.addCookie(var7); |
||||
} else { |
||||
FineLoggerFactory.getLogger().error("empty token cannot save."); |
||||
} |
||||
} catch (Exception var8) { |
||||
FineLoggerFactory.getLogger().error(var8.getMessage(), var8); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param httpServletRequest |
||||
* @param httpServletResponse |
||||
*/ |
||||
public static void logout(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse) |
||||
{ |
||||
if(!isLogin(httpServletRequest)){ |
||||
return ; |
||||
} |
||||
|
||||
try { |
||||
LoginService.getInstance().logout(httpServletRequest,httpServletResponse); |
||||
} catch (Exception e) { |
||||
ResponseUtils.failedResponse(httpServletResponse,"登出异常,请联系管理员!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:登出异常,请联系管理员!"); |
||||
FineLoggerFactory.getLogger().info("FRLOGException:"+e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 打印FR日志 |
||||
* @param message |
||||
*/ |
||||
public static void FRLogInfo(String message){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:"+message); |
||||
} |
||||
|
||||
/** |
||||
* 打印FR日志-error |
||||
* @param message |
||||
*/ |
||||
public static void FRLogError(String message){ |
||||
FineLoggerFactory.getLogger().error("FRLOG:"+message); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 根据用户名获取用户信息 |
||||
* @param userName |
||||
* @return |
||||
*/ |
||||
public static User getFRUserByUserName(String userName){ |
||||
try { |
||||
return UserService.getInstance().getUserByUserName(userName); |
||||
} catch (Exception e) { |
||||
FRLogInfo("获取用户信息异常:"+e.getMessage()); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
|
||||
|
||||
/** |
||||
* 获取带参数的访问链接 |
||||
* @return |
||||
*/ |
||||
public static String getAllUrl(HttpServletRequest httpServletRequest){ |
||||
return WebUtils.getOriginalURL(httpServletRequest); |
||||
} |
||||
|
||||
/** |
||||
* 根据originKey获取源链接 |
||||
* @param originKey |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static String getOriginUrl(String originKey) throws Exception { |
||||
if (StringUtils.isNotEmpty(originKey)) { |
||||
OriginUrlResponseBean originUrlResponseBean = (OriginUrlResponseBean) DecisionStatusService.originUrlStatusService().get(originKey); |
||||
DecisionStatusService.originUrlStatusService().delete(originKey); |
||||
if (originUrlResponseBean != null) { |
||||
return originUrlResponseBean.getOriginUrl(); |
||||
} |
||||
} |
||||
|
||||
return new OriginUrlResponseBean(TemplateUtils.render("${fineServletURL}")).getOriginUrl(); |
||||
} |
||||
|
||||
/** |
||||
* 判断是否开启模板认证 |
||||
* @param originKey |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static boolean isTempAuth(HttpServletRequest req,HttpServletResponse res) throws Exception { |
||||
ReportTemplateRequestChecker checker = new ReportTemplateRequestChecker(); |
||||
HandlerMethod hm = new HandlerMethod(new ReportRequestService(),ReportRequestService.class.getMethod("preview", HttpServletRequest.class, HttpServletResponse.class, String.class)); |
||||
return checker.checkRequest(req,res,hm); |
||||
} |
||||
|
||||
public static TableData getTableData(String serverDataSetName){ |
||||
TableData userInfo = TableDataConfig.getInstance().getTableData("serverDataSetName"); |
||||
|
||||
return userInfo; |
||||
} |
||||
} |
@ -0,0 +1,286 @@
|
||||
package com.eco.plugin.xx.hqctb.utils; |
||||
|
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.third.guava.collect.Lists; |
||||
import com.fr.third.org.apache.http.*; |
||||
import com.fr.third.org.apache.http.client.CookieStore; |
||||
import com.fr.third.org.apache.http.client.entity.UrlEncodedFormEntity; |
||||
import com.fr.third.org.apache.http.client.methods.HttpGet; |
||||
import com.fr.third.org.apache.http.client.methods.HttpPost; |
||||
import com.fr.third.org.apache.http.conn.ssl.NoopHostnameVerifier; |
||||
import com.fr.third.org.apache.http.entity.StringEntity; |
||||
import com.fr.third.org.apache.http.impl.client.BasicCookieStore; |
||||
import com.fr.third.org.apache.http.impl.client.CloseableHttpClient; |
||||
import com.fr.third.org.apache.http.impl.client.HttpClients; |
||||
import com.fr.third.org.apache.http.impl.cookie.BasicClientCookie; |
||||
import com.fr.third.org.apache.http.message.BasicNameValuePair; |
||||
import com.fr.third.org.apache.http.ssl.SSLContexts; |
||||
import com.fr.third.org.apache.http.ssl.TrustStrategy; |
||||
import com.fr.third.org.apache.http.util.EntityUtils; |
||||
|
||||
import javax.net.ssl.SSLContext; |
||||
import javax.servlet.http.Cookie; |
||||
import java.io.IOException; |
||||
import java.io.UnsupportedEncodingException; |
||||
import java.security.cert.CertificateException; |
||||
import java.security.cert.X509Certificate; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.Set; |
||||
|
||||
public class HttpUtils { |
||||
|
||||
public static String sendHttpGet(String url, String methodType, String requestJsonStr) throws IOException { |
||||
String result = ""; |
||||
CloseableHttpClient client = createHttpClient(null); |
||||
List<NameValuePair> params = Lists.newArrayList(); |
||||
params.add(new BasicNameValuePair("method", methodType)); |
||||
params.add(new BasicNameValuePair("request", requestJsonStr)); |
||||
String str = ""; |
||||
str = EntityUtils.toString(new UrlEncodedFormEntity(params, Consts.UTF_8)); |
||||
System.out.println(str); |
||||
HttpGet method = new HttpGet(url + "?" + str); |
||||
|
||||
try { |
||||
HttpResponse response=client.execute(method); |
||||
int status =response.getStatusLine().getStatusCode(); |
||||
HttpEntity entity = response.getEntity(); |
||||
String returnResult = EntityUtils.toString(entity, "utf-8"); |
||||
} catch (IOException var12) { |
||||
var12.printStackTrace(); |
||||
} finally { |
||||
method.releaseConnection(); |
||||
} |
||||
|
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* httpGet请求 |
||||
* @param url |
||||
* @return |
||||
*/ |
||||
public static String httpGet(String url,Cookie[] cookies,Map<String,String> header){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--url:"+url); |
||||
|
||||
//创建httpClient
|
||||
CloseableHttpClient httpclient = createHttpClient(cookies); |
||||
|
||||
HttpGet getMethod = new HttpGet(url); |
||||
|
||||
if(header != null && header.size() > 0){ |
||||
Set<String> keySet = header.keySet(); |
||||
|
||||
for(String key : keySet){ |
||||
getMethod.setHeader(key,header.get(key)); |
||||
} |
||||
} |
||||
|
||||
try { |
||||
HttpResponse response = httpclient.execute(getMethod); |
||||
int status =response.getStatusLine().getStatusCode(); |
||||
HttpEntity entity = response.getEntity(); |
||||
String returnResult = EntityUtils.toString(entity, "utf-8"); |
||||
|
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--status:"+status); |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--returnResult:"+returnResult); |
||||
|
||||
httpclient.close(); |
||||
|
||||
if (status == HttpStatus.SC_OK) { |
||||
return returnResult; |
||||
} |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--exception:"+e.getMessage()); |
||||
} |
||||
|
||||
try { |
||||
httpclient.close(); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:http关闭异常:"+e.getMessage()); |
||||
} |
||||
|
||||
return ""; |
||||
} |
||||
|
||||
/** |
||||
* HttpPost请求 |
||||
* @param postMethod |
||||
* @return |
||||
*/ |
||||
private static String HttpPost(HttpPost postMethod){ |
||||
CloseableHttpClient httpclient = createHttpClient(null); |
||||
|
||||
try { |
||||
HttpResponse response = httpclient.execute(postMethod); |
||||
int status = response.getStatusLine().getStatusCode(); |
||||
HttpEntity entity = response.getEntity(); |
||||
String returnResult = EntityUtils.toString(entity, "utf-8"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:status:"+status); |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:returnResult:"+returnResult); |
||||
httpclient.close(); |
||||
|
||||
if (status == HttpStatus.SC_OK) { |
||||
return returnResult; |
||||
} |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:exception:"+e.getMessage()); |
||||
} |
||||
|
||||
try { |
||||
httpclient.close(); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:http关闭异常:"+e.getMessage()); |
||||
} |
||||
|
||||
return ""; |
||||
} |
||||
|
||||
public static String HttpPostXML(String url, String xmlParam){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostXML:url:"+url); |
||||
|
||||
HttpPost postMethod = new HttpPost(url); |
||||
|
||||
postMethod.setHeader("Content-type", "text/html"); |
||||
HttpEntity entity2 = null; |
||||
try { |
||||
entity2 = new StringEntity(xmlParam); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostXML:参数异常:"+e.getMessage()); |
||||
return ""; |
||||
} |
||||
|
||||
postMethod.setEntity(entity2); |
||||
|
||||
return HttpPost(postMethod); |
||||
} |
||||
|
||||
public static String HttpPostText(String url, String xmlParam){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostText:url:"+url); |
||||
|
||||
HttpPost postMethod = new HttpPost(url); |
||||
|
||||
postMethod.setHeader("Content-type", "text/plain"); |
||||
HttpEntity entity2 = null; |
||||
try { |
||||
entity2 = new StringEntity(xmlParam); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostText:参数异常:"+e.getMessage()); |
||||
return ""; |
||||
} |
||||
|
||||
postMethod.setEntity(entity2); |
||||
|
||||
return HttpPost(postMethod); |
||||
} |
||||
|
||||
public static String HttpPostJson(String url, String param,Map<String,String> header){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostJSON:url:"+url); |
||||
|
||||
HttpPost postMethod = new HttpPost(url); |
||||
|
||||
postMethod.setHeader("Content-Type","application/json"); |
||||
|
||||
if(header != null && header.size() > 0){ |
||||
Set<String> keySet = header.keySet(); |
||||
|
||||
for(String key : keySet){ |
||||
postMethod.setHeader(key,header.get(key)); |
||||
} |
||||
} |
||||
|
||||
if(!Utils.isNullStr(param)){ |
||||
HttpEntity entity2 = null; |
||||
try { |
||||
entity2 = new StringEntity(param); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostJSON:参数异常:"+e.getMessage()); |
||||
return ""; |
||||
} |
||||
|
||||
postMethod.setEntity(entity2); |
||||
} |
||||
|
||||
return HttpPost(postMethod); |
||||
} |
||||
|
||||
public static String HttpPostWWWForm(String url, Map<String,String> header,Map<String,String> param){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpWWWForm:url:"+url); |
||||
|
||||
HttpPost postMethod = new HttpPost(url); |
||||
|
||||
if(header != null && header.size() > 0){ |
||||
Set<String> keySet = header.keySet(); |
||||
|
||||
for(String key : keySet){ |
||||
postMethod.setHeader(key,header.get(key)); |
||||
} |
||||
} |
||||
|
||||
if(param != null && param.size() > 0){ |
||||
List<NameValuePair> params = new ArrayList<NameValuePair>(param.size()); |
||||
|
||||
for(Map.Entry<String,String> map : param.entrySet()){ |
||||
params.add(new BasicNameValuePair(map.getKey(), map.getValue())); |
||||
} |
||||
|
||||
try { |
||||
postMethod.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpWWWForm:异常:"+e.getMessage()); |
||||
return ""; |
||||
} |
||||
} |
||||
|
||||
return HttpPost(postMethod); |
||||
} |
||||
|
||||
private static CloseableHttpClient createHttpClient(Cookie[] cookies){ |
||||
|
||||
SSLContext sslContext = null; |
||||
try { |
||||
sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() { |
||||
@Override |
||||
public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { |
||||
return true; |
||||
} |
||||
}).build(); |
||||
} catch (Exception e) { |
||||
FRUtils.FRLogInfo("exception:"+e.getMessage()); |
||||
} |
||||
|
||||
CloseableHttpClient httpclient = null; |
||||
|
||||
if(cookies != null && cookies.length > 0){ |
||||
CookieStore cookieStore = cookieToCookieStore(cookies); |
||||
|
||||
httpclient = HttpClients.custom().setSslcontext(sslContext). |
||||
setSSLHostnameVerifier(new NoopHostnameVerifier()).setDefaultCookieStore(cookieStore).build(); |
||||
} |
||||
else{ |
||||
httpclient = HttpClients.custom().setSslcontext(sslContext). |
||||
setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); |
||||
} |
||||
|
||||
return httpclient; |
||||
} |
||||
|
||||
/** |
||||
* cookies转cookieStore |
||||
* @param cookies |
||||
* @return |
||||
*/ |
||||
public static CookieStore cookieToCookieStore(Cookie[] cookies){ |
||||
CookieStore cookieStore = new BasicCookieStore(); |
||||
|
||||
if(cookies != null && cookies.length>0){ |
||||
for(Cookie cookie : cookies){ |
||||
BasicClientCookie cookie1 = new BasicClientCookie(cookie.getName(), cookie.getValue()); |
||||
cookieStore.addCookie(cookie1); |
||||
} |
||||
} |
||||
|
||||
return cookieStore; |
||||
} |
||||
} |
@ -0,0 +1,120 @@
|
||||
package com.eco.plugin.xx.hqctb.utils; |
||||
|
||||
import org.apache.commons.dbcp2.BasicDataSourceFactory; |
||||
|
||||
import javax.sql.DataSource; |
||||
import java.sql.Connection; |
||||
import java.sql.ResultSet; |
||||
import java.sql.SQLException; |
||||
import java.sql.Statement; |
||||
import java.util.Properties; |
||||
|
||||
public class JDBCUtils { |
||||
private static Properties properties = new Properties(); |
||||
private static DataSource dataSource; |
||||
|
||||
static{ |
||||
Properties pt = PropertiesUtils.getProperties2("/resources/db.properties"); |
||||
FRUtils.FRLogInfo("url:"+pt.getProperty("url")); |
||||
properties.setProperty("driverClassName","com.mysql.jdbc.Driver"); |
||||
properties.setProperty("url",pt.getProperty("url")); |
||||
properties.setProperty("username",pt.getProperty("username")); |
||||
properties.setProperty("password",pt.getProperty("password")); |
||||
properties.setProperty("initialSize","30"); |
||||
properties.setProperty("maxTotal","30"); |
||||
properties.setProperty("maxIdle","10"); |
||||
properties.setProperty("minIdle","5"); |
||||
properties.setProperty("maxWailMillis","1000"); |
||||
properties.setProperty("removeAbandonedOnMaintenance","true"); |
||||
properties.setProperty("removeAbandonedOnBorrow","true"); |
||||
properties.setProperty("removeAbandonedTimeout","300"); |
||||
try { |
||||
dataSource = BasicDataSourceFactory.createDataSource(properties); |
||||
} catch (Exception e) { |
||||
FRUtils.FRLogError("创建链接池异常:"+e.getMessage()); |
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
public static Connection getConnect(){ |
||||
Connection connection = null; |
||||
|
||||
try{ |
||||
connection = dataSource.getConnection(); |
||||
}catch(Exception e){ |
||||
FRUtils.FRLogError("获取数据库连接异常:"+e.getMessage()); |
||||
} |
||||
|
||||
return connection; |
||||
} |
||||
|
||||
/** |
||||
* 更新 |
||||
* @param sql |
||||
* @return |
||||
*/ |
||||
public static int update(String sql){ |
||||
Connection conn=null; |
||||
Statement st=null; |
||||
int count = 0; |
||||
|
||||
try { |
||||
conn = getConnect(); |
||||
st = conn.createStatement(); |
||||
count = st.executeUpdate(sql); |
||||
|
||||
} catch (SQLException e) { |
||||
FRUtils.FRLogError("执行updata语句异常"); |
||||
} finally { |
||||
release(conn, st, null); |
||||
} |
||||
|
||||
return count; |
||||
} |
||||
|
||||
private static void release(Connection conn, Statement st, ResultSet rs) { |
||||
closeRs(rs); |
||||
closeSt(st); |
||||
closeConn(conn); |
||||
} |
||||
|
||||
private static void closeRs(ResultSet rs) { |
||||
try { |
||||
if(rs!=null) { |
||||
rs.close(); |
||||
} |
||||
} catch (SQLException e) { |
||||
FRUtils.FRLogError("关闭rs异常"); |
||||
} finally { |
||||
rs=null; |
||||
} |
||||
|
||||
} |
||||
|
||||
private static void closeSt(Statement st) { |
||||
try { |
||||
if(st!=null) { |
||||
st.close(); |
||||
} |
||||
} catch (SQLException e) { |
||||
FRUtils.FRLogError("关闭st异常"); |
||||
} finally { |
||||
st=null; |
||||
} |
||||
|
||||
} |
||||
|
||||
private static void closeConn(Connection conn) { |
||||
try { |
||||
if(conn!=null) { |
||||
conn.close(); |
||||
} |
||||
} catch (SQLException e) { |
||||
FRUtils.FRLogError("关闭connect异常"); |
||||
} finally { |
||||
conn=null; |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,31 @@
|
||||
package com.eco.plugin.xx.hqctb.utils; |
||||
|
||||
import com.fr.io.utils.ResourceIOUtils; |
||||
|
||||
import java.io.BufferedReader; |
||||
import java.io.InputStream; |
||||
import java.io.InputStreamReader; |
||||
import java.util.Properties; |
||||
|
||||
public class PropertiesUtils { |
||||
|
||||
|
||||
/** |
||||
* 获取web-info下的配置文件 |
||||
* @param path |
||||
* @return |
||||
*/ |
||||
public static Properties getProperties2(String path){ |
||||
Properties p = new Properties(); |
||||
// "/resources/wz.properties"
|
||||
try{ |
||||
InputStream is = ResourceIOUtils.read(path); |
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is)); |
||||
p.load(bufferedReader); |
||||
}catch(Exception e){ |
||||
FRUtils.FRLogInfo("获取配置文件异常"); |
||||
} |
||||
|
||||
return p; |
||||
} |
||||
} |
@ -0,0 +1,108 @@
|
||||
package com.eco.plugin.xx.hqctb.utils; |
||||
|
||||
import com.fr.json.JSONObject; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.PrintWriter; |
||||
|
||||
public class ResponseUtils { |
||||
private static final int SUCCESS = 200; |
||||
private static final int FAILED = -1; |
||||
|
||||
public static void successResponse(HttpServletResponse res, String body) { |
||||
response(res, body, SUCCESS); |
||||
} |
||||
|
||||
public static void failedResponse(HttpServletResponse res, String body) { |
||||
response(res, body, FAILED); |
||||
} |
||||
|
||||
private static void response(HttpServletResponse res, String body, int code) { |
||||
JSONObject object = new JSONObject(); |
||||
PrintWriter pw; |
||||
try { |
||||
object.put("code", code); |
||||
object.put("data", body); |
||||
pw = WebUtils.createPrintWriter(res); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||
return; |
||||
} |
||||
res.setContentType("application/json;charset=utf-8"); |
||||
String result = object.toString(); |
||||
pw.println(result); |
||||
pw.flush(); |
||||
pw.close(); |
||||
} |
||||
|
||||
public static void response(HttpServletResponse res,JSONObject json){ |
||||
PrintWriter pw; |
||||
try { |
||||
pw = WebUtils.createPrintWriter(res); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||
return; |
||||
} |
||||
res.setContentType("application/json;charset=utf-8"); |
||||
String result = json.toString(); |
||||
pw.println(result); |
||||
pw.flush(); |
||||
pw.close(); |
||||
} |
||||
|
||||
public static void responseText(HttpServletResponse res,String text){ |
||||
PrintWriter pw; |
||||
try { |
||||
pw = WebUtils.createPrintWriter(res); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||
return; |
||||
} |
||||
res.setContentType("text/html;charset=utf-8"); |
||||
pw.println(text); |
||||
pw.flush(); |
||||
pw.close(); |
||||
} |
||||
|
||||
public static void responseXml(HttpServletResponse res,String xml){ |
||||
PrintWriter pw; |
||||
try { |
||||
pw = WebUtils.createPrintWriter(res); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||
return; |
||||
} |
||||
res.setContentType("text/xml;charset=utf-8"); |
||||
pw.println(xml); |
||||
pw.flush(); |
||||
pw.close(); |
||||
} |
||||
|
||||
public static void setCSRFHeader(HttpServletResponse httpServletResponse){ |
||||
httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); |
||||
httpServletResponse.setHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS,DELETE,HEAD,PUT,PATCH"); |
||||
httpServletResponse.setHeader("Access-Control-Max-Age", "36000"); |
||||
httpServletResponse.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept,Authorization,authorization"); |
||||
} |
||||
|
||||
public static void responseJsonp(HttpServletRequest req, HttpServletResponse res, JSONObject json){ |
||||
PrintWriter pw; |
||||
try { |
||||
pw = WebUtils.createPrintWriter(res); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||
return; |
||||
} |
||||
res.setContentType("text/javascript;charset=utf-8;charset=utf-8"); |
||||
String result = json.toString(); |
||||
|
||||
String jsonp=req.getParameter("callback"); |
||||
|
||||
pw.println(jsonp+"("+result+")"); |
||||
pw.flush(); |
||||
pw.close(); |
||||
} |
||||
} |
@ -0,0 +1,244 @@
|
||||
package com.eco.plugin.xx.hqctb.utils; |
||||
|
||||
import com.fr.base.TemplateUtils; |
||||
import com.fr.data.NetworkHelper; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
import com.fr.io.utils.ResourceIOUtils; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.stable.CodeUtils; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.third.org.apache.commons.codec.digest.DigestUtils; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.Cookie; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.BufferedReader; |
||||
import java.io.InputStream; |
||||
import java.net.URLEncoder; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.UUID; |
||||
import java.util.regex.Matcher; |
||||
import java.util.regex.Pattern; |
||||
|
||||
public class Utils { |
||||
|
||||
/** |
||||
* 判断字符串是否为空 |
||||
* @param str |
||||
* @return true 空字符串 false 非空字符串 |
||||
*/ |
||||
public static boolean isNullStr(String str){ |
||||
return !(str != null && !str.isEmpty() && !"null".equals(str)); |
||||
} |
||||
|
||||
/** |
||||
* 判断字符串是否非空 |
||||
* @param str |
||||
* @return |
||||
*/ |
||||
public static boolean isNotNullStr(String str){ |
||||
return !isNullStr(str); |
||||
} |
||||
|
||||
/** |
||||
* MD5加密 |
||||
* @param str |
||||
* @return |
||||
*/ |
||||
public static String getMd5Str(String str) |
||||
{ |
||||
return DigestUtils.md5Hex(str); |
||||
} |
||||
|
||||
/** |
||||
* 帆软shaEncode加密 |
||||
*/ |
||||
|
||||
public static String shaEncode(String str){ |
||||
return CodeUtils.sha256Encode(str); |
||||
} |
||||
|
||||
/** |
||||
* 获取uuid |
||||
*/ |
||||
public static String uuid(){ |
||||
return UUID.randomUUID().toString(); |
||||
} |
||||
|
||||
/** |
||||
* 替换空字符串 |
||||
* @param str |
||||
* @param replace |
||||
* @return |
||||
*/ |
||||
public static String replaceNullStr(String str,String replace){ |
||||
if(isNullStr(str)){ |
||||
return replace; |
||||
} |
||||
|
||||
return str; |
||||
} |
||||
|
||||
/** |
||||
* 获取请求体 |
||||
* @param req |
||||
* @return |
||||
*/ |
||||
public static JSONObject getRequestBody(HttpServletRequest req){ |
||||
StringBuffer sb = new StringBuffer(); |
||||
String line = null; |
||||
try { |
||||
BufferedReader reader = req.getReader(); |
||||
while ((line = reader.readLine()) != null) |
||||
sb.append(line); |
||||
} catch (Exception e) { |
||||
FRUtils.FRLogInfo("getRequestBody:exception:"+e.getMessage()); |
||||
} |
||||
//将空格和换行符替换掉避免使用反序列化工具解析对象时失败
|
||||
String jsonString = sb.toString().replaceAll("\\s","").replaceAll("\n",""); |
||||
|
||||
JSONObject json = new JSONObject(jsonString); |
||||
|
||||
return json; |
||||
} |
||||
|
||||
/** |
||||
* 获取ip |
||||
* @return |
||||
*/ |
||||
public static String getIp(HttpServletRequest req){ |
||||
String realIp = req.getHeader("X-Real-IP"); |
||||
String fw = req.getHeader("X-Forwarded-For"); |
||||
if (StringUtils.isNotEmpty(fw) && !"unKnown".equalsIgnoreCase(fw)) { |
||||
int var3 = fw.indexOf(","); |
||||
return var3 != -1 ? fw.substring(0, var3) : fw; |
||||
} else { |
||||
fw = realIp; |
||||
if (StringUtils.isNotEmpty(realIp) && !"unKnown".equalsIgnoreCase(realIp)) { |
||||
return realIp; |
||||
} else { |
||||
if (StringUtils.isBlank(realIp) || "unknown".equalsIgnoreCase(realIp)) { |
||||
fw = req.getHeader("Proxy-Client-IP"); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||
fw = req.getHeader("WL-Proxy-Client-IP"); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||
fw = req.getHeader("HTTP_CLIENT_IP"); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||
fw = req.getHeader("HTTP_X_FORWARDED_FOR"); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||
fw = req.getRemoteAddr(); |
||||
} |
||||
|
||||
return fw; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 根据key获取cookie |
||||
* @param req |
||||
* @return |
||||
*/ |
||||
public static String getCookieByKey(HttpServletRequest req,String key){ |
||||
Cookie[] cookies = req.getCookies(); |
||||
String cookie = ""; |
||||
|
||||
if(cookies == null || cookies.length <=0){ |
||||
return ""; |
||||
} |
||||
|
||||
for(int i = 0; i < cookies.length; i++) { |
||||
Cookie item = cookies[i]; |
||||
if (item.getName().equalsIgnoreCase(key)) { |
||||
cookie = item.getValue(); |
||||
} |
||||
} |
||||
|
||||
FRUtils.FRLogInfo("cookie:"+cookie); |
||||
|
||||
return cookie; |
||||
} |
||||
|
||||
/** |
||||
* 判断是否是手机端的链接 |
||||
* @param req |
||||
* @return |
||||
*/ |
||||
public static boolean isMobile(HttpServletRequest req) { |
||||
String[] mobileArray = {"iPhone", "iPad", "android", "windows phone", "xiaomi"}; |
||||
String userAgent = req.getHeader("user-agent"); |
||||
if (userAgent != null && userAgent.toUpperCase().contains("MOBILE")) { |
||||
for(String mobile : mobileArray) { |
||||
if(userAgent.toUpperCase().contains(mobile.toUpperCase())) { |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
return NetworkHelper.getDevice(req).isMobile(); |
||||
} |
||||
|
||||
/** |
||||
* 只编码中文 |
||||
* @param url |
||||
* @return |
||||
*/ |
||||
public static String encodeCH(String url ){ |
||||
Matcher matcher = Pattern.compile("[\\u4e00-\\u9fa5]").matcher(url); |
||||
|
||||
while(matcher.find()){ |
||||
String chn = matcher.group(); |
||||
url = url.replaceAll(chn, URLEncoder.encode(chn)); |
||||
} |
||||
|
||||
return url; |
||||
} |
||||
|
||||
/** |
||||
* 获取web-inf文件夹下的文件 |
||||
* filename /resources/ip4enc.properties |
||||
*/ |
||||
public static InputStream getResourcesFile(String filename){ |
||||
return ResourceIOUtils.read(filename); |
||||
} |
||||
|
||||
public static void toErrorPage(HttpServletResponse res,String path,Map<String, String> parameterMap){ |
||||
if(parameterMap == null){ |
||||
parameterMap = new HashMap<String, String>(); |
||||
} |
||||
|
||||
try { |
||||
String macPage = TemplateUtils.renderTemplate(path, parameterMap); |
||||
WebUtils.printAsString(res, macPage); |
||||
}catch (Exception e){ |
||||
FRUtils.FRLogError("跳转页面异常"); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 判断是否是管理员 |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
public static boolean isAdmin(String username) throws Exception{ |
||||
return UserService.getInstance().isAdmin(UserService.getInstance().getUserByUserName(username).getId()); |
||||
} |
||||
|
||||
public static String removeParam(String url,String param){ |
||||
if(!url.contains("?"+param) && !url.contains("&"+param)){ |
||||
return url; |
||||
} |
||||
|
||||
return url.substring(0,url.indexOf(url.contains("?"+param) ? "?"+param : "&"+param)); |
||||
} |
||||
} |
Loading…
Reference in new issue