Browse Source

open

master
pioneer 2 years ago
commit
7e8364c8d1
  1. 6
      README.md
  2. 24
      plugin.xml
  3. 31
      src/main/java/com/eco/plugin/xxx/jmcwmsg/config/InitializeMonitor.java
  4. 79
      src/main/java/com/eco/plugin/xxx/jmcwmsg/config/PluginSimpleConfig.java
  5. 38
      src/main/java/com/eco/plugin/xxx/jmcwmsg/dsdd/db/DBAccessProvider.java
  6. 14
      src/main/java/com/eco/plugin/xxx/jmcwmsg/dsdd/db/Dao.java
  7. 23
      src/main/java/com/eco/plugin/xxx/jmcwmsg/dsdd/dsdd/DSDDMsgFormula.java
  8. 90
      src/main/java/com/eco/plugin/xxx/jmcwmsg/dsdd/dsdd/TsBean.java
  9. 80
      src/main/java/com/eco/plugin/xxx/jmcwmsg/dsdd/dsdd/TsEntity.java
  10. 90
      src/main/java/com/eco/plugin/xxx/jmcwmsg/dsdd/dsdd/TsHandler.java
  11. 35
      src/main/java/com/eco/plugin/xxx/jmcwmsg/dsdd/webresource/DsddWebResourceProvider.java
  12. 98
      src/main/java/com/eco/plugin/xxx/jmcwmsg/utils/DataOpUtils.java
  13. 331
      src/main/java/com/eco/plugin/xxx/jmcwmsg/utils/FRUtils.java
  14. 259
      src/main/java/com/eco/plugin/xxx/jmcwmsg/utils/HttpUtils.java
  15. 108
      src/main/java/com/eco/plugin/xxx/jmcwmsg/utils/ResponseUtils.java
  16. 329
      src/main/java/com/eco/plugin/xxx/jmcwmsg/utils/Utils.java
  17. 440
      src/main/resources/com/eco/plugin/xxx/jmcwmsg/js/dsdd.js

6
README.md

@ -0,0 +1,6 @@
# open-JSD-10225
JSD-10225 通过帆软的定时调度功能,以客户的自研APP为载体,实现消息推送功能\
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\
仅作为开发者学习参考使用!禁止用于任何商业用途!\
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系【pioneer】处理。

24
plugin.xml

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin>
<id>com.eco.plugin.xxx.jmcwmsg</id>
<name><![CDATA[消息推送_EK]]></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[消息推送_EK]]></description>
<change-notes><![CDATA[
[2022-07-12] JSD-10225初始化
]]></change-notes>
<main-package>com.eco.plugin.xxx.jmcwmsg</main-package>
<lifecycle-monitor class="com.eco.plugin.xxx.jmcwmsg.config.InitializeMonitor"/>
<extra-decision>
<OutputFormulaProvider class="com.eco.plugin.xxx.jmcwmsg.dsdd.dsdd.DSDDMsgFormula" />
<WebResourceProvider class="com.eco.plugin.xxx.jmcwmsg.dsdd.webresource.DsddWebResourceProvider"/>
<DecisionDBAccessProvider class="com.eco.plugin.xxx.jmcwmsg.dsdd.db.DBAccessProvider"/>
</extra-decision>
<function-recorder class="com.eco.plugin.xxx.jmcwmsg.config.PluginSimpleConfig"/>
</plugin>

31
src/main/java/com/eco/plugin/xxx/jmcwmsg/config/InitializeMonitor.java

@ -0,0 +1,31 @@
package com.eco.plugin.xxx.jmcwmsg.config;
import com.eco.plugin.xxx.jmcwmsg.dsdd.dsdd.DSDDMsgFormula;
import com.eco.plugin.xxx.jmcwmsg.dsdd.dsdd.TsBean;
import com.eco.plugin.xxx.jmcwmsg.dsdd.dsdd.TsEntity;
import com.eco.plugin.xxx.jmcwmsg.dsdd.dsdd.TsHandler;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor;
import com.fr.schedule.extension.report.job.output.formula.FormulaBox;
import com.fr.schedule.feature.ScheduleOutputActionEntityRegister;
import com.fr.schedule.feature.output.OutputActionHandler;
/**
* @author xxx
* @version 10.0
* Created by xxx on 2021-12-03
*/
public class InitializeMonitor extends AbstractPluginLifecycleMonitor {
@Override
public void afterRun(PluginContext pluginContext) {
PluginSimpleConfig.getInstance();
OutputActionHandler.registerHandler(new TsHandler(), TsBean.class.getName());
ScheduleOutputActionEntityRegister.getInstance().addClass(TsEntity.class);
FormulaBox.KEY.register(new DSDDMsgFormula());
}
@Override
public void beforeStop(PluginContext pluginContext) {
}
}

