java中vo视图用法

1.实体类

/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.desk.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.flow.core.entity.FlowEntity;
import org.springframework.data.annotation.Transient;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 企业邮箱申请实体类
 *
 * @author Chill
 */
@Data
@TableName("blade_process_apply_email")
@EqualsAndHashCode(callSuper = true)
public class ApplyEmail extends FlowEntity {

	private static final long serialVersionUID = 1L;
	/**
	 * tenantId
	 */
	private String tenantId;
	/**
	 * 流程定义id
	 */
	private String processDefinitionId;
	/**
	 * 流程实例id
	 */
	private String processInstanceId;
	/**
	 * 流程申请时间
	 */
	private Date applyTime;
	/**
	 * 单据编号
	 */
	private String orderCode;
	/**
	 * 申请人
	 */
	@JsonSerialize(
		using = ToStringSerializer.class
	)
	private Long applyUser;
	private String applyUserName;
	/**
	 * 申请部门
	 */
	@JsonSerialize(
		using = ToStringSerializer.class
	)
	private Long applyDept;
	private String applyDeptName;
	/**
	 * 邮箱名称
	 */
	private String emailName;
	/**
	 * 联系电话
	 */
	private String contactPhone;
	/**
	 * 需求日期
	 */
	private Date demandDate;
	/**
	 * 说明
	 */
	private String declaration;
	/**
	 * 抄送人员
	 */
	private String ccUser ;
	/**
	 * 抄送人员名称
	 */
	private String ccUserName;
	/**
	 * 上传附件信息
	 */
	@Transient
	@TableField(exist = false)
	private List<OaAttachment> attachments;
}

  2.vo视图

package org.springblade.desk.vo;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.desk.entity.ApplyEmail;

/**
 * 视图类
 *
 * @author Sxx
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class ApplyEmailVO extends ApplyEmail {

	private String createUserName;

	private String createDeptName;
}

  3.包装器

/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.desk.wrapper;

import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.desk.entity.ApplyEmail;
import org.springblade.desk.vo.ApplyEmailVO;
import org.springblade.system.cache.SysCache;
import org.springblade.system.user.cache.UserCache;
import org.springblade.system.user.entity.User;

import java.util.Objects;

/**
 * entity包装类,返回视图层所需的字段
 *
 * @author Chill
 */
public class ApplyEmailWrapper extends BaseEntityWrapper<ApplyEmail, ApplyEmailVO> {

	public static ApplyEmailWrapper build() {
		return new ApplyEmailWrapper();
	}

	@Override
	public ApplyEmailVO entityVO(ApplyEmail entity) {
		ApplyEmailVO entityVO = Objects.requireNonNull(BeanUtil.copy(entity, ApplyEmailVO.class));
		if(!Func.isEmpty(entity.getCreateUser())){
			User user = UserCache.getUser(entity.getCreateUser());
			if(user!=null){
				entityVO.setCreateUserName(user.getName());
			}
		}
		if(!Func.isEmpty(entity.getCreateDept())){
			entityVO.setCreateDeptName(SysCache.getDeptName(entity.getCreateDept()));
		}
		return entityVO;
	}

}

  

posted @ 2021-04-23 10:25  红尘沙漏  阅读(661)  评论(0编辑  收藏  举报