导出EXcel文件Java代码
Posted Roam-G
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了导出EXcel文件Java代码相关的知识,希望对你有一定的参考价值。
导出EXcel文件Java代码
@RequestMapping(value="/findDistributeStockskuList",method=RequestMethod.POST)
@ApiOperation(value="搜索")
@ApiImplicitParams(
@ApiImplicitParam(name="findDistributeStockskuList",value="传入的参数",required=true,paramType="body",dataType="TbDistributeStocksku")
)
public ResultCode<TbDistributeStocksku> findDistributeStockskuList(@RequestBody TbDistributeStocksku find)
ResultCode<TbDistributeStocksku> rc = new ResultCode<>();
CacheEmployee ce = (CacheEmployee) SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal();
if(ce == null)
rc.setCode(CommonEnum.NO_PERMISSION.getCode());
rc.setMsg("没有权限");
return rc;
Map<String, Object> params = new HashMap<String, Object>();
params.put("supplierids", Sys.isCheckNull(ce.getSupplierId()));
//拼接查询条件
boolean findMyCustomer = false;//
if(2 == ce.getUserType())
//如果是卖家账号
params.put("companyidOrOwnids", Sys.isCheckNull(ce.getCustomerId()));
else
if(find.getCompanyid() != null && find.getCompanyid().intValue()>=0)
params.put("companyids", Sys.isCheckNull(find.getCompanyid()));
else if(find.getCompanyidList() != null && find.getCompanyidList().size()>0)
params.put("companyidList",find.getCompanyidList());
if(1 == ce.getIsAdministrator())
;
else
//如果是普通员工,只能看自己仓库的
params.put("warehouseids", Sys.isCheckNull(ce.getWarehouseId()));
if(Sys.isCheckNull(find.getCompanyid())>0 || (find.getCompanyidList() != null && find.getCompanyidList().size()>0))
//如果有指定卖家
else
if(1 == ce.getIsAdministrator())
//如果是超管,则查询所有卖家
else
//如果是普通员工
if(Sys.isCheckNull(ce.getCompanyIds()).length() >=4)
//如果该员工是某些卖家的负责人
String companyIds = ce.getCompanyIds().replace(";",",").replace(",,",",").replace(" ","");
companyIds = Sys.deletePrefixSuffix(companyIds,",");
String[] companyId_arr = companyIds.split(",");
ArrayList<Integer> companyIdList = new ArrayList<Integer>();
for(int i=0;i<companyId_arr.length;i++)
if(Sys.isNull(companyId_arr[i])== false && Sys.isDigit(companyId_arr[i]) == true)
companyIdList.add(Integer.valueOf(companyId_arr[i]));
if(companyIdList != null && companyIdList.size()>0)
params.put("companyidList",companyIdList);// 指定客户列表
findMyCustomer = true;
else
;//没有指定卖家,那就是查所有
if(find.getTimeStr() != null && find.getTimeStr().length == 2)
params.put("startTime",Sys.isCheckNull(find.getTimeStr()[0]));
params.put("endTime",Sys.isCheckNull(find.getTimeStr()[1]));
//params.put("supplierIds",Sys.isCheckNull(find.getTimeStr()[1]));
if(find.getStocksku() !=null )
// params.putt("stockskuslike", find.getStocksku());
if (find.getStocksku().indexOf(",") >= 0)
String[] stockSku_Arr = find.getStocksku().split(",");
ArrayList<String> stockSkuList = new ArrayList<String>();
for (String stockSku : stockSku_Arr)
if (Sys.isNull(stockSku) == false)
stockSkuList.add(stockSku);
params.put("stockSkuList", stockSkuList);
else
params.put("stockskuslike", Sys.isCheckNull(find.getStocksku()));// 模糊搜索
if(find.getFlagExe()==1)
params.put("startNum", Sys.getStartNum(find.getPage(), find.getPageSize()));
params.put("pageSize", find.getPageSize());
else
params.put("startNum", 0);
params.put("pageSize", 50000);
params.put("findallparams", 1);
params.put("orderBys", "create_time desc");
try
int count = distributeStockskuService.findDistributeStockskuCount(params);
rc.setTotalNum(count);
if(count>0)
if(0 == find.getFlagExe()) //如果是下载
TbDownloadConfig downloadConfig = downloadConfigService.findOneDownloadConfig();
int HHMM = Integer.valueOf(Sys.getCtime().substring(8,12));
if(count > downloadConfig.getMaxcount())
if((HHMM >= downloadConfig.getStarttime1() && HHMM<=downloadConfig.getEndtime1()) || HHMM >= downloadConfig.getStarttime2() && HHMM<=downloadConfig.getEndtime2())
rc.setCode(CommonEnum.OTHER_EXCEPTION.getCode());
rc.setMsg("当前下载量是"+count+"条,"+downloadConfig.getDescr());
return rc;
else
;//下载量超过限制,但不在禁止时间范围内
else
;//下载量没超过限制
Page page = new Page(find.getPage(),find.getPageSize(),count);
List<TbDistributeStocksku> list = distributeStockskuService.findDistributeStocksku(params);
//获取公司列表,转为Hash格式
HashMap<Integer,String> hash_customer = new HashMap<Integer,String>();
List<TbCustomer> customerList = customerService.findAllCustomerList(ce.getSupplierId(),true);
if(customerList != null && customerList.size() > 0)
for(TbCustomer customer:customerList)
hash_customer.put(customer.getId(),customer.getName());
if(list != null && list.size() > 0)
//展示公司的名称
for(TbDistributeStocksku bill:list)
bill.setCompanyName(Sys.isCheckNull(hash_customer.get(bill.getCompanyid())));
Integer nub=bill.getProductnum();
Double countbill=0.0;
if(nub>0)
for (int i = 0; i < nub; i++)
countbill+=bill.getPrice();
DecimalFormat format=new DecimalFormat("0.00");
String a=format.format(countbill);
bill.setCountprice(Double.parseDouble(a));
rc.setCode(CommonEnum.SUCCESS.getCode());
rc.setDatas(list);
list = null;
rc.setMsg(CommonEnum.SUCCESS.getMsg());
rc.setPop(page);
return rc;
else
rc.setCode(CommonEnum.NO_DATA.getCode());
rc.setMsg("没有满足条件的数据");
list = null;
else
rc.setCode(CommonEnum.NO_DATA.getCode());
rc.setMsg("没有满足条件的数据");
rc.setTotalNum(0);
if(CommonEnum.NO_DATA.getCode().equals(rc.getCode()) == true)
if(true == findMyCustomer)
//如果查无数据,并且该员工是指定卖家的负责人,则给的提示不一样
rc.setMsg("查无数据,您只能查看指定卖家的相关数据");
catch (SQLException e)
rc.setCode(CommonEnum.FAILED.getCode());
rc.setMsg(CommonEnum.FAILED.getMsg()+"[sql]:"+e.getMessage());
catch (Exception e)
rc.setCode(CommonEnum.FAILED.getCode());
rc.setMsg(CommonEnum.FAILED.getMsg()+"[other]:"+e.getMessage());
return rc;
以上是关于导出EXcel文件Java代码的主要内容,如果未能解决你的问题,请参考以下文章