79
src/main/java/com/eco/plugin/xxx/jmcwmsg/config/PluginSimpleConfig.java

@ -0,0 +1,79 @@
package com.eco.plugin.xxx.jmcwmsg.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.xxx.jmcwmsg.config", text = "消息推送配置", source = Original.PLUGIN)
public static PluginSimpleConfig getInstance() {
if (config == null) {
config = ConfigContext.getConfigInstance(PluginSimpleConfig.class);
}
return config;
}
@Identifier(value = "funcKey", name = "轻应用key", description = "轻应用key", status = Status.SHOW)
private Conf<String> funcKey = Holders.simple("");
@Identifier(value = "url", name = "接口地址", description = "接口地址", status = Status.SHOW)
private Conf<String> url = Holders.simple("");
@Identifier(value = "frdomain", name = "帆软域名", description = "帆软域名", status = Status.SHOW)
private Conf<String> frdomain = Holders.simple("");
@Identifier(value = "prefix", name = "url前缀", description = "url前缀", status = Status.SHOW)
private Conf<String> prefix = Holders.simple("");
public String getFuncKey() {
return funcKey.get();
}
public void setFuncKey(String url) {
this.funcKey.set(url);
}
public String getUrl() {
return url.get();
}
public void setUrl(String url) {
this.url.set(url);
}
public String getFrdomain() {
return frdomain.get();
}
public void setFrdomain(String url) {
this.frdomain.set(url);
}
public String getPrefix() {
return prefix.get();
}
public void setPrefix(String url) {
this.prefix.set(url);
}
@Override
public Object clone() throws CloneNotSupportedException {
PluginSimpleConfig cloned = (PluginSimpleConfig) super.clone();
// cloned.text = (Conf<String>) text.clone();
// cloned.count = (Conf<Integer>) count.clone();
// cloned.price = (Conf<Double>) price.clone();
// cloned.time = (Conf<Long>) time.clone();
// cloned.student = (Conf<Boolean>) student.clone();
return cloned;
}
}

38
src/main/java/com/eco/plugin/xxx/jmcwmsg/dsdd/db/DBAccessProvider.java

@ -0,0 +1,38 @@
package com.eco.plugin.xxx.jmcwmsg.dsdd.db;
import com.eco.plugin.xxx.jmcwmsg.dsdd.dsdd.TsEntity;
import com.fr.decision.plugin.db.AbstractDecisionDBAccessProvider;
import com.fr.stable.db.accessor.DBAccessor;
import com.fr.stable.db.dao.BaseDAO;
import com.fr.stable.db.dao.DAOProvider;
public class DBAccessProvider extends AbstractDecisionDBAccessProvider {
private static DBAccessor dbAccessor = null;
public static DBAccessor getDbAccessor(){
return dbAccessor;
}
@Override
public DAOProvider[] registerDAO() {
return new DAOProvider[]{
new DAOProvider() {
@Override
public Class getEntityClass() {
return TsEntity.class;
}
@Override
public Class<? extends BaseDAO> getDAOClass() {
return Dao.class;
}
}
};
}
@Override
public void onDBAvailable(DBAccessor dbAccessor) {
this.dbAccessor = dbAccessor;
}
}

14
src/main/java/com/eco/plugin/xxx/jmcwmsg/dsdd/db/Dao.java

@ -0,0 +1,14 @@
package com.eco.plugin.xxx.jmcwmsg.dsdd.db;
import com.eco.plugin.xxx.jmcwmsg.dsdd.dsdd.TsEntity;
import com.fr.stable.db.dao.BaseDAO;
import com.fr.stable.db.session.DAOSession;
/**
* Created by xxx on 2021-12-03.
*/
public class Dao extends BaseDAO<TsEntity> {
public Dao(DAOSession daoSession) {
super(daoSession);
}
}

23
src/main/java/com/eco/plugin/xxx/jmcwmsg/dsdd/dsdd/DSDDMsgFormula.java

