Jinquan_Ou
2023-03-22 f4c591df7d87b6276caa9aa09602c128bedcf738
导入接口
4个文件已修改
1个文件已添加
81 ■■■■■ 已修改文件
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfPropertyController.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/test/java/com/ruoyi/ExcelTest.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/domain/ZfProperty.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/impl/IZfPropertyServiceImpl.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java
@@ -7,6 +7,8 @@
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.FastByteArrayOutputStream;
import org.springframework.web.bind.annotation.GetMapping;
@@ -27,6 +29,7 @@
 * @author ruoyi
 */
@RestController
@Slf4j
public class CaptchaController
{
    @Resource(name = "captchaProducer")
@@ -94,6 +97,8 @@
        data.put("txt","77777");
        ajax.put("msg","操作成功");
        ajax.put("data",data);
        log.info("value:{}",code);
        return ajax;
    }
}
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfPropertyController.java
@@ -3,14 +3,19 @@
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.ZfProperty;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.service.IZfPropertyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
@@ -24,12 +29,16 @@
 * @Author Jin_quan Ou
 * @Date 2023-03-09 10:18
 */
@Slf4j
@RestController
@RequestMapping("/family/property")
public class ZfPropertyController extends BaseController
{
    @Autowired
    private IZfPropertyService zfPropertyService;
    @Autowired
    private TokenService tokenService;
    @GetMapping("/all")
    public AjaxResult  listAll(ZfProperty zfProperty){
@@ -59,10 +68,32 @@
    public void export(HttpServletResponse response,ZfProperty zfProperty)
    {
        List<ZfProperty> list = zfPropertyService.selectByCondition(zfProperty);
        log.info("导出记录为:{}",list);
        ExcelUtil<ZfProperty> util = new ExcelUtil<ZfProperty>(ZfProperty.class);
        util.exportExcel(response, list, "家庭资产记录数据");
    }
//
    /**
     * 导入家庭资产记录列表
     */
    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(@RequestParam("excelImport")MultipartFile file) throws Exception
    {
        ExcelUtil<ZfProperty> util = new ExcelUtil<>(ZfProperty.class);
        List<ZfProperty> propertyList = util.importExcel(file.getInputStream());
        log.info("资产列表为:{}",propertyList);
        if (zfPropertyService.saveBatch(propertyList)) {
            return AjaxResult.success("导入数据成功");
        }
        return AjaxResult.error("导入数据失败");
    }
    /**
     * 获取家庭资产记录详细信息
     */
ruoyi-admin/src/test/java/com/ruoyi/ExcelTest.java
New file
@@ -0,0 +1,27 @@
package com.ruoyi;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.ZfProperty;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.List;
/**
 * @Version 1.0
 * @Author Jin_quan Ou
 * @Date 2023-03-22 12:48
 */
@SpringBootTest
public class ExcelTest {
    @Test
    public void testExcelImport() throws Exception {
        InputStream is = new FileInputStream(new File("D:\\test.xlsx"));
        ExcelUtil<ZfProperty> util = new ExcelUtil<ZfProperty>(ZfProperty.class);
        List<ZfProperty> userList = util.importExcel(is);
    }
}
zhang-content/src/main/java/com/ruoyi/domain/ZfProperty.java
@@ -6,6 +6,8 @@
import com.ruoyi.common.annotation.Excel;
import lombok.Data;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
@@ -51,9 +53,11 @@
    @Excel(name="备注")
    private String remark;
    @Excel(name="创建时间")
//    @Excel(name="创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;
    private String url;
}
zhang-content/src/main/java/com/ruoyi/service/impl/IZfPropertyServiceImpl.java
@@ -8,10 +8,17 @@
import com.ruoyi.domain.ZfProperty;
import com.ruoyi.mapper.ZfPropertyMapper;
import com.ruoyi.service.IZfPropertyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
/**
@@ -19,13 +26,16 @@
 * @Author Jin_quan Ou
 * @Date 2023-03-09 10:36
 */
@Slf4j
@Service
public class IZfPropertyServiceImpl extends ServiceImpl<ZfPropertyMapper, ZfProperty> implements IZfPropertyService {
    @Override
    public List<ZfProperty> selectByCondition(ZfProperty zfProperty) {
        LambdaQueryWrapper<ZfProperty> lambdaQueryWrapper = buildCondition(zfProperty);
        return list(lambdaQueryWrapper);
        List<ZfProperty> list = list(lambdaQueryWrapper);
        log.info("返回的数据为:{}",list);
        return list;
    }
    private LambdaQueryWrapper<ZfProperty> buildCondition(ZfProperty zfProperty) {