kongdeqiang
2023-07-10 4f27e2a21aa7c0cbd07447b43fc3b83fd1525f88
修改
3个文件已修改
1个文件已添加
146 ■■■■■ 已修改文件
src/main/java/com/boying/controller/TicketBlackController.java 96 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/boying/controller/phone/TicketController.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/boying/entity/TicketBlack.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/boying/util/FileUtil.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/boying/controller/TicketBlackController.java
New file
@@ -0,0 +1,96 @@
package com.boying.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.boying.common.R;
import com.boying.common.SystemConfigProperties;
import com.boying.entity.*;
import com.boying.service.*;
import com.boying.util.DateUtilOther;
import com.boying.util.FileUtil;
import com.boying.util.NumberToCN;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.*;
@RestController
@RequestMapping("ffzf/ticketblack")
@RequiredArgsConstructor
public class TicketBlackController {
    private final TicketService ticketService;
    private final ViolationTypeService violationTypeService;
    private final TicketBlackService ticketBlackService;
    @PostMapping("findPage")
    public Object findPage(Page page, TicketBlack ticket){
        QueryWrapper<TicketBlack> wrapper =  new QueryWrapper<>();
        wrapper.lambda()
                .eq(StringUtils.isNotBlank(ticket.getCarNo()),TicketBlack::getCarNo,ticket.getCarNo())
                .eq(ticket.getIsActive() != null,TicketBlack::getIsActive,ticket.getIsActive())
                .orderByDesc(TicketBlack::getCreateTime);
        return R.ok(ticketBlackService.page(page, wrapper));
    }
    @PostMapping("/save")
    public Object save(TicketBlack ticket) throws IOException{
        QueryWrapper<TicketBlack> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(TicketBlack::getCarNo,ticket.getCarNo());
        List<TicketBlack> list = ticketBlackService.list(wrapper);
        if(list.size()>0){
            return R.failed("此车辆已存在黑名单");
        }
        ticket.setIsActive(1);
        ticket.setViolationCount(0);
        ticketBlackService.save(ticket);
        return R.ok();
    }
    /**
     * 通过id查询票据表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public R getById(@PathVariable("id" ) Integer id) {
        TicketBlack byId = ticketBlackService.getById(id);
        return R.ok(byId);
    }
    @PostMapping("/delete")
    public Object delete(Long id){
        TicketBlack ticket =ticketBlackService.getById(id);
        ticketBlackService.saveOrUpdate(ticket);
        return R.ok("操作成功");
    }
    @PostMapping("/updateById")
    public Object updateById(TicketBlack ticket){
        return R.ok( ticketBlackService.updateById(ticket));
    }
}
src/main/java/com/boying/controller/phone/TicketController.java
@@ -10,6 +10,7 @@
import com.boying.entity.*;
import com.boying.service.*;
import com.boying.util.DateUtilOther;
import com.boying.util.FileUtil;
import com.boying.util.NumberToCN;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
@@ -170,6 +171,11 @@
    public R getById(@PathVariable("id" ) Integer id) {
        Ticket byId = ticketService.getById(id);
        byId.setContent(violationTypeService.getById(byId.getViolationTypeId()).getContent());
        String shouQianMing = byId.getShouQianMing();
        if(shouQianMing != null){
            String get = FileUtil.netSourceToBase64(shouQianMing, "GET");
            byId.setShouQianMing(get);
        }
        return R.ok(byId);
    }
@@ -230,6 +236,7 @@
            tb.setCarType(ticket.getCarType());
            tb.setColor(ticket.getColor());
            tb.setViolationCount(1);
            tb.setIsActive(0);
            ticketBlackService.saveOrUpdate(tb);
        }else {
            TicketBlack ticketBlack = all.get(0);
src/main/java/com/boying/entity/TicketBlack.java
@@ -52,4 +52,10 @@
     * 黑名单(0:不是  1:是)
     */
    private int blackType;
    /**
     * 是否主动添加(0:不是  1:是)
     */
    private Integer isActive;
}
src/main/java/com/boying/util/FileUtil.java
@@ -10,8 +10,11 @@
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import sun.misc.BASE64Encoder;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Objects;
import java.util.UUID;
@@ -109,4 +112,38 @@
        }
    }
    public static String netSourceToBase64(String srcUrl,String requestMethod) {
        ByteArrayOutputStream outPut = new ByteArrayOutputStream();
        byte[] data = new byte[1024 * 8];
        try {
            // 创建URL
            URL url = new URL(srcUrl);
            // 创建链接
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod(requestMethod);
            conn.setConnectTimeout(10 * 1000);
            if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
                //连接失败/链接失效/文件不存在
                return null;
            }
            InputStream inStream = conn.getInputStream();
            int len = -1;
            while (-1 != (len = inStream.read(data))) {
                outPut.write(data, 0, len);
            }
            inStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        // 对字节数组Base64编码
        BASE64Encoder encoder = new BASE64Encoder();
        return encoder.encode(outPut.toByteArray());
    }
    public static void main(String[] args) {
        String get = netSourceToBase64("http://192.168.0.121:9999/admin/sys-file/platform/20230704154745.png", "GET");
        System.out.println(get);
    }
}