@ -0,0 +1,23 @@
package com.eco.plugin.xxx.jmcwmsg.dsdd.dsdd;
import com.fr.main.workbook.ResultWorkBook;
import com.fr.schedule.extension.report.provider.impl.AbstractReportOutputFormulaProvider;
import com.fr.schedule.extension.report.util.ScheduleParameterUtils;
import java.util.List;
import java.util.Map;
public class DSDDMsgFormula extends AbstractReportOutputFormulaProvider<TsBean, ResultWorkBook> {
public DSDDMsgFormula() {
}
public void dealWithFormulaParam(TsBean syncBean, ResultWorkBook resultWorkBook, List<Map<String, Object>> param) throws Exception {
syncBean.setTitle(ScheduleParameterUtils.dealWithParameter(syncBean.getTitle(), (Map)param.get(0), resultWorkBook));
syncBean.setContent(ScheduleParameterUtils.dealWithParameter(syncBean.getContent(), (Map)param.get(0), resultWorkBook));
syncBean.setMsgtype(ScheduleParameterUtils.dealWithParameter(syncBean.getMsgtype(), (Map)param.get(0), resultWorkBook));
}
public String getActionClassName() {
return TsBean.class.getName();
}
}

90
src/main/java/com/eco/plugin/xxx/jmcwmsg/dsdd/dsdd/TsBean.java

