二维码

This commit is contained in:
mashuai 2024-12-31 17:15:07 +08:00
parent 5198fea5d4
commit af02b8ed31
6 changed files with 321 additions and 23 deletions

View File

@ -2,7 +2,13 @@ package com.bonus.material.basic.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import cn.hutool.core.convert.Convert;
import com.bonus.common.biz.config.ListPagingUtil;
import com.bonus.common.core.utils.ServletUtils;
import com.bonus.common.log.enums.OperaType;
import com.bonus.material.basic.domain.BmQrBoxInfo;
import com.bonus.material.basic.domain.InputRecordInfo;
import com.bonus.material.common.annotation.PreventRepeatSubmit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -42,7 +48,7 @@ public class BmQrcodeInfoController extends BaseController
* 查询二维码管理列表
*/
@ApiOperation(value = "查询二维码管理列表")
@RequiresPermissions("basic:info:list")
//@RequiresPermissions("basic:info:list")
@GetMapping("/list")
public TableDataInfo list(BmQrcodeInfo bmQrcodeInfo)
{
@ -84,10 +90,24 @@ public class BmQrcodeInfoController extends BaseController
@PreventRepeatSubmit
@RequiresPermissions("basic:info:add")
@SysLog(title = "二维码管理", businessType = OperaType.INSERT, logType = 1,module = "仓储管理->新增二维码管理")
@PostMapping
@PostMapping("/add")
public AjaxResult add(@RequestBody BmQrcodeInfo bmQrcodeInfo)
{
return toAjax(bmQrcodeInfoService.insertBmQrcodeInfo(bmQrcodeInfo));
return bmQrcodeInfoService.insertBmQrcodeInfo(bmQrcodeInfo);
}
/**
* 下载二维码
* @param bmQrcodeInfo
* @param response
*/
@ApiOperation(value = "下载二维码")
@PreventRepeatSubmit
//@RequiresPermissions("basic:info:download")
@PostMapping("/download")
public void download(@RequestBody BmQrcodeInfo bmQrcodeInfo, HttpServletResponse response)
{
bmQrcodeInfoService.download(bmQrcodeInfo, response);
}
/**

View File

@ -6,6 +6,8 @@ import lombok.Data;
import lombok.ToString;
import com.bonus.common.core.web.domain.BaseEntity;
import java.util.List;
/**
* 二维码管理对象 bm_qrcode_info
*
@ -23,30 +25,63 @@ public class BmQrcodeInfo extends BaseEntity
/** 二维码ID */
private Long qrId;
@ApiModelProperty(value = "二维码id集合")
private List<Long> qrIds;
/** 二维码 */
@Excel(name = "二维码")
@ApiModelProperty(value = "二维码")
private String qrCode;
@ApiModelProperty(value = "二维码路径")
private String qrUrl;
/** 类型ID */
@Excel(name = "类型ID")
@ApiModelProperty(value = "类型ID")
private Long typeId;
@ApiModelProperty(value = "类型名称")
private String typeName;
@ApiModelProperty(value = "规格信号")
private String typeModelName;
@ApiModelProperty(value = "设备编码")
private String maCode;
/** 二维码类型 */
@Excel(name = "二维码类型")
@ApiModelProperty(value = "二维码类型")
private String qrType;
/** 任务ID */
@Excel(name = "任务ID")
@ApiModelProperty(value = "任务ID")
private Long taskId;
/** 数据所属组织 */
@Excel(name = "数据所属组织")
@ApiModelProperty(value = "数据所属组织")
private Long companyId;
@ApiModelProperty(value = "绑定状态")
private String bindStatus;
@ApiModelProperty(value = "绑定状态名称")
private String bindStatusName;
@ApiModelProperty(value="开始时间")
private String startTime;
@ApiModelProperty(value="结束时间")
private String endTime;
@ApiModelProperty(value="关键字")
private String keyWord;
@ApiModelProperty(value="二维码数量")
private int qrNum;
@ApiModelProperty(value="生产厂家id")
private Long supplierId;
@ApiModelProperty(value="生产厂家名称")
private String supplierName;
}

View File

@ -2,6 +2,7 @@ package com.bonus.material.basic.mapper;
import java.util.List;
import com.bonus.material.basic.domain.BmQrcodeInfo;
import org.apache.ibatis.annotations.Param;
/**
* 二维码管理Mapper接口
@ -58,4 +59,18 @@ public interface BmQrcodeInfoMapper
* @return 结果
*/
public int deleteBmQrcodeInfoByQrIds(Long[] qrIds);
/**
* 根据月份查询
* @param genMonth
* @return
*/
List<BmQrcodeInfo> selectByMonth(String genMonth);
/**
* 查询详情
* @param qrIds
* @return
*/
List<BmQrcodeInfo> getDetails(@Param("list") List<Long> qrIds);
}

