Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
27007 amit.gupta 1
package com.smartdukaan.cron.scheduled.leadsync;
2
 
3
import java.io.File;
27015 amit.gupta 4
import java.time.LocalDate;
27007 amit.gupta 5
import java.time.LocalDateTime;
27009 amit.gupta 6
import java.time.format.DateTimeFormatter;
27007 amit.gupta 7
import java.util.List;
8
 
9
import org.apache.commons.io.input.XmlStreamReader;
10
import org.apache.logging.log4j.LogManager;
11
import org.apache.logging.log4j.Logger;
12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.stereotype.Component;
14
import org.springframework.transaction.annotation.Transactional;
15
 
16
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
17
import com.spice.profitmandi.dao.entity.user.Lead;
18
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
19
import com.spice.profitmandi.dao.repository.dtr.LeadRepository;
20
 
21
@Component
22
@Transactional(rollbackFor = Throwable.class)
23
public class LeadSyncRunner {
24
 
25
	@Autowired
26
	LeadRepository leadRepository;
37729 amit 27
 
28
	@Autowired
29
	com.spice.profitmandi.dao.service.lead.LeadCreationService leadCreationService;
27007 amit.gupta 30
 
31
	private static final Logger LOGGER = LogManager.getLogger(LeadSyncRunner.class);
32
 
33
	public void syncLeads() throws Exception {
34
		XmlMapper xmlMapper = new XmlMapper();
35
		XmlStreamReader xmlStreamReader = new XmlStreamReader(new File("/root/leads.xml"));
36
		Items items = xmlMapper.readValue(xmlStreamReader, Items.class);
37
		List<Item> itemList = items.getItems();
37729 amit 38
		int skipped = 0;
27007 amit.gupta 39
		for (Item item : itemList) {
40
			Lead lead = new Lead();
41
			lead.setAddress(item.getLocation().trim());
42
			lead.setLeadMobile(item.getNumber().trim());
43
			lead.setCity(item.getLocation().trim());
44
			lead.setState(item.getState());
45
			lead.setLastName(item.getBusiness().trim());
46
			if(lead.getState().equals("Uttar Pradesh")) {
27087 amit.gupta 47
				lead.setAssignTo(1);
27007 amit.gupta 48
			} else if (lead.getState().equals("Haryana")) {
27087 amit.gupta 49
				lead.setAssignTo(1);
27007 amit.gupta 50
			} else if (lead.getState().equals("Delhi")) {
27087 amit.gupta 51
				lead.setAssignTo(1);
27007 amit.gupta 52
			} else {
27009 amit.gupta 53
				//Assign to sm
27087 amit.gupta 54
				//lead.setAssignTo(53);
55
				lead.setAssignTo(1);
27007 amit.gupta 56
			}
27010 amit.gupta 57
			lead.setAuthId(lead.getAssignTo());
27015 amit.gupta 58
			lead.setCreatedBy("daily-sync");
59
			lead.setSource("SD-WEB");
27007 amit.gupta 60
			lead.setFirstName(item.getName().trim());
27012 amit.gupta 61
			lead.setStatus(LeadStatus.followUp);
27007 amit.gupta 62
			lead.setColor("yellow");
27015 amit.gupta 63
			lead.setCreatedTimestamp(LocalDate.parse(item.getCreated(), DateTimeFormatter.ISO_DATE).atStartOfDay());
27007 amit.gupta 64
			lead.setUpdatedTimestamp(LocalDateTime.now());
37729 amit 65
			// Unattended: the nightly XML sync has no user. A number already being worked is
66
			// skipped (and mailed to the Call Center desk) rather than duplicated; a number whose
67
			// open lead has gone stale is taken over silently.
68
			if (leadCreationService.createUnattended(lead).isBlocked()) {
69
				skipped++;
70
			}
27007 amit.gupta 71
		}
37729 amit 72
		if (skipped > 0) {
73
			LOGGER.info("Lead sync: {} row(s) skipped, already being worked", skipped);
74
		}
27007 amit.gupta 75
	}
76
}