@ -0,0 +1,90 @@
package com.eco.plugin.xxx.jmcwmsg.dsdd.dsdd;
import com.fr.schedule.base.bean.output.BaseOutputAction;
import com.fr.schedule.base.entity.AbstractScheduleEntity;
import com.fr.schedule.base.type.RunType;
import com.fr.third.fasterxml.jackson.annotation.JsonSubTypes;
@JsonSubTypes.Type(value = TsBean.class, name = "TsBean")
public class TsBean extends BaseOutputAction {
private static final long serialVersionUID = 8245931480823179622L;
private String content = null;
private String msgtype = null;
private String title = null;
public TsBean(){
super();
}
//是否受不同用户生成不同附件影响
@Override
public boolean willExecuteByUser() {
return true;
}
@Override
public RunType runType() {
return RunType.SEND_EMAIL;
}
//这里直接关联第一步的entity类
@Override
public Class<? extends AbstractScheduleEntity> outputActionEntityClass() {
return TsEntity.class;
}
public TsBean id(String id){
setId(id);
return this;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public TsBean content(String content){
setContent(content);
return this;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public TsBean title(String title){
setTitle(title);
return this;
}
public String getMsgtype() {
return msgtype;
}
public void setMsgtype(String type) {
this.msgtype = type;
}
public TsBean msgtype(String type){
setMsgtype(type);
return this;
}
//转换成entity对象,用于数据库存储,注意属性不要漏了
@Override
public TsEntity createOutputActionEntity() {
return new TsEntity()
.id(this.getId())
.content(this.getContent())
.msgtype(this.getMsgtype())
.title(this.getTitle())
;
}
}

80
src/main/java/com/eco/plugin/xxx/jmcwmsg/dsdd/dsdd/TsEntity.java

@ -0,0 +1,80 @@
package com.eco.plugin.xxx.jmcwmsg.dsdd.dsdd;
import com.fr.schedule.base.entity.AbstractScheduleEntity;
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;
@Entity
@Table(name = "fine_output_xxx_message") //表名
@TableAssociation(associated = true)
public class TsEntity extends AbstractScheduleEntity{
public TsEntity(){}
@Column(name = "title")
private String title = null;
@Column(name = "content",length = 2000)
private String content = null;
@Column(name = "msgtype" )
private String msgtype = null;
public TsEntity id(String id) {
setId(id);
return this;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public TsEntity content(String content){
setContent(content);
return this;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public TsEntity title(String title){
setTitle(title);
return this;
}
public String getMsgtype() {
return msgtype;
}
public void setMsgtype(String content) {
this.msgtype = content;
}
public TsEntity msgtype(String content){
setMsgtype(content);
return this;
}
//转换成bean对象
@Override
public TsBean createBean() {
return new TsBean()
.id(this.getId())
.content(this.getContent())
.msgtype(this.getMsgtype())
.title(this.getTitle())
;
}
}

90
src/main/java/com/eco/plugin/xxx/jmcwmsg/dsdd/dsdd/TsHandler.java

@ -0,0 +1,90 @@
package com.eco.plugin.xxx.jmcwmsg.dsdd.dsdd;
import com.eco.plugin.xxx.jmcwmsg.config.PluginSimpleConfig;
import com.eco.plugin.xxx.jmcwmsg.utils.DataOpUtils;
import com.eco.plugin.xxx.jmcwmsg.utils.FRUtils;
import com.fr.schedule.base.bean.ScheduleTask;
import com.fr.schedule.base.controller.ScheduleTaskController;
import com.fr.schedule.feature.ScheduleContext;
import com.fr.schedule.feature.output.OutputActionHandler;
import com.fr.stable.query.QueryFactory;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;
public class TsHandler extends OutputActionHandler<TsBean>{
@Override
public void doAction(TsBean tsBean, Map<String, Object> map){
String userCodes = String.valueOf(map.get("username"));
String funcUrl = getTempUrl(tsBean,map);
String msgType = tsBean.getMsgtype();
String title = tsBean.getTitle();
String content = tsBean.getContent();
DataOpUtils.sendMsg(userCodes,msgType,title,content,funcUrl, PluginSimpleConfig.getInstance());
}
/**
* 获取定时调度
* @param taskName
* @return
*/
private static ScheduleTask getTask(String taskName){
ScheduleTask scheduleTask = null;
try {
ScheduleTaskController scheduleTaskController = ScheduleContext.getInstance().getScheduleTaskController();
scheduleTask = scheduleTaskController.getByTaskName(taskName,QueryFactory.create());
} catch (Exception e) {
FRUtils.FRLogInfo("任务异常:"+e.getMessage());
return null;
}
return scheduleTask;
}
/**
* 获取模板链接
* @param map
* @return
*/
private static String getTempUrl(TsBean tsBean,Map<String, Object> map){
String taskName = String.valueOf(map.get("taskName"));
ScheduleTask scheduleTask = getTask(taskName);
int showType = scheduleTask.getShowType();
String templateName = scheduleTask.getTemplatePath();
try {
templateName = URLEncoder.encode(templateName,"utf-8");
} catch (UnsupportedEncodingException e) {
FRUtils.FRLogInfo("编码模板名称异常:"+e.getMessage());
return "";
}
if(1 == showType){
templateName+="&op=write";
}
else if(2 == showType){
templateName += "&op=view";
}
else if(3 == showType){
templateName += "&op=write_plus";
}
return tsBean.getResultURL()+"/view/report?viewlet="+templateName;
}
/**
* 获取用户组信息
* @param map
* @return
*/
private static String[] getUserGroup(Map<String, Object> map){
String taskName = String.valueOf(map.get("taskName"));
ScheduleTask scheduleTask = getTask(taskName);
return scheduleTask.getUserGroup().createUserNameArray();
}
}

35
src/main/java/com/eco/plugin/xxx/jmcwmsg/dsdd/webresource/DsddWebResourceProvider.java

@ -0,0 +1,35 @@
package com.eco.plugin.xxx.jmcwmsg.dsdd.webresource;
import com.fr.decision.fun.impl.AbstractWebResourceProvider;
import com.fr.decision.web.MainComponent;
import com.fr.web.struct.Atom;
import com.fr.web.struct.Component;
import com.fr.web.struct.browser.RequestClient;
import com.fr.web.struct.category.ScriptPath;
import com.fr.web.struct.category.StylePath;
/**
*
*/
public class DsddWebResourceProvider extends AbstractWebResourceProvider {
@Override
public Atom attach() {
return MainComponent.KEY;
}
@Override
public Atom client() {
return new Component() {
@Override
public ScriptPath script(RequestClient requestClient) {
return ScriptPath.build("/com/eco/plugin/xxx/jmcwmsg/js/dsdd.js");
}
@Override
public StylePath style(RequestClient requestClient) {
return StylePath.EMPTY;
// return StylePath.build("/com/fr/plugin/jdfSSO/css/icon.css");
}
};
}
}

98
src/main/java/com/eco/plugin/xxx/jmcwmsg/utils/DataOpUtils.java

@ -0,0 +1,98 @@
package com.eco.plugin.wink.jmcwmsg.utils;
import com.eco.plugin.wink.jmcwmsg.config.PluginSimpleConfig;
import java.util.HashMap;
import java.util.Map;
/**
* 数据操作类
*/
public class DataOpUtils {
/**
* 发送短信
* @param userCodes
* @param msgType
* @param title
* @param content
* @param funcUrl
* @param psc
* @return
*/
public static boolean sendMsg(String userCodes, String msgType, String title, String content, String funcUrl, PluginSimpleConfig psc){
funcUrl = operUrl(funcUrl,psc);
String param = genParam(userCodes, msgType, title, content, psc.getFuncKey(), funcUrl);
String result = HttpUtils.HttpPostText(psc.getUrl(),param);
if(Utils.isNullStr(result)){
return false;
}
Map<String,String> resultMap = getResult(result);
return resultMap.get("code").equals("200");
}
/**
* 操作url
* @param url
* @param psc
* @return
*/
private static String operUrl(String url,PluginSimpleConfig psc){
return psc.getPrefix()+url.replaceAll(psc.getFrdomain(),"");
}
/**
* 获取请求结果
* @param result
* @return
*/
private static Map<String,String> getResult(String result){
String code = result.substring(result.indexOf("<msgCode>")+9,result.indexOf("</msgCode>"));
String msg = result.substring(result.indexOf("<message>")+9,result.indexOf("</message>"));
Map<String,String> resultMap = new HashMap<>();
resultMap.put("code",code);
resultMap.put("msg",msg);
return resultMap;
}
/**
* 生产请求参数
* @param userCodes
* @param msgType
* @param title
* @param content
* @param funcKey
* @param funcUrl
* @return
*/
private static String genParam(String userCodes,String msgType,String title,String content,String funcKey,String funcUrl){
String paramText = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:shw=\"http://shwocase.example.kingnode.com\">\n" +
" <soapenv:Header/>\n" +
" <soapenv:Body>\n" +
" <shw:push>\n" +
" <!--Zero or more repetitions:-->\n" +
" <userCodes>#userCodes</userCodes>\n" +
" <!--Optional:-->\n" +
" <msgType>#msgType</msgType>\n" +
" <!--Optional:-->\n" +
" <title><![CDATA[#title]]></title>\n" +
" <!--Optional:-->\n" +
" <content><![CDATA[#content]]></content>\n" +
" <!--Optional:-->\n" +
" <funcKey>#funcKey</funcKey>\n" +
" <!--Optional:-->\n" +
" <funcUrl>#funcUrl</funcUrl>\n" +
" </shw:push>\n" +
" </soapenv:Body>\n" +
"</soapenv:Envelope>";
return paramText.replaceAll("#userCodes",userCodes).replaceAll("#msgType",msgType).replaceAll("#title",title)
.replaceAll("#content",content).replaceAll("#funcKey",funcKey).replaceAll("#funcUrl",funcUrl);
}
}

331
src/main/java/com/eco/plugin/xxx/jmcwmsg/utils/FRUtils.java

@ -0,0 +1,331 @@
package com.eco.plugin.wink.jmcwmsg.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.base.constant.type.operation.ManualOperationType;
import com.fr.decision.authority.data.User;
import com.fr.decision.base.util.UUIDUtil;
import com.fr.decision.privilege.encrpt.PasswordValidator;
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.utils.UserSourceFactory;
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 param1 = AuthorityContext.getInstance().getUserController().find(QueryFactory.create().addRestriction(RestrictionFactory.eq("userName", userName)));
return param1 != null && !param1.isEmpty();
} catch (Exception param2) {
FineLoggerFactory.getLogger().error(param2.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 param1, String param2, int param3) {
try {
if (StringUtils.isNotEmpty(param2)) {
Cookie param4 = new Cookie("fine_auth_token", param2);
long param5 = param3 == -2 ? 1209600000L : (long)param3;
param4.setMaxAge((int)param5);
param4.setPath(ServerConfig.getInstance().getCookiePath());
param1.addCookie(param4);
Cookie param7 = new Cookie("fine_remember_login", String.valueOf(param3 == -2 ? -2 : -1));
param7.setMaxAge((int)param5);
param7.setPath(ServerConfig.getInstance().getCookiePath());
param1.addCookie(param7);
} else {
FineLoggerFactory.getLogger().error("empty token cannot save.");
}
} catch (Exception param8) {
FineLoggerFactory.getLogger().error(param8.getMessage(), param8);
}
}
/**
* 后台登出
* @param httpServletRequest
* @param httpServletResponse
*/
public static void logoutByToken(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String token)
{
httpServletRequest.setAttribute("fine_auth_token",token);
logout(httpServletRequest,httpServletResponse);
}
/**
*
* @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;
}
/**
* 解密FR密码
* @param password
* @return
*/
// public static String decryptFRPsd(String password){
// FRLogInfo("解密密码:"+password);
// return TransmissionTool.decrypt(password);
// }
/**
* 根据明文密码生成数据库中的密码用户密码校验用
* @return
*/
public static String getDBPsd(String username,String password){
PasswordValidator pv = UserSourceFactory.getInstance().getUserSource(ManualOperationType.KEY).getPasswordValidator();
String uuid = UUIDUtil.generate();
return pv.encode(username, password, uuid);
}
/**
* 获取带参数的访问链接
* @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
* @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);
}
/**
* 获取数据集数据
* @param serverDataSetName
* @return
*/
public static DataModel getTableData(String serverDataSetName){
TableData userInfo = TableDataConfig.getInstance().getTableData(serverDataSetName);
DataModel userInfoDM = userInfo.createDataModel(Calculator.createCalculator());
// userInfoDM.getRowCount();
// userInfoDM.getColumnIndex();
// userInfoDM.getValueAt()
return userInfoDM;
}
public static String getIndex(HttpServletRequest req){
String url = req.getScheme()+"://"+req.getServerName()+":"+String.valueOf(req.getServerPort())+req.getRequestURI();
return url;
}
}

259
src/main/java/com/eco/plugin/xxx/jmcwmsg/utils/HttpUtils.java

@ -0,0 +1,259 @@
package com.eco.plugin.wink.jmcwmsg.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.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);
FineLoggerFactory.getLogger().info("FRLOG:xmlParam:"+xmlParam);
HttpPost postMethod = new HttpPost(url);
postMethod.setHeader("Content-type", "text/plain");
HttpEntity entity2 = null;
entity2 = new StringEntity(xmlParam,"utf-8");
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;
}
}

