|   | 
| package com.matrix.system.hive.action; | 
|   | 
| import com.matrix.core.constance.MatrixConstance; | 
| 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.bean.SysUsers; | 
| 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.MoneyCardAssemble; | 
| import com.matrix.system.hive.bean.ShoppingGoods; | 
| import com.matrix.system.hive.bean.ShoppingGoodsAssemble; | 
| import com.matrix.system.hive.bean.SysShopInfo; | 
| import com.matrix.system.hive.dao.MoneyCardAssembleDao; | 
| import com.matrix.system.hive.dao.ShoppingGoodsAssembleDao; | 
| import com.matrix.system.hive.dao.ShoppingGoodsDao; | 
| import com.matrix.system.hive.dao.SysShopInfoDao; | 
| import com.matrix.system.hive.service.ShoppingGoodsService; | 
| import com.matrix.system.hive.service.SysShopInfoService; | 
| import org.apache.poi.ss.formula.functions.T; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Controller; | 
| import org.springframework.ui.ModelMap; | 
| import org.springframework.web.bind.annotation.RequestBody; | 
| 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.Arrays; | 
| import java.util.List; | 
|   | 
|   | 
| /** | 
|  * 商品 | 
|  * | 
|  * @author jiangyouyao | 
|  * @date 2016-8-22 | 
|  */ | 
| @Controller | 
| @RequestMapping(value = "admin/shoppinggoods") | 
| public class ShoppingGoodsController extends BaseController { | 
|     @Resource | 
|     private ShoppingGoodsService shoppingGoodsService; | 
|   | 
|     @Resource | 
|     private MoneyCardAssembleDao moneyCardAssembleDao; | 
|   | 
|     @Autowired | 
|     private ShoppingGoodsAssembleDao shoppingGoodsAssembleDao; | 
|   | 
|   | 
|     //记录编辑前的值Before_Edit_Value | 
|     public static final String BEV = "shoppinggoods_BEV"; | 
|   | 
|   | 
|     @Autowired | 
|     private ShoppingGoodsDao shoppingGoodsDao; | 
|   | 
|     @Resource | 
|     private SysShopInfoService shopInfoService; // 店铺信息Service | 
|   | 
|   | 
|     @Resource | 
|     private SysShopInfoDao shopInfoDao; // 店铺信息Service | 
|   | 
|   | 
|   | 
|   | 
|   | 
|   | 
|   | 
|   | 
|   | 
|   | 
|   | 
|     /** | 
|      * 分页查询产品 | 
|      * | 
|      * @param type    1,表示商品,2表示项目 3表示套餐4,充值卡不限制品牌 | 
|      * @param keyword 名称 | 
|      * @param pageVo  分页对象 | 
|      * @author jiangyouyao | 
|      */ | 
|     @RequestMapping(value = "/showGoodsList") | 
|     public @ResponseBody | 
|     AjaxResult showGoodsList(String type, String keyword, PaginationVO pageVo) { | 
|         ShoppingGoods shoppingGoods = new ShoppingGoods(); | 
|         QueryUtil.setQueryLimit(shoppingGoods); | 
|         shoppingGoods.setName(keyword); | 
|         shoppingGoods.setStaus(Dictionary.BUSINESS_STATE_UP);// 只查询上架的商品 | 
|         shoppingGoods.setSalePlatform(Dictionary.SHOPPING_GOODS_SALE_PLATFORM_XX);//只查询线下的商品 | 
|         shoppingGoods.setGoodType(type); | 
|         shoppingGoods.setIsDel(ShoppingGoods.NORMAL); | 
|         SysUsers users = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|         shoppingGoods.setShopId(users.getShopId()); | 
|         pageVo.setOrder("desc"); | 
|         pageVo.setSort("createTime"); | 
|   | 
|         return showList(shoppingGoodsService, shoppingGoods, pageVo); | 
|     } | 
|   | 
|     /** | 
|      * 根据产品id查询出产品 | 
|      * | 
|      * @author jiangyouyao | 
|      */ | 
|     @RequestMapping(value = "/findShoppingGoods") | 
|     public @ResponseBody | 
|     AjaxResult findShoppingGoods(Long id) { | 
|         ShoppingGoods shoppingGoods = shoppingGoodsService.findById(id); | 
|   | 
|         if (shoppingGoods != null) { | 
|             AjaxResult result = new AjaxResult(); | 
|             //查询的绑定关系 | 
|             if (Dictionary.SHOPPING_GOODS_TYPE_TC.equals(shoppingGoods.getGoodType())) { | 
|                 //家居产品和项目分离 | 
|                 shoppingGoods.setAssembleGoods(shoppingGoodsAssembleDao.selectGoodsByShoppingGoodsIdAndType(shoppingGoods.getId(), ShoppingGoods.SHOPPING_GOODS_TYPE_JJCP)); | 
|                 shoppingGoods.setAssembleProj(shoppingGoodsAssembleDao.selectGoodsByShoppingGoodsIdAndType(shoppingGoods.getId(), ShoppingGoods.SHOPPING_GOODS_TYPE_XM)); | 
|             } else if ( | 
|                     Dictionary.SHOPPING_GOODS_TYPE_XM.equals(shoppingGoods.getGoodType()) | 
|                             || Dictionary.SHOPPING_GOODS_TYPE_ZHK.equals(shoppingGoods.getGoodType()) | 
|             ) { | 
|                 shoppingGoods.setAssembleGoods(shoppingGoodsAssembleDao.selectGoodsByShoppingGoodsIdAndType(shoppingGoods.getId(), null)); | 
|             } else if (Dictionary.SHOPPING_GOODS_TYPE_CZK.equals(shoppingGoods.getGoodType())) { | 
|                 List<MoneyCardAssemble> moneyCardAssembles = moneyCardAssembleDao.selectByCardId(shoppingGoods.getId()); | 
|                 List<MoneyCardAssemble> assemblesGoods = new ArrayList<>(); | 
|                 List<Long> cates = new ArrayList<>(); | 
|                 moneyCardAssembles.forEach(item -> { | 
|                     if ("商品".equals(item.getType())) { | 
|                         item.setShoppingGoods(shoppingGoodsService.findById(item.getGoodsId())); | 
|                         assemblesGoods.add(item); | 
|                     } else if ("分类".equals(item.getType())) { | 
|                         cates.add(item.getCateId()); | 
|                     } | 
|                 }); | 
|                 result.putInMap("cates", cates); | 
|                 shoppingGoods.setCardAssembles(assemblesGoods); | 
|             } | 
|             result.setRows(Arrays.asList(shoppingGoods)); | 
|             result.setStatus(AjaxResult.STATUS_SUCCESS); | 
|             return result; | 
|         } else { | 
|             return AjaxResult.buildFailInstance("未查询到产品信息"); | 
|         } | 
|   | 
|     } | 
|   | 
|   | 
|     @RequestMapping(value = "/bachUpdate") | 
|     public @ResponseBody | 
|     AjaxResult bachUpdate(String ids, String cateId, int file) { | 
|         if (file == 1) { | 
|   | 
|             shoppingGoodsDao.bachUpdate(StringUtils.strToCollToLong(ids, ","), cateId, "cate_id"); | 
|         } | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, "修改成功"); | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 列表显示 | 
|      */ | 
|     @RequestMapping(value = "/showList") | 
|     public @ResponseBody | 
|     AjaxResult showList(ShoppingGoods shoppingGoods, PaginationVO pageVo) { | 
|         QueryUtil.setQueryLimit(shoppingGoods); | 
|         pageVo.setOrder("desc"); | 
|         pageVo.setSort("createTime"); | 
|         //2表示查询总部产品 | 
|         if (shoppingGoods.getHeadquarters()!=null && 2==shoppingGoods.getHeadquarters()) { | 
|             //仅查询本店产品 | 
|             SysShopInfo zbShop = shopInfoDao.selectZbShop(getMe().getCompanyId()); | 
|             //如果是总部自己查询自己的库存则不需加入这个调价 | 
|             if (getMe().getShopId().equals(zbShop.getId())){ | 
|                 shoppingGoods.setHeadquarters(1); | 
|             } | 
|         } | 
|         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 = "/showListShopId") | 
|     @ResponseBody | 
|     public AjaxResult showListShopId(ShoppingGoods shoppingGoods, PaginationVO pageVo) { | 
|         pageVo.setOrder("desc"); | 
|         pageVo.setSort("createTime"); | 
|         shoppingGoods.setIsDel(ShoppingGoods.NORMAL); | 
|         QueryUtil.setQueryLimitCom(shoppingGoods); | 
|         return showList(shoppingGoodsService, shoppingGoods, pageVo); | 
|     } | 
|   | 
|     /** | 
|      * 新增或修改页面 | 
|      */ | 
|     @RequestMapping(value = "/addOrModify") | 
|     public @ResponseBody | 
|     AjaxResult addOrModify(ShoppingGoods shoppingGoods) { | 
|         if (shoppingGoods.getId() != null) { | 
|             return modify(shoppingGoodsService, shoppingGoods, "商品"); | 
|         } else { | 
|             QueryUtil.setQueryLimit(shoppingGoods); | 
|             int i = shoppingGoodsService.add(shoppingGoods); | 
|             if (i > 0) { | 
|                 return new AjaxResult(AjaxResult.STATUS_SUCCESS, "添加成功"); | 
|             } else { | 
|                 return new AjaxResult(AjaxResult.STATUS_FAIL, "添加失败"); | 
|             } | 
|         } | 
|     } | 
|   | 
|     /** | 
|      * 修改产品信息 | 
|      */ | 
|     @RequestMapping(value = "/modifyShoppingGoods") | 
|     public @ResponseBody | 
|     AjaxResult modifyShoppingGoods(@RequestBody ShoppingGoods shoppingGoods) { | 
|   | 
|         shoppingGoodsService.modify(shoppingGoods); | 
|         return AjaxResult.buildSuccessInstance("修改成功"); | 
|   | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 新增产品信息 | 
|      */ | 
|     @RequestMapping(value = "/addShoppingGoods") | 
|     public @ResponseBody | 
|     AjaxResult addShoppingGoods(@RequestBody ShoppingGoods shoppingGoods) { | 
|   | 
|         QueryUtil.setQueryLimit(shoppingGoods); | 
|         shoppingGoodsService.add(shoppingGoods); | 
|         return AjaxResult.buildSuccessInstance("创建成功"); | 
|   | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 进入线上产品修改界面 | 
|      */ | 
|     @RequestMapping(value = "/editForm") | 
|     public String editForm(Long id) { | 
|         ShoppingGoods shoppingGoods; | 
|         if (id != null) { | 
|             shoppingGoods = shoppingGoodsService.findById(id); | 
|             WebUtil.getRequest().setAttribute("isUpdate", shoppingGoodsService.checkIsUpdate(id)); | 
|             WebUtil.getRequest().setAttribute("obj", shoppingGoods); | 
|         } else { | 
|             WebUtil.getRequest().setAttribute("isUpdate", true); | 
|         } | 
|         return "admin/hive/shopping/goods-form"; | 
|     } | 
|   | 
|     /** | 
|      * 进入线下产品修改界面 | 
|      */ | 
|     @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 = moneyCardAssembleDao.selectByModel(moneyCardAssembleQuery); | 
|                 String cates = ","; | 
|                 for (MoneyCardAssemble moneyCardAssemble : cateIdList) { | 
|                     cates += moneyCardAssemble.getCateId() + ","; | 
|                 } | 
|                 WebUtil.getRequest().setAttribute("cates", cates); | 
|                 // 查询充值卡中的产品 | 
|                 moneyCardAssembleQuery.setType(Dictionary.CZK_ASSEMBLE_SP); | 
|                 List<MoneyCardAssemble> goodsIdList = moneyCardAssembleDao.selectByModel(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/products/money-card-form"; | 
|             } else if (shoppingGoods.getGoodType().equals(Dictionary.SHOPPING_GOODS_TYPE_ZHK)) { | 
|                 WebUtil.getRequest().setAttribute("obj", shoppingGoods); | 
|                 return "admin/hive/products/zonghe-card-form"; | 
|             } | 
|   | 
|   | 
|             WebUtil.getRequest().setAttribute("obj", shoppingGoods); | 
|   | 
|         } else { | 
|             WebUtil.getRequest().setAttribute("isUpdate", true); | 
|         } | 
|         // 返回非充值卡页面 | 
|   | 
|         return "admin/hive/products/shoppinggoods-form"; | 
|     } | 
|   | 
|     /** | 
|      * 进入线下充值卡绑定产品界面 | 
|      */ | 
|     @RequestMapping(value = "/moneyCardBangding") | 
|     public String moneyCardBangding(Long id) { | 
|         ShoppingGoods shoppingGoods; | 
|         if (id != null) { | 
|             shoppingGoods = shoppingGoodsService.findById(id); | 
|             WebUtil.getRequest().setAttribute("obj", shoppingGoods); | 
|             MoneyCardAssemble moneyCardAssembleQuery = new MoneyCardAssemble(); | 
|             moneyCardAssembleQuery.setCardId(shoppingGoods.getId()); | 
|             // 查询充值卡中的分类 | 
|             moneyCardAssembleQuery.setType(Dictionary.CZK_ASSEMBLE_FL); | 
|             List<MoneyCardAssemble> cateIdList = moneyCardAssembleDao.selectByModel(moneyCardAssembleQuery); | 
|             String cates = ","; | 
|             for (MoneyCardAssemble moneyCardAssemble : cateIdList) { | 
|                 cates += moneyCardAssemble.getCateId() + ","; | 
|             } | 
|             WebUtil.getRequest().setAttribute("cates", cates); | 
|             // 查询充值卡中的产品 | 
|             moneyCardAssembleQuery.setType(Dictionary.CZK_ASSEMBLE_SP); | 
|             List<MoneyCardAssemble> goodsIdList = moneyCardAssembleDao.selectByModel(moneyCardAssembleQuery); | 
|             List<ShoppingGoods> goodsList = new ArrayList<>(); | 
|             for (MoneyCardAssemble moneyCardAssemble : goodsIdList) { | 
|                 goodsList.add(shoppingGoodsService.findById(moneyCardAssemble.getGoodsId())); | 
|             } | 
|             WebUtil.getRequest().setAttribute("goodsList", goodsList); | 
|         } | 
|         // 返回非充值卡页面 | 
|         return "admin/hive/products/select-bangding-list"; | 
|     } | 
|   | 
|   | 
|     @RequestMapping(value = "/lookInfo") | 
|     public String lookInfo(Long id, String flag) { | 
|         ShoppingGoods shoppingGoods; | 
|         if (id != null) { | 
|             shoppingGoods = shoppingGoodsService.findById(id); | 
|             WebUtil.getRequest().setAttribute("obj", shoppingGoods); | 
|         } | 
|         if (flag != null && flag.equals("underline")) { | 
|             return "admin/hive/products/shoppinggoods-look"; | 
|         } | 
|         return "admin/hive/shopping/shoppinggoods-look"; | 
|     } | 
|   | 
|     /** | 
|      * 删除 | 
|      */ | 
|     @RequestMapping(value = "/del") | 
|     public @ResponseBody | 
|     AjaxResult del(String keys) { | 
|   | 
|         List<Long> ids = StringUtils.strToCollToLong(keys, ","); | 
|         int i = shoppingGoodsService.remove(ids); | 
|         if (i > 0) { | 
|             return new AjaxResult(AjaxResult.STATUS_SUCCESS, "成功删除" + i + "条数据"); | 
|         } else { | 
|             return new AjaxResult(AjaxResult.STATUS_FAIL, "删除失败"); | 
|         } | 
|     } | 
|   | 
|     @RequestMapping(value = "/exportShoppinggoods") | 
|     public void exportShoppinggoods(ModelMap model, HttpServletRequest request, HttpServletResponse response, ShoppingGoods shoppingGoods) throws IOException { | 
|   | 
|         SysUsers users = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|         shoppingGoods.setShopId(users.getShopId()); | 
|         List<ExcelSheetPO> res = new ArrayList<>(); | 
|         ExcelSheetPO orderSheet = new ExcelSheetPO(); | 
|         String title = "商品资料"; | 
|         orderSheet.setSheetName(title); | 
|         orderSheet.setTitle(title); | 
|         String[] header = {"商品名称", "商品编号", "售价/(本金)", "参考价/(赠送金额)", "真实销量", "状态", "是否赠送", "类型", "分类", "是否固定套餐", "产品归属"}; | 
|         orderSheet.setHeaders(header); | 
|         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.getCode()); | 
|                 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()); | 
|                 temp.add(item.getHeadquarters() == 1 ? "总部产品" : "本店产品"); | 
|                 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); | 
|     } | 
|   | 
|   | 
| } |