Browse Source

open

master
pioneer 2 years ago
commit
720ec529cc
  1. 6
      README.md
  2. BIN
      lib/fine-plugin-com.tptj.plugin.hg.client.center.v10-1.3.8.jar
  3. 25
      plugin.xml
  4. 21
      src/main/java/com/eco/plugin/xx/jlyhsjtb/config/InitializeMonitor.java
  5. 107
      src/main/java/com/eco/plugin/xx/jlyhsjtb/config/PluginSimpleConfig.java
  6. 14
      src/main/java/com/eco/plugin/xx/jlyhsjtb/controller/ControllerRegisterProvider.java
  7. 152
      src/main/java/com/eco/plugin/xx/jlyhsjtb/controller/ControllerSelf.java
  8. 435
      src/main/java/com/eco/plugin/xx/jlyhsjtb/db/bean/OrgEntity.java
  9. 358
      src/main/java/com/eco/plugin/xx/jlyhsjtb/db/bean/UserEntity.java
  10. 152
      src/main/java/com/eco/plugin/xx/jlyhsjtb/db/controller/DBController.java
  11. 69
      src/main/java/com/eco/plugin/xx/jlyhsjtb/db/dao/OrgDao.java
  12. 76
      src/main/java/com/eco/plugin/xx/jlyhsjtb/db/dao/UserDao.java
  13. 62
      src/main/java/com/eco/plugin/xx/jlyhsjtb/function/AuthFunction.java
  14. 70
      src/main/java/com/eco/plugin/xx/jlyhsjtb/openapi/caller/GetOrgCaller.java
  15. 81
      src/main/java/com/eco/plugin/xx/jlyhsjtb/openapi/caller/GetUserCaller.java
  16. 71
      src/main/java/com/eco/plugin/xx/jlyhsjtb/openapi/caller/SyncIAMOrgCaller.java
  17. 65
      src/main/java/com/eco/plugin/xx/jlyhsjtb/openapi/caller/SyncIAMUserCaller.java
  18. 28
      src/main/java/com/eco/plugin/xx/jlyhsjtb/openapi/loader/GetOrgLoader.java
  19. 28
      src/main/java/com/eco/plugin/xx/jlyhsjtb/openapi/loader/GetUserLoader.java
  20. 28
      src/main/java/com/eco/plugin/xx/jlyhsjtb/openapi/loader/SyncIAMOrgLoader.java
  21. 28
      src/main/java/com/eco/plugin/xx/jlyhsjtb/openapi/loader/SyncIAMUserLoader.java
  22. 33
      src/main/java/com/eco/plugin/xx/jlyhsjtb/openapi/rgt/ARGT.java
  23. 235
      src/main/java/com/eco/plugin/xx/jlyhsjtb/utils/DateUtilSelf.java
  24. 170
      src/main/java/com/eco/plugin/xx/jlyhsjtb/utils/FRUserUtils.java
  25. 285
      src/main/java/com/eco/plugin/xx/jlyhsjtb/utils/FRUtils.java
  26. 93
      src/main/java/com/eco/plugin/xx/jlyhsjtb/utils/FtpUtils.java
  27. 265
      src/main/java/com/eco/plugin/xx/jlyhsjtb/utils/HttpUtils.java
  28. 100
      src/main/java/com/eco/plugin/xx/jlyhsjtb/utils/IOUtils.java
  29. 125
      src/main/java/com/eco/plugin/xx/jlyhsjtb/utils/PubUtils.java
  30. 108
      src/main/java/com/eco/plugin/xx/jlyhsjtb/utils/ResponseUtils.java
  31. 244
      src/main/java/com/eco/plugin/xx/jlyhsjtb/utils/Utils.java

6
README.md

@ -0,0 +1,6 @@
# open-JSD-9902
JSD-9902 oauth2单点认证\
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\
仅作为开发者学习参考使用!禁止用于任何商业用途!\
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系【pioneer】处理。

BIN
lib/fine-plugin-com.tptj.plugin.hg.client.center.v10-1.3.8.jar

Binary file not shown.

25
plugin.xml

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin>
<id>com.eco.plugin..jlyhsjtb</id>
<name><![CDATA[数据同步]]></name>
<active>yes</active>
<version>1.0.6</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..jlyhsjtb</main-package>
<lifecycle-monitor class="com.eco.plugin..jlyhsjtb.config.InitializeMonitor"/>
<extra-decision>
<ControllerRegisterProvider class="com.eco.plugin..jlyhsjtb.controller.ControllerRegisterProvider"/>
</extra-decision>
<extra-core>
<!-- <OpenClientAPIProvider class="com.eco.plugin..jlyhsjtb.openapi.rgt.ARGT"/>-->
<FunctionDefineProvider class="com.eco.plugin..jlyhsjtb.function.AuthFunction" name="checkData" description="检查数据"/>
<DBAccessProvider class="com.eco.plugin..jlyhsjtb.db.controller.DBController"/>
</extra-core>
<function-recorder class="com.eco.plugin..jlyhsjtb.config.PluginSimpleConfig"/>
</plugin>

21
src/main/java/com/eco/plugin/xx/jlyhsjtb/config/InitializeMonitor.java

@ -0,0 +1,21 @@
package com.eco.plugin.xx.jlyhsjtb.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) {
}
}

107
src/main/java/com/eco/plugin/xx/jlyhsjtb/config/PluginSimpleConfig.java

@ -0,0 +1,107 @@
package com.eco.plugin.xx.jlyhsjtb.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.jlyhsjtb.config", text = "数据同步配置", source = Original.PLUGIN)
public static PluginSimpleConfig getInstance() {
if (config == null) {
config = ConfigContext.getConfigInstance(PluginSimpleConfig.class);
}
return config;
}
@Identifier(value = "userurl", name = "用户补偿接口", description = "用户补偿接口", status = Status.SHOW)
private Conf<String> userurl = Holders.simple("");
@Identifier(value = "orgurl", name = "机构补偿接口", description = "机构补偿接口", status = Status.SHOW)
private Conf<String> orgurl = Holders.simple("");
@Identifier(value = "ftphost", name = "ftphost", description = "ftphost", status = Status.SHOW)
private Conf<String> ftphost = Holders.simple("");
@Identifier(value = "ftpport", name = "ftp端口", description = "ftp端口", status = Status.SHOW)
private Conf<Integer> ftpport = Holders.simple(0);
@Identifier(value = "ftpuser", name = "ftp用户名", description = "ftp用户名", status = Status.SHOW)
private Conf<String> ftpuser = Holders.simple("");
@Identifier(value = "ftppsd", name = "ftp密码", description = "ftp密码", status = Status.SHOW)
private Conf<String> ftppsd = Holders.simple("");
@Identifier(value = "ftpurl", name = "ftp文件路径", description = "ftp文件路径", status = Status.SHOW)
private Conf<String> ftpurl = Holders.simple("");
public String getUserurl() {
return userurl.get();
}
public void setUserurl(String url) {
this.userurl.set(url);
}
public String getOrgurl() {
return orgurl.get();
}
public void setOrgurl(String url) {
this.orgurl.set(url);
}
public String getFtphost() {
return ftphost.get();
}
public void setFtphost(String url) {
this.ftphost.set(url);
}
public Integer getFtpport() {
return ftpport.get();
}
public void setFtpport(Integer url) {
this.ftpport.set(url);
}
public String getFtpuser() {
return ftpuser.get();
}
public void setFtpuser(String url) {
this.ftpuser.set(url);
}
public String getFtppsd() {
return ftppsd.get();
}
public void setFtppsd(String url) {
this.ftppsd.set(url);
}
public String getFtpurl() {
return ftpurl.get();
}
public void setFtpurl(String url) {
this.ftpurl.set(url);
}
@Override
public Object clone() throws CloneNotSupportedException {
PluginSimpleConfig cloned = (PluginSimpleConfig) super.clone();
return cloned;
}
}

14
src/main/java/com/eco/plugin/xx/jlyhsjtb/controller/ControllerRegisterProvider.java

@ -0,0 +1,14 @@
package com.eco.plugin.xx.jlyhsjtb.controller;
import com.fr.decision.fun.impl.AbstractControllerRegisterProvider;
import com.fr.plugin.transform.FunctionRecorder;
@FunctionRecorder
public class ControllerRegisterProvider extends AbstractControllerRegisterProvider {
@Override
public Class<?>[] getControllers() {
return new Class[]{
ControllerSelf.class
};
}
}

152
src/main/java/com/eco/plugin/xx/jlyhsjtb/controller/ControllerSelf.java

