| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | |
| | | private SystemConfigProperties systemConfigProperties; |
| | | private Boolean taskFlag = false; |
| | | |
| | | //@Scheduled(cron = "0 0/1 * * * ?") |
| | | @Scheduled(cron = "0 0/1 * * * ?") |
| | | public void execute() throws Exception { |
| | | if (taskFlag == true) { |
| | | System.out.println("正在运行,强制退出-------》"); |
| | |
| | | QueryWrapper<OrderRecord> wrapper = new QueryWrapper<>(); |
| | | wrapper.lambda() |
| | | .eq(OrderRecord::getTicketStatus, 2) |
| | | .eq(OrderRecord::getType,1) |
| | | .isNotNull(OrderRecord::getEinvoicecode) |
| | | .orderByDesc(OrderRecord::getCreateTime); |
| | | List<OrderRecord> list = orderRecordService.list(wrapper); |
| | |
| | | } |
| | | //开取发票 |
| | | for (OrderRecord orderRecord : list) { |
| | | System.out.println("正在申请开票文件:" + orderRecord); |
| | | // System.out.println("正在申请开票文件:" + orderRecord); |
| | | doTicket(orderRecord); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | public void doTicket(OrderRecord orderRecord){ |
| | | String urlIp = systemConfigProperties.getIp4(); |
| | | String urlRoad = systemConfigProperties.getMEINVOICESTATUS(); |
| | | Map<String,Object> map1 = new HashMap<>(); |
| | | map1.put("bizcode",orderRecord.getBizCode()); |
| | | RestTemplate restTemplate = new RestTemplate(); |
| | | ResponseEntity<ReturnData> entity = restTemplate.postForEntity(urlIp+urlRoad, HTTPEntityUtil.setEntity(map1), ReturnData.class); |
| | | SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss"); |
| | | String txt = sdf3.format(new Date())+"申请开票缴款码为:"+orderRecord.getPayCode()+",\n"; |
| | | if(entity.getBody().getCode() == 1){ |
| | | System.out.println(entity.getBody()); |
| | | //申请成功,去获取开票文件 |
| | | txt += entity.getBody()+",\n"; |
| | | Object o = entity.getBody().getData().get(0); |
| | | String s = JSON.toJSONString(o); |
| | | Map<String,Object> mapTypes = (Map)JSON.parse(s); |
| | | txt += mapTypes+",\n"; |
| | | writeTxt(txt); |
| | | doTicketGet(mapTypes,orderRecord); |
| | | }else { |
| | | // System.out.println(entity.getBody()); |
| | | txt += "查询有误,"+entity.getBody()+"\n"; |
| | | writeTxt(txt); |
| | | } |
| | | } |
| | | |
| | | public void doTicketGet(Map<String,Object> map,OrderRecord orderRecord){ |
| | | String urlIp = systemConfigProperties.getIp4(); |
| | | String urlRoad = systemConfigProperties.getGETEINVOICEBYBIZCODE(); |
| | | Map<String,Object> map1 = new HashMap<>(); |
| | |
| | | RestTemplate restTemplate = new RestTemplate(); |
| | | ResponseEntity<ReturnData> entity = restTemplate.postForEntity(urlIp+urlRoad, HTTPEntityUtil.setEntity(map1), ReturnData.class); |
| | | if(entity.getBody().getCode() == 1){ |
| | | System.out.println(entity.getBody()); |
| | | // System.out.println(entity.getBody()); |
| | | txt += entity.getBody()+",\n"; |
| | | Object o1 = entity.getBody().getData().get(0); |
| | | String s1 = JSON.toJSONString(o1); |
| | | EticketFile eticketFile = JSONObject.parseObject(s1, EticketFile.class); |
| | | System.out.println(eticketFile); |
| | | // System.out.println(eticketFile); |
| | | txt += eticketFile+"\n"; |
| | | FileInfo fileInfo = FileUtil.generateBase64StringToFile(eticketFile.getEinvoicefile(), 1,1); |
| | | if(fileInfo != null){ |
| | | System.out.println(fileInfo); |
| | | fileInfoService.saveOrUpdate(fileInfo); |
| | | orderRecord.setFileId(fileInfo.getId()); |
| | | orderRecord.setTicketStatus(1); |
| | | orderRecordService.saveOrUpdate(orderRecord); |
| | | txt += fileInfo+"\n"; |
| | | txt += fileInfo.getFileName()+"\n"; |
| | | writeTxt(txt); |
| | | } |
| | | }else { |