关于java:populate

70次阅读

共计 7704 个字符,预计需要花费 20 分钟才能阅读完成。

package com.pinganfu.tortoise.org.config.dto;
import com.github.pagehelper.PageInfo;
import com.pinganfu.tortoise.admin.common.model.bean.*;
import com.pinganfu.tortoise.framework.context.TenantContext;
import com.pinganfu.tortoise.framework.db.PageInfoTranslator;
import com.pinganfu.tortoise.framework.domain.QueryCriteria;
import com.pinganfu.tortoise.framework.enums.EnabledFlag;
import com.pinganfu.tortoise.org.config.domain.IndustryField;
import com.pinganfu.tortoise.org.config.domain.IndustryFieldEnum;
import com.pinganfu.tortoise.org.config.domain.IndustryFieldScene;
import com.pinganfu.tortoise.org.config.domain.IndustryFieldType;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**

  • 展现层 <-> 服务层,行业字段转换类.

** @author FUCHUNJIE414

  • @version $Id: IndustryFieldAssembler.java, v 0.1 2020 年 5 月 14 日 下午 6:31:55 FUCHUNJIE414 Exp $

*/public class IndustryFieldAssembler {

private static final String SEPARATOR = ",";

public static IndustryField populate(IndustryFieldBean ifDto, TenantContext tenant, boolean isAdd) {

    if (null == ifDto) {return null;

}

    IndustryField ifield = new IndustryField();

ifield.setId(ifDto.getId());
ifield.setOrgCode(tenant.getTenantCode());
ifield.setFieldCode(ifDto.getFieldCode());
ifield.setFieldName(ifDto.getFieldName());
ifield.setFieldType(IndustryFieldType.parser(ifDto.getFieldType()));
ifield.setEnabled(EnabledFlag.parser(ifDto.getIsEnabled()));
ifield.setFieldLength(ifDto.getFieldLength());
ifield.setMemo(ifDto.getMemo());
ifield.setLastModify(ifDto.getUpdatedBy(), isAdd);
if (IndustryFieldType.ENUM.getCode().equals(ifDto.getFieldType())) {

        ifDto.getEnums().forEach(e -> {IndustryFieldEnum enumBean = new IndustryFieldEnum();

enumBean.setOrgCode(ifield.getOrgCode());
enumBean.setFieldCode(ifield.getFieldCode());
enumBean.setEnumCode(e.getEnumCode());
enumBean.setEnumName(e.getEnumName());
enumBean.setLastModify(ifield);
ifield.addEnum(enumBean);
});
}

    // 场景 

if (!CollectionUtils.isEmpty(ifDto.getSceneIds())) {

        ifDto.getSceneIds().forEach(e -> {IndustryFieldScene scene = new IndustryFieldScene();

});
}

    // 场景 

if (!CollectionUtils.isEmpty(ifield.getScenes())) {

        ifield.getScenes().forEach(e -> {SceneBean sceneBean = new SceneBean();

sceneBean.setId(e.getId());
sceneBean.setSceneName(e.getSceneName());
sceneBean.setOrgCode(e.getOrgCode());
sceneBean.setIsEnabled(e.getEnabled().getCode());
});
}
// if (!CollectionUtils.isEmpty(iField.getScenes())) {
// iField.getScenes().forEach(e -> {
// SceneBean sceneBean = new SceneBean();
// sceneBean.setId(e.getId());
// sceneBean.setSceneName(e.getSceneName());
// sceneBean.setOrgCode(e.getOrgCode());
// sceneBean.setIsEnabled(e.getEnabled().getCode());
// dto.addScene(sceneBean);
// });
// }
return ifield;
}

public static IndustryFieldEnum populate(IndustryFieldEnumBean enumDto, TenantContext tenant, boolean isAdd) {if (null == enumDto) {return null;

}

    IndustryFieldEnum ienum = new IndustryFieldEnum();

ienum.setId(enumDto.getId());
ienum.setOrgCode(tenant.getTenantCode());
ienum.setFieldCode(enumDto.getFieldCode());
ienum.setEnumCode(enumDto.getEnumCode());
ienum.setEnumName(enumDto.getEnumName());
ienum.setLastModify(enumDto.getUpdatedBy(), isAdd);
return ienum;
}

public static IndustryFieldEnumBean populate(IndustryFieldEnum ienum) {if (null == ienum) {return null;

}

    IndustryFieldEnumBean dto = new IndustryFieldEnumBean();

dto.setId(ienum.getId());
dto.setFieldCode(ienum.getFieldCode());
dto.setEnumCode(ienum.getEnumCode());
dto.setEnumName(ienum.getEnumName());
dto.setCreatedBy(ienum.getCreatedBy());
dto.setCreateTime(ienum.getCreateTime());
dto.setUpdatedBy(ienum.getUpdatedBy());
dto.setUpdateTime(ienum.getUpdateTime());
return dto;
}

public static Page<IndustryFieldBean> populate(PageInfo<IndustryField> iFields) {if (null == iFields) {return null;

}

    Page<IndustryFieldBean> result = new Page<>();

result.setList(new ArrayList<>());
// 复制分页信息
PageInfoTranslator.copyTo(iFields, result);
result.getList().addAll(populate(iFields.getList()));
return result;
}

public static List<IndustryFieldBean> populate(List<IndustryField> iFields) {if (null == iFields) {return null;

}

    List<IndustryFieldBean> dtos = new ArrayList<>();

for (IndustryField f : iFields) {

        dtos.add(populate(f));

}

    return dtos;

}

public static List<IndustryField> populateIndustryField(List<IndustryFieldBean> industryFieldBeans, TenantContext tenant) {if (null == industryFieldBeans) {return null;

}

    List<IndustryField> fields = new ArrayList<>();

for (IndustryFieldBean industryFieldBean : industryFieldBeans) {

        fields.add(populate(industryFieldBean, tenant, true));

}

    return fields;

}

public static IndustryFieldBean populate(IndustryField iField) {if (null == iField) {return null;

}

    IndustryFieldBean dto = new IndustryFieldBean();

dto.setId(iField.getId());
dto.setFieldCode(iField.getFieldCode());
dto.setFieldName(iField.getFieldName());
dto.setFieldType(iField.getFieldType().getCode());
dto.setIsEnabled(iField.getEnabled().getCode());
dto.setFieldLength(iField.getFieldLength());
dto.setMemo(iField.getMemo());
dto.setCreatedBy(iField.getCreatedBy());
dto.setCreateTime(iField.getCreateTime());
dto.setUpdatedBy(iField.getUpdatedBy());
dto.setUpdateTime(iField.getUpdateTime());
dto.setOrgCode(iField.getOrgCode());
// 场景
if (!CollectionUtils.isEmpty(iField.getScenes())) {

        iField.getScenes().forEach(e -> {SceneBean sceneBean = new SceneBean();

sceneBean.setId(e.getId());
sceneBean.setSceneName(e.getSceneName());
sceneBean.setOrgCode(e.getOrgCode());
sceneBean.setIsEnabled(e.getEnabled().getCode());
dto.addScene(sceneBean);
});
}

    // 枚举 

if (!CollectionUtils.isEmpty(iField.getEnums())) {

        iField.getEnums().forEach(e -> {dto.addEnum(populate(e));

});
}

    return dto;

}

public static Page<IndustryFieldEnumBean> populateEnum(PageInfo<IndustryFieldEnum> ieunms) {if (null == ieunms) {return null;

}

    Page<IndustryFieldEnumBean> result = new Page<>();

result.setList(new ArrayList<>());
// 复制分页信息
PageInfoTranslator.copyTo(ieunms, result);
result.getList().addAll(populateEnum(ieunms.getList()));
return result;
}

public static List<IndustryFieldEnumBean> populateEnum(List<IndustryFieldEnum> ienums) {if (null == ienums) {return null;

}

    List<IndustryFieldEnumBean> dtos = new ArrayList<>();

for (IndustryFieldEnum e : ienums) {

        dtos.add(populate(e));

}

    return dtos;

}

public static List<IndustryFieldSceneBean> populateFieldScene(List<IndustryFieldScene> list) {if (null == list) {return null;

}

    List<IndustryFieldSceneBean> dtos = new ArrayList<>();

for (IndustryFieldScene industryFieldScene : list) {

        dtos.add(populate(industryFieldScene));

}

    return dtos;

}

public static IndustryFieldSceneBean populate(IndustryFieldScene industryFieldScene){if (null == industryFieldScene) {return null;

}

    IndustryFieldSceneBean bean = new IndustryFieldSceneBean();

bean.setId(industryFieldScene.getId());
bean.setOrgCode(industryFieldScene.getOrgCode());
bean.setFieldId(industryFieldScene.getFieldId());
bean.setSceneId(industryFieldScene.getSceneId());
return bean;
}

public static List<IndustryFieldScene> populate(IndustryFieldBean ifDto, TenantContext tenant){List<IndustryFieldScene> iFieldScenes = new ArrayList<IndustryFieldScene>();
     

return iFieldScenes;
}

public static List<IndustryFieldScene> populate(PageInfo<IndustryField> iFields,

List<String> sceneIds, String currentUser, boolean isAdd) {

    List<IndustryFieldScene> iFieldScenes = new ArrayList<IndustryFieldScene>();

if (null == iFields || null == iFields.getList() || null == sceneIds) {

        return null;

}

    List<Long> sceneList = new ArrayList<Long>();

sceneIds.forEach(id -> {

        try {sceneList.add(Long.parseLong(id));

} catch (Exception e) {

            // 疏忽非法 ID.

}

    });

iFields.getList().forEach(

            field -> {
                sceneList.forEach(sceneId -> {if (isAdd && !field.checkExist(sceneId)) {iFieldScenes.add(new IndustryFieldScene(field.getOrgCode(), field

.getId(), sceneId));
}

                    if (!isAdd && field.checkExist(sceneId)) {iFieldScenes.add(new IndustryFieldScene(field.getOrgCode(), field

.getId(), sceneId));
}

                });

});
iFieldScenes.forEach(scene -> {

        scene.setLastModify(currentUser, true);

});
return iFieldScenes;
}

public static QueryCriteria populateFieldCodes(List<String> fieldCodes) {QueryCriteria criteria = new QueryCriteria(false);

criteria.add(“fieldCodes”, fieldCodes);
return criteria;
}
}

正文完
 0