李林
2024-04-08 ff057092893a5c3852d66d2423cfeb5463106079
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
package com.yuanchu.mom.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.yuanchu.mom.common.GetLook;
import com.yuanchu.mom.common.PrintChina;
import com.yuanchu.mom.dto.InsOrderPlanDTO;
import com.yuanchu.mom.dto.ReportPageDto;
import com.yuanchu.mom.dto.SampleOrderDto;
import com.yuanchu.mom.exception.ErrorException;
import com.yuanchu.mom.pojo.InsReport;
import com.yuanchu.mom.service.InsReportService;
import com.yuanchu.mom.mapper.InsReportMapper;
import com.yuanchu.mom.utils.QueryWrappers;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
 
/**
* @author Administrator
* @description 针对表【ins_report(检验报告)】的数据库操作Service实现
* @createDate 2024-03-17 22:10:02
*/
@Service
public class InsReportServiceImpl extends ServiceImpl<InsReportMapper, InsReport>
    implements InsReportService{
 
    @Resource
    private GetLook getLook;
 
    @Resource
    private InsReportMapper insReportMapper;
 
    @Value("${wordUrl}")
    private String wordUrl;
 
    @Override
    public Map<String, Object> pageInsReport(Page page, ReportPageDto reportPageDto) {
        Map<String, Object> map = new HashMap<>();
        map.put("head", PrintChina.printChina(ReportPageDto.class));
        Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("pageInsReport");
        if (map1.get("look") == 1) reportPageDto.setCreateUser(map1.get("userId"));
        map.put("body", insReportMapper.pageInsReport(page, QueryWrappers.queryWrappers(reportPageDto)));
        return map;
    }
 
    @Override
    public String wordToHtml(String path) {
        try(ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
            Document document = new Document();
            document.loadFromFile(path.replace("/word", wordUrl));
            document.saveToFile(outputStream, FileFormat.Html);
            return outputStream.toString();
        } catch (Exception e) {
            throw new ErrorException("转换失败");
        }
    }
 
    @Override
    public int inReport(String url, Integer id) {
        InsReport insReport = new InsReport();
        insReport.setId(id);
        insReport.setUrlS(url);
        return insReportMapper.updateById(insReport);
    }
 
    @Override
    public int upReportUrl(Integer id) {
        return insReportMapper.update(null, Wrappers.<InsReport>lambdaUpdate().eq(InsReport::getId, id).set(InsReport::getUrlS, null));
    }
}