108
src/main/java/com/eco/plugin/xxx/jmcwmsg/utils/ResponseUtils.java

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

329
src/main/java/com/eco/plugin/xxx/jmcwmsg/utils/Utils.java

@ -0,0 +1,329 @@
package com.eco.plugin.wink.jmcwmsg.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.List;
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 para3 = fw.indexOf(",");
return para3 != -1 ? fw.substring(0, para3) : 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);
}
/**
*
* @param res
* @param path /com/fr/plugin/loginAuth/html/getMac.html
* @param parameterMap
*/
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());
}
/**
* 去掉浏览器中的参数
* @param url
* @param param
* @return
*/
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));
}
/**
* 获取跳转链接
* @param req
* @param param
* @return
*/
public static String getRedirectUrl(HttpServletRequest req,String param){
String url = FRUtils.getAllUrl(req);
if(isNotNullStr(param)){
url = removeParam(url,param);
}
url = encodeCH(url);
return url;
}
/**
* 去除空格换行
* @param str
* @return
*/
public static String trim(String str){
return str.trim().replaceAll("\n","").replaceAll("\r","");
}
/**
* list 转化为指定字符分割的字符串
* @param list
* @param list
* @return
*/
public static String listToStr(List<String> list, String split){
String result = "";
if(list == null || list.size() <= 0){
return result;
}
for(String str : list){
result+=","+str;
}
result = result.substring(1);
return result;
}
/**
* array 转化为指定字符分割的字符串
* @param list
* @param list
* @return
*/
public static String arrayToStr(String[] list, String split){
String result = "";
if(list == null ||list.length <= 0){
return result;
}
for(int i=0;i<list.length;i++){
String str = list[i];
result+=","+str;
}
result = result.substring(1);
return result;
}
}

