Commit d5d230d6 authored by libin's avatar libin

会员模板下载

parent 12968aca
......@@ -42,7 +42,7 @@ public class BaseUserMemberExportBiz extends BaseBiz<BaseUserMemberExportMapper,
@Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
public void importUserMember(List<String[]> userMemberData){
public int importUserMember(List<String[]> userMemberData){
List<BaseUserMemberExport> baseUserMemberExports = new ArrayList<>();
List<Integer> levels = userMemberData.stream().map(x -> x[1]).map(Integer::valueOf).collect(Collectors.toList());
......@@ -90,6 +90,7 @@ public class BaseUserMemberExportBiz extends BaseBiz<BaseUserMemberExportMapper,
}
InsertBatch(baseUserMemberExports);
return baseUserMemberExports.size();
}
@Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
......
package com.github.wxiaoqi.security.admin.rest;
import com.github.wxiaoqi.security.admin.AdminBootstrap;
import com.github.wxiaoqi.security.admin.biz.BaseUserMemberBiz;
import com.github.wxiaoqi.security.admin.biz.BaseUserMemberExportBiz;
import com.github.wxiaoqi.security.admin.dto.UserMemberDTO;
import com.github.wxiaoqi.security.admin.entity.BaseUserMemberLevel;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.excel.ExcelImport;
import com.xxfc.platform.vehicle.common.RestResponse;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**
......@@ -73,7 +78,29 @@ public class UserMemberController {
}
}
userMemberData.remove(0);
baseUserMemberExportBiz.importUserMember(userMemberData);
return ObjectRestResponse.succ();
try {
int effectSize = baseUserMemberExportBiz.importUserMember(userMemberData);
return ObjectRestResponse.succ(effectSize);
}catch (BaseException ex){
return ObjectRestResponse.createDefaultFail();
}
}
@GetMapping("/user/excel_model/dowload")
public ResponseEntity<byte[]> dowloadUserMemberExcelModel(HttpServletResponse response){
// 重置response
response.reset();
//设置http头信息的内容
response.setCharacterEncoding("utf-8");
response.setContentType("application/vnd.ms-excel");
response.addHeader("Content-Disposition", "attachment;filename=usermember.xlsx");
InputStream inputStream = AdminBootstrap.class.getClassLoader().getResourceAsStream("file/usermember.xlsx");
try {
byte[] bytes = IOUtils.toByteArray(inputStream);
return ResponseEntity.ok(bytes);
} catch (IOException e) {
e.printStackTrace();
}
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment