insert into eam_properties_item_available (ItemNo,ValueNo,AvailableValue,CreatedDate,CreatedBy,ItemType)
values(#{itemNo},#{valueNo},#{availableValue},GetDate(),#{createdBy},#{itemType})
update eam_properties_item_available set AvailableValue=#{availableValue} where itemNo=#{itemNo} and ItemType=#{itemType} and ValueNo=#{valueNo}
delete from eam_properties_item_available where itemNo=#{itemNo} and ItemType=#{itemType} and ValueNo=#{valueNo}
insert into eam_properties_model_header
(function_type, code_no, code_desc, active, created_date, created_by, delflag, version, update_date, update_by)
values(#{functionType}, #{codeNo}, #{codeDesc}, #{active}, GetDate(), #{userId}, 'N', 0, getDate(), #{updateBy})
update eam_properties_model_header
set version = version + 1,
code_desc = #{codeDesc},
active = #{active},
update_by = #{updateBy},
update_date = GetDate()
where function_type = #{functionType}
and code_no = #{codeNo}
delete from eam_properties_model_header where function_type=#{functionType} and code_no=#{codeNo}
insert into eam_properties_model_detail
(function_type,code_no,properties_item_no,seq_no,created_date,created_by,delflag,version)
values (#{functionType}, #{codeNo}, #{itemNo}, #{seqNo}, GetDate(), #{userId}, 'N', 0)
delete from eam_properties_model_detail
where function_type = #{functionType}
and code_no = #{codeNo}
and properties_item_no = #{itemNo}
update eam_workPlan_item
set DefaultValue = #{defaultValue},
ValueType = #{valueType},
ValueType_DB = #{valueTypeDb},
ValueChooseFlag = #{valueChooseFlag},
UpdateDate = GetDate(),
UpdateBy = #{createdBy},
MaxValue = #{maxValue,jdbcType=FLOAT},
MinValue = #{minValue,jdbcType=FLOAT},
ItemRemark = #{itemRemark}
where site = #{site}
and planID = #{planID}
and ItemType = #{itemType}
and ItemNo = #{itemNo}
and ObjectID = #{objectID}
update eam_workPlan_item set DefaultValue=#{defaultValue},ValueType=#{valueType},ValueType_DB=#{valueTypeDb}
,ValueChooseFlag=#{valueChooseFlag},UpdateDate=GetDate(),UpdateBy=#{createdBy},MaxValue=null,MinValue=null,
ItemRemark=#{itemRemark}
where site=#{site} and planID=#{planID} and ItemType=#{itemType}
and ItemNo=#{itemNo}
insert into eam_workPlan_item_available
(Site,PlanID,ItemNo,ValueNo,AvailableValue,CreatedDate,CreatedBy,ItemType,ObjectID)
values(#{site},#{planID},#{itemNo},#{valueNo},#{availableValue},GetDate(),#{createdBy},#{itemType},#{objectID})
update eam_workPlan_item_available
set AvailableValue = #{availableValue},
updateBy = #{createdBy},
updateDate = GetDate()
where itemNo = #{itemNo} and ItemType = #{itemType} and ValueNo = #{valueNo} AND site = #{site} and planID = #{planID} and ObjectID = #{objectID}
delete from eam_workPlan_item_available
where itemNo=#{itemNo} and ItemType=#{itemType} and ValueNo=#{valueNo} AND site=#{site} and planID=#{planID} and ObjectID = #{objectID}
update eam_defect_feedBack
set Status = #{result},
FinishDate = GetDate(),
DefectID = #{defectID}
where Site = #{site}
and FeedBackID = #{planID}
update eam_workOrder
set Status = '待审核',
ActualOperator = #{actualOperator},
ActualDate = GetDate(),
Remark = #{remark},
disposal_measures = #{disposalMeasures},
WorkTime = #{workTime},
result = #{result,jdbcType=VARCHAR},
checkResult = #{checkResult}
where site = #{site}
and orderNo = #{orderNo}
update eam_workOrder
set Status = '已完工',
ActualOperator = #{actualOperator},
ActualDate = GetDate(),
Remark = #{remark},
disposal_measures = #{disposalMeasures},
WorkTime = #{workTime},
result = #{result,jdbcType=VARCHAR},
checkResult = #{checkResult}
where site = #{site}
and orderNo = #{orderNo}
INSERT into eam_workOrder_item
(Site,OrderNo,ItemNo,ItemDesc,DefaultValue,ValueType,ValueType_DB,ValueChooseFlag,MaxValue,MinValue,ItemRemark,ItemType,TextValue,NumberValue,CreatedDate,CreatedBy,FinishFlag,itemResult)
values (#{site},#{orderNo},#{itemNo},#{itemDesc},#{defaultValue},#{valueType},#{valueTypeDb},#{valueChooseFlag},#{maxValue,jdbcType=DOUBLE},#{minValue,jdbcType=DOUBLE},#{itemRemark,jdbcType=VARCHAR},#{itemType},#{textValue,jdbcType=VARCHAR},#{numberValue,jdbcType=DOUBLE},GetDate(),#{createdBy},#{finishFlag},#{itemResult})
update eam_workPlan
set status = '已结束'
where site = #{site}
and PlanID = #{planID}
and ObjectID = #{objectID}
and GetDate() > PlanEndDate
update eam_workPlan_overview
set next_work_date = (select top 1 PlanDate from eam_workOrder where site = #{site} and PlanID = #{planID} and PlanDate > GetDate() and status = '未开工' order by PlanDate)
where site = #{site} and plan_id = #{planID}
update eam_workOrder
set Status = '已取消'
where site = #{site}
and orderNo = #{orderNo}
update eam_workPlan
set Status = '已计划',
NextWorkDate = null
where site = #{site}
and PlanID = #{planID}
and deleteFlag = 'N'
update eam_workPlan_overview
set status = '已取消',
next_work_date = null
where site = #{site}
and plan_id = #{planID}
and delete_flag = 'N'
update eam_workPlan
set Status = '已取消',
NextWorkDate = null
where Site = #{site}
and PlanID = #{planID}
and deleteFlag = 'N'
update eam_workOrder
set Status = '已取消'
where site = #{site}
and PlanID = #{planID}
and status = '未开工'
delete from eam_workOrder_item
where site = #{site}
and OrderNo in (select OrderNo from eam_workOrder where site = #{site} and PlanID = #{planID} and status = '未开工' and PlanDate > GetDate() - 1 )
delete from eam_workOrder
where site = #{site}
and PlanID = #{planID}
and status = '未开工'
and PlanDate > GetDate() - 1
update eam_workOrder
set PlanOperator = #{planOperator}
where site = #{site} and orderNo = #{orderNo}
INSERT Into resource_spare (resource_id,part_no,delflag,version,site)
values(#{objectID},#{partNo},'',0,#{site})
delete from resource_spare
where resource_id = #{objectID}
and site = #{site}
INSERT Into resource_spare (resource_id,part_no,delflag,version,site)
select #{objectID},part_no,delflag,0,site from resource_spare where resource_id=#{oldObjectID} and site=#{site}
insert into eam_object_item (site,objectID,ItemNo,DefaultValue,ValueType,ValueType_DB,ValueChooseFlag,CreatedDate,CreatedBy,MaxValue,MinValue,
ItemType) values(#{site},#{objectID},#{itemNo},#{defaultValue},#{valueType},#{valueTypeDb},#{valueChooseFlag},GetDate(),#{userId},#{maxValue,jdbcType=DOUBLE},#{minValue,jdbcType=DOUBLE},#{itemType})
update eam_object_item set DefaultValue=#{defaultValue},ValueType=#{valueType},ValueType_DB=#{valueTypeDb}
,ValueChooseFlag=#{valueChooseFlag},MaxValue=#{maxValue,jdbcType=FLOAT},MinValue=#{minValue,jdbcType=FLOAT}
where site=#{site} and objectID=#{objectID} and ItemType=#{itemType}
and ItemNo=#{itemNo}
delete from eam_object_item where site=#{site} and objectID=#{objectID} and ItemType=#{itemType}
and ItemNo=#{itemNo}
insert into eam_object_item_available (Site,ObjectID,ItemNo,ItemType,ValueNo,AvailableValue,CreatedDate,CreatedBy)
select #{site},#{objectID},ItemNo,ItemType,ValueNo,AvailableValue,GetDate() ,#{userId} from eam_properties_item_available
where ItemNo=#{itemNo} and ItemType=#{itemType}
delete from eam_object_item_available where site=#{site} and objectID=#{objectID} and ItemType=#{itemType}
and ItemNo=#{itemNo}
insert into eam_object_item_available(Site,ObjectID,ItemNo,ItemType,ValueNo,AvailableValue,CreatedDate,CreatedBy)
values(#{site},#{objectID},#{itemNo},#{itemType},#{valueNo},#{availableValue},GetDate(),#{createdBy})
update eam_object_item_available set AvailableValue=#{availableValue},updateDate=GetDate(),updateBy=#{createdBy}
where site=#{site} and objectID=#{objectID} and ItemType=#{itemType} and ItemNo=#{itemNo} and ValueNo=#{valueNo}
delete from eam_object_item_available where site=#{site} and objectID=#{objectID} and ItemType=#{itemType} and ItemNo=#{itemNo} and ValueNo=#{valueNo}
delete from eam_object_item where site=#{site} and objectID=#{objectID} and ItemType=#{itemType}
delete from eam_object_item_available where site=#{site} and objectID=#{objectID} and ItemType=#{itemType}
insert into eam_object_item (site,objectID,ItemNo,DefaultValue,ValueType,ValueType_DB,ValueChooseFlag,CreatedDate,CreatedBy,MaxValue,MinValue,
ItemType)
select #{site},#{objectID},ItemNo,DefaultValue,ValueType,ValueType_DB,ValueChooseFlag,GetDate(),#{createBy},MaxValue,MinValue,ItemType
from eam_object_item where site=#{site} and objectID=#{oldObjectID} and ItemType=#{itemType}
insert into eam_object_item_available(Site,ObjectID,ItemNo,ItemType,ValueNo,AvailableValue,CreatedDate,CreatedBy)
select #{site},#{objectID},ItemNo,ItemType,ValueNo,AvailableValue,GetDate(),#{createBy}
from eam_object_item_available where site=#{site} and objectID=#{oldObjectID} and ItemType=#{itemType}
delete from eam_object_defect where site=#{site} and objectID=#{objectID}
insert into eam_object_defect(site,ObjectID,DefectID,Active)
select #{site},#{objectID},DefectID,Active
from eam_object_defect where site=#{site} and objectID=#{oldObjectID}
update eam_defect_feedBack set status='已取消' where FeedBackID=#{feedBackID} and site=#{site}
update eam_defect_feedBack
set status = '已下达',
PlanOperator = #{planOperator},
UpdateDate = GetDate(),
UpdateBy = #{updateBy}
where FeedBackID = #{feedBackID}
and site = #{site}
INSERT INTO eam_workOrder
(Site, OrderNo, PlanID, PropertiesCode, ObjectID, Status, PlanOperator, PlanDate, FunctionType, CreateDate, CreateBy)
values(#{site}, (select 'X'+ Right( '0000000000'+ convert(VARCHAR(10),isnull(max(convert(INT,SUBSTRING(OrderNo,3,10))),0)+1),8) from eam_workOrder where site=#{site} and FunctionType='C' ), #{feedBackID}, '', #{objectID}, '未开工', #{planOperator}, #{planDate}, 'C', GetDate(), #{userId})
delete from sys_oss where id = #{id}
UPDATE eam_workOrder
SET Status = '已完工'
WHERE Site = #{site}
AND OrderNo = #{orderNo}
UPDATE eam_workOrder
SET Status = '待审核'
WHERE Site = #{site}
AND OrderNo = #{orderNo}
UPDATE eam_workPlan_overview
SET status = '已结束'
WHERE site = #{site}
AND plan_id = #{planID}
INSERT INTO eam_workPlan_overview
(site, plan_id, plan_desc, status, plan_start_date, plan_end_date, created_date, created_by, update_date, update_by, remark, delete_flag, operator, operator_name, checker, checker_name, function_type, properties_code, plan_period, work_order_rule, plan_cycle)
VALUES (#{site}, #{planID}, #{planDesc}, '已计划', #{planStartDate}, #{planEndDate}, getDate(), #{createdBy}, getDate(), #{updateBy}, #{remark}, 'N', #{operator}, #{operatorName}, #{checker}, #{checkerName}, #{functionType}, #{propertiesCode}, #{planPeriod}, #{workOrderRule}, #{planCycle})
DELETE FROM eam_workPlan
WHERE Site = #{site}
AND PlanID = #{planID}
AND ObjectID = #{objectID}
INSERT INTO eam_workPlan
(Site,PlanID,PlanDesc,ObjectID,FunctionType,PropertiesCode,Operator,OperatorName,checker,checkerName,PlanPeriod,Status,PlanStartDate,PlanEndDate,CreatedDate,CreatedBy,Version,Remark,DeleteFlag)
values (#{site},#{planID},#{planDesc},#{objectID},#{functionType},#{propertiesCode},#{operator},#{operatorName},#{checker},#{checkerName},#{planPeriod},#{status},#{planStartDate},#{planEndDate},GetDate(),#{createdBy},0,#{remark},'N')
UPDATE eam_workPlan_overview
SET plan_desc = #{planDesc},
properties_code = #{propertiesCode},
plan_start_date = #{planStartDate},
plan_end_date = #{planEndDate},
plan_period = #{planPeriod},
remark = #{remark},
operator = #{operator},
operator_name = #{operatorName},
checker = #{checker},
checker_name = #{checkerName},
work_order_rule = #{workOrderRule}
WHERE site = #{site}
AND plan_id = #{planID}
AND function_type = #{functionType}
DELETE FROM eam_workPlan
WHERE Site = #{site}
AND PlanID = #{planID}
DELETE FROM eam_workPlan_item
WHERE Site = #{site}
AND PlanID = #{planID}
DELETE FROM eam_workPlan_item_available
WHERE Site = #{site}
AND PlanID = #{planID}
AND ObjectID = #{objectID}
UPDATE eam_workPlan_overview
SET status = '进行中',
next_work_date = #{planStartDate}
WHERE site = #{site}
AND plan_id = #{planID}
INSERT INTO eam_actual_operator
(site, order_no, function_type, operator)
VALUES (#{site}, #{orderNo}, #{functionType}, #{operator})
INSERT INTO eam_workOrder
(Site, OrderNo, PlanID, PropertiesCode, ObjectID, Status, PlanDate, FunctionType, CreateDate, CreateBy)
VALUES (#{site}, (select 'X' + Right('0000000000'+ convert(VARCHAR(10),isnull(max(convert(INT,SUBSTRING(OrderNo,3,10))),0)+1),8) from eam_workOrder where site = #{site} and FunctionType = 'C'),
#{planID}, '', #{objectID}, '未开工', getDate(), 'C', getDate(), #{createBy})
INSERT INTO eam_workOrder
(Site, OrderNo, PlanID, PlanDesc, PropertiesCode, ObjectID, Status, PlanOperator, PlanDate, FunctionType, CreateDate, CreateBy, checker, PlanOperatorName, checkerName)
VALUES (#{site}, (select 'W' + Right( '0000000000'+ convert(VARCHAR(10),isnull(max(convert(INT,SUBSTRING(OrderNo,3,10))),0)+1),8) from eam_workOrder where site = #{site} and FunctionType = 'B'),
#{planID}, #{planDesc}, #{propertiesCode}, #{objectID}, '未开工', #{planOperator}, Dateadd(dd, Datediff(dd,0,Getdate()), 0), #{functionType}, getDate(), #{createBy}, #{checker}, #{planOperatorName}, #{checkerName})
UPDATE eam_workOrder
SET Status = '已完工',
difficulty_level = #{difficultyLevel},
difficulty_remark = #{difficultyRemark}
WHERE Site = #{site}
AND OrderNo = #{orderNo}
INSERT INTO eam_admin_dept
(Site, admin_id, dept_id)
VALUES (#{site}, #{adminID}, #{deptId})
DELETE FROM eam_admin_dept
WHERE site = #{site}
AND admin_id = #{adminID}
DELETE FROM sys_oss
WHERE id = #{id}
INSERT INTO eam_workOrder
(Site, OrderNo, PlanID, PlanDesc, PropertiesCode, ObjectID, Status, PlanOperator, PlanDate, FunctionType,CreateDate, CreateBy, checker, PlanOperatorName, checkerName)
VALUES (#{site}, #{orderNo}, #{planID}, #{planDesc}, #{propertiesCode}, #{objectID}, '未开工', #{operator}, #{planStartDate}, #{functionType}, getDate(), #{userId}, #{checker}, #{operatorName}, #{checkerName})
INSERT INTO eam_workOrder
(Site, OrderNo, PlanID, PlanDesc, PropertiesCode, ObjectID, Status, PlanOperator, PlanDate, FunctionType,CreateDate, CreateBy, checker, PlanOperatorName, checkerName)
VALUES (#{site}, #{orderNo}, #{planID}, #{planDesc}, #{propertiesCode}, #{objectID}, '未开工', #{operator}, #{orderDate}, #{functionType}, getDate(), #{userId}, #{checker}, #{operatorName}, #{checkerName})
update eam_workPlan
set status = '进行中',
NextWorkDate = PlanStartDate
where site = #{site}
and PlanID = #{planID}
and FunctionType = #{functionType}
and ObjectID = #{objectID}