同时可以运行在JVM上的Kotlin~枚举和判定以及数据对象的写法总结

枚举

package io.github.deadzq.eenum

/**
 * @Author: zhangQi
 * @Date: 2020-09-24 11:34
 * 通讯录回调通知 类型
 */
enum class ContactEventChangeType(val changeType:String,val changeTypeEn:String) {
    create_user("新增成员事件","create_user"),
    update_user("更新成员事件","update_user"),
    delete_user("删除成员事件","delete_user"),

    create_party("新增部门事件","create_party"),
    update_party("更新部门事件","update_party"),
    delete_party("删除部门事件","delete_party"),

    update_tag("标签成员变更事件","update_tag")
}

判定

package io.github.deadzq.util

import io.github.deadzq.eenum.*
import org.springframework.stereotype.Component

/**
 * @Author: zhangQi
 * @Date: 2020-09-06 14:56
 * 状态判定
 */
@Component
class StatusUtil {

    /**
     * 群状态判定 id->描述
     */
    fun groupStatuId(groupStatuId:Int):String?{
        return when(groupStatuId){
            0 -> GroupStatus.zero.status
            1 -> GroupStatus.one.status
            2 -> GroupStatus.two.status
            3 -> GroupStatus.thr.status
            else -> null
        }
    }


    /**
     * 加群方式判定 id->描述
     */
    fun joinSceneId(joinSceneId:Int):String?{
        return when (joinSceneId) {
            1 ->  JoinScene.one.scene
            2 ->  JoinScene.two.scene
            3 ->  JoinScene.thr.scene
            else -> null
        }
    }

    /**
     * 成员类型判定 id->描述
     */
    fun memberTypeId(memberTypeId:Int):String?{
        return when (memberTypeId){
            1 -> MemberType.one.type
            2 -> MemberType.two.type
            else -> null
        }
    }

    /**
     * 消息群发类型中文含义
     */
    fun imTypeId(typeId:Int):String?{
        return when (typeId){
            1 -> ImType.text.type
            2 -> ImType.image.type
            3 -> ImType.link.type
            4 -> ImType.miniprogram.type
            else -> null
        }
    }

    /**
     * 客户流失未流失
     */
    fun lostCustId(lostCustId:Int):String?{
        return when(lostCustId){
            1 -> LostCustStatus.lost.status
            2 -> LostCustStatus.nolost.status
            else -> null
        }
    }

    /**
     * 客户流失原因
     */
    fun lostCustReason(changeType:String):String?{
        return when(changeType){
            "transfer_fail" -> LostCustReason.transfer_fail.reason
            "del_follow_user" -> LostCustReason.del_follow_user.reason
            "del_external_contact" -> LostCustReason.del_external_contact.reason
            else -> null
        }
    }

    /**
     * 消息群发类型标识
     */
    fun imTypeIdSignature(typeId:Int):String?{
        return when (typeId){
            1 -> ImType.text.signature
            2 -> ImType.image.signature
            3 -> ImType.link.signature
            4 -> ImType.miniprogram.signature
            else -> null
        }
    }

    /**
     * 群发消息接收类型
     */
    fun imRecvTypeId(recvTypeId:Int):String?{
        return when (recvTypeId){
            1 -> ImRecvType.single.type
            2 -> ImRecvType.group.type
            else -> null
        }
    }


    /**
     * 群发消息接收类型标识 single,group
     */
    fun imRecvTypeIdentification(recvTypeId:Int):String?{
        return when (recvTypeId){
            1 -> ImRecvType.single.identification
            2 -> ImRecvType.group.identification
            else -> null
        }
    }

    /**
     * 获取标签type的类型string
     */
    fun tagTypeId(tagTypeId:Int):String?{
        return when(tagTypeId){
            1 -> TagType.inside.type
            2 -> TagType.outside.type
            else -> null
        }
    }

}

数据对象(用于比如说json转换实体类.class,并调用相关方法完成转换,kotlin数据对象的好处在于可以自动完成字段的空值控制-在类型后加?号)

package io.github.deadzq.model

import com.fasterxml.jackson.annotation.JsonProperty
import io.vertx.core.json.JsonArray
import io.vertx.core.json.JsonObject

/**
 * @Author: zhangQi
 * @Date: 2020-11-17 13:40
 * followers数据对象
 */
data class FollowUserModel(
        var userid: String?,
        var remark: String?,
        var description: String?,
        var createtime: Long?,
        var tags: Any?,
        @JsonProperty("remark_corp_name")
        var remarkCorpName: String?,
        @JsonProperty("remark_mobiles")
        var remarkMobiles: Any?,
        @JsonProperty("oper_userid")
        var operUserid: String?,
        @JsonProperty("add_way")
        var addWay: Int?,
        var state: String?
) {

    fun listTags(): List<Tags>? {
        try {
            return (tags as JsonArray)
                    .mapNotNull { it as JsonObject }
                    .map {
                        it.mapTo(Tags::class.java)
                    }
        } catch (e: Exception) {
        }
        return null;
    }

    fun convertRemarkMobiles(): JsonArray? {
        try {
            return remarkMobiles as JsonArray
        } catch (e: Exception) {
        }
        return null;
    }

    data class Tags (
        var group_name:String?,
        var tag_name:String?,
        var tag_id:String?,
        var type:Int?
    )

}
posted @ 2020-11-18 10:43  ukyo--君君小时候  阅读(149)  评论(0编辑  收藏  举报