1.引入POI依赖 :
org.apache.poi
poi-ooxml
3.17
org.apache.poi
poi-ooxml-schemas
3.17
cn.hutool
hutool-all
4.5.10
2.controller层:
package com.techlutong.jzm.controller.admin;
/**
* Title: AdminJzmUserController
* Description: 会员管理相关接口
*
* @author jintian
* @created 2019/3/27 14:47
*/
import com.alibaba.fastjson.support.spring.annotation.FastJsonFilter;
import com.techlutong.jzm.config.JZMJsonView;
import com.techlutong.jzm.constant.CommonConstant;
import com.techlutong.jzm.service.JzmUserService;
import com.techlutong.jzm.vo.ResponseMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
@Api(value = "AdminJzmUserController", description = "jzm:AdminJzmUserController")
@RestController
@RequestMapping(value = CommonConstant.ApiPath.V1, produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
public class AdminJzmUserController {
@Autowired
JzmUserService jzmUserService;
/**
* 导出商铺信息
*
*
* @param shopName
* @param shopCode
* @param jzmShopAuditStatus
* @param response
* @return
* @throws Exception
*/
@ApiOperation(value="导出商铺信息", notes = "")
@GetMapping(value = CommonConstant.ApiAuth.ANON + "/exportJzmUserInfo")
public ResponseMessage exportJzmUserInfo(String shopName,String shopCode,String jzmShopAuditStatus, HttpServletResponse response)throws Exception{
return jzmUserService.exportJzmUserInfo(shopName,shopCode,jzmShopAuditStatus,response);
}
}
3.service层:
package com.techlutong.jzm.service;
import com.techlutong.jzm.model.JzmUser;
import com.techlutong.jzm.vo.ResponseMessage;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Title: JzmUserService
* Description: TODO
*
* @author
* @created
*/
public interface JzmUserService extends CommonService {
/**
* 导出商铺信息
*
*
* @param shopName
* @param shopCode
* @param jzmShopAuditStatus
* @param response
* @return
* @throws Exception
*/
ResponseMessage exportJzmUserInfo(String shopName,String shopCode,String jzmShopAuditStatus, HttpServletResponse response)throws Exception;
}
4.service实现层:
package com.techlutong.jzm.service.impl;
import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.github.wenhao.jpa.Specifications;
import com.techlutong.jzm.enums.*;
import com.techlutong.jzm.model.*;
import com.techlutong.jzm.repository.*;
import com.techlutong.jzm.service.*;
import com.techlutong.jzm.util.*;
import com.techlutong.jzm.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* Title: JzmUserService
* Description: TODO
*
* @author
* @created
*/
@Slf4j
@Service
public class JzmUserServiceImpl implements JzmUserService {
@Autowired
private JzmUserRepository jzmUserRepository;
/**
* 导出商铺信息
*
* @param shopName
* @param shopCode
* @param jzmShopAuditStatus
* @param response
* @return
* @throws Exception
*/
@Override
public ResponseMessage exportJzmUserInfo(String shopName,String shopCode,String jzmShopAuditStatus,HttpServletResponse response) throws Exception {
//个体商铺信息
List sellerListP = this.findByPersonal(shopName,shopCode,jzmShopAuditStatus);
//企业商铺信息
List sellerListE = this.findByEnterprise(shopName,shopCode,jzmShopAuditStatus);
List