姜友瑶
2022-08-09 c423224dbe37ea69c1a36c696f85490343e68c4c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
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);
 
    }
 
}