package com.sinata.shop.modular.mall.controller;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
import com.baomidou.mybatisplus.plugins.Page;
|
import com.sinata.common.enums.mall.EnumMallGoodsGroupType;
|
import com.sinata.common.enums.mall.EnumMallGoodsState;
|
import com.sinata.core.base.controller.BaseController;
|
import com.sinata.core.util.Convert;
|
import com.sinata.core.util.DateUtils2;
|
import com.sinata.core.util.ExcelExportUtil;
|
import com.sinata.shop.core.common.constant.factory.PageFactory;
|
import com.sinata.shop.core.shiro.ShiroKit;
|
import com.sinata.shop.modular.mall.model.*;
|
import com.sinata.shop.modular.mall.service.*;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.ui.Model;
|
import org.springframework.util.StringUtils;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletResponse;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* 套餐套餐商品控制器
|
*
|
* @author goku
|
*/
|
@Controller
|
@RequestMapping("/mallGoodsGroup")
|
public class MallGoodsGroupController extends BaseController {
|
|
private String PREFIX = "/mall/mallGoodsGroup/";
|
|
@Autowired
|
private IMallGoodsService mallGoodsService;
|
|
@Autowired
|
private IMallGoodsSkuService mallGoodsSkuService;
|
|
@Autowired
|
private IMallClassifyOneService mallClassifyOneService;
|
|
@Autowired
|
private IMallGoodsSpecService mallGoodsSpecService;
|
|
@Autowired
|
private IMallGoodsDetailService mallGoodsDetailService;
|
|
@Resource
|
private IMallTagService mallTagService;
|
|
|
/**
|
* 跳转到套餐商品首页
|
*/
|
@RequestMapping("")
|
public String index() {
|
return PREFIX + "mallGoodsGroup.html";
|
}
|
|
/**
|
* 获取套餐商品列表
|
*
|
* @param id 商品id
|
* @param state 商品状态
|
*/
|
@ResponseBody
|
@RequestMapping(value = "/list")
|
public Object list(String beginTime, String endTime, String goodsName, String id, Integer state, String goodsNo) {
|
Page<Map<String, Object>> page = new PageFactory().defaultPage();
|
|
page.setRecords(
|
wrapperList(page, beginTime, endTime, goodsName, id, state, goodsNo)
|
);
|
|
return super.packForBT(page);
|
}
|
public List<Map<String, Object>> wrapperList(Page<Map<String, Object>> page, String beginTime, String endTime, String goodsName, String id, Integer state, String goodsNo) {
|
Integer merchantId = ShiroKit.getUserId();
|
List<MallGoodsSku> goodsByMerchantList = mallGoodsSkuService.selectList(
|
new EntityWrapper<MallGoodsSku>()
|
.setSqlSelect("goods_id")
|
.eq("merchant_id", merchantId)
|
.groupBy("goods_id")
|
);
|
List<Integer> goodsIds = Arrays.asList(0);
|
if (goodsByMerchantList != null && goodsByMerchantList.size() > 0) {
|
goodsIds = goodsByMerchantList.stream().map(MallGoodsSku::getGoodsId).collect(Collectors.toList());
|
}
|
|
Wrapper wrapper = new EntityWrapper<MallGoods>()
|
.in("id", goodsIds)
|
.ne("group_type", EnumMallGoodsGroupType.GOODS.index)
|
.eq("is_delete", 0)
|
.orderBy("id", false);
|
|
// 时间搜索
|
if (!StringUtils.isEmpty(beginTime)) {
|
wrapper.ge("create_time", beginTime + " 00:00:00");
|
}
|
if (!StringUtils.isEmpty(endTime)) {
|
wrapper.le("create_time", endTime + " 23:59:59");
|
}
|
|
if (!StringUtils.isEmpty(goodsName)) {
|
wrapper.like("goods_name", goodsName);
|
}
|
if (!StringUtils.isEmpty(id)) {
|
if (id.indexOf("sp") != -1) {
|
String idd = id.substring(id.indexOf("sp") + 2);
|
wrapper.eq("id", Integer.parseInt(idd));
|
} else {
|
wrapper.eq("id", Integer.parseInt(id));
|
}
|
}
|
if (state != null) {
|
wrapper.eq("state", state);
|
}
|
if (goodsNo != null) {
|
wrapper.like("goods_no", goodsNo);
|
}
|
|
// 查询所有标签
|
List<MallTag> mallTags = mallTagService.getMallTags();
|
|
// 查询数据列表
|
List<Map<String, Object>> list;
|
if (page != null) {
|
list = mallGoodsService.selectMapsPage(page, wrapper).getRecords();
|
} else {
|
list = mallGoodsService.selectMaps(wrapper);
|
}
|
|
// 规格列表
|
List<MallGoodsSpec> selectList = mallGoodsSpecService.selectList(new EntityWrapper<MallGoodsSpec>().setSqlSelect("id, spec_name"));
|
|
return list.stream().peek(m -> {
|
Object classObj = m.get("classifyIdOne");
|
if (classObj != null) {
|
m.put("classifyName", mallClassifyOneService.selectById(Convert.toInt(classObj)).getClassifyName());
|
}
|
|
// 封装规格名
|
List<String> specNameList = new ArrayList<>();
|
List<MallGoodsSku> skuList = mallGoodsSkuService.selectList(new EntityWrapper<MallGoodsSku>().eq("goods_id", m.get("id")).eq("merchant_id", 0));
|
for (MallGoodsSku sku : skuList) {
|
String[] spIds = sku.getSpecGrep().split(",");
|
for (String spId : spIds) {
|
for (MallGoodsSpec spec : selectList) {
|
if (spec.getId().toString().equals(spId)) {
|
specNameList.add(spec.getSpecName());
|
}
|
}
|
}
|
}
|
m.put("specNames", specNameList.stream().distinct().collect(Collectors.joining(",")));
|
|
m.put("merchantCount", mallGoodsSkuService.selectCount(
|
new EntityWrapper<MallGoodsSku>()
|
.eq("goods_id", m.get("id"))
|
.ne("merchant_id", 0)
|
.groupBy("goods_id")
|
));
|
|
Object tagIds = m.get("tagIds");
|
if (tagIds != null) {
|
m.put("tagIds", mallTagService.getTagListByGoodsId(mallTags, tagIds.toString()).stream().collect(Collectors.joining("、")));
|
}
|
}).collect(Collectors.toList());
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/export")
|
public void export(String beginTime, String endTime, String goodsName, String id, Integer state, String goodsNo, HttpServletResponse response) {
|
List<Map<String, Object>> list = wrapperList(null, beginTime, endTime, goodsName, id, state, goodsNo);
|
|
// 表格数据【封装】
|
List<List<Object>> dataList = new ArrayList<>();
|
|
// 头部列【封装】
|
List<Object> shellList = new ArrayList<>();
|
shellList.add("创建时间");
|
shellList.add("商品编号");
|
shellList.add("商品分类");
|
shellList.add("商品名称");
|
shellList.add("商品副标题");
|
shellList.add("商品标签");
|
shellList.add("规格");
|
shellList.add("销售量");
|
shellList.add("商品库存");
|
shellList.add("售卖门店数");
|
shellList.add("销售价");
|
shellList.add("会员价");
|
shellList.add("商品状态");
|
dataList.add(shellList);
|
|
// 详细数据列【封装】
|
for (Map<String, Object> map : list) {
|
shellList = new ArrayList<>();
|
shellList.add(map.get("createTime"));
|
shellList.add(map.get("goodsNo"));
|
shellList.add(map.get("classifyName"));
|
shellList.add(map.get("goodsName"));
|
shellList.add(map.get("goodsTitle"));
|
shellList.add(map.get("tagIds"));
|
shellList.add(map.get("specNames"));
|
shellList.add(map.get("buyCount"));
|
shellList.add(map.get("stock"));
|
shellList.add(map.get("merchantCount"));
|
shellList.add(map.get("priceSale"));
|
shellList.add(map.get("priceMember"));
|
shellList.add(EnumMallGoodsState.getMarkByIndex((Integer) map.get("state")));
|
dataList.add(shellList);
|
}
|
try {
|
String title = "套餐商品";
|
// 调用工具类进行导出
|
ExcelExportUtil.easySheet(title + DateUtils2.formatDate(new Date(), "YYYYMMddHHmmSS"), title, dataList, response);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 跳转套餐商品详情
|
*/
|
@RequestMapping(value = "/detail/{mallGoodsId}")
|
public Object detail(@PathVariable("mallGoodsId") Integer mallGoodsId, Model model) {
|
MallGoods mallGoods = mallGoodsService.selectById(mallGoodsId);
|
mallGoods.setMallClassifyOne(this.mallClassifyOneService.selectById(mallGoods.getClassifyIdOne()));
|
|
MallGoodsDetail goodsDetail = this.mallGoodsDetailService.selectById(mallGoods.getId());
|
if (goodsDetail == null) {
|
goodsDetail = new MallGoodsDetail();
|
}
|
|
model.addAttribute("item", mallGoods);
|
model.addAttribute("mallGoodsDetail", goodsDetail);
|
|
return PREFIX + "mallGoodsGroup_detail.html";
|
}
|
|
}
|