郑永安
2023-06-19 f65443d8abeaedc9d102324565e8368e7c9d90c8
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
package com.gk.firework.Service.ServiceImpl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gk.firework.Domain.EnterpriseFeed;
import com.gk.firework.Domain.EnterpriseResource;
import com.gk.firework.Domain.Exception.BusinessException;
import com.gk.firework.Domain.UserInfo;
import com.gk.firework.Domain.Utils.*;
import com.gk.firework.Domain.Utils.Properties;
import com.gk.firework.Domain.Vo.EnterpriseFeedVo;
import com.gk.firework.Mapper.EnterpriseFeedMapper;
import com.gk.firework.Service.EnterpriseFeedService;
import com.gk.firework.Service.EnterpriseResourceService;
import com.gk.firework.Service.ExcelExportService;
import com.gk.firework.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
 
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
 
@Service("enterpriseFeedService")
public class EnterpriseFeedServiceImpl extends ServiceImpl<EnterpriseFeedMapper, EnterpriseFeed> implements EnterpriseFeedService {
 
    @Autowired
    private EnterpriseFeedMapper enterpriseFeedMapper;
    @Autowired
    private ExcelExportService excelExportService;
    @Autowired
    private EnterpriseResourceService enterpriseResourceService;
    @Autowired
    private UserService userService;
 
 
    /**
    * @Description: 查询自检
    * @date 2021/5/13 18:44
    */
    @Override
    public IPage selectPages(Page<EnterpriseFeed> page, Long id, UserInfo user) {
        Map<String, Object> params = new HashMap<>();
        params.put("tabletype", Constants.FEED);
        params.put("id", id);
        List<EnterpriseFeed> list = enterpriseFeedMapper.selectPages(page, params);
        return page.setRecords(list);
    }
 
    /**
    * @Description: 新增自检
    * @date 2021/5/13 18:44
    */
    @Override
    @Transactional
    public void addFeed(EnterpriseFeedVo enterpriseFeedVo, UserInfo user) {
 
        if (enterpriseFeedVo.getEnterpriseid() == null) {
            throw new BusinessException("缺少企业关键数据");
        }
 
        enterpriseFeedVo.setValidflag(true);
        enterpriseFeedVo.setCreatetime(new Date());
        enterpriseFeedVo.setCreateby(user.getId());
        enterpriseFeedVo.setCreatebyname(user.getUsername());
        this.save(enterpriseFeedVo);
 
        List<EnterpriseResource> adds = null;
        MultipartFile[] files = enterpriseFeedVo.getFile();
        try {
            if (files != null && files.length > 0) {
                adds = new ArrayList<>();
                Date now = new Date();
                for (MultipartFile file : files) {
                    String name = UploadUtil.uploadFile(file, Properties.enterprisePath);
                    EnterpriseResource er = new EnterpriseResource();
                    er.setTabletype(Constants.FEED);
                    er.setFilename(file.getOriginalFilename());
                    er.setUrl(Properties.enterprise + name);
                    er.setCreatetime(now);
                    er.setCreateby(user.getId());
                    er.setCreatebyname(user.getUsername());
                    er.setBelongid(enterpriseFeedVo.getId());
                    er.setValidflag(true);
                    adds.add(er);
                }
                //执行
                enterpriseResourceService.saveBatch(adds);
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException("上传失败,请联系管理员");
        }
 
    }
 
    /**
    * @Description: 导入反馈
    * @date 2021/5/13 18:52
    */
    @Override
    public void importFeed(MultipartFile file, UserInfo user,Long enterpriseId) {
        if (file == null || file.getSize() == 0) {
            throw new BusinessException("上传文件或者请求出现问题");
        }
 
        if(!FileOptUtils.isDirExists(Properties.filePath)){
            throw new BusinessException("发生错误或不为目录");
        }
        if (enterpriseId == null) {
            throw new BusinessException("缺少企业关键数据");
        }
 
        SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMMddHHmmssSSS" );
        String fileSave = Properties.enterprisePath + user.getUsername() +"_feed_" + sdf.format(new Date()) +".xlsx";
 
        try {
            file.transferTo(new File(fileSave));
            InputStream in = new FileInputStream(fileSave);
            String name = file.getOriginalFilename();
            assert name != null;
            Boolean isExcel2007 = name.substring(name.lastIndexOf(".") + 1).endsWith("xlsx");
            excelExportService.importFeedExcel(in, user, isExcel2007,enterpriseId);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            throw new BusinessException("找不到文件");
        } catch (IOException e) {
            e.printStackTrace();
            throw new BusinessException("发生错误,请联系管理员");
        }
    }
 
 
    /**
    * @Description: 导出反馈
    * @date 2021/5/14 11:11
    */
    @Override
    public List<Map> exportFeed(Map filter, UserInfo user) {
        UserInfo userInfo = userService.getById(user.getId());
        Map<String, Object> params = new HashMap<>();
        //监管部门 根据 地区看所有
        params.put("province", userInfo.getProvince());
        params.put("city", userInfo.getCity());
        params.put("district", userInfo.getArea());
        params.put("street", userInfo.getTown());
        params.put("committee", userInfo.getCommunity());
        //企业用户
        params.put("enterprisenumber", userInfo.getCompanynumber());
 
        //过滤条件
        { //企业类型
            params.put("safetySupervision", filter.get("safetysupervision"));
            //经济类型
            params.put("economicIndustry", filter.get("economicindustry"));
            //许可证有效|过期
            params.put("valid", filter.get("valid"));
            //地区
            params.put("filterProvince", filter.get("province"));
            params.put("filterCity", filter.get("city"));
            params.put("filterDistrict", filter.get("district"));
            params.put("filterStreet", filter.get("street"));
            params.put("filterCommittee", filter.get("committee"));
            //企业名称
            params.put("enterprisename", filter.get("enterprisename"));
 
        }
        return enterpriseFeedMapper.selectExportFeed(params);
    }
 
    @Override
    public List<Map> exportFeedById(Long id) {
        if (id == null) {
            throw new BusinessException("参数传递为空");
        }
        return enterpriseFeedMapper.selectExportFeedById(id);
    }
 
}