/*
 * ********************************************************************************************************************
 *
 *                     :*$@@%$*:                         ;:                ;;    ;;
 *                   :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
 *                  :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
 *                  =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
 *                  =@*                                  %!              @ $= % %@=   =%@!      %=
 *             *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
 *           %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
 *         ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
 *         $@*   ;@@@%=!:                *@*
 *         =@$    ;;;!=%@@@@=!           =@!
 *          %@$:      =@%: :*@@@*       %@=                    Copyright (c) 2016-2019.  北京上格云技术有限公司
 *           ;%@@$=$@@%*       *@@@$=%@@%;
 *              ::;::             ::;::                                              All rights reserved.
 *
 * ********************************************************************************************************************
 */

package com.persagy.server.service

import com.persagy.server.models.requests.EquipUpDateEnclosure
import com.persagy.server.models.requests.EquipUpDateEnclosureRequest
import com.alibaba.fastjson.JSONArray
import com.alibaba.fastjson.JSONObject
import com.persagy.base.extensions.toJson
import com.persagy.database.SFilter
import com.persagy.database.SQueryBuilder
import com.persagy.mybatis.SMybatisDao
import com.persagy.server.datacenter.models.entities.assistant.TaskPic
import com.persagy.server.models.PropertyEquip
import com.persagy.server.service.base.Service
import com.persagy.server.service.objects.PropertyService
import com.persagy.service.SPageContext
import com.persagy.service.models.enums.SResponseType
import com.persagy.service.models.responses.SBaseResponse
import org.slf4j.LoggerFactory

/**
 * 资产关联设备信息服务
 *
 * @author 张维新
 */
object PropertyEquipService : Service<PropertyEquip>(SMybatisDao(PropertyEquip::class.java)) {
    /** 日志 */
     val logger = LoggerFactory.getLogger(PropertyEquipService::class.java)

    /**
     * 查询之前的操作
     */
    override fun onQueryBefore(queryBuilder: SQueryBuilder<PropertyEquip>) {
        queryBuilder.tableName = "v_property_equip"
        return
    } // Function onQueryBefore()


