24	================================
25	import 'com.itam.util.UuidUtil';
26
27	var assigned_to = body.assigned_to;
28	var category_id = body.category_id;
29	var expiration_date = body.expiration_date;
30	var id = body.id;
31	var license_key = body.license_key;
32	var licensed_to_email = body.licensed_to_email;
33	var licensed_to_name = body.licensed_to_name;
34	var manufacturer_id = body.manufacturer_id;
35	var min_qty = body.min_qty;
36	var name = body.name;
37	var notes = body.notes;
38	var order_number = body.order_number;
39	var purchase_cost = body.purchase_cost;
40	var purchase_date = body.purchase_date;
41	var supplier_id = body.supplier_id;
42	var termination_date = body.termination_date;
43	var total_seats = body.total_seats;
44	var operatorName = body.operator_name != null ? body.operator_name : 'system';
45	var operatorId = body.operator_id;
46	assert body.name != null && body.name != '' : 400, '软件名称不能为空';
47	assert body.license_key != null && body.license_key != '' : 400, '序列号/密钥不能为空';
48
49	if (body.id != null) {
50	    var old = db.selectOne("""
51	        select * from itam_licenses where id = #{id} and deleted = 0
52	    """);
53
54	    db.update("""
55	    update itam_licenses
56	    <set>
57	        <if test="name != null">name = #{name},</if>
58	        license_key = #{license_key},
59	        total_seats = #{total_seats},
60	        manufacturer_id = #{manufacturer_id},
61	        category_id = #{category_id},
62	        assigned_to = #{assigned_to},
63	        min_qty = #{min_qty},
64	        licensed_to_name = #{licensed_to_name},
65	        licensed_to_email = #{licensed_to_email},
66	        supplier_id = #{supplier_id},
67	        order_number = #{order_number},
68	        purchase_cost = #{purchase_cost},
69	        purchase_date = #{purchase_date},
70	        expiration_date = #{expiration_date},
71	        termination_date = #{termination_date},
72	        notes = #{notes},
73	        update_time = now()
74	    </set>
75	    where id = #{id} and deleted = 0
76	    """);
77
78	    // 记录变更
79	    if (old != null) {
80	        var trackFields = ['name', 'license_key', 'total_seats', 'manufacturer_id', 'category_id', 'assigned_to', 'min_qty', 'licensed_to_name', 'licensed_to_email', 'supplier_id', 'order_number', 'purchase_cost', 'purchase_date', 'expiration_date', 'termination_date', 'notes'];
81	        for (field in trackFields) {
82	            var oldVal = old[field] != null ? '' + old[field] : null;
83	            var newVal = body[field] != null ? '' + body[field] : null;
84	            if (oldVal != newVal) {
85	                var changeId = UuidUtil.v7();
86	                db.insert("""
87	                insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
88	                values (#{changeId}, 'license', #{id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())
89	                """);
90	            }
91	        }
92	    }
93
94	    return { id: body.id };
95	} else {
96	    var newId = UuidUtil.v7();
97	    db.insert("""
98	    insert into itam_licenses (id, name, license_key, total_seats, manufacturer_id, category_id, assigned_to, min_qty, licensed_to_name, licensed_to_email, supplier_id, order_number, purchase_cost, purchase_date, expiration_date, termination_date, notes, create_time, update_time)
99	    values (#{newId}, #{name}, #{license_key}, #{total_seats}, #{manufacturer_id}, #{category_id}, #{assigned_to}, #{min_qty}, #{licensed_to_name}, #{licensed_to_email}, #{supplier_id}, #{order_number}, #{purchase_cost}, #{purchase_date}, #{expiration_date}, #{termination_date}, #{notes}, now(), now())
100	    """);
101
102	    var changeId = UuidUtil.v7();
103	    db.insert("""
104	    insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
105	    values (#{changeId}, 'license', #{newId}, #{name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())
106	    """);
107
108	    return { id: newId };
109	}
110

================================
import 'com.itam.util.UuidUtil';

var assigned_to = body.assigned_to;
var category_id = body.category_id;
var expiration_date = body.expiration_date;
var id = body.id;
var license_key = body.license_key;
var licensed_to_email = body.licensed_to_email;
var licensed_to_name = body.licensed_to_name;
var manufacturer_id = body.manufacturer_id;
var min_qty = body.min_qty;
var name = body.name;
var notes = body.notes;
var order_number = body.order_number;
var purchase_cost = body.purchase_cost;
var purchase_date = body.purchase_date;
var supplier_id = body.supplier_id;
var termination_date = body.termination_date;
var total_seats = body.total_seats;
var operatorName = body.operator_name != null ? body.operator_name : 'system';
var operatorId = body.operator_id;
assert body.name != null && body.name != '' : 400, '软件名称不能为空';
assert body.license_key != null && body.license_key != '' : 400, '序列号/密钥不能为空';

if (body.id != null) {
    var old = db.selectOne("""
        select * from itam_licenses where id = #{id} and deleted = 0
    """);

    db.update("""
    update itam_licenses
    <set>
        <if test="name != null">name = #{name},</if>
        license_key = #{license_key},
        total_seats = #{total_seats},
        manufacturer_id = #{manufacturer_id},
        category_id = #{category_id},
        assigned_to = #{assigned_to},
        min_qty = #{min_qty},
        licensed_to_name = #{licensed_to_name},
        licensed_to_email = #{licensed_to_email},
        supplier_id = #{supplier_id},
        order_number = #{order_number},
        purchase_cost = #{purchase_cost},
        purchase_date = #{purchase_date},
        expiration_date = #{expiration_date},
        termination_date = #{termination_date},
        notes = #{notes},
        update_time = now()
    </set>
    where id = #{id} and deleted = 0
    """);

    // 记录变更
    if (old != null) {
        var trackFields = ['name', 'license_key', 'total_seats', 'manufacturer_id', 'category_id', 'assigned_to', 'min_qty', 'licensed_to_name', 'licensed_to_email', 'supplier_id', 'order_number', 'purchase_cost', 'purchase_date', 'expiration_date', 'termination_date', 'notes'];
        for (field in trackFields) {
            var oldVal = old[field] != null ? '' + old[field] : null;
            var newVal = body[field] != null ? '' + body[field] : null;
            if (oldVal != newVal) {
                var changeId = UuidUtil.v7();
                db.insert("""
                insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
                values (#{changeId}, 'license', #{id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())
                """);
            }
        }
    }

    return { id: body.id };
} else {
    var newId = UuidUtil.v7();
    db.insert("""
    insert into itam_licenses (id, name, license_key, total_seats, manufacturer_id, category_id, assigned_to, min_qty, licensed_to_name, licensed_to_email, supplier_id, order_number, purchase_cost, purchase_date, expiration_date, termination_date, notes, create_time, update_time)
    values (#{newId}, #{name}, #{license_key}, #{total_seats}, #{manufacturer_id}, #{category_id}, #{assigned_to}, #{min_qty}, #{licensed_to_name}, #{licensed_to_email}, #{supplier_id}, #{order_number}, #{purchase_cost}, #{purchase_date}, #{expiration_date}, #{termination_date}, #{notes}, now(), now())
    """);

    var changeId = UuidUtil.v7();
    db.insert("""
    insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
    values (#{changeId}, 'license', #{newId}, #{name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())
    """);

    return { id: newId };
}


24	================================
25	import 'com.itam.util.UuidUtil';
26
27	var floor_type = body.floor_type;
28	var floor_val = body.floor_val;
29	var id = body.id;
30	var months = body.months;
31	var name = body.name;
32	var remark = body.remark;
33	var stages = body.stages;
34	var status = body.status;
35	var operatorName = body.operator_name != null ? body.operator_name : 'system';
36	var operatorId = body.operator_id;
37	assert body.name != null && body.name != '' : 400, '折旧规则名称不能为空';
38	assert body.months != null && body.months > 0 : 400, '折旧月数必须大于0';
39
40	if (body.id != null) {
41	    var old = db.selectOne("""
42	        select * from itam_depreciations where id = #{id} and deleted = 0
43	    """);
44
45	    db.update("""
46	    update itam_depreciations
47	    <set>
48	        <if test="name != null">name = #{name},</if>
49	        status = #{status},
50	        months = #{months},
51	        floor_type = #{floor_type},
52	        floor_val = #{floor_val},
53	        stages = #{stages},
54	        remark = #{remark},
55	        update_time = now()
56	    </set>
57	    where id = #{id} and deleted = 0
58	    """);
59
60	    if (old != null) {
61	        var trackFields = ['name', 'status', 'months', 'floor_type', 'floor_val', 'stages', 'remark'];
62	        for (field in trackFields) {
63	            var oldVal = old[field] != null ? '' + old[field] : null;
64	            var newVal = body[field] != null ? '' + body[field] : null;
65	            if (oldVal != newVal) {
66	                var changeId = UuidUtil.v7();
67	                db.insert("""
68	                insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
69	                values (#{changeId}, 'depreciation', #{id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())
70	                """);
71	            }
72	        }
73	    }
74
75	    return { id: body.id };
76	} else {
77	    var newId = UuidUtil.v7();
78	    db.insert("""
79	    insert into itam_depreciations (id, name, status, months, floor_type, floor_val, stages, remark, create_time, update_time)
80	    values (#{newId}, #{name}, #{status}, #{months}, #{floor_type}, #{floor_val}, #{stages}, #{remark}, now(), now())
81	    """);
82
83	    var changeId = UuidUtil.v7();
84	    db.insert("""
85	    insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
86	    values (#{changeId}, 'depreciation', #{newId}, #{name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())
87	    """);
88
89	    return { id: newId };
90	}
91

================================
import 'com.itam.util.UuidUtil';

var floor_type = body.floor_type;
var floor_val = body.floor_val;
var id = body.id;
var months = body.months;
var name = body.name;
var remark = body.remark;
var stages = body.stages;
var status = body.status;
var operatorName = body.operator_name != null ? body.operator_name : 'system';
var operatorId = body.operator_id;
assert body.name != null && body.name != '' : 400, '折旧规则名称不能为空';
assert body.months != null && body.months > 0 : 400, '折旧月数必须大于0';

