935090232@qq.com
2021-03-19 81a3369395a7cccceb7cd36f5238cc6fe2aa88e5
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
 
package com.matrix.system.hiveErp.action;
 
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.tools.ResponseHeadUtil;
import com.matrix.system.constance.Dictionary;
import com.matrix.system.hive.action.BaseController;
import com.matrix.system.hive.action.util.QueryUtil;
import com.matrix.system.hive.bean.MoneyCardAssemble;
import com.matrix.system.hive.bean.ShoppingGoods;
import com.matrix.system.hive.bean.ShoppingGoodsAssemble;
import com.matrix.system.hive.dao.ShoppingGoodsAssembleDao;
import com.matrix.system.hive.dao.ShoppingGoodsDao;
import com.matrix.system.hive.service.MoneyCardAssembleService;
import com.matrix.system.hive.service.ShoppingGoodsService;
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.annotation.Resource;
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.ArrayList;
import java.util.List;
 
 
/**
 * 商品
 *
 * @author jiangyouyao
 * @date 2016-8-22
 */
@Controller
@RequestMapping(value = "admin/erpShoppinggoods")
public class ErpShoppingGoodsController extends BaseController {
    @Resource
    private ShoppingGoodsService shoppingGoodsService;
 
    @Resource
    private MoneyCardAssembleService cardAssembleService;
 
    @Autowired
    private ShoppingGoodsAssembleDao shoppingGoodsAssembleDao;
 
 
    //记录编辑前的值Before_Edit_Value
    public static final String BEV = "shoppinggoods_BEV";
 
 
    @Autowired
    private ShoppingGoodsDao shoppingGoodsDao;
 
