Browse Source

组件相关三个接口

recovery
zy_Java 5 years ago
parent
commit
ff9b05de09
  1. 6
      form/src/main/java/com/ccsens/form/api/ModuleController.java
  2. 32
      form/src/main/java/com/ccsens/form/bean/dto/ModuleDto.java
  3. 2
      form/src/main/java/com/ccsens/form/bean/po/FormModuleOption.java
  4. 4
      form/src/main/java/com/ccsens/form/bean/po/FormModuleOptionExample.java
  5. 31
      form/src/main/java/com/ccsens/form/persist/dao/ModuleDao.java
  6. 30
      form/src/main/java/com/ccsens/form/persist/mapper/FormModuleConfigOptionMapper.java
  7. 30
      form/src/main/java/com/ccsens/form/persist/mapper/FormModuleOptionMapper.java
  8. 9
      form/src/main/java/com/ccsens/form/service/IModuleService.java
  9. 120
      form/src/main/java/com/ccsens/form/service/ModuleService.java
  10. 82
      form/src/main/resources/mapper_dao/ModuleDao.xml
  11. 40
      form/src/main/resources/mapper_raw/FormModuleOptionMapper.xml
  12. 29
      util/src/main/java/com/ccsens/util/QrCodeUtil.java

6
form/src/main/java/com/ccsens/form/api/ModuleController.java