if (body.id != null) {
    var old = db.selectOne("""
        select * from itam_depreciations where id = #{id} and deleted = 0
    """);

    db.update("""
    update itam_depreciations
    <set>
        <if test="name != null">name = #{name},</if>
        status = #{status},
        months = #{months},
        floor_type = #{floor_type},
        floor_val = #{floor_val},
        stages = #{stages},
        remark = #{remark},
        update_time = now()
    </set>
    where id = #{id} and deleted = 0
    """);

    if (old != null) {
        var trackFields = ['name', 'status', 'months', 'floor_type', 'floor_val', 'stages', 'remark'];
        for (field in trackFields) {
            var oldVal = old[field] != null ? '' + old[field] : null;
            var newVal = body[field] != null ? '' + body[field] : null;
            if (oldVal != newVal) {
                var changeId = UuidUtil.v7();
                db.insert("""
                insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
                values (#{changeId}, 'depreciation', #{id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())
                """);
            }
        }
    }

    return { id: body.id };
} else {
    var newId = UuidUtil.v7();
    db.insert("""
    insert into itam_depreciations (id, name, status, months, floor_type, floor_val, stages, remark, create_time, update_time)
    values (#{newId}, #{name}, #{status}, #{months}, #{floor_type}, #{floor_val}, #{stages}, #{remark}, now(), now())
    """);

    var changeId = UuidUtil.v7();
    db.insert("""
    insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
    values (#{changeId}, 'depreciation', #{newId}, #{name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())
    """);

    return { id: newId };
}


24	================================
25	import 'com.itam.util.UuidUtil';
26
27	var assigned_to = body.assigned_to;
28	var cost = body.cost;
29	var end_date = body.end_date;
30	var id = body.id;
31	var name = body.name;
32	var notes = body.notes;
33	var offering_status = body.offering_status;
34	var service_number = body.service_number;
35	var start_date = body.start_date;
36	var supplier_id = body.supplier_id;
37	var operatorName = body.operator_name != null ? body.operator_name : 'system';
38	var operatorId = body.operator_id;
39	assert body.name != null && body.name != '' : 400, '服务名称不能为空';
40
41	if (body.id != null) {
42	    var old = db.selectOne("""
43	        select * from itam_offering where id = #{id} and deleted = 0
44	    """);
45
46	    db.update("""
47	    update itam_offering
48	    <set>
49	        <if test="name != null">name = #{name},</if>
50	        supplier_id = #{supplier_id},
51	        assigned_to = #{assigned_to},
52	        service_number = #{service_number},
53	        start_date = #{start_date},
54	        end_date = #{end_date},
55	        cost = #{cost},
56	        notes = #{notes},
57	        offering_status = #{offering_status},
58	        update_time = now()
59	    </set>
60	    where id = #{id} and deleted = 0
61	    """);
62
63	    if (old != null) {
64	        var trackFields = ['name', 'supplier_id', 'assigned_to', 'service_number', 'start_date', 'end_date', 'cost', 'notes', 'offering_status'];
65	        for (field in trackFields) {
66	            var oldVal = old[field] != null ? '' + old[field] : null;
67	            var newVal = body[field] != null ? '' + body[field] : null;
68	            if (oldVal != newVal) {
69	                var changeId = UuidUtil.v7();
70	                db.insert("""
71	                insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
72	                values (#{changeId}, 'offering', #{id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())
73	                """);
74	            }
75	        }
76	    }
77
78	    return { id: body.id };
79	} else {
80	    var newId = UuidUtil.v7();
81	    db.insert("""
82	    insert into itam_offering (id, name, supplier_id, assigned_to, service_number, start_date, end_date, cost, notes, offering_status, create_time, update_time)
83	    values (#{newId}, #{name}, #{supplier_id}, #{assigned_to}, #{service_number}, #{start_date}, #{end_date}, #{cost}, #{notes}, #{offering_status}, now(), now())
84	    """);
85
86	    var changeId = UuidUtil.v7();
87	    db.insert("""
88	    insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
89	    values (#{changeId}, 'offering', #{newId}, #{name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())
90	    """);
91
92	    return { id: newId };
93	}
94

================================
import 'com.itam.util.UuidUtil';

var assigned_to = body.assigned_to;
var cost = body.cost;
var end_date = body.end_date;
var id = body.id;
var name = body.name;
var notes = body.notes;
var offering_status = body.offering_status;
var service_number = body.service_number;
var start_date = body.start_date;
var supplier_id = body.supplier_id;
var operatorName = body.operator_name != null ? body.operator_name : 'system';
var operatorId = body.operator_id;
assert body.name != null && body.name != '' : 400, '服务名称不能为空';

if (body.id != null) {
    var old = db.selectOne("""
        select * from itam_offering where id = #{id} and deleted = 0
    """);

    db.update("""
    update itam_offering
    <set>
        <if test="name != null">name = #{name},</if>
        supplier_id = #{supplier_id},
        assigned_to = #{assigned_to},
        service_number = #{service_number},
        start_date = #{start_date},
        end_date = #{end_date},
        cost = #{cost},
        notes = #{notes},
        offering_status = #{offering_status},
        update_time = now()
    </set>
    where id = #{id} and deleted = 0
    """);

    if (old != null) {
        var trackFields = ['name', 'supplier_id', 'assigned_to', 'service_number', 'start_date', 'end_date', 'cost', 'notes', 'offering_status'];
        for (field in trackFields) {
            var oldVal = old[field] != null ? '' + old[field] : null;
            var newVal = body[field] != null ? '' + body[field] : null;
            if (oldVal != newVal) {
                var changeId = UuidUtil.v7();
                db.insert("""
                insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
                values (#{changeId}, 'offering', #{id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())
                """);
            }
        }
    }

    return { id: body.id };
} else {
    var newId = UuidUtil.v7();
    db.insert("""
    insert into itam_offering (id, name, supplier_id, assigned_to, service_number, start_date, end_date, cost, notes, offering_status, create_time, update_time)
    values (#{newId}, #{name}, #{supplier_id}, #{assigned_to}, #{service_number}, #{start_date}, #{end_date}, #{cost}, #{notes}, #{offering_status}, now(), now())
    """);

    var changeId = UuidUtil.v7();
    db.insert("""
    insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
    values (#{changeId}, 'offering', #{newId}, #{name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())
    """);

    return { id: newId };
}


24	================================
25	import 'com.itam.util.UuidUtil';
26
27	var assigned_to = body.assigned_to;
28	var category_id = body.category_id;
29	var id = body.id;
30	var item_no = body.item_no;
31	var location_id = body.location_id;
32	var manufacturer_id = body.manufacturer_id;
33	var min_quantity = body.min_quantity;
34	var name = body.name;
35	var order_number = body.order_number;
36	var purchase_cost = body.purchase_cost;
37	var purchase_date = body.purchase_date;
38	var quantity = body.quantity;
39	var operatorName = body.operator_name != null ? body.operator_name : 'system';
40	var operatorId = body.operator_id;
41	assert body.name != null && body.name != '' : 400, '耗材名称不能为空';
42	assert body.category_id != null : 400, '分类不能为空';
43
44	if (body.id != null) {
45	    var old = db.selectOne("""
46	        select * from itam_consumables where id = #{id} and deleted = 0
47	    """);
48
49	    db.update("""
50	    update itam_consumables
51	    <set>
52	        <if test="name != null">name = #{name},</if>
53	        category_id = #{category_id},
54	        manufacturer_id = #{manufacturer_id},
55	        assigned_to = #{assigned_to},
56	        item_no = #{item_no},
57	        order_number = #{order_number},
58	        purchase_date = #{purchase_date},
59	        purchase_cost = #{purchase_cost},
60	        quantity = #{quantity},
61	        min_quantity = #{min_quantity},
62	        location_id = #{location_id},
63	        update_time = now()
64	    </set>
65	    where id = #{id} and deleted = 0
66	    """);
67
68	    if (old != null) {
69	        var trackFields = ['name', 'category_id', 'manufacturer_id', 'assigned_to', 'item_no', 'order_number', 'purchase_date', 'purchase_cost', 'quantity', 'min_quantity', 'location_id'];
70	        for (field in trackFields) {
71	            var oldVal = old[field] != null ? '' + old[field] : null;
72	            var newVal = body[field] != null ? '' + body[field] : null;
73	            if (oldVal != newVal) {
74	                var changeId = UuidUtil.v7();
75	                db.insert("""
76	                insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
77	                values (#{changeId}, 'consumable', #{id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())
78	                """);
79	            }
80	        }
81	    }
82
83	    return { id: body.id };
84	} else {
85	    var newId = UuidUtil.v7();
86	    db.insert("""
87	    insert into itam_consumables (id, name, category_id, manufacturer_id, assigned_to, item_no, order_number, purchase_date, purchase_cost, quantity, min_quantity, location_id, create_time, update_time)
88	    values (#{newId}, #{name}, #{category_id}, #{manufacturer_id}, #{assigned_to}, #{item_no}, #{order_number}, #{purchase_date}, #{purchase_cost}, #{quantity}, #{min_quantity}, #{location_id}, now(), now())
89	    """);
90
91	    var changeId = UuidUtil.v7();
92	    db.insert("""
93	    insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
94	    values (#{changeId}, 'consumable', #{newId}, #{name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())
95	    """);
96
97	    return { id: newId };
98	}
99

================================
import 'com.itam.util.UuidUtil';

var assigned_to = body.assigned_to;
var category_id = body.category_id;
var id = body.id;
var item_no = body.item_no;
var location_id = body.location_id;
var manufacturer_id = body.manufacturer_id;
var min_quantity = body.min_quantity;
var name = body.name;
var order_number = body.order_number;
var purchase_cost = body.purchase_cost;
var purchase_date = body.purchase_date;
var quantity = body.quantity;
var operatorName = body.operator_name != null ? body.operator_name : 'system';
var operatorId = body.operator_id;
assert body.name != null && body.name != '' : 400, '耗材名称不能为空';
assert body.category_id != null : 400, '分类不能为空';

