Commit f6d830a0 by zhangyu

导出

parent 74cff147
......@@ -912,4 +912,28 @@
<insert id="insertInfoByIp">
insert into sys_login_blacklist(black_ip,create_time) values (#{userIp},#{date})
</insert>
<select id="findListUser" resultType="com.ejweb.modules.user.entity.UserExport">
SELECT /*a.id,*/
a.login_name,
a.no,
a.name,
a.email,
a.phone,
a.mobile,
c.name AS company,
o.name AS office,
a.huawei_num,
a.user_type,
a.login_ip,
a.login_date,
a.login_flag,
a.photo
FROM sys_user a
LEFT JOIN sys_office c
ON c.id = a.company_id
LEFT JOIN sys_office o
ON o.id = a.office_id
WHERE a.del_flag='0'
AND user_type=6
</select>
</mapper>
\ No newline at end of file
......@@ -23,6 +23,7 @@ import com.ejweb.modules.user.service.UserService;
import com.jdair.util.http.client.HTTPClientUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
......@@ -32,7 +33,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.*;
......@@ -1063,5 +1067,63 @@ public class UserController {
}
}
@RequestMapping(value = "/edit/export")
public void exportFile(HttpServletRequest request, HttpServletResponse response) throws IOException {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("信息表");
List<UserExport> classmateList = userService.findListUser();
// 设置要导出的文件的名字
String fileName = "users" + new Date() + ".xls";
// 新增数据行,并且设置单元格数据
int rowNum = 1;
// headers表示excel表中第一行的表头 在excel表中添加表头
String[] headers = {"归属公司", "归属部门", "登录名", "密码", "工号", "姓名", "邮箱", "电话", "手机", "用户类型", "最后登陆IP", "最后登陆日期", "是否允许登陆", "头像"};
HSSFRow row = sheet.createRow(0);
for (int i = 0; i < headers.length; i++) {
HSSFCell cell = row.createCell(i);
HSSFRichTextString text = new HSSFRichTextString(headers[i]);
cell.setCellValue(text);
}
//在表中存放查询到的数据放入对应的列
for (UserExport item : classmateList) {
HSSFRow row1 = sheet.createRow(rowNum);
row1.createCell(0).setCellValue(item.getCompany());
row1.createCell(1).setCellValue(item.getOffice());
row1.createCell(2).setCellValue(item.getLoginName());
row1.createCell(3).setCellValue(item.getPassword());
row1.createCell(4).setCellValue(item.getNo());
row1.createCell(5).setCellValue(item.getName());
row1.createCell(6).setCellValue(item.getEmail());
row1.createCell(7).setCellValue(item.getPhone());
row1.createCell(8).setCellValue(item.getMobile());
row1.createCell(9).setCellValue(item.getUserType());
row1.createCell(10).setCellValue(item.getLoginIp());
row1.createCell(11).setCellValue(item.getLoginDate());
row1.createCell(12).setCellValue(item.getLoginFlag());
row1.createCell(13).setCellValue(item.getPhoto());
rowNum++;
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
workbook.write(os);
byte[] bytes = os.toByteArray();
response.reset();
response.setContentType("application/msexcel;charset=utf-8");
response.setHeader("Content-disposition", "attachment;filename= " + fileName);
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "*");
response.addHeader("Access-Control-Allow-Headers", "*");
response.getOutputStream().write(bytes);
response.getOutputStream().flush();
//response.getOutputStream().close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
......@@ -106,4 +106,5 @@ public interface UserDao extends CurdDao<UserEntity> {
LoginIpInfo findByIp(@Param("userIp") String userIp);
void insertInfoByIp(@Param("userIp") String userIp ,@Param("date") Date date);
List<UserExport> findListUser();
}
/**
* Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
*/
package com.ejweb.modules.user.entity;
import com.ejweb.core.base.BaseEntity;
import java.util.Date;
/**
* 用户Entity
* @author ThinkGem
* @version 2013-12-05
*/
public class UserExport extends BaseEntity {
private static final long serialVersionUID = 1L;
private String company; // 归属公司
private String office; // 归属部门
private String loginName;// 登录名
private String password;// 密码
private String no; // 工号
private String name; // 姓名
private String email; // 邮箱
private String phone; // 电话
private String mobile; // 手机
private String mobileNubmer; // 手机
private String userType;// 用户类型
private String loginIp; // 最后登陆IP
private String loginDate; // 最后登陆日期
private String loginFlag; // 是否允许登陆
private String photo; // 头像
private String oldLoginName;// 原登录名
private String newPassword; // 新密码
public static long getSerialVersionUID() {
return serialVersionUID;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public String getOffice() {
return office;
}
public void setOffice(String office) {
this.office = office;
}
public String getLoginName() {
return loginName;
}
public void setLoginName(String loginName) {
this.loginName = loginName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getMobileNubmer() {
return mobileNubmer;
}
public void setMobileNubmer(String mobileNubmer) {
this.mobileNubmer = mobileNubmer;
}
public String getUserType() {
return userType;
}
public void setUserType(String userType) {
this.userType = userType;
}
public String getLoginIp() {
return loginIp;
}
public void setLoginIp(String loginIp) {
this.loginIp = loginIp;
}
public String getLoginDate() {
return loginDate;
}
public void setLoginDate(String loginDate) {
this.loginDate = loginDate;
}
public String getLoginFlag() {
return loginFlag;
}
public void setLoginFlag(String loginFlag) {
this.loginFlag = loginFlag;
}
public String getPhoto() {
return photo;
}
public void setPhoto(String photo) {
this.photo = photo;
}
public String getOldLoginName() {
return oldLoginName;
}
public void setOldLoginName(String oldLoginName) {
this.oldLoginName = oldLoginName;
}
public String getNewPassword() {
return newPassword;
}
public void setNewPassword(String newPassword) {
this.newPassword = newPassword;
}
}
\ No newline at end of file
package com.ejweb.modules.user.entity;
import java.util.Date;
import com.ejweb.core.base.BaseEntity;
import com.ejweb.core.conf.GConstants;
import java.util.Date;
/**
* 用户详情扩展表 对应联系人列表功能
* @author lyw
......
......@@ -28,7 +28,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
......@@ -676,4 +675,7 @@ public class UserService extends CurdService<UserDao, UserEntity> {
// String date = simpleDateFormat.format(new Date());
dao.insertInfoByIp(userIp,new Date());
}
public List<UserExport> findListUser() {
return dao.findListUser();
}
}
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