自动化立体仓库 - WMS系统
zjj
2024-12-12 4103bb9c1279fa84dffa3d5aa99298da426b00fe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.zy.common.web;
 
import com.core.common.BaseRes;
import com.core.common.Cools;
import com.core.common.R;
import com.zy.common.config.AdminInterceptor;
import com.zy.common.utils.BarcodeUtils;
import com.zy.common.utils.QrCode;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;
 
/**
 * todo
 * Created by vincent on 2019-11-25
 */
@RestController
@RequestMapping("file/")
public class FileController {
 
  
    @RequestMapping(value = "/barcode/qrcode/auth")
//    @ManagerAuth(memo = "商品编号条形码获取(type:1(条形码);2(二维码)")
    public R matCodeBarcode(@RequestParam(defaultValue = "1") Integer type
                            , @RequestParam String param
                            , @RequestParam(required = false) Integer width
                            , @RequestParam(required = false) Integer height
                            , HttpServletResponse response) throws Exception {
        AdminInterceptor.cors(response);
        if (Cools.isEmpty(param)){
            return R.parse(BaseRes.EMPTY);
        }
        BufferedImage img;
        if (type == 1) {
            img = BarcodeUtils.encode(param, width, height);
        } else {
            img = QrCode.createImg(param, width, height);
        }
        if (!ImageIO.write(img, "jpg", response.getOutputStream())) {
            throw new IOException("Could not write an image of format jpg");
        }
        response.getOutputStream().flush();
        response.getOutputStream().close();
        return R.ok();
    }
 
}