safety-eval-service/scripts/gen-p2-nodes.py

296 lines
13 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
"""Generate P2 eight-node COLA boilerplate files."""
import os
ROOT = os.path.join(os.path.dirname(__file__), "..")
TABLES = {
"EvalRiskAnalysis": {
"table": "eval_risk_analysis",
"fields": [
("Long", "orgId"), ("Long", "projectId"), ("LocalDate", "analysisDate"),
("String", "evalTypeCode"), ("String", "evalTypeName"), ("String", "industryCode"),
("String", "industryName"), ("String", "evalScope"), ("Integer", "inBizScopeFlag"),
("String", "unitOverview"), ("String", "industryRiskDesc"), ("Integer", "staffMatchCode"),
("Integer", "needExpertCode"), ("Integer", "capabilityCode"), ("Integer", "feasibleCode"),
("Integer", "economicCode"), ("Integer", "riskLevelCode"), ("String", "riskLevelName"),
("Integer", "signContractCode"), ("String", "conclusionContent"), ("String", "approverName"),
("Integer", "approvalOpinionCode"), ("String", "approvalOpinionName"), ("LocalDate", "approvalDate"),
("Integer", "statusCode"), ("String", "statusName"),
],
"not_found": "EVAL_RISK_NOT_FOUND",
"node": "NODE_01",
},
"EvalRiskParticipant": {
"table": "eval_risk_participant",
"fields": [
("Long", "orgId"), ("Long", "projectId"), ("Long", "riskId"),
("Long", "personnelId"), ("String", "personnelName"), ("String", "deptName"),
("Integer", "signStatusCode"), ("String", "signStatusName"), ("String", "signFileUrl"),
("Integer", "sortOrder"),
],
"not_found": "EVAL_RISK_NOT_FOUND",
"node": "NODE_01",
"list_by": "riskId",
},
"EvalContract": {
"table": "eval_contract",
"fields": [
("Long", "orgId"), ("Long", "projectId"), ("String", "orgName"), ("String", "contractNo"),
("String", "projectName"), ("String", "projectIntro"), ("Long", "amountFen"),
("String", "projectTypeCode"), ("String", "projectTypeName"), ("String", "riskSummary"),
("String", "projectRegion"), ("String", "projectAddress"), ("LocalDate", "contractStartDate"),
("LocalDate", "contractEndDate"), ("String", "evalTypeCode"), ("String", "evalTypeName"),
("Integer", "toxicFlag"), ("Integer", "precursorFlag"), ("Integer", "crossProvinceFlag"),
("String", "businessScope"), ("String", "enterpriseName"), ("String", "industryCategory"),
("String", "officeAddress"), ("String", "creditCode"), ("String", "postCode"),
("String", "enterprisePhone"), ("String", "fax"), ("String", "legalPerson"),
("String", "contactName"), ("Integer", "staffCount"), ("String", "scanFileUrl"),
("Integer", "statusCode"), ("String", "statusName"),
],
"not_found": "EVAL_CONTRACT_NOT_FOUND",
"node": "NODE_02",
},
"EvalTeam": {
"table": "eval_team",
"fields": [
("Long", "orgId"), ("Long", "projectId"), ("Long", "leaderPersonnelId"),
("String", "leaderName"), ("Long", "controlPersonnelId"), ("String", "controlName"),
("Integer", "memberCount"), ("Integer", "statusCode"), ("String", "statusName"),
("LocalDateTime", "finishTime"),
],
"not_found": "EVAL_TEAM_NOT_FOUND",
"node": "NODE_03",
},
"EvalSurvey": {
"table": "eval_survey",
"fields": [
("Long", "orgId"), ("Long", "projectId"), ("LocalDate", "planSurveyDate"),
("String", "surveyPlace"), ("Integer", "noticeDoneFlag"), ("Integer", "inspectDoneFlag"),
("Integer", "rectifyDoneFlag"), ("Integer", "enterpriseDoneFlag"), ("Integer", "reviewDoneFlag"),
("Integer", "statusCode"), ("String", "statusName"),
],
"not_found": "EVAL_SURVEY_NOT_FOUND",
"node": "NODE_04",
},
"EvalSurveyNotice": {
"table": "eval_survey_notice",
"fields": [
("Long", "orgId"), ("Long", "projectId"), ("Long", "surveyId"),
("String", "noticeContent"), ("String", "memberSnapshot"), ("String", "stampFileUrl"),
("Integer", "statusCode"), ("String", "statusName"),
],
"not_found": "EVAL_SURVEY_NOT_FOUND",
"node": "NODE_04",
"unique_by": "surveyId",
},
"EvalSurveyCheckin": {
"table": "eval_survey_checkin",
"fields": [
("Long", "orgId"), ("Long", "projectId"), ("Long", "surveyId"),
("Long", "personnelId"), ("String", "personnelName"),
("Integer", "taskStatusCode"), ("String", "taskStatusName"), ("LocalDateTime", "planTime"),
("Integer", "checkinTypeCode"), ("String", "checkinTypeName"), ("LocalDateTime", "checkinTime"),
("java.math.BigDecimal", "longitude"), ("java.math.BigDecimal", "latitude"),
("String", "address"), ("Integer", "facePassFlag"), ("String", "photoUrls"),
("String", "signImageUrl"),
],
"not_found": "EVAL_SURVEY_NOT_FOUND",
"node": "NODE_04",
"list_by": "surveyId",
},
"EvalSurveyAttach": {
"table": "eval_survey_attach",
"fields": [
("Long", "orgId"), ("Long", "projectId"), ("Long", "surveyId"),
("String", "attachTypeCode"), ("String", "attachTypeName"), ("String", "fileName"),
("String", "fileUrl"), ("Integer", "reviewResultCode"), ("String", "reviewResultName"),
("String", "reviewContent"),
],
"not_found": "EVAL_SURVEY_NOT_FOUND",
"node": "NODE_04",
"list_by": "surveyId",
},
"EvalReportDraft": {
"table": "eval_report_draft",
"fields": [
("Long", "orgId"), ("Long", "projectId"), ("Integer", "draftVersionNo"),
("String", "templateCode"), ("String", "templateName"), ("String", "contentUrl"),
("String", "hintContent"), ("Integer", "statusCode"), ("String", "statusName"),
],
"not_found": "EVAL_DRAFT_NOT_FOUND",
"node": "NODE_05",
},
"EvalInternalReview": {
"table": "eval_internal_review",
"fields": [
("Long", "orgId"), ("Long", "projectId"), ("Long", "draftId"),
("Long", "reviewerPersonnelId"), ("String", "reviewerName"),
("Integer", "resultCode"), ("String", "resultName"), ("String", "opinionContent"),
("LocalDateTime", "reviewTime"), ("Integer", "statusCode"), ("String", "statusName"),
],
"not_found": "EVAL_INTERNAL_REVIEW_NOT_FOUND",
"node": "NODE_06",
},
"EvalTechReview": {
"table": "eval_tech_review",
"fields": [
("Long", "orgId"), ("Long", "projectId"), ("Long", "draftId"),
("Long", "reviewerPersonnelId"), ("String", "reviewerName"),
("Integer", "resultCode"), ("String", "resultName"), ("String", "opinionContent"),
("LocalDateTime", "reviewTime"), ("Integer", "statusCode"), ("String", "statusName"),
],
"not_found": "EVAL_TECH_REVIEW_NOT_FOUND",
"node": "NODE_07",
},
"EvalProcessControl": {
"table": "eval_process_control",
"fields": [
("Long", "orgId"), ("Long", "projectId"), ("Long", "controllerPersonnelId"),
("String", "controllerName"), ("Integer", "precheckPassFlag"),
("Integer", "resultCode"), ("String", "resultName"), ("String", "opinionContent"),
("Integer", "archiveFlag"), ("LocalDateTime", "controlTime"),
("Integer", "statusCode"), ("String", "statusName"),
],
"not_found": "EVAL_PROCESS_NOT_FOUND",
"node": "NODE_08",
},
"EvalSignTask": {
"table": "eval_sign_task",
"fields": [
("Long", "orgId"), ("Long", "projectId"), ("String", "nodeCode"), ("String", "nodeName"),
("String", "bizTypeCode"), ("String", "bizTypeName"), ("Long", "bizRefId"),
("Long", "signerPersonnelId"), ("String", "signerName"), ("String", "taskTitle"),
("Integer", "taskStatusCode"), ("String", "taskStatusName"), ("LocalDateTime", "expireTime"),
],
"not_found": "EVAL_SIGN_TASK_NOT_FOUND",
"node": "SIGN",
},
"EvalSignRecord": {
"table": "eval_sign_record",
"fields": [
("Long", "orgId"), ("Long", "projectId"), ("Long", "signTaskId"),
("Long", "signerPersonnelId"), ("String", "signerName"), ("String", "signImageUrl"),
("LocalDateTime", "signTime"), ("Integer", "clientTypeCode"), ("String", "clientTypeName"),
],
"not_found": "EVAL_SIGN_RECORD_NOT_FOUND",
"node": "SIGN",
"list_by": "signTaskId",
},
"EvalReport": {
"table": "eval_report",
"fields": [
("Long", "orgId"), ("Long", "projectId"), ("Long", "customerId"),
("String", "reportNo"), ("String", "reportName"), ("Integer", "reportYear"),
("String", "evalTypeCode"), ("String", "evalTypeName"), ("String", "businessScope"),
("String", "fileUrl"), ("String", "fileName"), ("Integer", "publicFlag"),
("Integer", "completeFlag"), ("Integer", "reportStatusCode"), ("String", "reportStatusName"),
("LocalDateTime", "archiveTime"),
],
"not_found": "EVAL_PROJECT_NOT_FOUND",
"internal": True,
},
}
COMMON_DO_FIELDS = [
("String", "deleteEnum"), ("String", "remarks"), ("String", "createName"), ("String", "updateName"),
("Long", "tenantId"), ("Integer", "version"), ("LocalDateTime", "createTime"),
("LocalDateTime", "updateTime"), ("Long", "createId"), ("Long", "updateId"), ("String", "env"),
]
def camel_to_snake(name):
import re
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
def write(path, content):
full = os.path.join(ROOT, path.replace("/", os.sep))
os.makedirs(os.path.dirname(full), exist_ok=True)
with open(full, "w", encoding="utf-8", newline="\n") as f:
f.write(content)
def gen_entity(name, fields):
imports = set()
for t, _ in fields + COMMON_DO_FIELDS:
if t.startswith("java."):
imports.add(f"import {t};")
elif t == "LocalDate":
imports.add("import java.time.LocalDate;")
elif t == "LocalDateTime":
imports.add("import java.time.LocalDateTime;")
imp = "\n".join(sorted(imports))
lines = [f"package org.qinan.safetyeval.domain.entity;\n", imp, "\n\n@Data\n", f"public class {name}Entity {{\n\n", " private Long id;\n"]
for t, f in fields:
lines.append(f" private {t.replace('java.math.', '')} {f};\n")
for t, f in COMMON_DO_FIELDS:
lines.append(f" private {t.replace('java.math.', '')} {f};\n")
lines.append("}\n")
write(f"safety-eval-domain/src/main/java/org/qinan/safetyeval/domain/entity/{name}Entity.java",
"".join(["import lombok.Data;\n\n"] + lines[1:]))
def gen_do(name, table, fields):
imports = ["import com.baomidou.mybatisplus.annotation.TableName;", "import lombok.Data;"]
for t, _ in fields + COMMON_DO_FIELDS:
if t.startswith("java."):
imports.append(f"import {t};")
elif t in ("LocalDate", "LocalDateTime"):
imports.append(f"import java.time.{t};")
body = "\n".join(imports) + f"\n\n@Data\n@TableName(\"{table}\")\npublic class {name}DO {{\n\n private Long id;\n"
for t, f in fields + COMMON_DO_FIELDS:
body += f" private {t.replace('java.math.', '')} {f};\n"
body += "}\n"
write(f"safety-eval-infrastructure/src/main/java/org/qinan/safetyeval/infrastructure/dataobject/{name}DO.java", body)
def gen_mapper(name):
content = f"""package org.qinan.safetyeval.infrastructure.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.qinan.safetyeval.infrastructure.dataobject.{name}DO;
@Mapper
public interface {name}Mapper extends BaseMapper<{name}DO> {{
}}
"""
write(f"safety-eval-infrastructure/src/main/java/org/qinan/safetyeval/infrastructure/mapper/{name}Mapper.java", content)
def gen_gateway(name):
content = f"""package org.qinan.safetyeval.domain.gateway;
import org.qinan.safetyeval.domain.entity.{name}Entity;
import org.qinan.safetyeval.domain.query.{name}Query;
import org.qinan.safetyeval.domain.query.PageResult;
import java.util.List;
public interface {name}Gateway {{
{name}Entity save({name}Entity entity);
{name}Entity get(Long id);
{name}Entity modify({name}Entity entity);
void delete(Long id);
{name}Entity getByProjectId(Long projectId, Long orgId);
List<{name}Entity> list({name}Query query);
PageResult<{name}Entity> page({name}Query query);
int nextDraftVersionNo(Long projectId, Long orgId);
}}
"""
# simplify gateway - not all need all methods; we'll trim in gateway impl
write(f"safety-eval-domain/src/main/java/org/qinan/safetyeval/domain/gateway/{name}Gateway.java", content)
print("Generator scaffold - run manual implementation for business logic")
for n in TABLES:
cfg = TABLES[n]
gen_entity(n, cfg["fields"])
gen_do(n, cfg["table"], cfg["fields"])
gen_mapper(n)
gen_gateway(n)
print(f"Generated {n}")