| | |
| | | |
| | | import com.matrix.core.constance.MatrixConstance; |
| | | import com.matrix.core.pojo.AjaxResult; |
| | | import com.matrix.core.tools.DateUtil; |
| | | 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.constance.AppConstance; |
| | | import com.matrix.system.common.tools.DataAuthUtil; |
| | | import com.matrix.system.common.tools.ResponseHeadUtil; |
| | | import com.matrix.system.hive.dao.SysOrderItemDao; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Controller; |
| | |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.OutputStream; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | public @ResponseBody |
| | | AjaxResult showList( @RequestParam Map<String , Object> param) { |
| | | SysUsers sysUsers = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); |
| | | if(!AppConstance.ZONGDIAN.equals(sysUsers.getShopName())){ |
| | | |
| | | if(!DataAuthUtil.hasAllShopAuth()){ |
| | | param.put("shopId",sysUsers.getShopId()); |
| | | } |
| | | return AjaxResult.buildSuccessInstance(orderItemDao.selectItemDetail(param), |
| | | orderItemDao.selectItemDetailTotal(param)); |
| | | } |
| | | @RequestMapping(value = "/exportShowList") |
| | | public void exportShowList(@RequestParam Map<String, Object> param, HttpServletResponse response) throws Exception { |
| | | SysUsers sysUsers = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); |
| | | String title = "产品销售明细统计"; |
| | | String[] header = {"门店", "销售日期", "订单号", "商品名称", "分类", "客户名", "购买数量", "单价", "健康顾问", "支付方式", "状态"}; |
| | | String[] column = {"SHOP_NAME", "pay_time", "ORDER_NO", "goodsName", "cateName", "VIP_NAME", "COUNT", "ZK_PRICE", "su_name", "pay_method", "status"}; |
| | | |
| | | if(!DataAuthUtil.hasAllShopAuth()){ |
| | | param.put("shopId", sysUsers.getShopId()); |
| | | } |
| | | List<Map<String, Object>> dataList = orderItemDao.selectItemDetail(param); |
| | | exportExcel(title, header,column, dataList, response); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 产品销售明细统计 |
| | |
| | | public @ResponseBody |
| | | AjaxResult summaryItemDetail( @RequestParam Map<String , Object> param) { |
| | | SysUsers sysUsers = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); |
| | | if(!AppConstance.ZONGDIAN.equals(sysUsers.getShopName())){ |
| | | |
| | | if(!DataAuthUtil.hasAllShopAuth()){ |
| | | param.put("shopId",sysUsers.getShopId()); |
| | | } |
| | | return AjaxResult.buildSuccessInstance(orderItemDao.summaryItemDetail(param), |
| | | orderItemDao.summaryItemDetailTotal(param)); |
| | | } |
| | | |
| | | @RequestMapping(value = "/exportSummaryItemDetail") |
| | | public void exportSummaryItemDetail(@RequestParam Map<String, Object> param, HttpServletResponse response) throws Exception { |
| | | SysUsers sysUsers = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); |
| | | String title = "产品销售明细统计"; |
| | | String[] header = {"门店", "商品名称", "分类", "销售数量", "销售总额"}; |
| | | String[] column = {"SHOP_NAME", "goodsName", "cateName", "COUNT", "ZK_PRICE"}; |
| | | |
| | | if(!DataAuthUtil.hasAllShopAuth()){ |
| | | param.put("shopId", sysUsers.getShopId()); |
| | | } |
| | | List<Map<String, Object>> dataList = orderItemDao.summaryItemDetail(param); |
| | | exportExcel(title, header,column, dataList, response); |
| | | } |
| | | |
| | | |
| | | public static void exportExcel(String title, String[] header,String[] column, List<Map<String, Object>> dataList, HttpServletResponse response) throws Exception { |
| | | //这里是从数据库里查数据并组装成我们想要的数据结构的过程 |
| | | List<ExcelSheetPO> res = new ArrayList<>(); |
| | | ExcelSheetPO orderSheet = new ExcelSheetPO(); |
| | | orderSheet.setSheetName(title); |
| | | orderSheet.setTitle(title); |
| | | orderSheet.setHeaders(header); |
| | | List<List<Object>> list = new ArrayList<>(); |
| | | if (dataList.size() > 0) { |
| | | for (Map<String, Object> item : dataList) { |
| | | List<Object> temp = new ArrayList<>(); |
| | | Arrays.stream(column).forEach(key-> temp.add(item.get(key))); |
| | | 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); |
| | | } |
| | | |
| | | |
| | | } |