@ -0,0 +1,152 @@
package com.eco.plugin.xx.jlyhsjtb.controller;
import com.eco.plugin.xx.jlyhsjtb.config.PluginSimpleConfig;
import com.eco.plugin.xx.jlyhsjtb.db.bean.OrgEntity;
import com.eco.plugin.xx.jlyhsjtb.db.bean.UserEntity;
import com.eco.plugin.xx.jlyhsjtb.db.controller.DBController;
import com.eco.plugin.xx.jlyhsjtb.utils.*;
import com.fr.decision.webservice.annotation.LoginStatusChecker;
import com.fr.json.JSONArray;
import com.fr.json.JSONObject;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.third.springframework.stereotype.Controller;
import com.fr.third.springframework.web.bind.annotation.PostMapping;
import com.fr.third.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
@Controller
@LoginStatusChecker(required = false)
@FunctionRecorder
public class ControllerSelf {
@PostMapping(value = "/sp/client/api/syncIAMUser")
@ResponseBody
public void syncIAMUser(HttpServletRequest request,HttpServletResponse response){
JSONObject userJson = Utils.getRequestBody(request);
FRUtils.FRLogInfo("userJson : "+userJson.toString());
JSONObject body = userJson.getJSONObject("body");
operateUser(body);
ResponseUtils.successResponse(response,"SUCCESS");
}
public static void operateUser(JSONObject userJson){
//增删改的标志
UserEntity userEntity = PubUtils.jsonObjToUserEntity(userJson);
String flag = userEntity.getType();
List<UserEntity> userList = new ArrayList<UserEntity>();
userList.add(userEntity);
if("delete".equals(flag)){
FRUtils.FRLogInfo("deleteUser:"+userEntity.getEmplyNo() + ";time:"+ DateUtilSelf.getNow());
DBController.batchUser(null,userList);
try {
// FRUserUtils.deleteByUsername(userEntity.getEmplyNo());
} catch (Exception e) {
FRUtils.FRLogError("删除用户失败:"+userEntity.getUsrId()+e.getMessage());
}
return ;
}
try {
PubUtils.addOrUpdateUser(userList,userEntity);
} catch (Exception e) {
FRUtils.FRLogError("新增删除用户失败:"+userEntity.getUsrId()+e.getMessage());
}
}
@PostMapping(value = "/sp/client/api/syncIAMOrg")
@ResponseBody
public void syncIAMOrg(HttpServletRequest request,HttpServletResponse response){
JSONObject userJson = Utils.getRequestBody(request);
FRUtils.FRLogInfo("orgJson : "+userJson.toString());
JSONObject body = userJson.getJSONObject("body");
//增删改的标志
OrgEntity orgEntity = PubUtils.jsonObjToOrgEntity(body);
String flag = orgEntity.getType();
List<OrgEntity> orgList = new ArrayList<OrgEntity>();
orgList.add(orgEntity);
if("delete".equals(flag)){
FRUtils.FRLogInfo("deleteorg:"+orgEntity.getBrCd()+ ";time:"+ DateUtilSelf.getNow());
DBController.batchOrg(null,orgList);
ResponseUtils.successResponse(response,"SUCCESS");
}
FRUtils.FRLogInfo("addOrUpdateOrg:"+orgEntity.getBrCd()+ ";time:"+ DateUtilSelf.getNow());
DBController.batchOrg(orgList,null);
ResponseUtils.successResponse(response,"SUCCESS");
}
public static void operateOrg(JSONObject orgJson){
//增删改的标志
OrgEntity orgEntity = PubUtils.jsonObjToOrgEntity(orgJson);
List<OrgEntity> orgList = new ArrayList<OrgEntity>();
orgList.add(orgEntity);
String flag = orgEntity.getType();
if("delete".equals(flag)){
FRUtils.FRLogInfo("deleteorg:"+orgEntity.getBrCd()+ ";time:"+ DateUtilSelf.getNow());
DBController.batchOrg(null,orgList);
return ;
}
FRUtils.FRLogInfo("addOrUpdateOrg:"+orgEntity.getBrCd()+ ";time:"+ DateUtilSelf.getNow());
DBController.batchOrg(orgList,null);
}
@PostMapping(value = "/getUserListPage")
@ResponseBody
public void getUserListPage(HttpServletRequest request,HttpServletResponse response){
JSONObject param = Utils.getRequestBody(request);
String url = PluginSimpleConfig.getInstance().getUserurl();
String result = HttpUtils.HttpPostJson(url,param.toString(),null);
if(Utils.isNullStr(result)){
FRUtils.FRLogError("获取用户补偿数据异常");
return ;
}
JSONObject userJson = new JSONObject(result);
JSONObject body = userJson.getJSONObject("body");
JSONArray usrInfArray = body.getJSONArray("usrInfArray");
for(int i =0;i<usrInfArray.length();i++){
operateUser(usrInfArray.getJSONObject(i));
}
}
@PostMapping(value = "/getOrgListPage")
@ResponseBody
public void getOrgListPage(HttpServletRequest request,HttpServletResponse response){
JSONObject param = Utils.getRequestBody(request);
String url = PluginSimpleConfig.getInstance().getOrgurl();
String result = HttpUtils.HttpPostJson(url,param.toString(),null);
if(Utils.isNullStr(result)){
FRUtils.FRLogError("获取机构补偿数据异常");
return ;
}
JSONObject orgJson = new JSONObject(result);
JSONObject body = orgJson.getJSONObject("body");
JSONArray orgInfArray = body.getJSONArray("usrInfArray");
for(int i =0;i<orgInfArray.length();i++){
operateOrg(orgInfArray.getJSONObject(i));
}
}
}

435
src/main/java/com/eco/plugin/xx/jlyhsjtb/db/bean/OrgEntity.java

