调用接口匹配数据并生成txt文件

package com.pistonint.bpm.module.cars.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pistonint.bpm.module.cars.dao.CarsMapper;
import com.pistonint.bpm.module.cars.entity.Cars;
import com.pistonint.bpm.module.cars.entity.vo.TaskInfoResp;
import com.pistonint.bpm.module.cars.service.CarsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

import static org.springframework.context.annotation.ScopedProxyMode.TARGET_CLASS;

/**
 * @description: CarsServiceImpl
 * @author: crs
 * @create: 2020-10-15 19:37
 * Copyright (c) 2019 广东数鼎科技有限公司 All rights reserved.
 */
@RestController
@RequestMapping("cars")
@Scope(proxyMode = TARGET_CLASS)
@Transactional
public class CarsServiceImpl extends ServiceImpl<CarsMapper, Cars> implements CarsService {
    private static Logger logger = LoggerFactory.getLogger(CarsServiceImpl.class);

    @Autowired
    private CarsMapper carsMapper;

    @GetMapping("/Info")
    public void colorFind(String keywords) {

        List<Cars> carsList = carsMapper.selectList(new QueryWrapper<Cars>());

        for (int i = 0; i < carsList.size(); i++) {
            Cars cars = new Cars();
            HttpHeaders headers = new HttpHeaders();
            headers.add("X-TOKEN", "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VySWQiOiIxIiwiYWNjb3VudCI6ImFkbWluIiwiaWF0IjoxNjAyNzU2NTc3LCJleHAiOjE2MDI3NzQ1Nzd9.f8Ns1XZ3bYlVW1IFc8U7gaowp-b2HYD2DVpy_Sg3XXw78WJ3Rrx92q0qhkzJhweBYGVWpVI2PTnD-CiWqLXBNA");
            RestTemplate restTemplate = new RestTemplate();
            String basicTrimMappingUrl = "http://47.112.179.158:6762/work/getTaskInfoBykeywords?keywords=" + carsList.get(i).getCarId();
            HttpEntity<String> requestEntity = new HttpEntity<>(null, headers);
            ResponseEntity<String> resEntity = restTemplate.exchange(basicTrimMappingUrl, HttpMethod.GET, requestEntity, String.class);
            logger.info("接口返回:" + resEntity.getBody());
            JSONObject jsonObject = JSONObject.parseObject(resEntity.getBody());
            TaskInfoResp colorResp = JSONObject.toJavaObject(jsonObject, TaskInfoResp.class);
            cars.setCarId(carsList.get(i).getCarId());
            if (colorResp.getRCode() == 1) {
                cars.setInfo(colorResp.getData().getTaskHistoryList().get(0).getTaskHistoryInfoList().get(0).getTaskState());
            }
            carsMapper.update(cars, new QueryWrapper<Cars>().eq("car_id", carsList.get(i).getCarId()));
        }
    }

    @GetMapping("/sql")
    public void sql() throws IOException {
        List<Cars> carsList = carsMapper.selectList(new QueryWrapper<Cars>().eq("info", "车源入库"));



        File file = new File("src/main/java/1.sql");
        //如果文件不存在,创建一个文件
        if (!file.exists()) {
            file.createNewFile();
        }
        FileWriter fw = null;
        BufferedWriter bw = null;
        try {
            fw = new FileWriter(file);
            String content="";
            for(int i=0 ;i<carsList.size();i++){
                content += "UPDATE `bpm`.`tb_schedule` \n" +
                    "SET `schedule_type` = 1,\n" +
                    "`user_id` = NULL,\n" +
                    "`group_id` = NULL,\n" +
                    "`group_name` = NULL,\n" +
                    "`user_name` = NULL,\n" +
                    "`remarks` = NULL,\n" +
                    "`finish_time` = NULL,\n" +
                    "`create_time` = '2020-10-10 18:51:04',\n" +
                    "`update_time` = '2020-10-10 18:51:04',\n" +
                    "`approval_status` = NULL,\n" +
                    "`is_cancel` = - 1,\n" +
                    "`is_schedule` = - 1,\n" +
                    "`batch_id` = NULL,\n" +
                    "`publish_time` = NULL,\n" +
                    "`approval_remarks` = NULL,\n" +
                    "`is_adjust` = NULL \n" +
                    "WHERE  `car_id` = '"+carsList.get(i).getCarId()+"';\n" ;
            }
            bw = new BufferedWriter(fw);
            bw.write(content);
        } catch (IOException e) {

        } finally {
            bw.close();
            fw.close();
        }


    }


}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值