ws183
2025-04-28 b306d1106b915bb13fd7a02217ae9c65de2fd03d
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package com.ld.igds.m;
 
import com.bstek.bdf2.core.model.DefaultDept;
import com.ld.igds.check.dto.CheckItemData;
import com.ld.igds.common.CoreCommonService;
import com.ld.igds.constant.FoodLevel;
import com.ld.igds.constant.FoodType;
import com.ld.igds.constant.FoodVariety;
import com.ld.igds.models.Building;
import com.ld.igds.models.Depot;
import com.ld.igds.models.DepotStore;
import com.ld.igds.models.MQuality;
import com.ld.igds.sys.service.SysDeptService;
import com.ld.igds.view.service.BuildingService;
import com.ld.igds.view.service.HDepotStoreService;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
 
/**
 * 打印各种报告单据管理类
 */
@Component
public class ReportManage {
 
    @Autowired
    private CoreCommonService commonService;
    @Autowired
    private SysDeptService sysDeptService;
    @Autowired
    private BuildingService buildingService;
    @Resource
    private HDepotStoreService depotStoreService;
 
    /**
     * 整车质检报告单据
     *
     * @param data
     * @return
     */
    public String printQualityBill(MQuality data) {
 
        //获取默认模版
        String htmlStr = "模板暂未确定!!";
 
        if (data.getFoodVariety().startsWith("111")) {
            //调用小麦质检报告模版
            htmlStr = ReportBill.QUALITY_111;
        }
        if (data.getFoodVariety().startsWith("112")) {
            //调用玉米质检报告模版
            htmlStr = ReportBill.QUALITY_112;
        }
        if (data.getFoodVariety().startsWith("113")) {
            //调用稻谷质检报告模版
            htmlStr = ReportBill.QUALITY_113;
        }
        if (data.getFoodVariety().startsWith("141")) {
            //调用大豆质检报告模版
            htmlStr = ReportBill.QUALITY_141;
        }
        if (data.getFoodVariety().startsWith("236")) {
            //调用稻谷质检报告模版
            htmlStr = ReportBill.QUALITY_113;
        }
        if (data.getFoodVariety().startsWith("212")) {
            //调用油脂质检报告模版
            htmlStr = ReportBill.QUALITY_212;
        }
 
        //获取单位名称
        DefaultDept dept = sysDeptService.getDeptById(data.getCompanyId());
        if (null != dept && StringUtils.isNotEmpty(dept.getName())) {
            htmlStr = htmlStr.replace("dwmc", dept.getName());
        } else {
            htmlStr = htmlStr.replace("dwmc", "-");
        }
 
        //获取库区名称
        dept = sysDeptService.getDeptById(data.getDeptId());
        if (null != dept && StringUtils.isNotEmpty(dept.getName())) {
            htmlStr = htmlStr.replace("deptName", dept.getName());
        } else {
            htmlStr = htmlStr.replace("deptName", "-");
        }
 
        //获取仓库信息
        Depot depot = commonService.getCacheDepot(data.getCompanyId(), data.getDepotId());
        String buildingName = "-";
        if (depot != null) {
            htmlStr = htmlStr.replace("depotName", depot.getName() == null ? "-" : depot.getName());
            htmlStr = htmlStr.replace("foodLocation", StringUtils.isEmpty(depot.getFoodLocation()) ? "-" : depot.getFoodLocation());
            htmlStr = htmlStr.replace("storeKeeperName", StringUtils.isEmpty(depot.getStoreKeeperName()) ? "-" : depot.getStoreKeeperName());
 
            //获取仓房信息
            if (StringUtils.isNotEmpty(depot.getBuildingId())) {
                Building building = buildingService.getCacheBuilding(depot.getCompanyId(), depot.getDeptId(), depot.getBuildingId());
                if (null != building) {
                    buildingName = building.getName();
                }
            }
        } else {
            htmlStr = htmlStr.replace("depotName", "-");
            htmlStr = htmlStr.replace("foodLocation", "-");
            htmlStr = htmlStr.replace("storeKeeperName", "-");
        }
        htmlStr = htmlStr.replace("buildingName", buildingName);
 
        htmlStr = htmlStr.replace("foodVariety", FoodVariety.getMsg(data.getFoodVariety()));
        htmlStr = htmlStr.replace("serId", data.getId());
 
        //获取质检时间之前的库存信息
        DepotStore lastDepotStore = depotStoreService.getLastData(data.getDepotId(), data.getTime());
        String storageReal = "-";
        String foodYear = "-";
        String foodType = "-";
        if(null != lastDepotStore){
            if(StringUtils.isNotEmpty(lastDepotStore.getFoodYear())){
                foodYear = lastDepotStore.getFoodYear();
            }
            if(null != lastDepotStore.getStorageReal()){
                storageReal = lastDepotStore.getStorageReal()/1000 + "";
            }
            if(StringUtils.isNotEmpty(lastDepotStore.getFoodType())){
                foodType = FoodType.getMsg(lastDepotStore.getFoodType());
            }
        }
        htmlStr = htmlStr.replace("storageReal", storageReal);
        htmlStr = htmlStr.replace("foodYear", foodYear);
        htmlStr = htmlStr.replace("foodType", foodType);
 
        htmlStr = htmlStr.replace("foodNumber", data.getDbsl() == null? "-":data.getDbsl()/1000 + "");
        htmlStr = htmlStr.replace("foodLevel", StringUtils.isEmpty(data.getFoodLevel()) ? "-" : FoodLevel.getMsg(data.getFoodLevel()));
 
        htmlStr = htmlStr.replace("checkNum", data.getYpsl() == null? "-":data.getYpsl() + "");
 
        htmlStr = htmlStr.replace("unit", StringUtils.isEmpty(data.getUnit()) ? "-" : data.getUnit());
        htmlStr = htmlStr.replace("sampleUser", StringUtils.isEmpty(data.getCheckUser()) ? "-" : data.getCheckUser());
        htmlStr = htmlStr.replace("checkUser", StringUtils.isEmpty(data.getUser()) ? "-" : data.getUser());
        htmlStr = htmlStr.replace("sampleTime", data.getCheckTime() == null ? "-" : DateFormatUtils.format(data.getCheckTime(), "yyyy/MM/dd HH:mm:ss"));
        htmlStr = htmlStr.replace("checkTime", data.getTime() == null ? "-" : DateFormatUtils.format(data.getTime(), "yyyy/MM/dd HH:mm:ss"));
        htmlStr = htmlStr.replace("bgcjsj", data.getBgcjsj() == null ? "-" : DateFormatUtils.format(data.getBgcjsj(), "yyyy/MM/dd HH:mm:ss"));
        htmlStr = htmlStr.replace("remark", StringUtils.isEmpty(data.getRemark()) ? "-" : data.getRemark());
 
        Map<String, String> checkBillItems = getCheckBillItems();
        // 遍历化验结果,存入map集合中
        String key;
        for (CheckItemData item : data.getCheckItems()) {
            key = item.getStandardId() + "_VAL";
            checkBillItems.put(key, item.getValue());
        }
 
        // 遍历map集合,替换化验单中化验值
        String value;
        for (String str : checkBillItems.keySet()) {
            value = checkBillItems.get(str);
            if (StringUtils.isNotEmpty(value)) {
                htmlStr = htmlStr.replace(str, value);
            } else {
                htmlStr = htmlStr.replace(str, "-");
            }
        }
 
        return htmlStr;
    }
 
 
    /**
     * 封装化验项数值,key-化验项编码,value-放置化验值
     *
     * @return
     */
    private Map<String, String> getCheckBillItems() {
        Map<String, String> map = new HashMap<>();
        map.put("C01_VAL", "");
        map.put("C02_VAL", "");
        map.put("C03_VAL", "");
        map.put("C04_VAL", "");
        map.put("C05_VAL", "");
        map.put("C06_VAL", "");
        map.put("C07_VAL", "");
        map.put("C08_VAL", "");
        map.put("C09_VAL", "");
        map.put("C10_VAL", "");
        map.put("C11_VAL", "");
        map.put("C12_VAL", "");
        map.put("C13_VAL", "");
        map.put("C14_VAL", "");
        map.put("C15_VAL", "");
        map.put("C16_VAL", "");
        map.put("C17_VAL", "");
        map.put("C18_VAL", "");
        map.put("C19_VAL", "");
        map.put("C20_VAL", "");
        map.put("C21_VAL", "");
        map.put("C22_VAL", "");
        map.put("C23_VAL", "");
        map.put("C24_VAL", "");
        map.put("C25_VAL", "");
        map.put("C26_VAL", "");
        map.put("C27_VAL", "");
        map.put("C28_VAL", "");
        map.put("C29_VAL", "");
        map.put("C30_VAL", "");
        map.put("C31_VAL", "");
        map.put("C32_VAL", "");
        map.put("C33_VAL", "");
        map.put("C34_VAL", "");
        map.put("C35_VAL", "");
        return map;
    }
}