@ -0,0 +1,435 @@
package com.eco.plugin.xx.jlyhsjtb.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 = "plugin_xx_entity_org")
@TableAssociation(associated = true)
public class OrgEntity extends BaseEntity {
@Column(name = "brId")
private String brId = null;
@Column(name = "brNm")
private String brNm = null;
@Column(name = "brCd")
private String brCd = null;
@Column(name = "sprBrId")
private String sprBrId = null;
@Column(name = "brTreeId")
private String brTreeId = null;
@Column(name = "brCtgry")
private String brCtgry = null;
@Column(name = "brTp")
private String brTp = null;
@Column(name = "brAcbPrsnNm")
private String brAcbPrsnNm = null;
@Column(name = "satrapLdr")
private String satrapLdr = null;
@Column(name = "brChrctrstc")
private String brChrctrstc = null;
@Column(name = "brSt")
private String brSt = null;
@Column(name = "loDstc")
private String loDstc = null;
@Column(name = "pstlId")
private String pstlId = null;
@Column(name = "telNo")
private String telNo = null;
@Column(name = "rgstrtnAdr")
private String rgstrtnAdr = null;
@Column(name = "ofcAdr")
private String ofcAdr = null;
@Column(name = "cmpilPplCnt")
private String cmpilPplCnt = null;
@Column(name = "actPplCnt")
private String actPplCnt = null;
@Column(name = "ovCmpilPplCnt")
private String ovCmpilPplCnt = null;
@Column(name = "ovGapPplCnt")
private String ovGapPplCnt = null;
@Column(name = "aprvdPrefNo")
private String aprvdPrefNo = null;
@Column(name = "brRspbl")
private String brRspbl = null;
@Column(name = "brBlngBarLine")
private String brBlngBarLine = null;
@Column(name = "aprvdFoundTm")
private String aprvdFoundTm = null;
@Column(name = "loCity")
private String loCity = null;
@Column(name = "fnPrmt")
private String fnPrmt = null;
@Column(name = "crtDt")
private String crtDt = null;
@Column(name = "bsnLicNo")
private String bsnLicNo = null;
@Column(name = "lgtLtt")
private String lgtLtt = null;
@Column(name = "fICd")
private String fICd = null;
@Column(name = "lglPrsn")
private String lglPrsn = null;
@Column(name = "loProv")
private String loProv = null;
@Column(name = "brLyrdLvl")
private String brLyrdLvl = null;
@Column(name = "brAcbPrsnCtcTel")
private String brAcbPrsnCtcTel = null;
@Column(name = "brShrtNm")
private String brShrtNm = null;
@Column(name = "zoneInOutFlg")
private String zoneInOutFlg = null;
@Column(name = "admnstvDstc")
private String admnstvDstc = null;
public String getAprvdFoundTm() {
return aprvdFoundTm;
}
public void setAprvdFoundTm(String aprvdFoundTm) {
this.aprvdFoundTm = aprvdFoundTm;
}
public String getLoCity() {
return loCity;
}
public void setLoCity(String loCity) {
this.loCity = loCity;
}
public String getFnPrmt() {
return fnPrmt;
}
public void setFnPrmt(String fnPrmt) {
this.fnPrmt = fnPrmt;
}
public String getCrtDt() {
return crtDt;
}
public void setCrtDt(String crtDt) {
this.crtDt = crtDt;
}
public String getBsnLicNo() {
return bsnLicNo;
}
public void setBsnLicNo(String bsnLicNo) {
this.bsnLicNo = bsnLicNo;
}
public String getLgtLtt() {
return lgtLtt;
}
public void setLgtLtt(String lgtLtt) {
this.lgtLtt = lgtLtt;
}
public String getfICd() {
return fICd;
}
public void setfICd(String fICd) {
this.fICd = fICd;
}
public String getLglPrsn() {
return lglPrsn;
}
public void setLglPrsn(String lglPrsn) {
this.lglPrsn = lglPrsn;
}
public String getLoProv() {
return loProv;
}
public void setLoProv(String loProv) {
this.loProv = loProv;
}
public String getBrLyrdLvl() {
return brLyrdLvl;
}
public void setBrLyrdLvl(String brLyrdLvl) {
this.brLyrdLvl = brLyrdLvl;
}
public String getBrAcbPrsnCtcTel() {
return brAcbPrsnCtcTel;
}
public void setBrAcbPrsnCtcTel(String brAcbPrsnCtcTel) {
this.brAcbPrsnCtcTel = brAcbPrsnCtcTel;
}
public String getBrShrtNm() {
return brShrtNm;
}
public void setBrShrtNm(String brShrtNm) {
this.brShrtNm = brShrtNm;
}
public String getZoneInOutFlg() {
return zoneInOutFlg;
}
public void setZoneInOutFlg(String zoneInOutFlg) {
this.zoneInOutFlg = zoneInOutFlg;
}
public String getAdmnstvDstc() {
return admnstvDstc;
}
public void setAdmnstvDstc(String admnstvDstc) {
this.admnstvDstc = admnstvDstc;
}
private String type = null;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getBrId() {
return brId;
}
public void setBrId(String brId) {
this.brId = brId;
}
public String getBrNm() {
return brNm;
}
public void setBrNm(String brNm) {
this.brNm = brNm;
}
public String getBrCd() {
return brCd;
}
public void setBrCd(String brCd) {
this.brCd = brCd;
}
public String getSprBrId() {
return sprBrId;
}
public void setSprBrId(String sprBrId) {
this.sprBrId = sprBrId;
}
public String getBrTreeId() {
return brTreeId;
}
public void setBrTreeId(String brTreeId) {
this.brTreeId = brTreeId;
}
public String getBrCtgry() {
return brCtgry;
}
public void setBrCtgry(String brCtgry) {
this.brCtgry = brCtgry;
}
public String getBrTp() {
return brTp;
}
public void setBrTp(String brTp) {
this.brTp = brTp;
}
public String getBrAcbPrsnNm() {
return brAcbPrsnNm;
}
public void setBrAcbPrsnNm(String brAcbPrsnNm) {
this.brAcbPrsnNm = brAcbPrsnNm;
}
public String getSatrapLdr() {
return satrapLdr;
}
public void setSatrapLdr(String satrapLdr) {
this.satrapLdr = satrapLdr;
}
public String getBrChrctrstc() {
return brChrctrstc;
}
public void setBrChrctrstc(String brChrctrstc) {
this.brChrctrstc = brChrctrstc;
}
public String getBrSt() {
return brSt;
}
public void setBrSt(String brSt) {
this.brSt = brSt;
}
public String getLoDstc() {
return loDstc;
}
public void setLoDstc(String loDstc) {
this.loDstc = loDstc;
}
public String getPstlId() {
return pstlId;
}
public void setPstlId(String pstlId) {
this.pstlId = pstlId;
}
public String getTelNo() {
return telNo;
}
public void setTelNo(String telNo) {
this.telNo = telNo;
}
public String getRgstrtnAdr() {
return rgstrtnAdr;
}
public void setRgstrtnAdr(String rgstrtnAdr) {
this.rgstrtnAdr = rgstrtnAdr;
}
public String getOfcAdr() {
return ofcAdr;
}
public void setOfcAdr(String ofcAdr) {
this.ofcAdr = ofcAdr;
}
public String getCmpilPplCnt() {
return cmpilPplCnt;
}
public void setCmpilPplCnt(String cmpilPplCnt) {
this.cmpilPplCnt = cmpilPplCnt;
}
public String getActPplCnt() {
return actPplCnt;
}
public void setActPplCnt(String actPplCnt) {
this.actPplCnt = actPplCnt;
}
public String getOvCmpilPplCnt() {
return ovCmpilPplCnt;
}
public void setOvCmpilPplCnt(String ovCmpilPplCnt) {
this.ovCmpilPplCnt = ovCmpilPplCnt;
}
public String getOvGapPplCnt() {
return ovGapPplCnt;
}
public void setOvGapPplCnt(String ovGapPplCnt) {
this.ovGapPplCnt = ovGapPplCnt;
}
public String getAprvdPrefNo() {
return aprvdPrefNo;
}
public void setAprvdPrefNo(String aprvdPrefNo) {
this.aprvdPrefNo = aprvdPrefNo;
}
public String getBrRspbl() {
return brRspbl;
}
public void setBrRspbl(String brRspbl) {
this.brRspbl = brRspbl;
}
public String getBrBlngBarLine() {
return brBlngBarLine;
}
public void setBrBlngBarLine(String brBlngBarLine) {
this.brBlngBarLine = brBlngBarLine;
}
}

358
src/main/java/com/eco/plugin/xx/jlyhsjtb/db/bean/UserEntity.java

