泛微二开系列(一)开发规范

前言:文档地址

.泛微云平台
https://e-cloudstore.com/cloud#/login

2.ecode使用说明
https://e-cloudstore.com/doc.html

3.泛微组件库
https://cloudstore.e-cology.cn/#/pc/doc/common-index

4.E9流程表单前端接口API
https://e-cloudstore.com/doc.html?appId=98cb7a20fae34aa3a7e3a3381dd8764e#E9%E6%B5%81%E7%A8%8B%E8%A1%A8%E5%8D%95%E5%89%8D%E7%AB%AF%E6%8E%A5%E5%8F%A3API

5.泛微后端接口API文档
https://e-cloudstore.com/ec/api/applist/index.html#/

6.ecology 后端开发文档
https://e-cloudstore.com/doc.html?appId=84e77d7890a14c439590b37707251859

7.ecology token使用
https://www.showdoc.com.cn/p/03bb207cb772a30e5e32cd7325b94c37

8.泛微首页介绍
https://e-cloudstore.com/e9/index0.html

9.ecology后端开发环境搭建
https://e-cloudstore.com/doc.html?appId=c6a9ae6e47b74d4da04c935ed51d177a&maxImgWidth=800#%E4%B8%83%E3%80%81resin%E8%BF%9C%E7%A8%8Bdebug%E9%85%8D%E7%BD%AE

10.Antd 组件库
https://ant.design/index-cn

11.Echarts 官网
https://echarts.apache.org/zh/index.html

E9 相关版本信息
react 统一版本为 16.4.1
Antd 统一是 1.x
https://1x.ant.design/components/table/

*泛微其他博主分享*
https://oneszhang.com/category/603039/
**
https://huahan.cc/cn

一、JAVA命名规范

1.1包名全部小写

1.2类名首字母大写,如果类名由多个单词组成,每个单词的首字母都要大写。

如: public class MyFirstClass{}

1.3变量名、方法名首字母小写,如果名称由多个单词组成,每个单词的首字母都要大写

如: int index=0;
public void toString(){}

1.4常量名全部大写

如: public static final String GAME_COLOR=”RED”;

1.5 所有命名规则必须遵循以下规则

  • 名称只能由字母、数字、下划线、S符号组成
  • 不能以数字开头
  • 名称不能使用JAVA中的关键字
  • 坚决不允许出现中文命名

1.6 类的注释

/**
* FileName: Testjava

*类的详细说明

*

*@author类创建者姓名
*@Date 创建日期
*@version 1.00版本
*/

1.7方法注释

在每个方法前面必须加上方法注释,注释模板如下:

/**
*类方法的详细使用说明
*
*@param 参数1参数1的使用说明
*@return 返回结果的说明
*@throws 异常类型错误代码 注明从此类方法中抛出异常的说明
*/

1.8后段代码规范

SQL错误例子:

例如select不能带*,因为会带来额外的I/O内存CPU的消耗;

sql使用‘+’拼接会带来sql注入的问题;

未判断执行的sql是否成功

