mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
package com.panzhihua.service_community.service.impl;
 
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.service_community.dao.*;
import com.panzhihua.service_community.entity.ComPbCheckUnit;
import com.panzhihua.service_community.entity.SysUser;
import com.panzhihua.service_community.model.dos.*;
import com.panzhihua.service_community.service.CodDataService;
import com.panzhihua.service_community.service.ComActActivityService;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
 
import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @title: BigScreenStatisticsServiceImpl
 * @projectName: 成都呐喊信息技术有限公司-智慧社区项目
 * @description: 国务院防疫数据服务实现类
 * @author: zzj
 * @date: 2022/4/1 9:56
 */
@Service
public class CodDataServiceImpl implements CodDataService {
    @Override
    public void getCodData() {
        //获取时间戳
        long timestamp = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"));
        String url = "http://103.66.32.242:8005/zwfwMovePortal/interface/interfaceJson";
        //以下常量值都是从网页源代码上获取到的------start
        final String STATE_COUNCIL_SIGNATURE_KEY = "fTN2pfuisxTavbTuYVSsNJHetwq5bJvCQkjjtiLM2dCratiA";
        final String STATE_COUNCIL_X_WIF_NONCE = "QkjjtiLM2dCratiA";
        final String STATE_COUNCIL_X_WIF_PAASID = "smt-application";
        //国务院疫情防控查询 appId
        final String STATE_COUNCIL_APP_ID = "NcApplication";
        //国务院疫情防控查询 PASSID
        final String STATE_COUNCIL_PASSID = "zdww";
        //国务院疫情防控查询 秘钥
        final String STATE_COUNCIL_NONCE = "123456789abcdefg";
        //国务院疫情防控查询 token
        final String STATE_COUNCIL_TOEKN = "23y0ufFl5YxIyGrI8hWRUZmKkvtSjLQA";
        //国务院疫情防控查询 key
        final String STATE_COUNCIL_KEY = "3C502C97ABDA40D0A60FBEE50FAAD1DA";
        //以下常量值都是从网页源代码上获取到的------end
        HttpHeaders requestHeaders = new HttpHeaders();
        Map<String,Object> body = new HashMap<>(10);
        //计算签名要用的字符串
        String signatureStr = String.format("%d%s%d",timestamp, STATE_COUNCIL_SIGNATURE_KEY,timestamp);
        //计算签名
        String signature = getSHA256StrJava(signatureStr).toUpperCase();
        //请求头参数封装
        requestHeaders.add( "x-wif-nonce",STATE_COUNCIL_X_WIF_NONCE);
        requestHeaders.add( "x-wif-paasid",STATE_COUNCIL_X_WIF_PAASID);
        requestHeaders.add( "x-wif-signature",signature);
        requestHeaders.add( "x-wif-timestamp",String.valueOf(timestamp));
        //body参数封装
        body.put("appId",STATE_COUNCIL_APP_ID);
        body.put("paasHeader",STATE_COUNCIL_PASSID);
        body.put("timestampHeader",timestamp);
        body.put("nonceHeader",STATE_COUNCIL_NONCE);
        //请求参数
        signatureStr = String.format("%d%s%s%d",timestamp,STATE_COUNCIL_TOEKN,STATE_COUNCIL_NONCE,timestamp);
        String signatureHeader = getSHA256StrJava(signatureStr).toUpperCase();
        body.put("signatureHeader",signatureHeader);
        body.put("key",STATE_COUNCIL_KEY);
        HttpEntity<String> httpEntity = new HttpEntity(body, requestHeaders);
        ResponseEntity<String> response = new RestTemplate().exchange(url, HttpMethod.POST,httpEntity,String.class);
        R r=JSONObject.parseObject(response.getBody(),R.class);
        ReturnData returnData=JSONObject.parseObject(JSONObject.toJSONString(r.getData()), ReturnData.class);
        List<Highlist> highlist=returnData.getHighlist();
        List<Middlelist> middlelist=returnData.getMiddlelist();
    }
    //查社区的表
    @Autowired
    private ComActDAO comActDAO;
    //单位表
    @Autowired
    private ComPbCheckUnitDao comPbCheckUnitDao;
    //用户表
    @Autowired
    private SysUserDao sysUserDao;
    //社区活动表
    @Autowired
    private ComActActivityDAO comActActivityDAO;
    @Autowired
    private ComActActivityService comActActivityService;
    //活动报名表
    @Autowired
    private ComActActSignDAO comActActSignDAO;
    //签到表
    @Autowired
    private ComActActRegistDAO comActActRegistDAO;
 
