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

import com.persagy.database.SFilter
import com.persagy.database.functions.SLength
import com.persagy.server.datacenter.models.entities.dict.DictBatchProcessing
import com.persagy.server.datacenter.models.entities.dict.DictSQueryRequest
import com.persagy.server.datacenter.models.entities.dict.EquipFamily
import com.persagy.server.datacenter.models.entities.dictnew.DefClass
import com.persagy.server.datacenter.models.entities.dictnew.DefFuncId
import com.persagy.server.datacenter.models.entities.dictnew.DefFuncIdProject
import com.persagy.server.datacenter.models.requests.CategoryRequest
import com.persagy.server.services.dict.EquipFamilyService
import com.persagy.server.services.dict.dictnew.DictDefClassService
import com.persagy.service.models.requests.SCreateRequest
import com.persagy.service.models.requests.SQueryRequest
import com.persagy.service.models.responses.SBaseResponse
import com.persagy.service.models.responses.SCreateResponse
import com.persagy.service.models.responses.SQueryResponse
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

/**
 * 字典
 *
 * @author wx  <zhangweixin@sagacloud.cn>
 * @date  2020/9/23 15:30
 */
@Tag(name = "040、字典")
@RestController
@RequestMapping("/dict")
class DictControllers {

    /**
     * 字典查询所有设备类型、部件所有类型、系统类型、专业类型
     *
     * @param  categoryRequest        查询信息条件
     * @return 查询结果
     */
    @Operation(summary = "类型-字典查询所有设备类型、部件所有类型、系统类型、专业类型", description = "输入设备类型：equipment，输入部件类型：component,输入系统类型：system,输入专业类型：major," +
            "专业和系统：majorSystem，业务空间类型 space ,专业下的设备类型 majorEquipment ,设备和部件equipmentAndComponent,设备类型要以及对应的部件equipmentComponent，专业下的系统，系统下的设备majorSystemEquip ,资产 property ")
    @PostMapping(value = ["/category"])
    fun categoryQuery(@RequestBody categoryRequest: CategoryRequest): SQueryResponse<DefClass> {
        return DictDefClassService.equipQuery(categoryRequest)
    } // Fun categoryQuery()

    /**
     * 项目字典
     *
     * @param request   查询条件
     * @return 查询结构
     */
    @Operation(summary ="查询项目下类型的信息点",description = "")
    @PostMapping(value = ["/query"])
    fun categoryInfoQuery(@RequestBody request: DictSQueryRequest): SQueryResponse<DefFuncId>{
        return DictDefClassService.categoryInfoQuery(request)
    } // Fun query()

    /**
     * 项目定制化设置
     *
     * @param request   信息点对象列表
     * @return 返回结果
     */
    @Operation(summary = "设置-项目定制化字典", description = "")
    @PostMapping(value = ["/setting-dic-project"])
    fun settingDict(@RequestBody request: SCreateRequest<DefFuncIdProject>): SCreateResponse<DefFuncIdProject> {
        return DictDefClassService.settingDict(request)
    } // Fun settingDict()

    /**
     * 重置-根据类型项目id 具体对象类型重置
     *
     * @param categoryRequest 类型
     * @return 返回结果
     */
    @Operation(summary = "重置-根据类型项目id 具体对象类型重置", description = "重置项目下具体的类别")
    @PostMapping(value = ["/reset-type"])
    fun resetType(@RequestBody categoryRequest: CategoryRequest): SBaseResponse {
        return DictDefClassService.resetType(categoryRequest)
    } // Fun resetType()

    /**
     * 重置-根据项目id
     */
    @Operation(summary = "重置-根据项目id", description = "重置项目下所有得定制信息点")
    @PostMapping(value = ["/reset-dic"])
    fun resetProjectId(): SBaseResponse{
        return DictDefClassService.resetProjectId()
    } // Fun reset()

    /**
     * 批量处理字典信息操作
     *
     * @param request   条件
     * @return 返回结果
     */
    @Operation(summary = "批量处理字典信息操作", description = "方案id ：全新设定（schemeZero）、方案1（schemeOne）、方案2（schemeTwo），" +
            "注意SchemeId为必填字段 ，优先级在列表中[R,S,M] ,一级标签[技术参数，基本参数] 列表为String类型")
    @PostMapping(value = ["/dict-batch"])
    fun createList(@RequestBody request: DictBatchProcessing): SCreateResponse<DictBatchProcessing>{
        return DictDefClassService.setSchemeProject(request)
    }

    /**
     * 设备族查询
     */
    @Operation(summary = "字典-查询设备对应的设备族", description = "")
    @PostMapping(value = ["/family/query"])
    fun familyQuery(@RequestBody request: SQueryRequest, type:String?): SQueryResponse<EquipFamily>{
        if (!type.isNullOrEmpty()){
            return EquipFamilyService.pageQuery(request, arrayListOf(SFilter.eq(SLength("EquipCode"), 6)))
        }
        return EquipFamilyService.pageQuery(request)
    }


}