瀏覽代碼

Merge branch 'master' of ssh://192.168.8.213:10022/miaxis/zzjs

Althars123 3 年之前
父節點
當前提交
d979eba271

+ 24 - 0
zzjs-admin/src/main/java/com/miaxis/pc/controller/car/CarController.java

@@ -0,0 +1,24 @@
+package com.miaxis.pc.controller.car;
+
+import com.miaxis.car.service.ICarBrandInfoService;
+import io.swagger.annotations.Api;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author wwl
+ * @version 1.0
+ * @date 2021/5/21 10:05
+ */
+@RestController
+@RequiredArgsConstructor
+@RequestMapping("/pc/car")
+@Api(tags={"【pc-汽车品牌】"})
+public class CarController {
+
+    private final ICarBrandInfoService carBrandInfoService;
+
+
+
+}

+ 128 - 0
zzjs-admin/src/test/java/com/miaxis/test/UpdateCarTest.java

@@ -0,0 +1,128 @@
+package com.miaxis.test;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.miaxis.ZzjsApplication;
+import com.miaxis.car.domain.CarBrandInfo;
+import com.miaxis.car.service.ICarBrandInfoService;
+import com.miaxis.common.core.domain.Response;
+import com.miaxis.common.enums.FileUploadTypeEnum;
+import com.miaxis.feign.service.ICarService;
+import com.qcloud.cos.COSClient;
+import com.qcloud.cos.model.ObjectMetadata;
+import com.qcloud.cos.model.PutObjectRequest;
+import com.qcloud.cos.model.PutObjectResult;
+import io.swagger.annotations.ApiOperation;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.web.bind.annotation.GetMapping;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author wwl
+ * @version 1.0
+ * @date 2021/5/21 11:51
+ */
+@SpringBootTest(classes = ZzjsApplication.class)
+@RunWith(SpringRunner.class)
+public class UpdateCarTest {
+
+    @Autowired
+    private ICarService carService;
+
+    @Autowired
+    private ICarBrandInfoService carBrandInfoService;
+
+    @Autowired
+    private COSClient cosClient;
+
+    private static String bucketName="t1-1305573081";
+    private static String path="https://t1-1305573081.file.myqcloud.com";
+    private static String preffix="t1";
+
+    /**
+     * 获取第三方汽车品牌接口
+     * @return
+     */
+    @Test
+    public void carBrand(){
+        String result = carService.car("brand","0,1,2,3","300");
+        JSONObject jsonString = JSONObject.parseObject(result);
+        List<Map> info = (List<Map>)jsonString.get("info");
+        ArrayList<CarBrandInfo> carBrandInfos = new ArrayList<>();
+        for (Map map : info) {
+            carBrandInfos.add(JSON.parseObject(JSON.toJSONString(map), CarBrandInfo.class));
+        }
+//        carBrandInfoService.saveBatch(carBrandInfos);
+        System.out.println(carBrandInfos);
+    }
+
+
+    @Test
+    public void test1() throws Exception {
+
+        List<CarBrandInfo> list = carBrandInfoService.list(new QueryWrapper<CarBrandInfo>().like("img", "car"));
+
+        for (CarBrandInfo carBrandInfo : list) {
+            URL httpUrl = new URL(carBrandInfo.getImg());
+            HttpURLConnection conn = (HttpURLConnection)httpUrl.openConnection();
+            conn.setRequestMethod("GET");
+            conn.setConnectTimeout(5 * 1000);
+            //通过输入流获取图片数据
+            InputStream inStream = conn.getInputStream();
+            //从输入流中获取得到图片的二进制数据
+            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+            byte[] buffer = new byte[1024];
+            int len = 0;
+            while( (len=inStream.read(buffer)) != -1 ){
+                outStream.write(buffer, 0, len);
+            }
+            byte[] btImg = outStream.toByteArray();
+            InputStream byteArrayInputStream = new ByteArrayInputStream(btImg);
+            int length = btImg.length;
+            ObjectMetadata objectMetadata = new ObjectMetadata();
+            // 从输入流上传必须制定content length, 否则http客户端可能会缓存所有数据,存在内存OOM的情况
+            objectMetadata.setContentLength(length);
+            // bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式
+            String bucketName = this.bucketName;
+
+            Calendar cal = Calendar.getInstance();
+            int year = cal.get(Calendar.YEAR);
+            int month=cal.get(Calendar.MONTH)+ 1;
+            int day=cal.get(Calendar.DATE);
+
+            //存储的文件名
+            String storagefileName = System.currentTimeMillis() + ".png";
+            // 指定要上传到 COS 上的路径
+            String key = "/"+this.preffix+"/"+FileUploadTypeEnum.CAR_BRAND.getFileType()+"/"+year+"/"+month+"/"+day+"/"+storagefileName;
+            PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, byteArrayInputStream,objectMetadata);
+            PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
+            String fileUrl=this.path + putObjectRequest.getKey();
+            inStream.close();
+            System.out.println("--------------"+fileUrl);
+            System.out.println("--------------"+key);
+
+            //更新汽车品牌logo
+            carBrandInfo.setImg(fileUrl);
+            carBrandInfo.setImgPath(key);
+            carBrandInfoService.updateById(carBrandInfo);
+        }
+
+    }
+
+
+
+}