View File

@ -1,8 +1,12 @@
package com.bonus.material.basic.service;
import java.util.List;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.material.basic.domain.BmQrcodeInfo;
import javax.servlet.http.HttpServletResponse;
/**
* 二维码管理Service接口
*
@ -33,7 +37,7 @@ public interface IBmQrcodeInfoService
* @param bmQrcodeInfo 二维码管理
* @return 结果
*/
public int insertBmQrcodeInfo(BmQrcodeInfo bmQrcodeInfo);
public AjaxResult insertBmQrcodeInfo(BmQrcodeInfo bmQrcodeInfo);
/**
* 修改二维码管理
@ -58,4 +62,11 @@ public interface IBmQrcodeInfoService
* @return 结果
*/
public int deleteBmQrcodeInfoByQrId(Long qrId);
/**
* 下载二维码
* @param bmQrcodeInfo
* @param response
*/
void download(BmQrcodeInfo bmQrcodeInfo, HttpServletResponse response);
}

View File

@ -1,13 +1,32 @@
package com.bonus.material.basic.service.impl;
import java.io.*;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import com.bonus.common.biz.config.BackstageApplication;
import com.bonus.common.biz.config.DateTimeHelper;
import com.bonus.common.biz.config.QrCodeUtils;
import com.bonus.common.biz.domain.purchase.PurchaseDto;
import com.bonus.common.biz.enums.HttpCodeEnum;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.material.purchase.domain.vo.PurchaseVo;
import com.google.zxing.WriterException;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bonus.material.basic.mapper.BmQrcodeInfoMapper;
import com.bonus.material.basic.domain.BmQrcodeInfo;
import com.bonus.material.basic.service.IBmQrcodeInfoService;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
/**
* 二维码管理Service业务层处理
*
@ -17,7 +36,7 @@ import com.bonus.material.basic.service.IBmQrcodeInfoService;
@Service
public class BmQrcodeInfoServiceImpl implements IBmQrcodeInfoService
{
@Autowired
@Resource
private BmQrcodeInfoMapper bmQrcodeInfoMapper;
/**
@ -51,10 +70,50 @@ public class BmQrcodeInfoServiceImpl implements IBmQrcodeInfoService
* @return 结果
*/
@Override
public int insertBmQrcodeInfo(BmQrcodeInfo bmQrcodeInfo)
public AjaxResult insertBmQrcodeInfo(BmQrcodeInfo bmQrcodeInfo)
{
bmQrcodeInfo.setCreateTime(DateUtils.getNowDate());
return bmQrcodeInfoMapper.insertBmQrcodeInfo(bmQrcodeInfo);
bmQrcodeInfo.setCreateBy(SecurityUtils.getUserId().toString());
String genMonth = DateTimeHelper.getNowMonth();
List<BmQrcodeInfo> list = bmQrcodeInfoMapper.selectByMonth(genMonth);
BmQrcodeInfo bean = null;
int num = 0;
int result = 0;
if (list != null && list.size() > 0) {
bean = list.get(0);
num = Integer.parseInt(bean.getQrCode().split("-")[1]);
}
for (int j = 1; j <= bmQrcodeInfo.getQrNum(); j++) {
genMonth = genMonth.replace("-", "");
String code = genMonth + "-" + String.format("%5d", num + j).replace(" ", "0");
// 新购管理-二维码打印-新增
String url = BackstageApplication.getUrl() + "backstage/machine/qrCodePage?qrcode=" + code;
// // 二维码的图片格式
String format = "jpg";
//设置路径
String mkdirsName = "images";
// linux 系统路径
String saveDirectory = "/data/imw/" + mkdirsName + "/";
String os = System.getProperty("os.name");
if (os.toLowerCase().startsWith("win")) {
//本地路径
saveDirectory = "D://files/" + mkdirsName + "/";
}
// 生成二维码
File files = new File(saveDirectory);
if (!files.exists()) {
files.mkdirs();
}
QrCodeUtils.generateQRImage(url, saveDirectory, code + ".jpg", format);
String qrUrl = saveDirectory + code + ".jpg";
bmQrcodeInfo.setQrCode(code);
bmQrcodeInfo.setQrUrl(qrUrl);
result += bmQrcodeInfoMapper.insertBmQrcodeInfo(bmQrcodeInfo);
}
if (result > 0) {
return AjaxResult.success("二维码生成成功");
}
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
}
/**
@ -93,4 +152,106 @@ public class BmQrcodeInfoServiceImpl implements IBmQrcodeInfoService
{
return bmQrcodeInfoMapper.deleteBmQrcodeInfoByQrId(qrId);
}
/**
* 下载二维码
* @param bmQrcodeInfo
* @param response
*/
@Override
public void download(BmQrcodeInfo bmQrcodeInfo, HttpServletResponse response) {
if (bmQrcodeInfo == null || CollectionUtils.isEmpty(bmQrcodeInfo.getQrIds())) {
throw new RuntimeException("下载二维码信息不能为空");
}
Set<String> addedEntries = new HashSet<>();
try (OutputStream os = response.getOutputStream();
ZipOutputStream zos = new ZipOutputStream(os)) {
//二维码下载
handlePurchaseId(addedEntries, bmQrcodeInfo, zos);
zos.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 处理二维码下载
* @param addedEntries
* @param bmQrcodeInfo
* @param zos
*/
private void handlePurchaseId(Set<String> addedEntries, BmQrcodeInfo bmQrcodeInfo, ZipOutputStream zos) throws IOException {
List<BmQrcodeInfo> details = bmQrcodeInfoMapper.getDetails(bmQrcodeInfo.getQrIds());
if (CollectionUtils.isNotEmpty(details)) {
for (BmQrcodeInfo detail : details) {
String typeName = detail.getTypeName();
String typeModelName = detail.getTypeModelName();
String path = detail.getQrUrl();
String qrCode = detail.getQrCode();
path = path.replace("filePath", "/data/imw");
extractedQrCode(qrCode);
extracted(addedEntries, zos, typeName, typeModelName, qrCode, path);
}
}
}
/**
* 二维码生产方法抽取
* @param qrCode
*/
private void extractedQrCode(String qrCode) {
// 新购管理-二维码打印-新增
String url = BackstageApplication.getUrl() + "backstage/machine/qrCodePage?qrcode=" + qrCode;
// // 二维码的图片格式
String format = "jpg";
//设置路径
String mkdirsName = "images";
// linux 系统路径
String saveDirectory = "/data/imw/" + mkdirsName + "/";
String os = System.getProperty("os.name");
if (os.toLowerCase().startsWith("win")) {
//本地路径
saveDirectory = "D://files/" + mkdirsName + "/";
}
// 生成二维码
File files = new File(saveDirectory);
if (!files.exists()) {
files.mkdirs();
}
QrCodeUtils.generateQRImage(url, saveDirectory, qrCode + ".jpg", format);
}
/**
* 二维码下载方法抽取
* @param zos
* @param typeName
* @param typeModelName
* @param code
* @param path
* @throws IOException
*/
private void extracted(Set<String> addedEntries, ZipOutputStream zos, String typeName, String typeModelName, String code, String path) throws IOException {
// 判断路径是否存在
File imageFile = new File(path);
if (!imageFile.exists()) {
return;
}
String entryName = "[" + typeName + "-" + typeModelName + "]" + code + ".jpg";
if (addedEntries.contains(entryName)) {
System.out.println("Duplicate entry skipped: " + entryName);
return;
}
addedEntries.add(entryName);
zos.setLevel(0);
zos.putNextEntry(new ZipEntry(entryName));
try (InputStream fis = new FileInputStream(imageFile)) {
byte[] buffer = new byte[1024];
int r;
while ((r = fis.read(buffer)) != -1) {
zos.write(buffer, 0, r);
}
}
zos.closeEntry();
}
}

View File

@ -21,26 +21,79 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select qr_id, qr_code, type_id, qr_type, task_id, create_by, create_time, update_by, update_time, remark, company_id from bm_qrcode_info
</sql>
<select id="selectBmQrcodeInfoList" parameterType="com.bonus.material.basic.domain.BmQrcodeInfo" resultMap="BmQrcodeInfoResult">
<include refid="selectBmQrcodeInfoVo"/>
<where>
<if test="qrCode != null and qrCode != ''"> and qr_code = #{qrCode}</if>
<if test="typeId != null "> and type_id = #{typeId}</if>
<if test="qrType != null and qrType != ''"> and qr_type = #{qrType}</if>
<if test="taskId != null "> and task_id = #{taskId}</if>
<if test="companyId != null "> and company_id = #{companyId}</if>
</where>
</select>
<select id="selectBmQrcodeInfoByQrId" parameterType="Long" resultMap="BmQrcodeInfoResult">
<include refid="selectBmQrcodeInfoVo"/>
where qr_id = #{qrId}
</select>
<select id="selectBmQrcodeInfoList" resultType="com.bonus.material.basic.domain.BmQrcodeInfo">
select bqi.id as qrId, bqi.qr_code as qrCode, mt1.type_name as typeName, mt.type_name as typeModelName,
bqi.ma_code as maCode, bqi.type_id as typeId, bqi.qr_type as qrType, bqi.task_id as taskId, bqi.create_by as
createBy,
bqi.create_time as createTime, bqi.update_by as updateBy,
bqi.update_time as updateTime,
bqi.remark as remark,
bqi.company_id as companyId,
bqi.is_bind as bindStatus,
msi.supplier as supplierName
from bm_qrcode_info bqi
left join ma_type mt on bqi.type_id = mt.type_id and mt.del_flag = '0'
left join ma_type mt1 on mt1.type_id = mt.parent_id and mt1.del_flag = '0'
left join ma_supplier_info msi on bqi.supplier_id = msi.supplier_id and msi.del_flag = '0'
<where>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
<![CDATA[and DATE_FORMAT( bqi.create_time, '%Y-%m-%d' ) BETWEEN #{startTime} AND #{endTime} ]]>
</if>
<if test="bindStatus != null and bindStatus != ''">and bqi.is_bind = #{bindStatus}</if>
<if test="keyWord != null and keyWord != ''">
and (
bqi.qr_code like concat('%', #{keyWord}, '%') or
mt1.type_name like concat('%', #{keyWord}, '%') or
mt.type_name like concat('%', #{keyWord}, '%') or
bqi.ma_code like concat('%', #{keyWord}, '%') or
msi.supplier like concat('%', #{keyWord}, '%') or
bqi.ma_code like concat('%', #{keyWord}, '%')
)
</if>
</where>
order by bqi.create_time desc
</select>
<select id="selectByMonth" resultType="com.bonus.material.basic.domain.BmQrcodeInfo">
SELECT
qr_code as qrCode
FROM
bm_qrcode_info
WHERE
DATE_FORMAT(create_time, '%Y-%m') = #{genMonth}
ORDER BY
qr_code DESC
</select>
<select id="getDetails" resultType="com.bonus.material.basic.domain.BmQrcodeInfo">
select bqi.id as qrId, bqi.qr_code as qrCode, bqi.qr_url as qrUrl, mt1.type_name as typeName, mt.type_name as typeModelName,
bqi.ma_code as maCode, bqi.type_id as typeId, bqi.qr_type as qrType, bqi.task_id as taskId, bqi.create_by as
createBy,
bqi.create_time as createTime, bqi.update_by as updateBy,
bqi.update_time as updateTime,
bqi.remark as remark,
bqi.company_id as companyId,
bqi.is_bind as bindStatus
from bm_qrcode_info bqi
left join ma_type mt on bqi.type_id = mt.type_id and mt.del_flag = '0'
left join ma_type mt1 on mt1.type_id = mt.parent_id and mt1.del_flag = '0'
where bqi.id in
<foreach collection="list" item="qrId" open="(" separator="," close=")">
#{qrId}
</foreach>
</select>
<insert id="insertBmQrcodeInfo" parameterType="com.bonus.material.basic.domain.BmQrcodeInfo" useGeneratedKeys="true" keyProperty="qrId">
insert into bm_qrcode_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="qrCode != null">qr_code,</if>
<if test="qrUrl != null">qr_url,</if>
<if test="typeId != null">type_id,</if>
<if test="qrType != null">qr_type,</if>
<if test="taskId != null">task_id,</if>
@ -50,9 +103,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateTime != null">update_time,</if>
<if test="remark != null">remark,</if>
<if test="companyId != null">company_id,</if>
<if test="supplierId != null">supplier_id,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="qrCode != null">#{qrCode},</if>
<if test="qrUrl != null">#{qrUrl},</if>
<if test="typeId != null">#{typeId},</if>
<if test="qrType != null">#{qrType},</if>
<if test="taskId != null">#{taskId},</if>
@ -62,6 +117,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateTime != null">#{updateTime},</if>
<if test="remark != null">#{remark},</if>
<if test="companyId != null">#{companyId},</if>
<if test="supplierId != null">#{supplierId},</if>
</trim>
</insert>