if (body.id != null) {
    var old = db.selectOne("""
        select * from itam_consumables where id = #{id} and deleted = 0
    """);

    db.update("""
    update itam_consumables
    <set>
        <if test="name != null">name = #{name},</if>
        category_id = #{category_id},
        manufacturer_id = #{manufacturer_id},
        assigned_to = #{assigned_to},
        item_no = #{item_no},
        order_number = #{order_number},
        purchase_date = #{purchase_date},
        purchase_cost = #{purchase_cost},
        quantity = #{quantity},
        min_quantity = #{min_quantity},
        location_id = #{location_id},
        update_time = now()
    </set>
    where id = #{id} and deleted = 0
    """);

    if (old != null) {
        var trackFields = ['name', 'category_id', 'manufacturer_id', 'assigned_to', 'item_no', 'order_number', 'purchase_date', 'purchase_cost', 'quantity', 'min_quantity', 'location_id'];
        for (field in trackFields) {
            var oldVal = old[field] != null ? '' + old[field] : null;
            var newVal = body[field] != null ? '' + body[field] : null;
            if (oldVal != newVal) {
                var changeId = UuidUtil.v7();
                db.insert("""
                insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
                values (#{changeId}, 'consumable', #{id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())
                """);
            }
        }
    }

    return { id: body.id };
} else {
    var newId = UuidUtil.v7();
    db.insert("""
    insert into itam_consumables (id, name, category_id, manufacturer_id, assigned_to, item_no, order_number, purchase_date, purchase_cost, quantity, min_quantity, location_id, create_time, update_time)
    values (#{newId}, #{name}, #{category_id}, #{manufacturer_id}, #{assigned_to}, #{item_no}, #{order_number}, #{purchase_date}, #{purchase_cost}, #{quantity}, #{min_quantity}, #{location_id}, now(), now())
    """);

    var changeId = UuidUtil.v7();
    db.insert("""
    insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
    values (#{changeId}, 'consumable', #{newId}, #{name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())
    """);

    return { id: newId };
}


Prompt:
<task-notification>
<task-id>b3gr2a060</task-id>
<tool-use-id>call_00_Ve3qGVOkabbBjiUjxae87432</tool-use-id>
<output-file>C:\Users\xuewu\AppData\Local\Temp\claude\c--Workspace-Project-tansci\96126fe7-9fce-45d2-80c8-6df5f05e1d22\tasks\b3gr2a060.output</output-file>
<status>completed</status>
<summary>Background command "Restart backend in background" completed (exit code 0)</summary>
</task-notification>


All 5 remaining save.ms files have the same issue — only `name` has an `<if>` guard in the UPDATE SET clause. I need to add `<if>` guards to ALL fields. Let me also check: the backend restarted successfully.

Let me now rewrite all 5 save.ms files with the fix. The pattern is:
1. Change all direct field references in the UPDATE SET block to be wrapped in `<if test="body.xxx != null">`
2. Change the old variable references (`#{name}`, `#{id}`) to use `body.xxx` format for consistency
3. Move the insert assertions to only the `else` branch
4. Change the update branch to have relaxed assertions

Let me write all 5 files now.


后端重启完成。现在修复所有 5 个 save.ms 文件，给 UPDATE 中所有字段加 `<if>` 保护。


Write

{
  "properties": {},
  "id": "b022e3fd-e74f-6b1d-9a08-f8e9d45a3ebb",
  "script": null,
  "groupId": "a11d35a7-d7f9-513b-b116-e9e8c56b26cc",
  "name": "保存",
  "createTime": 1778891835481,
  "updateTime": null,
  "lock": null,
  "createBy": null,
  "updateBy": null,
  "path": "/save",
  "method": "POST",
  "parameters": [],
  "options": [],
  "requestBody": null,
  "headers": [],
  "paths": [],
  "responseBody": null,
  "description": null,
  "requestBodyDefinition": null,
  "responseBodyDefinition": null
}
================================
import 'com.itam.util.UuidUtil';

var operatorName = body.operator_name != null ? body.operator_name : 'system';
var operatorId = body.operator_id;

if (body.id != null) {
    assert body.name == null || body.name != '' : 400, '软件名称不能为空';

    var old = db.selectOne("""
        select * from itam_licenses where id = #{body.id} and deleted = 0
    """);

    db.update("""
    update itam_licenses
    <set>
        <if test="body.name != null">name = #{body.name},</if>
        <if test="body.license_key != null">license_key = #{body.license_key},</if>
        <if test="body.total_seats != null">total_seats = #{body.total_seats},</if>
        <if test="body.manufacturer_id != null">manufacturer_id = #{body.manufacturer_id},</if>
        <if test="body.category_id != null">category_id = #{body.category_id},</if>
        <if test="body.assigned_to != null">assigned_to = #{body.assigned_to},</if>
        <if test="body.min_qty != null">min_qty = #{body.min_qty},</if>
        <if test="body.licensed_to_name != null">licensed_to_name = #{body.licensed_to_name},</if>
        <if test="body.licensed_to_email != null">licensed_to_email = #{body.licensed_to_email},</if>
        <if test="body.supplier_id != null">supplier_id = #{body.supplier_id},</if>
        <if test="body.order_number != null">order_number = #{body.order_number},</if>
        <if test="body.purchase_cost != null">purchase_cost = #{body.purchase_cost},</if>
        <if test="body.purchase_date != null">purchase_date = #{body.purchase_date},</if>
        <if test="body.expiration_date != null">expiration_date = #{body.expiration_date},</if>
        <if test="body.termination_date != null">termination_date = #{body.termination_date},</if>
        <if test="body.notes != null">notes = #{body.notes},</if>
        update_time = now()
    </set>
    where id = #{body.id} and deleted = 0
    """);

    if (old != null) {
        var trackFields = ['name', 'license_key', 'total_seats', 'manufacturer_id', 'category_id', 'assigned_to', 'min_qty', 'licensed_to_name', 'licensed_to_email', 'supplier_id', 'order_number', 'purchase_cost', 'purchase_date', 'expiration_date', 'termination_date', 'notes'];
        for (field in trackFields) {
            var oldVal = old[field] != null ? '' + old[field] : null;
            var newVal = body[field] != null ? '' + body[field] : null;
            if (oldVal != newVal) {
                var changeId = UuidUtil.v7();
                db.insert("""
                insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
                values (#{changeId}, 'license', #{body.id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())
                """);
            }
        }
    }

    return { id: body.id };
} else {
    assert body.name != null && body.name != '' : 400, '软件名称不能为空';
    assert body.license_key != null && body.license_key != '' : 400, '序列号/密钥不能为空';

    var newId = UuidUtil.v7();
    db.insert("""
    insert into itam_licenses (id, name, license_key, total_seats, manufacturer_id, category_id, assigned_to, min_qty, licensed_to_name, licensed_to_email, supplier_id, order_number, purchase_cost, purchase_date, expiration_date, termination_date, notes, create_time, update_time)
    values (#{newId}, #{body.name}, #{body.license_key}, #{body.total_seats}, #{body.manufacturer_id}, #{body.category_id}, #{body.assigned_to}, #{body.min_qty}, #{body.licensed_to_name}, #{body.licensed_to_email}, #{body.supplier_id}, #{body.order_number}, #{body.purchase_cost}, #{body.purchase_date}, #{body.expiration_date}, #{body.termination_date}, #{body.notes}, now(), now())
    """);

    var changeId = UuidUtil.v7();
    db.insert("""
    insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
    values (#{changeId}, 'license', #{newId}, #{body.name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())
    """);

    return { id: newId };
}


{
  "properties": {},
  "id": "c133f4fe-f85f-7c2e-ab19-f9f0e56c37dd",
  "script": null,
  "groupId": "b22e46b8-e8a0-614c-b227-f0f1e67d48ee",
  "name": "保存",
  "createTime": 1778891835481,
  "updateTime": null,
  "lock": null,
  "createBy": null,
  "updateBy": null,
  "path": "/save",
  "method": "POST",
  "parameters": [],
  "options": [],
  "requestBody": null,
  "headers": [],
  "paths": [],
  "responseBody": null,
  "description": null,
  "requestBodyDefinition": null,
  "responseBodyDefinition": null
}
================================
import 'com.itam.util.UuidUtil';

var operatorName = body.operator_name != null ? body.operator_name : 'system';
var operatorId = body.operator_id;

if (body.id != null) {
    assert body.name == null || body.name != '' : 400, '配件名称不能为空';

    var old = db.selectOne("""
        select * from itam_accessories where id = #{body.id} and deleted = 0
    """);

    db.update("""
    update itam_accessories
    <set>
        <if test="body.name != null">name = #{body.name},</if>
        <if test="body.asset_number != null">asset_number = #{body.asset_number},</if>
        <if test="body.category_id != null">category_id = #{body.category_id},</if>
        <if test="body.supplier_id != null">supplier_id = #{body.supplier_id},</if>
        <if test="body.manufacturer_id != null">manufacturer_id = #{body.manufacturer_id},</if>
        <if test="body.assigned_to != null">assigned_to = #{body.assigned_to},</if>
        <if test="body.specifications != null">specifications = #{body.specifications},</if>
        <if test="body.location_id != null">location_id = #{body.location_id},</if>
        <if test="body.depreciation_id != null">depreciation_id = #{body.depreciation_id},</if>
        <if test="body.quantity != null">quantity = #{body.quantity},</if>
        <if test="body.min_quantity != null">min_quantity = #{body.min_quantity},</if>
        <if test="body.purchase_date != null">purchase_date = #{body.purchase_date},</if>
        <if test="body.warranty_expiration_date != null">warranty_expiration_date = #{body.warranty_expiration_date},</if>
        <if test="body.purchase_cost != null">purchase_cost = #{body.purchase_cost},</if>
        <if test="body.order_number != null">order_number = #{body.order_number},</if>
        <if test="body.serial_number != null">serial_number = #{body.serial_number},</if>
        <if test="body.description != null">description = #{body.description},</if>
        update_time = now()
    </set>
    where id = #{body.id} and deleted = 0
    """);

    if (old != null) {
        var trackFields = ['name', 'asset_number', 'category_id', 'supplier_id', 'manufacturer_id', 'assigned_to', 'specifications', 'location_id', 'depreciation_id', 'quantity', 'min_quantity', 'purchase_date', 'warranty_expiration_date', 'purchase_cost', 'order_number', 'serial_number', 'description'];
        for (field in trackFields) {
            var oldVal = old[field] != null ? '' + old[field] : null;
            var newVal = body[field] != null ? '' + body[field] : null;
            if (oldVal != newVal) {
                var changeId = UuidUtil.v7();
                db.insert("""
                insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
                values (#{changeId}, 'accessory', #{body.id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())
                """);
            }
        }
    }

    return { id: body.id };
} else {
    assert body.name != null && body.name != '' : 400, '配件名称不能为空';
    assert body.category_id != null : 400, '分类不能为空';

    var newId = UuidUtil.v7();
    db.insert("""
    insert into itam_accessories (id, name, asset_number, category_id, supplier_id, manufacturer_id, assigned_to, specifications, location_id, depreciation_id, quantity, min_quantity, purchase_date, warranty_expiration_date, purchase_cost, order_number, serial_number, description, create_time, update_time)
    values (#{newId}, #{body.name}, #{body.asset_number}, #{body.category_id}, #{body.supplier_id}, #{body.manufacturer_id}, #{body.assigned_to}, #{body.specifications}, #{body.location_id}, #{body.depreciation_id}, #{body.quantity}, #{body.min_quantity}, #{body.purchase_date}, #{body.warranty_expiration_date}, #{body.purchase_cost}, #{body.order_number}, #{body.serial_number}, #{body.description}, now(), now())
    """);

    var changeId = UuidUtil.v7();
    db.insert("""
    insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
    values (#{changeId}, 'accessory', #{newId}, #{body.name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())
    """);

    return { id: newId };
}


