吉安感知网项目-后端
linwei
2026-06-05 8f625455f90dc28300270e021cc5d8e074f8308a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 *      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.sxkj.gd.workorder.wrapper;
 
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
import org.sxkj.gd.workorder.dto.GdTaskResultDTO;
import org.sxkj.gd.workorder.entity.GdTaskResultEntity;
import org.sxkj.gd.workorder.vo.GdTaskResultVO;
 
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
 
/**
 * 成果表 包装类,返回视图层所需的字段
 *
 * @author lw
 * @since 2026-01-14
 */
public class GdTaskResultWrapper extends BaseEntityWrapper<GdTaskResultEntity, GdTaskResultVO>  {
 
    public static GdTaskResultWrapper build() {
        return new GdTaskResultWrapper();
     }
 
    @Override
    public GdTaskResultVO entityVO(GdTaskResultEntity gdTaskResult) {
        return Objects.requireNonNull(BeanUtil.copy(gdTaskResult, GdTaskResultVO.class));
    }
 
    /**
     * 将DTO列表转换为Entity列表
     *
     * @param gdTaskResultDTOList DTO列表
     * @return Entity列表
     */
    public List<GdTaskResultEntity> listEntity(List<GdTaskResultDTO> gdTaskResultDTOList) {
        return gdTaskResultDTOList.stream()
                .map(this::convertDtoToEntity)
                .collect(Collectors.toList());
    }
 
    /**
     * 将单个DTO转换为Entity
     *
     * @param dto DTO对象
     * @return Entity对象
     */
    private GdTaskResultEntity convertDtoToEntity(GdTaskResultDTO dto) {
        GdTaskResultEntity entity = BeanUtil.copy(dto, GdTaskResultEntity.class);
 
        if (dto.getAttachmentType() != null) {
            entity.setAttachmentType(dto.getAttachmentType());
        } else if (dto.getDateType() != null) {
            entity.setAttachmentType(dto.getDateType());
        }
 
        return entity;
    }
 
    /**
     * 将文件类型字符串转换为附件类型编码
     *
     * @param fileType 文件类型字符串(图片/视频/照片)
     * @return 附件类型编码:0-图片,1-视频,2-其他
     */
    private Integer convertFileTypeToAttachmentType(String fileType) {
        if (fileType == null) {
            return 2;
        }
        switch (fileType.trim()) {
            case "图片":
            case "照片":
                return 0;
            case "视频":
                return 1;
            default:
                return 2;
        }
    }
 
}