Prechádzať zdrojové kódy

优化删除表单数据,存在子表且子表没有数据,删除异常问题

大数据与最优化研究所 3 mesiacov pred
rodič
commit
8abac19bac

+ 24 - 8
src/main/java/com/xjrsoft/module/form/service/impl/FormExecuteServiceImpl.java

@@ -655,10 +655,16 @@ public class FormExecuteServiceImpl implements IFormExecuteService {
                             //删除子表单数据
                             Entity childDeleteWhere = Entity.create(tableConfig.getTableName()).
                                     set(childTableConfig.get().getRelationField(), keyValues);
-                            Boolean result = SqlRunnerAdapter.db().dynamicDelete(childTableConfig.get().getTableName(), childDeleteWhere);
-                            // TODO 当子表没有添加数据的时候,删除结果为false。
-                            if (!result) {
-                                throw new MyException("删除数据失败");
+                            // 查询是否有子表数据,如果有就删除,没有返回
+                            String keyValuesStr = "(" + String.join(",", keyValues) + ")";
+
+                            long count = SqlRunnerAdapter.db().selectCount("select count(*) from " + childTableConfig.get().getTableName() + " where " + childTableConfig.get().getRelationField() + " in " + keyValuesStr);
+
+                            if(count > 0){
+                                Boolean result = SqlRunnerAdapter.db().dynamicDelete(childTableConfig.get().getTableName(), childDeleteWhere);
+                                if (!result) {
+                                    throw new MyException("删除数据失败");
+                                }
                             }
                         }
                     }
@@ -683,11 +689,21 @@ public class FormExecuteServiceImpl implements IFormExecuteService {
                             //删除子表单数据
                             Entity childDeleteWhere = Entity.create(tableConfig.getTableName()).
                                     set(childTableConfig.get().getRelationField(), keyValues);
-                            Boolean result = SqlRunnerAdapter.db().dynamicDelete(tableConfig.getTableName(), childDeleteWhere);
-                            if (!result) {
-                                throw new MyException("删除数据失败");
+//                            Boolean result = SqlRunnerAdapter.db().dynamicDelete(tableConfig.getTableName(), childDeleteWhere);
+//                            if (!result) {
+//                                throw new MyException("删除数据失败");
+//                            }
+                            // 查询是否有子表数据,如果有就删除,没有返回
+                            String keyValuesStr = "(" + String.join(",", keyValues) + ")";
+
+                            long count = SqlRunnerAdapter.db().selectCount("select count(*) from " + childTableConfig.get().getTableName() + " where " + childTableConfig.get().getRelationField() + " in " + keyValuesStr);
+
+                            if(count > 0){
+                                Boolean result = SqlRunnerAdapter.db().dynamicDelete(childTableConfig.get().getTableName(), childDeleteWhere);
+                                if (!result) {
+                                    throw new MyException("删除数据失败");
+                                }
                             }
-
                         }
                     }
                     //删除主表数据

+ 1 - 0
src/main/resources/sqlScript/20240717_sql.sql

@@ -127,6 +127,7 @@ create table billing_reimbursement
     applicant_id         bigint         NOT NULL comment '申请人id',
     applicant_name       varchar(255)   NOT NULL comment '申请人',
     department_manger_id bigint         NULL comment '所在部门主任id',
+    department_head_id   bigint         NULL comment '所在分管领导id',
     aply_time            datetime       NOT NULL comment '申请时间',
     gotrip_time          date           NOT NULL comment '出差开始日期',
     end_time             date           NOT NULL comment '出差结束日期',

+ 123 - 25
src/main/resources/sqlScript/20240723_sql.sql

