commit 575e4d4c652da398efd36e064d819854b76ac0ad Author: pioneer Date: Thu Jan 5 15:21:21 2023 +0800 open diff --git a/README.md b/README.md new file mode 100644 index 0000000..43f8226 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# open-JSD-10390 + +JSD-10390 审批流推送定制开发\ +免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ +仅作为开发者学习参考使用!禁止用于任何商业用途!\ +为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系【pioneer】处理。 \ No newline at end of file diff --git a/lib/finekit-10.0-20220427.jar b/lib/finekit-10.0-20220427.jar new file mode 100644 index 0000000..6793f18 Binary files /dev/null and b/lib/finekit-10.0-20220427.jar differ diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..7c66437 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,23 @@ + + + com.eco.plugin.xx.audit.cbd1 + + yes + 1.0.3 + 10.0 + 2021-02-10 + fr.open + com.fr.plugin + + + + 2022-6-14 19:10:52 + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/CBD1Config.java b/src/main/java/com/fr/plugin/CBD1Config.java new file mode 100644 index 0000000..5c880d4 --- /dev/null +++ b/src/main/java/com/fr/plugin/CBD1Config.java @@ -0,0 +1,57 @@ +package com.fr.plugin; + +import com.fr.config.*; +import com.fr.config.holder.Conf; +import com.fr.config.holder.factory.Holders; + +@Visualization(category = "xx审批插件配置") +public class CBD1Config extends DefaultConfiguration { + + private static volatile CBD1Config config = null; + + public static CBD1Config getInstance() { + if (config == null) { + config = ConfigContext.getConfigInstance(CBD1Config.class); + } + return config; + } + @Identifier(value = "aName", name = "审批的账号", description = "审批的账号", status = Status.SHOW) + private Conf aName = Holders.simple("xx"); + @Identifier(value = "aPwd", name = "审批的密码", description = "审批接口地址", status = Status.SHOW) + private Conf aPwd = Holders.simple("xx"); + + @Identifier(value = "apiUrl", name = "审批接口地址", description = "审批接口地址", status = Status.SHOW) + private Conf apiUrl = Holders.simple("http:xx/api/km-review/kmReviewRestService/addReview"); + public String getApiUrl() { + return apiUrl.get(); + } + public void setApiUrl(String apiUrl) { + this.apiUrl.set(apiUrl); + } + + public String getaName() { + return aName.get(); + } + + public void setaName( String aName) { + this.aName .set(aName); + } + + public String getaPwd() { + return aPwd.get(); + } + + public void setaPwd( String aPwd) { + this.aPwd .set(aPwd); + } + + @Override + public Object clone() throws CloneNotSupportedException { + CBD1Config cloned = (CBD1Config) super.clone(); + cloned.apiUrl = (Conf) this.apiUrl.clone(); + cloned.aName = (Conf) this.aName.clone(); + cloned.aPwd = (Conf) this.aPwd.clone(); + return cloned; + } + +} \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/CBD1LifeCycleMonitor.java b/src/main/java/com/fr/plugin/CBD1LifeCycleMonitor.java new file mode 100644 index 0000000..57cf7ef --- /dev/null +++ b/src/main/java/com/fr/plugin/CBD1LifeCycleMonitor.java @@ -0,0 +1,18 @@ +package com.fr.plugin; + +import com.fr.plugin.context.PluginContext; +import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor; +import com.fr.stable.fun.Authorize; + +@Authorize +public class CBD1LifeCycleMonitor extends AbstractPluginLifecycleMonitor { + @Override + public void afterRun(PluginContext pluginContext) { + CBD1Config.getInstance(); + } + + @Override + public void beforeStop(PluginContext pluginContext) { + + } +} diff --git a/src/main/java/com/fr/plugin/FunctionRecoder.java b/src/main/java/com/fr/plugin/FunctionRecoder.java new file mode 100644 index 0000000..963ca84 --- /dev/null +++ b/src/main/java/com/fr/plugin/FunctionRecoder.java @@ -0,0 +1,12 @@ +package com.fr.plugin; + +import com.fr.plugin.transform.ExecuteFunctionRecord; +import com.fr.plugin.transform.FunctionRecorder; + +@FunctionRecorder +public class FunctionRecoder { + @ExecuteFunctionRecord + public void exe(){ + System.out.println("插件功能埋点,虽然不会执行,除非上架应用"); + } +} diff --git a/src/main/java/com/fr/plugin/http/CBD1HttpHandler.java b/src/main/java/com/fr/plugin/http/CBD1HttpHandler.java new file mode 100644 index 0000000..c423e40 --- /dev/null +++ b/src/main/java/com/fr/plugin/http/CBD1HttpHandler.java @@ -0,0 +1,17 @@ +package com.fr.plugin.http; + +import com.fr.decision.fun.HttpHandler; +import com.fr.decision.fun.impl.AbstractHttpHandlerProvider; +import com.fr.plugin.http.handler.*; + +public class CBD1HttpHandler extends AbstractHttpHandlerProvider { + HttpHandler[] actions = new HttpHandler[]{ + new POSTAddReview1Handler(), + new ALLAuditCallback2Handler(), + }; + + @Override + public HttpHandler[] registerHandlers() { + return actions; + } +} diff --git a/src/main/java/com/fr/plugin/http/CBD1UrlAliasProvider.java b/src/main/java/com/fr/plugin/http/CBD1UrlAliasProvider.java new file mode 100644 index 0000000..3c1af0b --- /dev/null +++ b/src/main/java/com/fr/plugin/http/CBD1UrlAliasProvider.java @@ -0,0 +1,15 @@ +package com.fr.plugin.http; + +import com.fr.decision.fun.impl.AbstractURLAliasProvider; +import com.fr.decision.webservice.url.alias.URLAlias; +import com.fr.decision.webservice.url.alias.URLAliasFactory; + +public class CBD1UrlAliasProvider extends AbstractURLAliasProvider { + @Override + public URLAlias[] registerAlias() { + return new URLAlias[]{ + URLAliasFactory.createPluginAlias("/addReview", "/addReview", false), + URLAliasFactory.createPluginAlias("/auditCallback", "/auditCallback", true), + }; + } +} diff --git a/src/main/java/com/fr/plugin/http/handler/ALLAuditCallback2Handler.java b/src/main/java/com/fr/plugin/http/handler/ALLAuditCallback2Handler.java new file mode 100644 index 0000000..ef23c0e --- /dev/null +++ b/src/main/java/com/fr/plugin/http/handler/ALLAuditCallback2Handler.java @@ -0,0 +1,137 @@ +package com.fr.plugin.http.handler; + +import com.fanruan.api.log.LogKit; +import com.fr.decision.fun.impl.BaseHttpHandler; +import com.fr.json.JSONObject; +import com.fr.log.FineLoggerFactory; +import com.fr.plugin.utils.DBUtils; +import com.fr.stable.StringUtils; +import com.fr.third.springframework.web.bind.annotation.RequestMethod; +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; + +public class ALLAuditCallback2Handler extends BaseHttpHandler { + @Override + public RequestMethod getMethod() { + return null; + } + + @Override + public String getPath() { + return "/auditCallback" ; + } + + @Override + public boolean isPublic() { + return true; + } + + @Override + public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception { + String requestBody = getRequestBody(req); + LogKit.info("收到对方的JSON:{}",requestBody); + DBUtils dbUtils = new DBUtils(); + + JSONObject jsonObject = new JSONObject(requestBody); + + String sql="UPDATE VCM_BILL_SHZT\n" + + "SET AUDIT_STATUS = ?,AUDIT_TIME = ? ,AUDIT_NAME = ?\n" + + "WHERE\n" + + " BILL_CODE = ? "; + dbUtils.exSqlUpdate(sql,jsonObject.getString("isAudit"), + jsonObject.getString("time") + ,jsonObject.getString("member"), + jsonObject.getString("fd_order_number")); + String sql2="UPDATE VCM_BILL_JGDA \n" + + "SET CBD_INCOME_PROPORTION_PRICE = '1' \n" + + "WHERE\n" + + " BILL_CODE = ? \n" + + " AND ITEM_SPEC = ? \n" + + " AND ITEM_PRICE = ?"; + //如果选中了中杯 + String fd_Product_rice_med = jsonObject.getString("fd_Product_price_med"); + if (StringUtils.isNotBlank(fd_Product_rice_med)) { + dbUtils.exSqlUpdate(sql2, jsonObject.getString("fd_order_number"), "中杯", fd_Product_rice_med); + } + String fd_Product_price_big = jsonObject.getString("fd_Product_price_big"); + if (StringUtils.isNotBlank(fd_Product_price_big)) { + dbUtils.exSqlUpdate(sql2, jsonObject.getString("fd_order_number"), "大杯", fd_Product_price_big); + } + String fd_Product_price_ven = jsonObject.getString("fd_Product_price_ven"); + if (StringUtils.isNotBlank(fd_Product_price_ven)) { + dbUtils.exSqlUpdate(sql2, jsonObject.getString("fd_order_number"), "超大杯", fd_Product_price_ven); + } + JSONObject entries = new JSONObject(); + entries.put("success" , "true"); + WebUtils.printAsJSON(res, entries); + } + /** + * 获取请求体 + * + * @param req + * @return + */ + public static String 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) { + } + + return sb.toString(); + } + /** + * 根据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(); + } + } + + LogKit.info("cookie:" + cookie); + + return cookie; + } + + private String deleteCookieByName(HttpServletRequest request, HttpServletResponse response, String name) { + Cookie[] cookies = request.getCookies(); + if (null == cookies) { + FineLoggerFactory.getLogger().debug("没有cookie"); + } else { + for (Cookie cookie : cookies) { + if (cookie.getName().equals(name)) { + String cookieValue = cookie.getValue(); + //设置值为null + cookie.setValue(null); + //立即销毁cookie + cookie.setMaxAge(0); + cookie.setPath("/"); + FineLoggerFactory.getLogger().debug("被删除的cookie名字为:{}" , cookie.getName(), cookieValue); + response.addCookie(cookie); + return cookieValue; + } + } + } + return "" ; + } +} diff --git a/src/main/java/com/fr/plugin/http/handler/POSTAddReview1Handler.java b/src/main/java/com/fr/plugin/http/handler/POSTAddReview1Handler.java new file mode 100644 index 0000000..cb07491 --- /dev/null +++ b/src/main/java/com/fr/plugin/http/handler/POSTAddReview1Handler.java @@ -0,0 +1,111 @@ +package com.fr.plugin.http.handler; + +import com.fanruan.api.log.LogKit; +import com.fanruan.api.net.http.HttpKit; +import com.fr.decision.authority.data.User; +import com.fr.decision.fun.impl.BaseHttpHandler; +import com.fr.decision.webservice.v10.user.UserService; +import com.fr.json.JSONObject; +import com.fr.log.FineLoggerFactory; +import com.fr.plugin.CBD1Config; +import com.fr.third.springframework.http.*; +import com.fr.third.springframework.util.LinkedMultiValueMap; +import com.fr.third.springframework.util.MultiValueMap; +import com.fr.third.springframework.web.bind.annotation.RequestMethod; +import com.fr.third.springframework.web.client.RestTemplate; +import com.fr.web.utils.WebUtils; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.BufferedReader; +import java.util.Base64; +import java.util.HashMap; + +public class POSTAddReview1Handler extends BaseHttpHandler { + @Override + public RequestMethod getMethod() { + return RequestMethod.POST; + } + + @Override + public String getPath() { + return "/addReview"; + } + + @Override + public boolean isPublic() { + return false; + } + + @Override + public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception { + User user = UserService.getInstance().getUserByRequestCookie(req); + String userName = user.getUserName(); + String docSubject = req.getParameter("docSubject"); + String docContent = req.getParameter("docContent"); + String formJson = req.getParameter("formJson"); + String respJSON = postData(docSubject, docContent, userName, formJson); + res.setContentType("application/json"); + WebUtils.printAsString(res, respJSON); + } + + /** + * 多层级的VO对象,且包含上传功能的样例 + * 注意key的书写格式,类似EL表达式的方式,属性关系用'.', 列表和数组关系用[],Map关系用["xxx"] + */ + public static String postData(String docSubject,String docContent,String userName,String formJson) throws Exception{ + RestTemplate yourRestTemplate = new RestTemplate(); + CBD1Config config = CBD1Config.getInstance(); + String url = config.getApiUrl(); + //把SysNewsParamterForm转换成MultiValueMap + MultiValueMap wholeForm = new LinkedMultiValueMap<>(); + wholeForm.add("docSubject", docSubject ); + wholeForm.add("docCreator", "{\"LoginName\":\""+userName+"\"}"); + wholeForm.add("docContent", docContent ); + wholeForm.add("docStatus", "20");//文档状态,可以为草稿("10")或者待审("20")两种状态,默认为待审,允许为空 + wholeForm.add("fdTemplateId", "xxxxxx"); + wholeForm.add("formValues", formJson ); + //注意附件列表的key是一样的 + + HttpHeaders headers = new HttpHeaders(); + //如果EKP对该接口启用了Basic认证,那么客户端需要加入 + addAuth(headers,config.getaName()+":"+config.getaPwd()); + headers.setContentType(MediaType.MULTIPART_FORM_DATA); + //必须设置上传类型,如果入参是字符串,使用MediaType.TEXT_PLAIN;如果 + HttpEntity> entity = new HttpEntity>(wholeForm,headers); + + //有返回值的情况 VO可以替换成具体的JavaBean + ResponseEntity obj = yourRestTemplate.exchange(url, HttpMethod.POST, entity, String.class); + String body = obj.getBody(); + LogKit.info("请求接口:{} 参数:{} 响应:{}",url,wholeForm,body); + + return body; + } + + private static void addAuth(HttpHeaders headers, String users) { + String encode = Base64.getEncoder().encodeToString(users.getBytes()); + headers.add("Authorization", "Basic "+encode); + } + + /** + * 获取请求体 + * + * @param req + * @return + */ + public static String 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) { + } + + return sb.toString(); + } + +} diff --git a/src/main/java/com/fr/plugin/utils/DBUtils.java b/src/main/java/com/fr/plugin/utils/DBUtils.java new file mode 100644 index 0000000..af39033 --- /dev/null +++ b/src/main/java/com/fr/plugin/utils/DBUtils.java @@ -0,0 +1,192 @@ +package com.fr.plugin.utils; + +import com.fanruan.api.data.ConnectionKit; +import com.fr.log.FineLoggerFactory; +import com.fr.log.FineLoggerProvider; + +import java.math.BigDecimal; +import java.sql.*; +import java.util.*; + +public class DBUtils { + String db_name = ""; + + private static FineLoggerProvider logger = FineLoggerFactory.getLogger(); + + public DBUtils() { + this.db_name = "DJDB"; + } + + public com.fr.data.impl.Connection getDbConnect() { + return ConnectionKit.getConnection(db_name); + } + + public List> select(String sql, Object... params) { + logger.info("query data by sql:" + sql + Arrays.toString(params)); + try { + com.fr.data.impl.Connection dbConnect = getDbConnect(); + Connection con = dbConnect.createConnection(); + PreparedStatement preparedStatement = con.prepareStatement(sql); + setParams(preparedStatement, params); + ResultSet rs = preparedStatement.executeQuery(sql); + // 获得记录的详细信息,然后获得总列数 + ResultSetMetaData resMetaData = rs.getMetaData(); + int colNum = resMetaData.getColumnCount(); + // 用对象保存数据 + String name = ""; + String value = ""; + List> list = new ArrayList>(); + while (rs.next()) { + Map cells = new HashMap(); + for (int i = 0; i < colNum; i++) { + name = resMetaData.getColumnLabel(i); + if (cells.get(name) != null) { + name = resMetaData.getColumnLabel(i); + } + if (rs.getObject(i) != null && resMetaData.getColumnTypeName(i).equals("DATETIME") || resMetaData.getColumnTypeName(i).equals("TIMESTAMP")) { + value = rs.getObject(i).toString(); + cells.put(name, value.substring(0, value.length() - 2)); + } else { + cells.put(name, rs.getString(i)); + } + } + list.add(cells); + } + // 释放数据库资源 + rs.close(); + preparedStatement.close(); + con.close(); + return list; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public int exec(String sql, String date) throws Exception { + logger.info("query data by sql:{} 时间:{}", sql, date); + Connection con = null; + CallableStatement call = null; + try { + com.fr.data.impl.Connection dbConnect = getDbConnect(); + con = dbConnect.createConnection(); + call = con.prepareCall(sql); + call.registerOutParameter(1, Types.INTEGER); + call.execute(); + Integer ret = call.getInt(1); + return ret; + } catch (Exception e) { + e.printStackTrace(); + throw e; + } finally { + if (call != null) { + call.close(); + } + if (con != null) { + con.close(); + } + } + } + + public Map findOneRow(String sql, Object... params) { + List> select = select(sql, params); + if (select != null) { + if (!select.isEmpty()) { + return select.get(0); + } + } + return null; + } + + public boolean checkExist(String sql, Object... params) throws Exception { + Connection connection = getDbConnect().createConnection(); + PreparedStatement pstmt = connection.prepareStatement(sql); + setParams(pstmt, params); + try { + ResultSet resultSet = pstmt.executeQuery(); + if (resultSet.next()) { + return resultSet.getInt(1) > 0; + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + connection.close(); + } + + return false; + } + + private void setParams(PreparedStatement pstmt, Object... params) throws SQLException { + if (params.length > 0) { + int length = params.length; + for (int i = 1; i <= length; i++) { + pstmt.setObject(i, params[i - 1]); + } + } + } + + public int exSqlUpdate(String sql, Object... params) throws Exception { + logger.info("update data by sql:" + sql + " params " + Arrays.toString(params)); + PreparedStatement pstmt = null; + Connection connection = null; + try { + com.fr.data.impl.Connection dbConnect = getDbConnect(); + connection = dbConnect.createConnection(); + pstmt = connection.prepareStatement(sql); + setParams(pstmt, params); + int i = pstmt.executeUpdate(); + return i; + } catch (Exception e) { + FineLoggerFactory.getLogger().error("执行更新SQL报错: sql:{}", e, sql); + } finally { + if (pstmt != null) { + pstmt.close(); + } + if (connection != null) { + connection.close(); + } + } + return 0; + } + + /** + * 取查询结果集字段 + * + * @param sql + * @param params + * @return + * @throws Exception + */ + public List> exQuery(String sql, Object... params) throws Exception { + logger.info("query data by sql:" + sql + " params " + Arrays.toString(params)); + com.fr.data.impl.Connection dbConnect = getDbConnect(); + Connection connection = dbConnect.createConnection(); + PreparedStatement pstmt = connection.prepareStatement(sql); + setParams(pstmt, params); + ResultSet resultSet = pstmt.executeQuery(); + ResultSetMetaData resMetaData = resultSet.getMetaData(); + int columnCount = resMetaData.getColumnCount(); + List> arrs = new ArrayList>(); + while (resultSet.next()) { + String name; + String value; + Map one = new HashMap(); + for (int i = 1; i <= columnCount; i++) { + name = resMetaData.getColumnLabel(i); + if (one.get(name) != null) { + name = resMetaData.getColumnLabel(i); + } + if (resultSet.getObject(i) != null && resMetaData.getColumnTypeName(i).equals("DATETIME") || resMetaData.getColumnTypeName(i).equals("TIMESTAMP")) { + value = resultSet.getObject(i).toString(); + one.put(name, value.substring(0, value.length() - 2)); + } else { + one.put(name, resultSet.getString(i)); + } + } + arrs.add(one); + } + pstmt.close(); + connection.close(); + return arrs; + } +} diff --git a/src/main/resources/com/fr/plugin/demo.js b/src/main/resources/com/fr/plugin/demo.js new file mode 100644 index 0000000..b99f366 --- /dev/null +++ b/src/main/resources/com/fr/plugin/demo.js @@ -0,0 +1,110 @@ +//fd_med_tab 分隔 +var fd_med_tab=[]; +var zbwlmc1=ZBWLMC.split(","); +var zbpfdw1=ZBPFDW.split(","); +var zbpfdwjg1=ZBPFDWJG.split(","); +var zbpfyl1=ZBPFYL.split(","); +var zbje1=ZBJE.split(","); + +for(var i=0;i