code --customercloseController.java

package com.ningpai.customerclose.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.ningpai.customerclose.service.CustomerCloseService;
import com.ningpai.customerclose.vo.CustomerClose;
import com.ningpai.base.form.ResultMsg;
import com.ningpai.util.PageBean;
import com.ningpai.logger.util.OperaLogUtil;

import java.io.IOException;
import java.io.OutputStream;
import java.util.List;

/**
* 审核记录Controller_请求接收器
* @author gedan
* @version 1.0 2018-12-29
*/
@Controller("CustomerCloseController")
public class CustomerCloseController{
@Resource(name = "CustomerCloseService")
private CustomerCloseService customerCloseService;

/**
* 跳转审核记录分页列表页面
* @author gedan
* @version 1.0 2018-12-29
*/
@RequestMapping(value="/gotoCustomerClosePage",method={RequestMethod.GET,RequestMethod.POST})
public ModelAndView gotoCustomerClosePage(HttpServletRequest request, HttpServletResponse response, CustomerClose entity) {
PageBean pageBean = customerCloseService.selectCustomerCloseForPage(entity);
pageBean.setUrl("gotoCustomerClosePage.htm");
ModelAndView mv = new ModelAndView("jsp/customerclose/customerclose_page", "pageBean", pageBean);
return mv;
}

/**
* 查询单个审核记录详情,填充修改弹框显示
* @author gedan
* @version 1.0 2018-12-29
*/
@RequestMapping(value="/selectCustomerCloseForOne",method={RequestMethod.GET,RequestMethod.POST})
@ResponseBody
public CustomerClose selectCustomerCloseForOne(HttpServletRequest request, HttpServletResponse response, CustomerClose entity) {
return customerCloseService.selectCustomerCloseForOne(entity);
}

/**
* 添加审核记录
* @author gedan
* @version 1.0 2018-12-29
*/
@RequestMapping(value="/insertCustomerClose",method=RequestMethod.POST)
@ResponseBody
public ResultMsg insertCustomerClose(HttpServletRequest request,HttpServletResponse response,CustomerClose entity) {
ResultMsg rm = new ResultMsg();
try {
customerCloseService.insertCustomerClose(entity);
OperaLogUtil.addOperaLog(request, "添加审核记录", "审核记录标识:" + entity.getCustomerId());
rm.setCode(ResultMsg.SUCCESS);
rm.setNextUrl("gotoCustomerClosePage.htm");
} catch (Exception e) {
e.printStackTrace();
}
return rm;
}

/**
* 修改审核记录
* @author gedan
* @version 1.0 2018-12-29
*/
@RequestMapping(value="/updateCustomerClose",method=RequestMethod.POST)
@ResponseBody
public ResultMsg updateCustomerClose(HttpServletRequest request,HttpServletResponse response,CustomerClose entity) {
ResultMsg rm = new ResultMsg();
try {
customerCloseService.updateCustomerClose(entity);
OperaLogUtil.addOperaLog(request, "修改审核记录", "审核记录标识:" + entity.getCustomerId());
rm.setCode(ResultMsg.SUCCESS);
rm.setNextUrl("gotoCustomerClosePage.htm");
} catch (Exception e) {
e.printStackTrace();
}
return rm;
}

/**
* 根据参数删除审核记录
* @author gedan
* @version 1.0 2018-12-29
*/
@RequestMapping(value="/deleteCustomerClose",method=RequestMethod.POST)
@ResponseBody
public ResultMsg deleteCustomerClose(HttpServletRequest request,HttpServletResponse response,@RequestBody List<java.math.BigDecimal> ids) {
ResultMsg rm = new ResultMsg();
try {
customerCloseService.deleteCustomerClose(ids);
OperaLogUtil.addOperaLog(request, "删除审核记录", "审核记录标识:" + ids.toString());
rm.setCode(ResultMsg.SUCCESS);
rm.setNextUrl("gotoCustomerClosePage.htm");
} catch (Exception e) {
e.printStackTrace();
}
return rm;
}

/**
* 导出审核记录信息
* @author gedan
* @version 1.0 2018-12-29
*/
@RequestMapping(value="/exportCustomerCloseExcel",method={RequestMethod.GET,RequestMethod.POST})
public void exportCustomerCloseExcel(HttpServletRequest request, HttpServletResponse response, CustomerClose entity) {
List<CustomerClose> list = customerCloseService.selectCustomerCloseForList(entity);
// 第一步,创建一个webbook,对应一个Excel文件
HSSFWorkbook wb = new HSSFWorkbook();
// 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet
HSSFSheet sheet = wb.createSheet("审核记录信息");
// 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
HSSFRow row = sheet.createRow((int) 0);
// 第四步,创建单元格,并设置值表头 设置表头居中
HSSFCellStyle style = wb.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
// 设置宽度
sheet.setColumnWidth(0, 5000);
sheet.setColumnWidth(1, 5000);
sheet.setColumnWidth(2, 5000);
sheet.setColumnWidth(3, 5000);
sheet.setColumnWidth(4, 5000);
sheet.setColumnWidth(5, 5000);
sheet.setColumnWidth(6, 5000);
sheet.setColumnWidth(7, 5000);
sheet.setColumnWidth(8, 5000);
sheet.setColumnWidth(9, 5000);
sheet.setColumnWidth(10, 5000);
sheet.setColumnWidth(11, 5000);
sheet.setColumnWidth(12, 5000);
sheet.setColumnWidth(13, 5000);
sheet.setColumnWidth(14, 5000);
sheet.setColumnWidth(15, 5000);
sheet.setColumnWidth(16, 5000);
sheet.setColumnWidth(17, 5000);
sheet.setColumnWidth(18, 5000);
sheet.setColumnWidth(19, 5000);
sheet.setColumnWidth(20, 5000);
sheet.setColumnWidth(21, 5000);
sheet.setColumnWidth(22, 5000);
sheet.setColumnWidth(23, 5000);
sheet.setColumnWidth(24, 5000);
sheet.setColumnWidth(25, 5000);
sheet.setColumnWidth(26, 5000);
sheet.setColumnWidth(27, 5000);
sheet.setColumnWidth(28, 5000);
sheet.setColumnWidth(29, 5000);
sheet.setColumnWidth(30, 5000);
sheet.setColumnWidth(31, 5000);
sheet.setColumnWidth(32, 5000);

// 设置列头信息
HSSFCell cell = null;
cell = row.createCell(0);
cell.setCellValue("customerUsername");
cell.setCellStyle(style);
cell = row.createCell(1);
cell.setCellValue("customerPassword");
cell.setCellStyle(style);
cell = row.createCell(2);
cell.setCellValue("customerNickname");
cell.setCellStyle(style);
cell = row.createCell(3);
cell.setCellValue("isMobile");
cell.setCellStyle(style);
cell = row.createCell(4);
cell.setCellValue("isEmail");
cell.setCellStyle(style);
cell = row.createCell(5);
cell.setCellValue("isFlag");
cell.setCellStyle(style);
cell = row.createCell(6);
cell.setCellValue("loginIp");
cell.setCellStyle(style);
cell = row.createCell(7);
cell.setCellValue("loginTime");
cell.setCellStyle(style);
cell = row.createCell(8);
cell.setCellValue("createTime");
cell.setCellStyle(style);
cell = row.createCell(9);
cell.setCellValue("modifiedTime");
cell.setCellStyle(style);
cell = row.createCell(10);
cell.setCellValue("delFlag");
cell.setCellStyle(style);
cell = row.createCell(11);
cell.setCellValue("delTime");
cell.setCellStyle(style);
cell = row.createCell(12);
cell.setCellValue("customerImg");
cell.setCellStyle(style);
cell = row.createCell(13);
cell.setCellValue("captcha");
cell.setCellStyle(style);
cell = row.createCell(14);
cell.setCellValue("aeadTime");
cell.setCellStyle(style);
cell = row.createCell(15);
cell.setCellValue("pwdCaptcha");
cell.setCellStyle(style);
cell = row.createCell(16);
cell.setCellValue("pwdAeadTime");
cell.setCellStyle(style);
cell = row.createCell(17);
cell.setCellValue("thirdId");
cell.setCellStyle(style);
cell = row.createCell(18);
cell.setCellValue("isSeller");
cell.setCellStyle(style);
cell = row.createCell(19);
cell.setCellValue("isTempCust");
cell.setCellStyle(style);
cell = row.createCell(20);
cell.setCellValue("loginKey");
cell.setCellStyle(style);
cell = row.createCell(21);
cell.setCellValue("isSiteManager");
cell.setCellStyle(style);
cell = row.createCell(22);
cell.setCellValue("loginErrorCount");
cell.setCellStyle(style);
cell = row.createCell(23);
cell.setCellValue("loginLockTime");
cell.setCellStyle(style);
cell = row.createCell(24);
cell.setCellValue("userUniqueCode");
cell.setCellStyle(style);
cell = row.createCell(25);
cell.setCellValue("userSaltVal");
cell.setCellStyle(style);
cell = row.createCell(26);
cell.setCellValue("pcLoginTime");
cell.setCellStyle(style);
cell = row.createCell(27);
cell.setCellValue("verifiedId");
cell.setCellStyle(style);
cell = row.createCell(28);
cell.setCellValue("orderRebateFlag");
cell.setCellStyle(style);
cell = row.createCell(29);
cell.setCellValue("sort");
cell.setCellStyle(style);
cell = row.createCell(30);
cell.setCellValue("version");
cell.setCellStyle(style);
cell = row.createCell(31);
cell.setCellValue("releaseTime");
cell.setCellStyle(style);
cell = row.createCell(32);
cell.setCellValue("os");
cell.setCellStyle(style);

// 第五步,写入实体数据 实际应用中这些数据从数据库得到,
for (int i = 0; i < list.size(); i++) {
row = sheet.createRow(i+1);
CustomerClose cus = list.get(i);

//创建单元格,并设置值
if (cus.getCustomerUsername() != null) {
row.createCell(0).setCellValue(cus.getCustomerUsername());
}
if (cus.getCustomerPassword() != null) {
row.createCell(1).setCellValue(cus.getCustomerPassword());
}
if (cus.getCustomerNickname() != null) {
row.createCell(2).setCellValue(cus.getCustomerNickname());
}
if (cus.getIsMobile() != null) {
row.createCell(3).setCellValue(cus.getIsMobile());
}
if (cus.getIsEmail() != null) {
row.createCell(4).setCellValue(cus.getIsEmail());
}
if (cus.getIsFlag() != null) {
row.createCell(5).setCellValue(cus.getIsFlag());
}
if (cus.getLoginIp() != null) {
row.createCell(6).setCellValue(cus.getLoginIp());
}
if (cus.getLoginTimeStr() != null) {
row.createCell(7).setCellValue(cus.getLoginTimeStr());
}
if (cus.getCreateTimeStr() != null) {
row.createCell(8).setCellValue(cus.getCreateTimeStr());
}
if (cus.getModifiedTimeStr() != null) {
row.createCell(9).setCellValue(cus.getModifiedTimeStr());
}
if (cus.getDelFlag() != null) {
row.createCell(10).setCellValue(cus.getDelFlag());
}
if (cus.getDelTimeStr() != null) {
row.createCell(11).setCellValue(cus.getDelTimeStr());
}
if (cus.getCustomerImg() != null) {
row.createCell(12).setCellValue(cus.getCustomerImg());
}
if (cus.getCaptcha() != null) {
row.createCell(13).setCellValue(cus.getCaptcha());
}
if (cus.getAeadTimeStr() != null) {
row.createCell(14).setCellValue(cus.getAeadTimeStr());
}
if (cus.getPwdCaptcha() != null) {
row.createCell(15).setCellValue(cus.getPwdCaptcha());
}
if (cus.getPwdAeadTimeStr() != null) {
row.createCell(16).setCellValue(cus.getPwdAeadTimeStr());
}
if (cus.getThirdId() != null) {
row.createCell(17).setCellValue(cus.getThirdId());
}
if (cus.getIsSeller() != null) {
row.createCell(18).setCellValue(cus.getIsSeller());
}
if (cus.getIsTempCust() != null) {
row.createCell(19).setCellValue(cus.getIsTempCust());
}
if (cus.getLoginKey() != null) {
row.createCell(20).setCellValue(cus.getLoginKey());
}
if (cus.getIsSiteManager() != null) {
row.createCell(21).setCellValue(cus.getIsSiteManager());
}
if (cus.getLoginErrorCount() != null) {
row.createCell(22).setCellValue(cus.getLoginErrorCount());
}
if (cus.getLoginLockTimeStr() != null) {
row.createCell(23).setCellValue(cus.getLoginLockTimeStr());
}
if (cus.getUserUniqueCode() != null) {
row.createCell(24).setCellValue(cus.getUserUniqueCode());
}
if (cus.getUserSaltVal() != null) {
row.createCell(25).setCellValue(cus.getUserSaltVal());
}
if (cus.getPcLoginTimeStr() != null) {
row.createCell(26).setCellValue(cus.getPcLoginTimeStr());
}
if (cus.getVerifiedId() != null) {
row.createCell(27).setCellValue(cus.getVerifiedId());
}
if (cus.getOrderRebateFlag() != null) {
row.createCell(28).setCellValue(cus.getOrderRebateFlag());
}
if (cus.getSort() != null) {
row.createCell(29).setCellValue(cus.getSort());
}
if (cus.getVersion() != null) {
row.createCell(30).setCellValue(cus.getVersion());
}
if (cus.getReleaseTime() != null) {
row.createCell(31).setCellValue(cus.getReleaseTime());
}
if (cus.getOs() != null) {
row.createCell(32).setCellValue(cus.getOs());
}
}
// 第六步,将文件存到指定位置
String filename = String.valueOf(System.currentTimeMillis()).concat(".xls");
// 设置下载时客户端Excel的名称
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition", "attachment;filename=" + filename);
OutputStream ouputStream;
try {
ouputStream = response.getOutputStream();
wb.write(ouputStream);
ouputStream.flush();
ouputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}

}

猜你喜欢

转载自www.cnblogs.com/danJuly/p/10195254.html