+ 1 - 0
zzjs-common/src/main/java/com/miaxis/common/enums/FileUploadTypeEnum.java

@@ -10,6 +10,7 @@ public enum FileUploadTypeEnum
 {
     MEDIA_EXTENSION(98, "media", MimeTypeUtils.MEDIA_EXTENSION, "音视频文件"),
     CUSTOMER_TYPE(1, "customer", MimeTypeUtils.IMAGE_EXTENSION, "商户logo"),
+    CAR_BRAND(2, "car", MimeTypeUtils.IMAGE_EXTENSION, "汽车品牌logo"),
     OTHERS(99, "others", MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION, "其他文件");
 
     private final Integer code;

+ 44 - 0
zzjs-service/src/main/java/com/miaxis/car/domain/CarBrandInfo.java

@@ -0,0 +1,44 @@
+package com.miaxis.car.domain;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.miaxis.common.annotation.Excel;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * 汽车品牌表
+ * @author wwl
+ * @version 1.0
+ * @date 2021/5/21 10:36
+ */
+@Data
+@TableName("car_brand_info")
+@ApiModel(value = "CarBrandInfo", description = "汽车品牌表 car_brand_info")
+public class CarBrandInfo {
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id")
+    @ApiModelProperty(value = "主键")
+    private Long id;
+
+    @TableField("name")
+    @ApiModelProperty(value = "汽车品牌")
+    private String name;
+
+    @TableField("img")
+    @ApiModelProperty(value = "品牌logo")
+    private String img;
+
+    @TableField("first_Letter")
+    @ApiModelProperty(value = "品牌首字母")
+    private String firstletter;
+
+    @TableField("img_path")
+    @ApiModelProperty(value = "品牌logo文件路径")
+    private String imgPath;
+
+
+}

+ 12 - 0
zzjs-service/src/main/java/com/miaxis/car/mapper/CarBrandInfoMapper.java

@@ -0,0 +1,12 @@
+package com.miaxis.car.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.miaxis.car.domain.CarBrandInfo;
+
+/**
+ * @author wwl
+ * @version 1.0
+ * @date 2021/5/21 10:46
+ */
+public interface CarBrandInfoMapper extends BaseMapper<CarBrandInfo> {
+}

+ 12 - 0
zzjs-service/src/main/java/com/miaxis/car/service/ICarBrandInfoService.java

@@ -0,0 +1,12 @@
+package com.miaxis.car.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.miaxis.car.domain.CarBrandInfo;
+
+/**
+ * @author wwl
+ * @version 1.0
+ * @date 2021/5/21 10:41
+ */
+public interface ICarBrandInfoService extends IService<CarBrandInfo> {
+}

+ 16 - 0
zzjs-service/src/main/java/com/miaxis/car/service/impl/CarBrandInfoServiceImpl.java

@@ -0,0 +1,16 @@
+package com.miaxis.car.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.miaxis.car.domain.CarBrandInfo;
+import com.miaxis.car.mapper.CarBrandInfoMapper;
+import com.miaxis.car.service.ICarBrandInfoService;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author wwl
+ * @version 1.0
+ * @date 2021/5/21 10:42
+ */
+@Service
+public class CarBrandInfoServiceImpl extends ServiceImpl<CarBrandInfoMapper, CarBrandInfo> implements ICarBrandInfoService {
+}

+ 33 - 0
zzjs-service/src/main/java/com/miaxis/feign/service/ICarService.java

@@ -0,0 +1,33 @@
+package com.miaxis.feign.service;
+
+import com.miaxis.common.config.FeignConfig;
+import com.miaxis.feign.service.fallback.CarFallBackService;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.stereotype.Component;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+/**
+ * @author wwl
+ * @version 1.0
+ * @date 2021/5/21 10:13
+ */
+@FeignClient(name="carService",
+        url = "http://tool.bitefu.net",
+        fallbackFactory = CarFallBackService.class,configuration = FeignConfig.class)
+@Component
+public interface ICarService {
+
+    /**
+     *
+     * @param type brand
+     * @param from 数据源
+     * @param pagesize  数据源的量不一样 300调取所有
+     * @return
+     */
+    @GetMapping(value = "/car")
+    String car(@RequestParam("type") String type,
+               @RequestParam("from") String from,
+               @RequestParam("pagesize") String pagesize);
+
+}

+ 19 - 0
zzjs-service/src/main/java/com/miaxis/feign/service/fallback/CarFallBackService.java

@@ -0,0 +1,19 @@
+package com.miaxis.feign.service.fallback;
+
+import com.miaxis.feign.service.ICarService;
+import org.springframework.stereotype.Component;
+
+/**
+ *  调用服务端接口(异常、超时、宕机) 降级处理
+ * @author wwl
+ * @version 1.0
+ * @date 2021/5/21 10:20
+ */
+@Component
+public class CarFallBackService implements ICarService {
+
+    @Override
+    public String car(String type, String from, String pagesize) {
+        return "接口请求异常";
+    }
+}