Subversion Repositories SmartDukaan

Rev

Rev 34902 | Go to most recent revision | 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
34906 vikas 40
    public void createEarnings() {}
41
 
42
    @Override
43
    public AffiliateEarnings getEarnings() {
44
        return null;
45
    }
46
 
47
    @Override
48
    public Map<String,Object> getAffiliateData(int customerId) throws ProfitMandiBusinessException {
49
        Map<String,Object> resMap = new HashMap<>();
50
        Customer customer = customerRepository.selectById(customerId);
51
        if(customer!=null){
52
            List<AffiliateProduct> affiliateLinks = affiliateLinkRepository.findProductsByCustomerId(customerId);
53
            logger.info("AffiliateLinks size: {}",affiliateLinks);
54
            List<AffiliateEarnings> affiliateEarnings = affiliateRepository.findEarningsByCustomerId(customerId);
55
            String code = customer.getFirstName().substring(0, 1).toUpperCase() + customer.getLastName().substring(0, 1).toUpperCase() + customer.getId();
56
            List<PendingOrderItem> orderItems = orderItemRepository.selectAllByCustomer(code);
57
            logger.info("affiliateEarnings: {}",affiliateEarnings);
58
            resMap.put("affiliateLinks", affiliateLinks);
59
            resMap.put("affiliateEarnings", affiliateEarnings);
60
            resMap.put("affiliateOrders", orderItems);
61
        } else {
62
            resMap.put("affiliateLinks", "[]");
63
            resMap.put("affiliateEarnings", "[]");
64
            resMap.put("affiliateOrders", "[]");
65
        }
66
 
67
        return resMap;
68
    }
34902 vikas 69
}