package com.dzx.service.impl;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.servlet.ModelAndView;
import com.dzx.dao.EmployDao;
import com.dzx.domain.Employ;
import com.dzx.service.EmployService;
import com.dzx.util.HrmConstants;
@Service
public class EmployServiceImpl implements EmployService {
@Autowired
private EmployDao employDao;
@Transactional(readOnly = false)
@Override
public int addEmploy(Employ employ) {
// TODO Auto-generated method stub
return employDao.addEmploy(employ);
}
@Override
public List<Employ> findCardId(Employ employ) {
// TODO Auto-generated method stub
return employDao.findCardId(employ);
}
@Override
public List<Employ> selectAllEmploy(Employ employ) {
// TODO Auto-generated method stub
return employDao.selectAllEmploy(employ);
}
@Override
public ModelAndView selectEmploy(Employ employ) {
// TODO Auto-generated method stub
if (employ != null) {
int totalRecord = employDao.selectEmployCount(employ);
employ.setTotalRecord(totalRecord);
List<Employ> employList= employDao.selectEmploy(employ);
// 保存到request作用域
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject(HrmConstants.EMPLOY_LIST, employList);
modelAndView.setViewName("employ/employList");
return modelAndView;
} else {
return new ModelAndView();
}
}
@Override
public Employ findEmployById(int employId) {
// TODO Auto-generated method stub
return employDao.findEmployById(employId);
}
@Transactional(readOnly = false)
@Override
public int updateEmploy(Employ employ) {
// TODO Auto-generated method stub
return employDao.updateEmploy(employ);
}
@Transactional(readOnly = false)
@Override
public int deleteEmploy(Integer[] caption) {
// TODO Auto-generated method stub
if (caption != null) {
for (Integer integer : caption) {
employDao.deleteEmploy(integer);
}
}
return 0;
}
@Override
public Boolean importExcel(String[] thTitle, List<Employ> listValue, String tableTitle, String path) {
// 创建Excelworkbook
XSSFWorkbook workbook = new XSSFWorkbook();
// 创建一个工作表sheet
XSSFSheet sheet = workbook.createSheet();
// 创建表头样式
XSSFCellStyle cellStyle = workbook.createCellStyle();
XSSFFont font = workbook.createFont();// 字体
font.setFontName("黑体");
font.setFontHeightInPoints((short) 14);
cellStyle.setAlignment(HorizontalAlignment.CENTER);// 居中
cellStyle.setFont(font);// 字体
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, thTitle.length - 1)); // 合并单元格
// 创建表格样式
XSSFCellStyle cellStyle2 = workbook.createCellStyle();
cellStyle2.setAlignment(HorizontalAlignment.CENTER);// 居中
// 创建第一行
XSSFRow row0 = sheet.createRow(0);
XSSFCell cell = null;
cell = row0.createCell(0);
cell.setCellValue(tableTitle);// 设置标题值
cell.setCellStyle(cellStyle);
row0.setHeightInPoints((short) 20);// 设置行高
// 创建第二行
XSSFRow row2 = sheet.createRow(1);
// 插入第二行的数据
for (int i = 0; i < thTitle.length; i++) {
cell = row2.createCell(i);
cell.setCellValue(thTitle[i]);
cell.setCellStyle(cellStyle2);
}
// 第三行,追加数据
SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日");// 格式化日期
for (int i = 0; i < listValue.size(); i++) {
XSSFRow nextRow = sheet.createRow(i + 2);
XSSFCell cell2 = nextRow.createCell(0);
cell2.setCellValue(listValue.get(i).getId().toString());
cell.setCellStyle(cellStyle2);
cell2 = nextRow.createCell(1);
cell2.setCellValue(listValue.get(i).getDept().getName());
cell.setCellStyle(cellStyle2);
cell2 = nextRow.createCell(2);
cell2.setCellValue(listValue.get(i).getJob().getName());
cell.setCellStyle(cellStyle2);
cell2 = nextRow.createCell(3);
cell2.setCellValue(listValue.get(i).getSalary());
cell.setCellStyle(cellStyle2);
cell2 = nextRow.createCell(4);
cell2.setCellValue(listValue.get(i).getName());
cell.setCellStyle(cellStyle2);
cell2 = nextRow.createCell(5);
cell2.setCellValue(listValue.get(i).getCard_id());
cell.setCellStyle(cellStyle2);
cell2 = nextRow.createCell(6);
cell2.setCellValue(listValue.get(i).getAddress());
cell.setCellStyle(cellStyle2);
cell2 = nextRow.createCell(7);
cell2.setCellValue(listValue.get(i).getTel());
cell.setCellStyle(cellStyle2);
cell2 = nextRow.createCell(8);
cell2.setCellValue(listValue.get(i).getQQ_num());
cell.setCellStyle(cellStyle2);
cell2 = nextRow.createCell(9);
cell2.setCellValue(listValue.get(i).getEmail());
cell.setCellStyle(cellStyle2);
cell2 = nextRow.createCell(10);
cell2.setCellValue(listValue.get(i).getParty());
cell.setCellStyle(cellStyle2);
cell2 = nextRow.createCell(11);
cell2.setCellValue(format.format(listValue.get(i).getBirthday()));
cell.setCellStyle(cellStyle2);
cell2 = nextRow.createCell(12);
cell2.setCellValue(listValue.get(i).getRace());
cell.setCellStyle(cellStyle2);
cell2 = nextRow.createCell(13);
cell2.setCellValue(listValue.get(i).getEducation());
cell.setCellStyle(cellStyle2);
cell2 = nextRow.createCell(14);
cell2.setCellValue(listValue.get(i).getSpeciality());
cell.setCellStyle(cellStyle2);
cell2 = nextRow.createCell(15);
cell2.setCellValue(listValue.get(i).getHobby());
cell.setCellStyle(cellStyle2);
cell2 = nextRow.createCell(16);
cell2.setCellValue(listValue.get(i).getRemark());
cell.setCellStyle(cellStyle2);
cell2 = nextRow.createCell(17);
if (listValue.get(i).getSex()==1) {
cell2.setCellValue("男");
cell.setCellStyle(cellStyle2);
} else {
cell2.setCellValue("女");
cell.setCellStyle(cellStyle2);
}
cell2 = nextRow.createCell(18);
cell2.setCellValue(listValue.get(i).getPhone());
cell.setCellStyle(cellStyle2);
cell2 = nextRow.createCell(19);
cell2.setCellValue(format.format(listValue.get(i).getCreate_date()));
cell.setCellStyle(cellStyle2);
cell2 = nextRow.createCell(13);
cell2.setCellValue(listValue.get(i).getEducation());
cell.setCellStyle(cellStyle2);
// 设置列高,(第几列,像素)
sheet.setColumnWidth((short) i, (short) 3000);
}
// 创建一个文件
File file = new File(path);
try {
file.createNewFile();
// 将excel的内容写入到流中
FileOutputStream stream = FileUtils.openOutputStream(file);
workbook.write(stream);
stream.close();
workbook.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
ssm办公自动化OA系统 (206个子文件)
EmployServiceImpl.class 8KB
Employ.class 8KB
UserServiceImpl.class 7KB
EmployController.class 7KB
DeptController.class 6KB
JobServiceImpl.class 6KB
DeptServiceImpl.class 6KB
JobController.class 6KB
DocServiceImpl.class 6KB
MyDocController.class 6KB
MyUserController.class 4KB
User.class 4KB
MyLoginController.class 3KB
Doc.class 3KB
Dept.class 3KB
Job.class 3KB
HrmInterceptor.class 2KB
PageModel.class 2KB
HrmDownloadUtil.class 2KB
HrmConstants.class 1KB
UserService.class 1KB
LoginServiceImpl.class 845B
EmployService.class 828B
DeptService.class 736B
JobService.class 721B
DocService.class 630B
UserDao.class 523B
EmployDao.class 514B
DeptDao.class 488B
JobDao.class 473B
DocDao.class 383B
LoginService.class 274B
.classpath 665B
org.eclipse.wst.common.component 553B
org.eclipse.wst.jsdt.ui.superType.container 49B
bootstrap.css 134KB
main.css 6KB
404.gif 219KB
welcome.gif 56KB
commons-compress-1.18-tests.jar 9.32MB
commons-compress-1.18-test-sources.jar 9.11MB
poi-ooxml-schemas-4.1.0.jar 7.42MB
poi-4.1.0.jar 2.63MB
xmlbeans-3.1.0-javadoc.jar 2.49MB
xmlbeans-3.1.0.jar 2.46MB
commons-compress-1.18-javadoc.jar 2.31MB
mysql-connector-java-8.0.16.jar 2.19MB
xmlbeans-3.1.0-sources.jar 1.78MB
aspectjweaver.jar 1.76MB
poi-ooxml-4.1.0.jar 1.71MB
poi-scratchpad-4.1.0.jar 1.48MB
ehcache-core-2.6.5.jar 1.28MB
spring-context-4.1.6.RELEASE.jar 1002KB
spring-core-4.1.6.RELEASE.jar 984KB
mysql-connector-java-5.1.15-bin.jar 768KB
spring-webmvc-4.1.6.RELEASE.jar 762KB
commons-collections4-4.1.jar 734KB
spring-web-4.1.6.RELEASE.jar 702KB
mybatis-3.2.7.jar 696KB
javassist-3.17.1-GA.jar 695KB
spring-beans-4.1.6.RELEASE.jar 692KB
log4j-core-2.0-rc1.jar 686KB
commons-collections4-4.0.jar 596KB
commons-compress-1.18.jar 578KB
mchange-commons-java-0.2.3.4.jar 568KB
commons-compress-1.18-sources.jar 529KB
log4j-1.2.17.jar 478KB
commons-dbcp2-2.4.0-javadoc.jar 468KB
poi-examples-4.1.0.jar 419KB
spring-jdbc-4.1.6.RELEASE.jar 417KB
c3p0-0.9.2.1.jar 414KB
standard.jar 384KB
spring-orm-4.1.6.RELEASE.jar 367KB
spring-aop-4.1.6.RELEASE.jar 351KB
commons-pool2-2.6.2-javadoc.jar 332KB
commons-lang3-3.1.jar 308KB
cglib-2.2.2.jar 280KB
spring-expression-4.1.6.RELEASE.jar 253KB
spring-tx-4.1.6.RELEASE.jar 247KB
commons-beanutils-1.8.3.jar 227KB
commons-pool2-2.6.2-tests.jar 211KB
commons-dbcp2-2.4.0.jar 190KB
commons-dbcp2-2.4.0-sources.jar 170KB
commons-dbcp2-2.4.0-tests.jar 170KB
commons-io-2.2.jar 170KB
json-lib-2.4-jdk15.jar 155KB
commons-pool2-2.6.2-sources.jar 134KB
commons-pool2-2.6.2.jar 126KB
log4j-api-2.0-rc1.jar 113KB
commons-pool2-2.6.2-test-sources.jar 108KB
commons-dbcp2-2.4.0-test-sources.jar 108KB
ezmorph-1.0.6.jar 84KB
commons-fileupload-1.3.1.jar 67KB
commons-logging-1.1.3.jar 61KB
resolver.jar 59KB
mybatis-spring-1.2.2.jar 48KB
asm-3.3.1.jar 43KB
poi-excelant-4.1.0.jar 31KB
slf4j-api-1.7.5.jar 25KB
jstl.jar 20KB
共 206 条
- 1
- 2
- 3
资源评论
编程小海浪
- 粉丝: 29
- 资源: 36
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功