| | |
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | import org.fanli.facade.goods.entity.usergoods.UserGoodsStorage;
|
| | | import org.fanli.facade.goods.entity.usergoods.UserShareGoodsRecord.ShareSourceTypeEnum;
|
| | | import org.fanli.facade.goods.exception.taobao.CommonGoodsException;
|
| | | import org.fanli.facade.goods.exception.taobao.TaobaoGoodsDownException;
|
| | | import org.fanli.facade.goods.exception.taoke.TaoKeApiException;
|
| | | import org.fanli.facade.goods.exception.usergoods.UserGoodsStorageException;
|
| | | import org.fanli.facade.goods.exception.usergoods.UserShareGoodsRecordException;
|
| | | import org.fanli.facade.goods.service.taobao.CommonGoodsService;
|
| | | import org.fanli.facade.goods.service.usergoods.UserGoodsStorageService;
|
| | | import org.fanli.facade.goods.service.usergoods.UserShareGoodsRecordService;
|
| | | import org.fanli.facade.goods.utils.RedisGoodsManager;
|
| | | import org.fanli.facade.goods.utils.dataoke.TaoKeApiUtil;
|
| | | import org.fanli.facade.goods.utils.factory.CommonGoodsFactory;
|
| | | import org.fanli.facade.goods.utils.taobao.TaoBaoUtil;
|
| | | import org.fanli.facade.order.service.hongbao.HongBaoManageService;
|
| | | import org.fanli.facade.goods.utils.taobao.TaoKeGoodsApiUtil;
|
| | | import org.fanli.facade.system.exception.TaoKeApiException;
|
| | | import org.fanli.facade.system.service.common.ConfigService;
|
| | | import org.fanli.facade.system.service.hongbao.HongBaoManageService;
|
| | | import org.springframework.core.task.TaskExecutor;
|
| | | import com.alibaba.dubbo.config.annotation.Service;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | | import org.yeshi.utils.MoneyBigDecimalUtil;
|
| | |
|
| | | import com.alibaba.dubbo.config.annotation.Service;
|
| | | import com.google.gson.Gson;
|
| | | import com.google.gson.GsonBuilder;
|
| | | import com.yeshi.fanli.base.entity.goods.CommonGoods;
|
| | | import com.yeshi.fanli.base.entity.goods.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.goods.dao.usergoods.UserGoodsStorageMapper;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | @Service(version = "1.0.0")
|
| | | public class UserGoodsStorageServiceImpl implements UserGoodsStorageService {
|
| | | |
| | |
|
| | | @Resource(name = "taskExecutor")
|
| | | private TaskExecutor executor;
|
| | | |
| | |
|
| | | @Resource
|
| | | private RedisGoodsManager redisManager;
|
| | | |
| | |
|
| | | @Resource
|
| | | private ConfigService configService;
|
| | | |
| | |
|
| | | @Resource
|
| | | private CommonGoodsService commonGoodsService;
|
| | | |
| | | @Resource
|
| | | private HongBaoManageService manageService;
|
| | |
|
| | | @Resource
|
| | | private UserGoodsStorageMapper userGoodsStorageMapper;
|
| | | |
| | |
|
| | | @Resource
|
| | | private UserShareGoodsRecordService userShareGoodsRecordService;
|
| | |
|
| | | @Resource
|
| | | private HongBaoManageService hongBaoManageService;
|
| | |
|
| | |
| | | public int deleteBatchByPrimaryKey(List<Long> list) {
|
| | | return userGoodsStorageMapper.deleteBatchByPrimaryKey(list);
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * 根据主键 、uid 批量删除
|
| | | * |
| | | * @param list
|
| | | * @return
|
| | | */
|
| | |
| | | public List<UserGoodsStorage> listQueryByUid(long start, int count, Long uid) {
|
| | | return userGoodsStorageMapper.listQueryByUid(start, count, uid);
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public UserGoodsStorage getByUidAndAuctionId(Long uid, Long auctionId) {
|
| | | return userGoodsStorageMapper.getByUidAndAuctionId(uid, auctionId);
|
| | |
| | | public long countQueryByUid(Long uid) {
|
| | | return userGoodsStorageMapper.countQueryByUid(uid);
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public void updateShareState(Long shareId) {
|
| | | userGoodsStorageMapper.updateShareState(shareId);
|
| | |
| | | userGoodsStorageMapper.updateByPrimaryKeySelective(goodsStorage);
|
| | | } else {
|
| | | goodsStorage = new UserGoodsStorage();
|
| | | goodsStorage.setUid(uid);;
|
| | | goodsStorage.setUid(uid);
|
| | | ;
|
| | | goodsStorage.setState(UserGoodsStorage.STATE_NORMAL);
|
| | | goodsStorage.setCommonGoods(commonGoods);
|
| | | goodsStorage.setCreateTime(new Date());
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | |
| | | @Override
|
| | | public JSONArray getMyStorage(int page, int pageSize, Long uid) throws UserGoodsStorageException {
|
| | | |
| | | JSONArray array = new JSONArray();
|
| | |
|
| | | List<UserGoodsStorage> listStorage = listQueryByUid(page , pageSize, uid);
|
| | | JSONArray array = new JSONArray();
|
| | |
|
| | | List<UserGoodsStorage> listStorage = listQueryByUid(page, pageSize, uid);
|
| | | if (listStorage == null || listStorage.size() == 0) {
|
| | | return array;
|
| | | }
|
| | | |
| | | |
| | |
|
| | | List<Long> listGid = new ArrayList<Long>();
|
| | | for (UserGoodsStorage userGoodsStorage : listStorage) {
|
| | | CommonGoods commonGoods = userGoodsStorage.getCommonGoods();
|
| | |
| | | }
|
| | | listGid.add(commonGoods.getGoodsId());
|
| | | }
|
| | | |
| | |
|
| | | // API网络接口验证是否在售
|
| | | List<TaoBaoGoodsBrief> listTaoKeGoods = null;
|
| | | try {
|
| | | listTaoKeGoods = TaoKeApiUtil.getBatchGoodsInfo(listGid);
|
| | | listTaoKeGoods = TaoKeGoodsApiUtil.getBatchGoodsInfo(listGid);
|
| | | } catch (TaoKeApiException e) {
|
| | | e.printStackTrace();
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | |
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | |
| | | BigDecimal rate = manageService.getFanLiRate();
|
| | |
|
| | | BigDecimal rate = hongBaoManageService.getFanLiRate();
|
| | | Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
|
| | | .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
|
| | | |
| | |
|
| | | for (UserGoodsStorage userGoodsStorage : listStorage) {
|
| | | CommonGoods commonGoods = userGoodsStorage.getCommonGoods();
|
| | | if (commonGoods == null) {
|
| | | continue;
|
| | | }
|
| | | |
| | | if (listTaoKeGoods != null && listTaoKeGoods.size() > 0 ) {
|
| | | int state = 1; // 默认停售
|
| | |
|
| | | if (listTaoKeGoods != null && listTaoKeGoods.size() > 0) {
|
| | | int state = 1; // 默认停售
|
| | | Long goodsId = commonGoods.getGoodsId();
|
| | | for (TaoBaoGoodsBrief taoKeGoods: listTaoKeGoods) {
|
| | | for (TaoBaoGoodsBrief taoKeGoods : listTaoKeGoods) {
|
| | | Long auctionId = taoKeGoods.getAuctionId();
|
| | | if (goodsId == auctionId || goodsId.equals(auctionId)) {
|
| | | state = 0; // 在售
|
| | |
| | | }
|
| | | commonGoods.setState(state);
|
| | | }
|
| | | |
| | |
|
| | | TaoBaoGoodsBrief goodsBrief = TaoBaoUtil.convert(commonGoods);
|
| | | |
| | |
|
| | | // 判断是否已分享
|
| | | Integer storageState = userGoodsStorage.getState();
|
| | | if (storageState != null && storageState == UserGoodsStorage.STATE_SHARED) {
|
| | |
| | | goodsBrief.setState(2); // 已分享状态 优先显示已下架
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | String json = gson.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(goodsBrief, rate.toString(), null));
|
| | | |
| | |
|
| | | JSONObject dataObject = new JSONObject();
|
| | | dataObject.put("storageId", userGoodsStorage.getId());
|
| | | dataObject.put("goods", json);
|
| | | array.add(dataObject);
|
| | | }
|
| | | |
| | |
|
| | | return array;
|
| | | }
|
| | | |
| | | |
| | |
|
| | | @Override
|
| | | public boolean isExistStorage(Long uid, Long auctionId) {
|
| | | boolean state = false;
|
| | |
| | | }
|
| | | return state;
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public JSONObject shareGoods(Long uid, List<Long> listStorageID) |
| | | public JSONObject shareGoods(Long uid, List<Long> listStorageID)
|
| | | throws UserGoodsStorageException, UserShareGoodsRecordException {
|
| | | |
| | |
|
| | | List<UserGoodsStorage> listStorage = userGoodsStorageMapper.listQueryByIds(listStorageID);
|
| | | if (listStorage == null || listStorage.size() == 0) {
|
| | | throw new UserGoodsStorageException(1, "选品库商品不存在");
|
| | | }
|
| | | |
| | | |
| | |
|
| | | List<UserGoodsStorage> listResult = new ArrayList<UserGoodsStorage>();
|
| | | // 还原顺序 用于制图
|
| | | for (Long sid: listStorageID) {
|
| | | for (UserGoodsStorage torage: listStorage) {
|
| | | for (Long sid : listStorageID) {
|
| | | for (UserGoodsStorage torage : listStorage) {
|
| | | Long id = torage.getId();
|
| | | if (sid == id || sid.equals(id)) {
|
| | | listResult.add(torage);
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | |
| | |
|
| | | BigDecimal totalMoney = new BigDecimal(0.00);
|
| | | List<TaoBaoGoodsBrief> listGoodsBrief = new ArrayList<TaoBaoGoodsBrief>();
|
| | | |
| | | String rateStr = hongBaoManageService.get("hongbao_goods_proportion");
|
| | | |
| | | for (UserGoodsStorage userGoodsStorage: listResult) {
|
| | |
|
| | | BigDecimal rate = hongBaoManageService.getFanLiRate();
|
| | |
|
| | | for (UserGoodsStorage userGoodsStorage : listResult) {
|
| | | CommonGoods commonGoods = userGoodsStorage.getCommonGoods();
|
| | | TaoBaoGoodsBrief goodsBrief = TaoBaoUtil.convert(commonGoods);
|
| | | listGoodsBrief.add(goodsBrief);
|
| | | |
| | | BigDecimal money = TaoBaoUtil.getGoodsHongBaoMoney(goodsBrief, new BigDecimal(rateStr));
|
| | | BigDecimal money = TaoBaoUtil.getGoodsHongBaoMoney(goodsBrief, rate);
|
| | | totalMoney = MoneyBigDecimalUtil.add(totalMoney, money);
|
| | | }
|
| | | |
| | | String revenue = listGoodsBrief.size() + "个商品预估分享奖金:¥"+totalMoney;
|
| | | |
| | | Map<String,Object> map = userShareGoodsRecordService.save(uid, ShareSourceTypeEnum.storage, |
| | | null, listGoodsBrief);
|
| | | |
| | |
|
| | | String revenue = listGoodsBrief.size() + "个商品预估分享奖金:¥" + totalMoney;
|
| | |
|
| | | Map<String, Object> map = userShareGoodsRecordService.save(uid, ShareSourceTypeEnum.storage, null,
|
| | | listGoodsBrief);
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("revenue", revenue);
|
| | | data.put("shareId", map.get("shareId"));
|