| package com.matrix.system.hive.action; | 
|   | 
| import com.matrix.core.constance.MatrixConstance; | 
| import com.matrix.core.pojo.AjaxResult; | 
| import com.matrix.core.pojo.PaginationVO; | 
| import com.matrix.core.tools.DateUtil; | 
| import com.matrix.core.tools.StringUtils; | 
| import com.matrix.core.tools.WebUtil; | 
| import com.matrix.core.tools.excl.ExcelSheetPO; | 
| import com.matrix.core.tools.excl.ExcelVersion; | 
| import com.matrix.system.common.bean.SysUsers; | 
| import com.matrix.system.common.tools.ResponseHeadUtil; | 
| import com.matrix.system.constance.Dictionary; | 
| import com.matrix.system.hive.bean.ShoppingGoods; | 
| import com.matrix.system.hive.bean.SysStoreInfo; | 
| import com.matrix.system.hive.dao.SysStoreInfoDao; | 
| import com.matrix.system.hive.service.SysStoreInfoService; | 
| import org.apache.poi.ss.formula.functions.T; | 
| import org.springframework.stereotype.Controller; | 
| import org.springframework.ui.ModelMap; | 
| import org.springframework.web.bind.annotation.RequestMapping; | 
| import org.springframework.web.bind.annotation.ResponseBody; | 
|   | 
| import javax.annotation.Resource; | 
| import javax.servlet.http.HttpServletRequest; | 
| import javax.servlet.http.HttpServletResponse; | 
| import java.io.IOException; | 
| import java.io.OutputStream; | 
| import java.util.ArrayList; | 
| import java.util.List; | 
|   | 
|   | 
| /** | 
|  * 库存 | 
|  * | 
|  * @author jiangyouyao | 
|  * @date 2016-07-20 | 
|  */ | 
| @Controller | 
| @RequestMapping(value = "admin/store") | 
| public class StoreController extends BaseController { | 
|     @Resource | 
|     private SysStoreInfoService currentService; | 
|   | 
|     @Resource | 
|     private SysStoreInfoDao sysStoreInfoDao; | 
|   | 
|   | 
|     //记录编辑前的值Before_Edit_Value | 
|     public static final String BEV = "Store_BEV"; | 
|   | 
|     public static final String fnCode = "store"; | 
|     public static final String fnCode1 = "store1"; | 
|     public static final String fnCode2 = "store2"; | 
|     public static final String search = ":search"; | 
|     public static final String edit = ":edit"; | 
|     public static final String del = ":del"; | 
|     public static final String add = ":add"; | 
|     public static final String excelOut = ":excelOut"; | 
|   | 
|   | 
|     /** | 
|      * 列表显示 | 
|      */ | 
|     @RequestMapping(value = "/showList") | 
|     public @ResponseBody | 
|     AjaxResult showList(SysStoreInfo sysStoreInfo, PaginationVO pageVo) { | 
|         SysUsers users = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|         sysStoreInfo.setShopId(users.getShopId()); | 
|         sysStoreInfo.setCompanyId(users.getCompanyId()); | 
|         if (StringUtils.isNotBlank(sysStoreInfo.getName())) { | 
|             ShoppingGoods goods = new ShoppingGoods(); | 
|             goods.setName(sysStoreInfo.getName()); | 
|             sysStoreInfo.setGoods(goods); | 
|         } | 
|         List<SysStoreInfo> dataList = currentService.findInPage(sysStoreInfo, pageVo); | 
|         AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS,  dataList, currentService.findTotal(sysStoreInfo)); | 
|         return result; | 
|     } | 
|   | 
|     /** | 
|      * 按产品批次显示 | 
|      * @param sysStoreInfo | 
|      * @param pageVo | 
|      * @return | 
|      */ | 
|     @RequestMapping(value = "/showCountList") | 
|     public @ResponseBody | 
|     AjaxResult showCountList(SysStoreInfo sysStoreInfo, PaginationVO pageVo) { | 
|         SysUsers users = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|         sysStoreInfo.setShopId(users.getShopId()); | 
|         sysStoreInfo.setCompanyId(users.getCompanyId()); | 
|   | 
|         List<SysStoreInfo> dataList = sysStoreInfoDao.selectCountInPage(sysStoreInfo, pageVo); | 
|         AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS,  dataList, sysStoreInfoDao.selectCountTotalRecord(sysStoreInfo)); | 
|         return result; | 
|     } | 
|   | 
|   | 
|   | 
|     /** | 
|      * 新增或修改页面 | 
|      */ | 
|     @RequestMapping(value = "/addOrModify") | 
|     public @ResponseBody | 
|     AjaxResult addOrModify(SysStoreInfo sysStoreInfo) { | 
|   | 
|         if (!getMe().getShopRole().equals(Dictionary.FLAG_YES_Y)) { | 
|             sysStoreInfo.setStoreId(getMe().getShopId()); | 
|         } | 
|   | 
|         if (sysStoreInfo.getId() != null) { | 
|   | 
|             return modify(currentService, sysStoreInfo, "库存"); | 
|         } else { | 
|   | 
|             return add(currentService, sysStoreInfo, "库存"); | 
|         } | 
|     } | 
|   | 
|     /** | 
|      * 进入修改界面 | 
|      */ | 
|     @RequestMapping(value = "/editForm") | 
|     public String editForm(Long id) { | 
|         SysStoreInfo sysStoreInfo; | 
|         if (id != null) { | 
|             sysStoreInfo = currentService.findById(id); | 
|             WebUtil.getRequest().setAttribute("obj", sysStoreInfo); | 
|         } | 
|         return "admin/hive/products/goods-form"; | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 删除 | 
|      */ | 
|     @RequestMapping(value = "/del") | 
|     public @ResponseBody | 
|     AjaxResult del(String keys) { | 
|   | 
|         return remove(currentService, keys); | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 库存按批次导出 | 
|      */ | 
|     @RequestMapping(value = "/storeExportExcel") | 
|     public void storeExportExcel(SysStoreInfo sysStoreInfo, HttpServletResponse response) throws IOException { | 
|         SysUsers users = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|         sysStoreInfo.setShopId(users.getShopId()); | 
|         sysStoreInfo.setCompanyId(users.getCompanyId()); | 
|         if (StringUtils.isNotBlank(sysStoreInfo.getName())) { | 
|             ShoppingGoods goods = new ShoppingGoods(); | 
|             goods.setName(sysStoreInfo.getName()); | 
|             sysStoreInfo.setGoods(goods); | 
|         } | 
|         doStoreInfoExportExcel(response,sysStoreInfo); | 
|     } | 
|   | 
|     /** | 
|      * 库存按批次导出-不区分门店 | 
|      */ | 
|     @RequestMapping(value = "/erpStoreExportExcel") | 
|     public void erpStoreExportExcel(SysStoreInfo sysStoreInfo, HttpServletResponse response) throws IOException { | 
|         SysUsers users = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|         sysStoreInfo.setCompanyId(users.getCompanyId()); | 
|         if (StringUtils.isNotBlank(sysStoreInfo.getName())) { | 
|             ShoppingGoods goods = new ShoppingGoods(); | 
|             goods.setName(sysStoreInfo.getName()); | 
|             sysStoreInfo.setGoods(goods); | 
|         } | 
|         doStoreInfoExportExcel(response,sysStoreInfo); | 
|     } | 
|   | 
|   | 
|   | 
|   | 
|   | 
|   | 
|     /** | 
|      * 按产品维度导出库存 | 
|      */ | 
|     @RequestMapping(value = "/goodsCountExportExcel") | 
|     public void goodsCountExportExcel(ModelMap model, HttpServletRequest request, HttpServletResponse response, | 
|                        SysStoreInfo sysStoreInfo) throws IOException { | 
|         SysUsers users = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|         sysStoreInfo.setShopId(users.getShopId()); | 
|         sysStoreInfo.setCompanyId(users.getCompanyId()); | 
|         doGoodsCountExportExcel(response, sysStoreInfo); | 
|         return; | 
|     } | 
|   | 
|     /** | 
|      * 按产品维度导出库存不区分门店 | 
|      */ | 
|     @RequestMapping(value = "/erpGoodsCountExportExcel") | 
|     public void erpGoodsCountExportExcel(ModelMap model, HttpServletRequest request, HttpServletResponse response, | 
|                        SysStoreInfo sysStoreInfo) throws IOException { | 
|         SysUsers users = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|         sysStoreInfo.setCompanyId(users.getCompanyId()); | 
|         doGoodsCountExportExcel(response, sysStoreInfo); | 
|         return; | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 产品维度库存导出 | 
|      */ | 
|     private void doGoodsCountExportExcel(HttpServletResponse response, SysStoreInfo sysStoreInfo) throws IOException { | 
|         List<ExcelSheetPO> res = new ArrayList<>(); | 
|         ExcelSheetPO orderSheet = new ExcelSheetPO(); | 
|         String title = "库存明细"; | 
|         orderSheet.setSheetName(title); | 
|         orderSheet.setTitle(title); | 
|         String[] header = {"产品名称", "产品编号", "库存量","入库平均价", "产品单位", "库存预警值", "所属仓库",  "分类"}; | 
|         orderSheet.setHeaders(header); | 
|         List<SysStoreInfo> dataList = sysStoreInfoDao.selectCountInPage(sysStoreInfo, null); | 
|   | 
|   | 
|         List<List<Object>> list = new ArrayList<>(); | 
|         if (dataList.size() > 0) { | 
|             for (SysStoreInfo item : dataList) { | 
|                 List<Object> temp = new ArrayList<>(); | 
|                 ShoppingGoods getGoods = item.getGoods(); | 
|                 if(getGoods!=null){ | 
|                     temp.add(getGoods.getName()); | 
|                     temp.add(getGoods.getGoodsNo()); | 
|                     temp.add(item.getStoreTotal()); | 
|                     temp.add(item.getGoodsPrice()); | 
|                     temp.add(getGoods.getUnit()); | 
|                     temp.add(getGoods.getAlarmNum()); | 
|                     temp.add(getGoods.getName()); | 
|                     temp.add(item.getStoreName()); | 
|                     list.add(temp); | 
|                 } | 
|             } | 
|         } | 
|         orderSheet.setDataList(list); | 
|         res.add(orderSheet); | 
|         response = ResponseHeadUtil.setExcelHead(response); | 
|         response.setHeader("Content-Disposition", | 
|                 "attachment;filename=" + java.net.URLEncoder.encode(title + DateUtil.getTimeMark() + ".xlsx".trim(), "UTF-8")); | 
|         OutputStream os = response.getOutputStream(); | 
|         com.matrix.core.tools.excl.ExcelUtil.createWorkbookAtOutStream(ExcelVersion.V2007, res, os, true); | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 库存明细导出 | 
|      */ | 
|     private void doStoreInfoExportExcel(HttpServletResponse response, SysStoreInfo sysStoreInfo) throws IOException { | 
|         List<ExcelSheetPO> res = new ArrayList<>(); | 
|         ExcelSheetPO orderSheet = new ExcelSheetPO(); | 
|         String title = "库存明批次汇总"; | 
|         orderSheet.setSheetName(title); | 
|         orderSheet.setTitle(title); | 
|         String[] header = {"产品名称", "产品编号", "批次", "库存量","入库单价", "产品单位", "库存预警值", "所属仓库",  "分类"}; | 
|         orderSheet.setHeaders(header); | 
|         List<SysStoreInfo> dataList = currentService.findInPage(sysStoreInfo, null); | 
|   | 
|   | 
|         List<List<Object>> list = new ArrayList<>(); | 
|         if (dataList.size() > 0) { | 
|             for (SysStoreInfo item : dataList) { | 
|                 List<Object> temp = new ArrayList<>(); | 
|                 ShoppingGoods getGoods = item.getGoods(); | 
|                 if(getGoods!=null){ | 
|                     temp.add(getGoods.getName()); | 
|                     temp.add(getGoods.getGoodsNo()); | 
|                     temp.add(item.getBatch()); | 
|                     temp.add(item.getStoreTotal()); | 
|                     temp.add(item.getGoodsPrice()); | 
|                     temp.add(getGoods.getUnit()); | 
|                     temp.add(getGoods.getAlarmNum()); | 
|                     temp.add(getGoods.getName()); | 
|                     temp.add(item.getStoreName()); | 
|                     list.add(temp); | 
|                 } | 
|             } | 
|         } | 
|         orderSheet.setDataList(list); | 
|         res.add(orderSheet); | 
|         response = ResponseHeadUtil.setExcelHead(response); | 
|         response.setHeader("Content-Disposition", | 
|                 "attachment;filename=" + java.net.URLEncoder.encode(title + DateUtil.getTimeMark() + ".xlsx".trim(), "UTF-8")); | 
|         OutputStream os = response.getOutputStream(); | 
|         com.matrix.core.tools.excl.ExcelUtil.createWorkbookAtOutStream(ExcelVersion.V2007, res, os, true); | 
|     } | 
|   | 
| } |