    /**
     * 修改设备的附件,增量方式
     */
    fun equipUpDateEnclosurs(equipUpDateEnclosureRequest: EquipUpDateEnclosureRequest<EquipUpDateEnclosure>) : SBaseResponse {
        return try {
            val projectId = SPageContext.getHeader("ProjectId")
            val equipUpDateEnclosureList = equipUpDateEnclosureRequest.content
            if (!equipUpDateEnclosureList.isNullOrEmpty()){
                for (equipUpDateEnclosure in equipUpDateEnclosureList){
                    /** id不能为空 */
                    if (equipUpDateEnclosure.equipId.isNullOrEmpty()){
                        val sBaseResponse = SBaseResponse(SResponseType.failure)
                        sBaseResponse.message = "设备id不能为空"
                        sBaseResponse
                    }
                    val equip = PropertyService.select(SFilter.eq("projectId", projectId!!), SFilter.eq("id", equipUpDateEnclosure.equipId!!)).entity()

                    if (equip == null){

                    }

                    if (!equipUpDateEnclosure.Pic.isNullOrEmpty()){

                        if (!equip!!.ledgerParam.isNullOrEmpty()){
                            val containsKey = equip.ledgerParam!!.containsKey("PhotoDoc")
                            if (containsKey){
                                logger.debug("PhotoDoc存在")
                                logger.debug("PhotoDoc数据=${equip.ledgerParam!!["PhotoDoc"]}")
                                val photoDocMap = equip.ledgerParam!!["PhotoDoc"] as JSONObject
                                val containsKeyPic = photoDocMap.containsKey("Pic")
                                if (containsKeyPic){
                                    val any = photoDocMap["Pic"] as JSONArray
                                    any.addAll(equipUpDateEnclosure.Pic!!)
                                    logger.debug("图片数据=${any.toJson()}")
                                }else{
                                    photoDocMap["Pic"] = equipUpDateEnclosure.Pic!!
                                }
                            }else{
                                logger.debug("PhotoDoc不存在")
                                val mapPic = HashMap<String,ArrayList<TaskPic>>()
                                mapPic.put("Pic",equipUpDateEnclosure.Pic!!)
                                equip.ledgerParam!!.put("PhotoDoc",mapPic)
                            }
                        }else{
                            val mapPic = HashMap<String,ArrayList<TaskPic>>()
                            mapPic.put("Pic",equipUpDateEnclosure.Pic!!)
                            val mapPhotoDoc = HashMap<String,Any?>()
                            mapPhotoDoc.put("PhotoDoc",mapPic)
                            equip.ledgerParam = mapPhotoDoc
                        }
                    }
                    if (!equipUpDateEnclosure.archive.isNullOrEmpty()){
                        if (!equip!!.ledgerParam.isNullOrEmpty()){
                            val containsKey = equip.ledgerParam!!.containsKey("PhotoDoc")
                            if (containsKey){
                                logger.debug("PhotoDoc存在")
                                logger.debug("PhotoDoc数据=${equip.ledgerParam!!["PhotoDoc"]}")
                                val photoDocMap = equip.ledgerParam!!["PhotoDoc"] as JSONObject
                                val containsKeyPic = photoDocMap.containsKey("Archive")
                                if (containsKeyPic){
                                    val any = photoDocMap["Archive"] as JSONArray
                                    any.addAll(equipUpDateEnclosure.archive!!)
                                    logger.debug("图片数据=${any.toJson()}")
                                }else{
                                    photoDocMap["Archive"] = equipUpDateEnclosure.archive!!
                                }
                            }else{
                                logger.debug("PhotoDoc不存在")
                                val mapPic = HashMap<String,ArrayList<TaskPic>>()
                                mapPic.put("Archive",equipUpDateEnclosure.archive!!)
                                equip.ledgerParam!!.put("PhotoDoc",mapPic)
                            }
                        }else{
                            val mapPic = HashMap<String,ArrayList<TaskPic>>()
                            mapPic.put("Archive",equipUpDateEnclosure.archive!!)
                            val mapPhotoDoc = HashMap<String,Any?>()
                            mapPhotoDoc.put("PhotoDoc",mapPic)
                            equip.ledgerParam = mapPhotoDoc
                        }
                    }
                    if (!equipUpDateEnclosure.checkReport.isNullOrEmpty()){
                        if (!equip!!.ledgerParam.isNullOrEmpty()){
                            val containsKey = equip.ledgerParam!!.containsKey("Siteinstall")
                            if (containsKey){
                                logger.debug("Siteinstall存在")
                                logger.debug("Siteinstall数据=${equip.ledgerParam!!["Siteinstall"]}")
                                val photoDocMap = equip.ledgerParam!!["Siteinstall"] as JSONObject
                                val containsKeyPic = photoDocMap.containsKey("CheckReport")
                                if (containsKeyPic){
                                    val any = photoDocMap["CheckReport"] as JSONArray
                                    any.addAll(equipUpDateEnclosure.checkReport!!)
                                    logger.debug("图片数据=${any.toJson()}")
                                }else{
                                    photoDocMap["CheckReport"] = equipUpDateEnclosure.checkReport!!
                                }
                            }else{
                                logger.debug("Siteinstall不存在")
                                val mapPic = HashMap<String,ArrayList<TaskPic>>()
                                mapPic.put("CheckReport",equipUpDateEnclosure.checkReport!!)
                                equip.ledgerParam!!.put("Siteinstall",mapPic)
                            }
                        }else{
                            val mapPic = HashMap<String,ArrayList<TaskPic>>()
                            mapPic.put("CheckReport",equipUpDateEnclosure.checkReport!!)
                            val mapPhotoDoc = HashMap<String,Any?>()
                            mapPhotoDoc.put("Siteinstall",mapPic)
                            equip.ledgerParam = mapPhotoDoc
                        }

                    }
                    if (!equipUpDateEnclosure.drawing.isNullOrEmpty()){

                        if (!equip!!.ledgerParam.isNullOrEmpty()){
                            val containsKey = equip.ledgerParam!!.containsKey("PhotoDoc")
                            if (containsKey){
                                logger.debug("PhotoDoc存在")
                                logger.debug("PhotoDoc数据=${equip.ledgerParam!!["PhotoDoc"]}")
                                val photoDocMap = equip.ledgerParam!!["PhotoDoc"] as JSONObject
                                val containsKeyPic = photoDocMap.containsKey("Drawing")
                                if (containsKeyPic){
                                    val any = photoDocMap["Drawing"] as JSONArray
                                    any.addAll(equipUpDateEnclosure.drawing!!)
                                    logger.debug("图片数据=${any.toJson()}")
                                }else{
                                    photoDocMap["Drawing"] = equipUpDateEnclosure.drawing!!
                                }
                            }else{
                                logger.debug("PhotoDoc不存在")
                                val mapPic = HashMap<String,ArrayList<TaskPic>>()
                                mapPic.put("Drawing",equipUpDateEnclosure.drawing!!)
                                equip.ledgerParam!!.put("PhotoDoc",mapPic)
                            }
                        }else{
                            val mapPic = HashMap<String,ArrayList<TaskPic>>()
                            mapPic.put("Drawing",equipUpDateEnclosure.drawing!!)
                            val mapPhotoDoc = HashMap<String,Any?>()
                            mapPhotoDoc.put("PhotoDoc",mapPic)
                            equip.ledgerParam = mapPhotoDoc
                        }

                    }
                    if (!equipUpDateEnclosure.installDrawing.isNullOrEmpty()){

                        if (!equip!!.ledgerParam.isNullOrEmpty()){
                            val containsKey = equip.ledgerParam!!.containsKey("Siteinstall")
                            if (containsKey){
                                logger.debug("Siteinstall存在")
                                logger.debug("Siteinstall数据=${equip.ledgerParam!!["Siteinstall"]}")
                                val photoDocMap = equip.ledgerParam!!["Siteinstall"] as JSONObject
                                val containsKeyPic = photoDocMap.containsKey("InstallDrawing")
                                if (containsKeyPic){
                                    val any = photoDocMap["InstallDrawing"] as JSONArray
                                    any.addAll(equipUpDateEnclosure.installDrawing!!)
                                    logger.debug("图片数据=${any.toJson()}")
                                }else{
                                    photoDocMap["InstallDrawing"] = equipUpDateEnclosure.installDrawing!!
                                }
                            }else{
                                logger.debug("Siteinstall不存在")
                                val mapPic = HashMap<String,ArrayList<TaskPic>>()
                                mapPic.put("InstallDrawing",equipUpDateEnclosure.installDrawing!!)
                                equip.ledgerParam!!.put("Siteinstall",mapPic)
                            }
                        }else{
                            val mapPic = HashMap<String,ArrayList<TaskPic>>()
                            mapPic.put("InstallDrawing",equipUpDateEnclosure.installDrawing!!)
                            val mapPhotoDoc = HashMap<String,Any?>()
                            mapPhotoDoc.put("Siteinstall",mapPic)
                            equip.ledgerParam = mapPhotoDoc
                        }
                    }
                    if (!equipUpDateEnclosure.installPic.isNullOrEmpty()){
                        if (!equip!!.ledgerParam.isNullOrEmpty()){
                            val containsKey = equip.ledgerParam!!.containsKey("Siteinstall")
                            if (containsKey){
                                logger.debug("Siteinstall存在")
                                logger.debug("Siteinstall数据=${equip.ledgerParam!!["Siteinstall"]}")
                                val photoDocMap = equip.ledgerParam!!["Siteinstall"] as JSONObject
                                val containsKeyPic = photoDocMap.containsKey("InstallPic")
                                if (containsKeyPic){
                                    val any = photoDocMap["InstallPic"] as JSONArray
                                    any.addAll(equipUpDateEnclosure.installPic!!)
                                    logger.debug("图片数据=${any.toJson()}")
                                }else{
                                    photoDocMap["InstallPic"] = equipUpDateEnclosure.installPic!!
                                }
                            }else{
                                logger.debug("Siteinstall不存在")
                                val mapPic = HashMap<String,ArrayList<TaskPic>>()
                                mapPic.put("InstallPic",equipUpDateEnclosure.installPic!!)
                                equip.ledgerParam!!.put("Siteinstall",mapPic)
                            }
                        }else{
                            val mapPic = HashMap<String,ArrayList<TaskPic>>()
                            mapPic.put("InstallPic",equipUpDateEnclosure.installPic!!)
                            val mapPhotoDoc = HashMap<String,Any?>()
                            mapPhotoDoc.put("Siteinstall",mapPic)
                            equip.ledgerParam = mapPhotoDoc
                        }
                    }

                    if (!equipUpDateEnclosure.insuranceFile.isNullOrEmpty()){

                        if (!equip!!.ledgerParam.isNullOrEmpty()){
                            val containsKey = equip.ledgerParam!!.containsKey("InsuranceDoc")
                            if (containsKey){
                                logger.debug("InsuranceDoc存在")
                                logger.debug("InsuranceDoc数据=${equip.ledgerParam!!["InsuranceDoc"]}")
                                val photoDocMap = equip.ledgerParam!!["InsuranceDoc"] as JSONObject
                                val containsKeyPic = photoDocMap.containsKey("InsuranceFile")
                                if (containsKeyPic){
                                    val any = photoDocMap["InsuranceFile"] as JSONArray
                                    any.addAll(equipUpDateEnclosure.insuranceFile!!)
                                    logger.debug("图片数据=${any.toJson()}")
                                }else{
                                    photoDocMap["InsuranceFile"] = equipUpDateEnclosure.insuranceFile!!
                                }
                            }else{
                                logger.debug("InsuranceDoc不存在")
                                val mapPic = HashMap<String,ArrayList<TaskPic>>()
                                mapPic.put("InsuranceFile",equipUpDateEnclosure.insuranceFile!!)
                                equip.ledgerParam!!.put("InsuranceDoc",mapPic)
                            }
                        }else{
                            val mapPic = HashMap<String,ArrayList<TaskPic>>()
                            mapPic.put("InsuranceFile",equipUpDateEnclosure.insuranceFile!!)
                            val mapPhotoDoc = HashMap<String,Any?>()
                            mapPhotoDoc.put("InsuranceDoc",mapPic)
                            equip.ledgerParam = mapPhotoDoc
                        }

                    }
                    if (!equipUpDateEnclosure.nameplate.isNullOrEmpty()){
                        if (!equip!!.ledgerParam.isNullOrEmpty()){
                            val containsKey = equip.ledgerParam!!.containsKey("PhotoDoc")
                            if (containsKey){
                                logger.debug("PhotoDoc存在")
                                logger.debug("PhotoDoc数据=${equip.ledgerParam!!["PhotoDoc"]}")
                                val photoDocMap = equip.ledgerParam!!["PhotoDoc"] as JSONObject
                                val containsKeyPic = photoDocMap.containsKey("Nameplate")
                                if (containsKeyPic){
                                    val any = photoDocMap["Nameplate"] as JSONArray
                                    any.addAll(equipUpDateEnclosure.nameplate!!)
                                    logger.debug("图片数据=${any.toJson()}")
                                }else{
                                    photoDocMap["Nameplate"] = equipUpDateEnclosure.nameplate!!
                                }
                            }else{
                                logger.debug("PhotoDoc不存在")
                                val mapPic = HashMap<String,ArrayList<TaskPic>>()
                                mapPic.put("Nameplate",equipUpDateEnclosure.nameplate!!)
                                equip.ledgerParam!!.put("PhotoDoc",mapPic)
                            }
                        }else{
                            val mapPic = HashMap<String,ArrayList<TaskPic>>()
                            mapPic.put("Nameplate",equipUpDateEnclosure.nameplate!!)
                            val mapPhotoDoc = HashMap<String,Any?>()
                            mapPhotoDoc.put("PhotoDoc",mapPic)
                            equip.ledgerParam = mapPhotoDoc
                        }
                    }
                    /** 操作说明书 */
                    if (!equipUpDateEnclosure.operationManual.isNullOrEmpty()){
                        if (!equip!!.ledgerParam.isNullOrEmpty()){
                            val containsKey = equip.ledgerParam!!.containsKey("PhotoDoc")
                            if (containsKey){
                                logger.debug("PhotoDoc存在")
                                logger.debug("PhotoDoc数据=${equip.ledgerParam!!["PhotoDoc"]}")
                                val photoDocMap = equip.ledgerParam!!["PhotoDoc"] as JSONObject
                                val containsKeyPic = photoDocMap.containsKey("OperationManual")
                                if (containsKeyPic){
                                    val any = photoDocMap["OperationManual"] as JSONArray
                                    any.addAll(equipUpDateEnclosure.operationManual!!)
                                    logger.debug("图片数据=${any.toJson()}")
                                }else{
                                    photoDocMap["OperationManual"] = equipUpDateEnclosure.operationManual!!
                                }
                            }else{
                                logger.debug("PhotoDoc不存在")
                                val mapPic = HashMap<String,ArrayList<TaskPic>>()
                                mapPic.put("OperationManual",equipUpDateEnclosure.operationManual!!)
                                equip.ledgerParam!!.put("PhotoDoc",mapPic)
                            }
                        }else{
                            val mapPic = HashMap<String,ArrayList<TaskPic>>()
                            mapPic.put("OperationManual",equipUpDateEnclosure.operationManual!!)
                            val mapPhotoDoc = HashMap<String,Any?>()
                            mapPhotoDoc.put("PhotoDoc",mapPic)
                            equip.ledgerParam = mapPhotoDoc
                        }
                    }
                    /** 产品合格证 */
                    if (!equipUpDateEnclosure.productCertification.isNullOrEmpty()){
                        if (!equip!!.ledgerParam.isNullOrEmpty()){
                            val containsKey = equip.ledgerParam!!.containsKey("PhotoDoc")
                            if (containsKey){
                                logger.debug("PhotoDoc存在")
                                logger.debug("PhotoDoc数据=${equip.ledgerParam!!["PhotoDoc"]}")
                                val photoDocMap = equip.ledgerParam!!["PhotoDoc"] as JSONObject
                                val containsKeyPic = photoDocMap.containsKey("ProductCertification")
                                if (containsKeyPic){
                                    val any = photoDocMap["ProductCertification"] as JSONArray
                                    any.addAll(equipUpDateEnclosure.productCertification!!)
                                    logger.debug("图片数据=${any.toJson()}")
                                }else{
                                    photoDocMap["ProductCertification"] = equipUpDateEnclosure.productCertification!!
                                }
                            }else{
                                logger.debug("PhotoDoc不存在")
                                val mapPic = HashMap<String,ArrayList<TaskPic>>()
                                mapPic.put("ProductCertification",equipUpDateEnclosure.productCertification!!)
                                equip.ledgerParam!!.put("PhotoDoc",mapPic)
                            }
                        }else{
                            val mapPic = HashMap<String,ArrayList<TaskPic>>()
                            mapPic.put("ProductCertification",equipUpDateEnclosure.productCertification!!)
                            val mapPhotoDoc = HashMap<String,Any?>()
                            mapPhotoDoc.put("PhotoDoc",mapPic)
                            equip.ledgerParam = mapPhotoDoc
                        }
                    }
                    /** 维修保养手册 */
                    if (!equipUpDateEnclosure.maintainManual.isNullOrEmpty()){
                        if (!equip!!.ledgerParam.isNullOrEmpty()){
                            val containsKey = equip.ledgerParam!!.containsKey("OperationMainte")
                            if (containsKey){
                                logger.debug("OperationMainte存在")
                                logger.debug("OperationMainte数据=${equip.ledgerParam!!["OperationMainte"]}")
                                val photoDocMap = equip.ledgerParam!!["OperationMainte"] as JSONObject
                                val containsKeyPic = photoDocMap.containsKey("MaintainManual")
                                if (containsKeyPic){
                                    val any = photoDocMap["MaintainManual"] as JSONArray
                                    any.addAll(equipUpDateEnclosure.maintainManual!!)
                                    logger.debug("图片数据=${any.toJson()}")
                                }else{
                                    photoDocMap["MaintainManual"] = equipUpDateEnclosure.maintainManual!!
                                }
                            }else{
                                logger.debug("OperationMainte不存在")
                                val mapPic = HashMap<String,ArrayList<TaskPic>>()
                                mapPic.put("MaintainManual",equipUpDateEnclosure.maintainManual!!)
                                equip.ledgerParam!!.put("OperationMainte",mapPic)
                            }
                        }else{
                            val mapPic = HashMap<String,ArrayList<TaskPic>>()
                            mapPic.put("MaintainManual",equipUpDateEnclosure.maintainManual!!)
                            val mapPhotoDoc = HashMap<String,Any?>()
                            mapPhotoDoc.put("OperationMainte",mapPic)
                            equip.ledgerParam = mapPhotoDoc
                        }
                    }
                    /** 安装说明书 */
                    if (!equipUpDateEnclosure.installInstruction.isNullOrEmpty()){
                        if (!equip!!.ledgerParam.isNullOrEmpty()){
                            val containsKey = equip.ledgerParam!!.containsKey("Siteinstall")
                            if (containsKey){
                                logger.debug("Siteinstall存在")
                                logger.debug("Siteinstall数据=${equip.ledgerParam!!["Siteinstall"]}")
                                val photoDocMap = equip.ledgerParam!!["Siteinstall"] as JSONObject
                                val containsKeyPic = photoDocMap.containsKey("InstallInstruction")
                                if (containsKeyPic){
                                    val any = photoDocMap["InstallInstruction"] as JSONArray
                                    any.addAll(equipUpDateEnclosure.installInstruction!!)
                                    logger.debug("图片数据=${any.toJson()}")
                                }else{
                                    photoDocMap["InstallInstruction"] = equipUpDateEnclosure.installInstruction!!
                                }
                            }else{
                                logger.debug("Siteinstall不存在")
                                val mapPic = HashMap<String,ArrayList<TaskPic>>()
                                mapPic.put("InstallInstruction",equipUpDateEnclosure.installInstruction!!)
                                equip.ledgerParam!!.put("Siteinstall",mapPic)
                            }
                        }else{
                            val mapPic = HashMap<String,ArrayList<TaskPic>>()
                            mapPic.put("InstallInstruction",equipUpDateEnclosure.installInstruction!!)
                            val mapPhotoDoc = HashMap<String,Any?>()
                            mapPhotoDoc.put("Siteinstall",mapPic)
                            equip.ledgerParam = mapPhotoDoc
                        }
                    }
                    /** 验收报告 */
                    if (!equipUpDateEnclosure.acceptanceReport.isNullOrEmpty()){
                        if (!equip!!.ledgerParam.isNullOrEmpty()){
                            val containsKey = equip.ledgerParam!!.containsKey("SupplyPurchase")
                            if (containsKey){
                                logger.debug("SupplyPurchase存在")
                                logger.debug("SupplyPurchase数据=${equip.ledgerParam!!["SupplyPurchase"]}")
                                val photoDocMap = equip.ledgerParam!!["SupplyPurchase"] as JSONObject
                                val containsKeyPic = photoDocMap.containsKey("AcceptanceReport")
                                if (containsKeyPic){
                                    val any = photoDocMap["AcceptanceReport"] as JSONArray
                                    any.addAll(equipUpDateEnclosure.acceptanceReport!!)
                                    logger.debug("图片数据=${any.toJson()}")
                                }else{
                                    photoDocMap["AcceptanceReport"] = equipUpDateEnclosure.acceptanceReport!!
                                }
                            }else{
                                logger.debug("SupplyPurchase不存在")
                                val mapPic = HashMap<String,ArrayList<TaskPic>>()
                                mapPic.put("AcceptanceReport",equipUpDateEnclosure.acceptanceReport!!)
                                equip.ledgerParam!!.put("SupplyPurchase",mapPic)
                            }
                        }else{
                            val mapPic = HashMap<String,ArrayList<TaskPic>>()
                            mapPic.put("AcceptanceReport",equipUpDateEnclosure.acceptanceReport!!)
                            val mapPhotoDoc = HashMap<String,Any?>()
                            mapPhotoDoc.put("SupplyPurchase",mapPic)
                            equip.ledgerParam = mapPhotoDoc
                        }
                    }
                    /** 进场验收单 */
                    if (!equipUpDateEnclosure.approachingAcceptance.isNullOrEmpty()){
                        if (!equip!!.ledgerParam.isNullOrEmpty()){
                            val containsKey = equip.ledgerParam!!.containsKey("SupplyPurchase")
                            if (containsKey){
                                logger.debug("SupplyPurchase存在")
                                logger.debug("SupplyPurchase数据=${equip.ledgerParam!!["SupplyPurchase"]}")
                                val photoDocMap = equip.ledgerParam!!["SupplyPurchase"] as JSONObject
                                val containsKeyPic = photoDocMap.containsKey("ApproachingAcceptance")
                                if (containsKeyPic){
                                    val any = photoDocMap["ApproachingAcceptance"] as JSONArray
                                    any.addAll(equipUpDateEnclosure.approachingAcceptance!!)
                                    logger.debug("图片数据=${any.toJson()}")
                                }else{
                                    photoDocMap["ApproachingAcceptance"] = equipUpDateEnclosure.approachingAcceptance!!
                                }
                            }else{
                                logger.debug("SupplyPurchase不存在")
                                val mapPic = HashMap<String,ArrayList<TaskPic>>()
                                mapPic.put("ApproachingAcceptance",equipUpDateEnclosure.approachingAcceptance!!)
                                equip.ledgerParam!!.put("SupplyPurchase",mapPic)
                            }
                        }else{
                            val mapPic = HashMap<String,ArrayList<TaskPic>>()
                            mapPic.put("ApproachingAcceptance",equipUpDateEnclosure.approachingAcceptance!!)
                            val mapPhotoDoc = HashMap<String,Any?>()
                            mapPhotoDoc.put("SupplyPurchase",mapPic)
                            equip.ledgerParam = mapPhotoDoc
                        }
                    }
                    /** 供应合同 */
                    if (!equipUpDateEnclosure.supplierContract.isNullOrEmpty()){
                        if (!equip!!.ledgerParam.isNullOrEmpty()){
                            val containsKey = equip.ledgerParam!!.containsKey("SupplyPurchase")
                            if (containsKey){
                                logger.debug("SupplyPurchase存在")
                                logger.debug("SupplyPurchase数据=${equip.ledgerParam!!["SupplyPurchase"]}")
                                val photoDocMap = equip.ledgerParam!!["SupplyPurchase"] as JSONObject
                                val containsKeyPic = photoDocMap.containsKey("SupplierContract")
                                if (containsKeyPic){
                                    val any = photoDocMap["SupplierContract"] as JSONArray
                                    any.addAll(equipUpDateEnclosure.supplierContract!!)
                                    logger.debug("图片数据=${any.toJson()}")
                                }else{
                                    photoDocMap["SupplierContract"] = equipUpDateEnclosure.supplierContract!!
                                }
                            }else{
                                logger.debug("PSupplyPurchase不存在")
                                val mapPic = HashMap<String,ArrayList<TaskPic>>()
                                mapPic.put("SupplierContract",equipUpDateEnclosure.supplierContract!!)
                                equip.ledgerParam!!.put("PSupplyPurchase",mapPic)
                            }
                        }else{
                            val mapPic = HashMap<String,ArrayList<TaskPic>>()
                            mapPic.put("SupplierContract",equipUpDateEnclosure.supplierContract!!)
                            val mapPhotoDoc = HashMap<String,Any?>()
                            mapPhotoDoc.put("SupplyPurchase",mapPic)
                            equip.ledgerParam = mapPhotoDoc
                        }
                    }
                    /** 检测报告 */
                    if (!equipUpDateEnclosure.testReport.isNullOrEmpty()){
                        if (!equip!!.ledgerParam.isNullOrEmpty()){
                            val containsKey = equip.ledgerParam!!.containsKey("EquipManufactor")
                            if (containsKey){
                                logger.debug("EquipManufactor存在")
                                logger.debug("EquipManufactor数据=${equip.ledgerParam!!["EquipManufactor"]}")
                                val photoDocMap = equip.ledgerParam!!["EquipManufactor"] as JSONObject
                                val containsKeyPic = photoDocMap.containsKey("TestReport")
                                if (containsKeyPic){
                                    val any = photoDocMap["TestReport"] as JSONArray
                                    any.addAll(equipUpDateEnclosure.testReport!!)
                                    logger.debug("图片数据=${any.toJson()}")
                                }else{
                                    photoDocMap["TestReport"] = equipUpDateEnclosure.testReport!!
                                }
                            }else{
                                logger.debug("PhotoDoc不存在")
                                val mapPic = HashMap<String,ArrayList<TaskPic>>()
                                mapPic.put("TestReport",equipUpDateEnclosure.testReport!!)
                                equip.ledgerParam!!.put("EquipManufactor",mapPic)
                            }
                        }else{
                            val mapPic = HashMap<String,ArrayList<TaskPic>>()
                            mapPic.put("TestReport",equipUpDateEnclosure.testReport!!)
                            val mapPhotoDoc = HashMap<String,Any?>()
                            mapPhotoDoc.put("EquipManufactor",mapPic)
                            equip.ledgerParam = mapPhotoDoc
                        }
                    }

                    /** 原厂证明 */
                    if (!equipUpDateEnclosure.originalCertificate.isNullOrEmpty()){
                        if (!equip!!.ledgerParam.isNullOrEmpty()){
                            val containsKey = equip.ledgerParam!!.containsKey("EquipManufactor")
                            if (containsKey){
                                logger.debug("EquipManufactor存在")
                                logger.debug("EquipManufactor数据=${equip.ledgerParam!!["EquipManufactor"]}")
                                val photoDocMap = equip.ledgerParam!!["EquipManufactor"] as JSONObject
                                val containsKeyPic = photoDocMap.containsKey("OriginalCertificate")
                                if (containsKeyPic){
                                    val any = photoDocMap["OriginalCertificate"] as JSONArray
                                    any.addAll(equipUpDateEnclosure.originalCertificate!!)
                                    logger.debug("图片数据=${any.toJson()}")
                                }else{
                                    photoDocMap["OriginalCertificate"] = equipUpDateEnclosure.originalCertificate!!
                                }
                            }else{
                                logger.debug("EquipManufactor不存在")
                                val mapPic = HashMap<String,ArrayList<TaskPic>>()
                                mapPic.put("OriginalCertificate",equipUpDateEnclosure.originalCertificate!!)
                                equip.ledgerParam!!.put("EquipManufactor",mapPic)
                            }
                        }else{
                            val mapPic = HashMap<String,ArrayList<TaskPic>>()
                            mapPic.put("OriginalCertificate",equipUpDateEnclosure.originalCertificate!!)
                            val mapPhotoDoc = HashMap<String,Any?>()
                            mapPhotoDoc.put("EquipManufactor",mapPic)
                            equip.ledgerParam = mapPhotoDoc
                        }
                    }


                    /** 更新设备 */
                    PropertyService.update(equip!!,null, SFilter.eq("projectId",projectId!!), SFilter.eq("id",equipUpDateEnclosure.equipId!!))

                }


                try {
                    val jsonObject = org.json.JSONObject()
                    jsonObject.put("type", "7")
                    jsonObject.put("projectId", projectId)
                    val jsonArray = org.json.JSONArray()
                    for (entity in equipUpDateEnclosureList) {
                        val jsonInfos = org.json.JSONObject()
                        jsonInfos.put("id", entity.equipId)
                        jsonArray.put(jsonInfos)
                    }
                    jsonObject.put("infos", jsonArray)

                    /** 发送消息 */
                    messageHandler.sendMessage(jsonObject.toString())
                } catch (e: Exception) {
                    e.printStackTrace()
                }

                val sBaseResponse = SBaseResponse(SResponseType.success)
                sBaseResponse
            }else{
                val sBaseResponse = SBaseResponse(SResponseType.failure)
                sBaseResponse.message = "不能传入空值"
                sBaseResponse
            }
        } catch (e: Exception) {
            e.printStackTrace()
            SBaseResponse(SResponseType.failure)
        }
    } //

} // Object PropertyService
