2020-09-18-x
Xplorist Lv6

2020-09-18

todo-list

  • 修改ePDMWeb的端口为8080,修改231.103上的Nginx端口为80
  • 叫运维帮忙修改10.244.168.180上关于10.244.231.103上的项目代理

record-list

  • 测试使用nginx来将工管系统中的页面脱离出来

  • 同一个nginx中的静态资源配置和单页应用访问配置不能共存

  • 用nginx作网关,通过反向代理将耗材模块的前后端分离,并从工管系统中脱离出来

  • 以后的新模块都不用在老工管系统里面开发了,现在可以通过反向代理一个新项目来整合到工管系统中去

  • 耗材模块都放在阶段下面,分成四个模块,前端为Vue cli项目,然后四个路由,工管系统中添加四个路由地址就行了。

  • 分析NPI阶段打样表数据结构

  • 创建耗材需求(新)打样模块的数据表

  • IntelliJ IDEA的Generate POJOs.groovy生成JPA Entity

  • IDEA自定义Generate POJOs.groovy生成实体 - JPA+Lombok的模板

  • 使用 IntelliJ IDEA 快速生成项目代码

  • Generate POJOs4JPA.groovy

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187

    import com.intellij.database.model.DasTable
    import com.intellij.database.model.ObjectKind
    import com.intellij.database.util.Case
    import com.intellij.database.util.DasUtil

    import java.sql.Date
    import java.time.LocalDateTime
    import java.time.format.DateTimeFormatter


    /*
    * Available context bindings:
    * SELECTION Iterable<DasObject>
    * PROJECT project
    * FILES files helper
    */

    packageName = "com.sample;"

    typeMapping = [
    (~/(?i)int|tinyint|smallint|mediumint/) : "Integer",
    (~/(?i)bool|bit/) : "Boolean",
    (~/(?i)float|double|decimal|real|number/): "BigDecimal",
    (~/(?i)datetime|timestamp|date|time/) : "Date",
    (~/(?i)binary|bfile|raw|image/) : "InputStream",
    (~/(?i)blob|clob/) : "lob",
    (~/(?i)/) : "String"
    ]


    FILES.chooseDirectoryAndSave("Choose directory", "Choose where to store generated files") { dir ->
    SELECTION.filter { it instanceof DasTable && it.getKind() == ObjectKind.TABLE }.each { generate(it, dir) }
    }


    def generate(table, dir) {
    def className = javaName(table.getName(), true) + "Entity"
    def fields = calcFields(table)
    packageName = getPackageName(dir)
    // 解决乱码问题
    new File(dir, className + ".java").withPrintWriter("utf-8") { out -> generate(out, className, fields, table) }
    }


    // 获取包所在文件夹路径
    def getPackageName(dir) {
    return dir.toString().replaceAll("\\\\", ".").replaceAll("/", ".").replaceAll("^.*src(\\.main\\.java\\.)?", "") + ";"
    }

    def generate(out, className, fields, table) {
    out.println "package $packageName"
    out.println ""
    out.println "import javax.persistence.*;"
    out.println "import java.io.Serializable;"
    out.println "import lombok.*;"

    Set types = new HashSet()

    fields.each() {
    types.add(it.type)
    }

    if (types.contains("BigDecimal")) {
    out.println "import java.math.BigDecimal;"
    }

    if (types.contains("Date")) {
    out.println "import java.util.Date;"
    out.println "import org.hibernate.annotations.GenericGenerator;"
    out.println "import org.hibernate.annotations.UpdateTimestamp;"
    out.println "import org.hibernate.annotations.CreationTimestamp;"
    out.println "import com.fasterxml.jackson.annotation.JsonFormat;"
    }

    if (types.contains("InputStream")) {
    out.println "import java.io.InputStream;"
    }
    out.println ""
    out.println "/**\n" +
    " * @Author: C3005579 xbr\n" +
    " * @Date: " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm")) +"\n"+
    " */"
    out.println "@Data"
    out.println "@Entity"
    out.println "@Table (name = \"" + table.getName() + "\")"
    out.println "@Builder"
    out.println "@NoArgsConstructor"
    out.println "@AllArgsConstructor"
    out.println "public class $className implements Serializable {"
    out.println ""
    out.println genSerialID()
    fields.each() {
    out.println ""
    // 输出注释
    if (isNotEmpty(it.commoent)) {
    out.println "\t/**${it.commoent.toString()}*/"
    }
    // 输出Java Annotation(注解)
    if (it.annos != "") out.println " ${it.annos}"
    // 输出成员变量
    out.println "\tprivate ${it.type} ${it.name};"
    }
    out.println ""
    out.println "}"
    }

    def calcFields(table) {
    DasUtil.getColumns(table).reduce([]) { fields, col ->
    def spec = Case.LOWER.apply(col.getDataType().getSpecification())

    def typeStr = typeMapping.find { p, t -> p.matcher(spec).find() }.value
    def comm = [
    colName : col.getName(),
    name : javaName(col.getName(), false),
    type : typeStr,
    commoent: col.getComment(),
    annos : "\t@Column(name = \"" + col.getName() + "\" )"]
    if ("id".equals(Case.LOWER.apply(col.getName()))){
    comm.annos = "\t@Id\n"
    //自增主键需要
    comm.annos += "\t@GenericGenerator(name = \"idGen\", strategy = \"uuid\")\n"
    comm.annos += "\t@GeneratedValue(generator = \"idGen\")\n"
    comm.annos += "\t@Column(name = \"id\")"
    }
    if ("create_time".equals(Case.LOWER.apply(col.getName()))){
    comm.annos += "\n\t@CreationTimestamp"
    comm.annos += "\n\t@Temporal(TemporalType.TIMESTAMP)"
    comm.annos += "\n\t@JsonFormat(pattern = \"yyyy-MM-dd HH:mm:ss\",timezone=\"GMT+8\")"
    }
    if ("update_time".equals(Case.LOWER.apply(col.getName()))){
    comm.annos += "\n\t@UpdateTimestamp"
    comm.annos += "\n\t@Temporal(TemporalType.TIMESTAMP)"
    comm.annos += "\n\t@JsonFormat(pattern = \"yyyy-MM-dd HH:mm:ss\",timezone=\"GMT+8\")"
    }
    if ("delete_time".equals(Case.LOWER.apply(col.getName()))){
    comm.annos += "\n\t@JsonFormat(pattern = \"yyyy-MM-dd HH:mm:ss\",timezone=\"GMT+8\")"
    }
    if("lob".equals(typeStr)) {
    comm.type = "String";
    comm.annos = "\t@Lob\n"
    comm.annos += "\t@Basic(fetch = FetchType.EAGER)\n"
    comm.annos += "\t@Column(name = \"" + col.getName() + "\", columnDefinition = \"CLOB\")"
    }
    fields += [comm]
    }
    }

    def javaName(str, capitalize) {
    def s = com.intellij.psi.codeStyle.NameUtil.splitNameIntoWords(str)
    .collect { Case.LOWER.apply(it).capitalize() }
    .join("")
    .replaceAll(/[^\p{javaJavaIdentifierPart}[_]]/, "_")
    // 这里是因为我的表都是以T_命名的,所以需要处理去掉生成类名时的开头的T,如果不用处理注释掉下面这句代码
    //s = s[1..s.size() - 1]
    capitalize || s.length() == 1? s : Case.LOWER.apply(s[0]) + s[1..-1]
    }

    def fileName(str, capitalize) {
    def s = com.intellij.psi.codeStyle.NameUtil.splitNameIntoWords(str)
    .collect { Case.LOWER.apply(it).capitalize() }
    .join("")
    .replaceAll(/[^\p{javaJavaIdentifierPart}[_]]/, "_")
    capitalize || s.length() == 1? s : Case.LOWER.apply(s[0]) + s[1..-1]
    }

    def isNotEmpty(content) {
    return content != null && content.toString().trim().length() > 0
    }

    static String changeStyle(String str, boolean toCamel) {
    if (!str || str.size() <= 1)
    return str

    if (toCamel) {
    String r = str.toLowerCase().split('_').collect { cc -> Case.LOWER.apply(cc).capitalize() }.join('')
    return r[0].toLowerCase() + r[1..-1]
    } else {
    str = str[0].toLowerCase() + str[1..-1]
    return str.collect { cc -> ((char) cc).isUpperCase() ? '_' + cc.toLowerCase() : cc }.join('')
    }
    }

    static String genSerialID() {
    return "\tprivate static final long serialVersionUID = " + Math.abs(new Random().nextLong()) + "L;";
    }

home-redcord-list

  • 为routine_record repository建立hexo 显示,这个要实现貌似比较复杂,有必要吗?貌似不是很需要,只要把routine_record中的内容移植到knowledge-library-blog下就行了。
    况且,routine_record创建的目的就是为了处理knowledge-library-blog不完善的情况。统一一下也是好的吧。
 评论