Rev 34906 | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.dao.service;import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;import com.spice.profitmandi.dao.entity.affiliate.AffiliateEarnings;import com.spice.profitmandi.dao.entity.affiliate.AffiliateProduct;import com.spice.profitmandi.dao.entity.fofo.Customer;import com.spice.profitmandi.dao.entity.fofo.PendingOrderItem;import com.spice.profitmandi.dao.repository.affiliate.AffiliateRepository;import com.spice.profitmandi.dao.repository.affiliateLink.AffiliateLinkRepository;import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;import com.spice.profitmandi.dao.repository.fofo.PendingOrderItemRepository;import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component;import java.time.LocalDateTime;import java.util.HashMap;import java.util.List;import java.util.Map;@Componentpublic class AffiliateServiceImpl implements AffiliateService {private static final Logger logger = LogManager.getLogger(AffiliateServiceImpl.class);@AutowiredAffiliateRepository affiliateRepository;@AutowiredAffiliateLinkRepository affiliateLinkRepository;@AutowiredPendingOrderItemRepository orderItemRepository;@AutowiredCustomerRepository customerRepository;@Overridepublic void createEarnings(AffiliateEarnings earnings) {affiliateRepository.persist(earnings);}@Overridepublic List<AffiliateEarnings> getEarnings(int customerId) {return affiliateRepository.findEarningsByCustomerId(customerId);}@Overridepublic Map<String,Object> getAffiliateData(int customerId) throws ProfitMandiBusinessException {Map<String,Object> resMap = new HashMap<>();Customer customer = customerRepository.selectById(customerId);if(customer!=null){List<AffiliateProduct> affiliateLinks = affiliateLinkRepository.findProductsByCustomerId(customerId);logger.info("AffiliateLinks size: {}",affiliateLinks);List<AffiliateEarnings> affiliateEarnings = affiliateRepository.findEarningsByCustomerId(customerId);String code = customer.getFirstName().substring(0, 1).toUpperCase() + customer.getLastName().substring(0, 1).toUpperCase() + customer.getId();List<PendingOrderItem> orderItems = orderItemRepository.selectAllByCustomer(code);logger.info("affiliateEarnings: {}",affiliateEarnings);resMap.put("affiliateLinks", affiliateLinks);resMap.put("affiliateEarnings", affiliateEarnings);resMap.put("affiliateOrders", orderItems);} else {resMap.put("affiliateLinks", "[]");resMap.put("affiliateEarnings", "[]");resMap.put("affiliateOrders", "[]");}return resMap;}}