/*
 * *********************************************************************************************************************
 *
 *          !!
 *        .F88X
 *        X8888Y
 *      .}888888N;
 *        i888888N;        .:!              .I$WI:
 *          R888888I      .'N88~            i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8&
 *          .R888888I    .;N8888~          .X8'  "8I.!,/8"  !%NY8`"8I8~~8>,88I
 *            +888888N;  .8888888Y                                  "&&8Y.}8,
 *            ./888888N;  .R888888Y        .'}~    .>}'.`+>  i}!    "i'  +/'  .'i~  !11,.:">,  .~]!  .i}i
 *              ~888888%:  .I888888l      .]88~`1/iY88Ii+1'.R$8$8]"888888888>  Y8$  W8E  X8E  W8888'188Il}Y88$*
 *              18888888    E8888881    .]W%8$`R8X'&8%++N8i,8N%N8+l8%`  .}8N:.R$RE%N88N%N$K$R  188,FE$8%~Y88I
 *            .E888888I  .i8888888'      .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~
 *            8888888I  .,N888888~        ~88i"8W,!N8*.I88.}888%F,i$88"F88"  888:E8X.>88!i88>`888*.}Fl1]*}1YKi'
 *          i888888N'      I888Y          ]88;/EX*IFKFK88X  K8R  .l8W  88Y  ~88}'88E&%8W.X8N``]88!.$8K  .:W8I
 *        .i888888N;        I8Y          .&8$  .X88!  i881.:%888>I88  ;88]  +88+.';;;;:.Y88X  18N.,88l  .+88/
 *      .:R888888I
 *      .&888888I                                          Copyright (c) 2009-2020.  博锐尚格科技股份有限公司
 *        ~8888'
 *        .!88~                                                                     All rights reserved.
 *
 * *********************************************************************************************************************
 */

package com.persagy.server.services.objects

import com.persagy.mybatis.SMybatisDao
import com.persagy.server.datacenter.models.entities.objects.Project
import com.persagy.server.services.base.Service
import org.slf4j.LoggerFactory

/**
 * 项目信息服务
 *
 * @author 张维新
 */
object ProjectService : Service<Project>(SMybatisDao(Project::class.java)) {
    /** 日志 */
    private val logger = LoggerFactory.getLogger(ProjectService::class.java)



    /**
     * 创建项目
     *
     * @param   code        城市编码
     * @param   password    项目密码
     * @param   project     项目对象
     * @return              创建结果信息
     */
//    fun create(code: String?, password: String, project: Project, messageHandler: MessageHandler?): SCreateResponse {
//        return try {
//            /** code不能为空 */
//            if (code.isNullOrEmpty()) {
//                val sCreateResponse = SCreateResponse()
//                sCreateResponse.message = "请输入正确的区域编码"
//                sCreateResponse.result = SResponseType.failure
//                return sCreateResponse
//            } else {
//                /** 查询code是否正确 */
//                val entity = DictProvincialCityCodeService.select(SFilter.eq("code", code)).entity()
//                if (entity == null) {
//                    val sCreateResponse = SCreateResponse()
//                    sCreateResponse.message = "区域码不存在"
//                    sCreateResponse.result = SResponseType.failure
//                    return sCreateResponse
//                }
//            }
//            /** 获取区域存在几个建筑 */
//            val count = baseDao.select(SFilter.contain("id", code)).exec()
//            logger.debug("数量=${count.size}")
//            /** 项目id */
//            if (!project.id.isNullOrEmpty()) {
//                val isWith = project.id!!.startsWith("Pj")
//                if (!isWith) {
//                    project.id = IdUtils.projectIdCreate(code, count.size)
//                }
//            } else {
//                project.id = IdUtils.projectIdCreate(code, count.size)
//            }
//
//            if (project.name.isNullOrEmpty()){
//                val genId = String.format("%1$4s", count.size+1).replace(' ', '0')
//                val cityCodeEntity = DictProvincialCityCodeService.select(SFilter.eq("code", code)).entity()
//                var  nameCity =cityCodeEntity!!.name!!+genId+"项目"
//                if (!cityCodeEntity.parent.isNullOrEmpty()){
//                    val cityCode = DictProvincialCityCodeService.select(SFilter.eq("code", cityCodeEntity.parent!!)).entity()
//                    nameCity = cityCode!!.name+cityCodeEntity.name!!+genId+"项目"
//
//                    if (!cityCode.parent.isNullOrEmpty()){
//                        val city = DictProvincialCityCodeService.select(SFilter.eq("code", cityCode.parent!!)).entity()
//                        nameCity = city!!.name+cityCode.name+cityCodeEntity.name!!+genId+"项目"
//                    }
//                }
//                project.name = nameCity
//            }
//
//            logger.debug("项目id = ${project.id}")
//            /** 项目密码 */
//            project.password = password
//            val isSuccess = baseDao.insert(project)
//            /** 创建成功 */
//            if (isSuccess) {
//                val jsonObject = JSONObject()
//                jsonObject.put("type", "1")
//                jsonObject.put("projectId", project.id)
//                jsonObject.put("id", project.id)
//                /** 发送消息 */
//                messageHandler!!.sendMessage(jsonObject.toString())
//                /** 返回创建成功的项目id */
//                SCreateResponse(project.id!!)
//            } else {
//                val sCreateResponse = SCreateResponse()
//                sCreateResponse.message = "创建失败"
//                sCreateResponse.result = SResponseType.failure
//                sCreateResponse
//            }
//        } catch (e: Exception) {
//            e.printStackTrace()
//            SCreateResponse(SResponseType.failure, e.message!!)
//        }
//    } // Function create()

    /**
     * 根据id删除
     *
     * @param   idList      id数组
     * @return              删除的结果信息
     */
//    fun delete(idList: ArrayList<String>, messageHandler: MessageHandler?): SDeleteResponse {
//        try {
//            /** 成功集合 */
//            val successList = ArrayList<Any>()
//            /** 失败集合 */
//            val failureList = ArrayList<Any>()
//            for (id in idList) {
//                val isDelete = ProjectService.delete("id" to id)
//                /** 删除成功 */
//                if (isDelete) {
//                    val jsonObject = JSONObject()
//                    jsonObject.put("type", "2")
//                    jsonObject.put("projectId", id)
//                    jsonObject.put("id", id)
//                    /** 发送消息 */
//                    messageHandler!!.sendMessage(jsonObject.toString())
//                    successList.add(id)
//                } else {
//                    /** 删除失败 */
//                    failureList.add(id)
//                }
//            }
//            return SDeleteResponse(successList, failureList)
//        } catch (e: Exception) {
//            e.printStackTrace()
//            return SDeleteResponse(SResponseType.failure, e.message!!)
//        }
//    } // Function delete()

} // Object ProjectService