    /**
     * 列表显示
     */
    @RequestMapping(value = "/showList")
    public @ResponseBody
    AjaxResult showList(ShoppingGoods shoppingGoods, PaginationVO pageVo) {
        if(StringUtils.isBlank(pageVo.getSort())){
            pageVo.setOrder("desc");
            pageVo.setSort("createTime");
        }
        QueryUtil.setQueryLimitCom(shoppingGoods);
        shoppingGoods.setIsDel(ShoppingGoods.NORMAL);
        List<ShoppingGoods> dataList = shoppingGoodsService.findInPage(shoppingGoods, pageVo);
        AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS,  dataList, shoppingGoodsService.findTotal(shoppingGoods));
        return result;
    }
 
    /**
     * 进入线下产品修改界面
     */
    @RequestMapping(value = "/editFormUderline")
    public String editFormUderline(Long id) {
        ShoppingGoods shoppingGoods;
        if (id != null) {
            WebUtil.getRequest().setAttribute("isUpdate", shoppingGoodsService.checkIsUpdate(id));
            shoppingGoods = shoppingGoodsService.findById(id);
 
            //查询的绑定关系
            if (Dictionary.SHOPPING_GOODS_TYPE_JJCP.equals(shoppingGoods.getGoodType())) {
                List<ShoppingGoodsAssemble> assembleList = shoppingGoodsAssembleDao.selectGoodsByShoppingGoodsId(shoppingGoods.getId());
                shoppingGoods.setAssembleGoods(assembleList);
            } else if (Dictionary.SHOPPING_GOODS_TYPE_XM.equals(shoppingGoods.getGoodType())) {
                List<ShoppingGoodsAssemble> assembleList = shoppingGoodsAssembleDao.selectProjByShoppingGoodsId(shoppingGoods.getId());
                shoppingGoods.setAssembleProj(assembleList);
            } else if (Dictionary.SHOPPING_GOODS_TYPE_TC.equals(shoppingGoods.getGoodType())) {
 
                List<ShoppingGoodsAssemble> assembleListGoods = shoppingGoodsAssembleDao.selectGoodsByShoppingGoodsId(shoppingGoods.getId());
                shoppingGoods.setAssembleGoods(assembleListGoods);
                List<ShoppingGoodsAssemble> assembleListProj = shoppingGoodsAssembleDao.selectProjByShoppingGoodsId(shoppingGoods.getId());
                shoppingGoods.setAssembleProj(assembleListProj);
            } else if (Dictionary.SHOPPING_GOODS_TYPE_ZHK.equals(shoppingGoods.getGoodType())) {
                List<ShoppingGoodsAssemble> assembleList = shoppingGoodsAssembleDao.selectAssembleShoppingGoodsByShoppingGoodsId(shoppingGoods.getId());
                shoppingGoods.setZongheCarGoods(assembleList);
            }
 
 
            // 如果是充值卡
            if (shoppingGoods.getGoodType().equals(Dictionary.SHOPPING_GOODS_TYPE_CZK)) {
                MoneyCardAssemble moneyCardAssembleQuery = new MoneyCardAssemble();
                moneyCardAssembleQuery.setCardId(shoppingGoods.getId());
                // 查询充值卡中的分类
                moneyCardAssembleQuery.setType(Dictionary.CZK_ASSEMBLE_FL);
                List<MoneyCardAssemble> cateIdList = cardAssembleService.findByModel(moneyCardAssembleQuery);
                String cates = ",";
                for (MoneyCardAssemble moneyCardAssemble : cateIdList) {
                    cates += moneyCardAssemble.getCateId() + ",";
                }
                WebUtil.getRequest().setAttribute("cates", cates);
                // 查询充值卡中的产品
                moneyCardAssembleQuery.setType(Dictionary.CZK_ASSEMBLE_SP);
                List<MoneyCardAssemble> goodsIdList = cardAssembleService.findByModel(moneyCardAssembleQuery);
                List<ShoppingGoods> goodsList = new ArrayList<>();
                String goodsIds = "";
                for (MoneyCardAssemble moneyCardAssemble : goodsIdList) {
                    goodsList.add(shoppingGoodsService.findById(moneyCardAssemble.getGoodsId()));
                    goodsIds += moneyCardAssemble.getGoodsId() + ",";
                }
                WebUtil.getRequest().setAttribute("goodsIds", goodsIds);
                // 返回充值卡编辑界面
                WebUtil.getRequest().setAttribute("obj", shoppingGoods);
                return "admin/hive-erp/products/money-card-form";
            } else if (shoppingGoods.getGoodType().equals(Dictionary.SHOPPING_GOODS_TYPE_ZHK)) {
                WebUtil.getRequest().setAttribute("obj", shoppingGoods);
                return "admin/hive-erp/products/zonghe-card-form";
            }
 
 
 
            WebUtil.getRequest().setAttribute("obj", shoppingGoods);
 
        } else {
            WebUtil.getRequest().setAttribute("isUpdate", true);
        }
        // 返回非充值卡页面
 
        return "admin/hive-erp/products/goods-form";
    }
 
 
    /**
     * 删除
     */
    @RequestMapping(value = "/del")
    public @ResponseBody
    AjaxResult del(String keys) {
 
        return remove(shoppingGoodsService, keys);
    }
 
    @RequestMapping(value = "/exportShoppinggoods")
    public void exportShoppinggoods(ModelMap model, HttpServletRequest request, HttpServletResponse response, ShoppingGoods shoppingGoods) throws IOException {
        if (shoppingGoods.getGoodType() != null && !"".equals(shoppingGoods.getGoodType())) {
            shoppingGoods.setGoodType(new String(shoppingGoods.getGoodType().getBytes("iso-8859-1"), "UTF-8"));
        }
        List<ExcelSheetPO> res = new ArrayList<>();
        ExcelSheetPO orderSheet = new ExcelSheetPO();
        String title = "商品资料";
        orderSheet.setSheetName(title);
        orderSheet.setTitle(title);
        String[] header = {"商品名称", "售价/(本金)", "参考价/(赠送金额)", "真实销量", "状态", "是否赠送", "类型", "分类", "套餐卡"};
        orderSheet.setHeaders(header);
        QueryUtil.setQueryLimitCom(shoppingGoods);
        List<ShoppingGoods> dataList = shoppingGoodsService.findAll(shoppingGoods);
        List<List<Object>> list = new ArrayList<>();
        if (dataList.size() > 0) {
            for (ShoppingGoods item : dataList) {
                List<Object> temp = new ArrayList<>();
                temp.add(item.getName());
                temp.add(item.getSealPice());
                temp.add(item.getReferencePice());
                temp.add(item.getRealSealCount());
                temp.add(item.getStaus());
                temp.add(item.getIsPresent());
                temp.add(item.getGoodType());
                temp.add(item.getCateName());
                temp.add(item.getIsCourse());
                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);
    }
 
}