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 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 httpEntity = new HttpEntity(body, requestHeaders); ResponseEntity 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=returnData.getHighlist(); List 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> set = new HashSet<>(); for (int i = 0; i < 10; i++) { Map map = new HashMap<>(); map.put("1","2"); set.add(map); } for (Map 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 signAndRegist = new ArrayList<>(); // //key: 活动名称 value:社区id // MultiValueMap map1 = new LinkedMultiValueMap<>(); // //key:活动名称 value: 活动开始时间 // MultiValueMap dateHashMap = new LinkedMultiValueMap<>(); // // List 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 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 wrapper = new QueryWrapper<>(); //// wrapper.eq("community_id",comAct.getCommunityId()); // wrapper.eq("app_id","wx118de8a734d269f0"); // wrapper.eq("name",cellValue6); // wrapper.eq("status",1); // List 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 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 dateList = dateHashMap.get(cellValue1); // assert dateList != null; // if( !dateList.contains(date3)){ // comActActivityService.save(comActActivity); // dateHashMap.add(cellValue1,date3); // } else { // QueryWrapper 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 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; } }