健腾mes后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

2760 lines
120 KiB

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.jianteng.modules.pms.mapper.EamMapper">
<select id="eamAdminSearch" parameterType="com.jianteng.modules.pms.data.EamAdminData" resultType="com.jianteng.modules.pms.data.EamAdminData">
SELECT distinct
ea.Site,
ea.AdminID,
ea.AdminName,
ea.Phone,
ea.Email,
ea.Tel,
ea.LevelID,
eal.AdminLevelDesc,
ea.MesUser,
ea.Active,
ea.CreatedDate,
ea.created_by,
ea.update_date,
ea.update_by
FROM eam_admin as ea
LEFT JOIN eam_adminLevel as eal ON ea.LevelID = eal.AdminLevelID and ea.site = eal.site
left join eam_admin_dept as ead on ea.site = ead.site and ea.AdminID = ead.admin_id
LEFT JOIN sys_department as ved ON ead.site = ved.site and ead.dept_id = ved.department_id
<where>
<if test="query.site != null and query.site != ''">
AND ea.site = #{query.site}
</if>
<if test="query.adminID != null and query.adminID != ''">
AND ea.adminID like '%' + #{query.adminID} +'%'
</if>
<if test="query.adminName != null and query.adminName != ''">
AND ea.adminName like '%' + #{query.adminName}+'%'
</if>
<if test="query.departmentName != null and query.departmentName != ''">
AND ved.department_name like '%' + #{query.departmentName}+'%'
</if>
<if test="query.active != null and query.active != ''">
AND ea.active = #{query.active}
</if>
</where>
</select>
<select id="eamAdminSearch2" parameterType="com.jianteng.modules.pms.data.EamAdminData" resultType="com.jianteng.modules.pms.data.EamAdminData">
SELECT distinct
ea.Site,
ea.bu_no,
dbo.get_bu_desc(ea.Site, ea.bu_no) as buDesc,
ea.AdminID,
ea.AdminName,
ea.Phone,
ea.Email,
ea.Tel,
ea.LevelID,
eal.AdminLevelDesc,
ea.MesUser,
ea.Active,
ea.CreatedDate,
ea.created_by,
ea.update_date,
ea.update_by
FROM eam_admin as ea
LEFT JOIN eam_adminLevel as eal ON ea.LevelID = eal.AdminLevelID and ea.site = eal.site and ea.bu_no = eal.bu_no
left join eam_admin_dept as ead on ea.site = ead.site and ea.AdminID = ead.admin_id and ea.bu_no = ead.bu_no
LEFT JOIN sys_department as ved ON ead.site = ved.site and ead.dept_id = ved.department_id and ead.bu_no = ved.bu_no
<where>
ea.site in (select site from eam_access_site where username = #{userName})
and (ea.site + '-' + ea.bu_no) in (select * from dbo.query_bu(#{query.userName}))
<if test="adminID != null and adminID != ''">
AND ea.adminID like '%' + #{adminID} +'%'
</if>
<if test="adminName != null and adminName != ''">
AND ea.adminName like '%' + #{adminName}+'%'
</if>
<if test="departmentName != null and departmentName != ''">
AND ved.department_name like '%' + #{departmentName}+'%'
</if>
<if test="active != null and active != ''">
AND ea.active = #{active}
</if>
</where>
</select>
<select id="eamFamilySearch" parameterType="com.jianteng.modules.pms.data.EamFamilyData" resultType="com.jianteng.modules.pms.data.EamFamilyData">
SELECT
Site,
bu_no,
dbo.get_bu_desc(site, bu_no) as buDesc,
FamilyID,
FamilyDesc,
Active,
create_date,
create_by,
update_date,
update_by
FROM eam_family
<where>
site in (select site from eam_access_site where username = #{query.userName})
and (site + '-' + bu_no) in (select * from dbo.query_bu(#{query.userName}))
<if test="query.buDesc != null and query.buDesc != ''">
AND dbo.get_bu_desc ( site, bu_no ) = #{query.buDesc}
</if>
<if test="query.familyID != null and query.familyID != ''">
AND familyID like '%' + #{query.familyID} +'%'
</if>
<if test="query.familyDesc != null and query.familyDesc != ''">
AND familyDesc like '%' + #{query.familyDesc} +'%'
</if>
<if test="query.active != null and query.active != ''">
AND active = #{query.active}
</if>
</where>
</select>
<select id="eamGroupSearch" parameterType="com.jianteng.modules.pms.data.EamGroupData" resultType="com.jianteng.modules.pms.data.EamGroupData">
SELECT
Site,
bu_no,
dbo.get_bu_desc(site, bu_no) as buDesc,
GroupID,
GroupDesc,
Active,
create_date,
create_by,
update_date,
update_by
FROM eam_group
<where>
site in (select site from eam_access_site where username = #{query.userName})
and (site + '-' + bu_no) in (select * from dbo.query_bu(#{query.userName}))
<if test="query.buDesc != null and query.buDesc != ''">
AND dbo.get_bu_desc ( site, bu_no ) = #{query.buDesc}
</if>
<if test="query.groupID != null and query.groupID != ''">
AND groupID like '%' + #{query.groupID} + '%'
</if>
<if test="query.groupDesc != null and query.groupDesc != ''">
AND groupDesc like '%' + #{query.groupDesc} + '%'
</if>
<if test="query.active != null and query.active != ''">
AND active = #{query.active}
</if>
</where>
</select>
<select id="eamLocationSearch" parameterType="com.jianteng.modules.pms.data.EamLocationData" resultType="com.jianteng.modules.pms.data.EamLocationData">
SELECT
Site,
bu_no,
dbo.get_bu_desc(site, bu_no) as buDesc,
LocationID,
LocationName,
Active,
create_date,
create_by,
update_date,
update_by
FROM eam_location
<where>
site in (select site from eam_access_site where username = #{query.userName})
and (site + '-' + bu_no) in (select * from dbo.query_bu(#{query.userName}))
<if test="query.buDesc != null and query.buDesc != ''">
AND dbo.get_bu_desc ( site, bu_no ) = #{query.buDesc}
</if>
<if test="query.locationID != null and query.locationID != ''">
AND locationID like '%' + #{query.locationID} +'%'
</if>
<if test="query.locationName != null and query.locationName != ''">
AND locationName like '%' + #{query.locationName} +'%'
</if>
<if test="query.active != null and query.active != ''">
AND active = #{query.active}
</if>
</where>
</select>
<select id="eamManufacturerSearch" parameterType="com.jianteng.modules.pms.data.EamManufacturerData" resultType="com.jianteng.modules.pms.data.EamManufacturerData">
SELECT
Site,
bu_no,
dbo.get_bu_desc(site, bu_no) as buDesc,
ManufacturerID,
ManufacturerName,
Active,
Contact,
Phone,
Address,
Email,
Remark,
create_date,
create_by,
update_date,
update_by
FROM eam_manufacturer
<where>
site in (select site from eam_access_site where username = #{query.userName})
and (site + '-' + bu_no) in (select * from dbo.query_bu(#{query.userName}))
<if test="query.buDesc != null and query.buDesc != ''">
AND dbo.get_bu_desc ( site, bu_no ) = #{query.buDesc}
</if>
<if test="query.manufacturerID != null and query.manufacturerID != ''">
AND manufacturerID like '%' + #{query.manufacturerID} +'%'
</if>
<if test="query.manufacturerName != null and query.manufacturerName != ''">
AND manufacturerName like '%' + #{query.manufacturerName} +'%'
</if>
<if test="query.active != null and query.active != ''">
AND active = #{query.active}
</if>
</where>
</select>
<select id="eamAdminLevelSearch" parameterType="com.jianteng.modules.pms.data.EamAdminLevelData" resultType="com.jianteng.modules.pms.data.EamAdminLevelData">
SELECT
Site,
bu_no,
dbo.get_bu_desc(site, bu_no) as buDesc,
AdminLevelID,
AdminLevelDesc,
Active,
create_date,
create_by,
update_date,
update_by
FROM eam_adminLevel
<where>
site in (select site from eam_access_site where username = #{query.userName})
and (site + '-' + bu_no) in (select * from dbo.query_bu(#{query.userName}))
<if test="query.buDesc != null and query.buDesc != ''">
AND dbo.get_bu_desc ( site, bu_no ) = #{query.buDesc}
</if>
<if test="query.adminLevelID != null and query.adminLevelID != ''">
AND adminLevelID like '%' + #{query.adminLevelID} +'%'
</if>
<if test="query.adminLevelDesc != null and query.adminLevelDesc != ''">
AND adminLevelDesc like '%' + #{query.adminLevelDesc}+'%'
</if>
<if test="query.active != null and query.active != ''">
AND active = #{query.active}
</if>
</where>
</select>
<select id="eamSupplierSearch" parameterType="com.jianteng.modules.pms.data.EamSupplierData" resultType="com.jianteng.modules.pms.data.EamSupplierData">
SELECT
Site,
bu_no,
dbo.get_bu_desc(site, bu_no) as buDesc,
SupplierID,
SupplierName,
[Group],
Active,
Contact,
Phone,
Address,
Email,
Remark,
create_date,
create_by,
update_date,
update_by
FROM eam_supplier
<where>
site in (select site from eam_access_site where username = #{query.userName})
and (site + '-' + bu_no) in (select * from dbo.query_bu(#{query.userName}))
<if test="query.buDesc != null and query.buDesc != ''">
AND dbo.get_bu_desc ( site, bu_no ) = #{query.buDesc}
</if>
<if test="query.supplierID != null and query.supplierID != ''">
AND supplierID like '%' + #{query.supplierID} +'%'
</if>
<if test="query.supplierName != null and query.supplierName != ''">
AND supplierName like '%' + #{query.supplierName} +'%'
</if>
<if test="query.active != null and query.active != ''">
AND active = #{query.active}
</if>
</where>
</select>
<select id="searchItemAvailable" resultType="com.jianteng.modules.pms.data.EamPropertiesItemAvailableData">
SELECT
site,
bu_no,
ItemNo,
ValueNo,
AvailableValue,
CreatedDate,
CreatedBy,
ItemType
from eam_properties_item_available
where itemNo = #{itemNo} and ItemType = #{itemType} and site = #{site} and bu_no = #{buNo}
</select>
<select id="getItemValueNo" resultType="Double">
SELECT isnull( max(valueNo),0)+1 from eam_properties_item_available where itemNo = #{itemNo} and ItemType = #{itemType} and site = #{site} and bu_no = #{buNo}
</select>
<select id="getItemValueNoForPlan" resultType="Double">
SELECT isnull( max(valueNo),0)+1 from eam_workPlan_item_available where itemNo = #{itemNo} and ItemType = #{itemType} and site = #{site} and PlanID = #{planID} and bu_no = #{buNo}
</select>
<insert id="saveItemAvailable">
insert into eam_properties_item_available (ItemNo, ValueNo, AvailableValue, CreatedDate, CreatedBy, ItemType, site, bu_no)
values(#{itemNo}, #{valueNo}, #{availableValue}, GetDate(), #{createdBy}, #{itemType}, #{site}, #{buNo})
</insert>
<update id="updateItemAvailable">
update eam_properties_item_available
set AvailableValue = #{availableValue}
where itemNo = #{itemNo} and ItemType = #{itemType} and ValueNo = #{valueNo} and site = #{site} and bu_no = #{buNo}
</update>
<delete id="deleteItemAvailable">
delete from eam_properties_item_available where itemNo = #{itemNo} and ItemType = #{itemType} and ValueNo = #{valueNo} and site = #{site} and bu_no = #{buNo}
</delete>
<select id="eamPropertiesModelSearch" parameterType="com.jianteng.modules.pms.data.EamPropertiesModelHeaderData" resultType="com.jianteng.modules.pms.data.EamPropertiesModelHeaderData">
SELECT
site,
bu_no,
dbo.get_bu_desc(site, bu_no) as buDesc,
function_type,
code_no,
code_desc,
active,
created_date,
created_by,
update_date,
update_by,
delflag,
version,
CASE WHEN dbo.eam_model_is_use(site, function_type, code_no) > 0 THEN 'Y'
else 'N'
END as isUse
FROM eam_properties_model_header
<where>
site in (select site from eam_access_site where username = #{query.userName})
and (site + '-' + bu_no) in (select * from dbo.query_bu(#{query.userName}))
<if test="query.buDesc != null and query.buDesc != ''">
AND dbo.get_bu_desc ( site, bu_no ) = #{query.buDesc}
</if>
<if test="query.codeNo != null and query.codeNo != ''">
AND code_no like '%' + #{query.codeNo} +'%'
</if>
<if test="query.codeDesc != null and query.codeDesc != ''">
AND code_desc like '%' + #{query.codeDesc} +'%'
</if>
<if test="query.active != null and query.active != ''">
AND active = #{query.active}
</if>
<if test='query.isUse != null and query.isUse != "" and query.isUse == "Y"'>
AND dbo.eam_model_is_use(site, function_type, code_no) > 0
</if>
<if test='query.isUse != null and query.isUse != "" and query.isUse == "N"'>
AND dbo.eam_model_is_use(site, function_type, code_no) = 0
</if>
and function_type = #{query.functionType}
</where>
</select>
<insert id="eamPropertiesModelSave" >
insert into eam_properties_model_header
(function_type, code_no, code_desc, active, created_date, created_by, delflag, version, update_date, update_by, site, bu_no)
values (#{functionType}, #{codeNo}, #{codeDesc}, #{active}, GetDate(), #{userId}, 'N', 0, getDate(), #{updateBy}, #{site}, #{buNo})
</insert>
<update id="eamPropertiesModelEdit">
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} and site = #{site} and bu_no = #{buNo}
</update>
<select id="checkPropertiesModel" resultType="EamPropertiesModelHeaderData">
SELECT
function_type,
code_no,
code_desc,
active,
created_date,
created_by,
update_date,
update_by,
delflag,
version
FROM eam_properties_model_header
where function_type = #{functionType} and code_no = #{codeNo} and site = #{site} and bu_no = #{buNo}
</select>
<delete id="deleteModelDetail">
delete from eam_properties_model_detail
where function_type = #{functionType} and code_no = #{codeNo} and site = #{site} and bu_no = #{buNo}
</delete>
<delete id="eamPropertiesModelDelete" >
delete from eam_properties_model_header where function_type = #{functionType} and code_no = #{codeNo} and site = #{site} and bu_no = #{buNo}
</delete>
<select id="searchModalDetails" resultType="EamPropertiesModelDetailData">
SELECT
a.site,
a.bu_no,
a.function_type,
a.code_no,
a.properties_item_no itemNo,
a.seq_no,
b.ItemDesc,
b.DefaultValue,
b.ValueType,
b.ValueType_DB,
b.ValueChooseFlag,
b.MaxValue,
b.MinValue,
b.ItemRemark,
b.ItemType
FROM eam_properties_model_detail a
left join eam_properties_item b on a.function_type = b.itemType and a.properties_item_no = b.itemNo and a.site = b.site and a.bu_no = b.bu_no
where a.function_type = #{functionType} and a.code_no = #{codeNo} and a.site = #{site} and a.bu_no = #{buNo}
</select>
<select id="checkItem" resultType="EamPropertiesModelDetailData">
SELECT
ItemDesc
FROM eam_properties_item
where itemType = #{functionType} and itemNo = #{itemNo} and site = #{site} and bu_no = #{buNo}
</select>
<select id="checkModalDetails" resultType="EamPropertiesModelDetailData">
SELECT
site,
bu_no,
function_type,
code_no,
properties_item_no itemNo,
seq_no
FROM eam_properties_model_detail
where function_type = #{functionType} and code_no = #{codeNo} and properties_item_no = #{itemNo} and site = #{site} and bu_no = #{buNo}
</select>
<select id="getModalDetailSeqNo" resultType="Integer">
SELECT
isnull(max(seq_no),0) + 1
from eam_properties_model_detail
where function_type = #{functionType} and code_no = #{codeNo} and site = #{site} and bu_no = #{buNo}
</select>
<insert id="saveModalDetails">
insert into eam_properties_model_detail
(function_type, code_no, properties_item_no, seq_no, created_date, created_by, delflag, version, site, bu_no)
values (#{functionType}, #{codeNo}, #{itemNo}, #{seqNo}, GetDate(), #{userId}, 'N', 0, #{site}, #{buNo})
</insert>
<delete id="deleteModalDetails">
delete from eam_properties_model_detail
where function_type = #{functionType} and code_no = #{codeNo} and properties_item_no = #{itemNo} and site = #{site} and bu_no = #{buNo}
</delete>
<select id="eamWorkPlanOverviewSearch" parameterType="com.jianteng.modules.pms.data.EamWorkPlanInData" resultType="com.jianteng.modules.pms.data.EamWorkPlanInData">
SELECT
a.site,
a.bu_no,
dbo.get_bu_desc(a.site, a.bu_no) as buDesc,
a.plan_id,
a.plan_desc,
a.status,
a.plan_start_date,
a.plan_end_date,
a.created_date,
a.created_by,
a.update_date,
a.update_by,
a.remark,
a.next_work_date,
a.delete_flag,
a.operator,
a.operator_name,
a.checker,
a.checker_name,
a.function_type,
a.properties_code,
a.plan_period,
d.code_desc,
a.work_order_rule,
a.plan_cycle,
a.task_start_date,
a.plan_halt_date,
a.auto_renewal
FROM eam_workPlan_overview as a
LEFT JOIN eam_properties_model_header as d ON a.site = d.site and a.function_type = d.function_type and a.properties_code = d.code_no and a.bu_no = d.bu_no
<where>
a.site in (select site from eam_access_site where username = #{query.userName})
and (a.site + '-' + a.bu_no) in (select * from dbo.query_bu(#{query.userName}))
and a.delete_flag = 'N' AND a.function_type = #{query.functionType}
<if test="query.buDesc != null and query.buDesc != ''">
AND dbo.get_bu_desc ( a.site, a.bu_no ) = #{query.buDesc}
</if>
<if test="query.planID != null and query.planID != ''">
AND a.plan_id like '%' + #{query.planID} +'%'
</if>
<if test="query.planDesc != null and query.planDesc != ''">
AND a.plan_desc like '%' + #{query.planDesc}+'%'
</if>
<if test="query.status != null and query.status != ''">
AND a.status = #{query.status}
</if>
<if test="query.startDate != null ">
AND a.plan_start_date >= #{query.startDate}
</if>
<if test="query.endDate != null ">
AND #{query.endDate} >= a.plan_start_date
</if>
</where>
ORDER BY a.created_date DESC
</select>
<select id="eamWorkPlanSearch" parameterType="com.jianteng.modules.pms.data.EamWorkPlanInData" resultType="com.jianteng.modules.pms.data.EamWorkPlanInData">
SELECT
a.Site,
a.PlanID,
a.PlanDesc,
a.ObjectID,
a.FunctionType,
a.PropertiesCode,
a.Operator,
a.checker,
a.PlanPeriod,
a.Status,
a.PlanStartDate,
a.PlanEndDate,
a.CreatedDate,
a.CreatedBy,
a.UpdateDate,
a.UpdateBy,
a.Version,
a.Remark,
a.NextWorkDate,
b.ObjectDesc,
d.code_desc
FROM eam_workPlan a
left join eam_object b on a.Site = b.Site and a.ObjectID = b.ObjectID
left join eam_properties_model_header d on a.FunctionType = d.function_type and a.PropertiesCode = d.code_no
<where>
AND a.DeleteFlag = 'N'
AND a.FunctionType = #{query.functionType}
<if test="query.planID != null and query.planID != ''">
AND a.PlanID like '%' + #{query.planID} +'%'
</if>
<if test="query.planDesc != null and query.planDesc != ''">
AND a.PlanDesc like '%' + #{query.planDesc}+'%'
</if>
<if test="query.status != null and query.status != ''">
AND a.status = #{query.status}
</if>
<if test="query.startDate != null ">
AND a.PlanStartDate >= #{query.startDate}
</if>
<if test="query.endDate != null ">
AND #{query.endDate} >= a.PlanStartDate
</if>
</where>
</select>
<select id="selectNameById" resultType="string" parameterType="string">
SELECT
AdminName
FROM eam_admin
WHERE AdminID = #{s}
</select>
<select id="searchPlanItems" resultType="com.jianteng.modules.pms.data.EamWorkPlanItemData">
SELECT
a.Site,
a.bu_no,
a.PlanID,
a.ItemNo,
a.ItemDesc,
a.DefaultValue,
a.ValueType,
a.ValueType_DB,
a.ValueChooseFlag,
a.UpdateDate,
a.UpdateBy,
a.MaxValue,
a.MinValue,
a.ItemRemark,
a.ItemType,
a.CreatedDate,
a.CreatedBy,
a.ObjectID
FROM eam_workPlan_item a
<where>
a.PlanID = #{planID} and a.Site = #{site} and a.ItemType = #{functionType} and bu_no = #{buNo}
<if test = "objectID != null and objectID != ''">
AND a.ObjectID = #{objectID}
</if>
</where>
</select>
<select id="searchPlanItemAvailable" resultType="com.jianteng.modules.pms.data.EamWorkPlanItemAvailableData">
SELECT
Site,
bu_no,
PlanID,
ItemNo,
ItemType,
ValueNo,
AvailableValue,
CreatedDate,
CreatedBy,
UpdateDate,
UpdateBy,
ObjectID
from eam_workPlan_item_available
where PlanID = #{planID} and itemNo = #{itemNo} and site = #{site} and ItemType = #{itemType} and ObjectID = #{objectID} and bu_no = #{buNo}
</select>
<update id="updatePlanItems">
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} and bu_no = #{buNo}
</update>
<update id="updatePlanItemsForNull">
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}
</update>
<insert id="saveItemAvailableForPlan">
insert into eam_workPlan_item_available
(Site, PlanID, ItemNo, ValueNo, AvailableValue, CreatedDate, CreatedBy, ItemType, ObjectID, bu_no)
values(#{site}, #{planID}, #{itemNo}, #{valueNo}, #{availableValue}, GetDate(), #{createdBy}, #{itemType}, #{objectID}, #{buNo})
</insert>
<update id="updateItemAvailableForPlan">
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} and bu_no = #{buNo}
</update>
<delete id="deletePlanItemAvailable">
delete from eam_workPlan_item_available
where itemNo = #{itemNo} and ItemType = #{itemType} and ValueNo = #{valueNo} AND site = #{site} and planID = #{planID} and ObjectID = #{objectID} and bu_no = #{buNo}
</delete>
<select id="objectIDBlur" resultType="com.jianteng.modules.pms.data.EamObjectData">
select objectID,ObjectDesc from eam_object where active='Y' and Site=#{site} and ObjectID=#{objectID}
</select>
<select id="modalCodeBlur" resultType="com.jianteng.modules.pms.data.EamPropertiesModelHeaderData">
select code_no,code_desc from eam_properties_model_header where active = 'Y' and function_type = #{functionType} and code_no = #{codeNo}
</select>
<select id="eamWorkOrderSearch" parameterType="com.jianteng.modules.pms.data.EamWorkOrderInData" resultType="com.jianteng.modules.pms.data.EamWorkOrderInData">
SELECT
a.Site,
a.bu_no,
dbo.get_bu_desc(a.site, a.bu_no) as buDesc,
a.OrderNo,
a.PlanID,
a.PlanDesc,
a.PropertiesCode,
a.ObjectID,
a.Status,
a.PlanOperator,
a.checker,
a.ActualOperator,
a.PlanDate,
a.ActualDate,
a.FunctionType,
a.CreateDate,
d.operatorName as createBy,
a.Remark,
a.StartTime,
a.EndTime,
a.WorkTime,
a.PlanOperatorName,
a.checkerName,
dbo.eam_Get_eamAdminName(a.Site, a.ActualOperator) ActualOperatorName,
dbo.eam_Get_eamObjectDesc(a.Site, a.bu_no, a.ObjectID) objectDesc,
dbo.eam_Get_eam_properties_CodeDesc(a.site, a.bu_no, a.FunctionType, a.PropertiesCode) codeDesc,
a.result,
b.urgency,
a.checkResult,
b.DefectID,
c.DefectDesc,
a.disposal_measures,
a.check_work_plan_id,
a.check_item_no,
a.reach_date,
a.reach_operator,
a.reach_operator_name,
b.FeedBackDesc,
dbo.joint_id(a.Site, a.bu_no, a.OrderNo, a.FunctionType) as adminID,
dbo.joint_name(a.Site, a.bu_no, a.OrderNo, a.FunctionType) as operator,
a.check_remark,
a.document_source
FROM eam_workOrder a
LEFT JOIN eam_defect_feedBack b on a.site = b.site and a.PlanID = b.feedBackID and a.bu_no = b.bu_no
LEFT JOIN eam_defect c on b.DefectID = c.DefectID
LEFT JOIN operator as d on a.site = d.site and a.CreateBy = d.operatorID and d.active = 'Y'
left join eam_object as eo on eo.site = a.site and eo.ObjectID = a.ObjectID and eo.bu_no = a.bu_no
left join sys_department as sd ON eo.site = sd.site and eo.dept_id = sd.department_id and eo.bu_no = sd.bu_no
left join Access_dept as ead ON ead.site = sd.site and ead.department_id = sd.department_id and ead.bu_no = sd.bu_no
left join sys_user as ea on ead.username = ea.username
left join eam_workPlan_overview as ewo on a.site = ewo.site and a.PlanID = ewo.plan_id and a.bu_no = ewo.bu_no
<where>
a.site in (select site from eam_access_site where username = #{query.userName})
and (a.site + '-' + a.bu_no) in (select * from dbo.query_bu(#{query.userName}))
and ea.username = #{query.userName}
<if test="query.buDesc != null and query.buDesc != ''">
AND dbo.get_bu_desc ( a.site, a.bu_no ) = #{query.buDesc}
</if>
<if test="query.orderNo != null and query.orderNo != ''">
AND a.OrderNo like '%' + #{query.orderNo} +'%'
</if>
<if test="query.planID != null and query.planID != ''">
AND a.PlanID like '%' + #{query.planID} +'%'
</if>
<if test="query.planDesc != null and query.planDesc != ''">
AND a.PlanDesc like '%' + #{query.planDesc} +'%'
</if>
<if test="query.objectID != null and query.objectID != ''">
AND a.ObjectID like '%' + #{query.objectID} +'%'
</if>
<if test="query.planOperatorName != null and query.planOperatorName != ''">
AND a.PlanOperatorName like '%' + #{query.planOperatorName} +'%'
</if>
<if test='(query.status == null || query.status == "") and query.functionType == "A" and query.searchType == "checkOrder" '>
AND a.status != '已取消'
</if>
<if test='query.status != null and query.status != "" and query.functionType == "A" and query.searchType == "checkOrder" '>
AND a.status = #{query.status}
</if>
<if test='query.functionType == "A" and query.searchType == "reportCheck" '>
AND a.status = '未开工'
</if>
<if test='(query.status == null || query.status == "") and query.functionType == "B" and query.searchType == "maintenanceOrder" '>
AND a.status != '已取消'
</if>
<if test='query.status != null and query.status != "" and query.functionType == "B" and query.searchType == "maintenanceOrder" '>
AND a.status = #{query.status}
</if>
<if test='query.functionType == "B" and query.searchType == "reportMaintenance" '>
AND (a.status = '未开工' or a.status = '已到达')
</if>
<if test='(query.status == null || query.status == "") and query.functionType == "C" and query.searchType == "reportDefect" '>
AND (a.status = '未开工' or a.status = '已到达')
</if>
<if test='query.status != null and query.status != "" and query.functionType == "C" and query.searchType == "reportDefect" '>
AND a.status = #{query.status}
</if>
<if test='query.documentSource != null and query.documentSource != "" and query.functionType == "C" and query.searchType == "reportDefect" '>
AND a.document_source = #{query.documentSource}
</if>
<if test="query.planDate != null">
AND a.PlanDate = #{query.planDate}
</if>
<if test="query.startDate != null ">
AND a.PlanDate >= #{query.startDate}
</if>
<if test="query.endDate != null ">
AND #{query.endDate} >= a.PlanDate
</if>
<if test="query.endDate == null ">
AND getDate() >= a.PlanDate
</if>
<if test='query.functionType == "A"'>
and getDate() >= dbo.compare_date(ewo.task_start_date)
</if>
AND a.FunctionType = #{query.functionType}
</where>
ORDER BY a.CreateDate,
CASE WHEN b.urgency = '特急' THEN 1
WHEN b.urgency = '紧急' THEN 2
WHEN b.urgency = '一般' THEN 3
END
</select>
<select id="eamWorkOrderSearchForDefect" parameterType="com.jianteng.modules.pms.data.EamWorkOrderInData" resultType="com.jianteng.modules.pms.data.EamWorkOrderInData">
SELECT
a.Site,
a.bu_no,
dbo.get_bu_desc(a.site, a.bu_no) as buDesc,
a.OrderNo,
a.PlanID,
a.ObjectID,
a.Status,
a.PlanOperator,
a.ActualOperator,
a.PlanDate,
a.ActualDate,
a.FunctionType,
a.CreateDate,
d.operatorName as createBy,
a.Remark,
a.StartTime,
a.EndTime,
a.WorkTime,
dbo.eam_Get_eamAdminName(a.Site,a.PlanOperator) as planOperatorName,
b.DefectID,
c.DefectDesc,
dbo.eam_Get_eamObjectDesc(a.Site, a.bu_no, a.ObjectID) as objectDesc,
dbo.eam_Get_eam_properties_CodeDesc(a.site, a.bu_no, a.FunctionType, a.PropertiesCode) as codeDesc,
a.result,
b.urgency,
a.disposal_measures,
a.difficulty_level,
a.difficulty_remark,
f.department_name,
a.reach_date,
b.CreatedDate,
a.handling_method,
dbo.eam_Get_eamResourceDesc(a.Site, a.ObjectID) as resourceDesc,
CASE
WHEN (DATEDIFF(SECOND, b.CreatedDate, a.reach_date) <![CDATA[<]]> 60) THEN DATEDIFF(SECOND, b.CreatedDate, a.reach_date) / 60.0
ELSE DATEDIFF(MINUTE, b.CreatedDate, a.reach_date)
END AS responseTime,
b.FeedBackDesc,
dbo.joint_name(a.Site,a.bu_no,a.OrderNo,a.FunctionType) as actualOperatorName,
a.fault_reason,
a.preventive_measure,
a.document_source
FROM eam_workOrder a
left join eam_defect_feedBack b on a.site = b.site and a.PlanID = b.feedBackID and a.bu_no = b.bu_no
left join eam_defect c on b.DefectID = c.DefectID
left join operator as d on a.site = d.site and a.CreateBy = d.operatorID and d.active = 'Y'
left join eam_object as e on a.site = e.site and a.ObjectID = e.ObjectID and e.Active = 'Y' and a.bu_no = e.bu_no
left join sys_department as f on e.site = f.site and e.dept_id = f.department_id and e.bu_no = f.bu_no
left join Access_dept as ead ON ead.site = f.site and ead.department_id = f.department_id and ead.bu_no = f.bu_no
left join sys_user as ea on ead.username = ea.username
<where>
a.site in (select site from eam_access_site where username = #{query.userName})
and (a.site + '-' + a.bu_no) in (select * from dbo.query_bu(#{query.userName}))
and ea.username = #{query.userName}
<if test="query.buDesc != null and query.buDesc != ''">
AND dbo.get_bu_desc ( a.site, a.bu_no ) = #{query.buDesc}
</if>
<if test="query.deptArr != null">
AND
<foreach collection="query.deptArr" item="item" open="(" separator="or" close=")">
f.department_name like '%' + #{item} + '%'
</foreach>
</if>
<if test="query.orderNo != null and query.orderNo != ''">
AND a.OrderNo like '%' + #{query.orderNo} +'%'
</if>
<if test="query.planID != null and query.planID != ''">
AND a.PlanID like '%' + #{query.planID} +'%'
</if>
<if test="query.objectID != null and query.objectID != ''">
AND a.ObjectID like '%' + #{query.objectID} +'%'
</if>
<if test="query.planOperator != null and query.planOperator != ''">
AND a.PlanOperator like '%' + #{query.planOperator} +'%'
</if>
<if test="query.status != null and query.status != ''">
AND a.status = #{query.status}
</if>
<if test="query.documentSource != null and query.documentSource != ''">
AND a.document_source = #{query.documentSource}
</if>
<if test="query.startDate != null ">
AND a.PlanDate >= #{query.startDate}
</if>
<if test="query.endDate != null ">
AND #{query.endDate} >= a.PlanDate
</if>
and a.FunctionType =#{query.functionType}
</where>
ORDER BY a.PlanDate,
CASE WHEN b.urgency = '特急' THEN 1
WHEN b.urgency = '紧急' THEN 2
WHEN b.urgency = '一般' THEN 3
END
</select>
<select id="eamDefectSearch" parameterType="com.jianteng.modules.pms.data.EamDefectData" resultType="com.jianteng.modules.pms.data.EamDefectData">
SELECT
DefectID,
DefectDesc,
Active,
create_date,
create_by,
update_date,
update_by,
fault_type
FROM eam_defect
<where>
<if test="query.defectID != null and query.defectID != ''">
AND defectID like '%' + #{query.defectID} + '%'
</if>
<if test="query.defectDesc != null and query.defectDesc != ''">
AND defectDesc like '%' + #{query.defectDesc} + '%'
</if>
<if test="query.active != null and query.active != ''">
AND active = #{query.active}
</if>
</where>
order by id
</select>
<select id="eamObjectDefectSearch" parameterType="com.jianteng.modules.pms.data.EamObjectDefectInData" resultType="com.jianteng.modules.pms.data.EamObjectDefectInData">
SELECT
a.site,
a.ObjectID,
a.DefectID,
a.Active,
a.id,
b.ObjectDesc,
c.DefectDesc,
a.create_date,
a.create_by,
a.update_date,
a.update_by
FROM eam_object_defect a
left join eam_object b on a.site=b.site and a.ObjectID = b.ObjectID
left join eam_defect c on a.DefectID = c.DefectID
<where>
<if test="query.objectID != null and query.objectID != ''">
AND a.ObjectID like '%' + #{query.objectID} + '%'
</if>
<if test="query.objectDesc != null and query.objectDesc != ''">
AND b.ObjectDesc like '%' + #{query.objectDesc} + '%'
</if>
<if test="query.defectID != null and query.defectID != ''">
AND a.defectID like '%' + #{query.defectID} + '%'
</if>
<if test="query.defectDesc != null and query.defectDesc != ''">
AND c.defectDesc like '%' + #{query.defectDesc} + '%'
</if>
<if test="query.active != null and query.active != ''">
AND a.active = #{query.active}
</if>
</where>
order by a.id
</select>
<select id="getObjectList" parameterType="com.jianteng.modules.pms.data.EamObjectInData" resultType="com.jianteng.modules.pms.data.EamObjectInData">
SELECT
a.Site,
a.ObjectID,
a.ObjectDesc,
a.LocationID,
a.FamilyID,
a.GroupID,
b.FamilyDesc,
c.LocationName
FROM eam_object a
LEFT JOIN eam_family b ON a.site = b.site and a.FamilyID = b.FamilyID and a.bu_no = b.bu_no
LEFT JOIN eam_location as c ON a.LocationID = c.LocationID and a.site = c.site and a.bu_no = c.bu_no
<where>
<if test="objectID != null and objectID != ''">
AND a.ObjectID like '%' + #{objectID} + '%'
</if>
<if test="objectDesc != null and objectDesc != ''">
AND a.ObjectDesc like '%' + #{objectDesc} + '%'
</if>
AND a.site = #{site} AND a.active = 'Y' and a.bu_no = #{buNo}
</where>
</select>
<select id="checkEamFamilyDelete" resultType="com.jianteng.modules.pms.data.EamObjectData">
SELECT
a.site,
a.objectID
from eam_object as a
left join eam_family as b on a.site = b.site and a.FamilyID = b.FamilyID
where a.site = '2' and (b.son_id like #{sonId} + '%' or a.FamilyID = #{familyID})
</select>
<select id="checkEamGroupDelete" resultType="com.jianteng.modules.pms.data.EamObjectData">
SELECT site, objectID from eam_object where site = #{site} and GroupID = #{groupID}
</select>
<select id="checkEamLocationDelete" resultType="com.jianteng.modules.pms.data.EamObjectData">
SELECT site ,objectID from eam_object where site=#{site} and LocationID=#{locationID}
</select>
<select id="eamWorkPlanItemSearchForReport" resultType="com.jianteng.modules.pms.data.EamWorkOrderItemInData">
SELECT
a.Site,
a.bu_no,
c.OrderNo,
a.ItemNo,
a.ItemDesc,
a.DefaultValue,
a.ValueType,
a.ValueType_DB,
a.ValueChooseFlag,
a.MaxValue,
a.MinValue,
a.ItemRemark,
a.ItemType,
a.image_flag,
a.produce_control_flag,
CASE WHEN b.id is null THEN 'N'
ELSE 'Y'
END as uploadFlag,
a.item_notes
from eam_workPlan_item as a
left join eam_workOrder as c on a.site = c.site and a.PlanID = c.PlanID and a.bu_no = c.bu_no
left join (SELECT MAX (id) as id, order_ref1, order_ref2, order_ref3, order_ref4 FROM sys_oss GROUP BY order_ref1, order_ref2, order_ref3, order_ref4) as b
on b.order_ref1 = a.site and b.order_ref2 = c.OrderNo and b.order_ref3 = a.ItemNo and order_ref4 = a.bu_no
where a.site = #{site} and c.orderNo = #{orderNo} and a.ObjectID = #{objectID} and a.bu_no = #{buNo}
</select>
<select id="checkEamOrderStatus" resultType="com.jianteng.modules.pms.data.EamWorkOrderInData">
SELECT
Site,
status,
OrderNo
from eam_workOrder
where site = #{site} and orderNo = #{orderNo} and bu_no = #{buNo}
</select>
<select id="getAdminIDWithMesUser" resultType="com.jianteng.modules.pms.data.EamAdminData">
SELECT username as adminID
from sys_user
where username = #{mesUser}
</select>
<update id="updateDefectResult" >
update eam_defect_feedBack
set Status = #{result},
FinishDate = GetDate(),
DefectID = #{defectID}
where Site = #{site} and FeedBackID = #{planID} and bu_no = #{buNo}
</update>
<update id="reportWorkOrder" parameterType="EamWorkOrderInData">
update eam_workOrder
set Status = '待审核',
ActualOperator = #{actualOperator},
ActualDate = #{actualDate},
Remark = #{remark},
disposal_measures = #{disposalMeasures},
WorkTime = CASE
WHEN (DATEDIFF(SECOND, reach_date, #{actualDate}) <![CDATA[<]]> 60) THEN DATEDIFF(SECOND, reach_date, #{actualDate}) / 60.0
ELSE ceiling(floor(DATEDIFF(SECOND, reach_date, #{actualDate}) * 1.0 / 30) / 2)
END,
result = #{result,jdbcType=VARCHAR},
checkResult = #{checkResult},
handling_method = #{handlingMethod},
fault_reason = #{faultReason},
preventive_measure = #{preventiveMeasure}
where site = #{site} and orderNo = #{orderNo} and FunctionType = #{functionType} and bu_no = #{buNo}
</update>
<update id="reportWorkOrder2" parameterType="EamWorkOrderInData">
update eam_workOrder
set Status = '待审核',
ActualOperator = #{actualOperator},
reach_date = #{reachDate},
ActualDate = #{actualDate},
Remark = #{remark},
disposal_measures = #{disposalMeasures},
WorkTime = #{workTime},
result = #{result,jdbcType=VARCHAR},
checkResult = #{checkResult},
handling_method = #{handlingMethod},
check_remark = #{checkRemark}
where site = #{site} and orderNo = #{orderNo} and FunctionType = #{functionType} and bu_no = #{buNo}
</update>
<update id="defectReportWorkOrder" >
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>
<insert id="saveWorkOrderItem">
INSERT into eam_workOrder_item
(Site, bu_no, OrderNo, ItemNo, ItemDesc, DefaultValue, ValueType, ValueType_DB, ValueChooseFlag, MaxValue, MinValue, ItemRemark, ItemType, TextValue, NumberValue, CreatedDate, CreatedBy, FinishFlag, itemResult, item_notes)
values (#{site}, #{buNo}, #{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}, #{itemNotes})
</insert>
<!-- 修改 eam_workPlan 状态为已结束 -->
<update id="closePlanWithCheck">
update eam_workPlan
set status = '已结束'
where site = #{site}
and PlanID = #{planID}
and ObjectID = #{objectID}
and GetDate() > PlanEndDate
</update>
<!-- 报工后更新下一个工作日期 -->
<update id="updatePlanNextDate">
update eam_workPlan_overview
set next_work_date = (select top 1 PlanDate from eam_workOrder where site = #{site} and bu_no = #{buNo} and PlanID = #{planID} and PlanDate > GetDate() and status = '未开工' order by PlanDate)
where site = #{site} and plan_id = #{planID} and bu_no = #{buNo}
</update>
<select id="eamWorkOrderReportSearch" resultType="com.jianteng.modules.pms.data.EamWorkOrderItemInData">
SELECT
Site,
bu_no,
OrderNo,
ItemNo,
ItemDesc,
DefaultValue,
ValueType,
ValueType_DB,
ValueChooseFlag,
MaxValue,
MinValue,
ItemRemark,
ItemType,
TextValue,
NumberValue,
CreatedDate,
CreatedBy,
FinishFlag,
itemResult,
item_notes
from eam_workOrder_item
where site = #{site} and orderNo = #{orderNo} and bu_no = #{buNo}
</select>
<update id="cancelOrder" parameterType="EamWorkOrderInData">
update eam_workOrder
set Status = '已取消'
where site = #{site} and orderNo = #{orderNo} and FunctionType = #{functionType} and bu_no = #{buNo}
</update>
<update id="cancelOrderAll" parameterType="EamWorkOrderInData">
update eam_workOrder
set Status = '已取消'
where site = #{site} and PlanID = #{planID} and FunctionType = #{functionType} and ObjectID = #{objectID} and Status = #{status} and bu_no = #{buNo}
</update>
<select id="checkPlanStatus" resultType="com.jianteng.modules.pms.data.EamWorkPlanInData">
SELECT
site,
bu_no,
status
from eam_workPlan_overview
where site = #{site} and plan_id = #{planID} and delete_flag = 'N' and bu_no = #{buNo}
</select>
<update id="planOrder">
update eam_workPlan
set Status = '已计划',
NextWorkDate = null
where site = #{site} and PlanID = #{planID} and deleteFlag = 'N' and bu_no = #{buNo}
</update>
<update id="cancelPlan">
update eam_workPlan_overview
set status = '已取消',
next_work_date = null
where site = #{site} and plan_id = #{planID} and delete_flag = 'N' and bu_no = #{buNo}
</update>
<update id="updateWorkPlanStatus">
update eam_workPlan
set Status = '已取消',
NextWorkDate = null
where Site = #{site} and PlanID = #{planID} and deleteFlag = 'N' and bu_no = #{buNo}
</update>
<update id="cancelOrderWithPlanID">
update eam_workOrder
set Status = '已取消'
where site = #{site} and PlanID = #{planID} and status = '未开工' and bu_no = #{buNo}
</update>
<update id="deleteOrderDetailWithPlanID">
delete from eam_workOrder_item
where site = #{site} and bu_no = #{buNo}
and OrderNo in (select OrderNo from eam_workOrder where site = #{site} and PlanID = #{planID} and status = '未开工' and PlanDate > GetDate() - 1 )
</update>
<update id="deleteOrderWithPlanID">
delete from eam_workOrder
where site = #{site} and bu_no = #{buNo}
and PlanID = #{planID} and status = '未开工' and PlanDate > GetDate() - 1
</update>
<update id="updateOrderPlanOperator">
update eam_workOrder
set PlanOperator = #{planOperator}
where site = #{site} and orderNo = #{orderNo}
</update>
<select id="getSpareSelectList" resultType="com.jianteng.modules.pms.data.PartSpareInData">
select a.site ,a.part_no,a.part_description,a.spec,b.resource_id objectID from part_spare a
left join resource_spare b on a.site = b.site and a.part_no = b.part_no and resource_id = #{objectID}
<where>
<if test="partNo != null and partNo != ''">
AND a.part_no like '%' + #{partNo} + '%'
</if>
<if test="partDescription != null and partDescription != ''">
AND a.part_description like '%' + #{partDescription} + '%'
</if>
and a.site=#{site} and a.active='Y'
</where>
</select>
<select id="checkPartSpare" resultType="com.jianteng.modules.pms.data.PartSpareInData">
select part_no
from resource_spare
where site = #{site}
and resource_id = #{objectID}
and part_no = #{partNo}
</select>
<insert id="savePartSpare" >
INSERT Into resource_spare (resource_id,part_no,delflag,version,site)
values(#{objectID},#{partNo},'',0,#{site})
</insert>
<delete id="deletePartSpare">
delete from resource_spare
where resource_id = #{objectID}
and site = #{site}
</delete>
<insert id="copyPartSpare" >
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>
<select id="getWorkPlanDataWithObjectID" resultType="com.jianteng.modules.pms.data.EamWorkPlanInData">
SELECT a.Site,a.PlanID,a.PlanDesc,a.ObjectID,a.FunctionType,a.PropertiesCode,a.Operator,a.PlanPeriod,a.Status,
a.PlanStartDate,a.PlanEndDate,a.CreatedDate,a.CreatedBy,a.UpdateDate,a.UpdateBy,a.Version,a.Remark
,a.NextWorkDate,b.ObjectDesc,c.adminName,d.code_desc
FROM eam_workPlan a
left join eam_object b on a.Site=b.Site and a.ObjectID=b.ObjectID
left join eam_admin c on a.Site=c.Site and a.operator=c.AdminID
left join eam_properties_model_header d on a.FunctionType=d.function_type and a.PropertiesCode=d.code_no
where a.site=#{site} and a.ObjectID=#{objectID} and a.FunctionType=#{functionType} and a.DeleteFlag='N'
and status in ('已计划','进行中')
</select>
<select id="getObjectItemList" resultType="com.jianteng.modules.pms.data.EamObjectItemInData">
SELECT a.site,a.objectID,a.ItemNo,a.DefaultValue,a.ValueType,a.ValueType_DB,a.ValueChooseFlag,a.CreatedDate,a.CreatedBy,
a.MaxValue,a.MinValue,a.ItemType,b.ItemDesc,b.ItemRemark from eam_object_item a left join eam_properties_item b
on a.ItemNo=b.ItemNo and a.ItemType=b.ItemType
where a.site=#{site} and a.ObjectID=#{objectID}
and a.ItemType=#{itemType}
</select>
<select id="getDefectWithObject" resultType="com.jianteng.modules.pms.data.EamObjectDefectInData">
SELECT a.site,a.ObjectID,a.DefectID,a.Active,a.id,b.DefectDesc
from eam_object_defect a left join eam_defect b
on a.DefectID=b.DefectID
where a.site=#{site} and a.ObjectID=#{objectID}
</select>
<select id="checkEamObjectItemData" resultType="com.jianteng.modules.pms.data.EamObjectItemInData">
select site,objectID,ItemNo,DefaultValue,ValueType,ValueType_DB,ValueChooseFlag,CreatedDate,CreatedBy,MaxValue,MinValue,
ItemType from eam_object_item where site=#{site} and objectID=#{objectID} and ItemType=#{itemType} and ItemNo=#{itemNo}
</select>
<insert id="saveNewEamObjectItem" >
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})
</insert>
<update id="editEamObjectItem">
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}
</update>
<delete id="deleteObjectItem">
delete from eam_object_item where site=#{site} and objectID=#{objectID} and ItemType=#{itemType}
and ItemNo=#{itemNo}
</delete>
<insert id="saveNewEamObjectItemAvailable">
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}
</insert>
<delete id="deleteEamObjectItemAvailable">
delete from eam_object_item_available where site=#{site} and objectID=#{objectID} and ItemType=#{itemType}
and ItemNo=#{itemNo}
</delete>
<select id="searchObjectItemAvailable" resultType="com.jianteng.modules.pms.data.EamObjectItemAvailableData">
select Site,ObjectID,ItemNo,ItemType,ValueNo,AvailableValue from eam_object_item_available
where site=#{site} and objectID=#{objectID} and ItemType=#{itemType} and ItemNo=#{itemNo}
</select>
<select id="getItemValueNoForObject" resultType="Double">
SELECT isnull( max(valueNo),0)+1 from eam_object_item_available where itemNo=#{itemNo} and ItemType=#{itemType} and site=#{site} and objectID=#{objectID}
</select>
<insert id="saveObjectItemAvailable">
insert into eam_object_item_available(Site,ObjectID,ItemNo,ItemType,ValueNo,AvailableValue,CreatedDate,CreatedBy)
values(#{site},#{objectID},#{itemNo},#{itemType},#{valueNo},#{availableValue},GetDate(),#{createdBy})
</insert>
<update id="updateObjectItemAvailable">
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}
</update>
<delete id="deleteObjectItemAvailable">
delete from eam_object_item_available where site=#{site} and objectID=#{objectID} and ItemType=#{itemType} and ItemNo=#{itemNo} and ValueNo=#{valueNo}
</delete>
<delete id="deleteObjectItemForCopy">
delete from eam_object_item where site=#{site} and objectID=#{objectID} and ItemType=#{itemType}
</delete>
<delete id="deleteObjectItemAvailableForCopy">
delete from eam_object_item_available where site=#{site} and objectID=#{objectID} and ItemType=#{itemType}
</delete>
<insert id="copyObjectItem" >
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>
<insert id="copyObjectItemAvailable">
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}
</insert>
<delete id="deleteObjectDefectForCopy">
delete from eam_object_defect where site=#{site} and objectID=#{objectID}
</delete>
<insert id="copyObjectDefect">
insert into eam_object_defect(site,ObjectID,DefectID,Active)
select #{site},#{objectID},DefectID,Active
from eam_object_defect where site=#{site} and objectID=#{oldObjectID}
</insert>
<select id="eamFeedBackSearch" resultType="com.jianteng.modules.pms.data.EamDefectFeedBackInData">
select
a.Site,
a.bu_no,
dbo.get_bu_desc(a.site, a.bu_no) as buDesc,
a.FeedBackID,
a.FeedBackDesc,
a.ObjectID,
a.DefectID,
a.FunctionType,
a.PlanOperator,
a.ActualOperator,
a.Status,
a.PlanDate,
a.Remark,
a.urgency,
a.deleteFlag,
a.CreatedDate,
a.CreatedBy,
c.operatorName as feedbackBy,
a.UpdateDate,
a.UpdateBy,
a.Version,
a.DefectDate,
dbo.eam_Get_eamAdminName(a.Site,a.PlanOperator) PlanOperatorName,
b.defectDesc,
dbo.eam_Get_eamObjectDesc(a.Site, a.bu_no, a.ObjectID) ObjectDesc,
FinishDate,
dbo.joint_name(a.Site, a.bu_no, (select OrderNo from eam_workOrder where PlanID = a.FeedBackID and site = a.site and Result = '维修完成' and bu_no = a.bu_no),a.FunctionType) as actualOperatorName
from eam_defect_feedBack a
left join eam_defect b on a.DefectID = b.DefectID
left join operator as c on a.site = c.site and a.CreatedBy = c.operatorID
left join eam_object as e on a.site = e.site and a.ObjectID = e.ObjectID and e.Active = 'Y' and a.bu_no = e.bu_no
left join sys_department as f on e.site = f.site and e.dept_id = f.department_id and e.bu_no = f.bu_no
left join Access_dept as ead ON ead.site = f.site and ead.department_id = f.department_id and ead.bu_no = f.bu_no
left join sys_user as ea on ead.username = ea.username
<where>
a.site in (select site from eam_access_site where username = #{query.userName})
and (a.site + '-' + a.bu_no) in (select * from dbo.query_bu(#{query.userName}))
and ea.username = #{query.userName}
<if test="query.buDesc != null and query.buDesc != ''">
AND dbo.get_bu_desc (a.site, a.bu_no) = #{query.buDesc}
</if>
<if test="query.feedBackID != null and query.feedBackID != ''">
AND a.feedBackID like '%' + #{query.feedBackID} +'%'
</if>
<if test="query.defectDesc != null and query.defectDesc != ''">
AND b.defectDesc like '%' + #{query.defectDesc} +'%'
</if>
<if test="query.objectID != null and query.objectID != ''">
AND a.ObjectID like '%' + #{query.objectID} +'%'
</if>
<if test="query.planOperator != null and query.planOperator != ''">
AND a.PlanOperator like '%' + #{query.planOperator} +'%'
</if>
<if test="query.status != null and query.status != ''">
AND a.status = #{query.status}
</if>
<if test="query.startDate != null ">
AND a.defectDate >= #{query.startDate}
</if>
<if test="query.endDate != null ">
AND #{query.endDate} >= a.defectDate
</if>
and a.FunctionType = #{query.functionType}
</where>
ORDER BY a.DefectDate,
CASE WHEN a.urgency = '特急' THEN 1
WHEN a.urgency = '紧急' THEN 2
WHEN a.urgency = '一般' THEN 3
END
</select>
<select id="eamFeedBackCheck" resultType="com.jianteng.modules.pms.data.EamDefectFeedBackInData">
select Site, FeedBackID, FeedBackDesc, ObjectID, DefectID, Status from eam_defect_feedBack where FeedBackID = #{feedBackID} and site = #{site} and bu_no = #{buNo}
</select>
<update id="cancelFeedBack" >
update eam_defect_feedBack
set status = '已取消'
where FeedBackID = #{feedBackID} and site = #{site} and bu_no = #{buNo}
</update>
<update id="updateFeedBack">
update eam_defect_feedBack
set status = '已下达',
PlanOperator = #{planOperator},
UpdateDate = GetDate(),
UpdateBy = #{updateBy}
where FeedBackID = #{feedBackID} and site = #{site} and bu_no = #{buNo}
</update>
<insert id="saveDefectOrder">
INSERT INTO eam_workOrder
(Site, bu_no, OrderNo, PlanID, PropertiesCode, ObjectID, Status, PlanOperator, PlanDate, FunctionType, CreateDate, CreateBy)
values(#{site}, #{buNo}, (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' and bu_no = #{buNo}), #{feedBackID}, '', #{objectID}, '未开工', #{planOperator}, #{planDate}, 'C', GetDate(), #{userId})
</insert>
<select id="getItemLists" resultType="com.jianteng.modules.pms.data.EamPropertiesItemData">
SELECT
a.site,
a.bu_no,
a.itemNo,
a.ItemDesc,
a.ItemRemark
FROM eam_properties_item a
LEFT JOIN eam_properties_model_detail b on b.function_type = #{functionType} and b.code_no = #{codeNo} and b.properties_item_no = a.ItemNo and a.site = b.site and a.bu_no = b.bu_no
<where>
a.ItemType = #{functionType}
and a.site = #{site} and a.bu_no = #{buNo}
AND b.code_no is null
<if test = "itemNo != null and itemNo != ''">
AND a.ItemNo LIKE '%' + #{itemNo} + '%'
</if>
<if test = "itemDesc != null and itemDesc != ''">
AND a.ItemDesc LIKE '%' + #{itemDesc} + '%'
</if>
</where>
</select>
<select id="getModelItemLists" resultType="com.jianteng.modules.pms.data.EamPropertiesItemData">
select
a.site,
a.bu_no,
a.properties_item_no itemNo,
b.ItemDesc,
b.ItemRemark
from eam_properties_model_detail a
left join eam_properties_item b on a.properties_item_no = b.ItemNo and a.function_type = b.ItemType and a.site = b.site and a.bu_no = b.bu_no
where a.site = #{site} and a.bu_no = #{buNo} and a.code_no = #{codeNo}
and a.function_type = #{functionType}
</select>
<delete id="deleteObjectFile">
delete from sys_oss where id = #{id}
</delete>
<select id="checkSparPartImage" resultType="SysOssEntity" parameterType="EamWorkOrderInData">
SELECT id, url, create_date, file_name, new_file_name, created_by,
order_ref1, order_ref2, order_ref3, file_type, file_suffix, file_type_code
FROM sys_oss
WHERE order_ref2 = #{orderNo}
AND order_ref1 = #{site}
AND order_ref3 = 'reportSparPart'
</select>
<!-- 获取机修人员列表 -->
<select id="getOperatorList" resultType="EamAdminData" parameterType="EamAdminData">
SELECT
ea.AdminID,
ea.AdminName,
ea.Phone,
dbo.get_eam_dept_str(ea.site,ea.AdminID) as departmentName,
ea.Email,
ea.Tel,
ea.LevelID,
eal.AdminLevelDesc,
ea.MesUser,
ea.Active,
ea.CreatedDate
FROM eam_admin as ea
LEFT JOIN eam_adminLevel as eaL ON ea.LevelID = eal.AdminLevelID and ea.site = eal.site
<where>
ea.Active = 'Y'
AND ea.Site = #{site}
<if test = "adminID != null and adminID != ''">
AND ea.AdminID LIKE '%' + #{adminID}+'%'
</if>
<if test = "adminName != null and adminName != ''">
AND ea.AdminName LIKE '%' + #{adminName}+'%'
</if>
</where>
</select>
<!-- 获取审核人员列表 -->
<select id="getCheckerList" resultType="EamAdminData" parameterType="EamAdminData">
SELECT
a.user_id,
a.username as adminID,
a.email,
a.mobile as phone,
a.user_display as adminName,
dbo.get_bu_desc(c.site,c.bu_no) as buDesc,
d.role_id,
e.role_name
FROM sys_user as a
LEFT JOIN eam_access_site as b on a.username = b.username
LEFT JOIN AccessBu as c on b.username = c.username and b.site = c.site
LEFT JOIN sys_user_role as d on a.user_id = d.user_id
LEFT JOIN sys_role as e on d.role_id = e.role_id
<where>
b.site = #{site} and c.bu_no = #{buNo}
<if test = "adminID != null and adminID != ''">
AND a.username LIKE '%' + #{adminID}+'%'
</if>
<if test = "adminName != null and adminName != ''">
AND a.user_display LIKE '%' + #{adminName}+'%'
</if>
<if test = "buDesc != null and buDesc != ''">
AND dbo.get_bu_desc(a.site,c.bu_no) LIKE '%' + #{buDesc}+'%'
</if>
<if test = "roleName != null and roleName != ''">
AND e.role_name LIKE '%' + #{roleName}+'%'
</if>
</where>
</select>
<!-- 点检工单审核 -->
<update id="checkWorkOrder" parameterType="EamWorkOrderInData">
UPDATE eam_workOrder
SET Status = '已完工'
WHERE Site = #{site} AND OrderNo = #{orderNo} and bu_no = #{buNo}
</update>
<update id="cancelCheckWorkOrder" parameterType="EamWorkOrderInData">
UPDATE eam_workOrder
SET Status = '待审核'
WHERE Site = #{site} AND OrderNo = #{orderNo} and bu_no = #{buNo}
</update>
<!-- 查看点检工单状态 -->
<select id="checkWorkOrderStatus" resultType="EamWorkOrderInData" parameterType="EamWorkOrderInData">
SELECT
OrderNo
FROM eam_workOrder
WHERE site = #{site} AND PlanID = #{planID} AND Status != '已完工' and bu_no = #{buNo}
</select>
<!-- 点检工单审核 -->
<update id="updateWorkPlanOverviewStatus" parameterType="EamWorkOrderInData">
UPDATE eam_workPlan_overview
SET status = '已结束'
WHERE site = #{site} AND plan_id = #{planID} and bu_no = #{buNo}
</update>
<!-- 新增点检计划 -->
<insert id="saveWorkPlan" parameterType="EamWorkPlanInData">
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, task_start_date, plan_halt_date, auto_renewal, bu_no)
VALUES (#{site}, #{planID}, #{planDesc}, '已计划', #{planStartDate}, #{planEndDate}, getDate(), #{createdBy}, getDate(), #{updateBy}, #{remark}, 'N', #{operator}, #{operatorName}, #{checker}, #{checkerName}, #{functionType}, #{propertiesCode}, #{planPeriod}, #{workOrderRule}, #{planCycle}, #{taskStartDate}, #{planHaltDate}, #{autoRenewal}, #{buNo})
</insert>
<!-- 生成工单ID -->
<select id="selectOrderId" resultType="string" parameterType="EamWorkPlanInData">
SELECT
Right('0000000000'+ convert(VARCHAR(10), isnull(max(convert(INT,SUBSTRING(PlanID,3,10))),0)+1),8)
FROM eam_workPlan
WHERE site = #{site} AND FunctionType = #{functionType} and bu_no = #{buNo}
</select>
<!-- 查询计划中的设备列表 -->
<select id="getPlanDetailList" resultType="WorkPlanDetailData" parameterType="WorkPlanDetailData">
SELECT
ewp.PlanID,
ewp.PlanDesc,
ewp.ObjectID,
eo.ObjectDesc,
eo.FamilyID,
ef.FamilyDesc,
eo.LocationID,
el.LocationName
FROM eam_workPlan as ewP
LEFT JOIN eam_object as eo ON ewP.ObjectID = eo.ObjectID and ewP.Site = eo.Site and ewP.bu_no = eo.bu_no
LEFT JOIN eam_family as ef ON eo.FamilyID = ef.FamilyID and ewP.Site = ef.Site and ewP.bu_no = ef.bu_no
LEFT JOIN eam_location as el ON eo.LocationID = el.LocationID and ewP.Site = el.Site and ewP.bu_no = el.bu_no
<where>
ewP.site = #{site} and ewP.bu_no = #{buNo}
AND ewp.PlanID = #{planID}
<if test = "objectID != null and objectID != ''">
AND eo.ObjectID LIKE '%' + #{objectID}+'%'
</if>
<if test = "objectDesc != null and objectDesc != ''">
AND eo.ObjectDesc LIKE '%' + #{objectDesc}+'%'
</if>
</where>
</select>
<!-- 删除计划中的设备 -->
<delete id="delPlanDetail" parameterType="WorkPlanDetailData">
DELETE FROM eam_workPlan
WHERE Site = #{site}
AND PlanID = #{planID}
AND ObjectID = #{objectID}
</delete>
<!-- 获取当前计划不包含的设备 -->
<select id="getObjList1" resultType="WorkPlanDetailData" parameterType="WorkPlanDetailData">
SELECT
a.ObjectID,
a.ObjectDesc,
a.FamilyID,
ef.FamilyDesc,
a.LocationID,
el.LocationName
FROM eam_object a
LEFT JOIN eam_workPlan b ON b.PlanID = #{planID} and b.ObjectID = a.ObjectID and a.site = b.site and a.bu_no = b.bu_no
LEFT JOIN eam_family as ef ON a.FamilyID = ef.FamilyID and a.site = ef.site and a.bu_no = ef.bu_no
LEFT JOIN eam_location as el ON a.LocationID = el.LocationID and a.site = el.site and a.bu_no = el.bu_no
WHERE a.site = #{site} and a.bu_no = #{buNo} and b.PlanID is null
</select>
<!-- 获取当前计划包含的设备 -->
<select id="getObjList2" resultType="WorkPlanDetailData" parameterType="WorkPlanDetailData">
SELECT
a.ObjectID,
b.ObjectDesc,
b.FamilyID,
ef.FamilyDesc,
b.LocationID,
el.LocationName
FROM eam_workPlan a
LEFT JOIN eam_object b ON a.ObjectID = b.ObjectID and a.site = b.site and a.bu_no = b.bu_no
LEFT JOIN eam_family as ef ON b.FamilyID = ef.FamilyID and a.site = ef.site and a.bu_no = ef.bu_no
LEFT JOIN eam_location as el ON b.LocationID = el.LocationID and a.site = el.site and a.bu_no = el.bu_no
WHERE a.PlanID = #{planID} and a.site = #{site} and a.bu_no = #{buNo}
</select>
<!-- 添加计划设备 -->
<insert id="addObject" parameterType="EamWorkPlanInData">
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')
</insert>
<!-- 修改工单计划 -->
<update id="updateWorkPlan" parameterType="EamWorkPlanInData">
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},
task_start_date = #{taskStartDate},
plan_cycle = #{planCycle},
plan_halt_date = #{planHaltDate},
auto_renewal = #{autoRenewal}
WHERE site = #{site} AND plan_id = #{planID} AND function_type = #{functionType} and bu_no = #{buNo}
</update>
<!-- 删除该计划的旧设备 -->
<delete id="delWorkPlanObject" parameterType="EamWorkPlanInData">
DELETE FROM eam_workPlan
WHERE Site = #{site} AND PlanID = #{planID} and bu_no = #{buNo}
</delete>
<!-- 删除该计划的旧设备item -->
<delete id="delWorkPlanItem" parameterType="EamWorkPlanInData">
DELETE FROM eam_workPlan_item
WHERE Site = #{site} AND PlanID = #{planID} and bu_no = #{buNo}
</delete>
<!-- 删除该计划的旧设备itemAvailable-->
<delete id="delWorkPlanItemAvailable">
DELETE FROM eam_workPlan_item_available
WHERE Site = #{site}
AND PlanID = #{planID}
AND ObjectID = #{objectID}
</delete>
<!-- 查询该计划的设备 -->
<select id="planObjectSearch" resultType="EamWorkPlanItemData" parameterType="EamWorkPlanItemData">
SELECT DISTINCT
a.ObjectID,
b.ObjectDesc
FROM eam_workPlan_item as a
LEFT JOIN eam_object as b ON a.ObjectID = b.ObjectID and a.site = b.site and a.bu_no = b.bu_no
WHERE a.Site = #{site} AND a.PlanID = #{planID} and a.bu_no = #{buNo}
</select>
<!-- 修改该计划状态 -->
<update id="updateOverviewStatus" parameterType="EamWorkPlanInData">
UPDATE eam_workPlan_overview
SET status = '进行中',
next_work_date = plan_start_date
WHERE site = #{site} AND plan_id = #{planID} and bu_no = #{buNo}
</update>
<!-- 查询文件路径 -->
<select id="searchFileUrl" resultType="SysOssEntity" parameterType="EamWorkOrderInData">
SELECT
id,
url,
file_name
FROM sys_oss WHERE order_ref1 = #{site} AND order_ref2 = #{orderNo} AND order_ref3 = #{folder} and order_ref4 = #{buNo}
</select>
<!-- 新增子明细信息 -->
<insert id="saveOperator" parameterType="EamWorkOrderInData">
INSERT INTO eam_actual_operator
(site, order_no, function_type, operator, bu_no)
VALUES (#{site}, #{orderNo}, #{functionType}, #{operator}, #{buNo})
</insert>
<!-- AND Status = '已完工' AND PlanOperator is not null-->
<!-- 查询实际维修人员 -->
<select id="getActualOperatorList2" resultType="EamAdminData">
SELECT
ea.AdminID,
ea.AdminName
FROM eam_actual_operator as eao
LEFT JOIN eam_admin as ea ON eao.operator = ea.AdminID and eao.site = ea.Site
LEFT JOIN eam_workOrder as ew ON eao.site = ew.Site and eao.function_type = ew.FunctionType and eao.order_no = ew.OrderNo
WHERE eao.site = #{site} AND eao.function_type = #{functionType} AND ew.PlanID = #{planID}
</select>
<!-- 查询实际维修人员 -->
<select id="getActualOperatorList" resultType="EamAdminData">
SELECT
ea.username as adminID,
ea.user_display as AdminName
FROM eam_actual_operator as eao
LEFT JOIN sys_user as ea ON eao.operator = ea.username
WHERE eao.site = #{site} AND eao.order_no = #{orderNo} AND eao.function_type = #{functionType} and eao.bu_no = #{buNo}
</select>
<!-- 查询设备所属部门 -->
<select id="selectDeptByObjectID" resultType="string" parameterType="string">
SELECT ved.department_name
FROM eam_object as eo
LEFT JOIN sys_department as ved ON eo.site = ved.site and eo.dept_id = ved.department_id
WHERE eo.site = #{site}
AND eo.ObjectID = #{objectID}
</select>
<!-- 查询用户所属部门 -->
<select id="selectAdminIdByUserName" resultType="string" parameterType="string">
SELECT AdminID
FROM eam_admin
WHERE site = #{site}
AND MesUser = #{username}
</select>
<!-- &lt;!&ndash; 查询部门列表 &ndash;&gt;-->
<!-- <select id="getDeptList" resultType="string" parameterType="string">-->
<!-- SELECT-->
<!-- ved.department_name-->
<!-- FROM eam_admin_dept as ead-->
<!-- LEFT JOIN sys_department as ved ON ead.site = ved.site and ead.dept_id = ved.department_id-->
<!-- LEFT JOIN eam_admin as ea ON ead.site = ea.site and ead.admin_id = ea.AdminID-->
<!-- WHERE ead.site = #{site} AND ea.MesUser = #{username}-->
<!-- </select>-->
<!-- 查询部门列表 -->
<select id="getDeptList" resultType="string" parameterType="string">
SELECT
distinct c.department_name
from sys_user as a
left join Access_dept as b on a.username = b.username
left join sys_department as c on c.site in (select site from eam_access_site where username = #{username})
and (c.site + '-' + c.bu_no) in (select * from dbo.query_bu(#{username}))
and b.department_id = c.department_id
where a.username = #{username}
</select>
<!-- 生成新的维修工单 -->
<insert id="saveDefectWorkOrder" parameterType="EamWorkOrderInData">
INSERT INTO eam_workOrder
(Site, bu_no, OrderNo, PlanID, PropertiesCode, ObjectID, Status, PlanDate, FunctionType, CreateDate, CreateBy, check_work_plan_id, check_item_no, document_source)
VALUES (#{site}, #{buNo}, #{orderNo}, #{planID}, '', #{objectID}, '未开工', getDate(), 'C', getDate(), #{createBy}, #{checkWorkPlanId}, #{checkItemNo}, #{documentSource})
</insert>
<!-- 创建count表 -->
<insert id="saveDefectRecordCount2" parameterType="EamWorkOrderInData">
INSERT INTO eam_workOrder_count
(Site, bu_no, OrderNo, PlanID, PropertiesCode, ObjectID, Status, PlanDate, FunctionType, CreateDate, CreateBy, check_work_plan_id, check_item_no)
VALUES (#{site}, #{buNo}, #{orderNo}, #{planID}, '', #{objectID}, '未开工', getDate(), 'C', getDate(), #{createBy}, #{checkWorkPlanId}, #{checkItemNo})
</insert>
<!-- 获取旧工单的基础信息 -->
<select id="queryOldWorkOrderMessage" resultType="EamWorkOrderInData" parameterType="EamWorkOrderInData">
select
PlanOperator,
PlanOperatorName,
checker,
checkerName
from eam_workOrder where site = #{site} and OrderNo = #{orderNo} and FunctionType = #{functionType} and bu_no = #{buNo}
</select>
<!-- 生成新的维保工单 -->
<insert id="saveMaintenanceWorkOrder" parameterType="EamWorkOrderInData">
INSERT INTO eam_workOrder
(Site, bu_no, OrderNo, PlanID, PlanDesc, PropertiesCode, ObjectID, Status, PlanOperator, PlanDate, FunctionType, CreateDate, CreateBy, checker, PlanOperatorName, checkerName)
VALUES (#{site}, #{buNo}, #{orderNo}, #{planID}, #{planDesc}, #{propertiesCode}, #{objectID}, '未开工', #{planOperator}, Dateadd(dd, Datediff(dd,0,Getdate()), 0), #{functionType}, getDate(), #{createBy}, #{checker}, #{planOperatorName}, #{checkerName})
</insert>
<!-- 检查系统操作人和审核人员是否一致 -->
<select id="selectNameByMes" resultType="EamAdminData" parameterType="EamAdminData">
SELECT AdminName
FROM eam_admin
WHERE site = #{site}
AND MesUser = #{mesUser}
</select>
<!-- 维修审核确认 -->
<update id="submitDefect" parameterType="EamWorkOrderInData">
UPDATE eam_workOrder
SET Status = #{status},
difficulty_level = #{difficultyLevel},
difficulty_remark = #{difficultyRemark}
WHERE Site = #{site} AND OrderNo = #{orderNo} and bu_no = #{buNo}
</update>
<!-- 查询设备的点检和维保历史记录 -->
<select id="queryHistoryRecord" resultType="EamWorkOrderInData" parameterType="EamWorkOrderInData">
SELECT
top 10
ewo.OrderNo,
ewo.PlanID,
ewo.PlanDesc,
ewo.ActualDate,
ewo.ObjectID,
eo.ObjectDesc,
ewo.Remark,
dbo.eam_Get_eamAdminName(ewo.site,ewo.ActualOperator) ActualOperatorName,
ewo.checkResult
FROM eam_workOrder as ewo
LEFT JOIN eam_object as eo ON ewo.site = eo.site and ewo.ObjectID = eo.ObjectID and ewo.bu_no = eo.bu_no
WHERE ewo.site = #{site} AND ewo.ObjectID = #{objectID} AND ewo.FunctionType = #{functionType} AND ewo.Status = '已完工' and ewo.bu_no = #{buNo}
ORDER BY ewo.ActualDate desc
</select>
<!-- 查询设备的维修历史记录 -->
<select id="queryDefectHistoryRecord" resultType="EamWorkOrderInData" parameterType="EamWorkOrderInData">
SELECT
top 10
ewo.OrderNo,
ewo.PlanID,
ewo.PlanDesc,
ewo.ActualDate,
ewo.Remark,
ewo.Result,
ewo.disposal_measures,
ed.DefectDesc,
ewo.WorkTime
FROM eam_workOrder as ewo
LEFT JOIN eam_object as eo ON ewo.site = eo.site and ewo.ObjectID = eo.ObjectID and ewo.bu_no = eo.bu_no
LEFT JOIN eam_defect_feedBack as edf ON ewo.site = edf.site and ewo.PlanID = edf.FeedBackID and ewo.bu_no = edf.bu_no
LEFT JOIN eam_defect as ed ON ed.DefectID = edf.DefectID
WHERE ewo.site = #{site} AND ewo.ObjectID = #{objectID} AND ewo.FunctionType = #{functionType} AND ewo.Status = '已完工' and ewo.bu_no = #{buNo} ORDER BY ewo.ActualDate desc
</select>
<!-- 查询部门列表 -->
<select id="getEmpyDeptList" resultType="EmpyDept" parameterType="EmpyDept">
SELECT
site,
department_id as deptId,
department_name as deptName
FROM sys_department
<where>
site in (select site from eam_access_site where username = #{userName})
and (site + '-' + bu_no) in (select * from dbo.query_bu(#{userName}))
<if test = "deptId != null and deptId != ''">
AND department_id LIKE '%' + #{deptId}+'%'
</if>
<if test = "deptName != null and deptName != ''">
AND department_name LIKE '%' + #{deptName}+'%'
</if>
</where>
</select>
<!-- 生成新的维修工单 -->
<insert id="saveAdminDepartment">
INSERT INTO eam_admin_dept
(Site, admin_id, dept_id)
VALUES (#{site}, #{adminID}, #{deptId})
</insert>
<!-- 查询部门详情 -->
<select id="getDeptDetail" resultType="EamAdminData" parameterType="string">
SELECT
ved.department_id as department,
ved.department_name as departmentName
FROM eam_admin_dept as ead
LEFT JOIN sys_department as ved ON ead.site = ved.site and ead.dept_id = ved.department_id and ead.bu_no = ved.bu_no
WHERE ead.site in (select site from eam_access_site where username = #{userName})
and (ead.site + '-' + ead.bu_no) in (select * from dbo.query_bu(#{userName}))
AND ead.admin_id = #{adminID}
</select>
<!-- 删除旧数据-->
<delete id="deleteAdminDepartment">
DELETE FROM eam_admin_dept
WHERE site = #{site}
AND admin_id = #{adminID}
</delete>
<!-- 获取可用的MES账号 -->
<select id="getMesList" resultType="SysUserEntity" parameterType="SysUserEntity">
SELECT
a.username,
a.user_display
FROM sys_user a
LEFT JOIN eam_admin b ON b.MesUser = a.username and a.site = b.site
WHERE a.site = #{site}
AND b.MesUser is null
</select>
<!-- 查询点检项目 -->
<select id="eamPropertiesItemSearch" parameterType="EamPropertiesItemData" resultType="EamPropertiesItemData">
SELECT
site,
bu_no,
dbo.get_bu_desc(site, bu_no) as buDesc,
ItemNo,
ItemDesc,
DefaultValue,
ValueType,
ValueType_DB as valueTypeDb,
ValueChooseFlag,
CreatedDate,
CreatedBy,
update_date,
update_by,
MaxValue,
MinValue,
ItemRemark,
ItemType,
image_flag,
produce_control_flag
FROM eam_properties_item
<where>
site in (select site from eam_access_site where username = #{query.userName})
and (site + '-' + bu_no) in (select * from dbo.query_bu(#{query.userName}))
and ItemType = #{query.itemType}
<if test="query.buDesc != null and query.buDesc != ''">
AND dbo.get_bu_desc ( site, bu_no ) = #{query.buDesc}
</if>
<if test="query.itemNo != null and query.itemNo != ''">
AND ItemNo LIKE '%' + #{query.itemNo}+'%'
</if>
<if test="query.itemDesc != null and query.itemDesc != ''">
AND ItemDesc LIKE '%' + #{query.itemDesc}+'%'
</if>
</where>
</select>
<!-- 删除图片-->
<delete id="imageDelete" parameterType="SysOssEntity">
DELETE FROM sys_oss
WHERE id = #{id}
</delete>
<!-- 检查该日期内是否已有该设备的计划 -->
<select id="checkObjectPlan" resultType="EamWorkPlanInData" parameterType="EamWorkPlanInData">
SELECT
a.PlanID,
a.ObjectID
FROM eam_workPlan a
LEFT JOIN eam_workOrder b ON a.site = b.site AND a.PlanID = b.PlanID and a.FunctionType = b.FunctionType and a.ObjectID = b.ObjectID and a.bu_no = b.bu_no
WHERE a.site = #{site} and a.bu_no = #{buNo}
AND a.ObjectID = #{objectID} AND a.FunctionType = #{functionType} AND a.Status in ('已计划','进行中') AND a.deleteFlag = 'N'
AND (convert(varchar(10), a.PlanStartDate, 120) between #{planStartDate} and #{planEndDate}
or convert(varchar(10), a.PlanEndDate, 120) between #{planStartDate} and #{planEndDate}
or (DATEDIFF(day, a.PlanStartDate, #{planStartDate}) >= 0 and DATEDIFF(day, #{planEndDate}, a.PlanEndDate) >= 0)
)
and a.PropertiesCode = #{propertiesCode} and a.plan_cycle = #{planCycle} and a.PlanPeriod = #{planPeriod}
and b.Status not in ('已取消','已完成','待审核')
</select>
<!-- 查询当前计划 -->
<select id="queryWorkPlan" resultType="EamWorkPlanInData" parameterType="EamWorkPlanInData">
SELECT
site,
bu_no,
plan_id,
plan_desc,
properties_code,
#{objectID} as objectID,
status,
operator,
delete_flag,
plan_start_date,
plan_end_date,
plan_period,
function_type,
checker,
checker_name,
operator_name,
work_order_rule,
plan_cycle
FROM eam_workPlan_overview
WHERE site = #{site} AND plan_id = #{planID} AND function_type = #{functionType} and bu_no = #{buNo}
</select>
<!-- 获得工单号 -->
<select id="queryPlanOrderNo" resultType="string" parameterType="EamWorkPlanInData">
SELECT
Right( '0000000000'+ convert(VARCHAR(10),isnull(max(convert(INT,SUBSTRING(OrderNo,3,10))),0)+1),8)
FROM eam_workOrder
WHERE site = #{site} and bu_no = #{buNo} AND FunctionType = #{functionType}
</select>
<!-- 新增工单 -->
<insert id="insertWorkOrder" parameterType="EamWorkPlanInData">
INSERT INTO eam_workOrder
(Site, bu_no, OrderNo, PlanID, PlanDesc, PropertiesCode, ObjectID, Status, PlanOperator, PlanDate, FunctionType,CreateDate, CreateBy, checker, PlanOperatorName, checkerName)
VALUES (#{site}, #{buNo}, #{orderNo}, #{planID}, #{planDesc}, #{propertiesCode}, #{objectID}, '未开工', #{operator}, #{planStartDate}, #{functionType}, getDate(), #{userId}, #{checker}, #{operatorName}, #{checkerName})
</insert>
<!-- 循环新增工单 -->
<insert id="forInsertWorkOrder" parameterType="EamWorkPlanInData">
INSERT INTO eam_workOrder
(Site, bu_no, OrderNo, PlanID, PlanDesc, PropertiesCode, ObjectID, Status, PlanOperator, PlanDate, FunctionType,CreateDate, CreateBy, checker, PlanOperatorName, checkerName)
VALUES (#{site}, #{buNo}, #{orderNo}, #{planID}, #{planDesc}, #{propertiesCode}, #{objectID}, '未开工', #{operator}, #{orderDate}, #{functionType}, getDate(), #{userId}, #{checker}, #{operatorName}, #{checkerName})
</insert>
<!-- 更改plan表的状态为进行中 -->
<update id="updatePlanStatus" parameterType="EamWorkPlanInData">
update eam_workPlan
set status = '进行中',
NextWorkDate = PlanStartDate
where site = #{site} and PlanID = #{planID} and FunctionType = #{functionType} and ObjectID = #{objectID} and bu_no = #{buNo}
</update>
<!-- 获得工单号 -->
<select id="queryFileByOrderNoAndItemNo" resultType="SysOssEntity" parameterType="EamWorkOrderItemInData">
SELECT
id,
file_name
FROM sys_oss
WHERE order_ref1 = #{site} AND order_ref2 = #{orderNo} AND order_ref3 = #{itemNo} and order_ref4 = #{buNo}
</select>
<!-- 删除原来工单项目-->
<delete id="deleteWorkPlanItem" parameterType="EamWorkOrderItemInData">
DELETE FROM eam_workPlan_item
WHERE site = #{site} and PlanID = #{planID} and ItemType = #{itemType} and ObjectID = #{objectID} and bu_no = #{buNo}
</delete>
<!-- 删除原来的可选值-->
<delete id="deleteWorkPlanItemAvailable" parameterType="EamWorkOrderItemInData">
DELETE FROM eam_workPlan_item_available
WHERE site = #{site} and PlanID = #{planID} and ItemType = #{itemType} and ObjectID = #{objectID} and bu_no = #{buNo}
</delete>
<!-- 添加新项目 -->
<insert id="saveWorkPlanItem" parameterType="EamWorkOrderItemInData">
INSERT INTO eam_workPlan_item (Site, bu_no, PlanID, ObjectID, ItemNo, ItemDesc, DefaultValue, ValueType, ValueType_DB, ValueChooseFlag, MaxValue, MinValue, ItemRemark, ItemType, CreatedDate, CreatedBy, image_flag, produce_control_flag)
select
#{site},
#{buNo},
#{planID},
#{objectID},
a.ItemNo,
a.ItemDesc,
case when c.site is not null then c.DefaultValue else a.DefaultValue end,
case when c.site is not null then c.ValueType else a.ValueType end,
case when c.site is not null then c.ValueType_DB else a.ValueType_DB end,
case when c.site is not null then c.ValueChooseFlag else a.ValueChooseFlag end,
case when c.site is not null then c.MaxValue else a.MaxValue end,
case when c.site is not null then c.MinValue else a.MinValue end,
a.ItemRemark,
a.ItemType,
GetDate(),
#{userId},
a.image_flag,
a.produce_control_flag
from eam_properties_item a
left join eam_properties_model_detail b on a.ItemType = b.function_type and a.ItemNo = b.properties_item_no and a.site = b.site and a.bu_no = b.bu_no
left join eam_object_item c on a.ItemType = c.ItemType and a.ItemNo = c.ItemNo and c.objectID = #{objectID}
where a.ItemType = #{itemType} and b.code_no = #{propertiesCode} and a.site = #{site} and a.bu_no = #{buNo}
</insert>
<!-- 添加新项目可选值 -->
<insert id="saveWorkPlanItemAvailable" parameterType="EamWorkOrderItemInData">
INSERT INTO eam_workPlan_item_available (Site, bu_no, PlanID, ObjectID, ItemNo, ItemType, ValueNo, AvailableValue, CreatedDate, CreatedBy)
SELECT DISTINCT
#{site},
#{buNo},
#{planID},
#{objectID},
a.ItemNo,
a.ItemType,
case when c.ValueNo is not null then c.ValueNo else a.ValueNo end,
case when c.ValueNo is not null then c.AvailableValue else a.AvailableValue end,
GetDate(),
#{userId}
FROM eam_properties_item_available a
LEFT JOIN eam_properties_model_detail b on a.ItemType = b.function_type and a.ItemNo = b.properties_item_no and a.site = b.site and a.bu_no = b.bu_no
LEFT JOIN eam_object_item_available c on a.ItemNo = c.ItemNo and a.ItemType = c.ItemType and c.ObjectID = #{objectID}
WHERE a.ItemType = #{itemType} and b.code_no = #{propertiesCode} and a.site = #{site} and a.bu_no = #{buNo}
</insert>
<!-- 检查维修任务号是否已存在 -->
<select id="getEamGzData" resultType="EamDefectFeedBackData" parameterType="EamDefectFeedBackData">
select
a.Site,
a.bu_no,
a.FeedBackID,
a.FeedBackDesc,
a.ObjectID,
a.Status
from eam_defect_feedBack a
left join eam_defect b on a.DefectID = b.DefectID
<where>
a.site = #{site} and a.deleteFlag = 'N' and a.bu_no = #{buNo}
<if test="feedBackID != null and feedBackID != ''">
AND a.FeedBackID LIKE '%' + #{feedBackID}+'%'
</if>
<if test="feedBackDesc != null and feedBackDesc != ''">
AND a.FeedBackDesc LIKE '%' + #{feedBackDesc}+'%'
</if>
<if test="objectInfo != null and objectInfo != ''">
AND (a.ObjectID like '%' + #{objectInfo} + '%' or dbo.eam_Get_eamObjectDesc(a.Site, a.bu_no, a.ObjectID) like '%' + #{objectInfo} + '%')
</if>
<if test="defectInfo != null and defectInfo != ''">
AND (a.DefectID like '%' + #{defectInfo} + '%' or b.defectDesc like '%' + #{defectInfo} + '%')
</if>
</where>
</select>
<!-- 保存故障信息 -->
<insert id="saveEamGzBbData" parameterType="EamDefectFeedBackData">
INSERT INTO eam_defect_feedBack
(Site, bu_no, FeedBackID, FeedBackDesc, ObjectID, DefectID, FunctionType, PlanOperator, Status, PlanDate, Remark, deleteFlag, CreatedDate, CreatedBy, Version, DefectDate, urgency)
VALUES (#{site}, #{buNo}, #{feedBackID}, #{feedBackDesc}, #{objectID}, #{defectID}, #{functionType}, #{planOperator}, #{status}, #{planDate}, #{remark}, #{deleteFlag}, getDate(), #{createdBy}, #{version}, #{defectDate}, #{urgency})
</insert>
<!-- 查看现场动控是否开启 -->
<select id="selectControlBaseData" resultType="SysSceneDynamicControlModelEntity" parameterType="string">
SELECT
type,
base_data,
base_desc,
status,
remark,
third_type,
second_type,
page_control,
control_style
FROM sys_scene_dynamic_control_model
where site = #{site} and control_no = #{controlNo}
</select>
<!-- 修改反馈状态为已下达 -->
<update id="updateDefectFeedBackStatus" parameterType="EamDefectFeedBackData">
UPDATE eam_defect_feedBack
SET Status = '已下达'
WHERE Site = #{site} AND FeedBackID = #{feedBackID} and bu_no = #{buNo}
</update>
<!-- 查询工单号 -->
<select id="getOrderNo" resultType="string" parameterType="EamWorkOrderInData">
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' and bu_no = #{buNo}
</select>
<!-- 创建维修工单 -->
<insert id="saveWorkOrder" parameterType="EamDefectFeedBackData">
INSERT INTO eam_workOrder
(Site, bu_no, OrderNo, PlanID, PropertiesCode, ObjectID, Status, PlanDate, FunctionType, CreateDate, CreateBy, PlanDesc, document_source)
VALUES (#{site}, #{buNo}, #{orderNo}, #{feedBackID}, '', #{objectID}, '未开工', getDate(), 'C', getDate(), #{createdBy}, #{feedBackDesc}, #{documentSource})
</insert>
<!-- 创建维修count表数据 -->
<insert id="saveDefectRecordCount" parameterType="EamDefectFeedBackData">
INSERT INTO eam_workOrder_count
(Site, bu_no, OrderNo, PlanID, PropertiesCode, ObjectID, Status, PlanDate, FunctionType, CreateDate, CreateBy, PlanDesc)
VALUES (#{site}, #{buNo}, #{orderNo}, #{feedBackID}, '', #{objectID}, '未开工', getDate(), 'C', getDate(), #{createdBy}, #{feedBackDesc})
</insert>
<!-- 修改工单 -->
<update id="updateWorkOrder" parameterType="EamWorkOrderInData">
update eam_workOrder
set update_by = #{mesUser},
update_date = GetDate(),
Remark = #{remark},
reach_date = #{reachDate},
ActualDate = #{actualDate},
WorkTime = #{workTime},
<if test='functionType == "B" and checkResult == "合格"'>
disposal_measures = '',
</if>
<if test='functionType == "B" and checkResult == "异常"'>
disposal_measures = #{disposalMeasures},
</if>
checkResult = #{checkResult},
check_remark = #{checkRemark},
fault_reason = #{faultReason},
preventive_measure = #{preventiveMeasure}
where site = #{site} and orderNo = #{orderNo} and bu_no = #{buNo}
</update>
<!-- 修改工单项目 -->
<update id="updateWorkOrderItem" parameterType="EamWorkOrderItemInData">
update eam_workOrder_item
set update_by = #{updateBy},
update_date = GetDate(),
<if test='valueTypeDb == "T"'>
TextValue = #{textValue},
</if>
<if test='valueTypeDb == "N"'>
NumberValue = #{numberValue},
</if>
itemResult = #{itemResult}
where site = #{site} and OrderNo = #{orderNo} and ItemNo = #{itemNo} and bu_no = #{buNo}
</update>
<!-- 删除之前的协同人员-->
<delete id="delOperator" parameterType="EamWorkOrderInData">
DELETE FROM eam_actual_operator
WHERE site = #{site} and order_no = #{orderNo} and function_type = #{functionType} and bu_no = #{buNo}
</delete>
<!-- 到达 -->
<update id="reach" parameterType="EamWorkOrderInData">
update eam_workOrder
set Status = #{status},
reach_date = GetDate(),
reach_operator = #{reachOperator},
reach_operator_name = #{reachOperatorName}
where site = #{site} and OrderNo = #{orderNo} and FunctionType = #{functionType} and bu_No = #{buNo}
</update>
<!-- 查询是否已经上传图片 -->
<select id="checkUploadAlready" resultType="SysOssEntity" parameterType="EamWorkOrderItemData">
SELECT
id
FROM sys_oss
where order_ref1 = #{site} and order_ref2 = #{orderNo} and order_ref3 = #{itemNo}
</select>
<!-- 查询文件路径 -->
<select id="searchItemFileUrl" resultType="SysOssEntity" parameterType="EamWorkOrderItemData">
SELECT
id,
url,
file_name
FROM sys_oss
WHERE order_ref1 = #{site} and order_ref2 = #{orderNo} and order_ref3 = #{itemNo} and order_ref4 = #{buNo}
</select>
<!-- 根据工单号查询知识库记录 -->
<select id="selectKnowledgeRecordByOrderNo" resultType="EamKnowledgeBaseData" parameterType="EamWorkOrderInData">
SELECT
site,
bu_no,
num
FROM eam_knowledge_base
WHERE site = #{site} and order_no = #{orderNo} and bu_no = #{buNo}
</select>
<!-- 根据工单号修改知识库记录 -->
<update id="updateKnowledgeRecordByOrderNo" parameterType="EamWorkOrderInData">
update eam_knowledge_base
set update_date = getDate(),
update_by = #{updateBy}
where site = #{site} and order_no = #{orderNo} and bu_no = #{buNo}
</update>
<!-- 新增设备知识库记录 -->
<insert id="saveKnowledgeRecord" parameterType="EamWorkOrderInData">
INSERT INTO eam_knowledge_base
(site, bu_no, num, file_type, defect_describe, disposal_measures, create_date, create_by, object_id, defect_id, order_no)
VALUES (#{site}, #{buNo}, (select 'ZS'+ Right('0000000000' + convert(VARCHAR(10), isnull(max(convert(INT, SUBSTRING(num, 3, 10))), 0) + 1), 8) from eam_knowledge_base where site = #{site}), '维修', #{planDesc}, #{disposalMeasures}, getDate(), #{createBy}, #{objectID}, #{defectID}, #{orderNo})
</insert>
<!-- 修改反馈状态为已取消 -->
<update id="updateFeedBackStatus" parameterType="EamWorkOrderInData">
UPDATE eam_defect_feedBack
SET Status = '已取消'
WHERE Site = #{site} AND FeedBackID = #{planID} and bu_no = #{buNo}
</update>
<!-- 获取所有分类 -->
<select id="getFamilyTree" resultType="EamFamilyData" parameterType="EamFamilyData">
SELECT
site,
bu_no,
FamilyID,
FamilyDesc,
parent_id,
son_id,
Active
FROM eam_family
WHERE site in (select site from eam_access_site where username = #{userName})
and (site + '-' + bu_no) in (select * from dbo.query_bu(#{userName}))
and Active = 'Y'
</select>
<!-- 获得sonId -->
<select id="getSonId" resultType="string" parameterType="EamFamilyData">
SELECT
Right('0000' + convert(varchar(10),isnull(max(convert(INT,Right(son_id,2))),0)+1),2)
FROM eam_family
WHERE site = #{site} and bu_no = #{buNo} and son_id like #{parentId} + '%'
</select>
<!-- 删除该分类以及其子类-->
<delete id="eamFamilyDelete" parameterType="EamFamilyData">
DELETE FROM eam_family
WHERE site = #{site} and bu_no = #{buNo} and FamilyID = #{familyID}
<if test="sonId != null and sonId != ''">
and son_id like #{sonId} + '%'
</if>
</delete>
<select id="getEamWorkOrder" resultType="EamWorkOrderInData" parameterType="EamWorkOrderInData">
EXEC EAM_WORK_ORDER #{site}, #{username}, #{orderNo}, #{planID}, #{objectID}, #{status}, #{startDate}, #{endDate}, #{functionType}, '*'
</select>
<!-- 修改执行结果 -->
<update id="updateReportResult" parameterType="EamWorkOrderInData">
update eam_workOrder
set ActualDate = #{actualDate},
reach_date = #{reachDate},
fault_reason = #{faultReason},
handling_method = #{handlingMethod},
preventive_measure = #{preventiveMeasure},
Remark = #{remark},
WorkTime = #{workTime}
where site = #{site} and orderNo = #{orderNo} and FunctionType = #{functionType} and bu_no = #{buNo}
</update>
<!-- 根据设备查所属部门 -->
<select id="queryDepartmentByObjectId" resultType="EamObjectAdminData" parameterType="EamDefectFeedBackData">
SELECT
eo.site,
eo.bu_no,
eo.ObjectDesc,
eo.dept_id,
el.LocationName
FROM eam_object as eo
LEFT JOIN eam_location as el on eo.site = el.site and eo.LocationID = el.LocationID and eo.bu_no = el.bu_no
WHERE eo.site = #{site} and eo.ObjectID = #{objectID} and eo.bu_no = #{buNo}
</select>
<!-- 根据部门ID查机修人员电话 -->
<select id="queryPhoneByDepartmentId" resultType="EamObjectAdminData" parameterType="EamObjectAdminData">
SELECT
ed.user_display as adminName,
ed.mobile as phone
FROM Access_dept as edd
LEFT JOIN sys_user ed on edd.username = ed.username and edd.site in (select site from eam_access_site where username = ed.username)
and (edd.site + '-' + edd.bu_no) in (select * from dbo.query_bu(ed.username))
WHERE edd.site = #{site} and edd.department_id = #{deptId} and edd.bu_no = #{buNo} and ed.mobile is not null
</select>
<!-- 保存短信记录 -->
<insert id="saveMessageRecord" parameterType="MessageRecordData">
INSERT INTO send_message_record (site, bu_no, plan_id, object_id, defect_id, feed_back_desc, sender, recipient, phone, send_date)
VALUES (#{site}, #{buNo}, #{planId}, #{objectId}, #{defectId}, #{feedBackDesc}, #{sender}, #{recipient}, #{phone}, getDate())
</insert>
<!-- 查出计划结束日期为今天并且自动续期标识为Y的计划 -->
<select id="selectPlanToday" resultType="EamWorkPlanInData" parameterType="EamWorkPlanInData">
SELECT
site,
plan_id,
plan_desc,
status,
plan_start_date,
plan_end_date,
created_date,
created_by,
update_date,
update_by,
remark,
next_work_date,
delete_flag,
operator,
operator_name,
checker,
checker_name,
function_type,
properties_code,
plan_period,
work_order_rule,
plan_cycle,
task_start_date,
plan_halt_date,
auto_renewal
FROM eam_workPlan_overview
WHERE site = #{site} and status != #{status} and delete_flag = #{deleteFlag} and DATEDIFF(day, plan_end_date, getdate()) = 0 and auto_renewal = #{autoRenewal}
</select>
<!-- 查出老计划的设备 -->
<select id="selectObjectByPlanID" resultType="EamObjectInData" parameterType="EamWorkPlanInData">
SELECT
Site,
PlanID,
PlanDesc,
ObjectID,
FunctionType,
PropertiesCode,
Status
FROM eam_workPlan
WHERE site = #{site} and PlanID = #{planID} and FunctionType = #{functionType}
</select>
<!-- 获取用户 bu -->
<select id="getSiteAndBuByUserName" resultType="BuData" parameterType="BuData">
SELECT
a.site,
c.sitename,
(a.site + '_' + a.bu_no) as buNo,
b.bu_desc
FROM AccessBu as a
left join bu as b on a.bu_no = b.bu_no and a.site = b.site
left join site as c on a.site = c.siteid
WHERE a.username = #{username}
</select>
<select id="eamCheckRecordSearch" parameterType="com.jianteng.modules.pms.data.EamWorkOrderInData" resultType="com.jianteng.modules.pms.data.EamWorkOrderInData">
SELECT
a.Site,
a.bu_no,
dbo.get_bu_desc(a.site, a.bu_no) as buDesc,
a.OrderNo,
a.PlanID,
a.PlanDesc,
a.PropertiesCode,
a.ObjectID,
a.Status,
a.PlanOperator,
a.checker,
a.ActualOperator,
a.PlanDate,
a.ActualDate,
a.FunctionType,
a.CreateDate,
d.operatorName as createBy,
a.Remark,
a.StartTime,
a.EndTime,
a.WorkTime,
a.PlanOperatorName,
a.checkerName,
dbo.eam_Get_eamAdminName(a.Site, a.ActualOperator) ActualOperatorName,
dbo.eam_Get_eamObjectDesc(a.Site, a.bu_no, a.ObjectID) objectDesc,
dbo.eam_Get_eam_properties_CodeDesc(a.site, a.bu_no, a.FunctionType, a.PropertiesCode) codeDesc,
a.result,
b.urgency,
a.checkResult,
b.DefectID,
c.DefectDesc,
a.disposal_measures,
a.check_work_plan_id,
a.check_item_no,
a.reach_date,
a.reach_operator,
a.reach_operator_name,
b.FeedBackDesc,
dbo.joint_id(a.Site, a.bu_no, a.OrderNo, a.FunctionType) as adminID,
dbo.joint_name(a.Site, a.bu_no, a.OrderNo, a.FunctionType) as operator,
a.check_remark,
a.document_source,
ewi.ItemNo,
ewi.ItemDesc,
ewi.DefaultValue,
ewi.ValueType,
ewi.ValueType_DB,
ewi.ValueChooseFlag,
ewi.MaxValue,
ewi.MinValue,
ewi.ItemRemark,
ewi.ItemType,
ewi.TextValue,
ewi.NumberValue,
ewi.CreatedDate,
ewi.CreatedBy,
ewi.FinishFlag,
ewi.itemResult,
ewi.item_notes
FROM eam_workOrder a
left join eam_workOrder_item ewi on a.site = ewi.site and a.OrderNo = ewi.OrderNo and a.bu_no = ewi.bu_no
LEFT JOIN eam_defect_feedBack b on a.site = b.site and a.PlanID = b.feedBackID and a.bu_no = b.bu_no
LEFT JOIN eam_defect c on b.DefectID = c.DefectID
LEFT JOIN operator as d on a.site = d.site and a.CreateBy = d.operatorID and d.active = 'Y'
left join eam_object as eo on eo.site = a.site and eo.ObjectID = a.ObjectID and eo.bu_no = a.bu_no
left join sys_department as sd ON eo.site = sd.site and eo.dept_id = sd.department_id and eo.bu_no = sd.bu_no
left join Access_dept as ead ON ead.site = sd.site and ead.department_id = sd.department_id and ead.bu_no = sd.bu_no
left join sys_user as ea on ead.username = ea.username
left join eam_workPlan_overview as ewo on a.site = ewo.site and a.PlanID = ewo.plan_id and a.bu_no = ewo.bu_no
<where>
a.site in (select site from eam_access_site where username = #{query.userName})
and (a.site + '-' + a.bu_no) in (select * from dbo.query_bu(#{query.userName}))
and ea.username = #{query.userName}
<if test="query.buDesc != null and query.buDesc != ''">
AND dbo.get_bu_desc ( a.site, a.bu_no ) = #{query.buDesc}
</if>
<if test="query.orderNo != null and query.orderNo != ''">
AND a.OrderNo like '%' + #{query.orderNo} +'%'
</if>
<if test="query.planID != null and query.planID != ''">
AND a.PlanID like '%' + #{query.planID} +'%'
</if>
<if test="query.planDesc != null and query.planDesc != ''">
AND a.PlanDesc like '%' + #{query.planDesc} +'%'
</if>
<if test="query.objectID != null and query.objectID != ''">
AND a.ObjectID like '%' + #{query.objectID} +'%'
</if>
<if test="query.planOperatorName != null and query.planOperatorName != ''">
AND a.PlanOperatorName like '%' + #{query.planOperatorName} +'%'
</if>
<if test='(query.status == null || query.status == "") and query.functionType == "A" and query.searchType == "checkOrder" '>
AND a.status != '已取消'
</if>
<if test='query.status != null and query.status != "" and query.functionType == "A" and query.searchType == "checkOrder" '>
AND a.status = #{query.status}
</if>
<if test='query.functionType == "A" and query.searchType == "reportCheck" '>
AND a.status = '未开工'
</if>
<if test='(query.status == null || query.status == "") and query.functionType == "B" and query.searchType == "maintenanceOrder" '>
AND a.status != '已取消'
</if>
<if test='query.status != null and query.status != "" and query.functionType == "B" and query.searchType == "maintenanceOrder" '>
AND a.status = #{query.status}
</if>
<if test='query.functionType == "B" and query.searchType == "reportMaintenance" '>
AND (a.status = '未开工' or a.status = '已到达')
</if>
<if test='(query.status == null || query.status == "") and query.functionType == "C" and query.searchType == "reportDefect" '>
AND (a.status = '未开工' or a.status = '已到达')
</if>
<if test='query.status != null and query.status != "" and query.functionType == "C" and query.searchType == "reportDefect" '>
AND a.status = #{query.status}
</if>
<if test='query.documentSource != null and query.documentSource != "" and query.functionType == "C" and query.searchType == "reportDefect" '>
AND a.document_source = #{query.documentSource}
</if>
<if test="query.planDate != null">
AND a.PlanDate = #{query.planDate}
</if>
<if test="query.startDate != null ">
AND a.PlanDate >= #{query.startDate}
</if>
<if test="query.endDate != null ">
AND #{query.endDate} >= a.PlanDate
</if>
<if test="query.endDate == null ">
AND getDate() >= a.PlanDate
</if>
<if test='query.functionType == "A"'>
and getDate() >= dbo.compare_date(ewo.task_start_date)
</if>
<if test="query.reachDate != null ">
AND a.reach_date >= #{query.reachDate}
</if>
<if test="query.actualDate != null ">
AND #{query.actualDate} >= a.ActualDate
</if>
<if test="query.itemNo != null and query.itemNo != ''">
AND ewi.ItemNo like '%' + #{query.itemNo} +'%'
</if>
<if test="query.itemDesc != null and query.itemDesc != ''">
AND ewi.ItemDesc like '%' + #{query.itemDesc} +'%'
</if>
AND a.FunctionType = #{query.functionType}
</where>
ORDER BY a.CreateDate,
CASE WHEN b.urgency = '特急' THEN 1
WHEN b.urgency = '紧急' THEN 2
WHEN b.urgency = '一般' THEN 3
END
</select>
<select id="eamDefectRecordSearch" parameterType="com.jianteng.modules.pms.data.EamWorkOrderInData" resultType="com.jianteng.modules.pms.data.EamWorkOrderInData">
SELECT
a.Site,
a.bu_no,
dbo.get_bu_desc(a.site, a.bu_no) as buDesc,
a.OrderNo,
a.PlanID,
a.ObjectID,
a.Status,
a.PlanOperator,
a.ActualOperator,
a.PlanDate,
a.ActualDate,
a.FunctionType,
a.CreateDate,
d.operatorName as createBy,
a.Remark,
a.StartTime,
a.EndTime,
a.WorkTime,
dbo.eam_Get_eamAdminName(a.Site,a.PlanOperator) as planOperatorName,
b.DefectID,
c.DefectDesc,
dbo.eam_Get_eamObjectDesc(a.Site, a.bu_no, a.ObjectID) as objectDesc,
dbo.eam_Get_eam_properties_CodeDesc(a.site, a.bu_no, a.FunctionType, a.PropertiesCode) as codeDesc,
a.result,
b.urgency,
a.disposal_measures,
a.difficulty_level,
a.difficulty_remark,
f.department_name,
a.reach_date,
b.CreatedDate,
a.handling_method,
dbo.eam_Get_eamResourceDesc(a.Site, a.ObjectID) as resourceDesc,
CASE
WHEN (DATEDIFF(SECOND, b.CreatedDate, a.reach_date) <![CDATA[<]]> 60) THEN DATEDIFF(SECOND, b.CreatedDate, a.reach_date) / 60.0
ELSE DATEDIFF(MINUTE, b.CreatedDate, a.reach_date)
END AS responseTime,
b.FeedBackDesc,
dbo.joint_name(a.Site,a.bu_no,a.OrderNo,a.FunctionType) as actualOperatorName,
a.fault_reason,
a.preventive_measure,
a.document_source,
ewi.ItemNo,
ewi.ItemDesc,
ewi.DefaultValue,
ewi.ValueType,
ewi.ValueType_DB,
ewi.ValueChooseFlag,
ewi.MaxValue,
ewi.MinValue,
ewi.ItemRemark,
ewi.ItemType,
ewi.TextValue,
ewi.NumberValue,
ewi.FinishFlag,
ewi.itemResult,
ewi.item_notes
FROM eam_workOrder a
left join eam_workOrder_item ewi on a.site = ewi.site and a.OrderNo = ewi.OrderNo and a.bu_no = ewi.bu_no
left join eam_defect_feedBack b on a.site = b.site and a.PlanID = b.feedBackID and a.bu_no = b.bu_no
left join eam_defect c on b.DefectID = c.DefectID
left join operator as d on a.site = d.site and a.CreateBy = d.operatorID and d.active = 'Y'
left join eam_object as e on a.site = e.site and a.ObjectID = e.ObjectID and e.Active = 'Y' and a.bu_no = e.bu_no
left join sys_department as f on e.site = f.site and e.dept_id = f.department_id and e.bu_no = f.bu_no
left join Access_dept as ead ON ead.site = f.site and ead.department_id = f.department_id and ead.bu_no = f.bu_no
left join sys_user as ea on ead.username = ea.username
<where>
a.site in (select site from eam_access_site where username = #{query.userName})
and (a.site + '-' + a.bu_no) in (select * from dbo.query_bu(#{query.userName}))
and ea.username = #{query.userName}
<if test="query.buDesc != null and query.buDesc != ''">
AND dbo.get_bu_desc ( a.site, a.bu_no ) = #{query.buDesc}
</if>
<if test="query.deptArr != null">
AND
<foreach collection="query.deptArr" item="item" open="(" separator="or" close=")">
f.department_name like '%' + #{item} + '%'
</foreach>
</if>
<if test="query.orderNo != null and query.orderNo != ''">
AND a.OrderNo like '%' + #{query.orderNo} +'%'
</if>
<if test="query.planID != null and query.planID != ''">
AND a.PlanID like '%' + #{query.planID} +'%'
</if>
<if test="query.objectID != null and query.objectID != ''">
AND a.ObjectID like '%' + #{query.objectID} +'%'
</if>
<if test="query.planOperator != null and query.planOperator != ''">
AND a.PlanOperator like '%' + #{query.planOperator} +'%'
</if>
<if test="query.status != null and query.status != ''">
AND a.status = #{query.status}
</if>
<if test="query.documentSource != null and query.documentSource != ''">
AND a.document_source = #{query.documentSource}
</if>
<if test="query.startDate != null ">
AND a.PlanDate >= #{query.startDate}
</if>
<if test="query.endDate != null ">
AND #{query.endDate} >= a.PlanDate
</if>
<if test="query.reachDate != null ">
AND a.reach_date >= #{query.reachDate}
</if>
<if test="query.actualDate != null ">
AND #{query.actualDate} >= a.ActualDate
</if>
<if test="query.itemNo != null and query.itemNo != ''">
AND ewi.ItemNo like '%' + #{query.itemNo} +'%'
</if>
<if test="query.itemDesc != null and query.itemDesc != ''">
AND ewi.ItemDesc like '%' + #{query.itemDesc} +'%'
</if>
and a.FunctionType =#{query.functionType}
</where>
ORDER BY a.PlanDate,
CASE WHEN b.urgency = '特急' THEN 1
WHEN b.urgency = '紧急' THEN 2
WHEN b.urgency = '一般' THEN 3
END
</select>
</mapper>