{
  "properties": {},
  "id": "d244f50f-f960-8d3f-bc2a-faf1e67d59ff",
  "script": null,
  "groupId": "c33f57c9-f9b1-725d-c338-f1f2e78d5aff",
  "name": "保存",
  "createTime": 1778891835481,
  "updateTime": null,
  "lock": null,
  "createBy": null,
  "updateBy": null,
  "path": "/save",
  "method": "POST",
  "parameters": [],
  "options": [],
  "requestBody": null,
  "headers": [],
  "paths": [],
  "responseBody": null,
  "description": null,
  "requestBodyDefinition": null,
  "responseBodyDefinition": null
}
================================
import 'com.itam.util.UuidUtil';

var operatorName = body.operator_name != null ? body.operator_name : 'system';
var operatorId = body.operator_id;

if (body.id != null) {
    assert body.name == null || body.name != '' : 400, '耗材名称不能为空';

    var old = db.selectOne("""
        select * from itam_consumables where id = #{body.id} and deleted = 0
    """);

    db.update("""
    update itam_consumables
    <set>
        <if test="body.name != null">name = #{body.name},</if>
        <if test="body.category_id != null">category_id = #{body.category_id},</if>
        <if test="body.manufacturer_id != null">manufacturer_id = #{body.manufacturer_id},</if>
        <if test="body.assigned_to != null">assigned_to = #{body.assigned_to},</if>
        <if test="body.item_no != null">item_no = #{body.item_no},</if>
        <if test="body.order_number != null">order_number = #{body.order_number},</if>
        <if test="body.purchase_date != null">purchase_date = #{body.purchase_date},</if>
        <if test="body.purchase_cost != null">purchase_cost = #{body.purchase_cost},</if>
        <if test="body.quantity != null">quantity = #{body.quantity},</if>
        <if test="body.min_quantity != null">min_quantity = #{body.min_quantity},</if>
        <if test="body.location_id != null">location_id = #{body.location_id},</if>
        update_time = now()
    </set>
    where id = #{body.id} and deleted = 0
    """);

    if (old != null) {
        var trackFields = ['name', 'category_id', 'manufacturer_id', 'assigned_to', 'item_no', 'order_number', 'purchase_date', 'purchase_cost', 'quantity', 'min_quantity', 'location_id'];
        for (field in trackFields) {
            var oldVal = old[field] != null ? '' + old[field] : null;
            var newVal = body[field] != null ? '' + body[field] : null;
            if (oldVal != newVal) {
                var changeId = UuidUtil.v7();
                db.insert("""
                insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
                values (#{changeId}, 'consumable', #{body.id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())
                """);
            }
        }
    }

    return { id: body.id };
} else {
    assert body.name != null && body.name != '' : 400, '耗材名称不能为空';
    assert body.category_id != null : 400, '分类不能为空';

    var newId = UuidUtil.v7();
    db.insert("""
    insert into itam_consumables (id, name, category_id, manufacturer_id, assigned_to, item_no, order_number, purchase_date, purchase_cost, quantity, min_quantity, location_id, create_time, update_time)
    values (#{newId}, #{body.name}, #{body.category_id}, #{body.manufacturer_id}, #{body.assigned_to}, #{body.item_no}, #{body.order_number}, #{body.purchase_date}, #{body.purchase_cost}, #{body.quantity}, #{body.min_quantity}, #{body.location_id}, now(), now())
    """);

    var changeId = UuidUtil.v7();
    db.insert("""
    insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
    values (#{changeId}, 'consumable', #{newId}, #{body.name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())
    """);

    return { id: newId };
}


{
  "properties": {},
  "id": "e355f60f-fa71-9e4f-cd3b-fbf2f78d6aff",
  "script": null,
  "groupId": "d44f68da-fac2-836e-d449-f2f3e89d6bff",
  "name": "保存",
  "createTime": 1778891835481,
  "updateTime": null,
  "lock": null,
  "createBy": null,
  "updateBy": null,
  "path": "/save",
  "method": "POST",
  "parameters": [],
  "options": [],
  "requestBody": null,
  "headers": [],
  "paths": [],
  "responseBody": null,
  "description": null,
  "requestBodyDefinition": null,
  "responseBodyDefinition": null
}
================================
import 'com.itam.util.UuidUtil';

var operatorName = body.operator_name != null ? body.operator_name : 'system';
var operatorId = body.operator_id;

if (body.id != null) {
    assert body.name == null || body.name != '' : 400, '折旧规则名称不能为空';

    var old = db.selectOne("""
        select * from itam_depreciations where id = #{body.id} and deleted = 0
    """);

    db.update("""
    update itam_depreciations
    <set>
        <if test="body.name != null">name = #{body.name},</if>
        <if test="body.status != null">status = #{body.status},</if>
        <if test="body.months != null">months = #{body.months},</if>
        <if test="body.floor_type != null">floor_type = #{body.floor_type},</if>
        <if test="body.floor_val != null">floor_val = #{body.floor_val},</if>
        <if test="body.stages != null">stages = #{body.stages},</if>
        <if test="body.remark != null">remark = #{body.remark},</if>
        update_time = now()
    </set>
    where id = #{body.id} and deleted = 0
    """);

    if (old != null) {
        var trackFields = ['name', 'status', 'months', 'floor_type', 'floor_val', 'stages', 'remark'];
        for (field in trackFields) {
            var oldVal = old[field] != null ? '' + old[field] : null;
            var newVal = body[field] != null ? '' + body[field] : null;
            if (oldVal != newVal) {
                var changeId = UuidUtil.v7();
                db.insert("""
                insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
                values (#{changeId}, 'depreciation', #{body.id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())
                """);
            }
        }
    }

    return { id: body.id };
} else {
    assert body.name != null && body.name != '' : 400, '折旧规则名称不能为空';
    assert body.months != null && body.months > 0 : 400, '折旧月数必须大于0';

    var newId = UuidUtil.v7();
    db.insert("""
    insert into itam_depreciations (id, name, status, months, floor_type, floor_val, stages, remark, create_time, update_time)
    values (#{newId}, #{body.name}, #{body.status}, #{body.months}, #{body.floor_type}, #{body.floor_val}, #{body.stages}, #{body.remark}, now(), now())
    """);

    var changeId = UuidUtil.v7();
    db.insert("""
    insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
    values (#{changeId}, 'depreciation', #{newId}, #{body.name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())
    """);

    return { id: newId };
}


{
  "properties": {},
  "id": "f466f71f-fb82-af5f-de4c-fcf3f89d7cff",
  "script": null,
  "groupId": "e55f79eb-fb93-947e-e55a-f3f4e9ae7dff",
  "name": "保存",
  "createTime": 1778891835481,
  "updateTime": null,
  "lock": null,
  "createBy": null,
  "updateBy": null,
  "path": "/save",
  "method": "POST",
  "parameters": [],
  "options": [],
  "requestBody": null,
  "headers": [],
  "paths": [],
  "responseBody": null,
  "description": null,
  "requestBodyDefinition": null,
  "responseBodyDefinition": null
}
================================
import 'com.itam.util.UuidUtil';

var operatorName = body.operator_name != null ? body.operator_name : 'system';
var operatorId = body.operator_id;

if (body.id != null) {
    assert body.name == null || body.name != '' : 400, '服务名称不能为空';

    var old = db.selectOne("""
        select * from itam_offering where id = #{body.id} and deleted = 0
    """);

    db.update("""
    update itam_offering
    <set>
        <if test="body.name != null">name = #{body.name},</if>
        <if test="body.supplier_id != null">supplier_id = #{body.supplier_id},</if>
        <if test="body.assigned_to != null">assigned_to = #{body.assigned_to},</if>
        <if test="body.service_number != null">service_number = #{body.service_number},</if>
        <if test="body.start_date != null">start_date = #{body.start_date},</if>
        <if test="body.end_date != null">end_date = #{body.end_date},</if>
        <if test="body.cost != null">cost = #{body.cost},</if>
        <if test="body.notes != null">notes = #{body.notes},</if>
        <if test="body.offering_status != null">offering_status = #{body.offering_status},</if>
        update_time = now()
    </set>
    where id = #{body.id} and deleted = 0
    """);

    if (old != null) {
        var trackFields = ['name', 'supplier_id', 'assigned_to', 'service_number', 'start_date', 'end_date', 'cost', 'notes', 'offering_status'];
        for (field in trackFields) {
            var oldVal = old[field] != null ? '' + old[field] : null;
            var newVal = body[field] != null ? '' + body[field] : null;
            if (oldVal != newVal) {
                var changeId = UuidUtil.v7();
                db.insert("""
                insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
                values (#{changeId}, 'offering', #{body.id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())
                """);
            }
        }
    }

    return { id: body.id };
} else {
    assert body.name != null && body.name != '' : 400, '服务名称不能为空';

    var newId = UuidUtil.v7();
    db.insert("""
    insert into itam_offering (id, name, supplier_id, assigned_to, service_number, start_date, end_date, cost, notes, offering_status, create_time, update_time)
    values (#{newId}, #{body.name}, #{body.supplier_id}, #{body.assigned_to}, #{body.service_number}, #{body.start_date}, #{body.end_date}, #{body.cost}, #{body.notes}, #{body.offering_status}, now(), now())
    """);

    var changeId = UuidUtil.v7();
    db.insert("""
    insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
    values (#{changeId}, 'offering', #{newId}, #{body.name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())
    """);

    return { id: newId };
}


The file c:\Workspace\Project\tansci\our-itam\data\magic-api\api\asset\license\save.ms has been updated successfully. (file state is current in your context — no need to Read it back)