440
src/main/resources/com/eco/plugin/xxx/jmcwmsg/js/dsdd.js

@ -0,0 +1,440 @@
BI.config("dec.provider.schedule", function (provider) {
provider.registerHandingWay({
text: "消息推送",
value:"com.eco.plugin.xxx.jmcwmsg.dsdd.dsdd.TsBean",
cardType: "dec.schedule.task.file.handling.oa",
actions: [] // action
}, [DecCst.Schedule.TaskType.DEFAULT, DecCst.Schedule.TaskType.REPORT, DecCst.Schedule.TaskType.BI]);
});
var Plugin = BI.inherit(BI.Widget, {
props: {
baseCls: ""
},
_store: function () {
return BI.Models.getModel("dec.model.schedule.task.file.handling.oa")
},
watch: {
linkType: function (e) {
this.linkGroup.setValue(e),
this.customizeLinkText.setVisible(e === DecCst.Schedule.MessageUrl.Type.OUT)
},
type:function(e){
this.title.setVisible(e*1 !== 1)
},
linkGroupItems: function (e) {
this.linkGroup.populate(BI.createItems(e, {
type: "bi.single_select_radio_item",
logic: {
dynamic: !0
}
})),
this.model.isNotReportTask && this.store.setLinkType(DecCst.Schedule.MessageUrl.Type.OUT)
}
},
render: function () {
var t = this,
e = this.options.value[0],
n = this;
if(e == undefined){
e = {};
}
// this.store.setLinkType(e.linkOpenType*1);
// this.store.setType(e.type*1);
return {
type: "bi.vertical",
tgap: 15,
items: [{
type: "bi.horizontal_adapt",
columnSize: [115, "fill"],
items: [{
type: "bi.label",
cls: "dec-font-weight-bold",
width: 115,
height: 24,
textAlign: "left",
text: "消息类型"
}, {
type: "dec.label.editor.item",
textCls: "dec-font-weight-bold",
height: 24,
// lgap: 20,
invisible: 0,
textWidth: "",
watermark: "",
editorWidth: 300,
value: e.msgtype,
ref: function (e) {
n.msgtype = e
}
}
]
}, {
type: "bi.horizontal_adapt",
columnSize: [115, "fill"],
items: [{
type: "bi.label",
cls: "dec-font-weight-bold",
width: 115,
height: 24,
textAlign: "left",
text: "标题"
}, {
type: "dec.label.editor.item",
textCls: "dec-font-weight-bold",
height: 24,
// lgap: 20,
invisible: 0,
textWidth: "",
watermark: "标题",
editorWidth: 300,
value: e.title,
ref: function (e) {
n.title = e
}
}
]
},
{
type: "bi.horizontal_adapt",
columnSize: [115, "fill"],
items: [{
type: "bi.label",
cls: "dec-font-weight-bold",
width: 115,
height: 24,
textAlign: "left",
text: BI.i18nText("Dec-Basic_Content")
}, {
type: "dec.error_label",
height: 100,
el: {
type: "bi.textarea_editor",
cls: "bi-border",
width: 300,
height: 98,
watermark: "内容",
ref: function (e) {
n.contentText = e
},
value:e.content,
listeners: [{
eventName: BI.TextAreaEditor.EVENT_FOCUS,
action: function () {
n.contentBubbles.hideError()
}
}, {
eventName: BI.TextAreaEditor.EVENT_CHANGE,
action: function () {
n.contentBubbles.hideError()
}
}
]
},
ref: function (e) {
n.contentBubbles = e
}
}
]
}
]
}
},
/**
*
*
* @returns {boolean}
*/
validation: function () {
return true;
},
setValue: function (e) {
var t = this;
BI.map(e, function (e, i) {
if (i.runType === DecCst.Schedule.RunType.CLIENT_NOTIFICATION)
{
t.contentText.setValue(i.content), t.title.setValue(i.title), t.msgtype.setValue(i.msgtype)
}
})
},
/**
*
* outputActionList
* @returns {{}}
*/
getValue: function () {
return {
"@class": "com.eco.plugin.xxx.jmcwmsg.dsdd.dsdd.TsBean",
actionName: "com.eco.plugin.xxx.jmcwmsg.dsdd.dsdd.TsBean",
content: this.contentText.getValue(),
msgtype:this.msgtype.getValue(),
title:this.title.getValue()
}
}
});
BI.shortcut("dec.schedule.task.file.handling.oa", Plugin);
//数据
var e = BI.inherit(Fix.Model, {
context: ["currTask"],
state: function () {
return {
linkType: DecCst.Schedule.MessageUrl.Type.INNER,
type:1
}
},
computed: {
isBITask: function () {
return this.model.currTask.taskType === DecCst.Schedule.TaskType.BI
},
isNotReportTask: function () {
return this.model.currTask.taskType !== DecCst.Schedule.TaskType.REPORT
},
linkGroupItems: function () {
var e = BI.deepClone(BI.Constants.getConstant("dec.constant.schedule.task.handing.client.link"));
return this.model.isNotReportTask ? (e[0].disabled = !0, e[0].selected = !1, e[1].selected = !0, this.setLinkType(DecCst.Schedule.MessageUrl.Type.OUT)) : (e[0].disabled = !1, e[0].selected = this.model.linkType === DecCst.Schedule.MessageUrl.Type.INNER, e[1].selected = this.model.linkType === DecCst.Schedule.MessageUrl.Type.OUT),
e
},
typeGroupItems: function () {
return [{disabled:false,selected:true,text:'消息推送',value:'1'},{disabled:false,selected:false,text:'代办推送',value:'2'}]
}
},
actions: {
setLinkType: function (e) {
this.model.linkType = e
},
setType: function(e){
this.model.type = e;
}
}
});
BI.model("dec.model.schedule.task.file.handling.oa", e)
//处理空数组问题
var e = BI.inherit(BI.Widget, {
props: {
baseCls: "dec-schedule-task-handling",
$testId: "dec-schedule-task-handling",
value: {
scheduleOutput: {
outputActionList: []
}
}
},
_store: function () {
return BI.Models.getModel("dec.model.schedule.task.handling", {
value: this.options.value
})
},
watch: {
selectedWay: function (e) {
this.leftGroup.populate(this._createLeftItems(e)),
this.leftGroup.setValue(this.model.leftTab),
this.handlingWayGroup.setValue(e)
},
leftTab: function (e) {
this.centerTab.setSelect(e)
},
topItems: function (e) {
this.handlingWayGroup.populate(e),
this.handlingWayGroup.setValue(this.model.selectedWay)
},
taskType: function () {
this.centerTab.empty()
}
},
render: function () {
var i = this;
return {
type: "bi.vertical",
items: [{
el: {
type: "bi.vertical",
bgap: 5,
items: [{
type: "bi.absolute",
items: [{
el: {
type: "bi.horizontal",
tgap: 5,
items: [{
type: "bi.label",
height: 24,
cls: "dec-font-weight-bold",
text: BI.i18nText("Dec-Task_Handling"),
textAlign: "left"
}
]
},
left: 0,
top: 0
}
]
}, {
el: {
type: "bi.button_group",
layouts: [{
type: "bi.left",
lgap: 40,
bgap: 15
}
],
chooseType: BI.ButtonGroup.CHOOSE_TYPE_MULTI,
items: this.model.topItems,
value: this.model.selectedWay,
ref: function (e) {
i.handlingWayGroup = e
},
listeners: [{
eventName: BI.ButtonGroup.EVENT_CHANGE,
action: function (e, t) {
i.store.setHandlingWay(e, t.isSelected())
}
}
]
},
lgap: 50
}
]
},
tgap: 10
}, {
type: "bi.htape",
cls: "handling-body bi-border-top",
items: [{
type: "bi.button_group",
cls: "bi-border-right",
width: 200,
layouts: [{
type: "bi.vertical"
}
],
items: this._createLeftItems(this.model.selectedWay),
value: this.model.leftTab,
ref: function (e) {
i.leftGroup = e
},
listeners: [{
eventName: BI.ButtonGroup.EVENT_CHANGE,
action: function (e) {
i.store.setLeftTab(e)
}
}
]
}, {
type: "bi.absolute",
items: [{
el: {
type: "bi.tab",
showIndex: this.model.leftTab,
cardCreator: BI.bind(i._cardCreator, this),
ref: function (e) {
i.centerTab = e
}
},
top: 0,
left: 15,
bottom: 0,
right: 0
}
]
}
]
}
]
}
},
validation: function (e) {
var n = this,
o = [],
r = n.model.handlingItems;
BI.each(this.model.editingWay, function (e, t) {
var i = n[t + "Pane"];
if (!BI.isFunction(i.validation) || i.validation()) {
if (!BI.isNull(i.getValue()))
return !0;
o.push(r[t].text)
} else
o.push(r[t].text)
}),
0 < BI.size(o) && BI.Msg.alert(BI.i18nText("Dec-Basic_Tips"), BI.i18nText("Dec-Error_Task_File_Handling_Value", o.join(","))),
e(0 === BI.size(o))
},
getValue: function () {
var i = {};
BI.each(this.model.outputActionList, function (e, t) {
i[t.actionName] = t
});
var o = {},
r = [],
s = [],
a = [],
e = this.model.editingWay,
c = this,
l = c.model.handlingItems;
BI.each(e, function (e, t) {
var i,
n = c[t + "Pane"];
n && BI.isNotEmptyObject(n.getValue()) && ((i = n.getValue(), BI.isNotNull(l[t].actions) && l[t].actions.length > 0) ? (r.push(t), BI.each(i, function (e, t) {
var i = t.actionName;
r.push(i),
o[i] = t
}), s = BI.concat(s, BI.difference(l[t].actions, r))) : (r.push(t), o[t] = i), a.push(l[t].runType))
});
var t = BI.filter(i, function (e, t) {
return c.store.isDefaultByRunType(t, a) || c.store.isDefaultValueItem(t, r, s)
});
return {
scheduleOutput: BI.extend({}, this.model.currTask.scheduleOutput, {
outputActionList: BI.map(o, function (e, t) {
return delete t.runType,
BI.extend({
resultURL: window.location.protocol + "//" + window.location.host + Dec.fineServletURL
}, t)
}).concat(t)
})
}
},
_cardCreator: function (i) {
var t = this,
e = BI.find(this.model.handlingItems, function (e, t) {
return t.value === i
});
return e && BI.isKey(e.cardType) ? {
type: e.cardType,
value: this.store.findActionValue(e, BI.deepClone(this.model.outputActionList)),
ref: function (e) {
t[i + "Pane"] = e
}
}
: {
type: "bi.label",
text: i
}
},
_createLeftItems: function (e) {
var n = this;
return BI.map(e, function (e, t) {
var i = n.model.handlingItems[t].text;
return {
type: "dec.schedule.task.file.handling.item",
text: i,
value: t,
listeners: [{
eventName: "EVENT_DELETE",
action: function () {
n.store.deleteAction(t, i)
}
}
]
}
})
}
});
BI.shortcut("dec.schedule.task.handling", e)
Loading…
Cancel
Save