java List<Map<String,Object>
xml
<select id="selectShopList" resultType="java.util.HashMap">
SELECT
p.PARTY_NAME partyName,
c.CUSTOMER_NAME customerName,
s.SHOP_ID shopId,
s.SHOP_NAME shopName FROM shop_info s,customer_info c,party p
WHERE s.CUSTOMER_ID=c.CUSTOMER_ID AND s.PARTY_ID=p.PARTY_ID AND p.COUNTRY_ID=#{countryId}
</select> <select id="selectShopRole" resultType="java.util.HashMap">
SELECT
u.USER_NAME userName,
m.salertype salerType
FROM shop_saler_mapping m,user_login u WHERE m.`user_login_id`=u.`USER_LOGIN_ID`
AND m.shop_id=#{shopId}
</select>
dao
//获取门店信息
public List<HashMap<String, Object>> selectShopList(@Param("countryId")String countryId) throws Exception; //获取门店中的角色信息
public List<HashMap<String,Object>> selectShopRole(@Param("shopId")String shopId) throws Exception;
service
//导出门店人员信息
public XSSFWorkbook exportShopRole( String[] excelHeader,
String title) throws Exception;
service.impl
public XSSFWorkbook exportShopInfo(String searchStr,String conditions, String[] excelHeader,
String title) throws Exception {
//门店信息集合
List<Shop> list = shopDao.exportShopInfo(searchStr,conditions); int[] excelWidth = {,,,,,,,,,,,,}; XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet(title); XSSFRow row = sheet.createRow(); //导出字体样式
XSSFFont font = workbook.createFont();
font.setFontHeightInPoints((short) ); // 字体大小 //导出样式
XSSFCellStyle style = workbook.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
style.setFont(font); for (int i = ; i < excelWidth.length; i++) {
sheet.setColumnWidth(i, * excelWidth[i]);
} //表头数据
for (int i = ; i < excelHeader.length; i++) {
XSSFCell cell = row.createCell(i);
cell.setCellValue(excelHeader[i]);
cell.setCellStyle(style); } //表体数据
for (int i = ; i < list.size(); i++) {
row = sheet.createRow(i+);
Shop shop = list.get(i); //门店名
XSSFCell cell0 = row.createCell();
cell0.setCellValue(shop.getShopName());
cell0.setCellStyle(style); //客户编码
XSSFCell cell1 = row.createCell();
cell1.setCellValue(shop.getCustomerCode());
cell1.setCellStyle(style); //门店等级
XSSFCell cell2 = row.createCell();
if(shop.getLevel()!=null){
if(shop.getLevel().equals("")){
cell2.setCellValue("A");
}else if(shop.getLevel().equals("")){
cell2.setCellValue("B");
}else if(shop.getLevel().equals("")){
cell2.setCellValue("C");
}else if(shop.getLevel().equals("")){
cell2.setCellValue("D");
}else if(shop.getLevel().equals("")){
cell2.setCellValue("S");
}else if(shop.getLevel().equals("")){
cell2.setCellValue("AA");
}else{
cell2.setCellValue(shop.getLevel());
}
}else{
cell2.setCellValue(shop.getLevel());
} cell2.setCellStyle(style); //进驻时间
XSSFCell cell3 = row.createCell();
if(shop.getEnterDate()==null || shop.getEnterDate().equals("")){
cell3.setCellValue("");
}else{
cell3.setCellValue(DateFormatUtils.format(shop.getEnterDate(), "yyyy-MM-dd"));
}
cell3.setCellStyle(style); //区域
XSSFCell cell4 = row.createCell();
cell4.setCellValue(shop.getPartyName());
cell4.setCellStyle(style); //省份
XSSFCell cell5 = row.createCell();
cell5.setCellValue(shop.getProvinceName());
cell5.setCellStyle(style); //地址
XSSFCell cell6 = row.createCell();
cell6.setCellValue(shop.getDetailAddress());
cell6.setCellStyle(style); //联系人
XSSFCell cell7 = row.createCell();
cell7.setCellValue(shop.getContactName());
cell7.setCellStyle(style); //联系人电话
XSSFCell cell8 = row.createCell();
cell8.setCellValue(shop.getPhone());
cell8.setCellStyle(style); //邮箱
XSSFCell cell9 = row.createCell();
cell9.setCellValue(shop.getEmail());
cell9.setCellStyle(style); //经度
XSSFCell cell10 = row.createCell();
if( shop.getLng()==null){
cell10.setCellValue();
}else{
cell10.setCellValue(shop.getLng());
}
cell10.setCellStyle(style); //纬度
XSSFCell cell11 = row.createCell();
if( shop.getLat()==null){
cell11.setCellValue();
}else{
cell11.setCellValue(shop.getLat());
} cell11.setCellStyle(style); //Location
XSSFCell cell12 = row.createCell();
cell12.setCellValue(shop.getLocation());
cell12.setCellStyle(style);
} return workbook;
} @Override
public XSSFWorkbook exportShopRole(
String[] excelHeader, String title) throws Exception {
//门店信息
List<HashMap<String, Object>> shopList = shopDao.selectShopList(WebPageUtil.getLoginedUser().getPartyId()); int[] excelWidth = {,,,,,};
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet(title); //导出字体样式
XSSFFont font = workbook.createFont();
font.setFontHeightInPoints((short) ); // 字体大小 //导出样式
XSSFCellStyle style = workbook.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
style.setFont(font); XSSFCellStyle style1 = workbook.createCellStyle();
style1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
style1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
style1.setFillForegroundColor(HSSFColor.GOLD.index);
style1.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
style1.setFont(font); for (int i = ; i < excelWidth.length; i++) {
sheet.setColumnWidth(i, * excelWidth[i]);
} XSSFRow row = sheet.createRow(); //表头数据
for (int i = ; i < excelHeader.length; i++) {
XSSFCell cell = row.createCell(i);
cell.setCellValue(excelHeader[i]);
cell.setCellStyle(style1);
} //左边区域,渠道,门店名
for (int i = ; i < shopList.size(); i++) {
//返回map,每一个shopId对应一个map
HashMap<String, Object> shopMap=shopList.get(i); String shopId = shopMap.get("shopId").toString(); //门店id中对应的用户名
List<HashMap<String,Object>> listRole = shopDao.selectShopRole(shopId); String promoter="";
String ywy="";
String dd="";
for (int j = ; j < listRole.size(); j++) {
HashMap<String,Object> shop2 = listRole.get(j); if(shop2.get("salerType").toString().equals(""))
{
ywy+=shop2.get("userName")+"/";
}
else if(shop2.get("salerType").toString().equals(""))
{
promoter+=shop2.get("userName")+"/";
}
else if(shop2.get("salerType").toString().equals(""))
{
dd+=shop2.get("userName")+"/";
} } //结束循环,结果放在循环外
shopMap.put("promoter", promoter);
shopMap.put("ywy", ywy);
shopMap.put("dd", dd); }
////////////end/////////// //excel export for (int j = ; j < shopList.size(); j++) { row = sheet.createRow(j+); //区域
XSSFCell cell0 = row.createCell();
cell0.setCellValue(shopList.get(j).get("partyName").toString());
cell0.setCellStyle(style); //渠道
XSSFCell cell1 = row.createCell();
cell1.setCellValue(shopList.get(j).get("customerName").toString());
cell1.setCellStyle(style); //门店
XSSFCell cell2 = row.createCell();
cell2.setCellValue(shopList.get(j).get("shopName").toString());
cell2.setCellStyle(style); XSSFCell cell3 = row.createCell(+);
cell3.setCellValue(shopList.get(j).get("promoter").toString());
cell3.setCellStyle(style); XSSFCell cell4 = row.createCell(+);
cell4.setCellValue(shopList.get(j).get("ywy").toString());
cell4.setCellStyle(style); XSSFCell cell5 = row.createCell(+);
cell5.setCellValue(shopList.get(j).get("dd").toString());
cell5.setCellStyle(style);
} return workbook;
}
}
action
//导出门店人员信息
public void exportShopRole(){
try {
String title ="Export All Info";
String fileName = getExportExcelName(title);
final String userAgent = request.getHeader("USER-AGENT");
if (null != userAgent){
if (- != userAgent.indexOf("Firefox")) {//Firefox
fileName = new String(fileName.getBytes(), "ISO8859-1");
}else if (- != userAgent.indexOf("Chrome")) {//Chrome
fileName = new String(fileName.getBytes(), "ISO8859-1");
} else {//IE7+
fileName = URLEncoder.encode(fileName, "UTF-8");
fileName = StringUtils.replace(fileName, "+", "%20");//替换空格
}
} else {
fileName = fileName;
} //国家化列表头
String[] excelHeader = {"Party","Dealer Name","Store Name",
"Promoter Name","Sales Man Name","MD Name"}; XSSFWorkbook workbook = shopService.exportShopRole(excelHeader, title);
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
OutputStream ouputStream = response.getOutputStream();
workbook.write(ouputStream);
ouputStream.flush();
ouputStream.close();
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage(),e);
}
}
java List<Map<String,Object>的更多相关文章
- java List<Map<String,Object>遍历的方法
public static void main(String[] args) { List<HashMap<String, Object>> list = new ArrayL ...
- List<Map<String,Object>>使用Java代码遍历
List<Map<String,Object>>的结果集怎么使用Java代码遍历以获取String,Object的值: package excel; import java.u ...
- java中对List<Map<String,Object>>中的中文汉字排序
import java.text.Collator;import java.util.ArrayList;import java.util.Collections;import java.util.C ...
- JAVA中对List<Map<String,Object>>中的中文汉字进行排序
转载于:http://blog.csdn.net/flykos/article/details/54631573 参考:http://www.jb51.net/article/88710.htm 本篇 ...
- JAVA中对List<map<String,Object>>根据map某个key值进行排序
方法compareTo()比较此对象与指定对象的顺序.如果该对象小于.等于或大于指定对象,则分别返回负整数.零或正整数.返回整数,1,-1,0:返回1表示大于,返回-1表示小于,返回0表示相等. 普通 ...
- java中List<Map<String, Object>>关于null的判断
List<Map<String, Object>> selectTmFileInfo = fileInfoService.selectTmFileInfoByToken(cTo ...
- javaBean与Map<String,Object>互转
背景:有时候想不通阿帕奇的BeanUtils是怎么进行map和Bean互相转化的. 工作闲暇之余,自己写个一小段代码,一探究竟,试试才发现,原来一切并非我们想的那么什么和复杂. 注:这里只是简单实例, ...
- 迭代输出Map和List<Map<String,Object>>的方法
一.Map<String,Object> String:key的类型 Object:value的类型,value可能是String,或者int类型,什么类型都可以 对于Map接口来说,本身 ...
- Java中Map和Object的互相转换方式
一.使用Apache中的BeanUtils类,导入commons-beanutils包. Jar包Maven下载地址:https://mvnrepository.com/artifact/common ...
随机推荐
- Android & iOS 启动画面工具
感谢Aone!为我们开发了如此便捷的工具!! 以下为原文: Android & iOS 启动画面工具 下载:OneSplash.启动画面工具.Aone.20190318.zip 说明:这一个 ...
- 团队-爬虫豆瓣top250项目-模块开发过程
项目托管平台地址:https://github.com/gengwenhao/GetTop250.git 开发模块功能: "get_info()单个页面的爬取"功能,开发时间:15 ...
- locate语法
1.命令格式:locate [参数] [文件] 2.命令功能:locate命令可以在搜寻数据库时快速找到档案,数据库由updatedb程序来更新,updatedb是由cron daemon周期性建立的 ...
- dos脚本2
一.简单批处理内部命令简介 1.Echo 命令 打开回显或关闭请求回显功能,或显示消息.如果没有任何参数,echo 命令将显示当 前回显设置. 语法 echo [{on off}] [mess ...
- 基于TCP的安卓客户端开发
一.Socket通信简介 Android与服务器的通信方式主要有两种,一是Http通信,一是Socket通信.两者的最大差异在于,http连接使用的是“请求—响应方式”,即在请求时建立连接通道,当客户 ...
- Django runserver UnicodeDecodeError
编码问题可以说是我遇到过的python 2.7最大的败笔 今天写django时,很简单的一个项目却报UnicodeDecodeError,而我的代码中一个中文字符都没有出现. 如下: 网上找到的所谓解 ...
- ubuntu16.04+caffe+GPU+cuda+cudnn安装教程
步骤简述: 1.安装GPU驱动(系统适配,不采取手动安装的方式) 2.安装依赖(cuda依赖库,caffe依赖) 3.安装cuda 4.安装cudnn(只是复制文件加链接,不需要编译安装的过程) 5. ...
- 【EMV L2】DDA标准动态数据认证处理流程
[标准动态数据认证DDA] 标准动态数据处理过程,除了动态签名由卡片生成以外,其他都是由终端执行的.处理过程: 1.认证中心公钥的获取终端使用认证中心公钥索引(PKI)以及卡片中的注册的应用提供商标识 ...
- Python全栈之路----函数----局部变量
全局变量是定义在函数外部以及代码的变量,全局能用. 局部变量就是定义在函数里的变量,只能在局部生效. 在函数内部,可以引用全局变量. 如果全局和局部都有一个名字相同的变量,在函数内会优先调用函数内的局 ...
- SQL-记录-005
对于记录的操作涉及的知识比较多,分多篇文章进行梳理. 记录创建篇:记录删除篇:记录修改篇:记录查询篇: