|
|
|
@ -1,8 +1,19 @@ |
|
|
|
|
package org.jeecg.modules.demo.fabric.controller; |
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.util.*; |
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
|
|
import com.google.zxing.WriterException; |
|
|
|
|
import com.google.zxing.client.j2se.MatrixToImageWriter; |
|
|
|
|
import com.google.zxing.BarcodeFormat; |
|
|
|
|
import com.google.zxing.EncodeHintType; |
|
|
|
|
import com.google.zxing.MultiFormatWriter; |
|
|
|
|
import com.google.zxing.common.BitMatrix; |
|
|
|
|
import com.google.zxing.qrcode.QRCodeWriter; |
|
|
|
|
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; |
|
|
|
|
import org.jeecg.common.api.vo.Result; |
|
|
|
|
import org.jeecg.common.system.query.QueryGenerator; |
|
|
|
|
import org.jeecg.modules.demo.fabric.entity.ZyFabric; |
|
|
|
@ -63,11 +74,43 @@ public class ZyFabricController extends JeecgController<ZyFabric, IZyFabricServi |
|
|
|
|
public Result<?> queryPageList(ZyFabric zyFabric, |
|
|
|
|
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo, |
|
|
|
|
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize, |
|
|
|
|
HttpServletRequest req) { |
|
|
|
|
HttpServletRequest req) throws IOException, WriterException { |
|
|
|
|
QueryWrapper<ZyFabric> queryWrapper = QueryGenerator.initQueryWrapper(zyFabric, req.getParameterMap()); |
|
|
|
|
// QueryWrapper queryWrapper = new QueryWrapper();
|
|
|
|
|
Page<ZyFabric> page = new Page<>(pageNo, pageSize); |
|
|
|
|
IPage<ZyFabric> pageList = zyFabricService.page(page, queryWrapper); |
|
|
|
|
|
|
|
|
|
MultiFormatWriter multiFormatWriter = new MultiFormatWriter(); |
|
|
|
|
@SuppressWarnings("rawtypes") |
|
|
|
|
Map hints = new HashMap(); |
|
|
|
|
//设置UTF-8, 防止中文乱码
|
|
|
|
|
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); |
|
|
|
|
//设置二维码四周白色区域的大小
|
|
|
|
|
hints.put(EncodeHintType.MARGIN, 1); |
|
|
|
|
//设置二维码的容错性
|
|
|
|
|
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); |
|
|
|
|
//width:图片完整的宽;height:图片完整的高
|
|
|
|
|
//因为要在二维码下方附上文字,所以把图片设置为长方形(高大于宽)
|
|
|
|
|
int width = 150; |
|
|
|
|
int height = 150; |
|
|
|
|
//画二维码,记得调用multiFormatWriter.encode()时最后要带上hints参数,不然上面设置无效
|
|
|
|
|
QRCodeWriter qrCodeWriter = new QRCodeWriter(); |
|
|
|
|
List<Object> img= new ArrayList<>(); |
|
|
|
|
String content=""; |
|
|
|
|
//批量生成二维码
|
|
|
|
|
for (int i=0;i<pageList.getRecords().size();i++){ |
|
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
|
|
|
|
String fabricNumber = pageList.getRecords().get(i).getFabricNumber(); |
|
|
|
|
String name = pageList.getRecords().get(i).getName(); |
|
|
|
|
content = "面料名称:"+name+",面料编号:"+fabricNumber; |
|
|
|
|
BitMatrix bitMatrix = qrCodeWriter.encode(content, BarcodeFormat.QR_CODE, width, height, hints); |
|
|
|
|
MatrixToImageWriter.writeToStream(bitMatrix, "PNG", outputStream); |
|
|
|
|
Base64.Encoder encoder = Base64.getEncoder(); |
|
|
|
|
String text = encoder.encodeToString(outputStream.toByteArray()); |
|
|
|
|
pageList.getRecords().get(i).setQRcode("data:image/png;base64,"+text); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return Result.OK(pageList); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|