From f4c591df7d87b6276caa9aa09602c128bedcf738 Mon Sep 17 00:00:00 2001 From: Jinquan_Ou <Jinquan@gdut.com> Date: 星期三, 22 三月 2023 14:52:21 +0800 Subject: [PATCH] 导入接口 --- ruoyi-admin/src/test/java/com/ruoyi/ExcelTest.java | 27 +++++++++++++ ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfPropertyController.java | 33 ++++++++++++++++ zhang-content/src/main/java/com/ruoyi/domain/ZfProperty.java | 6 ++ ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java | 5 ++ zhang-content/src/main/java/com/ruoyi/service/impl/IZfPropertyServiceImpl.java | 12 +++++ 5 files changed, 80 insertions(+), 3 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java index b28ca68..00b53ba 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java +++ b/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; } } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfPropertyController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfPropertyController.java index aa0c7f4..ee85e92 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfPropertyController.java +++ b/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,6 +29,7 @@ * @Author Jin_quan Ou * @Date 2023-03-09 10:18 */ +@Slf4j @RestController @RequestMapping("/family/property") public class ZfPropertyController extends BaseController @@ -31,11 +37,14 @@ @Autowired private IZfPropertyService zfPropertyService; + @Autowired + private TokenService tokenService; + @GetMapping("/all") public AjaxResult listAll(ZfProperty zfProperty){ Integer pageNum = Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1); Integer pageSize = Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10); - return zfPropertyService.selectUserList(zfProperty,pageNum,pageSize); + return zfPropertyService.selectUserList(zfProperty, pageNum, pageSize); } // /** @@ -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("瀵煎叆鏁版嵁澶辫触"); + + } + + /** * 鑾峰彇瀹跺涵璧勪骇璁板綍璇︾粏淇℃伅 */ diff --git a/ruoyi-admin/src/test/java/com/ruoyi/ExcelTest.java b/ruoyi-admin/src/test/java/com/ruoyi/ExcelTest.java new file mode 100644 index 0000000..e0d8ec9 --- /dev/null +++ b/ruoyi-admin/src/test/java/com/ruoyi/ExcelTest.java @@ -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); + } +} diff --git a/zhang-content/src/main/java/com/ruoyi/domain/ZfProperty.java b/zhang-content/src/main/java/com/ruoyi/domain/ZfProperty.java index 02ed3d7..b339e4a 100644 --- a/zhang-content/src/main/java/com/ruoyi/domain/ZfProperty.java +++ b/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; } diff --git a/zhang-content/src/main/java/com/ruoyi/service/impl/IZfPropertyServiceImpl.java b/zhang-content/src/main/java/com/ruoyi/service/impl/IZfPropertyServiceImpl.java index 4a881ba..3628078 100644 --- a/zhang-content/src/main/java/com/ruoyi/service/impl/IZfPropertyServiceImpl.java +++ b/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) { -- Gitblit v1.9.1