{
  "properties": {},
  "id": "b022e3fd-e74f-6b1d-9a08-f8e9d45a3ebb",
  "script": null,
  "groupId": "a11d35a7-d7f9-513b-b116-e9e8c56b26cc",
  "name": "保存",
  "createTime": 1778891835481,
  "updateTime": null,
  "lock": null,
  "createBy": null,
  "updateBy": null,
  "path": "/save",
  "method": "POST",
  "parameters": [],
  "options": [],
  "requestBody": null,
  "headers": [],
  "paths": [],
  "responseBody": null,
  "description": null,
  "requestBodyDefinition": null,
  "responseBodyDefinition": null
}
================================
import 'com.itam.util.UuidUtil';

var operatorName = body.operator_name != null ? body.operator_name : 'system';
var operatorId = body.operator_id;

if (body.id != null) {
    assert body.name == null || body.name != '' : 400, '软件名称不能为空';

    var old = db.selectOne("""
        select * from itam_licenses where id = #{body.id} and deleted = 0
    """);

    db.update("""
    update itam_licenses
    <set>
        <if test="body.name != null">name = #{body.name},</if>
        <if test="body.license_key != null">license_key = #{body.license_key},</if>
        <if test="body.total_seats != null">total_seats = #{body.total_seats},</if>
        <if test="body.manufacturer_id != null">manufacturer_id = #{body.manufacturer_id},</if>
        <if test="body.category_id != null">category_id = #{body.category_id},</if>
        <if test="body.assigned_to != null">assigned_to = #{body.assigned_to},</if>
        <if test="body.min_qty != null">min_qty = #{body.min_qty},</if>
        <if test="body.licensed_to_name != null">licensed_to_name = #{body.licensed_to_name},</if>
        <if test="body.licensed_to_email != null">licensed_to_email = #{body.licensed_to_email},</if>
        <if test="body.supplier_id != null">supplier_id = #{body.supplier_id},</if>
        <if test="body.order_number != null">order_number = #{body.order_number},</if>
        <if test="body.purchase_cost != null">purchase_cost = #{body.purchase_cost},</if>
        <if test="body.purchase_date != null">purchase_date = #{body.purchase_date},</if>
        <if test="body.expiration_date != null">expiration_date = #{body.expiration_date},</if>
        <if test="body.termination_date != null">termination_date = #{body.termination_date},</if>
        <if test="body.notes != null">notes = #{body.notes},</if>
        update_time = now()
    </set>
    where id = #{body.id} and deleted = 0
    """);

    if (old != null) {
        var trackFields = ['name', 'license_key', 'total_seats', 'manufacturer_id', 'category_id', 'assigned_to', 'min_qty', 'licensed_to_name', 'licensed_to_email', 'supplier_id', 'order_number', 'purchase_cost', 'purchase_date', 'expiration_date', 'termination_date', 'notes'];
        for (field in trackFields) {
            var oldVal = old[field] != null ? '' + old[field] : null;
            var newVal = body[field] != null ? '' + body[field] : null;
            if (oldVal != newVal) {
                var changeId = UuidUtil.v7();
                db.insert("""
                insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
                values (#{changeId}, 'license', #{body.id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())
                """);
            }
        }
    }

    return { id: body.id };
} else {
    assert body.name != null && body.name != '' : 400, '软件名称不能为空';
    assert body.license_key != null && body.license_key != '' : 400, '序列号/密钥不能为空';

    var newId = UuidUtil.v7();
    db.insert("""
    insert into itam_licenses (id, name, license_key, total_seats, manufacturer_id, category_id, assigned_to, min_qty, licensed_to_name, licensed_to_email, supplier_id, order_number, purchase_cost, purchase_date, expiration_date, termination_date, notes, create_time, update_time)
    values (#{newId}, #{body.name}, #{body.license_key}, #{body.total_seats}, #{body.manufacturer_id}, #{body.category_id}, #{body.assigned_to}, #{body.min_qty}, #{body.licensed_to_name}, #{body.licensed_to_email}, #{body.supplier_id}, #{body.order_number}, #{body.purchase_cost}, #{body.purchase_date}, #{body.expiration_date}, #{body.termination_date}, #{body.notes}, now(), now())
    """);

    var changeId = UuidUtil.v7();
    db.insert("""
    insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
    values (#{changeId}, 'license', #{newId}, #{body.name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())
    """);

    return { id: newId };
}

-var expiration_date = body.expiration_date;

-var licensed_to_email = body.licensed_to_email;

-var licensed_to_name = body.licensed_to_name;

-var manufacturer_id = body.manufacturer_id;

-var purchase_cost = body.purchase_cost;

-var purchase_date = body.purchase_date;

-var termination_date = body.termination_date;

-assert body.name != null && body.name != '' : 400, '软件名称不能为空';

-assert body.license_key != null && body.license_key != '' : 400, '序列号/密钥不能为空';

+    assert body.name == null || body.name != '' : 400, '软件名称不能为空';

-        select * from itam_licenses where id = #{id} and deleted = 0

+        select * from itam_licenses where id = #{body.id} and deleted = 0

-        <if test="name != null">name = #{name},</if>

-        manufacturer_id = #{manufacturer_id},

-        licensed_to_name = #{licensed_to_name},

-        licensed_to_email = #{licensed_to_email},

-        order_number = #{order_number},

-        purchase_cost = #{purchase_cost},

-        purchase_date = #{purchase_date},

-        expiration_date = #{expiration_date},

-        termination_date = #{termination_date},

+        <if test="body.name != null">name = #{body.name},</if>

+        <if test="body.license_key != null">license_key = #{body.license_key},</if>

+        <if test="body.total_seats != null">total_seats = #{body.total_seats},</if>

+        <if test="body.manufacturer_id != null">manufacturer_id = #{body.manufacturer_id},</if>

+        <if test="body.category_id != null">category_id = #{body.category_id},</if>

+        <if test="body.assigned_to != null">assigned_to = #{body.assigned_to},</if>

+        <if test="body.min_qty != null">min_qty = #{body.min_qty},</if>

+        <if test="body.licensed_to_name != null">licensed_to_name = #{body.licensed_to_name},</if>

+        <if test="body.licensed_to_email != null">licensed_to_email = #{body.licensed_to_email},</if>

+        <if test="body.supplier_id != null">supplier_id = #{body.supplier_id},</if>

+        <if test="body.order_number != null">order_number = #{body.order_number},</if>

+        <if test="body.purchase_cost != null">purchase_cost = #{body.purchase_cost},</if>

+        <if test="body.purchase_date != null">purchase_date = #{body.purchase_date},</if>

+        <if test="body.expiration_date != null">expiration_date = #{body.expiration_date},</if>

+        <if test="body.termination_date != null">termination_date = #{body.termination_date},</if>

+        <if test="body.notes != null">notes = #{body.notes},</if>

+    where id = #{body.id} and deleted = 0

-    // 记录变更

