| package com.matrix.system.shopXcx.api.action; | 
|   | 
| import com.matrix.core.pojo.AjaxResult; | 
| import com.matrix.biz.bean.BizUser; | 
|   | 
| import com.matrix.component.redis.RedisUserLoginUtils; | 
| import com.matrix.system.shopXcx.bean.ShopCollection; | 
| import com.matrix.system.shopXcx.dao.ShopCollectionDao; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Controller; | 
| import org.springframework.web.bind.annotation.*; | 
|   | 
| import java.util.HashMap; | 
| import java.util.List; | 
| import java.util.Map; | 
|   | 
|   | 
| /** | 
|  * @description 收藏 | 
|  * @author jiangyouyao | 
|  * @date 2019-06-11 10:15 | 
|  */ | 
| @CrossOrigin(origins = "*", maxAge = 3600) | 
| @Controller | 
| @RequestMapping(value = "wxapi/Collection") | 
| public class WxCollectionAction { | 
|     @Autowired | 
|     private ShopCollectionDao collectionDao; | 
|     @Autowired | 
|     private RedisUserLoginUtils redisUserLoginUtils; | 
|   | 
|     /** | 
|      * 接收保存收藏数据 | 
|      */ | 
|     @PostMapping(value = "/saveCollection") | 
|     public @ResponseBody | 
|     AjaxResult saveCollection(@RequestBody ShopCollection collection) { | 
|         BizUser loginUser = redisUserLoginUtils.getLoginUser(BizUser.class); | 
|         collection.setCreateBy(loginUser.getOpenId()); | 
|         collection.setUpdateBy(loginUser.getOpenId()); | 
|         collection.setCollUserid(loginUser.getOpenId()); | 
|         collection.setCompanyId(loginUser.getCompanyId()); | 
|         int i = collectionDao.insert(collection); | 
|   | 
|         if (i == 0) { | 
|             return new AjaxResult(AjaxResult.STATUS_FAIL, "保存失败"); | 
|         } | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, "保存成功"); | 
|     } | 
|   | 
|     /** | 
|      * 根据ID删除收藏 | 
|      * @param | 
|      * @return | 
|      */ | 
|     @PostMapping("/deleteByCollId/{collId}") | 
|     @ResponseBody | 
|     public AjaxResult deleteByCollId(@PathVariable("collId") Integer collId){ | 
|         int i = collectionDao.deleteById(collId); | 
|         if (i == 0) { | 
|             return new AjaxResult(AjaxResult.STATUS_FAIL, "删除失败"); | 
|         } | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, "删除成功"); | 
|     } | 
|   | 
|     /** | 
|      * 根据产品ID删除收藏 | 
|      * @param | 
|      * @return | 
|      */ | 
|     @PostMapping("/deleteByProductId/{collProductid}") | 
|     @ResponseBody | 
|     public AjaxResult deleteByProductId(@PathVariable("collProductid") Integer collProductid){ | 
|         Map<String, Object> deleteMap = new HashMap<>(); | 
|         BizUser loginUser = redisUserLoginUtils.getLoginUser(BizUser.class); | 
|         String collUserid = loginUser.getOpenId(); | 
|         deleteMap.put("collProductid", collProductid); | 
|         deleteMap.put("collUserid", collUserid); | 
|         int i = collectionDao.deleteByProductId(deleteMap); | 
|         if (i == 0) { | 
|             return new AjaxResult(AjaxResult.STATUS_FAIL, "删除失败"); | 
|         } | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, "删除成功"); | 
|     } | 
|   | 
|     /** | 
|      * 根据用户ID查询收藏 | 
|      * @param | 
|      * @return | 
|      */ | 
|     @PostMapping("/findCollection") | 
|     @ResponseBody | 
|     public AjaxResult getCollectionByUserId(@RequestBody ShopCollection collection) { | 
|         BizUser loginUser = redisUserLoginUtils.getLoginUser(BizUser.class); | 
|         String userId = loginUser.getOpenId(); | 
|         collection.setCollUserid(userId); | 
|         List<ShopCollection> list = collectionDao.selectByUserId(collection); | 
|         AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, list, list.size()); | 
|         return result; | 
|     } | 
|   | 
|     /** | 
|      * 根据用户ID和产品ID查询收藏 | 
|      * @param | 
|      * @return | 
|      */ | 
|     @PostMapping("/findByUserIdAndProid/{collProductid}") | 
|     @ResponseBody | 
|     public AjaxResult findByUserIdAndProid(@PathVariable("collProductid") Integer collProductid) { | 
|         BizUser loginUser = redisUserLoginUtils.getLoginUser(BizUser.class); | 
|         String userId = loginUser.getOpenId(); | 
|         List<ShopCollection> list = collectionDao.selectByUserIdAndProid(collProductid,userId); | 
|         AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, list, list.size()); | 
|         return result; | 
|     } | 
| } |