@@ -1,32 +1,31 @@
-
 -- 学生消费数据
 DROP TABLE IF EXISTS `student_consume_date`;
 CREATE TABLE student_consume_date
 (
-    id               bigint      not null comment '主键编号' primary key,
-    create_user_id   bigint          null comment '创建人',
-    create_date      datetime        null comment '创建时间',
-    modify_user_id   bigint          null comment '修改人',
-    modify_date      datetime        null comment '修改时间',
-    delete_mark      int         not null comment '删除标记',
-    enabled_mark     int         not null comment '有效标志',
-    sort_code        int             null comment '序号',
-
-    class_id      bigint     not null comment '班级id',
-    class_name       VARCHAR(256)     not null comment '班级名称',
-    student_id       bigint           not null comment '学生id',
-    student_name     VARCHAR(256)     null comment '学生姓名',
-    student_user_name       VARCHAR(256)     null comment '学生学号',
-    consume_time     datetime         not null comment '消费时间',
-    consume_money    DECIMAL(10, 2)   not null comment '消费金额',
-    consume_type     VARCHAR(16)     not null comment '消费类型',
-    grade_name       VARCHAR(256)     null comment '年级名称',
-    grade_id       VARCHAR(256)     null comment '年级id',
-    major_name       VARCHAR(256)     null comment '专业名称',
-    major_id       VARCHAR(256)     null comment '专业id'
-
-)ENGINE = InnoDB
- DEFAULT CHARSET = utf8mb4
+    id                bigint         NOT NULL COMMENT '主键编号' PRIMARY KEY,
+    create_user_id    bigint         NULL COMMENT '创建人',
+    create_date       datetime       NULL COMMENT '创建时间',
+    modify_user_id    bigint         NULL COMMENT '修改人',
+    modify_date       datetime       NULL COMMENT '修改时间',
+    delete_mark       int            NOT NULL COMMENT '删除标记',
+    enabled_mark      int            NOT NULL COMMENT '有效标志',
+    sort_code         int            NULL COMMENT '序号',
+
+    class_id          bigint         NOT NULL COMMENT '班级id',
+    class_name        VARCHAR(256)   NOT NULL COMMENT '班级名称',
+    student_id        bigint         NOT NULL COMMENT '学生id',
+    student_name      VARCHAR(256)   NULL COMMENT '学生姓名',
+    student_user_name VARCHAR(256)   NULL COMMENT '学生学号',
+    consume_time      datetime       NOT NULL COMMENT '消费时间',
+    consume_money     DECIMAL(10, 2) NOT NULL COMMENT '消费金额',
+    consume_type      VARCHAR(16)    NOT NULL COMMENT '消费类型',
+    grade_name        VARCHAR(256)   NULL COMMENT '年级名称',
+    grade_id          VARCHAR(256)   NULL COMMENT '年级id',
+    major_name        VARCHAR(256)   NULL COMMENT '专业名称',
+    major_id          VARCHAR(256)   NULL COMMENT '专业id'
+
+) ENGINE = InnoDB
+  DEFAULT CHARSET = utf8mb4
     COMMENT ='学生消费数据';
 
 # 消费类型 consume_type
@@ -35,3 +34,102 @@ CREATE TABLE student_consume_date
 -- 超市        consume_type_2       consume_type_2
 -- 图书馆      consume_type_3       consume_type_3
 -- 其他        consume_type_4       consume_type_4