-                values (#{changeId}, 'license', #{id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())

+                values (#{changeId}, 'license', #{body.id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())

+    assert body.name != null && body.name != '' : 400, '软件名称不能为空';

+    assert body.license_key != null && body.license_key != '' : 400, '序列号/密钥不能为空';

-    values (#{newId}, #{name}, #{license_key}, #{total_seats}, #{manufacturer_id}, #{category_id}, #{assigned_to}, #{min_qty}, #{licensed_to_name}, #{licensed_to_email}, #{supplier_id}, #{order_number}, #{purchase_cost}, #{purchase_date}, #{expiration_date}, #{termination_date}, #{notes}, now(), now())

+    values (#{newId}, #{body.name}, #{body.license_key}, #{body.total_seats}, #{body.manufacturer_id}, #{body.category_id}, #{body.assigned_to}, #{body.min_qty}, #{body.licensed_to_name}, #{body.licensed_to_email}, #{body.supplier_id}, #{body.order_number}, #{body.purchase_cost}, #{body.purchase_date}, #{body.expiration_date}, #{body.termination_date}, #{body.notes}, now(), now())

-    values (#{changeId}, 'license', #{newId}, #{name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())

+    values (#{changeId}, 'license', #{newId}, #{body.name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())

{
  "properties": {},
  "id": "6551709f-46cd-5438-8d52-cff974a494a1",
  "script": null,
  "groupId": "25a971ba-6a80-5bb8-88f2-a0d53c183824",
  "name": "保存",
  "createTime": 1778891835481,
  "updateTime": null,
  "lock": null,
  "createBy": null,
  "updateBy": null,
  "path": "/save",
  "method": "POST",
  "parameters": [],
  "options": [],
  "requestBody": null,
  "headers": [],
  "paths": [],
  "responseBody": null,
  "description": null,
  "requestBodyDefinition": null,
  "responseBodyDefinition": null
}
================================
import 'com.itam.util.UuidUtil';

var assigned_to = body.assigned_to;
var category_id = body.category_id;
var expiration_date = body.expiration_date;
var id = body.id;
var license_key = body.license_key;
var licensed_to_email = body.licensed_to_email;
var licensed_to_name = body.licensed_to_name;
var manufacturer_id = body.manufacturer_id;
var min_qty = body.min_qty;
var name = body.name;
var notes = body.notes;
var order_number = body.order_number;
var purchase_cost = body.purchase_cost;
var purchase_date = body.purchase_date;
var supplier_id = body.supplier_id;
var termination_date = body.termination_date;
var total_seats = body.total_seats;
var operatorName = body.operator_name != null ? body.operator_name : 'system';
var operatorId = body.operator_id;
assert body.name != null && body.name != '' : 400, '软件名称不能为空';
assert body.license_key != null && body.license_key != '' : 400, '序列号/密钥不能为空';

if (body.id != null) {
    var old = db.selectOne("""
        select * from itam_licenses where id = #{id} and deleted = 0
    """);

    db.update("""
    update itam_licenses
    <set>
        <if test="name != null">name = #{name},</if>
        license_key = #{license_key},
        total_seats = #{total_seats},
        manufacturer_id = #{manufacturer_id},
        category_id = #{category_id},
        assigned_to = #{assigned_to},
        min_qty = #{min_qty},
        licensed_to_name = #{licensed_to_name},
        licensed_to_email = #{licensed_to_email},
        supplier_id = #{supplier_id},
        order_number = #{order_number},
        purchase_cost = #{purchase_cost},
        purchase_date = #{purchase_date},
        expiration_date = #{expiration_date},
        termination_date = #{termination_date},
        notes = #{notes},
        update_time = now()
    </set>
    where id = #{id} and deleted = 0
    """);

    // 记录变更
    if (old != null) {
        var trackFields = ['name', 'license_key', 'total_seats', 'manufacturer_id', 'category_id', 'assigned_to', 'min_qty', 'licensed_to_name', 'licensed_to_email', 'supplier_id', 'order_number', 'purchase_cost', 'purchase_date', 'expiration_date', 'termination_date', 'notes'];
        for (field in trackFields) {
            var oldVal = old[field] != null ? '' + old[field] : null;
            var newVal = body[field] != null ? '' + body[field] : null;
            if (oldVal != newVal) {
                var changeId = UuidUtil.v7();
                db.insert("""
                insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
                values (#{changeId}, 'license', #{id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())
                """);
            }
        }
    }

    return { id: body.id };
} else {
    var newId = UuidUtil.v7();
    db.insert("""
    insert into itam_licenses (id, name, license_key, total_seats, manufacturer_id, category_id, assigned_to, min_qty, licensed_to_name, licensed_to_email, supplier_id, order_number, purchase_cost, purchase_date, expiration_date, termination_date, notes, create_time, update_time)
    values (#{newId}, #{name}, #{license_key}, #{total_seats}, #{manufacturer_id}, #{category_id}, #{assigned_to}, #{min_qty}, #{licensed_to_name}, #{licensed_to_email}, #{supplier_id}, #{order_number}, #{purchase_cost}, #{purchase_date}, #{expiration_date}, #{termination_date}, #{notes}, now(), now())
    """);

    var changeId = UuidUtil.v7();
    db.insert("""
    insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
    values (#{changeId}, 'license', #{newId}, #{name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())
    """);

    return { id: newId };
}


The file c:\Workspace\Project\tansci\our-itam\data\magic-api\api\asset\accessory\save.ms has been updated successfully. (file state is current in your context — no need to Read it back)

{
  "properties": {},
  "id": "c133f4fe-f85f-7c2e-ab19-f9f0e56c37dd",
  "script": null,
  "groupId": "b22e46b8-e8a0-614c-b227-f0f1e67d48ee",
  "name": "保存",
  "createTime": 1778891835481,
  "updateTime": null,
  "lock": null,
  "createBy": null,
  "updateBy": null,
  "path": "/save",
  "method": "POST",
  "parameters": [],
  "options": [],
  "requestBody": null,
  "headers": [],
  "paths": [],
  "responseBody": null,
  "description": null,
  "requestBodyDefinition": null,
  "responseBodyDefinition": null
}
================================
import 'com.itam.util.UuidUtil';

var operatorName = body.operator_name != null ? body.operator_name : 'system';
var operatorId = body.operator_id;

if (body.id != null) {
    assert body.name == null || body.name != '' : 400, '配件名称不能为空';

    var old = db.selectOne("""
        select * from itam_accessories where id = #{body.id} and deleted = 0
    """);

    db.update("""
    update itam_accessories
    <set>
        <if test="body.name != null">name = #{body.name},</if>
        <if test="body.asset_number != null">asset_number = #{body.asset_number},</if>
        <if test="body.category_id != null">category_id = #{body.category_id},</if>
        <if test="body.supplier_id != null">supplier_id = #{body.supplier_id},</if>
        <if test="body.manufacturer_id != null">manufacturer_id = #{body.manufacturer_id},</if>
        <if test="body.assigned_to != null">assigned_to = #{body.assigned_to},</if>
        <if test="body.specifications != null">specifications = #{body.specifications},</if>
        <if test="body.location_id != null">location_id = #{body.location_id},</if>
        <if test="body.depreciation_id != null">depreciation_id = #{body.depreciation_id},</if>
        <if test="body.quantity != null">quantity = #{body.quantity},</if>
        <if test="body.min_quantity != null">min_quantity = #{body.min_quantity},</if>
        <if test="body.purchase_date != null">purchase_date = #{body.purchase_date},</if>
        <if test="body.warranty_expiration_date != null">warranty_expiration_date = #{body.warranty_expiration_date},</if>
        <if test="body.purchase_cost != null">purchase_cost = #{body.purchase_cost},</if>
        <if test="body.order_number != null">order_number = #{body.order_number},</if>
        <if test="body.serial_number != null">serial_number = #{body.serial_number},</if>
        <if test="body.description != null">description = #{body.description},</if>
        update_time = now()
    </set>
    where id = #{body.id} and deleted = 0
    """);

    if (old != null) {
        var trackFields = ['name', 'asset_number', 'category_id', 'supplier_id', 'manufacturer_id', 'assigned_to', 'specifications', 'location_id', 'depreciation_id', 'quantity', 'min_quantity', 'purchase_date', 'warranty_expiration_date', 'purchase_cost', 'order_number', 'serial_number', 'description'];
        for (field in trackFields) {
            var oldVal = old[field] != null ? '' + old[field] : null;
            var newVal = body[field] != null ? '' + body[field] : null;
            if (oldVal != newVal) {
                var changeId = UuidUtil.v7();
                db.insert("""
                insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
                values (#{changeId}, 'accessory', #{body.id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())
                """);
            }
        }
    }

    return { id: body.id };
} else {
    assert body.name != null && body.name != '' : 400, '配件名称不能为空';
    assert body.category_id != null : 400, '分类不能为空';

    var newId = UuidUtil.v7();
    db.insert("""
    insert into itam_accessories (id, name, asset_number, category_id, supplier_id, manufacturer_id, assigned_to, specifications, location_id, depreciation_id, quantity, min_quantity, purchase_date, warranty_expiration_date, purchase_cost, order_number, serial_number, description, create_time, update_time)
    values (#{newId}, #{body.name}, #{body.asset_number}, #{body.category_id}, #{body.supplier_id}, #{body.manufacturer_id}, #{body.assigned_to}, #{body.specifications}, #{body.location_id}, #{body.depreciation_id}, #{body.quantity}, #{body.min_quantity}, #{body.purchase_date}, #{body.warranty_expiration_date}, #{body.purchase_cost}, #{body.order_number}, #{body.serial_number}, #{body.description}, now(), now())
    """);

    var changeId = UuidUtil.v7();
    db.insert("""
    insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
    values (#{changeId}, 'accessory', #{newId}, #{body.name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())
    """);

    return { id: newId };
}

-var depreciation_id = body.depreciation_id;

-var manufacturer_id = body.manufacturer_id;

-var purchase_cost = body.purchase_cost;

-var purchase_date = body.purchase_date;

-var serial_number = body.serial_number;

-var specifications = body.specifications;

-var warranty_expiration_date = body.warranty_expiration_date;

-assert body.name != null && body.name != '' : 400, '配件名称不能为空';

-assert body.category_id != null : 400, '分类不能为空';

+    assert body.name == null || body.name != '' : 400, '配件名称不能为空';

-        select * from itam_accessories where id = #{id} and deleted = 0

+        select * from itam_accessories where id = #{body.id} and deleted = 0

-        <if test="name != null">name = #{name},</if>

-        asset_number = #{asset_number},

-        manufacturer_id = #{manufacturer_id},

-        specifications = #{specifications},

-        depreciation_id = #{depreciation_id},

-        min_quantity = #{min_quantity},

-        purchase_date = #{purchase_date},

-        warranty_expiration_date = #{warranty_expiration_date},

-        purchase_cost = #{purchase_cost},

-        order_number = #{order_number},

-        serial_number = #{serial_number},

+        <if test="body.name != null">name = #{body.name},</if>

+        <if test="body.asset_number != null">asset_number = #{body.asset_number},</if>

+        <if test="body.category_id != null">category_id = #{body.category_id},</if>

+        <if test="body.supplier_id != null">supplier_id = #{body.supplier_id},</if>

+        <if test="body.manufacturer_id != null">manufacturer_id = #{body.manufacturer_id},</if>

+        <if test="body.assigned_to != null">assigned_to = #{body.assigned_to},</if>

+        <if test="body.specifications != null">specifications = #{body.specifications},</if>

+        <if test="body.location_id != null">location_id = #{body.location_id},</if>

+        <if test="body.depreciation_id != null">depreciation_id = #{body.depreciation_id},</if>

+        <if test="body.quantity != null">quantity = #{body.quantity},</if>

+        <if test="body.min_quantity != null">min_quantity = #{body.min_quantity},</if>

+        <if test="body.purchase_date != null">purchase_date = #{body.purchase_date},</if>

+        <if test="body.warranty_expiration_date != null">warranty_expiration_date = #{body.warranty_expiration_date},</if>

+        <if test="body.purchase_cost != null">purchase_cost = #{body.purchase_cost},</if>

+        <if test="body.order_number != null">order_number = #{body.order_number},</if>

+        <if test="body.serial_number != null">serial_number = #{body.serial_number},</if>

+        <if test="body.description != null">description = #{body.description},</if>

+    where id = #{body.id} and deleted = 0

-                values (#{changeId}, 'accessory', #{id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())

+                values (#{changeId}, 'accessory', #{body.id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())

+    assert body.name != null && body.name != '' : 400, '配件名称不能为空';

+    assert body.category_id != null : 400, '分类不能为空';

-    values (#{newId}, #{name}, #{asset_number}, #{category_id}, #{supplier_id}, #{manufacturer_id}, #{assigned_to}, #{specifications}, #{location_id}, #{depreciation_id}, #{quantity}, #{min_quantity}, #{purchase_date}, #{warranty_expiration_date}, #{purchase_cost}, #{order_number}, #{serial_number}, #{description}, now(), now())

+    values (#{newId}, #{body.name}, #{body.asset_number}, #{body.category_id}, #{body.supplier_id}, #{body.manufacturer_id}, #{body.assigned_to}, #{body.specifications}, #{body.location_id}, #{body.depreciation_id}, #{body.quantity}, #{body.min_quantity}, #{body.purchase_date}, #{body.warranty_expiration_date}, #{body.purchase_cost}, #{body.order_number}, #{body.serial_number}, #{body.description}, now(), now())

-    values (#{changeId}, 'accessory', #{newId}, #{name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())

+    values (#{changeId}, 'accessory', #{newId}, #{body.name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())

{
  "properties": {},
  "id": "3d31f810-7182-56a7-8d95-b8377b0e82db",
  "script": null,
  "groupId": "2b123de0-230e-5a36-9258-449f513ae52e",
  "name": "保存",
  "createTime": 1778891835481,
  "updateTime": null,
  "lock": null,
  "createBy": null,
  "updateBy": null,
  "path": "/save",
  "method": "POST",
  "parameters": [],
  "options": [],
  "requestBody": null,
  "headers": [],
  "paths": [],
  "responseBody": null,
  "description": null,
  "requestBodyDefinition": null,
  "responseBodyDefinition": null
}
================================
import 'com.itam.util.UuidUtil';

var asset_number = body.asset_number;
var assigned_to = body.assigned_to;
var category_id = body.category_id;
var depreciation_id = body.depreciation_id;
var description = body.description;
var id = body.id;
var location_id = body.location_id;
var manufacturer_id = body.manufacturer_id;
var min_quantity = body.min_quantity;
var name = body.name;
var order_number = body.order_number;
var purchase_cost = body.purchase_cost;
var purchase_date = body.purchase_date;
var quantity = body.quantity;
var serial_number = body.serial_number;
var specifications = body.specifications;
var supplier_id = body.supplier_id;
var warranty_expiration_date = body.warranty_expiration_date;
var operatorName = body.operator_name != null ? body.operator_name : 'system';
var operatorId = body.operator_id;
assert body.name != null && body.name != '' : 400, '配件名称不能为空';
assert body.category_id != null : 400, '分类不能为空';

if (body.id != null) {
    var old = db.selectOne("""
        select * from itam_accessories where id = #{id} and deleted = 0
    """);

    db.update("""
    update itam_accessories
    <set>
        <if test="name != null">name = #{name},</if>
        asset_number = #{asset_number},
        category_id = #{category_id},
        supplier_id = #{supplier_id},
        manufacturer_id = #{manufacturer_id},
        assigned_to = #{assigned_to},
        specifications = #{specifications},
        location_id = #{location_id},
        depreciation_id = #{depreciation_id},
        quantity = #{quantity},
        min_quantity = #{min_quantity},
        purchase_date = #{purchase_date},
        warranty_expiration_date = #{warranty_expiration_date},
        purchase_cost = #{purchase_cost},
        order_number = #{order_number},
        serial_number = #{serial_number},
        description = #{description},
        update_time = now()
    </set>
    where id = #{id} and deleted = 0
    """);

    if (old != null) {
        var trackFields = ['name', 'asset_number', 'category_id', 'supplier_id', 'manufacturer_id', 'assigned_to', 'specifications', 'location_id', 'depreciation_id', 'quantity', 'min_quantity', 'purchase_date', 'warranty_expiration_date', 'purchase_cost', 'order_number', 'serial_number', 'description'];
        for (field in trackFields) {
            var oldVal = old[field] != null ? '' + old[field] : null;
            var newVal = body[field] != null ? '' + body[field] : null;
            if (oldVal != newVal) {
                var changeId = UuidUtil.v7();
                db.insert("""
                insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
                values (#{changeId}, 'accessory', #{id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())
                """);
            }
        }
    }

    return { id: body.id };
} else {
    var newId = UuidUtil.v7();
    db.insert("""
    insert into itam_accessories (id, name, asset_number, category_id, supplier_id, manufacturer_id, assigned_to, specifications, location_id, depreciation_id, quantity, min_quantity, purchase_date, warranty_expiration_date, purchase_cost, order_number, serial_number, description, create_time, update_time)
    values (#{newId}, #{name}, #{asset_number}, #{category_id}, #{supplier_id}, #{manufacturer_id}, #{assigned_to}, #{specifications}, #{location_id}, #{depreciation_id}, #{quantity}, #{min_quantity}, #{purchase_date}, #{warranty_expiration_date}, #{purchase_cost}, #{order_number}, #{serial_number}, #{description}, now(), now())
    """);

    var changeId = UuidUtil.v7();
    db.insert("""
    insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
    values (#{changeId}, 'accessory', #{newId}, #{name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())
    """);

    return { id: newId };
}


The file c:\Workspace\Project\tansci\our-itam\data\magic-api\api\asset\consumable\save.ms has been updated successfully. (file state is current in your context — no need to Read it back)

{
  "properties": {},
  "id": "d244f50f-f960-8d3f-bc2a-faf1e67d59ff",
  "script": null,
  "groupId": "c33f57c9-f9b1-725d-c338-f1f2e78d5aff",
  "name": "保存",
  "createTime": 1778891835481,
  "updateTime": null,
  "lock": null,
  "createBy": null,
  "updateBy": null,
  "path": "/save",
  "method": "POST",
  "parameters": [],
  "options": [],
  "requestBody": null,
  "headers": [],
  "paths": [],
  "responseBody": null,
  "description": null,
  "requestBodyDefinition": null,
  "responseBodyDefinition": null
}
================================
import 'com.itam.util.UuidUtil';

var operatorName = body.operator_name != null ? body.operator_name : 'system';
var operatorId = body.operator_id;

if (body.id != null) {
    assert body.name == null || body.name != '' : 400, '耗材名称不能为空';

    var old = db.selectOne("""
        select * from itam_consumables where id = #{body.id} and deleted = 0
    """);

    db.update("""
    update itam_consumables
    <set>
        <if test="body.name != null">name = #{body.name},</if>
        <if test="body.category_id != null">category_id = #{body.category_id},</if>
        <if test="body.manufacturer_id != null">manufacturer_id = #{body.manufacturer_id},</if>
        <if test="body.assigned_to != null">assigned_to = #{body.assigned_to},</if>
        <if test="body.item_no != null">item_no = #{body.item_no},</if>
        <if test="body.order_number != null">order_number = #{body.order_number},</if>
        <if test="body.purchase_date != null">purchase_date = #{body.purchase_date},</if>
        <if test="body.purchase_cost != null">purchase_cost = #{body.purchase_cost},</if>
        <if test="body.quantity != null">quantity = #{body.quantity},</if>
        <if test="body.min_quantity != null">min_quantity = #{body.min_quantity},</if>
        <if test="body.location_id != null">location_id = #{body.location_id},</if>
        update_time = now()
    </set>
    where id = #{body.id} and deleted = 0
    """);

    if (old != null) {
        var trackFields = ['name', 'category_id', 'manufacturer_id', 'assigned_to', 'item_no', 'order_number', 'purchase_date', 'purchase_cost', 'quantity', 'min_quantity', 'location_id'];
        for (field in trackFields) {
            var oldVal = old[field] != null ? '' + old[field] : null;
            var newVal = body[field] != null ? '' + body[field] : null;
            if (oldVal != newVal) {
                var changeId = UuidUtil.v7();
                db.insert("""
                insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
                values (#{changeId}, 'consumable', #{body.id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())
                """);
            }
        }
    }

    return { id: body.id };
} else {
    assert body.name != null && body.name != '' : 400, '耗材名称不能为空';
    assert body.category_id != null : 400, '分类不能为空';

    var newId = UuidUtil.v7();
    db.insert("""
    insert into itam_consumables (id, name, category_id, manufacturer_id, assigned_to, item_no, order_number, purchase_date, purchase_cost, quantity, min_quantity, location_id, create_time, update_time)
    values (#{newId}, #{body.name}, #{body.category_id}, #{body.manufacturer_id}, #{body.assigned_to}, #{body.item_no}, #{body.order_number}, #{body.purchase_date}, #{body.purchase_cost}, #{body.quantity}, #{body.min_quantity}, #{body.location_id}, now(), now())
    """);

    var changeId = UuidUtil.v7();
    db.insert("""
    insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
    values (#{changeId}, 'consumable', #{newId}, #{body.name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())
    """);

    return { id: newId };
}

-var manufacturer_id = body.manufacturer_id;

-var purchase_cost = body.purchase_cost;

-var purchase_date = body.purchase_date;

-assert body.name != null && body.name != '' : 400, '耗材名称不能为空';

-assert body.category_id != null : 400, '分类不能为空';

+    assert body.name == null || body.name != '' : 400, '耗材名称不能为空';

-        select * from itam_consumables where id = #{id} and deleted = 0

+        select * from itam_consumables where id = #{body.id} and deleted = 0

-        <if test="name != null">name = #{name},</if>

-        manufacturer_id = #{manufacturer_id},

-        order_number = #{order_number},

-        purchase_date = #{purchase_date},

-        purchase_cost = #{purchase_cost},

-        min_quantity = #{min_quantity},

+        <if test="body.name != null">name = #{body.name},</if>

+        <if test="body.category_id != null">category_id = #{body.category_id},</if>

+        <if test="body.manufacturer_id != null">manufacturer_id = #{body.manufacturer_id},</if>

+        <if test="body.assigned_to != null">assigned_to = #{body.assigned_to},</if>

+        <if test="body.item_no != null">item_no = #{body.item_no},</if>

+        <if test="body.order_number != null">order_number = #{body.order_number},</if>

+        <if test="body.purchase_date != null">purchase_date = #{body.purchase_date},</if>

+        <if test="body.purchase_cost != null">purchase_cost = #{body.purchase_cost},</if>

+        <if test="body.quantity != null">quantity = #{body.quantity},</if>

+        <if test="body.min_quantity != null">min_quantity = #{body.min_quantity},</if>

+        <if test="body.location_id != null">location_id = #{body.location_id},</if>

+    where id = #{body.id} and deleted = 0

-                values (#{changeId}, 'consumable', #{id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())

+                values (#{changeId}, 'consumable', #{body.id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())

+    assert body.name != null && body.name != '' : 400, '耗材名称不能为空';

+    assert body.category_id != null : 400, '分类不能为空';

-    values (#{newId}, #{name}, #{category_id}, #{manufacturer_id}, #{assigned_to}, #{item_no}, #{order_number}, #{purchase_date}, #{purchase_cost}, #{quantity}, #{min_quantity}, #{location_id}, now(), now())

+    values (#{newId}, #{body.name}, #{body.category_id}, #{body.manufacturer_id}, #{body.assigned_to}, #{body.item_no}, #{body.order_number}, #{body.purchase_date}, #{body.purchase_cost}, #{body.quantity}, #{body.min_quantity}, #{body.location_id}, now(), now())

-    values (#{changeId}, 'consumable', #{newId}, #{name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())

+    values (#{changeId}, 'consumable', #{newId}, #{body.name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())

{
  "properties": {},
  "id": "1e5743e4-076c-56db-b06d-b94858f1b3b0",
  "script": null,
  "groupId": "e6b93db2-0e31-546d-ad30-5c6cbbc55413",
  "name": "保存",
  "createTime": 1778891835481,
  "updateTime": null,
  "lock": null,
  "createBy": null,
  "updateBy": null,
  "path": "/save",
  "method": "POST",
  "parameters": [],
  "options": [],
  "requestBody": null,
  "headers": [],
  "paths": [],
  "responseBody": null,
  "description": null,
  "requestBodyDefinition": null,
  "responseBodyDefinition": null
}
================================
import 'com.itam.util.UuidUtil';

var assigned_to = body.assigned_to;
var category_id = body.category_id;
var id = body.id;
var item_no = body.item_no;
var location_id = body.location_id;
var manufacturer_id = body.manufacturer_id;
var min_quantity = body.min_quantity;
var name = body.name;
var order_number = body.order_number;
var purchase_cost = body.purchase_cost;
var purchase_date = body.purchase_date;
var quantity = body.quantity;
var operatorName = body.operator_name != null ? body.operator_name : 'system';
var operatorId = body.operator_id;
assert body.name != null && body.name != '' : 400, '耗材名称不能为空';
assert body.category_id != null : 400, '分类不能为空';

if (body.id != null) {
    var old = db.selectOne("""
        select * from itam_consumables where id = #{id} and deleted = 0
    """);

    db.update("""
    update itam_consumables
    <set>
        <if test="name != null">name = #{name},</if>
        category_id = #{category_id},
        manufacturer_id = #{manufacturer_id},
        assigned_to = #{assigned_to},
        item_no = #{item_no},
        order_number = #{order_number},
        purchase_date = #{purchase_date},
        purchase_cost = #{purchase_cost},
        quantity = #{quantity},
        min_quantity = #{min_quantity},
        location_id = #{location_id},
        update_time = now()
    </set>
    where id = #{id} and deleted = 0
    """);

    if (old != null) {
        var trackFields = ['name', 'category_id', 'manufacturer_id', 'assigned_to', 'item_no', 'order_number', 'purchase_date', 'purchase_cost', 'quantity', 'min_quantity', 'location_id'];
        for (field in trackFields) {
            var oldVal = old[field] != null ? '' + old[field] : null;
            var newVal = body[field] != null ? '' + body[field] : null;
            if (oldVal != newVal) {
                var changeId = UuidUtil.v7();
                db.insert("""
                insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
                values (#{changeId}, 'consumable', #{id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())
                """);
            }
        }
    }

    return { id: body.id };
} else {
    var newId = UuidUtil.v7();
    db.insert("""
    insert into itam_consumables (id, name, category_id, manufacturer_id, assigned_to, item_no, order_number, purchase_date, purchase_cost, quantity, min_quantity, location_id, create_time, update_time)
    values (#{newId}, #{name}, #{category_id}, #{manufacturer_id}, #{assigned_to}, #{item_no}, #{order_number}, #{purchase_date}, #{purchase_cost}, #{quantity}, #{min_quantity}, #{location_id}, now(), now())
    """);

    var changeId = UuidUtil.v7();
    db.insert("""
    insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
    values (#{changeId}, 'consumable', #{newId}, #{name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())
    """);

    return { id: newId };
}


The file c:\Workspace\Project\tansci\our-itam\data\magic-api\api\asset\depreciation\save.ms has been updated successfully. (file state is current in your context — no need to Read it back)

{
  "properties": {},
  "id": "e355f60f-fa71-9e4f-cd3b-fbf2f78d6aff",
  "script": null,
  "groupId": "d44f68da-fac2-836e-d449-f2f3e89d6bff",
  "name": "保存",
  "createTime": 1778891835481,
  "updateTime": null,
  "lock": null,
  "createBy": null,
  "updateBy": null,
  "path": "/save",
  "method": "POST",
  "parameters": [],
  "options": [],
  "requestBody": null,
  "headers": [],
  "paths": [],
  "responseBody": null,
  "description": null,
  "requestBodyDefinition": null,
  "responseBodyDefinition": null
}
================================
import 'com.itam.util.UuidUtil';

var operatorName = body.operator_name != null ? body.operator_name : 'system';
var operatorId = body.operator_id;

if (body.id != null) {
    assert body.name == null || body.name != '' : 400, '折旧规则名称不能为空';

    var old = db.selectOne("""
        select * from itam_depreciations where id = #{body.id} and deleted = 0
    """);

    db.update("""
    update itam_depreciations
    <set>
        <if test="body.name != null">name = #{body.name},</if>
        <if test="body.status != null">status = #{body.status},</if>
        <if test="body.months != null">months = #{body.months},</if>
        <if test="body.floor_type != null">floor_type = #{body.floor_type},</if>
        <if test="body.floor_val != null">floor_val = #{body.floor_val},</if>
        <if test="body.stages != null">stages = #{body.stages},</if>
        <if test="body.remark != null">remark = #{body.remark},</if>
        update_time = now()
    </set>
    where id = #{body.id} and deleted = 0
    """);

    if (old != null) {
        var trackFields = ['name', 'status', 'months', 'floor_type', 'floor_val', 'stages', 'remark'];
        for (field in trackFields) {
            var oldVal = old[field] != null ? '' + old[field] : null;
            var newVal = body[field] != null ? '' + body[field] : null;
            if (oldVal != newVal) {
                var changeId = UuidUtil.v7();
                db.insert("""
                insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
                values (#{changeId}, 'depreciation', #{body.id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())
                """);
            }
        }
    }

    return { id: body.id };
} else {
    assert body.name != null && body.name != '' : 400, '折旧规则名称不能为空';
    assert body.months != null && body.months > 0 : 400, '折旧月数必须大于0';

    var newId = UuidUtil.v7();
    db.insert("""
    insert into itam_depreciations (id, name, status, months, floor_type, floor_val, stages, remark, create_time, update_time)
    values (#{newId}, #{body.name}, #{body.status}, #{body.months}, #{body.floor_type}, #{body.floor_val}, #{body.stages}, #{body.remark}, now(), now())
    """);

    var changeId = UuidUtil.v7();
    db.insert("""
    insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
    values (#{changeId}, 'depreciation', #{newId}, #{body.name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())
    """);

    return { id: newId };
}

-assert body.name != null && body.name != '' : 400, '折旧规则名称不能为空';

-assert body.months != null && body.months > 0 : 400, '折旧月数必须大于0';

+    assert body.name == null || body.name != '' : 400, '折旧规则名称不能为空';

-        select * from itam_depreciations where id = #{id} and deleted = 0

+        select * from itam_depreciations where id = #{body.id} and deleted = 0

-        <if test="name != null">name = #{name},</if>

+        <if test="body.name != null">name = #{body.name},</if>

+        <if test="body.status != null">status = #{body.status},</if>

+        <if test="body.months != null">months = #{body.months},</if>

+        <if test="body.floor_type != null">floor_type = #{body.floor_type},</if>

+        <if test="body.floor_val != null">floor_val = #{body.floor_val},</if>

+        <if test="body.stages != null">stages = #{body.stages},</if>

+        <if test="body.remark != null">remark = #{body.remark},</if>

+    where id = #{body.id} and deleted = 0

-                values (#{changeId}, 'depreciation', #{id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())

+                values (#{changeId}, 'depreciation', #{body.id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())

+    assert body.name != null && body.name != '' : 400, '折旧规则名称不能为空';

+    assert body.months != null && body.months > 0 : 400, '折旧月数必须大于0';

-    values (#{newId}, #{name}, #{status}, #{months}, #{floor_type}, #{floor_val}, #{stages}, #{remark}, now(), now())

+    values (#{newId}, #{body.name}, #{body.status}, #{body.months}, #{body.floor_type}, #{body.floor_val}, #{body.stages}, #{body.remark}, now(), now())

-    values (#{changeId}, 'depreciation', #{newId}, #{name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())

+    values (#{changeId}, 'depreciation', #{newId}, #{body.name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())

{
  "properties": {},
  "id": "88b0124c-a77d-5323-849a-b93ef4d5ba97",
  "script": null,
  "groupId": "cd7e5106-ce44-533e-9425-83d1841090b1",
  "name": "保存",
  "createTime": 1778891835481,
  "updateTime": null,
  "lock": null,
  "createBy": null,
  "updateBy": null,
  "path": "/save",
  "method": "POST",
  "parameters": [],
  "options": [],
  "requestBody": null,
  "headers": [],
  "paths": [],
  "responseBody": null,
  "description": null,
  "requestBodyDefinition": null,
  "responseBodyDefinition": null
}
================================
import 'com.itam.util.UuidUtil';

var floor_type = body.floor_type;
var floor_val = body.floor_val;
var id = body.id;
var months = body.months;
var name = body.name;
var remark = body.remark;
var stages = body.stages;
var status = body.status;
var operatorName = body.operator_name != null ? body.operator_name : 'system';
var operatorId = body.operator_id;
assert body.name != null && body.name != '' : 400, '折旧规则名称不能为空';
assert body.months != null && body.months > 0 : 400, '折旧月数必须大于0';

if (body.id != null) {
    var old = db.selectOne("""
        select * from itam_depreciations where id = #{id} and deleted = 0
    """);

    db.update("""
    update itam_depreciations
    <set>
        <if test="name != null">name = #{name},</if>
        status = #{status},
        months = #{months},
        floor_type = #{floor_type},
        floor_val = #{floor_val},
        stages = #{stages},
        remark = #{remark},
        update_time = now()
    </set>
    where id = #{id} and deleted = 0
    """);

    if (old != null) {
        var trackFields = ['name', 'status', 'months', 'floor_type', 'floor_val', 'stages', 'remark'];
        for (field in trackFields) {
            var oldVal = old[field] != null ? '' + old[field] : null;
            var newVal = body[field] != null ? '' + body[field] : null;
            if (oldVal != newVal) {
                var changeId = UuidUtil.v7();
                db.insert("""
                insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
                values (#{changeId}, 'depreciation', #{id}, #{old.name}, 'update', #{field}, #{oldVal}, #{newVal}, #{operatorId}, #{operatorName}, now())
                """);
            }
        }
    }

    return { id: body.id };
} else {
    var newId = UuidUtil.v7();
    db.insert("""
    insert into itam_depreciations (id, name, status, months, floor_type, floor_val, stages, remark, create_time, update_time)
    values (#{newId}, #{name}, #{status}, #{months}, #{floor_type}, #{floor_val}, #{stages}, #{remark}, now(), now())
    """);

    var changeId = UuidUtil.v7();
    db.insert("""
    insert into itam_change_record (id, asset_type, asset_id, asset_name, change_type, field_name, old_value, new_value, operator_id, operator_name, create_time)
    values (#{changeId}, 'depreciation', #{newId}, #{name}, 'create', null, null, null, #{operatorId}, #{operatorName}, now())
    """);

    return { id: newId };
}