RecordSet rs = new RecordSet();
String sql="select * from tablename where c = '"+parm1+"'";
rs.executeQuery(sql);
if (rs.next(){
//代码逻辑
}

修改后

RecordSet rs = new RecordSet();
String sql = "select a,b,c,d from tablename where c=? and d=?";
if((rs.executeQuery(sql,parm1,parm2)&&rs.next()){
//功能逻辑
}else{

}

事务回滚的方式

先给出一个错误的例子:如果sql1执行成功,sql2执行失败会导致数据错误

RecordSet rs = new RecordSet();
//更新财务报表1
String sql1 = "update table1 set a=? where b=?";
rs.executeUpdate(sgl1,parm1,parm2);
//更新财务报表2
String sgl2 = "update table2 set c=? where b=?";
rs.executeUpdate(sgl2,parm1,parm2);

修改后

RecordSetTrans rst = new RecordSetTrans();
rst.setAutoCommit(false);
try{
//更新财务报表1
String sql = "update table1 set a=? where b=?";
if(!rst.executeUpdate(sql1,parm1,parm2)){
   throw new Exception();
}
//更新财务报表2
String sgl2 = "update table2 set c=? where b=?";
if(!rst.executeUpdate(sql2,parm1,parm2){
   throw new Exception();
}
rst.commit():
}catch (Exception e) {
   rst.rollback();
   e.printStackTrace();
}

参数判空及重复new RecordSet

先给出错误例子

String sql="select a,b,c,d from tablename where c = ?";
while("".equals(parm1)){
  RecordSet rs = new RecordSet();
  if(rs.executeQuery(sql,parm1)&&rs.next()){
     parm1 = rs.getString(1);
  }else{

  }
}

修改后

RecordSet rs = new RecordSet();
String sql="select a,b,c,d from tablename where c = ?";
while(parm1!=null&&"equals(parm1)){
  if(rs.executeQuery(sql,parm1)&&rs.next()){
     parm1 = rs.getString(1);
  }else{

  }
}

RecodeSet通过参数传进,不应该在方法上定义

先提供错误例子

public String MyTest(String parm1,String parm2){
  RecordSet rs = new RecordSet();
  String sql="select a,b,c,d from tablename where c = ?";
  while("".equals(parm1)){
    if(rs.executeQuery(sql,parm1)&&rs.next())
      parm1=rs.getString(1);
    }else{

    }
}

public String MyMain(){
 String parm1="1";
 String parm2="2";
 MyTest(parm1,parm2);
 return null;
}

修改后

public String MyTest(String parm1,String parm2,RecordSet rs){
  String sql="select a,b,c,d from tablename where c = ?";
  while("".equals(parm1)){
    if(rs.executeQuery(sgl,parm1)&&rs.next()){
       parm1=rs.getString(1);
    }else{
    
    }
  }
  return null;
}

private RecordSet rs = new RecordSet();
public String MyMain(){
  String parm1="1";
  String parm2="2";
  MyTest(parm1,parm2,rs);
  return null;
}

文件存储位置

必须在ecolog目录下的filesystem必须写相对路径,禁止使用绝对路径

####示例
File file = new File("filesystem/功能文件/年份/月份/文件名称"):
####禁止
File file = new File("/usr/weaver/ecology/filesystem/功能文件/年份/月份/文件名称”);
File file = new File(“ecology/filesystem/功能文件/年份/月份/文件名称");
File file = new File("/filesystem/功能文件/年份/月份/文件名称");

日志写入规范

方法一(推荐):
Logger log = LoggerFactory.getLogger();
log.info("测试日志");
日志文件所在目录:ecology/log/integration/integration.log

方法二:
BaseBean bb = new BaseBean();
bb.writeLog("测试日志");

日志文件所在目录:ecology/log/ecolog

二、Ecode规范

2.1 Ecode代码规范

let命令,是用来声明变量。它的用法类似于var,但是所声明的变量,只在let命令所在的代码块内有效。
const命令 const声明一个只读的常量。一旦声明,常量的值就不能改变。
var可以重复声明,从逻辑角度来说,声明只需要声明一次。
<!DOCTYPE html>
<html>
<head>
<script>
function example1() {
  let x = 10;
  let y = 10;
  let z = 10;
  z = 20;  //let 在所在代码块内有效,同一代码块内不能重复定义(即不能再次 let z = 20)
 
  if (true) {
    let x = 20; // 不会影响外部的,这是跟var 区别的地方 
    y = 20;     // 会影响外部的 x
    console.log("let:x:"+x+",y:"+y); //控制台输出 x:20 ,y :20
  }
  console.log("let:x:"+x+",y:"+y+",z:"+z);  //控制台输出 x:10,y:20,z:20
}
example1()

function example2() {
  const x = 10;
  const y = 10;
  const z = 10;
 // z = 20;  //const 声明一个只读常量,一旦声明,不能改变(声明),即 z=20/const z=20;都会报错
 
  
 
  if (true) {
    const x = 20; // 不会影响外部的x,注意的是,不能改变,即 x=20/会报错
    const y = 20; // 会影响外部的y,注意的是,不能改变,即 y=20/会报错
    console.log("const:x:"+x+",y:"+y); //控制台输出 x:20 ,y :20
  }
  console.log("const:x:"+x+",y:"+y+",z:"+z);  //控制台输出 x:10,y:10,z:10 
}
example2();


function example3() {
  var x = 10;
  var y = 10;
  var z = 10;
  var z = 20;
  if (true) {
    var x = 20; // 影响外部的 x
    y = 20;     // 会影响外部的 y
    console.log("var:x:"+x+",y:"+y); //控制台输出 x:20 ,y :20
  }
  console.log("var:"+x+",y:"+y+",z:"+z);  //控制台输出 x:10,y:20,z:20
 
}
example3()
</script>
</head>
<body>
test
</body>
</html>

2.2Ecode注释规范

/**
*@author作者
@Data日期
*功能描述修改签字意见默认字体大小
*/
ecodeSDK.overwritePropsFnOueueMapSet('WeaRichText',{
fn:(newPropos,name)=>{
  if(!((ecodeSDK.checkLPath( /spa/workflow/static4form/index html#/main/workflow/req'))&&!(ecodeSDKcheckLPath(/spa/workflow/index form,jsp#/main/workflow/req))return;
  return newPropos;
}
})

2.3发布禁止存在console.log()

2.4禁止在复写组件中使用请求接口

ecodesDK.overwritePropsFnQueueMapSet('WeaTop',//组件名
  fn:(newProps)=>{ //newProps代表组件参数
  //进行位置判断
  //调用接口
  callApi('/api/ec/dev/table/datas', 'POST', params).then(data => {
    console.log(data) // jsonObj or text
  })
},
order:1.//排序字段,如果存在同一个页面复写了同一个组件,控制顺序时使用
desc:'在这里写此复写的作用,在调试的时候方便查找'
});

Ecode例子

##前置加载文件
ecodeSDK.overwritePropsFnQueueMapSet('Button',{
  fn:(newProps)=>{
    if(!ecodesDK.checkLPath('/wui/index.html#/main/workflow/listDoing')) return ;
    if(newProps.type !== "primary") return;
    newProps.className = `$(newProps.className) new-workflow-btn`;
    return newProps;
  },
  order:1,
  desc:'修改Button颜色'
})
修改样式
.new-workflow-btn{
  background-color: #ff006a;
  border-color: #ff006a;
}

三、SQL规范

  • 语句关键字应全部使用小写。
  • 引用字符时应使用单引号。如: update tablename set key=’value’
  • 连接符或运算符or、in、and、=,<=,>=,+,-等前后宜加上一个空格、否则容易导致以下类似问题例如在语句selecta-b from table中,a.b均为变量,拼写该语句时,如果a= 6,b=-3,则语句变为select 6–3 from table。–被视为SQL的注释,结果语句报错
  • 不得使用“select * from …”语法,必须标明字段名。即select col1, col2,… from tablea where …
  • 严禁使用“insert into table_name values (?,?,?)” 语法,统一使用“insert into table_name(col1.col2…….) values (?,?…….)”
  • SOL语句包含多表连接时,必须加上表的别名,对每个字段的使用都要带上表别名,肌 select a.col1.a.col2, b.col3 from tablea a, tableb b where a.col4=b.col5,可以避免字段同名的情况目可以提高查询下效率
  • 应避免显式或隐含的类型转换。例如在where子句中numeric型和int型的列的比较。
  • 在子查询中前后必须加上括号。select col1, col2 from tablea where col3 in ( select col4 from tableb where col4>0)
  • 执行SQL时一次应只执行一条,如果多条语句则应分开执行,但必须保持在一个事务中。不得一次执行通讨分号等分开的多条语句,这样外理不清晰。
  • 如果能采用or代替,则不宜使用in 语句。in语句中的元素不得超过1000个,如果超过,则应拆分为多条SQL语句,严禁使用xx in( ”,”,”) or xx in(”,”,”)

四、参数获取

weaver.file.Prop.getPropValue(“文件名”“属性名”);
ecology\WEB-INF\prop\文件名.properties
只能读这个路径下的配置文件

泛微二开系列(一)开发规范插图
CONTROL_BASE_URL = weaver.file.Prop.getPropValue("nccsync","CONTROL_BASE_URL");
WECHAT_ROOT_URL = weaver.file.Prop.getPropValue("nccsync","WECHAT_ROOT_URL");
APPKEY = weaver.file.Prop.getPropValue("nccsync","APPKEY");