+
+ALTER TABLE ods_zzxxgkjcsj
+    ADD provincial_code varchar(6) NOT NULL COMMENT '省机构编码' AFTER enabled_mark;
+
+ALTER TABLE ods_zzxxgkjcsj
+    ADD provincial_name varchar(60) NOT NULL COMMENT '省机构名称' AFTER provincial_code;
+
+ALTER TABLE ods_zzxxgkjcsj
+    ADD municipal_code varchar(6) NOT NULL COMMENT '市机构编码' AFTER provincial_name;
+
+ALTER TABLE ods_zzxxgkjcsj
+    ADD municipal_name varchar(60) NOT NULL COMMENT '市机构名称' AFTER municipal_code;
+
+ALTER TABLE ods_zzxxgkjcsj
+    ADD district_and_county_code varchar(6) NOT NULL COMMENT '区县机构编码' AFTER municipal_name;
+
+ALTER TABLE ods_zzxxgkjcsj
+    ADD district_and_county_name varchar(60) NOT NULL COMMENT '区县机构名称' AFTER district_and_county_code;
+
+ALTER TABLE ods_zzxxgkjcsj
+    DROP COLUMN location;
+
+ALTER TABLE ods_zzxxgkjcsj
+    ADD existing_school_staff_num int NOT NULL COMMENT '现有教职工总数' AFTER establish_date;
+
+ALTER TABLE ods_zzxxgkjcsj
+    MODIFY supervisory_department varchar(500) NULL COMMENT '学校主管部门' AFTER school_type;
+
+ALTER TABLE ods_zzxxgkjcsj
+    ADD existing_student_num int NOT NULL COMMENT '现有学生数' AFTER existing_school_staff_num;
+
+ALTER TABLE ods_zzxxgkjcsj
+    ADD set_up_major_num int NOT NULL COMMENT '本校开设专业数' AFTER existing_student_num;
+
+ALTER TABLE ods_zzxxgkjcsj
+    ADD characteristic_applications_num int NOT NULL COMMENT '学校特色应用数' AFTER set_up_major_num;
+
+ALTER TABLE ods_zzxxgkjcsj
+    MODIFY exit_bandwidth varchar(500) NOT NULL COMMENT '学校园出口带宽';
+
+ALTER TABLE ods_zzxxgkjcsj
+    MODIFY backbone_bandwidth varchar(500) NOT NULL COMMENT '校园主干网带宽';
+
+ALTER TABLE ods_zzxxgkjcsj
+    MODIFY wired_access int NOT NULL COMMENT '有线网络接入数';
+
+ALTER TABLE ods_zzxxgkjcsj
+    MODIFY wireless_access int NOT NULL COMMENT '无线网络接入数';
+
+ALTER TABLE ods_zzxxgkjcsj
+    MODIFY multimedia_classrooms int NOT NULL COMMENT '多媒体教室数';
+
+ALTER TABLE ods_zzxxgkjcsj
+    MODIFY is_double_excellence varchar(500) NOT NULL COMMENT '是否双优学校';
+
+ALTER TABLE ods_zzxxgkjcsj
+    MODIFY exit_bandwidth int NOT NULL COMMENT '学校园出口带宽';
+
+ALTER TABLE ods_zzxxgkjcsj
+    MODIFY backbone_bandwidth int NOT NULL COMMENT '校园主干网带宽';
+
+ALTER TABLE ods_zzxxgkjcsj
+    ADD sort_code int NULL COMMENT '序号' AFTER enabled_mark;
+
+ALTER TABLE base_student_scholarship_applicant
+    ADD COLUMN `identification_number` varchar(256) NOT NULL COMMENT '身份证号',
+    ADD COLUMN `base_student_scholarship_name` varchar(256) NOT NULL COMMENT '申请奖助学金名称',
+    ADD COLUMN `personal_circumstances` longtext NOT NULL COMMENT '描述个人情况',
+    ADD COLUMN `application_reason` longtext NOT NULL COMMENT '阐述申请理由';
+
+alter table ods_zzxxgkjcsj
+    modify create_date datetime null comment '创建时间';
+
+alter table ods_zzxxgkjcsj
+    modify modify_date datetime null comment '修改日期';
+
+alter table ods_zzxxgkjcsj
+    modify delete_mark int not null comment '删除标记';
+
+alter table ods_zzxxgkjcsj
+    modify enabled_mark int not null comment '有效标记';
+
+alter table ods_zzxxgkjcsj
+    modify school_name varchar(60) null comment '学校名称';
+
+alter table ods_zzxxgkjcsj
+    modify school_code varchar(10) null comment '学校代码';
+
+alter table ods_zzxxgkjcsj
+    modify school_institution_code varchar(18) null comment '学校机构代码';
+
+alter table ods_zzxxgkjcsj
+    modify supervisory_department varchar(65) null comment '学校主管部门';
+
+alter table ods_zzxxgkjcsj
+    modify organizer_name varchar(60) null comment '学校举办者名称';
+
+ALTER TABLE base_student_scholarship_applicant
+    ADD COLUMN `teacher_id` BIGINT NOT NULL COMMENT '班主任id';