package com.matrix.system.hive.action;
|
|
import cn.hutool.core.collection.CollUtil;
|
import com.matrix.core.pojo.AjaxResult;
|
import com.matrix.core.pojo.PaginationVO;
|
import com.matrix.core.tools.DateUtil;
|
import com.matrix.core.tools.excl.ExcelSheetPO;
|
import com.matrix.core.tools.excl.ExcelVersion;
|
import com.matrix.system.common.tools.ResponseHeadUtil;
|
import com.matrix.system.constance.Dictionary;
|
import com.matrix.system.hive.action.util.QueryUtil;
|
import com.matrix.system.hive.bean.SysOrder;
|
import com.matrix.system.hive.bean.SysProjServices;
|
import com.matrix.system.hive.dao.SysStoreInfoDao;
|
import com.matrix.system.hive.pojo.StoreInOutRecordVO;
|
import com.matrix.system.hive.service.SysOrderService;
|
import com.matrix.system.hive.service.SysProjServicesService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
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.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.IOException;
|
import java.io.OutputStream;
|
import java.net.URLEncoder;
|
import java.util.*;
|
import java.util.function.Function;
|
import java.util.stream.Collectors;
|
|
|
/**
|
* 库存
|
*
|
* @author jiangyouyao
|
* @date 2016-07-20
|
*/
|
@Controller
|
@RequestMapping(value = "admin/storeInOut")
|
public class StoreInOutController extends BaseController {
|
|
@Autowired
|
SysStoreInfoDao storeInfoDao;
|
|
@Autowired
|
SysOrderService orderService;
|
|
@Autowired
|
SysProjServicesService projServicesService;
|
|
/**
|
* 列表显示
|
*/
|
@RequestMapping(value = "/showList")
|
public @ResponseBody
|
AjaxResult showList(StoreInOutRecordVO inOutRecordVO, PaginationVO pageVo) {
|
QueryUtil.setQueryLimitCom(inOutRecordVO);
|
List<StoreInOutRecordVO> dataList =storeInfoDao.findStoreInOutRecord(inOutRecordVO,pageVo);
|
|
//原始订单号赋值
|
setExtInfo(dataList);
|
|
return AjaxResult.buildSuccessInstance(dataList,storeInfoDao.findStoreInOutTotal(inOutRecordVO));
|
}
|
|
/**
|
* 填充扩展信息
|
* @param dataList
|
*/
|
private void setExtInfo(List<StoreInOutRecordVO> dataList) {
|
List<Long> serviceIds = dataList.stream().map(StoreInOutRecordVO::getServiceId).filter(e -> Objects.nonNull(e)).collect(Collectors.toList());
|
List<Long> orderIds = dataList.stream().map(StoreInOutRecordVO::getOrderId).filter(e -> Objects.nonNull(e)).collect(Collectors.toList());
|
List<SysOrder> orderList = orderService.findByIds(orderIds);
|
Map<String, SysOrder> orderMap=new HashMap<>();
|
Map<String, SysProjServices> serviceMap=new HashMap<>();
|
if(CollUtil.isNotEmpty(orderList)){
|
orderMap = orderList.stream().collect(Collectors.toMap(e->String.format("%s_%s",e.getId(),"DD"), Function.identity(), (a, b) -> a));
|
}
|
List<SysProjServices> projServicesList = projServicesService.findByIds(serviceIds);
|
if(CollUtil.isNotEmpty(projServicesList)){
|
serviceMap= projServicesList.stream().collect(Collectors.toMap(e->String.format("%s_%s",e.getId(),"FWD"), Function.identity(), (a, b) -> a));
|
}
|
if(orderMap.size()>0){
|
for (StoreInOutRecordVO e : dataList){
|
if(Objects.nonNull(e.getOrderId())){
|
SysOrder order = orderMap.get(String.format("%s_%s", e.getOrderId(), "DD"));
|
if(Objects.nonNull(order)){
|
e.setSourceOrderNo(order.getOrderNo() );
|
e.setVipName(order.getVipName());
|
}
|
}
|
if(Objects.nonNull(e.getServiceId())){
|
SysProjServices sysProjServices = serviceMap.get(String.format("%s_%s", e.getServiceId(), "FWD"));
|
if(Objects.nonNull(sysProjServices)){
|
e.setSourceOrderNo( sysProjServices.getServiceNo());
|
e.setVipName(sysProjServices.getVipName());
|
}
|
}
|
}
|
|
|
|
}
|
}
|
|
|
/**
|
* 显示当前登录人门店数据
|
*/
|
@RequestMapping(value = "/showCurrentShopList")
|
public @ResponseBody
|
AjaxResult showCurrentShopList(StoreInOutRecordVO inOutRecordVO, PaginationVO pageVo) {
|
QueryUtil.setQueryLimit(inOutRecordVO);
|
List<StoreInOutRecordVO> dataList =storeInfoDao.findStoreInOutRecord(inOutRecordVO,pageVo);
|
return AjaxResult.buildSuccessInstance(dataList,storeInfoDao.findStoreInOutTotal(inOutRecordVO));
|
}
|
|
|
@RequestMapping(value = "/exportExcel")
|
public void report(ModelMap model, HttpServletRequest request, HttpServletResponse response, StoreInOutRecordVO inOutRecordVO) throws IOException {
|
|
QueryUtil.setQueryLimitCom(inOutRecordVO);
|
|
List<ExcelSheetPO> res = new ArrayList<>();
|
ExcelSheetPO orderSheet = new ExcelSheetPO();
|
String title = "库存流向明细";
|
orderSheet.setSheetName(title);
|
orderSheet.setTitle(title);
|
String[] header = {"时间", "产品编码", "商品名称", "库存分类", "出库数量", "出库单价", "出库金额", "来源单据", "下单客户", "单据编号", "单据类型", "库存批次", "操作人", "单据备注", "门店"};
|
orderSheet.setHeaders(header);
|
|
if (getMe().getShopRole().equals(Dictionary.FLAG_NO_N)) {
|
inOutRecordVO.setShopId(getMe().getShopId());
|
}
|
List<StoreInOutRecordVO> dataList =storeInfoDao.findStoreInOutRecord(inOutRecordVO,null);
|
|
//原始订单号赋值
|
setExtInfo(dataList);
|
|
List<List<Object>> list = new ArrayList<>();
|
if (dataList.size() > 0) {
|
for (StoreInOutRecordVO item : dataList) {
|
List<Object> temp = new ArrayList<>();
|
String strDate = DateUtil.dateToString(item.getCreateTime(), DateUtil.DATE_FORMAT_MM);
|
temp.add(strDate);
|
temp.add(item.getCode());
|
temp.add(item.getName());
|
temp.add(item.getTypeName());
|
temp.add(item.getAmount());
|
temp.add(item.getGoodsPrice());
|
temp.add(item.getTotalPrice());
|
temp.add(item.getSourceOrderNo());
|
temp.add(item.getVipName());
|
temp.add(item.getOrderNo());
|
temp.add(item.getOrderType());
|
temp.add(item.getBatch());
|
temp.add(item.getUserName());
|
temp.add(item.getRemark());
|
temp.add(item.getShopName());
|
list.add(temp);
|
}
|
}
|
orderSheet.setDataList(list);
|
res.add(orderSheet);
|
response = ResponseHeadUtil.setExcelHead(response);
|
response.setHeader("Content-Disposition",
|
"attachment;filename=" + 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);
|
|
}
|
|
}
|