| | |
| | | package com.yeshi.fanli.controller.client.v1;
|
| | |
|
| | | import java.io.PrintWriter;
|
| | | import java.util.ArrayList;
|
| | | import java.util.HashSet;
|
| | | import java.util.List;
|
| | | import java.util.Set;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | import org.springframework.stereotype.Controller;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RequestMethod;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | |
|
| | | import com.google.gson.Gson;
|
| | | import com.google.gson.reflect.TypeToken;
|
| | | import com.yeshi.fanli.entity.accept.AcceptData;
|
| | | import com.yeshi.fanli.entity.bus.user.UserGoodsStorage;
|
| | | import com.yeshi.fanli.exception.share.UserShareGoodsRecordException;
|
| | | import com.yeshi.fanli.exception.user.UserGoodsStorageException;
|
| | | import com.yeshi.fanli.service.inter.config.ConfigService;
|
| | | import com.yeshi.fanli.service.inter.user.UserGoodsStorageService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
|
| | | @Controller
|
| | | @RequestMapping("api/v1/userstorage")
|
| | | public class UserGoodsStorageController {
|
| | |
|
| | | @Resource
|
| | | private ConfigService configService;
|
| | | |
| | | @Resource
|
| | | private UserGoodsStorageService userGoodsStorageService;
|
| | |
|
| | | /**
|
| | | * 单个商品加入选品库
|
| | | * |
| | | * @param callback
|
| | | * @param storageIds
|
| | | * id数组
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "accordtorage", method = RequestMethod.POST)
|
| | | public void accordtorage(AcceptData acceptData, Long uid, Long auctionId, Integer goodsType, PrintWriter out) {
|
| | |
|
| | | if (auctionId == null) {
|
| | | out.print(JsonUtil.loadFalseResult("未选择商品"));
|
| | | return;
|
| | | }
|
| | | |
| | | if (uid == null) {
|
| | | out.print(JsonUtil.loadFalseResult("用户未登录"));
|
| | | return;
|
| | | }
|
| | | |
| | | if (goodsType == null) {
|
| | | goodsType = Constant.SOURCE_TYPE_TAOBAO;
|
| | | }
|
| | | |
| | | try {
|
| | | UserGoodsStorage userGoodsStorage = userGoodsStorageService.getByUidAndAuctionId(uid, auctionId, goodsType);
|
| | | boolean storageState = false;
|
| | | if (userGoodsStorage != null) {
|
| | | // 取消加入选品库
|
| | | userGoodsStorageService.deleteByPrimaryKey(userGoodsStorage.getId());
|
| | | } else {
|
| | | // 加入选品库
|
| | | Set<Long> set = new HashSet<Long>();
|
| | | set.add(auctionId);
|
| | | userGoodsStorageService.save(uid, set, goodsType);
|
| | | storageState = true;
|
| | | }
|
| | | |
| | | JSONObject data = new JSONObject();
|
| | | data.put("storageState", storageState);
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | |
|
| | | } catch (Exception e) {
|
| | | out.print(JsonUtil.loadFalseResult("操作失败"));
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | |
| | | /**
|
| | | * 批量添加选品库
|
| | | * |
| | | * @param acceptData
|
| | | * @param uid
|
| | | * 用户id
|
| | | * @param auctionId
|
| | | * 淘宝商品id
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "addstorage", method = RequestMethod.POST)
|
| | | public void addStorage(AcceptData acceptData, Long uid, String auctionIds, Integer goodsType,PrintWriter out) {
|
| | | try {
|
| | | Gson gson = new Gson();
|
| | | Set<Long> set = gson.fromJson(auctionIds, new TypeToken<HashSet<Long>>() {}.getType());
|
| | | if (set == null || set.size() == 0) {
|
| | | out.print(JsonUtil.loadFalseResult("未选择商品"));
|
| | | return;
|
| | | }
|
| | |
|
| | | if (goodsType == null) {
|
| | | goodsType = Constant.SOURCE_TYPE_TAOBAO;
|
| | | }
|
| | | userGoodsStorageService.save(uid, set, goodsType);
|
| | | out.print(JsonUtil.loadTrueResult("添加成功"));
|
| | |
|
| | | } catch (UserGoodsStorageException e) {
|
| | | out.print(JsonUtil.loadFalseResult(e.getMsg()));
|
| | | } catch (Exception e) {
|
| | | out.print(JsonUtil.loadFalseResult("添加失败"));
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 查询用户选品库数据
|
| | | * |
| | | * @param acceptData
|
| | | * @param page
|
| | | * 页码 初始值 1
|
| | | * @param uid
|
| | | * 用户id
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "getstoragelist", method = RequestMethod.POST)
|
| | | public void getStorageList(AcceptData acceptData, Integer page, Long uid, PrintWriter out) {
|
| | |
|
| | | if (page == null || page < 1) {
|
| | | out.print(JsonUtil.loadFalseResult("页码不正确"));
|
| | | return;
|
| | | }
|
| | |
|
| | | if (uid == null) {
|
| | | out.print(JsonUtil.loadFalseResult("用户未登录"));
|
| | | return;
|
| | | }
|
| | |
|
| | | try {
|
| | | int pageSize = Constant.PAGE_SIZE;
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | JSONArray array = new JSONArray();
|
| | |
|
| | | long count = userGoodsStorageService.countQueryByUid(uid, null);
|
| | | if (count > 0) {
|
| | | array = userGoodsStorageService.getMyStorage((page - 1) * pageSize, pageSize, uid, null);
|
| | | }
|
| | |
|
| | | data.put("count", count);
|
| | | data.put("result_list", array);
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | |
|
| | | } catch (Exception e) {
|
| | | out.print(JsonUtil.loadFalseResult("加载列表失败"));
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 删除
|
| | | * |
| | | * @param callback
|
| | | * @param storageIds
|
| | | * id数组
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "deletestorage", method = RequestMethod.POST)
|
| | | public void deleteStorage(AcceptData acceptData, Long uid, String storageIds, PrintWriter out) {
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(storageIds)) {
|
| | | out.print(JsonUtil.loadFalseResult("未选择商品"));
|
| | | return;
|
| | | }
|
| | | |
| | | if (uid == null) {
|
| | | out.print(JsonUtil.loadFalseResult("用户未登录"));
|
| | | return;
|
| | | }
|
| | |
|
| | | try {
|
| | | Gson gson = new Gson();
|
| | | List<Long> list = gson.fromJson(storageIds, new TypeToken<ArrayList<Long>>() {}.getType());
|
| | | if (list == null || list.size() == 0) {
|
| | | out.print(JsonUtil.loadFalseResult("未选择商品"));
|
| | | return;
|
| | | }
|
| | |
|
| | | userGoodsStorageService.deleteBatchByUidAndPrimaryKey(uid, list);
|
| | | out.print(JsonUtil.loadTrueResult("删除成功"));
|
| | |
|
| | | } catch (Exception e) {
|
| | | out.print(JsonUtil.loadFalseResult("删除失败"));
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | |
| | | |
| | | |
| | |
|
| | | /**
|
| | | * 分享商品返回二维码图片
|
| | | * |
| | | * @param callback
|
| | | * @param storageIds
|
| | | * id数组
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "sharegoods", method = RequestMethod.POST)
|
| | | public void shareGoods(AcceptData acceptData, Long uid, String storageIds, Integer goodsType, PrintWriter out) {
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(storageIds)) {
|
| | | out.print(JsonUtil.loadFalseResult("分享商品不能为空"));
|
| | | return;
|
| | | }
|
| | | |
| | | if (uid == null) {
|
| | | out.print(JsonUtil.loadFalseResult("用户未登录"));
|
| | | return;
|
| | | }
|
| | |
|
| | | try {
|
| | | Gson gson = new Gson();
|
| | | List<Long> listStorageID = gson.fromJson(storageIds, new TypeToken<ArrayList<Long>>() {}.getType());
|
| | | if (listStorageID == null || listStorageID.size() < 9) {
|
| | | out.print(JsonUtil.loadFalseResult("分享商品数量不足"));
|
| | | return;
|
| | | }
|
| | | |
| | | if (listStorageID.size() != 9) {
|
| | | out.print(JsonUtil.loadFalseResult("分享商品数量只能是9个"));
|
| | | return;
|
| | | }
|
| | | |
| | | if (goodsType == null) {
|
| | | goodsType = Constant.SOURCE_TYPE_TAOBAO;
|
| | | }
|
| | |
|
| | | JSONObject data = userGoodsStorageService.shareGoods(uid, listStorageID, goodsType);
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | |
| | | } catch (UserGoodsStorageException e) {
|
| | | out.print(JsonUtil.loadFalseResult("分享失败"));
|
| | | e.printStackTrace();
|
| | | } catch (UserShareGoodsRecordException e) {
|
| | | out.print(JsonUtil.loadFalseResult("分享失败"));
|
| | | e.printStackTrace();
|
| | | } catch (Exception e) {
|
| | | out.print(JsonUtil.loadFalseResult("分享失败"));
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.controller.client.v1; |
| | | |
| | | import java.io.PrintWriter; |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.yeshi.utils.JsonUtil; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.yeshi.fanli.entity.accept.AcceptData; |
| | | import com.yeshi.fanli.entity.bus.user.UserGoodsStorage; |
| | | import com.yeshi.fanli.exception.share.UserShareGoodsRecordException; |
| | | import com.yeshi.fanli.exception.user.UserGoodsStorageException; |
| | | import com.yeshi.fanli.service.inter.config.ConfigService; |
| | | import com.yeshi.fanli.service.inter.user.UserGoodsStorageService; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | |
| | | @Controller |
| | | @RequestMapping("api/v1/userstorage") |
| | | public class UserGoodsStorageController { |
| | | |
| | | @Resource |
| | | private ConfigService configService; |
| | | |
| | | @Resource |
| | | private UserGoodsStorageService userGoodsStorageService; |
| | | |
| | | /** |
| | | * 单个商品加入选品库 |
| | | * |
| | | * id数组 |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "accordtorage", method = RequestMethod.POST) |
| | | public void accordtorage(AcceptData acceptData, Long uid, String auctionId, PrintWriter out) { |
| | | |
| | | if (auctionId == null) { |
| | | out.print(JsonUtil.loadFalseResult("未选择商品")); |
| | | return; |
| | | } |
| | | |
| | | if (uid == null) { |
| | | out.print(JsonUtil.loadFalseResult("用户未登录")); |
| | | return; |
| | | } |
| | | |
| | | |
| | | try { |
| | | UserGoodsStorage userGoodsStorage = userGoodsStorageService.getByUidAndAuctionId(uid, auctionId, Constant.SOURCE_TYPE_TAOBAO); |
| | | boolean storageState = false; |
| | | if (userGoodsStorage != null) { |
| | | // 取消加入选品库 |
| | | userGoodsStorageService.deleteByPrimaryKey(userGoodsStorage.getId()); |
| | | } else { |
| | | // 加入选品库 |
| | | Set<String> set = new HashSet<>(); |
| | | set.add(auctionId); |
| | | userGoodsStorageService.save(uid, set, Constant.SOURCE_TYPE_TAOBAO); |
| | | storageState = true; |
| | | } |
| | | |
| | | JSONObject data = new JSONObject(); |
| | | data.put("storageState", storageState); |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | |
| | | } catch (Exception e) { |
| | | out.print(JsonUtil.loadFalseResult("操作失败")); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 批量添加选品库 |
| | | * |
| | | * @param acceptData |
| | | * @param uid |
| | | * 用户id |
| | | * 淘宝商品id |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "addstorage", method = RequestMethod.POST) |
| | | public void addStorage(AcceptData acceptData, Long uid, String auctionIds, Integer goodsType,PrintWriter out) { |
| | | try { |
| | | Gson gson = new Gson(); |
| | | Set<String> set = gson.fromJson(auctionIds, new TypeToken<HashSet<String>>() {}.getType()); |
| | | if (set == null || set.size() == 0) { |
| | | out.print(JsonUtil.loadFalseResult("未选择商品")); |
| | | return; |
| | | } |
| | | |
| | | if (goodsType == null) { |
| | | goodsType = Constant.SOURCE_TYPE_TAOBAO; |
| | | } |
| | | userGoodsStorageService.save(uid, set, goodsType); |
| | | out.print(JsonUtil.loadTrueResult("添加成功")); |
| | | |
| | | } catch (UserGoodsStorageException e) { |
| | | out.print(JsonUtil.loadFalseResult(e.getMsg())); |
| | | } catch (Exception e) { |
| | | out.print(JsonUtil.loadFalseResult("添加失败")); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查询用户选品库数据 |
| | | * |
| | | * @param acceptData |
| | | * @param page |
| | | * 页码 初始值 1 |
| | | * @param uid |
| | | * 用户id |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "getstoragelist", method = RequestMethod.POST) |
| | | public void getStorageList(AcceptData acceptData, Integer page, Long uid, PrintWriter out) { |
| | | |
| | | if (page == null || page < 1) { |
| | | out.print(JsonUtil.loadFalseResult("页码不正确")); |
| | | return; |
| | | } |
| | | |
| | | if (uid == null) { |
| | | out.print(JsonUtil.loadFalseResult("用户未登录")); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | int pageSize = Constant.PAGE_SIZE; |
| | | |
| | | JSONObject data = new JSONObject(); |
| | | JSONArray array = new JSONArray(); |
| | | |
| | | long count = userGoodsStorageService.countQueryByUid(uid, null); |
| | | if (count > 0) { |
| | | array = userGoodsStorageService.getMyStorage((page - 1) * pageSize, pageSize, uid, null); |
| | | } |
| | | |
| | | data.put("count", count); |
| | | data.put("result_list", array); |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | |
| | | } catch (Exception e) { |
| | | out.print(JsonUtil.loadFalseResult("加载列表失败")); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除 |
| | | * |
| | | * @param storageIds |
| | | * id数组 |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "deletestorage", method = RequestMethod.POST) |
| | | public void deleteStorage(AcceptData acceptData, Long uid, String storageIds, PrintWriter out) { |
| | | |
| | | if (StringUtil.isNullOrEmpty(storageIds)) { |
| | | out.print(JsonUtil.loadFalseResult("未选择商品")); |
| | | return; |
| | | } |
| | | |
| | | if (uid == null) { |
| | | out.print(JsonUtil.loadFalseResult("用户未登录")); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | Gson gson = new Gson(); |
| | | List<Long> list = gson.fromJson(storageIds, new TypeToken<ArrayList<Long>>() {}.getType()); |
| | | if (list == null || list.size() == 0) { |
| | | out.print(JsonUtil.loadFalseResult("未选择商品")); |
| | | return; |
| | | } |
| | | |
| | | userGoodsStorageService.deleteBatchByUidAndPrimaryKey(uid, list); |
| | | out.print(JsonUtil.loadTrueResult("删除成功")); |
| | | |
| | | } catch (Exception e) { |
| | | out.print(JsonUtil.loadFalseResult("删除失败")); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 分享商品返回二维码图片 |
| | | * |
| | | * @param storageIds |
| | | * id数组 |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "sharegoods", method = RequestMethod.POST) |
| | | public void shareGoods(AcceptData acceptData, Long uid, String storageIds, PrintWriter out) { |
| | | |
| | | if (StringUtil.isNullOrEmpty(storageIds)) { |
| | | out.print(JsonUtil.loadFalseResult("分享商品不能为空")); |
| | | return; |
| | | } |
| | | |
| | | if (uid == null) { |
| | | out.print(JsonUtil.loadFalseResult("用户未登录")); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | Gson gson = new Gson(); |
| | | List<Long> listStorageID = gson.fromJson(storageIds, new TypeToken<ArrayList<Long>>() {}.getType()); |
| | | if (listStorageID == null || listStorageID.size() < 9) { |
| | | out.print(JsonUtil.loadFalseResult("分享商品数量不足")); |
| | | return; |
| | | } |
| | | |
| | | if (listStorageID.size() != 9) { |
| | | out.print(JsonUtil.loadFalseResult("分享商品数量只能是9个")); |
| | | return; |
| | | } |
| | | |
| | | JSONObject data = userGoodsStorageService.shareGoods(uid, listStorageID); |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | |
| | | } catch (UserGoodsStorageException e) { |
| | | out.print(JsonUtil.loadFalseResult("分享失败")); |
| | | e.printStackTrace(); |
| | | } catch (UserShareGoodsRecordException e) { |
| | | out.print(JsonUtil.loadFalseResult("分享失败")); |
| | | e.printStackTrace(); |
| | | } catch (Exception e) { |
| | | out.print(JsonUtil.loadFalseResult("分享失败")); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |