Rev 35435 | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.web.controller;import java.time.LocalDateTime;import java.util.Date;import java.util.List;import java.util.Set;import javax.servlet.http.HttpServletRequest;import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Qualifier;import org.springframework.http.ResponseEntity;import org.springframework.stereotype.Controller;import org.springframework.transaction.annotation.Transactional;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.ResponseCodeHolder;import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;import com.spice.profitmandi.common.model.ProfitMandiConstants;import com.spice.profitmandi.common.model.UserInfo;import com.spice.profitmandi.common.util.StringUtils;import com.spice.profitmandi.common.util.Utils;import com.spice.profitmandi.common.web.util.ResponseSender;import com.spice.profitmandi.dao.entity.dtr.Brand;import com.spice.profitmandi.dao.entity.dtr.DistrictMaster;import com.spice.profitmandi.dao.entity.dtr.Document;import com.spice.profitmandi.dao.entity.dtr.Retailer;import com.spice.profitmandi.dao.entity.dtr.RetailerBrand;import com.spice.profitmandi.dao.entity.dtr.RetailerRegisteredAddress;import com.spice.profitmandi.dao.entity.dtr.Shop;import com.spice.profitmandi.dao.entity.dtr.ShopAddress;import com.spice.profitmandi.dao.entity.dtr.User;import com.spice.profitmandi.dao.entity.dtr.UserAccount;import com.spice.profitmandi.dao.entity.dtr.UserRole;import com.spice.profitmandi.dao.entity.fofo.FofoStore;import com.spice.profitmandi.dao.entity.user.Address;import com.spice.profitmandi.dao.entity.user.Cart;import com.spice.profitmandi.dao.entity.user.Counter;import com.spice.profitmandi.dao.entity.user.PrivateDealUser;import com.spice.profitmandi.dao.entity.user.PrivateDealUserAddressMapping;import com.spice.profitmandi.dao.enumuration.dtr.AccountType;import com.spice.profitmandi.dao.enumuration.dtr.RoleType;import com.spice.profitmandi.dao.model.RetailerFofoInterest;import com.spice.profitmandi.dao.repository.dtr.BrandRepository;import com.spice.profitmandi.dao.repository.dtr.DistrictMasterRepository;import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;import com.spice.profitmandi.dao.repository.dtr.Mongo;import com.spice.profitmandi.dao.repository.dtr.RetailerAddressRepository;import com.spice.profitmandi.dao.repository.dtr.RetailerBrandRepository;import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;import com.spice.profitmandi.dao.repository.dtr.RoleRepository;import com.spice.profitmandi.dao.repository.dtr.ShopAddressRepository;import com.spice.profitmandi.dao.repository.dtr.ShopRepository;import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;import com.spice.profitmandi.dao.repository.dtr.UserRepository;import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;import com.spice.profitmandi.dao.repository.user.AddressRepository;import com.spice.profitmandi.dao.repository.user.CartRepository;import com.spice.profitmandi.dao.repository.user.CounterRepository;import com.spice.profitmandi.dao.repository.user.PrivateDealUserAddressMappingRepository;import com.spice.profitmandi.dao.repository.user.PrivateDealUserRepository;import com.spice.profitmandi.service.user.RetailerService;import com.spice.profitmandi.web.req.Category;import com.spice.profitmandi.web.req.CreateRetailerAddressRequest;import com.spice.profitmandi.web.req.CreateRetailerRequest;import com.spice.profitmandi.web.req.RetailerAddBrandRequest;import in.shop2020.model.v1.inventory.StateInfo;import in.shop2020.model.v1.user.CartStatus;import io.swagger.annotations.ApiImplicitParam;import io.swagger.annotations.ApiImplicitParams;import io.swagger.annotations.ApiOperation;@Controller@Transactional(rollbackFor=Throwable.class)public class RetailerController {private static final Logger LOGGER=LogManager.getLogger(RetailerController.class);@Autowired@Qualifier("userRepository")private UserRepository userRepository;@Autowired@Qualifier("userUserRepository")private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;@Autowiredprivate RetailerService retailerService;@Autowiredprivate UserRoleRepository userRoleRepository;@Autowiredprivate RoleRepository roleRepository;@Autowiredprivate ResponseSender<?> responseSender;@Autowiredprivate RetailerRepository retailerRepository;@Autowiredprivate BrandRepository brandRepository;@Autowiredprivate AddressRepository addressRepository;@Autowiredprivate DocumentRepository documentRepository;@Autowiredprivate ShopRepository shopRepository;@Autowiredprivate UserAccountRepository userAccountRepository;@Autowiredprivate RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;@Autowiredprivate RetailerAddressRepository retailerAddressRepository;@Autowiredprivate ShopAddressRepository shopAddressRepository;@Autowiredprivate RetailerBrandRepository retailerBrandRepository;@Autowiredprivate CounterRepository counterRepository;@Autowiredprivate PrivateDealUserRepository privateDealUserRepository;@Autowiredprivate PrivateDealUserAddressMappingRepository privateDealUserAddressMappingRepository;@Autowiredprivate CartRepository cartRepository;@Autowiredprivate DistrictMasterRepository districtMasterRepository;@Autowiredprivate FofoStoreRepository fofoStoreRepository;@Autowiredprivate Mongo mongoClient;@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",required = true, dataType = "string", paramType = "header")})@ApiOperation(value = "Create Retailer")@RequestMapping(value = ProfitMandiConstants.URL_RETAILER, method=RequestMethod.POST)public ResponseEntity<?> createRetailer(HttpServletRequest request, @RequestBody CreateRetailerRequest createRetailerRequest) throws ProfitMandiBusinessException{LOGGER.info("request received with body [{}] at url {{}}: ", createRetailerRequest, request.getRequestURL().toString());UserInfo userInfo = (UserInfo)request.getAttribute("userInfo");LOGGER.info("requestAttribute [userInfo={}]", userInfo);User user = userRepository.selectById(userInfo.getUserId());this.createRetailer(user, createRetailerRequest);return responseSender.ok(ResponseCodeHolder.getMessage("RTLR_OK_1000"));}private void createRetailer(User user, CreateRetailerRequest createRetailerRequest)throws ProfitMandiBusinessException{Retailer retailer = new Retailer();retailer.setName(createRetailerRequest.getName());retailer.setNumber(createRetailerRequest.getNumber());retailer.setType(createRetailerRequest.getType());retailer.setMonthlySaleValue(createRetailerRequest.getMonthlySaleValue());retailer.setMonthlySaleVolume(createRetailerRequest.getMonthlySaleVolume());retailer.setPrimaryBuyingMode(createRetailerRequest.getPrimaryBuyingMode());retailer.setRecharge(createRetailerRequest.getLineOfBusiness().isRecharge());retailer.setMobile(createRetailerRequest.getLineOfBusiness().isMobile());retailer.setAccessories(createRetailerRequest.getLineOfBusiness().isAccessories());retailer.setOther1(createRetailerRequest.getLineOfBusiness().getOther1());retailer.setOther2(createRetailerRequest.getLineOfBusiness().getOther2());if(createRetailerRequest.getDocumentId() == 0){retailer.setDocumentId(null);}else{/*Document retailerDocument = documentRepository.selectById(createRetailerRequest.getDocumentId());if(retailerRepository.isExistByDocumentId(retailerDocument.getId())){LOGGER.error("documet is already mapped with another retailer");throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, retailerDocument.getId(), "DCMNT_1000");}*/retailer.setDocumentId(createRetailerRequest.getDocumentId());documentRepository.markDocumentAsPersisted(createRetailerRequest.getDocumentId());}Shop shop = new Shop();shop.setName(createRetailerRequest.getShop().getName());if(createRetailerRequest.getShop().getDocumentId() == 0){shop.setDocumentId(null);}else{/*final Document shopDocument = documentRepository.selectById(createRetailerRequest.getShop().getDocumentId());if(shopRepository.isExistByDocumentId(shopDocument.getId())){throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, shopDocument.getId(), "DCMNT_1000");}*/shop.setDocumentId(createRetailerRequest.getShop().getDocumentId());documentRepository.markDocumentAsPersisted(createRetailerRequest.getShop().getDocumentId());}com.spice.profitmandi.dao.entity.user.User saholicUser = null;boolean foundRetailerFlag = false;try {saholicUser = userUserRepository.selectByEmailId(user.getEmailId());}catch (ProfitMandiBusinessException e) {LOGGER.info("User doesnt exist in old system");}if(saholicUser == null){Cart cart = new Cart();cart.setCartStatus(CartStatus.ACTIVE);cartRepository.persist(cart);saholicUser = new com.spice.profitmandi.dao.entity.user.User();saholicUser.setEmailId(user.getEmailId());saholicUser.setName(createRetailerRequest.getName());saholicUser.setActiveCartId(cart.getId());saholicUser.setCreateTimestamp(LocalDateTime.now());userUserRepository.persist(saholicUser);}else{foundRetailerFlag = true;}Retailer foundRetailer = null;try{foundRetailer = retailerRepository.selectById(saholicUser.getId());}catch(ProfitMandiBusinessException profitMandiBusinessException){LOGGER.info("Retailer is not registered");}if(foundRetailer != null){throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, saholicUser.getEmailId(), "RTLR_1011");}//in.shop2020.model.v1.user.User saholicUser = Utils.createSaholicUser(user.getEmailId());retailer.setId(saholicUser.getId());retailerRepository.persist(retailer);shop.setRetailerId(retailer.getId());//LOGGER.info("Shop is persisting ... [{}]",shop);shopRepository.persist(shop);this.addBrandWithRetailer(retailer.getId(), createRetailerRequest.getCategories());final Address addressRetailer = this.createAddress(createRetailerRequest.getAddress());addressRetailer.setRetaierId(retailer.getId());addressRepository.persist(addressRetailer);final RetailerRegisteredAddress retailerRegisteredAddress = new RetailerRegisteredAddress();retailerRegisteredAddress.setRetailerId(retailer.getId());retailerRegisteredAddress.setAddressId(addressRetailer.getId());retailerRegisteredAddressRepository.persist(retailerRegisteredAddress);if(!createRetailerRequest.isShopAddressSameAsRetailerAddress() && createRetailerRequest.getAddress() == null){throw new ProfitMandiBusinessException(ProfitMandiConstants.ADDRESS, "", "");}if(createRetailerRequest.isShopAddressSameAsRetailerAddress()){ShopAddress shopAddress = new ShopAddress();shopAddress.setShopId(shop.getId());shopAddress.setAddressId(addressRetailer.getId());shopAddressRepository.persist(shopAddress);}else{final Address addressShop = this.createAddress(createRetailerRequest.getShop().getAddress());addressShop.setRetaierId(retailer.getId());addressShop.setName(createRetailerRequest.getShop().getName());addressRepository.persist(addressShop);ShopAddress shopAddress = new ShopAddress();shopAddress.setShopId(shop.getId());shopAddress.setAddressId(addressShop.getId());shopAddressRepository.persist(shopAddress);}UserAccount ua = new UserAccount();ua.setAccountKey(saholicUser.getId());ua.setUserId(user.getId());ua.setType(AccountType.saholic);userAccountRepository.persist(ua);UserAccount ua2 = new UserAccount();ua2.setAccountKey(saholicUser.getActiveCartId());ua2.setUserId(user.getId());ua2.setType(AccountType.cartId);userAccountRepository.persist(ua2);UserRole ur = new UserRole();ur.setRoleId(roleRepository.selectByName(RoleType.RETAILER.name()).getId());ur.setUserId(user.getId());userRoleRepository.persist(ur);if(foundRetailerFlag){LOGGER.info("\n\n\n****retailer found\n\n\n");PrivateDealUser privateDealUser = null;try{privateDealUser = privateDealUserRepository.selectById(saholicUser.getId());}catch(ProfitMandiBusinessException profitMandiBusinessException){LOGGER.error("PrivateDealUser not found : ", profitMandiBusinessException);}if(privateDealUser == null) {privateDealUser = new PrivateDealUser();privateDealUser.setActive(true);privateDealUser.setBulkShipmentAmountLimit(50000);privateDealUser.setId(saholicUser.getId());privateDealUserRepository.persist(privateDealUser);PrivateDealUserAddressMapping privateDealUserAddressMapping = new PrivateDealUserAddressMapping();privateDealUserAddressMapping.setUserId(retailer.getId());privateDealUserAddressMapping.setAddressId(addressRetailer.getId());privateDealUserAddressMappingRepository.persist(privateDealUserAddressMapping);}if(privateDealUser.getCounterId() == null){Integer counterId = this.createCounter(user.getEmailId(), createRetailerRequest.getGstNumber(), user.getMobileNumber(), retailer.getName(), addressRetailer.getId());privateDealUser.setCounterId(counterId);privateDealUserRepository.persist(privateDealUser);}}else{LOGGER.info("retailer not found");//gst number intergration with counterInteger counterId = this.createCounter(user.getEmailId(), createRetailerRequest.getGstNumber(), user.getMobileNumber(), retailer.getName(), addressRetailer.getId());PrivateDealUser privateDealUser = null;try{privateDealUser = privateDealUserRepository.selectById(saholicUser.getId());}catch(ProfitMandiBusinessException profitMandiBusinessException){LOGGER.warn("PrivateDealUser not found");}if(privateDealUser != null){//LOGGER.info("PrivateDealUser found with id [{}]", saholicUser.getId());privateDealUser.setCounterId(counterId);privateDealUserRepository.update(privateDealUser);}else{LOGGER.info("PrivateDealUser not found with id [{}], creating it", saholicUser.getId());privateDealUser = new PrivateDealUser();privateDealUser.setActive(true);privateDealUser.setBulkShipmentAmountLimit(50000);privateDealUser.setId(saholicUser.getId());privateDealUser.setCounterId(counterId);privateDealUserRepository.persist(privateDealUser);}PrivateDealUserAddressMapping privateDealUserAddressMapping = new PrivateDealUserAddressMapping();privateDealUserAddressMapping.setUserId(retailer.getId());privateDealUserAddressMapping.setAddressId(addressRetailer.getId());privateDealUserAddressMappingRepository.persist(privateDealUserAddressMapping);saholicUser.setAddressId(addressRetailer.getId());userUserRepository.persist(saholicUser);}}private Integer createCounter(String emailId, String gstNumber, String mobileNumber, String name, int addressId){if(gstNumber != null && !gstNumber.isEmpty()){Counter counter = new Counter();counter.setEmailId(emailId);counter.setGstin(gstNumber);counter.setMobileNumber(mobileNumber);counter.setName(name);counter.setAddressId(addressId);counter.setCreatedOn(LocalDateTime.now());counterRepository.persist(counter);return counter.getId();}else{return null;}}private void addBrandWithRetailer(int retailerId, Set<Category> categories)throws ProfitMandiBusinessException{for(Category category : categories){for(com.spice.profitmandi.web.req.Brand brandModel : category.getBrands()){Brand brand = brandRepository.selectByIdAndName(brandModel.getId(), brandModel.getName());final RetailerBrand retailerBrand = new RetailerBrand();retailerBrand.setRetailerId(retailerId);retailerBrand.setBrandId(brand.getId());retailerBrandRepository.persist(retailerBrand);}}}@ApiOperation(value = "Create Fofo Store")@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_FOFO_FOFO_STORE, method=RequestMethod.POST)public ResponseEntity<?> createFofoStore(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.DISTRICT_NAME) String districtName) throws ProfitMandiBusinessException, Exception{UserInfo userInfo = (UserInfo)request.getAttribute("userInfo");LOGGER.info("requestAttribute [userInfo={}]", userInfo);User user = userRepository.selectById(userInfo.getUserId());// = userAccountRepository.selectRetailerIdByUserId(user.getId());UserAccount userAccounts = userAccountRepository.selectSaholicByUserId(user.getId());Retailer retailer = retailerRepository.selectById(userAccounts.getAccountKey());try{userRoleRepository.selectByUserIdAndRoleId(user.getId(), roleRepository.selectByName(RoleType.FOFO.name()).getId());}catch(ProfitMandiBusinessException profitMandiBusinessException){throw new ProfitMandiBusinessException(ProfitMandiConstants.USER_ID, user.getId(), "USR_1013");}boolean foundFofoStore = false;try{fofoStoreRepository.selectByRetailerId(retailer.getId());foundFofoStore = true;}catch (ProfitMandiBusinessException profitMandiBusinessException) {}if(foundFofoStore){throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "USR_1014");}int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailer.getId());Address retailerAddress = addressRepository.selectById(retailerAddressId);StateInfo stateInfo = Utils.getStateInfo(retailerAddress.getState());DistrictMaster districtMaster = districtMasterRepository.selectByNameAndStateShortName(districtName, stateInfo.getShortName());FofoStore fofoStore = new FofoStore();String latestStoreCode = fofoStoreRepository.selectLatestStore().getCode();int latestCodeCounter = Integer.parseInt(latestStoreCode.replaceAll("[A-Z]", ""));fofoStore.setId(retailer.getId());String fofoStoreCode = StringUtils.generateFofoStoreSequence(districtMaster.getStateShortName() + districtMaster.getShortName(), latestCodeCounter + 1);fofoStore.setCode(fofoStoreCode);fofoStoreRepository.persist(fofoStore);return responseSender.ok(ResponseCodeHolder.getMessage("RTLR_OK_1003"));}@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_EMAIL_ID_OR_MOBILE_NUMBER, method = RequestMethod.GET)public ResponseEntity<?> getByEmailIdOrMobileNumber(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.EMAIL_ID_OR_MOBILE_NUMBER) String emailIdOrMobileNumber) throws ProfitMandiBusinessException{LOGGER.info("Request Received at url {} with emailIdOrMobileNumber {}", request.getRequestURI(), emailIdOrMobileNumber);return responseSender.ok(retailerService.getByEmailIdOrMobileNumber(emailIdOrMobileNumber));}@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ALL,method=RequestMethod.GET)public ResponseEntity<?> getAll(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PAGE_NUMBER) int pageNumber, @RequestParam(name = ProfitMandiConstants.PAGE_SIZE) int pageSize){LOGGER.info("requested url : "+request.getRequestURL().toString());return responseSender.ok(retailerRepository.selectAll(pageNumber, pageSize));}@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID, method=RequestMethod.GET)public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id) throws ProfitMandiBusinessException{LOGGER.info("requested url : "+request.getRequestURL().toString());return responseSender.ok(retailerRepository.selectById(id));}@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_NAME, method=RequestMethod.GET)public ResponseEntity<?> getByName(HttpServletRequest request, @RequestParam(name = "name") String name) throws ProfitMandiBusinessException{LOGGER.info("requested url : "+request.getRequestURL().toString());return responseSender.ok(retailerRepository.selectByName(name));}@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID,method=RequestMethod.DELETE)public ResponseEntity<?> removeById(HttpServletRequest request, @RequestParam(name = "id") int id) throws ProfitMandiBusinessException{LOGGER.info("requested url : "+request.getRequestURL().toString());retailerRepository.deleteById(id);return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));}@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_ADD, method=RequestMethod.POST)public ResponseEntity<?> addShop(HttpServletRequest request, @RequestBody com.spice.profitmandi.web.req.Shop createShop, @RequestParam(name = "retailerId") int retailerId) throws ProfitMandiBusinessException{LOGGER.info("requested url : "+request.getRequestURL().toString());Document document = documentRepository.selectById(createShop.getDocumentId());if(shopRepository.isExistByDocumentId(createShop.getDocumentId())){LOGGER.error("documet is already mapped with another shop");throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "");}retailerRepository.selectById(retailerId);Shop shop = new Shop();shop.setRetailerId(retailerId);Address address = this.createAddress(createShop.getAddress());addressRepository.persist(address);shop.setAddressId(address.getId());shop.setDocumentId(document.getId());shopRepository.persist(shop);ShopAddress shopAddress = new ShopAddress();shopAddress.setAddressId(address.getId());shopAddress.setShopId(shop.getId());shopAddressRepository.persist(shopAddress);return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));}@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_REMOVE, method=RequestMethod.DELETE)public ResponseEntity<?> removeShop(HttpServletRequest request, @RequestParam(name = "shopId") int shopId, @RequestParam(name = "retailerId") int retailerId) throws ProfitMandiBusinessException{LOGGER.info("requested url : "+request.getRequestURL().toString());retailerRepository.removeShop(shopId, retailerId);return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));}private Address createAddress(com.spice.profitmandi.web.req.Address createAddress){Address address = new Address();address.setName(createAddress.getName());address.setLine1(createAddress.getLine1());address.setLine2(createAddress.getLine2());address.setLandmark(createAddress.getLandmark());address.setCity(createAddress.getCity());address.setState(createAddress.getState());address.setPinCode(createAddress.getPinCode());address.setCountry(createAddress.getCountry());address.setPhoneNumber(createAddress.getPhoneNumber());return address;}@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_ADD, method=RequestMethod.POST)public ResponseEntity<?> addAddress(HttpServletRequest request, @RequestBody CreateRetailerAddressRequest createRetailerAddress) throws ProfitMandiBusinessException{LOGGER.info("requested url : "+request.getRequestURL().toString());retailerRepository.addAddress(this.createAddress(createRetailerAddress.getAddress()), createRetailerAddress.getRetailerId());return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));}@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_REMOVE, method=RequestMethod.DELETE)public ResponseEntity<?> removeAddress(HttpServletRequest request, @RequestParam(name = "addressId") int addressId, @RequestParam(name = "retailerId") int retailerId) throws ProfitMandiBusinessException{LOGGER.info("requested url : "+request.getRequestURL().toString());retailerRepository.removeAddress(addressId, retailerId);return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));}@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_ADD, method=RequestMethod.POST)public ResponseEntity<?> addBrand(HttpServletRequest request, @RequestBody RetailerAddBrandRequest retailerAddBrandRequest) throws ProfitMandiBusinessException{LOGGER.info("requested url : "+request.getRequestURL().toString());retailerRepository.selectById(retailerAddBrandRequest.getRetailerId());this.addBrandWithRetailer(retailerAddBrandRequest.getRetailerId(), retailerAddBrandRequest.getCategories());return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));}@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_REMOVE, method=RequestMethod.DELETE)public ResponseEntity<?> removeBrand(HttpServletRequest request, @RequestParam(name = "brandId") int brandId, @RequestParam(name = "retailerId") int retailerId) throws ProfitMandiBusinessException{LOGGER.info("requested url : "+request.getRequestURL().toString());brandRepository.selectById(brandId);retailerRepository.selectById(retailerId);retailerBrandRepository.deleteByRetailerIdBrandId(retailerId, brandId);return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));}@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_DOCUMENT, method=RequestMethod.GET)public ResponseEntity<?> getDocumentById(HttpServletRequest request, @RequestParam(name = "retailerId") int retailerId) throws ProfitMandiBusinessException{LOGGER.info("requested url : "+request.getRequestURL().toString());return responseSender.ok(retailerRepository.selectDocumentById(retailerId));}@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_REGISTERED_ADDRESS, method=RequestMethod.GET)public ResponseEntity<?> getRegisteredAddressById(HttpServletRequest request, @RequestParam(name = "retailerId") int retailerId) throws ProfitMandiBusinessException{LOGGER.info("requested url : "+request.getRequestURL().toString());return responseSender.ok(retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId));}@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_ALL, method=RequestMethod.GET)public ResponseEntity<?> getAllShops(HttpServletRequest request, @RequestParam(name = "id") int id)throws ProfitMandiBusinessException{LOGGER.info("requested url : "+request.getRequestURL().toString());return responseSender.ok(shopRepository.selectByRetailerId(id));}@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_ALL, method=RequestMethod.GET)public ResponseEntity<?> getAllAddresses(HttpServletRequest request, @RequestParam(name = "id") int id) throws ProfitMandiBusinessException {LOGGER.info("requested url : "+request.getRequestURL().toString());List<Integer> addressIds = retailerAddressRepository.selectAddressIdsByRetailerId(id);return responseSender.ok(addressRepository.selectByIds(addressIds));}@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_ALL, method=RequestMethod.GET)public ResponseEntity<?> getAllBrads(HttpServletRequest request, @RequestParam(name = "id") int id){LOGGER.info("requested url : "+request.getRequestURL().toString());return responseSender.ok(retailerBrandRepository.selectBrandNamesByRetailerId(id));}@RequestMapping(value = "/retailer/showFofoInterest", method=RequestMethod.GET)public ResponseEntity<?> showFofoInterest(HttpServletRequest request) throws ProfitMandiBusinessException{UserInfo userInfo = (UserInfo)request.getAttribute("userInfo");User user = userRepository.selectById(userInfo.getUserId());RetailerFofoInterest retailerInterest = new RetailerFofoInterest();retailerInterest.setCity(user.getCity());retailerInterest.setMobile(user.getMobileNumber());retailerInterest.setUserId(userInfo.getUserId());if(user.getPinCode()!=null){retailerInterest.setPinCode(user.getPinCode());}retailerInterest.setInterestShownOn(new Date());LOGGER.info("requested url : "+request.getRequestURL().toString());return responseSender.ok(mongoClient.saveRetailerInterestOnFofo(retailerInterest));}@RequestMapping(value = "/retailer/hasRetailerShownInterest", method=RequestMethod.GET)public ResponseEntity<?> getAllBrads(HttpServletRequest request) throws Throwable{UserInfo userInfo = (UserInfo)request.getAttribute("userInfo");LOGGER.info("requested url : "+request.getRequestURL().toString());return responseSender.ok(mongoClient.hasRetailerShownInterest(userInfo.getUserId()));}}