feige
2025-04-29 fb7ca62d2854c82ac6e0a551bf921dabe6ee7bbc
增加了二维码接口
2个文件已修改
5个文件已添加
350 ■■■■■ 已修改文件
ruoyi-admin/pom.xml 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/qrCodeController.java 162 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/domain/qrcode.java 45 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/mapper/qrcodeMapper.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/impl/qrCodeServiceImpl.java 105 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/qrCodeService.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/pom.xml
@@ -77,6 +77,13 @@
            <artifactId>ruoyi-common</artifactId>
        </dependency>
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.7.1</version>
        </dependency>
        <!-- 腾讯云 -->
        <dependency>
            <groupId>com.qcloud</groupId>
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/qrCodeController.java
New file
@@ -0,0 +1,162 @@
package com.ruoyi.web.controller.zhang;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.sign.Base64;
import com.ruoyi.domain.qrcode;
import com.ruoyi.framework.config.ServerConfig;
import com.ruoyi.service.qrCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.util.FastByteArrayOutputStream;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import static com.ruoyi.common.core.page.TableSupport.PAGE_NUM;
import static com.ruoyi.common.core.page.TableSupport.PAGE_SIZE;
@RestController
@RequestMapping("/qrCode")
public class qrCodeController {
    @Autowired
    private ServerConfig serverConfig;
    @Autowired
    private qrCodeService coSService;
    @GetMapping("/all")
    public AjaxResult listAll(qrcode cos){
        //  startPage();
        Integer pageNum = Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1);
        Integer pageSize = Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10);
        return coSService.selectDataList(cos, pageNum,pageSize);
    }
    @GetMapping(value = "/getInf")
    public AjaxResult getInf(@RequestParam(name = "id") Long id) {
        return AjaxResult.success(coSService.getById(id));
    }
    @Log(title = "生成二维码记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody qrcode cos) throws ParseException {
        cos.setCreateTime(new Date());
            try {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                Date d  = null;
                d = sdf.parse("2024-01-01");
            }catch (Exception e) {
                e.printStackTrace();
            }
        return coSService.addData(cos);
    }
    @Log(title = "生成二维码记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody qrcode cos)
    {
        //  cos.setApproveStatus(1);
        return coSService.updateData(cos);
    }
//
    /**
     * 批量删除保洁收纳记录
     */
//    @PreAuthorize("@ss.hasPermi('system:property:remove')")
    @Log(title = "生成二维码记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return coSService.deleteData(ids);
    }
    @Log(title = "二维码生成记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, qrcode cos)
    {
        List<qrcode> list = coSService.selectByCondition(cos);
        // log.info("导出记录为:{}",list);
        ExcelUtil<qrcode> util = new ExcelUtil<>(qrcode.class);
        util.exportExcel(response, list, "二维码生成记录数据");
    }
    @GetMapping("/generateCode")
    public AjaxResult generateCode(@RequestParam  Integer id, @RequestParam  String uri) {
        AjaxResult ajax = AjaxResult.success();
        BufferedImage image = null;
        QrConfig config = new QrConfig(300, 300);
        config.setMargin(3);
        //   config.setErrorCorrection(ErrorCorrectionLevel.H);
// 设置前景色,既二维码颜色(青色)
// config.setForeColor(new Color(0,60,130).getRGB());
// config.setBackColor(new Color(242,242,242).getRGB());
        image = QrCodeUtil.generate(uri, //二维码内容
                config
        );
        String url = "";
        // 转换流信息写出
        FastByteArrayOutputStream os = new FastByteArrayOutputStream();
        try
        {
            ImageIO.write(image, "jpg", os);
            //    ImageIO.write(image, "jpg", new File("D:/1.jpg"));
            String filePath = RuoYiConfig.getUploadPath();
            InputStream input = new ByteArrayInputStream(os.toByteArray());
            //InputStream转成MultipartFile
            MultipartFile multipartFile =new MockMultipartFile("file", "file.jpg", "text/plain", input);
            String fileName = FileUploadUtils.upload(multipartFile,filePath);
            url = serverConfig.getUrl() + fileName;
            System.out.println(url);
            System.out.println(fileName);
            System.out.println(FileUtils.getName(fileName));
            qrcode cos = new qrcode();
            cos.setId(id);
            cos.setCodeS(fileName);
            coSService.updateData(cos);;
//            urls.add(url);
//
//            fileNames.add(fileName);
//            newFileNames.add(FileUtils.getName(fileName));
//            originalFilenames.add(file.getOriginalFilename());
        }
        catch (IOException e)
        {
            return AjaxResult.error(e.getMessage());
        }
        ajax.put("uuid", "222222222222222222222");
        ajax.put("img", Base64.encode(os.toByteArray()));
        return ajax;
    }
}
ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml
@@ -56,7 +56,7 @@
    </select>
    <select id="selectMenuTreeAllSuperAdmin" resultMap="SysMenuResult">
        select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.`query`, m.visible, m.status, ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time
        from sys_menu m where m.menu_type in ('M', 'C') and m.status = 0 and m.menu_id in (11, 12, 13, 14)
        from sys_menu m where m.menu_type in ('M', 'C') and m.status = 0 and m.menu_id in (11, 12, 13, 14,15)
        order by m.parent_id, m.order_num
    </select>
    <select id="selectMenuListByUserId" parameterType="SysMenu" resultMap="SysMenuResult">
zhang-content/src/main/java/com/ruoyi/domain/qrcode.java
New file
@@ -0,0 +1,45 @@
package com.ruoyi.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.annotation.Excel;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
@TableName("qrcode")
public class qrcode  implements Serializable {
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;
    @Excel(name = "姓名")
    private String name;
    @Excel(name = "标题")
    private String title;
    private String filePath;
    @Excel(name = "图片" ,height=55, cellType = Excel.ColumnType.IMAGE)
    private String codeS;
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date createTime;
    /**
     * 开始时间
     */
    @TableField(exist = false)
    private Date happenStartDeadTime;
    /**
     * 结束时间
     */
    @TableField(exist = false)
    private Date happenEndDeadTime;
}
zhang-content/src/main/java/com/ruoyi/mapper/qrcodeMapper.java
New file
@@ -0,0 +1,8 @@
package com.ruoyi.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.domain.qrcode;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface qrcodeMapper extends BaseMapper<qrcode>{
}
zhang-content/src/main/java/com/ruoyi/service/impl/qrCodeServiceImpl.java
New file
@@ -0,0 +1,105 @@
package com.ruoyi.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.MapUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.Physcial;
import com.ruoyi.domain.qrcode;
import com.ruoyi.mapper.PhyscialMapper;
import com.ruoyi.mapper.qrcodeMapper;
import com.ruoyi.service.PhyscialService;
import com.ruoyi.service.qrCodeService;
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@Service
public class qrCodeServiceImpl extends ServiceImpl<qrcodeMapper, qrcode> implements qrCodeService {
    private LambdaQueryWrapper<qrcode> buildCondition(qrcode cos){
        LambdaQueryWrapper<qrcode> lqw = new LambdaQueryWrapper<>();
        lqw.like(!StringUtils.isEmpty(cos.getName()),qrcode::getName,cos.getName())
                .between(cos.getHappenStartDeadTime()!=null&&cos.getHappenEndDeadTime()!=null,qrcode::getCreateTime,cos.getHappenStartDeadTime(),cos.getHappenEndDeadTime());
//        lqw.like(!StringUtils.isEmpty(zfProperty.getType()), ZfProperty::getType, zfProperty.getType())
//                .like(!StringUtils.isEmpty(zfProperty.getTitle()), ZfProperty::getTitle, zfProperty.getTitle())
//                .like(!StringUtils.isEmpty(zfProperty.getLocation()), ZfProperty::getLocation, zfProperty.getLocation())
//                .like(!StringUtils.isEmpty(zfProperty.getHolder()), ZfProperty::getHolder, zfProperty.getHolder())
//                .like(!StringUtils.isEmpty(zfProperty.getAddress()), ZfProperty::getAddress, zfProperty.getAddress())
//                .like(!StringUtils.isEmpty(zfProperty.getRemark()), ZfProperty::getRemark, zfProperty.getRemark())
//                .eq(zfProperty.getFamilyId()!=null,ZfProperty::getFamilyId,zfProperty.getFamilyId())
//                .in(ZfProperty::getFamilyId,familyIdList)
//                .eq(zfProperty.getHappenTime()!=null,ZfProperty::getHappenTime,zfProperty.getHappenTime())
//                .between(zfProperty.getHappenStartTime() != null && zfProperty.getHappenEndTime() != null, ZfProperty::getHappenTime, zfProperty.getHappenStartTime(), zfProperty.getHappenEndTime());
//        if(cos.getUid()!=1)
//            lqw.eq(cos.getUid()!=null, coscan::getUid,cos.getUid());
        lqw.orderByDesc(qrcode::getCreateTime);
        return lqw;
    }
    @Override
    public List<qrcode> selectByCondition(qrcode cos) {
        LambdaQueryWrapper<qrcode> lqw = buildCondition(cos);
        List<qrcode> beanRecords = list(lqw);
        return beanRecords;
    }
    @Override
    public AjaxResult selectDataList(qrcode cos, Integer pageNum, Integer pageSize) {
        LambdaQueryWrapper<qrcode> lqw = buildCondition(cos);
        System.out.println(pageNum);
        System.out.println(pageSize);
        System.out.println("--------------------");
        Page<qrcode> zfPropertyPage = new Page<>(pageNum, pageSize);
        Page<qrcode> pageResult =
                // page(zfPropertyPage);
                page(zfPropertyPage, lqw);
        long total = pageResult.getTotal();
        List<qrcode> beanRecords = pageResult.getRecords();//得到查询出来的数据
        System.out.println(beanRecords);
        //  List<ZfProperty> dtoResult = markOwnData(familyId, beanRecords);
        HashMap<String, Object> data = MapUtils.getResult(pageResult);
        return AjaxResult.success(data);
    }
    @Override
    public AjaxResult addData(qrcode cos) throws ParseException {
        if (save(cos)) {
            return AjaxResult.success();
        }
        else{
            return AjaxResult.error();
        }
    }
    @Override
    public AjaxResult updateData(qrcode cos) {
        if(this.updateById(cos))
            return AjaxResult.success("修改成功!");
        else
            return AjaxResult.error("修改失败!");
    }
    @Override
    public AjaxResult deleteData(Long[] ids) {
        if (this.removeByIds(Arrays.asList(ids))) {
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }
}
zhang-content/src/main/java/com/ruoyi/service/qrCodeService.java
New file
@@ -0,0 +1,21 @@
package com.ruoyi.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.domain.qrcode;
import java.text.ParseException;
import java.util.List;
public interface qrCodeService extends IService<qrcode> {
    public List<qrcode> selectByCondition(qrcode cos);
    public AjaxResult selectDataList(qrcode cos, Integer pageNum, Integer pageSize);
    public AjaxResult addData(qrcode cos) throws ParseException;
    public AjaxResult updateData(qrcode cos);
    public AjaxResult deleteData(Long[] ids) ;
}