    public static void main(String[] args) {
        HashSet<Map<String,String>> set = new HashSet<>();
 
        for (int i = 0; i < 10; i++) {
            Map<String,String> map = new HashMap<>();
            map.put("1","2");
            set.add(map);
        }
        for (Map<String, String> map : set) {
            System.out.println(map);
        }
 
    }
 
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void importData(MultipartFile file) throws IOException {
//        InputStream inputStream = file.getInputStream();
//        Workbook workbook = new XSSFWorkbook(inputStream);
//        Sheet sheet = workbook.getSheetAt(0);
//
//        List<String> signAndRegist = new ArrayList<>();
//        //key: 活动名称    value:社区id
//        MultiValueMap<String, String> map1 = new LinkedMultiValueMap<>();
//        //key:活动名称    value: 活动开始时间
//        MultiValueMap<String, Date> dateHashMap = new LinkedMultiValueMap<>();
//
//        List<String> list = new ArrayList<>();
//        int totalRowNum = sheet.getLastRowNum();
//        for (int i = 1; i <= totalRowNum; i++){
//            Row row = sheet.getRow(i);
//            row.getCell(2).setCellType(CellType.STRING);
//            String cellValue1 = row.getCell(2).getStringCellValue();
//            list.add(cellValue1);
//        }
//        Map<String, Long> map = list.stream().collect(Collectors.groupingBy(s -> s, Collectors.counting()));
//        for (int i = 1; i <= totalRowNum; i++) {
//            Row row = sheet.getRow(i);
//            System.out.println("第几行:" + i);
//            //党组织名称
//            row.getCell(1).setCellType(CellType.STRING);
//            String cellValue = row.getCell(1).getStringCellValue();
//            //活动名称
//            row.getCell(2).setCellType(CellType.STRING);
//            String cellValue1 = row.getCell(2).getStringCellValue();
//            //活动内容
//            row.getCell(3).setCellType(CellType.STRING);
//            String cellValue2 = row.getCell(3).getStringCellValue();
//            //活动时长
//            row.getCell(4).setCellType(CellType.STRING);
//            String cellValue3 = row.getCell(4).getStringCellValue();
//            //活动所在社区名称
//            row.getCell(5).setCellType(CellType.STRING);
//            String cellValue4 = row.getCell(5).getStringCellValue();
//            ComActDO comAct = comActDAO.queryByName(cellValue4);
//            //参加活动党员姓名
//            row.getCell(6).setCellType(CellType.STRING);
//            String cellValue6 = row.getCell(6).getStringCellValue();
//            QueryWrapper<SysUser> wrapper = new QueryWrapper<>();
////            wrapper.eq("community_id",comAct.getCommunityId());
//            wrapper.eq("app_id","wx118de8a734d269f0");
//            wrapper.eq("name",cellValue6);
//            wrapper.eq("status",1);
//            List<SysUser> sysUsers = sysUserDao.selectList(wrapper);
//            if(CollectionUtil.isEmpty(sysUsers)){
//                continue;
//            }
//            Long userId = sysUsers.get(0).getUserId();
//            //单位
//            row.getCell(7).setCellType(CellType.STRING);
//            String cellValue7 = row.getCell(7).getStringCellValue();
//
//            //管理员
//            row.getCell(8).setCellType(CellType.STRING);
//            String cellValue8 = row.getCell(8).getStringCellValue();
//
//            QueryWrapper<ComPbCheckUnit> queryWrapper = new QueryWrapper<>();
//            queryWrapper.eq("name",cellValue7);
//            queryWrapper.eq("belong_to","仁和区");
//            ComPbCheckUnit comPbCheckUnit = comPbCheckUnitDao.selectOne(queryWrapper);
//
//            //活动发布时间
//            Date date = row.getCell(10).getDateCellValue();
//            //活动开始报名时间
//            Date date1 = row.getCell(11).getDateCellValue();
//            //活动结束报名时间
//            Date date2 = row.getCell(12).getDateCellValue();
//            //活动开始时间
//            Date date3 = row.getCell(13).getDateCellValue();
//            //活动结束时间
//            Date date4 = row.getCell(14).getDateCellValue();
//
//            ComActActivityDO comActActivity = new ComActActivityDO();
//            comActActivity.setActivityName(cellValue1);
//            comActActivity.setActivityAddr(comAct.getAddress());
//            comActActivity.setLng(comAct.getLng());
//            comActActivity.setLat(comAct.getLat());
//           // comActActivity.setStatus();
//            comActActivity.setPublishAt(date);
//            comActActivity.setSignUpBegin(date1);
//            comActActivity.setSignUpEnd(date2);
//            comActActivity.setBeginAt(date3);
//            comActActivity.setEndAt(date4);
//            comActActivity.setAattendPeople("居民,志愿者,党员");
//            comActActivity.setParticipantMax(-1);
//            comActActivity.setActivityType("志愿服务");
//            comActActivity.setHasPrize(0);
//            comActActivity.setIsQrCode(1);
//            comActActivity.setContactName(cellValue8);
//            comActActivity.setContent(cellValue2);
//            comActActivity.setCommunityId(comAct.getCommunityId());
//            comActActivity.setCreateAt(new Date());
//            int sum = map.get(cellValue1).intValue();
//            comActActivity.setParticipantRewardWay(2);
//            comActActivity.setVolunteerRewardWay(2);
//            comActActivity.setPbRewardWay(2);
//            comActActivity.setDuration(sum * Integer.parseInt(cellValue3));
//            comActActivity.setType(3);
//            comActActivity.setPartyMemberMax(-1);
//            comActActivity.setSignOutRange(1000);
//
//
//            if( i == 1){
//                comActActivityService.save(comActActivity);
//                dateHashMap.add(cellValue1,date3);
//            } else {
//                if(dateHashMap.containsKey(cellValue1)){
//                    List<Date> dateList = dateHashMap.get(cellValue1);
//                    assert dateList != null;
//                    if( !dateList.contains(date3)){
//                        comActActivityService.save(comActActivity);
//                        dateHashMap.add(cellValue1,date3);
//                    } else {
//                        QueryWrapper<ComActActivityDO> wrapper1 = new QueryWrapper<>();
//                        wrapper1.eq("activity_name",cellValue1);
//                        wrapper1.eq("begin_at",date3);
//                        System.out.println(cellValue1);
//                        System.out.println(comAct.getCommunityId());
//                        System.out.println(cellValue6);
//                        List<ComActActivityDO> doList = comActActivityDAO.selectList(wrapper1);
//                        comActActivity.setId(doList.get(doList.size() - 1).getId());
//                    }
//                } else {
//                    comActActivityService.save(comActActivity);
//                    dateHashMap.add(cellValue1,date3);
//                }
//            }
//
//
//            System.out.println(comActActivity.getId());
//
//            if(!signAndRegist.contains(comActActivity.getId() + "-" + userId)) {
//                ComActActSignDO comActActSign = new ComActActSignDO();
//                comActActSign.setActivityId(comActActivity.getId());
//                comActActSign.setUserId(userId);
//                comActActSign.setCreateAt(date1);
//                comActActSign.setSignIdentity(2);
//                comActActSign.setStatus(1);
//                comActActSign.setCheckUnitId(comPbCheckUnit.getId());
//                comActActSignDAO.insert(comActActSign);
//
//                ComActActRegistDO comActActRegist = new ComActActRegistDO();
//                comActActRegist.setActivityId(comActActivity.getId());
//                comActActRegist.setUserId(userId);
//                comActActRegist.setCreateAt(date3);
//                comActActRegist.setSignIdentity(2);
//                comActActRegist.setCheckUnitId(comPbCheckUnit.getId());
//                comActActRegist.setStartTime(date3);
//
//                Calendar calendar = Calendar.getInstance();
//                calendar.setTime(date3);
//                calendar.add(Calendar.HOUR_OF_DAY, Integer.parseInt(cellValue3));
//                Date time = calendar.getTime();
//                comActActRegist.setEndTime(time);
//                comActActRegist.setPosition(comAct.getAddress());
//                comActActRegist.setTimes(1);
//                comActActRegist.setCodeId(1768091384461426690L);
//                comActActRegist.setAward(0);
//                comActActRegist.setType(2);
//                comActActRegistDAO.insert(comActActRegist);
//            }
//            signAndRegist.add(comActActivity.getId() + "-" + userId);
//        }
    }
 
    public static String getSHA256StrJava(String str) {
        MessageDigest messageDigest;
        String encodeStr = "";
        try {
            messageDigest = MessageDigest.getInstance("SHA-256");
            messageDigest.update(str.getBytes(StandardCharsets.UTF_8));
            byte[] bytes = messageDigest.digest();
            StringBuffer stringBuffer = new StringBuffer();
            String temp = null;
            for (int i = 0; i < bytes.length; i++) {
                temp = Integer.toHexString(bytes[i] & 0xFF);
                if (temp.length() == 1) {
                    //1得到一位的进行补0操作
                    stringBuffer.append("0");
                }
                stringBuffer.append(temp);
            }
            encodeStr = stringBuffer.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return encodeStr;
    }
}