kongdeqiang
2023-06-08 d0c8bb3267a8a666b9a7ad1ae406c88b2fceff58
src/main/java/com/boying/job/YCEticketScheduled.java
@@ -15,6 +15,7 @@
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;
@@ -44,7 +45,7 @@
    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("正在运行,强制退出-------》");
@@ -53,6 +54,7 @@
        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);
@@ -71,6 +73,32 @@
    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<>();
        map1.put("einvoicecode", orderRecord.getEinvoicecode());
@@ -88,16 +116,15 @@
            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 {