@ -44,9 +44,9 @@ public class ModuleController {
@MustLogin
@ApiOperation(value = "查找表单内组件和配置信息", notes = "zy:查找表单内添加的组件的配置和选项信息,如果没有则返回改组价模板的默认配置")
@RequestMapping(value = "/get/formModule", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<List<ModuleVo.ModuleInfo>> getFormModule(@ApiParam @Validated @RequestBody QueryDto<ModuleDto.GetFormModule> params) {
public JsonResponse<ModuleVo.ModuleInfo> getFormModule(@ApiParam @Validated @RequestBody QueryDto<ModuleDto.GetFormModule> params) {
log.info("查找表单内组件和配置信息:{}",params);
List<ModuleVo.ModuleInfo> moduleInfoList = moduleService.getFormModule(params);
ModuleVo.ModuleInfo moduleInfoList = moduleService.getFormModule(params.getParam(),params.getUserId());
log.info("查找表单内组件和配置信息结果:{}",moduleInfoList);
return JsonResponse.newInstance().ok(moduleInfoList);
}
@ -56,7 +56,7 @@ public class ModuleController {
@RequestMapping(value = "/update/formModule", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse updateFormModule(@ApiParam @Validated @RequestBody QueryDto<ModuleDto.UpdateFormModule> params) {
log.info("修改组件的配置信息和选项:{}",params);
moduleService.updateFormModule(params);
moduleService.updateFormModule(params.getParam(),params.getUserId());
log.info("修改组件的配置信息和选项成功");
return JsonResponse.newInstance().ok();
}

32
form/src/main/java/com/ccsens/form/bean/dto/ModuleDto.java

@ -4,7 +4,9 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* @author
@ -25,5 +27,35 @@ public class ModuleDto {
@NotNull
@ApiModelProperty("表单组件关联id")
private Long formModuleId;
@ApiModelProperty("配置信息")
private List<ModuleConfig> configList;
@ApiModelProperty("选项信息")
private List<ModuleOption> optionList;
}
@Data
@ApiModel("修改组件配置")
public static class ModuleConfig{
@ApiModelProperty("类型 0显示 1校验 2统计 默认0")
private Byte type;
@NotBlank
@ApiModelProperty("组件配置code")
private String configKey;
@NotBlank
@ApiModelProperty("配置的内容")
private String configValue;
}
@Data
@ApiModel("修改组件配置")
public static class ModuleOption{
@NotBlank
@ApiModelProperty("选项配置code")
private String optionKey;
@NotBlank
@ApiModelProperty("选项内容")
private String optionValue;
@ApiModelProperty("子选项")
private List<ModuleOption> subOptionList;
}
}

2
form/src/main/java/com/ccsens/form/bean/po/FormModuleConfigOption.java → form/src/main/java/com/ccsens/form/bean/po/FormModuleOption.java

@ -3,7 +3,7 @@ package com.ccsens.form.bean.po;
import java.io.Serializable;
import java.util.Date;
public class FormModuleConfigOption implements Serializable {
public class FormModuleOption implements Serializable {
private Long id;
private Long formModuleId;

4
form/src/main/java/com/ccsens/form/bean/po/FormModuleConfigOptionExample.java → form/src/main/java/com/ccsens/form/bean/po/FormModuleOptionExample.java

@ -4,14 +4,14 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class FormModuleConfigOptionExample {
public class FormModuleOptionExample {
protected String orderByClause;
protected boolean distinct;
protected List<Criteria> oredCriteria;
public FormModuleConfigOptionExample() {
public FormModuleOptionExample() {
oredCriteria = new ArrayList<Criteria>();
}

31
form/src/main/java/com/ccsens/form/persist/dao/ModuleDao.java

@ -2,6 +2,7 @@ package com.ccsens.form.persist.dao;
import com.ccsens.form.bean.vo.ModuleVo;
import com.ccsens.form.persist.mapper.ModuleMapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -11,7 +12,35 @@ import java.util.List;
public interface ModuleDao extends ModuleMapper {
/**
* 查找所有的组件模板和对应配置信息
* @return
* @return 返回所有组件模板的信息
*/
List<ModuleVo.ModuleInfo> queryModule();
/**
* 通过表单内的组件id查询组件基本信息
* @param formModuleId 表单内的组件id
* @return 返回组件基本信息
*/
ModuleVo.ModuleInfo getModuleByFormModuleId(@Param("formModuleId") Long formModuleId);
/**
* 通过表单内的组件id查询自定义的组件配置信息
* @param formModuleId 表单组件关联信息的id
* @return 返回配置信息
*/
List<ModuleVo.ModuleConfig> getConfigByFormModuleId(@Param("formModuleId")Long formModuleId);
/**
* 通过组件id查找组件默认的配置信息
* @param moduleId 组件id
* @return 返回配置信息
*/
List<ModuleVo.ModuleConfig> getConfigByModuleId(@Param("moduleId")Long moduleId);
/**
* 通过表单组件关联信息id查找选项信息
* @param formModuleId 表单组件关联信息id
* @return 返回选项信息
*/
List<ModuleVo.Option> getOptionByFormModuleId(@Param("formModuleId")Long formModuleId,@Param("parentId")Long parentId);
}

30
form/src/main/java/com/ccsens/form/persist/mapper/FormModuleConfigOptionMapper.java

@ -1,30 +0,0 @@
package com.ccsens.form.persist.mapper;
import com.ccsens.form.bean.po.FormModuleConfigOption;
import com.ccsens.form.bean.po.FormModuleConfigOptionExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface FormModuleConfigOptionMapper {
long countByExample(FormModuleConfigOptionExample example);
int deleteByExample(FormModuleConfigOptionExample example);
int deleteByPrimaryKey(Long id);
int insert(FormModuleConfigOption record);
int insertSelective(FormModuleConfigOption record);
List<FormModuleConfigOption> selectByExample(FormModuleConfigOptionExample example);
FormModuleConfigOption selectByPrimaryKey(Long id);
int updateByExampleSelective(@Param("record") FormModuleConfigOption record, @Param("example") FormModuleConfigOptionExample example);
int updateByExample(@Param("record") FormModuleConfigOption record, @Param("example") FormModuleConfigOptionExample example);
int updateByPrimaryKeySelective(FormModuleConfigOption record);
int updateByPrimaryKey(FormModuleConfigOption record);
}

30
form/src/main/java/com/ccsens/form/persist/mapper/FormModuleOptionMapper.java

@ -0,0 +1,30 @@
package com.ccsens.form.persist.mapper;
import com.ccsens.form.bean.po.FormModuleOption;
import com.ccsens.form.bean.po.FormModuleOptionExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface FormModuleOptionMapper {
long countByExample(FormModuleOptionExample example);
int deleteByExample(FormModuleOptionExample example);
int deleteByPrimaryKey(Long id);
int insert(FormModuleOption record);
int insertSelective(FormModuleOption record);
List<FormModuleOption> selectByExample(FormModuleOptionExample example);
FormModuleOption selectByPrimaryKey(Long id);
int updateByExampleSelective(@Param("record") FormModuleOption record, @Param("example") FormModuleOptionExample example);
int updateByExample(@Param("record") FormModuleOption record, @Param("example") FormModuleOptionExample example);
int updateByPrimaryKeySelective(FormModuleOption record);
int updateByPrimaryKey(FormModuleOption record);
}

9
form/src/main/java/com/ccsens/form/service/IModuleService.java

@ -18,14 +18,17 @@ public interface IModuleService {
/**
* 根据id查询表单内添加的组件的信息
* @param params 表单内添加的组件的id
* @param param 表单内添加的组件的id
* @param userId userId
* @return 返回组件的配置和选项信息
*/
List<ModuleVo.ModuleInfo> getFormModule(QueryDto<ModuleDto.GetFormModule> params);
ModuleVo.ModuleInfo getFormModule(ModuleDto.GetFormModule param, Long userId);
/**
* 修改组件的配置和选项
* @param userId userId
* @param params 返回空
*/
void updateFormModule(QueryDto<ModuleDto.UpdateFormModule> params);
void updateFormModule(ModuleDto.UpdateFormModule params,Long userId);
}

120
form/src/main/java/com/ccsens/form/service/ModuleService.java

@ -1,10 +1,16 @@
package com.ccsens.form.service;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Snowflake;
import com.ccsens.form.bean.dto.ModuleDto;
import com.ccsens.form.bean.po.Module;
import com.ccsens.form.bean.po.FormModuleConfig;
import com.ccsens.form.bean.po.FormModuleConfigExample;
import com.ccsens.form.bean.po.FormModuleOption;
import com.ccsens.form.bean.po.FormModuleOptionExample;
import com.ccsens.form.bean.vo.ModuleVo;
import com.ccsens.form.persist.dao.ModuleDao;
import com.ccsens.util.bean.dto.QueryDto;
import com.ccsens.form.persist.mapper.FormModuleConfigMapper;
import com.ccsens.form.persist.mapper.FormModuleOptionMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
@ -22,20 +28,120 @@ import java.util.List;
public class ModuleService implements IModuleService{
@Resource
private ModuleDao moduleDao;
@Resource
private FormModuleConfigMapper formModuleConfigMapper;
@Resource
private FormModuleOptionMapper formModuleOptionMapper;
@Resource
private Snowflake snowflake;
/**
* 查找所有组件模板
*/
@Override
public List<ModuleVo.ModuleInfo> queryModule() {
return moduleDao.queryModule();;
return moduleDao.queryModule();
}
/**
* 根据id查询表单内添加的组件的信息
*/
@Override
public List<ModuleVo.ModuleInfo> getFormModule(QueryDto<ModuleDto.GetFormModule> params) {
return null;
public ModuleVo.ModuleInfo getFormModule(ModuleDto.GetFormModule param, Long userId) {
//查找组件基本信息
ModuleVo.ModuleInfo moduleInfo = moduleDao.getModuleByFormModuleId(param.getFormModuleId());
//查找当前组件的配置
List<ModuleVo.ModuleConfig> moduleConfigList = moduleDao.getConfigByFormModuleId(param.getFormModuleId());
//没有配置信息则查询默认配置
if(CollectionUtil.isEmpty(moduleConfigList)){
moduleConfigList = moduleDao.getConfigByModuleId(moduleInfo.getId());
}
moduleInfo.setModuleConfigList(moduleConfigList);
//查找选项信息
List<ModuleVo.Option> optionList = getOptionByFormModuleId(param.getFormModuleId(),0L);
moduleInfo.setOptionList(optionList);
return moduleInfo;
}
/**
* 通过表单内的组价id和上级id查看选项信息
*/
private List<ModuleVo.Option> getOptionByFormModuleId(Long formModuleId,Long parentId){
List<ModuleVo.Option> optionList = moduleDao.getOptionByFormModuleId(formModuleId,parentId);
if(CollectionUtil.isNotEmpty(optionList)){
optionList.forEach(option -> {
List<ModuleVo.Option> subOptionList = moduleDao.getOptionByFormModuleId(formModuleId,option.getId());
if(CollectionUtil.isNotEmpty(subOptionList)) {
option.setSubOption(subOptionList);
}
});
}
return optionList;
}
/**
* 修改组件的配置和选项
*/
@Override
public void updateFormModule(QueryDto<ModuleDto.UpdateFormModule> params) {
public void updateFormModule(ModuleDto.UpdateFormModule param,Long userId) {
//查询以前的配置,删除
FormModuleConfigExample moduleConfigExample = new FormModuleConfigExample();
moduleConfigExample.createCriteria().andFormModuleIdEqualTo(param.getFormModuleId());
List<FormModuleConfig> formModuleConfigList = formModuleConfigMapper.selectByExample(moduleConfigExample);
if(CollectionUtil.isNotEmpty(formModuleConfigList)){
formModuleConfigList.forEach(formModuleConfig -> {
formModuleConfig.setRecStatus((byte) 2);
formModuleConfig.setOperator(userId);
formModuleConfigMapper.updateByPrimaryKeySelective(formModuleConfig);
});
}
//查询以前的选项,删除
FormModuleOptionExample moduleOptionExample = new FormModuleOptionExample();
moduleOptionExample.createCriteria().andFormModuleIdEqualTo(param.getFormModuleId());
List<FormModuleOption> formModuleOptionList = formModuleOptionMapper.selectByExample(moduleOptionExample);
if(CollectionUtil.isNotEmpty(formModuleOptionList)){
formModuleOptionList.forEach(formModuleOption -> {
formModuleOption.setRecStatus((byte) 2);
formModuleOption.setOperator(userId);
formModuleOptionMapper.updateByPrimaryKeySelective(formModuleOption);
});
}
//添加新配置
if(CollectionUtil.isNotEmpty(param.getConfigList())){
param.getConfigList().forEach(config -> {
FormModuleConfig formModuleConfig = new FormModuleConfig();
formModuleConfig.setId(snowflake.nextId());
formModuleConfig.setType(config.getType());
formModuleConfig.setFormModuleId(param.getFormModuleId());
formModuleConfig.setConfigKey(config.getConfigKey());
formModuleConfig.setConfigValue(config.getConfigValue());
formModuleConfig.setOperator(userId);
formModuleConfigMapper.insertSelective(formModuleConfig);
});
}
//添加新选项
saveOption(param.getOptionList(),param.getFormModuleId(),userId,0L);
}
private void saveOption(List<ModuleDto.ModuleOption> moduleOptionList, Long formModuleId, Long userId, Long parentId){
if(CollectionUtil.isNotEmpty(moduleOptionList)){
int sequence = 1;
for (ModuleDto.ModuleOption moduleOption : moduleOptionList){
FormModuleOption formModuleOption = new FormModuleOption();
formModuleOption.setId(snowflake.nextId());
formModuleOption.setFormModuleId(formModuleId);
formModuleOption.setOperator(userId);
formModuleOption.setParentId(parentId);
formModuleOption.setSequence(sequence);
formModuleOption.setOptionKey(moduleOption.getOptionKey());
formModuleOption.setOptionValue(moduleOption.getOptionValue());
formModuleOptionMapper.insertSelective(formModuleOption);
if(CollectionUtil.isNotEmpty(moduleOption.getSubOptionList())){
saveOption(moduleOption.getSubOptionList(),formModuleId,userId,formModuleOption.getId());
}
sequence++;
}
}
}
}

82
form/src/main/resources/mapper_dao/ModuleDao.xml

@ -2,8 +2,88 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ccsens.form.persist.dao.ModuleDao">
<resultMap id="moduleInfo" type="com.ccsens.form.bean.vo.ModuleVo$ModuleInfo">
<id column="id" property="id"/>
<result column="type" property="type"/>
<result column="logo" property="logo"/>
<result column="dName" property="name"/>
<result column="option" property="option"/>
<result column="hierarchy" property="hierarchy"/>
<collection property="moduleConfigList" ofType="com.ccsens.form.bean.vo.ModuleVo$ModuleConfig">
<id column="configId" property="configId"/>
<result column="cType" property="type"/>
<result column="configKey" property="configKey"/>
<result column="configValue" property="configValue"/>
</collection>
<collection property="optionList" ofType="com.ccsens.form.bean.vo.ModuleVo$Option">
<id column="optionId" property="id"/>
<result column="optionKey" property="optionKey"/>
<result column="optionValue" property="optionValue"/>
<result column="sequence" property="sequence"/>
</collection>
</resultMap>
<select id="queryModule" resultType="com.ccsens.form.bean.vo.ModuleVo$ModuleInfo">
<select id="queryModule" resultMap="moduleInfo">
SELECT
m.id,
m.type,
m.logo,
m.`name`,
m.`option`,
m.hierarchy,
c.id as configId,
c.type as cType,
c.config_key as configKey,
c.config_value as configValue
from
t_module m
LEFT JOIN
(SELECT * FROM t_module_config WHERE rec_status = 0) c on c.module_id = m.id
where
m.rec_status = 0
ORDER BY m.id
</select>
<select id="getModuleByFormModuleId" resultType="com.ccsens.form.bean.vo.ModuleVo$ModuleInfo">
SELECT
m.id,
m.type,
m.logo,
m.`name`,
m.`option`,
m.hierarchy
from
t_form_module f
LEFT JOIN t_module m on f.module_id = m.id
WHERE
f.id = #{formModuleId}
and f.rec_status = 0
and m.rec_status = 0
</select>
<select id="getConfigByFormModuleId" resultType="com.ccsens.form.bean.vo.ModuleVo$ModuleConfig">
SELECT
id as configId,
type as type,
config_key as configKey,
config_value as configValue
from
t_form_module_config
WHERE
form_module_id = #{formModuleId}
</select>
<select id="getConfigByModuleId" resultType="com.ccsens.form.bean.vo.ModuleVo$ModuleConfig">
SELECT
id as configId,
type as type,
config_key as configKey,
config_value as configValue
from
t_module_config
WHERE
module_id = #{moduleId}
and rec_status = 0
</select>
<select id="getOptionByFormModuleId" resultType="com.ccsens.form.bean.vo.ModuleVo$Option">
</select>

40
form/src/main/resources/mapper_raw/FormModuleConfigOptionMapper.xml → form/src/main/resources/mapper_raw/FormModuleOptionMapper.xml

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ccsens.form.persist.mapper.FormModuleConfigOptionMapper">
<resultMap id="BaseResultMap" type="com.ccsens.form.bean.po.FormModuleConfigOption">
<mapper namespace="com.ccsens.form.persist.mapper.FormModuleOptionMapper">
<resultMap id="BaseResultMap" type="com.ccsens.form.bean.po.FormModuleOption">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="form_module_id" jdbcType="BIGINT" property="formModuleId" />
<result column="parent_id" jdbcType="BIGINT" property="parentId" />
@ -75,13 +75,13 @@
id, form_module_id, parent_id, option_key, option_value, sequence, operator, created_at,
updated_at, rec_status
</sql>
<select id="selectByExample" parameterType="com.ccsens.form.bean.po.FormModuleConfigOptionExample" resultMap="BaseResultMap">
<select id="selectByExample" parameterType="com.ccsens.form.bean.po.FormModuleOptionExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from t_form_module_config_option
from t_form_module_option
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
@ -92,21 +92,21 @@
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from t_form_module_config_option
from t_form_module_option
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from t_form_module_config_option
delete from t_form_module_option
where id = #{id,jdbcType=BIGINT}
</delete>
<delete id="deleteByExample" parameterType="com.ccsens.form.bean.po.FormModuleConfigOptionExample">
delete from t_form_module_config_option
<delete id="deleteByExample" parameterType="com.ccsens.form.bean.po.FormModuleOptionExample">
delete from t_form_module_option
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.ccsens.form.bean.po.FormModuleConfigOption">
insert into t_form_module_config_option (id, form_module_id, parent_id,
<insert id="insert" parameterType="com.ccsens.form.bean.po.FormModuleOption">
insert into t_form_module_option (id, form_module_id, parent_id,
option_key, option_value, sequence,
operator, created_at, updated_at,
rec_status)
@ -115,8 +115,8 @@
#{operator,jdbcType=BIGINT}, #{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP},
#{recStatus,jdbcType=TINYINT})
</insert>
<insert id="insertSelective" parameterType="com.ccsens.form.bean.po.FormModuleConfigOption">
insert into t_form_module_config_option
<insert id="insertSelective" parameterType="com.ccsens.form.bean.po.FormModuleOption">
insert into t_form_module_option
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
@ -182,14 +182,14 @@
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.ccsens.form.bean.po.FormModuleConfigOptionExample" resultType="java.lang.Long">
select count(*) from t_form_module_config_option
<select id="countByExample" parameterType="com.ccsens.form.bean.po.FormModuleOptionExample" resultType="java.lang.Long">
select count(*) from t_form_module_option
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update t_form_module_config_option
update t_form_module_option
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=BIGINT},
@ -227,7 +227,7 @@
</if>
</update>
<update id="updateByExample" parameterType="map">
update t_form_module_config_option
update t_form_module_option
set id = #{record.id,jdbcType=BIGINT},
form_module_id = #{record.formModuleId,jdbcType=BIGINT},
parent_id = #{record.parentId,jdbcType=BIGINT},
@ -242,8 +242,8 @@
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.ccsens.form.bean.po.FormModuleConfigOption">
update t_form_module_config_option
<update id="updateByPrimaryKeySelective" parameterType="com.ccsens.form.bean.po.FormModuleOption">
update t_form_module_option
<set>
<if test="formModuleId != null">
form_module_id = #{formModuleId,jdbcType=BIGINT},
@ -275,8 +275,8 @@
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.ccsens.form.bean.po.FormModuleConfigOption">
update t_form_module_config_option
<update id="updateByPrimaryKey" parameterType="com.ccsens.form.bean.po.FormModuleOption">
update t_form_module_option
set form_module_id = #{formModuleId,jdbcType=BIGINT},
parent_id = #{parentId,jdbcType=BIGINT},
option_key = #{optionKey,jdbcType=VARCHAR},

29
util/src/main/java/com/ccsens/util/QrCodeUtil.java

@ -1,10 +1,18 @@
package com.ccsens.util;
import cn.hutool.core.date.DateUtil;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import net.glxn.qrgen.core.image.ImageType;
import net.glxn.qrgen.javase.QRCode;
import java.io.*;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.HashMap;
/**
* 二维码工具类
@ -82,4 +90,25 @@ public class QrCodeUtil {
return fileName;
}
/**
* 生成二位吗utf-8
* @return 返回文件位置不带前缀
*/
public String getQrCodeWithUtf8(String value, String filePath) throws Exception {
//文件地址
String fileName = "qrCode/" + DateUtil.today() + "/" + System.currentTimeMillis() + ".png";
QRCodeWriter qrCodeWriter = new QRCodeWriter();
HashMap<EncodeHintType, Object> hints = new HashMap<>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
BitMatrix bitMatrix =qrCodeWriter.encode(value, BarcodeFormat.QR_CODE, 1000, 1000,hints);
Path path = FileSystems.getDefault().getPath(filePath + fileName);
MatrixToImageWriter.writeToPath(bitMatrix, "PNG", path);
return fileName;
}
}

Loading…
Cancel
Save