Commit 861c4133 authored by reedmi's avatar reedmi

Merge remote-tracking branch 'origin/custom-for-wangli' into custom-for-wangli

parents b83ff073 57bf2fd7
......@@ -3,4 +3,5 @@
.classpath
.project
.settings
/filters/dev
\ No newline at end of file
/filters/dev
upload/
package com.originspark.drp.controllers.projects.inventories;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -12,15 +14,16 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.originspark.drp.controllers.BaseController;
import com.originspark.drp.util.FileUtil;
import com.originspark.drp.util.poi.exporter.CurrentInventoriesGenerator;
import com.originspark.drp.web.models.projects.inventories.CurrentInventoryUI;
@Controller
@RequestMapping("inventories")
public class InventoryController extends BaseController {
private Logger logger = Logger.getLogger(InventoryController.class);
private Logger logger = Logger.getLogger(InventoryController.class);
@RequestMapping(value = "/current", method = RequestMethod.GET)
@ResponseBody
......@@ -82,13 +85,30 @@ public class InventoryController extends BaseController {
}*/
@RequestMapping(value = "/{type}/export", method = RequestMethod.GET)
public void exportExcel(@PathVariable String type, @RequestParam(required=true) String ids,HttpServletRequest request, HttpServletResponse response){
if(type == null || "".equals(type)) {
public void exportExcel(@PathVariable String type, @RequestParam(required = false) String ids, HttpServletResponse response) {
if (type == null || "".equals(type)) {
logger.error("库存导出错误");
return;
}
if("current".equals(type)) {
} else if("monthend".equals(type)) {
if ("current".equals(type)) {
// 实时库存的导出
List<CurrentInventoryUI> inventories = inventoryService.pagedCurrentInventories(-1, 0);
String fileName = "currentInventories_";
File file = CurrentInventoriesGenerator.generate(fileName, inventories, FileUtil.getResourcesPath(request()));
if (file != null) {
try {
response.setContentType("application/x-excel;charset=UTF-8");
response.setHeader("content-Disposition", "attachment;filename=" + file.getName());// "attachment;filename=test.xls"
InputStream is = new FileInputStream(file);
IOUtils.copyLarge(is, response.getOutputStream());
} catch (IOException ex) {
logger.error("商品导出错误");
}
}
} else if ("monthend".equals(type)) {
}
}
}
......@@ -13,6 +13,7 @@ import org.springframework.transaction.annotation.Transactional;
import com.originspark.drp.dao.BaseDAOSupport;
import com.originspark.drp.web.models.projects.inventories.CurrentInventoryUI;
@SuppressWarnings("rawtypes")
@Transactional
@Service
public class InventoryServiceBean extends BaseDAOSupport implements InventoryService {
......@@ -33,7 +34,12 @@ public class InventoryServiceBean extends BaseDAOSupport implements InventorySer
@Override
public List<CurrentInventoryUI> pagedCurrentInventories(int start, int limit) {
Query query = em.createNativeQuery(CURRENT_SUM_SQL);
List<Object[]> res = query.setFirstResult(start).setMaxResults(limit).getResultList();
List<Object[]> res;
if (start >= 0 && limit > 0) {
res = query.setFirstResult(start).setMaxResults(limit).getResultList();
} else {
res = query.getResultList();
}
List<CurrentInventoryUI> currentInventories = new ArrayList<CurrentInventoryUI>();
Object[] objAry;
......@@ -45,9 +51,9 @@ public class InventoryServiceBean extends BaseDAOSupport implements InventorySer
inventory.setUnit(objAry[2] + "");
inventory.setBrand(objAry[3] + "");
inventory.setOutcome(objAry[4] == null ? BigDecimal.ZERO : (BigDecimal) objAry[4]);
inventory.setIncount(objAry[5] == null ? 0L : ((BigDecimal)objAry[5]).longValue());
inventory.setIncount(objAry[5] == null ? 0L : ((BigDecimal) objAry[5]).longValue());
inventory.setIncome(objAry[6] == null ? BigDecimal.ZERO : (BigDecimal) objAry[6]);
inventory.setOutcount(objAry[7] == null ? 0L : ((BigDecimal)objAry[7]).longValue());
inventory.setOutcount(objAry[7] == null ? 0L : ((BigDecimal) objAry[7]).longValue());
currentInventories.add(inventory);
}
......@@ -57,7 +63,8 @@ public class InventoryServiceBean extends BaseDAOSupport implements InventorySer
@Override
public Long pagedCurrentInventoriesCount() {
Query query = em.createNativeQuery(CURRENT_COUNT);
BigInteger count = (BigInteger)query.getSingleResult();
BigInteger count = (BigInteger) query.getSingleResult();
return count.longValue();
}
}
package com.originspark.drp.util.poi.exporter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.mutable.MutableInt;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import com.originspark.drp.web.models.projects.inventories.CurrentInventoryUI;
public class CurrentInventoriesGenerator {
/**
* 生成月末盘点表的excel
*
* @param fileName 文件名:项目名称_系统名称_2014-02_月末盘点
* @param inventories
* @param resourcePath 代指目录/WebContent/resources
* @return
*/
public static File generate(String fileName, List<CurrentInventoryUI> inventories, String resourcePath) {
try {
// Open excel template
InputStream inp = new FileInputStream(FileUtils.getFile(resourcePath + "/document_templates/currentInventory.xls"));
Workbook wb = WorkbookFactory.create(inp);
Sheet mainSheet = wb.getSheetAt(0);
// This is used as a pointer
MutableInt currentRow = new MutableInt(1);
for (CurrentInventoryUI inventory : inventories) {
Row row = mainSheet.createRow(currentRow.intValue());
row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue(inventory.getName());
row.createCell(1, Cell.CELL_TYPE_STRING).setCellValue(inventory.getModel());
row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(inventory.getUnit());
row.createCell(3, Cell.CELL_TYPE_STRING).setCellValue(inventory.getIncount());
row.createCell(4, Cell.CELL_TYPE_STRING).setCellValue(inventory.getOutcount() + "");
row.createCell(5, Cell.CELL_TYPE_STRING).setCellValue(inventory.getRestcount() + "");
row.createCell(6, Cell.CELL_TYPE_STRING).setCellValue(inventory.getIncome() + "");
row.createCell(7, Cell.CELL_TYPE_STRING).setCellValue(inventory.getOutcome() + "");
row.createCell(8, Cell.CELL_TYPE_STRING).setCellValue(inventory.getProfit() + "");
currentRow.increment();
}
File dir = new File(resourcePath + "/upload");
if (!dir.exists()) {
dir.mkdir();
}
File output = File.createTempFile(fileName, ".xls", dir);
FileOutputStream fos = new FileOutputStream(output);
wb.write(fos);
fos.close();
return output;
} catch (Exception e) {
return null;
}
}
}
......@@ -23,16 +23,16 @@ public class WareGenerator {
/**
* 生成商品表的excel
*
* @param fileName
* @param wares
* @param fileName
* @param wares
* @param resourcePath 代指目录/WebContent/resources
* @return
*/
public static File generate(String fileName,List<Ware> wares,String resourcePath){
public static File generate(String fileName, List<Ware> wares, String resourcePath) {
try {
// Open excel template
InputStream inp = new FileInputStream(FileUtils.getFile( resourcePath + "/document_templates/ware.xls"));
InputStream inp = new FileInputStream(FileUtils.getFile(resourcePath + "/document_templates/ware.xls"));
Workbook wb = WorkbookFactory.create(inp);
Sheet mainSheet = wb.getSheetAt(0);
......@@ -47,11 +47,14 @@ public class WareGenerator {
row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(ware.getModel());
row.createCell(3, Cell.CELL_TYPE_STRING).setCellValue(ware.getUnit());
Vendor vendor = ware.getVendor();
row.createCell(4, Cell.CELL_TYPE_STRING).setCellValue(vendor==null?"":vendor.getName());
row.createCell(4, Cell.CELL_TYPE_STRING).setCellValue(vendor == null ? "" : vendor.getName());
currentRow.increment();
}
File output = File.createTempFile(fileName, ".xls", new File(resourcePath + "/upload"));
File dir = new File(resourcePath + "/upload");
if (!dir.exists()) {
dir.mkdir();
}
File output = File.createTempFile(fileName, ".xls", dir);
FileOutputStream fos = new FileOutputStream(output);
wb.write(fos);
fos.close();
......
......@@ -10,15 +10,14 @@ Ext.define('drp.app.controller.projects.inventories.CurrentInventoryController',
}
},
'currentinventoryview button[action=exportCurrentInventoryExcel]' : {
click : function(btn){
var formonth = btn.up('monthendinventoryview').down('monthfield').getSubmitValue();
document.location = "project/"+projectId+"/inventories/current/export?formonth="+formonth;
click : function(btn) {
document.location = "inventories/current/export";
}
}
});
},
views : ['drp.app.view.projects.inventories.CurrentInventoryView'],
models :['drp.app.model.projects.inventories.CurrentInventoryModel'],
models : ['drp.app.model.projects.inventories.CurrentInventoryModel'],
stores : ['drp.app.store.projects.inventories.CurrentInventoryStore']
});
\ No newline at end of file
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