Subversion Repositories SmartDukaan

Rev

Rev 33873 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.spice.profitmandi.web.controller;

import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;

import com.spice.profitmandi.dao.cart.SmartCartService;
import com.spice.profitmandi.dao.entity.cs.PartnerRegion;
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
import com.spice.profitmandi.dao.model.*;
import com.spice.profitmandi.service.inventory.*;
import com.spice.profitmandi.web.services.SolrService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.spice.profitmandi.common.enumuration.MessageType;
import com.spice.profitmandi.common.model.CustomRetailer;
import com.spice.profitmandi.common.model.ProfitMandiConstants;
import com.spice.profitmandi.common.model.SendNotificationModel;
import com.spice.profitmandi.common.services.mandii.MandiiService;
import com.spice.profitmandi.common.web.util.ResponseSender;
import com.spice.profitmandi.dao.cart.CartService;
import com.spice.profitmandi.dao.entity.auth.AuthUser;
import com.spice.profitmandi.dao.entity.catalog.FocusedModelByPassRequest;
import com.spice.profitmandi.dao.entity.cs.Position;
import com.spice.profitmandi.dao.entity.dtr.User;
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
import com.spice.profitmandi.dao.entity.fofo.FofoPayment;
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
import com.spice.profitmandi.dao.enumuration.catalog.ByPassRequestStatus;
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
import com.spice.profitmandi.dao.enumuration.fofo.PaymentStatus;
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
import com.spice.profitmandi.dao.repository.catalog.FocusedModelByPassRepository;
import com.spice.profitmandi.dao.repository.catalog.FocusedModelRepository;
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
import com.spice.profitmandi.dao.repository.cs.CsService;
import com.spice.profitmandi.dao.repository.cs.PartnerRegionRepository;
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
import com.spice.profitmandi.dao.repository.dtr.RetailerBlockBrandsRepository;
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
import com.spice.profitmandi.dao.repository.fofo.FofoPaymentRepository;
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
import com.spice.profitmandi.dao.util.ContentPojoPopulator;
import com.spice.profitmandi.service.FofoUser;
import com.spice.profitmandi.service.NotificationService;
import com.spice.profitmandi.service.PartnerInvestmentService;
import com.spice.profitmandi.service.transaction.TransactionService;
import com.spice.profitmandi.service.user.RetailerService;
import com.spice.profitmandi.service.wallet.WalletService;
import com.spice.profitmandi.web.res.ValidateCartResponse;

import in.shop2020.model.v1.order.WalletReferenceType;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Controller
@Transactional(readOnly = true, rollbackFor = Throwable.class)
public class SmartCartController {

    private static final Logger logger = LogManager.getLogger(SmartCartController.class);

    @Autowired
    private ResponseSender<?> responseSender;

    @Autowired
    private UserAccountRepository userAccountRepository;

    @Autowired
    CartService cartService;

    @Autowired
    private SmartCartService smartCartService;

    @Autowired
    private SolrService solrService;






    @RequestMapping(value = "/cart/createSmartCart", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<?> createSmartCart(HttpServletRequest request, Model model) throws Exception {

        int userId = (int) request.getAttribute("userId");
        int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);

        logger.info("retailerId- {}",retailerId);

        Set<Integer> smartCartReadyCatalogIds = smartCartService.getAllItemIdsForSmartCartOfPartner(retailerId);

        logger.info("smartCartReadyCatalogIds {}",smartCartReadyCatalogIds);

        List<FofoCatalogResponse> dealResponse = new ArrayList<>();

        if(smartCartReadyCatalogIds.size() >0 ){

            dealResponse = solrService.dealResponse(smartCartReadyCatalogIds,retailerId);
        }

        return responseSender.ok(dealResponse);
    }


}