Subversion Repositories SmartDukaan

Rev

Rev 34906 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
34902 vikas 1
package com.spice.profitmandi.dao.service;
2
 
34906 vikas 3
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
4
import com.spice.profitmandi.dao.entity.affiliate.AffiliateEarnings;
5
import com.spice.profitmandi.dao.entity.affiliate.AffiliateProduct;
6
import com.spice.profitmandi.dao.entity.fofo.Customer;
7
import com.spice.profitmandi.dao.entity.fofo.PendingOrderItem;
8
import com.spice.profitmandi.dao.repository.affiliate.AffiliateRepository;
9
import com.spice.profitmandi.dao.repository.affiliateLink.AffiliateLinkRepository;
10
import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;
11
import com.spice.profitmandi.dao.repository.fofo.PendingOrderItemRepository;
12
import org.apache.logging.log4j.LogManager;
13
import org.apache.logging.log4j.Logger;
14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.stereotype.Component;
16
 
17
import java.time.LocalDateTime;
18
import java.util.HashMap;
19
import java.util.List;
20
import java.util.Map;
21
 
22
@Component
34902 vikas 23
public class AffiliateServiceImpl implements AffiliateService {
34906 vikas 24
 
25
    private static final Logger logger = LogManager.getLogger(AffiliateServiceImpl.class);
26
 
27
    @Autowired
28
    AffiliateRepository affiliateRepository;
29
 
30
    @Autowired
31
    AffiliateLinkRepository affiliateLinkRepository;
32
 
33
    @Autowired
34
    PendingOrderItemRepository orderItemRepository;
35
 
36
    @Autowired
37
    CustomerRepository customerRepository;
38
 
34902 vikas 39
    @Override
34917 vikas 40
    public void createEarnings(AffiliateEarnings earnings) {
41
        affiliateRepository.persist(earnings);
42
    }
34906 vikas 43
 
44
    @Override
34917 vikas 45
    public List<AffiliateEarnings> getEarnings(int customerId) {
46
        return affiliateRepository.findEarningsByCustomerId(customerId);
34906 vikas 47
    }
48
 
49
    @Override
50
    public Map<String,Object> getAffiliateData(int customerId) throws ProfitMandiBusinessException {
51
        Map<String,Object> resMap = new HashMap<>();
52
        Customer customer = customerRepository.selectById(customerId);
53
        if(customer!=null){
54
            List<AffiliateProduct> affiliateLinks = affiliateLinkRepository.findProductsByCustomerId(customerId);
55
            logger.info("AffiliateLinks size: {}",affiliateLinks);
56
            List<AffiliateEarnings> affiliateEarnings = affiliateRepository.findEarningsByCustomerId(customerId);
57
            String code = customer.getFirstName().substring(0, 1).toUpperCase() + customer.getLastName().substring(0, 1).toUpperCase() + customer.getId();
58
            List<PendingOrderItem> orderItems = orderItemRepository.selectAllByCustomer(code);
59
            logger.info("affiliateEarnings: {}",affiliateEarnings);
60
            resMap.put("affiliateLinks", affiliateLinks);
61
            resMap.put("affiliateEarnings", affiliateEarnings);
62
            resMap.put("affiliateOrders", orderItems);
63
        } else {
64
            resMap.put("affiliateLinks", "[]");
65
            resMap.put("affiliateEarnings", "[]");
66
            resMap.put("affiliateOrders", "[]");
67
        }
68
 
69
        return resMap;
70
    }
34902 vikas 71
}