package com.slcf.service.impl; import java.io.IOException; import java.io.OutputStream; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletResponse; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.slcf.bean.LocDetailCondition; import com.slcf.dao.LocDetailDao; import com.slcf.pojo.LocDetailBean; import com.slcf.service.LocDetailService; import com.slcf.util.DateTimeUtil; /** * 库存明细接口实现 * @author admin * @date 2018年11月15日 */ @Service public class LocDetailServiceImpl implements LocDetailService { @Autowired LocDetailDao locDetailDao; /** * 添加 */ public int insertLocDetail(LocDetailBean locDetail) { int result=0; try { result=locDetailDao.insertLocDetail(locDetail); }catch(Exception e) { System.out.println(e.getMessage()); } return result; } // /** // * 统计数量 // */ // public int queryLocDetailCount(){ // int result = 0; // try { // result = locDetailDao.getLocDetailCount(); // }catch(Exception e) { // System.out.println(e.getMessage()); // } // return result; // } /** * 分页查询所有 */ public Map queryLocDetailList(LocDetailCondition locDetailCon) { try { Map map=new HashMap(); List list=locDetailDao.queryLocDetailList(locDetailCon); int count =locDetailDao.getLocDetailCount(locDetailCon); map.put("rows", list); map.put("total", count); return map; }catch(Exception e) { System.out.println(e.getMessage()); return null; } } // public List queryLocDetailList(int spage, int epage) { // try { // return locDetailDao.queryLocDetailList(spage, epage); // }catch(Exception e) { // System.out.println(e.getMessage()); // return null; // } // } /** * 根据id查找 */ public LocDetailBean queryLocDetailById(String loc_no,String matnr) { try { return locDetailDao.getLocDetailById(loc_no,matnr); }catch(Exception e) { System.out.println(e.getMessage()); return null; } } //更新 public int upLocDetail(LocDetailBean locDetail) { int result=0; try { result=locDetailDao.upLocDetail(locDetail); }catch(Exception e) { System.out.println(e.getMessage()); } return result; } /** * 根据id删除 */ public int delLocDetail(String loc_no,String mat_no) { int result=0; try { result=locDetailDao.delLocDetailById(loc_no,mat_no); }catch(Exception e) { System.out.println(e.getMessage()); } return result; } /** * 查询所有 * @return */ public List getLocDetailList() { try { return locDetailDao.getLocDetailList(); }catch(Exception e) { System.out.println(e.getMessage()); return null; } } /** * 查询编码库存总数量 */ public int getLocStockCount(String mat_no) { int result=0; try { result=locDetailDao.getLocStockCount(mat_no); }catch(Exception e) { System.out.println(e.getMessage()); } return result; } //导出excel public void ExportLocDetailList(LocDetailCondition locDetail, HttpServletResponse response) { //输出Excel文件 try { //HSSFWorkbook对象(excel的文档对象) HSSFWorkbook workBook=new HSSFWorkbook(); //sheet对象(excel的表单) HSSFSheet sheet=workBook.createSheet("库存明细"); //行数,参数为行索引(excel的行) // HSSFRow rowHead=sheet.createRow(0);//第一行 可以是0~65535之间的任何一个 // //创建excel的单元格,参数为列索引,可以是0~255之间的任何一个 // HSSFCell cellOne=rowHead.createCell(0); // cellOne.setCellValue("用户信息");//表头 //合并单元格CellRangeAddress构造参数依次表示起始行,截至行,起始列, 截至列 // sheet.addMergedRegion(new CellRangeAddress(0,0,0,5)); sheet.setColumnWidth(0, (int)((10 + 0.72) * 256)); sheet.setColumnWidth(1, (int)((20 + 0.72) * 256)); sheet.setColumnWidth(2, (int)((15 + 0.72) * 256)); sheet.setColumnWidth(3, (int)((15 + 0.72) * 256)); sheet.setColumnWidth(4, (int)((8 + 0.72) * 256)); sheet.setColumnWidth(5, (int)((15 + 0.72) * 256)); sheet.setColumnWidth(6, (int)((10 + 0.72) * 256)); sheet.setColumnWidth(7, (int)((8 + 0.72) * 256)); sheet.setColumnWidth(8, (int)((10 + 0.72) * 256)); sheet.setColumnWidth(9, (int)((10 + 0.72) * 256)); sheet.setColumnWidth(10, (int)((10 + 0.72) * 256)); sheet.setColumnWidth(11, (int)((10 + 0.72) * 256)); HSSFRow rows=sheet.createRow(0);//第二行 //创建单元格并设置单元格内容 rows.createCell(0).setCellValue("库位号"); rows.createCell(1).setCellValue("物料"); rows.createCell(2).setCellValue("物料描述"); rows.createCell(3).setCellValue("物料标签ID"); rows.createCell(4).setCellValue("工厂"); rows.createCell(5).setCellValue("数量"); rows.createCell(6).setCellValue("单位"); rows.createCell(7).setCellValue("托盘码"); rows.createCell(8).setCellValue("用户ID"); rows.createCell(9).setCellValue("仓库号"); rows.createCell(10).setCellValue("请求编号"); rows.createCell(11).setCellValue("行项目"); List list=locDetailDao.getLocDetailAll(locDetail); for(int i=0;i getLocDetailByLoc(String loc_no, int type) { try { if(type==1) { return locDetailDao.getLocDetlByBarcode(loc_no); }else{ return locDetailDao.getLocDetlByLoc(loc_no); } }catch(Exception e) { System.out.println(e.getMessage()); return null; } } /** * 根据库位号删除库存 */ public int delLocDetailByLocNo(String loc_no) { int result=0; try { result=locDetailDao.delLocDetailByLocNo(loc_no); }catch(Exception e) { System.out.println(e.getMessage()); } return result; } }