package com.linkwechat.wecom.domain.dto;

import cn.hutool.core.collection.CollectionUtil;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.bean.BeanUtils;
import com.linkwechat.wecom.domain.WeDepartment;
import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @description: 企业部门
 * @author: HaoN
 * @create: 2020-08-27 15:54
 **/
@Data
public class WeDepartMentDto extends WeResultDto {



    private List<DeartMentDto> department=new ArrayList<>();

    public WeDepartMentDto(){

    }


    public WeDepartMentDto(WeDepartment weDepartment){

        DeartMentDto deartMentDto=new WeDepartMentDto().new DeartMentDto();
        BeanUtils.copyPropertiesignoreOther(weDepartment,deartMentDto);
        department.add(deartMentDto);
    }

    public List<WeDepartment> findWeDepartments(){
        List<WeDepartment> weDepartments=new ArrayList<>();
        if(CollectionUtil.isNotEmpty(this.department)){
            this.department.forEach(k->{
                weDepartments.add(
                        WeDepartment.builder()
                                .deptId(k.getId())
                                .name(k.getName())
                                .parentId(k.getParentid())
                                .delFlag(0)
                                .createTime(new Date())
                                .updateTime(new Date())
                                .createBy(StringUtils.isEmpty(SecurityUtils.getUsername())?"0":SecurityUtils.getUsername())
                                .updateBy(StringUtils.isEmpty(SecurityUtils.getUsername())?"0":SecurityUtils.getUsername())
                                .build()
                );
            });

        }
        return weDepartments;
    }



    @Data
    public class DeartMentDto{

        private Long id;

        private String name;

        private Long parentid;

    }



}
