/*
 * *********************************************************************************************************************
 *
 *          !!
 *        .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.utils

import java.text.SimpleDateFormat
import java.util.*


/**
 * id生成帮助类
 *
 * @author 张维新
 */
object IdUtils {

    /**
     * 生成项目id
     *
     * @param   code    城市六位编码
     * @param   num     城市存在建筑的数量
     * @return          返回项目id
     */
    fun projectIdCreate(code: String, num: Int): String {
        try {
            if (num + 1 > 9999) {
                throw  SecurityException("建筑数量已超出最大值")
            }
            val nums = num + 1
            val genId = String.format("%1$4s", nums).replace(' ', '0')
            val sb = StringBuilder()
            val appendId = sb.append("Pj").append(code).append(genId)

            return appendId.toString()
        } catch (e: Throwable) {
            e.printStackTrace()
        }
        throw  SecurityException("id生成失败")
    } // Function ProjectId

    /**
     * 生成建筑Id
     *
     * @param   projectId   项目id
     * @return              建筑id
     */
    fun buildIdCreate(projectId: String): String {
        val bdid = projectId.replace("Pj", "Bd")
        val sb = StringBuilder()
        val uuid = UUID.randomUUID().toString()
        val uuId = uuid.replace("-", "")
        val buildId = sb.append(bdid).append(uuId)
        return buildId.toString()
    } // Function buildIdCreate

    /**
     * 生成楼层Id
     *
     * @param   projectId   项目id
     * @return              楼层id
     */
    fun floorIdCreate(projectId: String): String {
        val bdid = projectId.replace("Pj", "Fl")
        val sb = StringBuilder()
        val uuid = UUID.randomUUID().toString()
        val uuId = uuid.replace("-", "")
        val floorId = sb.append(bdid).append(uuId)
        return floorId.toString()
    } // Function floorIdCreate

    /**
     * 生成空间Id
     *
     * @param   projectId   项目id
     * @return              空间id
     */
    fun spaceIdCreate(projectId: String): String {
        val bdid = projectId.replace("Pj", "Sp")
        val sb = StringBuilder()
        val uuid = UUID.randomUUID().toString()
        val uuId = uuid.replace("-", "")
        val spaceId = sb.append(bdid).append(uuId)
        return spaceId.toString()
    } // Function spaceIdCreate

    /**
     * 生成元空间Id
     *
     * @param   projectId   项目id
     * @return              元空间id
     */
    fun iSpaceIdCreate(projectId: String): String {
        val bdid = projectId.replace("Pj", "Si")
        val sb = StringBuilder()
        val uuid = UUID.randomUUID().toString()
        val uuId = uuid.replace("-", "")
        val siId = sb.append(bdid).append(uuId)
        return siId.toString()
    } // Function iSpaceIdCreate

    /**
     * 生成系统Id
     *
     * @param   projectId   项目id
     * @return              系统id
     */
    fun systemIdCreate(projectId: String): String {
        val bdid = projectId.replace("Pj", "Sy")
        val sb = StringBuilder()
        val uuid = UUID.randomUUID().toString()
        val uuId = uuid.replace("-", "")
        val systemId = sb.append(bdid).append(uuId)
        return systemId.toString()
    } // Function systemIdCreate

    /**
     * 生成设备Id
     *
     * @param   projectId   项目id
     * @return              设备id
     */
    fun equipmentIdCreate(projectId: String): String {
        val bdid = projectId.replace("Pj", "Eq")
        val sb = StringBuilder()
        val uuid = UUID.randomUUID().toString()
        val uuId = uuid.replace("-", "")
        val eqId = sb.append(bdid).append(uuId)
        return eqId.toString()
    } // Function equipmentIdCreate

    /**
     * 生成设备部件Id
     *
     * @param   projectId   项目id
     * @return              设备部件id
     */
    fun equipmentComponentIdCreate(projectId: String): String {
        val bdid = projectId.replace("Pj", "Ec")
        val sb = StringBuilder()
        val uuid = UUID.randomUUID().toString()
        val uuId = uuid.replace("-", "")
        val ecId = sb.append(bdid).append(uuId)
        return ecId.toString()
    } // Function equipmentComponentIdCreate

    /**
     * 生成设施Id
     *
     * @param   projectId   项目id
     * @return              设施id
     */
    fun structureIdCreate(projectId: String): String {
        val bdid = projectId.replace("Pj", "St")
        val sb = StringBuilder()
        val uuid = UUID.randomUUID().toString()
        val uuId = uuid.replace("-", "")
        val stId = sb.append(bdid).append(uuId)
        return stId.toString()
    } // Function structureIdCreate

    /**
     * 生成设施部件Id
     *
     * @param   projectId   项目id
     * @return              设施部件id
     */
    fun structureComponentIdCreate(projectId: String): String {
        val bdid = projectId.replace("Pj", "Sc")
        val sb = StringBuilder()
        val uuid = UUID.randomUUID().toString()
        val uuId = uuid.replace("-", "")
        val scId = sb.append(bdid).append(uuId)
        return scId.toString()
    } // Function structureComponentIdCreate

    /**
     * 生成资产编码Id
     *
     * @param   projectId   项目id
     * @return              设备资产编码id
     */
    fun peIdCreate(projectId: String): String {
        val bdid = "Pe"
        val sb = StringBuilder()
        val uuid = UUID.randomUUID().toString()
        val uuId = uuid.replace("-", "")
        val peId = sb.append(bdid).append(uuId)
        return peId.toString()
    } // Function peIdCreate

    /**
     * 生成竖井Id
     *
     * @param   projectId   项目id
     * @return              竖井id
     */
    fun shaftIdCreate(projectId: String): String {
        val bdid = projectId.replace("Pj", "Sh")
        val sb = StringBuilder()
        val uuid = UUID.randomUUID().toString()
        val uuId = uuid.replace("-", "")
        val shId = sb.append(bdid).append(uuId)
        return shId.toString()
    } // Function shaftIdCreate

    /**
     * 生成租户Id
     *
     * @param   projectId   项目id
     * @return              租户id
     */
    fun tenantIdCreate(projectId: String): String {
        val bdid = projectId.replace("Pj", "VOTn")
        val sb = StringBuilder()
        val uuid = UUID.randomUUID().toString()
        val uuId = uuid.replace("-", "")
        val shId = sb.append(bdid).append(uuId)
        return shId.toString()
    } // Function shaftIdCreate

    /**
     * 生成uuid
     *
     * @return              uuid
     */
    fun uuidCreate(): String {
        val uuid = UUID.randomUUID().toString()
        return uuid.replace("-", "")
    } // Function uuidCreate


    fun time():String {
        val df = SimpleDateFormat("yyyy-MM-dd HH:mm:ss") //设置日期格式
        println(df.format(Date())) // new Date()为获取当前系统时间
        return df.format(Date())
    }


} // Object IdUtils