3 changed files with 338 additions and 11 deletions
@ -0,0 +1,312 @@ |
|||
package com.demo.cost; |
|||
|
|||
import lombok.SneakyThrows; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.noear.wood.DbContext; |
|||
|
|||
@Slf4j |
|||
public class TbsMatchServiceImpl { |
|||
|
|||
@SneakyThrows |
|||
public void updateStatus(){ |
|||
DbContext jslContext = TbsMapper.getJslDbContext(); |
|||
|
|||
String sqlUpdate1 = "update tbs_activity t left join tbs_cost_apply a on a.id = t.cost_apply_id set t.activity_state = 3 where a.xlt_sync = 2"; |
|||
String sqlUpdate2 = "update tbs_activity t left join tbs_cost_apply a on a.id = t.cost_apply_id set t.activity_state = 4,t.release_flag =1,t.finished_flag =1 where t.release_amount > 0 and a.xlt_sync = 2 "; |
|||
String sqlUpdate3 = "update tbs_activity t left join tbs_cost_apply a on a.id = t.cost_apply_id set t.activity_state = 2,t.finished_flag =1 where t.total_amount = t.used_amount and a.xlt_sync = 2 "; |
|||
String sqlUpdate4 = "update tbs_cost_apply set charge_state = 3 where xlt_sync = 2"; |
|||
|
|||
jslContext.sql(sqlUpdate1).execute(); |
|||
jslContext.sql(sqlUpdate2).execute(); |
|||
jslContext.sql(sqlUpdate3).execute(); |
|||
jslContext.sql(sqlUpdate4).execute(); |
|||
|
|||
} |
|||
|
|||
@SneakyThrows |
|||
public void matchBudget(){ |
|||
DbContext jslContext = TbsMapper.getJslDbContext(); |
|||
|
|||
String sql = "UPDATE tbs_activity_center_goods g " + |
|||
"LEFT JOIN bms_cost_center c ON g.center_id = c.id " + |
|||
"SET g.center_code = c.`code`, g.center_name = c.`name` " + |
|||
"WHERE g.center_type = 'center' and g.sync_budget =1 "; |
|||
|
|||
String sql2 = "UPDATE tbs_activity_center_goods g " + |
|||
"LEFT JOIN bms_region c ON g.center_id = c.id " + |
|||
"SET g.center_code = c.`code`, g.center_name = c.`name` " + |
|||
"WHERE g.center_type = 'saleRegion' and g.sync_budget =1 "; |
|||
|
|||
jslContext.sql(sql).execute(); |
|||
jslContext.sql(sql2).execute(); |
|||
|
|||
String sql_drop = "drop table temp_ids"; |
|||
|
|||
jslContext.sql(sql_drop).execute(); |
|||
|
|||
String sql_temp_create = "CREATE TABLE temp_ids " + |
|||
"SELECT g.id " + |
|||
"FROM tbs_activity_center_goods g " + |
|||
"LEFT JOIN tbs_budget b ON g.center_id = b.center_id " + |
|||
"LEFT JOIN tbs_budget_condition c ON b.id = c.budget_id AND g.target_level_path_ids LIKE CONCAT(c.target_level_path_ids, '_%') " + |
|||
"LEFT JOIN tbs_schedule_item_budget i ON b.id = i.budget_id AND g.act_start_date BETWEEN i.start_date AND i.end_date " + |
|||
"WHERE g.act_start_date >= '2023-01-01' " + |
|||
"AND c.id IS NOT NULL " + |
|||
"AND i.id IS NOT NULL"; |
|||
|
|||
jslContext.sql(sql_temp_create).execute(); |
|||
|
|||
String updateSql1 = "UPDATE tbs_activity_center_goods g SET g.sync_budget = 0"; |
|||
|
|||
String updateSql2 = "UPDATE tbs_activity_center_goods g LEFT JOIN temp_ids i on g.id = i.id " + |
|||
"SET g.sync_budget = 1 where i.id is not null"; |
|||
|
|||
String updateSql3 = "UPDATE tbs_activity_center_goods g SET g.sync_budget = 1 where g.center_amount = 0"; |
|||
|
|||
String updateSql4 = "UPDATE tbs_cost_apply a SET a.new_budget_sync = 0 where a.budget_sync = 0"; |
|||
String updateSql5 = "UPDATE tbs_cost_apply AS a " + |
|||
"LEFT JOIN tbs_activity_center_goods AS g ON a.id = g.cost_apply_id " + |
|||
"SET a.new_budget_sync = 3 " + |
|||
"WHERE g.sync_budget = 0 and a.xlt_sync = 2"; |
|||
String updateSql6 = "UPDATE tbs_cost_apply a SET a.budget_sync = 2 where a.new_budget_sync != 3 and a.budget_sync = 0 and a.xlt_sync = 2"; |
|||
|
|||
jslContext.sql(updateSql1).execute(); |
|||
jslContext.sql(updateSql2).execute(); |
|||
jslContext.sql(updateSql3).execute(); |
|||
jslContext.sql(updateSql4).execute(); |
|||
jslContext.sql(updateSql5).execute(); |
|||
jslContext.sql(updateSql6).execute(); |
|||
|
|||
String insertSql = "INSERT INTO tbs_budget_cost_item ( " + |
|||
" center_goods_code, " + |
|||
" cost_apply_id, " + |
|||
" activity_id, " + |
|||
" activity_code, " + |
|||
" subject_id, " + |
|||
" subject_code, " + |
|||
" subject_name, " + |
|||
" center_type, " + |
|||
" center_id, " + |
|||
" center_code, " + |
|||
" center_name, " + |
|||
" center_amount, " + |
|||
" center_rate, " + |
|||
" center_goods_amount, " + |
|||
" center_goods_rate, " + |
|||
" target_type, " + |
|||
" target_id, " + |
|||
" target_code, " + |
|||
" target_name, " + |
|||
" target_level_path_ids, " + |
|||
" target_level_path_names, " + |
|||
" remark, " + |
|||
" create_time, " + |
|||
" update_time, " + |
|||
" tenant_id, " + |
|||
" create_by, " + |
|||
" update_by, " + |
|||
" del_flag, " + |
|||
" act_start_date, " + |
|||
" act_end_date, " + |
|||
" pre_start_date, " + |
|||
" pre_end_date, " + |
|||
" pre_check_date, " + |
|||
" schedule_id, " + |
|||
" schedule_item_id, " + |
|||
" schedule_item_name, " + |
|||
" schedule_item_amount, " + |
|||
" schedule_item_amount_used, " + |
|||
" schedule_item_amount_apply, " + |
|||
" budget_id, " + |
|||
" schedule_item_budget_id, " + |
|||
" center_good_item_id, " + |
|||
" invalid_flag, " + |
|||
" supplier_id, " + |
|||
" supplier_code, " + |
|||
" supplier_name " + |
|||
") " + |
|||
"SELECT " + |
|||
" g.center_goods_code, " + |
|||
" g.cost_apply_id, " + |
|||
" g.activity_id, " + |
|||
" g.activity_code, " + |
|||
" g.subject_id, " + |
|||
" g.subject_code, " + |
|||
" g.subject_name, " + |
|||
" g.center_type, " + |
|||
" g.center_id, " + |
|||
" g.center_code, " + |
|||
" g.center_name, " + |
|||
" g.center_amount, " + |
|||
" g.center_rate, " + |
|||
" g.center_goods_amount, " + |
|||
" g.center_goods_rate, " + |
|||
" g.target_type, " + |
|||
" g.target_id, " + |
|||
" g.target_code, " + |
|||
" g.target_name, " + |
|||
" g.target_level_path_ids, " + |
|||
" g.target_level_path_names, " + |
|||
" g.remark, " + |
|||
" g.create_time, " + |
|||
" g.update_time, " + |
|||
" g.tenant_id, " + |
|||
" g.create_by, " + |
|||
" g.update_by, " + |
|||
" g.del_flag, " + |
|||
" g.act_start_date, " + |
|||
" g.act_end_date, " + |
|||
" g.pre_start_date, " + |
|||
" g.pre_end_date, " + |
|||
" g.pre_check_date, " + |
|||
" i.schedule_id, " + |
|||
" i.schedule_item_id, " + |
|||
" i.item_name as schedule_item_name, " + |
|||
" i.budget_amount as schedule_item_amount, " + |
|||
" 0 as schedule_item_amount_used, " + |
|||
" g.center_amount as schedule_item_amount_apply, " + |
|||
" i.budget_id, " + |
|||
" i.id AS schedule_item_budget_id, " + |
|||
" g.id AS center_good_item_id, " + |
|||
" 0 as invalid_flag, " + |
|||
" g.supplier_id, " + |
|||
" g.supplier_code, " + |
|||
" g.supplier_name " + |
|||
"FROM " + |
|||
" tbs_activity_center_goods g " + |
|||
" LEFT JOIN tbs_budget b ON g.center_id = b.center_id " + |
|||
" LEFT JOIN tbs_budget_condition c ON b.id = c.budget_id AND g.target_level_path_ids LIKE CONCAT(c.target_level_path_ids, '_%') " + |
|||
" LEFT JOIN tbs_schedule_item_budget i ON b.id = i.budget_id AND g.act_start_date BETWEEN i.start_date AND i.end_date " + |
|||
" left join tbs_cost_apply a on a.id = g.cost_apply_id " + |
|||
"WHERE " + |
|||
" i.id IS NOT NULL " + |
|||
" AND c.id IS NOT NULL " + |
|||
" and a.budget_sync = 2"; |
|||
jslContext.sql(insertSql).execute(); |
|||
|
|||
String insertSql2 = "INSERT INTO tbs_budget_log ( " + |
|||
" budget_id, " + |
|||
" budget_code, " + |
|||
" rollback_flag, " + |
|||
" migrate_flag, " + |
|||
" opt_type, " + |
|||
" opt_user_id, " + |
|||
" opt_user_name, " + |
|||
" opt_user_code, " + |
|||
" amount, " + |
|||
" schedule_id, " + |
|||
" schedule_item_id, " + |
|||
" schedule_item_budget_id, " + |
|||
" schedule_org_id, " + |
|||
" schedule_item_org_id, " + |
|||
" schedule_item_budget_org_id, " + |
|||
" item_name, " + |
|||
" start_date, " + |
|||
" end_date, " + |
|||
" subject_id, " + |
|||
" subject_code, " + |
|||
" subject_name, " + |
|||
" center_type, " + |
|||
" center_id, " + |
|||
" center_code, " + |
|||
" center_name, " + |
|||
" center_org_id, " + |
|||
" center_org_code, " + |
|||
" center_org_name, " + |
|||
" supplier_id, " + |
|||
" supplier_code, " + |
|||
" supplier_name, " + |
|||
" activity_id, " + |
|||
" activity_code, " + |
|||
" activity_theme, " + |
|||
" cost_apply_id, " + |
|||
" cost_apply_code, " + |
|||
" cost_apply_theme, " + |
|||
" policy_id, " + |
|||
" policy_code, " + |
|||
" policy_title, " + |
|||
" policy_item_id, " + |
|||
" policy_item_code, " + |
|||
" remark, " + |
|||
" target_type, " + |
|||
" target_id, " + |
|||
" target_code, " + |
|||
" target_name, " + |
|||
" target_level_path_ids, " + |
|||
" target_level_path_names, " + |
|||
" tenant_id, " + |
|||
" del_flag, " + |
|||
" migrate_time " + |
|||
") " + |
|||
"SELECT " + |
|||
" i.budget_id, " + |
|||
" b.budget_code, " + |
|||
" 0 as rollback_flag, " + |
|||
" 0 as migrate_flag, " + |
|||
" 1 as opt_type, " + |
|||
" 0 as opt_user_id, " + |
|||
" '系统管理员' as opt_user_name, " + |
|||
" 0 as opt_user_code, " + |
|||
" -g.center_amount as amount, " + |
|||
" i.schedule_id, " + |
|||
" i.schedule_item_id, " + |
|||
" i.id as schedule_item_budget_id, " + |
|||
" NULL, " + |
|||
" NULL, " + |
|||
" NULL, " + |
|||
" i.item_name, " + |
|||
" g.act_start_date, " + |
|||
" g.act_end_date, " + |
|||
" g.subject_id, " + |
|||
" g.subject_code, " + |
|||
" g.subject_name, " + |
|||
" g.center_type, " + |
|||
" g.center_id, " + |
|||
" g.center_code, " + |
|||
" g.center_name, " + |
|||
" NULL, " + |
|||
" NULL, " + |
|||
" NULL, " + |
|||
" g.supplier_id, " + |
|||
" g.supplier_code, " + |
|||
" g.supplier_name, " + |
|||
" g.activity_id, " + |
|||
" g.activity_code, " + |
|||
" act.act_title, " + |
|||
" g.cost_apply_id, " + |
|||
" a.`code`, " + |
|||
" a.charge_theme, " + |
|||
" NULL, " + |
|||
" NULL, " + |
|||
" NULL, " + |
|||
" NULL, " + |
|||
" NULL, " + |
|||
" NULL, " + |
|||
" g.target_type, " + |
|||
" g.target_id, " + |
|||
" g.target_code, " + |
|||
" g.target_name, " + |
|||
" g.target_level_path_ids, " + |
|||
" g.target_level_path_names, " + |
|||
" '001', " + |
|||
" '0', " + |
|||
" NULL " + |
|||
"FROM " + |
|||
" tbs_activity_center_goods g " + |
|||
" LEFT JOIN tbs_budget b ON g.center_id = b.center_id " + |
|||
" LEFT JOIN tbs_budget_condition c ON b.id = c.budget_id AND g.target_level_path_ids LIKE CONCAT(c.target_level_path_ids, '_%') " + |
|||
" LEFT JOIN tbs_schedule_item_budget i ON b.id = i.budget_id AND g.act_start_date BETWEEN i.start_date AND i.end_date " + |
|||
" LEFT JOIN tbs_cost_apply a ON a.id = g.cost_apply_id " + |
|||
" LEFT JOIN tbs_activity act ON act.id = g.activity_id " + |
|||
"WHERE " + |
|||
" i.id IS NOT NULL " + |
|||
" AND c.id IS NOT NULL " + |
|||
" AND a.budget_sync =2"; |
|||
jslContext.sql(insertSql2).execute(); |
|||
|
|||
String lastUpdateSql = "UPDATE tbs_cost_apply a SET a.budget_sync = 1 where a.new_budget_sync != 3 and a.budget_sync = 2 and xlt_sync =2"; |
|||
jslContext.sql(lastUpdateSql).execute(); |
|||
|
|||
|
|||
} |
|||
} |
Loading…
Reference in new issue