/**
 * Copyright 2019 DH
 * All right reserved.
 * 项目名称: 运维系统
 * 创建日期:2023/10/19
 */
package org.springblade.modules.baseinfo.wateruseconsumer.wrapper;

import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;

import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.modules.baseinfo.org.service.IDeptRegionService;
import org.springblade.modules.baseinfo.wateruseconsumer.entity.WaterUseConsumerInfoEntity;
import org.springblade.modules.baseinfo.wateruseconsumer.vo.WaterUseConsumerInfoVO;
import org.springblade.modules.system.entity.Dept;
import org.springblade.modules.system.service.IDeptService;

import java.util.Objects;

/***
 * Date:2023/10/19
 * Title:文件所属模块（必须填写）
 * Description：对本文件的详细描述，原则上不能少于30字
 * @author dylan
 * @version 1.0
 * Remark：认为有必要的其他信息
 */
public class WaterUseConsumerWrapper extends BaseEntityWrapper<WaterUseConsumerInfoEntity, WaterUseConsumerInfoVO> {
    public static WaterUseConsumerWrapper build() {
        return new WaterUseConsumerWrapper();
    }

    private static IDeptService deptService;

    private static IDeptService getDeptService() {
        if (deptService == null) {
            deptService = SpringUtil.getBean(IDeptService.class);
        }
        return deptService;
    }


    @Override
    public WaterUseConsumerInfoVO entityVO(WaterUseConsumerInfoEntity entity) {
        WaterUseConsumerInfoVO vo = Objects.requireNonNull(BeanUtil.copy(entity, WaterUseConsumerInfoVO.class));
        if (vo.getOrgName()==null){
            if (vo.getOrgId()!=null){
               Dept dept= getDeptService().getById(vo.getOrgId());
               vo.setOrgName(dept.getDeptName());
            }
        }
        return vo;
    }
}