@ -0,0 +1,358 @@
package com.eco.plugin.xx.jlyhsjtb.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 = "plugin_xx_entity_user")
@TableAssociation(associated = true)
public class UserEntity extends BaseEntity {
@Column(name = "usrId")
private String usrId = null;
@Column(name = "surnmNm")
private String surnmNm = null;
@Column(name = "emplyNo")
private String emplyNo = null;
@Column(name = "password")
private String password = null;
@Column(name = "crnSt")
private String crnSt = null;
@Column(name = "loCo")
private String loCo = null;
@Column(name = "loDept")
private String loDept = null;
@Column(name = "identTp")
private String identTp = null;
@Column(name = "identNo")
private String identNo = null;
private String type = null;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getIdentNo() {
return identNo;
}
public void setIdentNo(String identNo) {
this.identNo = identNo;
}
@Column(name = "gender")
private String gender = null;
@Column(name = "brthDt")
private String brthDt = null;
@Column(name = "nation")
private String nation = null;
@Column(name = "ntvPlc")
private String ntvPlc = null;
@Column(name = "domcChrctrstc")
private String domcChrctrstc = null;
@Column(name = "mrtlSt")
private String mrtlSt = null;
@Column(name = "pltclSt")
private String pltclSt = null;
@Column(name = "inParDt")
private String inParDt = null;
@Column(name = "hltStatus")
private String hltStatus = null;
@Column(name = "rsdnAdr")
private String rsdnAdr = null;
@Column(name = "pst")
private String pst = null;
@Column(name = "position")
private String position = null;
@Column(name = "pstPostnLvl")
private String pstPostnLvl = null;
@Column(name = "mblNo")
private String mblNo = null;
@Column(name = "mailBox")
private String mailBox = null;
@Column(name = "pstlCd")
private String pstlCd = null;
@Column(name = "edctHist")
private String edctHist = null;
@Column(name = "dplma")
private String dplma = null;
@Column(name = "ifHestEdctHist")
private String ifHestEdctHist = null;
@Column(name = "ctfInfArray")
private String ctfInfArray = null;
@Column(name = "famMbrInfArray")
private String famMbrInfArray = null;
public String getUsrId() {
return usrId;
}
public void setUsrId(String usrId) {
this.usrId = usrId;
}
public String getSurnmNm() {
return surnmNm;
}
public void setSurnmNm(String surnmNm) {
this.surnmNm = surnmNm;
}
public String getEmplyNo() {
return emplyNo;
}
public void setEmplyNo(String emplyNo) {
this.emplyNo = emplyNo;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getCrnSt() {
return crnSt;
}
public void setCrnSt(String crnSt) {
this.crnSt = crnSt;
}
public String getLoCo() {
return loCo;
}
public void setLoCo(String loCo) {
this.loCo = loCo;
}
public String getLoDept() {
return loDept;
}
public void setLoDept(String loDept) {
this.loDept = loDept;
}
public String getIdentTp() {
return identTp;
}
public void setIdentTp(String identTp) {
this.identTp = identTp;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getBrthDt() {
return brthDt;
}
public void setBrthDt(String brthDt) {
this.brthDt = brthDt;
}
public String getNation() {
return nation;
}
public void setNation(String nation) {
this.nation = nation;
}
public String getNtvPlc() {
return ntvPlc;
}
public void setNtvPlc(String ntvPlc) {
this.ntvPlc = ntvPlc;
}
public String getDomcChrctrstc() {
return domcChrctrstc;
}
public void setDomcChrctrstc(String domcChrctrstc) {
this.domcChrctrstc = domcChrctrstc;
}
public String getMrtlSt() {
return mrtlSt;
}
public void setMrtlSt(String mrtlSt) {
this.mrtlSt = mrtlSt;
}
public String getPltclSt() {
return pltclSt;
}
public void setPltclSt(String pltclSt) {
this.pltclSt = pltclSt;
}
public String getInParDt() {
return inParDt;
}
public void setInParDt(String inParDt) {
this.inParDt = inParDt;
}
public String getHltStatus() {
return hltStatus;
}
public void setHltStatus(String hltStatus) {
this.hltStatus = hltStatus;
}
public String getRsdnAdr() {
return rsdnAdr;
}
public void setRsdnAdr(String rsdnAdr) {
this.rsdnAdr = rsdnAdr;
}
public String getPst() {
return pst;
}
public void setPst(String pst) {
this.pst = pst;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public String getPstPostnLvl() {
return pstPostnLvl;
}
public void setPstPostnLvl(String pstPostnLvl) {
this.pstPostnLvl = pstPostnLvl;
}
public String getMblNo() {
return mblNo;
}
public void setMblNo(String mblNo) {
this.mblNo = mblNo;
}
public String getMailBox() {
return mailBox;
}
public void setMailBox(String mailBox) {
this.mailBox = mailBox;
}
public String getPstlCd() {
return pstlCd;
}
public void setPstlCd(String pstlCd) {
this.pstlCd = pstlCd;
}
public String getEdctHist() {
return edctHist;
}
public void setEdctHist(String edctHist) {
this.edctHist = edctHist;
}
public String getDplma() {
return dplma;
}
public void setDplma(String dplma) {
this.dplma = dplma;
}
public String getIfHestEdctHist() {
return ifHestEdctHist;
}
public void setIfHestEdctHist(String ifHestEdctHist) {
this.ifHestEdctHist = ifHestEdctHist;
}
public String getCtfInfArray() {
return ctfInfArray;
}
public void setCtfInfArray(String ctfInfArray) {
this.ctfInfArray = ctfInfArray;
}
public String getFamMbrInfArray() {
return famMbrInfArray;
}
public void setFamMbrInfArray(String famMbrInfArray) {
this.famMbrInfArray = famMbrInfArray;
}
}

152
src/main/java/com/eco/plugin/xx/jlyhsjtb/db/controller/DBController.java

@ -0,0 +1,152 @@
package com.eco.plugin.xx.jlyhsjtb.db.controller;
import com.eco.plugin.xx.jlyhsjtb.db.bean.OrgEntity;
import com.eco.plugin.xx.jlyhsjtb.db.bean.UserEntity;
import com.eco.plugin.xx.jlyhsjtb.db.dao.OrgDao;
import com.eco.plugin.xx.jlyhsjtb.db.dao.UserDao;
import com.eco.plugin.xx.jlyhsjtb.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 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, OrgDao.DAO
};
}
@Override
public void onDBAvailable(DBAccessor accessor) {
DBController.accessor = accessor;
}
/**
* 批量操作
* @param addOrUpdate
* @param delete
* @return
*/
public static boolean batchUser(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 {
//usrid与id相同
UserEntity ae =context.getDAO(UserDao.class).getById(dbe.getUsrId());
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 {
UserEntity ae =context.getDAO(UserDao.class).getById(dbe.getUsrId());
context.getDAO(UserDao.class).remove(ae.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 batchOrg(List<OrgEntity> addOrUpdate, List<OrgEntity> delete){
//新增或者删除
if(addOrUpdate != null && addOrUpdate.size() > 0){
for(final OrgEntity dbe : addOrUpdate){
try{
accessor.runDMLAction(new DBAction<Boolean>() {
@Override
public Boolean run(DAOContext context) throws Exception {
OrgEntity ae =context.getDAO(OrgDao.class).getById(dbe.getBrId());
if(ae != null ){
dbe.setId(ae.getId());
context.getDAO(OrgDao.class).update(dbe);
}else{
context.getDAO(OrgDao.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 OrgEntity dbe : delete){
try{
accessor.runDMLAction(new DBAction<Boolean>() {
@Override
public Boolean run(DAOContext context) throws Exception {
OrgEntity ae =context.getDAO(OrgDao.class).getById(dbe.getBrId());
context.getDAO(OrgDao.class).remove(ae.getId());
return true;
}
});
}catch(Throwable e){
FRUtils.FRLogError("batch delete exception ->"+e.getMessage() + dbe.toString());
}
}
}
return true;
}
}

69
src/main/java/com/eco/plugin/xx/jlyhsjtb/db/dao/OrgDao.java

@ -0,0 +1,69 @@
package com.eco.plugin.xx.jlyhsjtb.db.dao;
import com.eco.plugin.xx.jlyhsjtb.db.bean.OrgEntity;
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 OrgDao extends BaseDAO<OrgEntity> {
public OrgDao(DAOSession session) {
super(session);
}
@Override
protected Class<OrgEntity> getEntityClass() {
return OrgEntity.class;
}
public final static DAOProvider DAO = new DAOProvider() {
@Override
public Class getEntityClass() {
return OrgEntity.class;
}
@Override
public Class<? extends BaseDAO> getDAOClass() {
return OrgDao.class;
}
};
public void add(OrgEntity 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(OrgEntity entity) throws Exception {
getSession().merge(entity);
}
public OrgEntity getByUsername(String username) throws Exception {
QueryCondition condition = QueryFactory.create()
.addRestriction(RestrictionFactory.eq("username", username));
return findOne(condition);
}
public List<OrgEntity> like(String pid, String type)throws Exception{
QueryCondition condition = QueryFactory.create()
.addRestriction(RestrictionFactory.like("", pid)).addRestriction(RestrictionFactory.like(OrgEntity.COLUMN_ID,type));
return find(condition);
}
}

76
src/main/java/com/eco/plugin/xx/jlyhsjtb/db/dao/UserDao.java

@ -0,0 +1,76 @@
package com.eco.plugin.xx.jlyhsjtb.db.dao;
import com.eco.plugin.xx.jlyhsjtb.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 UserEntity getByUserId(String userid) throws Exception {
QueryCondition condition = QueryFactory.create()
.addRestriction(RestrictionFactory.eq("usrid", userid));
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);
}
}

62
src/main/java/com/eco/plugin/xx/jlyhsjtb/function/AuthFunction.java

@ -0,0 +1,62 @@
package com.eco.plugin.xx.jlyhsjtb.function;
import com.eco.plugin.xx.jlyhsjtb.config.PluginSimpleConfig;
import com.eco.plugin.xx.jlyhsjtb.controller.ControllerSelf;
import com.eco.plugin.xx.jlyhsjtb.utils.DateUtilSelf;
import com.eco.plugin.xx.jlyhsjtb.utils.FtpUtils;
import com.eco.plugin.xx.jlyhsjtb.utils.IOUtils;
import com.fr.json.JSONArray;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.script.AbstractFunction;
import java.io.File;
import java.util.Date;
@FunctionRecorder
public class AuthFunction extends AbstractFunction {
@Override
public Object run(Object[] objects) {
PluginSimpleConfig psc = PluginSimpleConfig.getInstance();
checkUser(psc);
checkOrg(psc);
return "success";
}
private void checkUser(PluginSimpleConfig psc) {
String tody = DateUtilSelf.DateToString(new Date(),"yyyyMMdd");
String url = psc.getFtpurl()+"/"+tody;
String checkFileName = "IAMJ_USER_"+tody+".ok";
File checkFile = FtpUtils.downloadFromLinux(psc.getFtphost(),psc.getFtpport(),psc.getFtpuser(),psc.getFtppsd(),url,checkFileName);
if(checkFile != null && checkFile.exists()){
String dataFileName = "IAMJ_USER_"+tody+".dat";
File dataFile = FtpUtils.downloadFromLinux(psc.getFtphost(),psc.getFtpport(),psc.getFtpuser(),psc.getFtppsd(),url,dataFileName);
String jsonStr = IOUtils.readTxtFile(dataFile);
JSONArray datas = new JSONArray("["+jsonStr+"]");
for(int i=0;i<datas.length();i++){
ControllerSelf.operateUser(datas.getJSONObject(i));
}
}
}
private void checkOrg(PluginSimpleConfig psc) {
String tody = DateUtilSelf.DateToString(new Date(),"yyyyMMdd");
String url = psc.getFtpurl()+"/"+tody;
String checkFileName = "IAMJ_ORG_"+tody+".ok";
File checkFile = FtpUtils.downloadFromLinux(psc.getFtphost(),psc.getFtpport(),psc.getFtpuser(),psc.getFtppsd(),url,checkFileName);
if(checkFile != null && checkFile.exists()){
String dataFileName = "IAMJ_ORG_"+tody+".dat";
File dataFile = FtpUtils.downloadFromLinux(psc.getFtphost(),psc.getFtpport(),psc.getFtpuser(),psc.getFtppsd(),url,dataFileName);
String jsonStr = IOUtils.readTxtFile(dataFile);
JSONArray datas = new JSONArray("["+jsonStr+"]");
for(int i=0;i<datas.length();i++){
ControllerSelf.operateOrg(datas.getJSONObject(i));
}
}
}
}

70
src/main/java/com/eco/plugin/xx/jlyhsjtb/openapi/caller/GetOrgCaller.java

@ -0,0 +1,70 @@
package com.eco.plugin.xx.jlyhsjtb.openapi.caller;
import com.eco.plugin.xx.jlyhsjtb.config.PluginSimpleConfig;
import com.eco.plugin.xx.jlyhsjtb.db.bean.OrgEntity;
import com.eco.plugin.xx.jlyhsjtb.db.controller.DBController;
import com.eco.plugin.xx.jlyhsjtb.utils.*;
import com.fr.decision.authority.AuthorityContext;
import com.fr.decision.authority.controller.DefaultAuthorityController;
import com.fr.decision.webservice.Response;
import com.fr.json.JSONArray;
import com.fr.json.JSONObject;
import com.tptj.plugin.hg.client.open.exception.CodeException;
import com.tptj.plugin.hg.client.open.impl.AbstractAPICaller;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class GetOrgCaller extends AbstractAPICaller {
public static final GetOrgCaller CALLER = new GetOrgCaller();
private final DefaultAuthorityController authorityController = AuthorityContext.getInstance().getAuthorityController();
@Override
public Response call(HttpServletRequest request, Map<String, Object> map, Map<String, Object> map1) throws CodeException {
JSONObject param = Utils.getRequestBody(request);
String url = PluginSimpleConfig.getInstance().getOrgurl();
String result = HttpUtils.HttpPostJson(url,param.toString(),null);
if(Utils.isNullStr(result)){
FRUtils.FRLogError("获取机构补偿数据异常");
return Response.ok("SUCCESS");
}
JSONObject orgJson = new JSONObject(result);
JSONObject body = orgJson.getJSONObject("body");
JSONArray orgInfArray = body.getJSONArray("orgInfArray");
for(int i =0;i<orgInfArray.length();i++){
operateOrg(orgInfArray.getJSONObject(i));
}
return Response.ok("SUCCESS");
}
@Override
public String Description() {
return "组织补偿接口";
}
public static void operateOrg(JSONObject orgJson){
//增删改的标志
OrgEntity orgEntity = PubUtils.jsonObjToOrgEntity(orgJson);
List<OrgEntity> orgList = new ArrayList<OrgEntity>();
orgList.add(orgEntity);
String flag = orgEntity.getType();
if("delete".equals(flag)){
FRUtils.FRLogInfo("deleteorg:"+orgEntity.getBrCd()+ ";time:"+ DateUtilSelf.getNow());
DBController.batchOrg(null,orgList);
return ;
}
FRUtils.FRLogInfo("addOrUpdateOrg:"+orgEntity.getBrCd()+ ";time:"+ DateUtilSelf.getNow());
DBController.batchOrg(orgList,null);
}
}

81
src/main/java/com/eco/plugin/xx/jlyhsjtb/openapi/caller/GetUserCaller.java

@ -0,0 +1,81 @@
package com.eco.plugin.xx.jlyhsjtb.openapi.caller;
import com.eco.plugin.xx.jlyhsjtb.config.PluginSimpleConfig;
import com.eco.plugin.xx.jlyhsjtb.db.bean.UserEntity;
import com.eco.plugin.xx.jlyhsjtb.db.controller.DBController;
import com.eco.plugin.xx.jlyhsjtb.utils.*;
import com.fr.decision.authority.AuthorityContext;
import com.fr.decision.authority.controller.DefaultAuthorityController;
import com.fr.decision.webservice.Response;
import com.fr.json.JSONArray;
import com.fr.json.JSONObject;
import com.tptj.plugin.hg.client.open.exception.CodeException;
import com.tptj.plugin.hg.client.open.impl.AbstractAPICaller;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class GetUserCaller extends AbstractAPICaller {
public static final GetUserCaller CALLER = new GetUserCaller();
private final DefaultAuthorityController authorityController = AuthorityContext.getInstance().getAuthorityController();
@Override
public Response call(HttpServletRequest request, Map<String, Object> map, Map<String, Object> map1) throws CodeException {
JSONObject param = Utils.getRequestBody(request);
String url = PluginSimpleConfig.getInstance().getUserurl();
String result = HttpUtils.HttpPostJson(url,param.toString(),null);
if(Utils.isNullStr(result)){
FRUtils.FRLogError("获取用户补偿数据异常");
return Response.ok("SUCCESS");
}
JSONObject userJson = new JSONObject(result);
JSONObject body = userJson.getJSONObject("body");
JSONArray usrInfArray = body.getJSONArray("usrInfArray");
for(int i =0;i<usrInfArray.length();i++){
operateUser(usrInfArray.getJSONObject(i));
}
return Response.ok("SUCCESS");
}
@Override
public String Description() {
return "用户补偿接口";
}
public static void operateUser(JSONObject userJson){
//增删改的标志
UserEntity userEntity = PubUtils.jsonObjToUserEntity(userJson);
String flag = userEntity.getType();
List<UserEntity> userList = new ArrayList<UserEntity>();
userList.add(userEntity);
if("delete".equals(flag)){
FRUtils.FRLogInfo("deleteUser:"+userEntity.getEmplyNo() + ";time:"+ DateUtilSelf.getNow());
DBController.batchUser(null,userList);
try {
FRUserUtils.deleteByUsername(userEntity.getEmplyNo());
} catch (Exception e) {
FRUtils.FRLogError("删除用户失败:"+userEntity.getUsrId()+e.getMessage());
}
return ;
}
try {
PubUtils.addOrUpdateUser(userList,userEntity);
} catch (Exception e) {
FRUtils.FRLogError("新增删除用户失败:"+userEntity.getUsrId()+e.getMessage());
}
}
}

71
src/main/java/com/eco/plugin/xx/jlyhsjtb/openapi/caller/SyncIAMOrgCaller.java

@ -0,0 +1,71 @@
package com.eco.plugin.xx.jlyhsjtb.openapi.caller;
import com.eco.plugin.xx.jlyhsjtb.db.bean.OrgEntity;
import com.eco.plugin.xx.jlyhsjtb.db.controller.DBController;
import com.eco.plugin.xx.jlyhsjtb.utils.DateUtilSelf;
import com.eco.plugin.xx.jlyhsjtb.utils.FRUtils;
import com.eco.plugin.xx.jlyhsjtb.utils.PubUtils;
import com.eco.plugin.xx.jlyhsjtb.utils.Utils;
import com.fr.decision.authority.AuthorityContext;
import com.fr.decision.authority.controller.DefaultAuthorityController;
import com.fr.decision.webservice.Response;
import com.fr.json.JSONObject;
import com.tptj.plugin.hg.client.open.exception.CodeException;
import com.tptj.plugin.hg.client.open.impl.AbstractAPICaller;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class SyncIAMOrgCaller extends AbstractAPICaller {
public static final SyncIAMOrgCaller CALLER = new SyncIAMOrgCaller();
private final DefaultAuthorityController authorityController = AuthorityContext.getInstance().getAuthorityController();
@Override
public Response call(HttpServletRequest request, Map<String, Object> map, Map<String, Object> map1) throws CodeException {
JSONObject userJson = Utils.getRequestBody(request);
JSONObject body = userJson.getJSONObject("sysHead");
//增删改的标志
OrgEntity orgEntity = PubUtils.jsonObjToOrgEntity(body);
String flag = orgEntity.getType();
List<OrgEntity> orgList = new ArrayList<OrgEntity>();
orgList.add(orgEntity);
if("delete".equals(flag)){
FRUtils.FRLogInfo("deleteorg:"+orgEntity.getBrCd()+ ";time:"+ DateUtilSelf.getNow());
DBController.batchOrg(null,orgList);
return Response.ok("SUCCESS");
}
FRUtils.FRLogInfo("addOrUpdateOrg:"+orgEntity.getBrCd()+ ";time:"+ DateUtilSelf.getNow());
DBController.batchOrg(orgList,null);
return Response.ok("SUCCESS");
}
@Override
public String Description() {
return "组织增量接口";
}
public static void operateOrg(JSONObject orgJson){
//增删改的标志
OrgEntity orgEntity = PubUtils.jsonObjToOrgEntity(orgJson);
List<OrgEntity> orgList = new ArrayList<OrgEntity>();
orgList.add(orgEntity);
String flag = orgEntity.getType();
if("delete".equals(flag)){
FRUtils.FRLogInfo("deleteorg:"+orgEntity.getBrCd()+ ";time:"+ DateUtilSelf.getNow());
DBController.batchOrg(null,orgList);
return ;
}
FRUtils.FRLogInfo("addOrUpdateOrg:"+orgEntity.getBrCd()+ ";time:"+ DateUtilSelf.getNow());
DBController.batchOrg(orgList,null);
}
}

65
src/main/java/com/eco/plugin/xx/jlyhsjtb/openapi/caller/SyncIAMUserCaller.java

@ -0,0 +1,65 @@
package com.eco.plugin.xx.jlyhsjtb.openapi.caller;
import com.eco.plugin.xx.jlyhsjtb.db.bean.UserEntity;
import com.eco.plugin.xx.jlyhsjtb.db.controller.DBController;
import com.eco.plugin.xx.jlyhsjtb.utils.*;
import com.fr.decision.authority.AuthorityContext;
import com.fr.decision.authority.controller.DefaultAuthorityController;
import com.fr.decision.webservice.Response;
import com.fr.json.JSONObject;
import com.tptj.plugin.hg.client.open.exception.CodeException;
import com.tptj.plugin.hg.client.open.impl.AbstractAPICaller;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class SyncIAMUserCaller extends AbstractAPICaller {
public static final SyncIAMUserCaller CALLER = new SyncIAMUserCaller();
private final DefaultAuthorityController authorityController = AuthorityContext.getInstance().getAuthorityController();
@Override
public Response call(HttpServletRequest request, Map<String, Object> map, Map<String, Object> map1) throws CodeException {
JSONObject userJson = Utils.getRequestBody(request);
JSONObject body = userJson.getJSONObject("sysHead");
operateUser(body);
return Response.ok("SUCCESS");
}
@Override
public String Description() {
return "用户增量接口";
}
public static void operateUser(JSONObject userJson){
//增删改的标志
UserEntity userEntity = PubUtils.jsonObjToUserEntity(userJson);
String flag = userEntity.getType();
List<UserEntity> userList = new ArrayList<UserEntity>();
userList.add(userEntity);
if("delete".equals(flag)){
FRUtils.FRLogInfo("deleteUser:"+userEntity.getEmplyNo() + ";time:"+ DateUtilSelf.getNow());
DBController.batchUser(null,userList);
try {
FRUserUtils.deleteByUsername(userEntity.getEmplyNo());
} catch (Exception e) {
FRUtils.FRLogError("删除用户失败:"+userEntity.getUsrId()+e.getMessage());
}
return ;
}
try {
PubUtils.addOrUpdateUser(userList,userEntity);
} catch (Exception e) {
FRUtils.FRLogError("新增删除用户失败:"+userEntity.getUsrId()+e.getMessage());
}
}
}

28
src/main/java/com/eco/plugin/xx/jlyhsjtb/openapi/loader/GetOrgLoader.java

@ -0,0 +1,28 @@
package com.eco.plugin.xx.jlyhsjtb.openapi.loader;
import com.eco.plugin.xx.jlyhsjtb.openapi.caller.GetOrgCaller;
import com.tptj.plugin.hg.client.open.fun.APICaller;
import com.tptj.plugin.hg.client.open.impl.AbstractAPILoader;
public class GetOrgLoader extends AbstractAPILoader {
@Override
public String APIName(){
return "组织补偿接口";
}
@Override
public String RequestType() {
return "POST";
}
@Override
public String path() {
return "getOrgListPage";
}
@Override
public APICaller APICaller() {
return new GetOrgCaller();
}
}

28
src/main/java/com/eco/plugin/xx/jlyhsjtb/openapi/loader/GetUserLoader.java

@ -0,0 +1,28 @@
package com.eco.plugin.xx.jlyhsjtb.openapi.loader;
import com.eco.plugin.xx.jlyhsjtb.openapi.caller.GetUserCaller;
import com.tptj.plugin.hg.client.open.fun.APICaller;
import com.tptj.plugin.hg.client.open.impl.AbstractAPILoader;
public class GetUserLoader extends AbstractAPILoader {
@Override
public String APIName(){
return "用户补偿接口";
}
@Override
public String RequestType() {
return "POST";
}
@Override
public String path() {
return "getUserListPage";
}
@Override
public APICaller APICaller() {
return new GetUserCaller();
}
}

28
src/main/java/com/eco/plugin/xx/jlyhsjtb/openapi/loader/SyncIAMOrgLoader.java

@ -0,0 +1,28 @@
package com.eco.plugin.xx.jlyhsjtb.openapi.loader;
import com.eco.plugin.xx.jlyhsjtb.openapi.caller.SyncIAMOrgCaller;
import com.tptj.plugin.hg.client.open.fun.APICaller;
import com.tptj.plugin.hg.client.open.impl.AbstractAPILoader;
public class SyncIAMOrgLoader extends AbstractAPILoader {
@Override
public String APIName(){
return "组织增量接口";
}
@Override
public String RequestType() {
return "POST";
}
@Override
public String path() {
return "syncIAMOrg";
}
@Override
public APICaller APICaller() {
return new SyncIAMOrgCaller();
}
}

28
src/main/java/com/eco/plugin/xx/jlyhsjtb/openapi/loader/SyncIAMUserLoader.java

@ -0,0 +1,28 @@
package com.eco.plugin.xx.jlyhsjtb.openapi.loader;
import com.eco.plugin.xx.jlyhsjtb.openapi.caller.SyncIAMUserCaller;
import com.tptj.plugin.hg.client.open.fun.APICaller;
import com.tptj.plugin.hg.client.open.impl.AbstractAPILoader;
public class SyncIAMUserLoader extends AbstractAPILoader {
@Override
public String APIName(){
return "用户增量接口";
}
@Override
public String RequestType() {
return "POST";
}
@Override
public String path() {
return "syncIAMUser";
}
@Override
public APICaller APICaller() {
return new SyncIAMUserCaller();
}
}

33
src/main/java/com/eco/plugin/xx/jlyhsjtb/openapi/rgt/ARGT.java

@ -0,0 +1,33 @@
package com.eco.plugin.xx.jlyhsjtb.openapi.rgt;
import com.eco.plugin.xx.jlyhsjtb.openapi.loader.GetOrgLoader;
import com.eco.plugin.xx.jlyhsjtb.openapi.loader.GetUserLoader;
import com.eco.plugin.xx.jlyhsjtb.openapi.loader.SyncIAMOrgLoader;
import com.eco.plugin.xx.jlyhsjtb.openapi.loader.SyncIAMUserLoader;
import com.fr.plugin.transform.ExecuteFunctionRecord;
import com.fr.plugin.transform.FunctionRecorder;
import com.tptj.plugin.hg.client.open.fun.APILoader;
import com.tptj.plugin.hg.client.open.impl.AbstractAPICallerProvider;
@FunctionRecorder
public class ARGT extends AbstractAPICallerProvider {
@ExecuteFunctionRecord
@Override
public APILoader[] registerCallers() {
return new APILoader[]{
new SyncIAMUserLoader(),new SyncIAMOrgLoader(),new GetUserLoader(),new GetOrgLoader()
};
}
@Override
public String groupName() {
return "数据同步接口";
}
@Override
public String groupDescription() {
return "数据同步接口,包括用户、组织增量接口和用户、组织补偿机制接口";
}
}

235
src/main/java/com/eco/plugin/xx/jlyhsjtb/utils/DateUtilSelf.java

@ -0,0 +1,235 @@
package com.eco.plugin.xx.jlyhsjtb.utils;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
public class DateUtilSelf {
/**
* 获取当前时间 格式 yyyy-MM-dd HH:mm:ss
* @return
*/
public static String getNow() {
return DateToString(new Date(),"yyyy-MM-dd HH:mm:ss");
}
/**
* 日期转换为日期字符串
* @param date
* @param formatStr
* @return String
*/
public static String DateToString(Date date,String formatStr) {
SimpleDateFormat sdf = new SimpleDateFormat(formatStr);
String dateStr = sdf.format(date).toString();
return dateStr;
}
/**
* 日期字符串转换日期
* @param dateStr
* @param formatStr
* @return Date
*/
public static Date strToDate(String dateStr,String formatStr){
SimpleDateFormat sdf = new SimpleDateFormat(formatStr);
Date date = null;
try {
date = sdf.parse(dateStr);
}
catch(Exception e) {
}
return date;
}
/**
* Date转Timestamp
* @param date
* @return
*/
public static Timestamp dateToTimestamp(Date date) {
Date transDate = DateUtilSelf.strToDate(DateUtilSelf.DateToString(date, "yyyy-MM-dd hh:mm:ss"),"yyyy-MM-dd hh:mm:ss");
Timestamp timestamp = new Timestamp(transDate.getTime());
return timestamp;
}
/**
* Date字符串转Timestamp
* @param dateStr
* @param format
* @return
*/
public static Timestamp strToTimestamp(String dateStr,String format) {
Date date = strToDate(dateStr,format);
Timestamp timestamp = new Timestamp(date.getTime());
return timestamp;
}
/**
* 获取两个日期字符串之间的天数
* @param startDateStr
* @param endDateStr
* @param formatStr
* @return
*/
public static int getDays(String startDateStr,String endDateStr,String formatStr) {
Date startDate = strToDate(startDateStr,formatStr);
Date endDate = strToDate(endDateStr,formatStr);
long startTime = startDate.getTime();
long endTime = endDate.getTime();
int days = (int) ((endTime - startTime)/(60*60*24*1000));
return days;
}
/**
* 获取给定时间之前之后的时间
* @param type
* @param dateStr
* @param count
* @param formatStr
* @return
*/
public static String getAfterDateStr(int type,String dateStr,int count,String formatStr) {
Date startDate = strToDate(dateStr,formatStr);
Calendar calendar = Calendar.getInstance();
calendar.setTime(startDate);
calendar.add(type, count);
String endDateStr = DateToString(calendar.getTime(),formatStr);
return endDateStr;
}
/**
* 获取给定时间之前之后的时间
* @param type
* @param date
* @param count
* @param formatStr
* @return
*/
public static String getAfterDateStr(int type,Date date,int count,String formatStr) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(type, count);
String endDateStr = DateToString(calendar.getTime(),formatStr);
return endDateStr;
}
/**
* 获取给定时间之前之后的时间
* @param type
* @param date
* @param count
* @return
*/
public static Date getAfterDateStr(int type,Date date,int count) {
Calendar dateResult = Calendar.getInstance();
dateResult.setTime(date);
dateResult.add(type, count);
return dateResult.getTime();
}
/**
* 时间戳转日期
* @param timestamp
* @return
*/
public static Date timestampToDate(Timestamp timestamp) {
Date date = new Date(timestamp.getTime());
return date;
}
/**
* 时间戳转时间字符串
* @param timestamp
* @param format 日期格式
* @return
*/
public static String timestampToStr(Timestamp timestamp,String format) {
Date date = timestampToDate(timestamp);
String timeStr = DateToString(date, format);
return timeStr;
}
/**
* 获取所给日期length天内每s一天的日期
* @param date 所给日期yyyy-MM-dd
* @param length 长度
* @return
*/
public static List<String> getDateList(String date,int length){
List<String> dateList = new ArrayList<String>();
String format = "yyyy-MM-dd";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//获取length天后的日期
String targetDate = getAfterDateStr(Calendar.DATE,date,length,format);
Date start = null;
Date end = null;
if(length >= 0) {
start = strToDate(date,format);
end = strToDate(targetDate,format);
}else {
start = strToDate(targetDate,format);
end = strToDate(date,format);
}
Calendar calBegin = Calendar.getInstance();
calBegin.setTime(start);
Calendar calEnd = Calendar.getInstance();
calEnd.setTime(end);
while (end.after(calBegin.getTime())) {
calBegin.add(Calendar.DATE, 1);
String dayStr = sdf.format(calBegin.getTime());
dateList.add(dayStr);
}
return dateList;
}
/**
* 比较startDate是否在endDate之前
* @param startDate
* @param endDate
* @param format
* @return 0 两个日期相等 <0 开始日期在结束日期之前 >0 开始日期在结束日期之后
*/
public static int comparisonDate(String startDate,String endDate,String format) {
Date start = strToDate(startDate,format);
Date end = strToDate(endDate,format);
return start.compareTo(end);
}
//获取当前日期年、月、日、时、分、秒
public static int getCount(int type){
Calendar calendar = Calendar.getInstance();
return calendar.get(type);
}
}

170
src/main/java/com/eco/plugin/xx/jlyhsjtb/utils/FRUserUtils.java

@ -0,0 +1,170 @@
package com.eco.plugin.xx.jlyhsjtb.utils;
import com.fr.decision.authority.data.User;
import com.fr.decision.privilege.TransmissionTool;
import com.fr.decision.webservice.bean.user.DepRoleBean;
import com.fr.decision.webservice.bean.user.UserBean;
import com.fr.decision.webservice.bean.user.UserRolesBean;
import com.fr.decision.webservice.bean.user.UserUpdateBean;
import com.fr.decision.webservice.v10.login.LoginService;
import com.fr.decision.webservice.v10.user.UserService;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
public class FRUserUtils {
/**
* 获取用户Service
* @return
*/
public static UserService getUserService(){
return UserService.getInstance();
}
/**
* 添加用户
* @param userBean
*/
public static void addUser(UserBean userBean) throws Exception {
userBean.setPassword(TransmissionTool.defaultEncrypt(userBean.getPassword()));
getUserService().addUser(userBean);
}
/**
* 删除用户
* @param userBean
*/
public static void updateUser(UserBean userBean) throws Exception {
getUserService().editUser(userBean,"");
}
/**
* 删除用户
* @param user
* @return
*/
public static int deleteUser(User user) throws Exception {
String userId = user.getId();
UserUpdateBean userUpdateBean = new UserUpdateBean();
userUpdateBean.setRemoveUserIds(new String[]{userId});
return getUserService().deleteUsers(userUpdateBean);
}
/**
* 删除用户 根据用户名删除用户
* @param username
* @return
*/
public static int deleteByUsername(String username) throws Exception {
User user = getUserByUserName(username);
String userId = user.getId();
UserUpdateBean userUpdateBean = new UserUpdateBean();
userUpdateBean.setRemoveUserIds(new String[]{userId});
return getUserService().deleteUsers(userUpdateBean);
}
/**
* 根据用户名获取用户实体
* @param userName
* @return
*/
public static User getUserByUserName(String userName) throws Exception {
return getUserService().getUserByUserName(userName);
}
/**
* 根据用户名获取用户实体
* @param userName
* @return
*/
public static UserBean getUserBeanByUserName(String userName ) throws Exception {
String id = getUserService().getUserByUserName(userName).getId();
return getUser(id);
}
/**
* 根据id获取用户
* @param id
* @return
* @throws Exception
*/
public static UserBean getUser(String id) throws Exception {
return getUserService().getUser(id);
}
/**
* 判断是否是管理员
* @param username
* @return
*/
public static boolean isAdmin(String username) throws Exception{
return getUserService().isAdmin(getUserByUserName(username).getId());
}
/**
* 禁用启用用户
* @param userId
* @param state false 禁用 true 启用
* @throws Exception 异常说明失败
*/
public static void forbidUser(String userId,boolean state) throws Exception {
getUserService().forbidUser(userId,state);
}
/**
* 修改用户部门
* @param departmentId
* @param postId
* @param ud
* @throws Exception
*/
public static void updateDepartmentPostUsers(String departmentId, String postId, UserUpdateBean ud) throws Exception {
getUserService().updateDepartmentPostUsers(departmentId,"",ud);
}
public static User getCurrentUser(HttpServletRequest req) throws Exception {
String username = LoginService.getInstance().getCurrentUserNameFromRequestCookie(req);
if(Utils.isNullStr(username)){
return null;
}
return getUserByUserName(username);
}
/**
* 获取用户部门角色
* @param username
* @return
* @throws Exception
*/
private static UserRolesBean getUserRolesBean(String username) throws Exception {
return FRUserUtils.getUserService().getUserDepAndCustomRoles(username);
}
/**
* 获取部门职务
* @param username
* @return
* @throws Exception
*/
public static List<DepRoleBean> getDepRoleBean(String username) throws Exception{
return getUserRolesBean(username).getDepRoles();
}
/**
* 获取角色
* @param username
* @return
* @throws Exception
*/
public static List<String> getCustomRoles(String username) throws Exception{
return getUserRolesBean(username).getCustomRoles();
}
}

285
src/main/java/com/eco/plugin/xx/jlyhsjtb/utils/FRUtils.java

@ -0,0 +1,285 @@
package com.eco.plugin.xx.jlyhsjtb.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 {
//HttpSession session = httpServletRequest.getSession(true);
FRToken = LoginService.getInstance().login(httpServletRequest, httpServletResponse, userName);
//httpServletRequest.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME,FRToken);
//session.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME, FRToken);
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");
// DataModel userInfoDM = userInfo.createDataModel(Calculator.createCalculator());
return userInfo;
}
}

93
src/main/java/com/eco/plugin/xx/jlyhsjtb/utils/FtpUtils.java

@ -0,0 +1,93 @@
package com.eco.plugin.xx.jlyhsjtb.utils;
import com.fr.ftp.client.FTPClient;
import com.fr.ftp.client.FTPClientConfig;
import com.fr.ftp.client.FTPFile;
import com.fr.ftp.client.FTPReply;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
public class FtpUtils {
/**
* 从linux下载ftp文件
* @param host
* @param port
* @param user
* @param password
* @param dir
* @param filename
* @return
*/
public static File downloadFromLinux(String host,int port,String user,String password,String dir,String filename) {
File templateFile = null;
FTPClient ftp=null;
try
{
//设置ftp连接
ftp=new FTPClient();
ftp.connect(host,port);
ftp.login(user, password);
ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
//设置linux环境
FTPClientConfig conf = new FTPClientConfig( FTPClientConfig.SYST_UNIX);
ftp.configure(conf);
//判断是否连接成功
int reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply))
{
ftp.disconnect();
FRUtils.FRLogError("ftp连接失败replyCode:"+reply);
return null;
}
//设置访问被动模式
ftp.setRemoteVerificationEnabled(false);
ftp.enterLocalPassiveMode();
//检索ftp目录下所有的文件,利用时间字符串进行过滤
boolean hasdir = ftp.changeWorkingDirectory(dir);
if(!hasdir){
return null;
}
FTPFile[]fs = ftp.listFiles();
for(FTPFile f:fs)
{
String ftpFilename =f.getName();
if(ftpFilename.equals(filename))
{
templateFile = File.createTempFile("test","txt");
OutputStream ios = new FileOutputStream(templateFile);
ftp.retrieveFile(f.getName(), ios);
ios.close();
break;
}
}
}
catch (Exception e)
{
FRUtils.FRLogError("ftp下载失败:"+e.getMessage());
}
finally
{
if(ftp != null){
try
{
ftp.disconnect();
} catch (Exception ioe)
{
FRUtils.FRLogError("释放ftp连接失败");
}
}
}
return templateFile;
}
}

265
src/main/java/com/eco/plugin/xx/jlyhsjtb/utils/HttpUtils.java

@ -0,0 +1,265 @@
package com.eco.plugin..jlyhsjtb.utils;
import com.fr.log.FineLoggerFactory;
import com.fr.third.org.apache.http.HttpEntity;
import com.fr.third.org.apache.http.HttpResponse;
import com.fr.third.org.apache.http.HttpStatus;
import com.fr.third.org.apache.http.NameValuePair;
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.UnsupportedEncodingException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
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 {
/**
* 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;
}
}

100
src/main/java/com/eco/plugin/xx/jlyhsjtb/utils/IOUtils.java

@ -0,0 +1,100 @@
package com.eco.plugin.xx.jlyhsjtb.utils;
import java.io.*;
public class IOUtils {
/**
* 将inputStream写入本地文件
* @param url
* @param inputStream
*/
public static void writeFile(String url, InputStream inputStream){
int index;
byte[] bytes = new byte[1024];
FileOutputStream downloadFile = null ;
try {
downloadFile = new FileOutputStream(url);
while ((index = inputStream.read(bytes)) != -1) {
downloadFile.write(bytes, 0, index);
downloadFile.flush();
}
}catch(Exception e){
FRUtils.FRLogInfo("Exception:writeFile:"+e.getMessage());
}finally {
try {
inputStream.close();
downloadFile.close();
}
catch (Exception e){
FRUtils.FRLogInfo("Exception:writeFile:finally"+e.getMessage());
}
}
}
/**
* 字符串转输入流
* @param str
* @return
*/
public static InputStream strToInputStream(String str){
try {
return new ByteArrayInputStream(str.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
FRUtils.FRLogInfo("IOUtils-strToInputStream:exception:"+e.getMessage());
}
return null;
}
public static String inputStreamToStr(InputStream inputStream) {
StringBuffer stringBuffer = new StringBuffer();
byte[] byt = new byte[4096];
try {
for (int i; (i = inputStream.read(byt)) != -1; ) {
stringBuffer.append(new String(byt, 0, i));
}
}catch(Exception e){
FRUtils.FRLogInfo("Exception:inputStreamToStr:"+e.getMessage());
}
return stringBuffer.toString();
}
/**
* 读取txt文件
* @param file
* @return
*/
public static String readTxtFile(File file){
if(file == null || !file.isFile() || !file.exists()){
return "";
}
String result = "";
BufferedReader br = null;
try{
br = new BufferedReader(new FileReader(file));
String line = "";
while((line = br.readLine()) != null){
result += ","+line;
}
result = result.substring(1,result.length());
br.close();
}catch(Exception e){
FRUtils.FRLogError("读取txt文件异常!");
}finally {
if(br != null){
try {
br.close();
} catch (IOException e) {
FRUtils.FRLogError("BufferedReader关闭异常");
}
}
}
return result;
}
}

125
src/main/java/com/eco/plugin/xx/jlyhsjtb/utils/PubUtils.java

@ -0,0 +1,125 @@
package com.eco.plugin.xx.jlyhsjtb.utils;
import com.eco.plugin.xx.jlyhsjtb.db.bean.OrgEntity;
import com.eco.plugin.xx.jlyhsjtb.db.bean.UserEntity;
import com.eco.plugin.xx.jlyhsjtb.db.controller.DBController;
import com.fr.json.JSONObject;
import java.util.List;
/**
* 公共工具类
*/
public class PubUtils {
/**
* 添加或修改用户 包含对数据库及帆软用户的操作
* @param userList
* @param userEntity
* @throws Exception
*/
public static void addOrUpdateUser(List<UserEntity> userList, UserEntity userEntity) throws Exception {
FRUtils.FRLogInfo("addOrUpdateUser:"+userEntity.getEmplyNo() + ";time:"+DateUtilSelf.getNow());
//将用户数据添加到数据库表中
DBController.batchUser(userList,null);
}
/**
* json数据转换为Userentity实体
* @param userJson
* @return
*/
public static UserEntity jsonObjToUserEntity(JSONObject userJson){
UserEntity userEntity = new UserEntity();
userEntity.setType(userJson.getString("oprlTp"));
userEntity.setId(userJson.getString("usrId"));
userEntity.setUsrId(userJson.getString("usrId"));
userEntity.setSurnmNm(userJson.getString("surnmNm"));
userEntity.setEmplyNo(userJson.getString("emplyNo"));
userEntity.setPassword(userJson.getString("password"));
userEntity.setCrnSt(userJson.getString("crnSt"));
userEntity.setLoCo(userJson.getString("loCo"));
userEntity.setLoDept(userJson.getString("loDept"));
userEntity.setIdentTp(userJson.getString("identTp"));
userEntity.setIdentNo(userJson.getString("identNo"));
userEntity.setGender(userJson.getString("gender"));
userEntity.setBrthDt(userJson.getString("brthDt"));
userEntity.setNation(userJson.getString("nation"));
userEntity.setNtvPlc(userJson.getString("ntvPlc"));
userEntity.setDomcChrctrstc(userJson.getString("domcChrctrstc"));
userEntity.setMrtlSt(userJson.getString("mrtlSt"));
userEntity.setPltclSt(userJson.getString("pltclSt"));
userEntity.setInParDt(userJson.getString("inParDt"));
userEntity.setHltStatus(userJson.getString("hltStatus"));
userEntity.setRsdnAdr(userJson.getString("rsdnAdr"));
userEntity.setPst(userJson.getString("pst"));
userEntity.setPosition(userJson.getString("position"));
userEntity.setPstPostnLvl(userJson.getString("pstPostnLvl"));
userEntity.setMblNo(userJson.getString("mblNo"));
userEntity.setMailBox(userJson.getString("mailBox"));
userEntity.setPstlCd(userJson.getString("pstlCd"));
userEntity.setEdctHist(userJson.getString("edctHist"));
userEntity.setDplma(userJson.getString("dplma"));
userEntity.setIfHestEdctHist(userJson.getString("ifHestEdctHist"));
userEntity.setCtfInfArray(userJson.getString("ctfInfArray"));
userEntity.setFamMbrInfArray(userJson.getString("famMbrInfArray"));
return userEntity;
}
/**
* json数据转换为Orgentity实体
* @param orgJson
* @return
*/
public static OrgEntity jsonObjToOrgEntity(JSONObject orgJson){
OrgEntity orgEntity = new OrgEntity();
orgEntity.setType(orgJson.getString("oprlTp"));
orgEntity.setId(orgJson.getString("brId"));
orgEntity.setBrId(orgJson.getString("brId"));
orgEntity.setBrNm(orgJson.getString("brNm"));
orgEntity.setBrCd(orgJson.getString("brCd"));
orgEntity.setSprBrId(orgJson.getString("sprBrId"));
orgEntity.setBrTreeId(orgJson.getString("brTreeId"));
orgEntity.setBrCtgry(orgJson.getString("brCtgry"));
orgEntity.setBrTp(orgJson.getString("brTp"));
orgEntity.setBrAcbPrsnNm(orgJson.getString("brAcbPrsnNm"));
orgEntity.setSatrapLdr(orgJson.getString("satrapLdr"));
orgEntity.setBrChrctrstc(orgJson.getString("brChrctrstc"));
orgEntity.setBrSt(orgJson.getString("brSt"));
orgEntity.setLoDstc(orgJson.getString("loDstc"));
orgEntity.setPstlId(orgJson.getString("pstlId"));
orgEntity.setTelNo(orgJson.getString("telNo"));
orgEntity.setRgstrtnAdr(orgJson.getString("rgstrtnAdr"));
orgEntity.setOfcAdr(orgJson.getString("ofcAdr"));
orgEntity.setCmpilPplCnt(orgJson.getString("cmpilPplCnt"));
orgEntity.setActPplCnt(orgJson.getString("actPplCnt"));
orgEntity.setOvCmpilPplCnt(orgJson.getString("ovCmpilPplCnt"));
orgEntity.setOvGapPplCnt(orgJson.getString("ovGapPplCnt"));
orgEntity.setAprvdPrefNo(orgJson.getString("aprvdPrefNo"));
orgEntity.setBrRspbl(orgJson.getString("brRspbl"));
orgEntity.setBrBlngBarLine(orgJson.getString("brBlngBarLine"));
orgEntity.setAprvdFoundTm(orgJson.getString("aprvdFoundTm"));
orgEntity.setLoCity(orgJson.getString("loCity"));
orgEntity.setFnPrmt(orgJson.getString("fnPrmt"));
orgEntity.setCrtDt(orgJson.getString("crtDt"));
orgEntity.setBsnLicNo(orgJson.getString("bsnLicNo"));
orgEntity.setLgtLtt(orgJson.getString("lgtLtt"));
orgEntity.setfICd(orgJson.getString("fICd"));
orgEntity.setLglPrsn(orgJson.getString("lglPrsn"));
orgEntity.setLoProv(orgJson.getString("loProv"));
orgEntity.setBrLyrdLvl(orgJson.getString("brLyrdLvl"));
orgEntity.setBrAcbPrsnCtcTel(orgJson.getString("brAcbPrsnCtcTel"));
orgEntity.setBrShrtNm(orgJson.getString("brShrtNm"));
orgEntity.setZoneInOutFlg(orgJson.getString("zoneInOutFlg"));
orgEntity.setAdmnstvDstc(orgJson.getString("admnstvDstc"));
return orgEntity;
}
}

108
src/main/java/com/eco/plugin/xx/jlyhsjtb/utils/ResponseUtils.java

@ -0,0 +1,108 @@
package com.eco.plugin.xx.jlyhsjtb.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();
}
}

244
src/main/java/com/eco/plugin/xx/jlyhsjtb/utils/Utils.java

@ -0,0 +1,244 @@
package com.eco.plugin.xx.jlyhsjtb.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…
Cancel
Save