<?xml version="1.0" encoding="utf-8"?>

<databaseChangeLog
		xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
        http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
	<changeSet author="suhuiguang" id="1628836692856-1" runOnChange="true">
		<sql endDelimiter="#">
			DROP PROCEDURE IF EXISTS `updatePlanTask`#
			CREATE PROCEDURE `updatePlanTask`(IN `planTaskId` int,IN `pointId` int,IN `planTaskDetailId` int,IN `executorId` bigint)
			BEGIN
			declare num int ;
			declare orgCode VARCHAR(50) ;
			declare currentTaskNum int ;
			update p_plan_task_detail set is_finish = 1 where id=planTaskDetailId;
			select finish_num, org_code from p_plan_task where id = planTaskId into num, orgCode;
			select count(1) into currentTaskNum from p_plan_task_detail where task_no = planTaskId and is_finish in(0,2);
			UPDATE p_plan_task_detail SET executor_id = executorId,executor_date = current_timestamp where id = planTaskDetailId;
			if currentTaskNum > 0 THEN
			update p_plan_task set finish_num = (num + 1) where id = planTaskId;
			ELSE
			update p_plan_task set finish_num = (num + 1), finish_status = 2 where id = planTaskId;
			end if;
			END#
		</sql>
	</changeSet>
	<changeSet author="suhuiguang" id="1629352951339-1" runOnChange="true">
		<sql>
			DROP TRIGGER  IF EXISTS `addPointConfig`;
			DROP TRIGGER  IF EXISTS `updatePointConfig`;
			DROP TRIGGER  IF EXISTS `updatePointConfig`;
		</sql>
	</changeSet>
</databaseChangeLog>