Subversion Repositories SmartDukaan

Rev

Rev 24388 | Rev 24439 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 24388 Rev 24417
Line 1... Line 1...
1
package com.spice.profitmandi.dao.repository.cs;
1
package com.spice.profitmandi.dao.repository.cs;
2
 
2
 
3
import java.time.LocalDateTime;
3
import java.time.LocalDateTime;
-
 
4
import java.util.ArrayList;
-
 
5
import java.util.HashMap;
-
 
6
import java.util.List;
-
 
7
import java.util.Map;
4
 
8
 
5
import org.springframework.beans.factory.annotation.Autowired;
9
import org.springframework.beans.factory.annotation.Autowired;
6
import org.springframework.stereotype.Component;
10
import org.springframework.stereotype.Component;
7
 
11
 
8
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
12
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
-
 
13
import com.spice.profitmandi.common.model.CustomRetailer;
-
 
14
import com.spice.profitmandi.dao.entity.auth.AuthUser;
9
import com.spice.profitmandi.dao.entity.cs.Activity;
15
import com.spice.profitmandi.dao.entity.cs.Activity;
-
 
16
import com.spice.profitmandi.dao.entity.cs.PartnerRegion;
-
 
17
import com.spice.profitmandi.dao.entity.cs.Position;
10
import com.spice.profitmandi.dao.entity.cs.Ticket;
18
import com.spice.profitmandi.dao.entity.cs.Ticket;
-
 
19
import com.spice.profitmandi.dao.entity.cs.TicketSubCategory;
11
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
20
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
-
 
21
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
-
 
22
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
-
 
23
import com.spice.profitmandi.service.user.RetailerService;
12
 
24
 
13
@Component
25
@Component
14
public class CsServiceImpl implements CsService {
26
public class CsServiceImpl implements CsService {
15
	
27
 
16
	@Autowired
28
	@Autowired
17
	TicketRepository ticketRepository;
29
	TicketRepository ticketRepository;
18
	
30
 
19
	@Autowired
31
	@Autowired
20
	TicketCategoryRepository ticketCategoryRepository;
32
	TicketCategoryRepository ticketCategoryRepository;
21
	
33
 
22
	@Autowired
34
	@Autowired
23
	TicketSubCategoryRepository ticketSubCategoryRepository;
35
	TicketSubCategoryRepository ticketSubCategoryRepository;
24
	
36
 
25
	@Autowired 
37
	@Autowired
26
	ActivityRepository activityRepository;
38
	ActivityRepository activityRepository;
-
 
39
 
-
 
40
	@Autowired
-
 
41
	PartnerRegionRepository partnerRepository;
27
	
42
 
-
 
43
	@Autowired
-
 
44
	private PositionRepository positionRepository;
-
 
45
 
-
 
46
	@Autowired
-
 
47
	private AuthRepository authRepository;
-
 
48
 
-
 
49
	@Autowired
-
 
50
	private RetailerService retailerService;
-
 
51
 
28
	@Override
52
	@Override
29
	public void createTicket(int fofoId, int subcategoryId, String message) {
53
	public void createTicket(int fofoId, int categoryId, int subcategoryId, String message) {
30
		
54
 
31
		ActivityType type = ActivityType.OPENED;
55
		ActivityType type = ActivityType.OPENED;
-
 
56
		EscalationType escalationType = EscalationType.L1;
32
		Ticket ticket = new Ticket();
57
		Ticket ticket = new Ticket();
33
		ticket.setSubCategoryId(subcategoryId);
58
		ticket.setSubCategoryId(subcategoryId);
-
 
59
		ticket.setFofoId(fofoId);
34
		ticket.setCreateTimestamp(LocalDateTime.now());
60
		ticket.setCreateTimestamp(LocalDateTime.now());
-
 
61
		ticket.setUpdateTimestamp(LocalDateTime.now());
35
		try {
62
		try {
36
			ticket.setAssigneeId(this.getAssigneeId(subcategoryId, type));
63
			ticket.setAssigneeId(this.getAssigneeId(categoryId, escalationType));
37
		} catch (Exception e) {
64
		} catch (Exception e) {
38
			e.printStackTrace();
65
			e.printStackTrace();
39
		}
66
		}
40
		ticketRepository.persist(ticket);
67
		ticketRepository.persist(ticket);
41
		
-
 
42
		Activity activity = this.createActivity(type, message, 0);
68
		Activity activity = this.createActivity(type, message, 0);
43
		this.addActivity(ticket.getId(), activity);
69
		this.addActivity(ticket.getId(), activity);
44
		
-
 
45
		this.addActivity(ticket.getId(), activity);
-
 
46
	}
70
	}
47
 
71
 
48
	private Activity createActivity(ActivityType activityType, String message, int createdBy) {
72
	private Activity createActivity(ActivityType activityType, String message, int createdBy) {
49
		Activity activity = new Activity();
73
		Activity activity = new Activity();
50
		activity.setMessage(message);
74
		activity.setMessage(message);
51
		activity.setCreatedBy(createdBy);
75
		activity.setCreatedBy(createdBy);
52
		activity.setType(activityType);
76
		activity.setType(activityType);
-
 
77
		activity.setCreateTimestamp(LocalDateTime.now());
53
		return activity;
78
		return activity;
54
	}
79
	}
55
	
80
 
56
	private int getAssigneeId(int subcategoryId, ActivityType escalationType) throws ProfitMandiBusinessException {
81
	private int getAssigneeId(int categoryId, EscalationType escalationType) throws ProfitMandiBusinessException {
-
 
82
 
-
 
83
		Position position = positionRepository.selectPositionbyCategoryIdAndEscalationType(categoryId, escalationType);
-
 
84
		return position.getAuthUserId();
57
		return 0;
85
		/*
58
		/*if(ActivityType.escalationTypes.contains(escalationType)) {
86
		 * if(ActivityType.escalationTypes.contains(escalationType)) {
59
			//escalationMatrix
87
		 * //escalationMatrix } else { throw new
60
		} else {
-
 
61
			throw new ProfitMandiBusinessException("SubCategory", subcategoryId, "Could not find Assignee for ");
88
		 * ProfitMandiBusinessException("SubCategory", subcategoryId,
-
 
89
		 * "Could not find Assignee for "); }
62
		}*/
90
		 */
63
	}
91
	}
64
 
92
 
65
	@Override
93
	@Override
66
	public void addActivity(int ticketId, Activity activity) {
94
	public void addActivity(int ticketId, Activity activity) {
67
		activity.setTicketId(ticketId);
95
		activity.setTicketId(ticketId);
-
 
96
		activityRepository.persist(activity);
-
 
97
	}
-
 
98
 
-
 
99
	@Override
-
 
100
	public void addPartnerToRegion(int regionId, List<Integer> fofoIds) {
-
 
101
 
-
 
102
		for (Integer fofoId : fofoIds) {
-
 
103
			PartnerRegion partnerRegion = partnerRepository.selectByRegionIdAndFofoId(regionId, fofoId);
-
 
104
			if (partnerRegion == null) {
-
 
105
				partnerRegion = new PartnerRegion();
-
 
106
				partnerRegion.setFofoId(fofoId);
-
 
107
				partnerRegion.setRegionId(regionId);
-
 
108
				partnerRepository.persist(partnerRegion);
-
 
109
			} else {
-
 
110
				continue;
-
 
111
			}
-
 
112
		}
-
 
113
	}
-
 
114
 
-
 
115
	@Override
-
 
116
	public Map<Integer, AuthUser> getAuthUserIdAndAuthUserMap(List<Ticket> tickets) {
-
 
117
		Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
-
 
118
		for (Ticket ticket : tickets) {
-
 
119
			AuthUser authUser = authRepository.selectById(ticket.getAssigneeId());
-
 
120
			authUserIdAndAuthUserMap.put(ticket.getAssigneeId(), authUser);
-
 
121
		}
-
 
122
		return authUserIdAndAuthUserMap;
-
 
123
	}
-
 
124
 
-
 
125
	@Override
-
 
126
	public Map<Integer, TicketSubCategory> getSubCategoryIdAndSubCategoryMap(List<Ticket> tickets) {
-
 
127
		Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = new HashMap<>();
-
 
128
		for (Ticket ticket : tickets) {
-
 
129
			TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());
-
 
130
			subCategoryIdAndSubCategoryMap.put(ticket.getSubCategoryId(), ticketSubCategory);
-
 
131
		}
-
 
132
		return subCategoryIdAndSubCategoryMap;
-
 
133
	}
-
 
134
 
-
 
135
	@Override
-
 
136
	public Map<Integer, CustomRetailer> getPartnerByFofoIds(List<Ticket> tickets) {
-
 
137
		List<Integer> fofoIds = new ArrayList<>();
-
 
138
		for (Ticket ticket : tickets) {
-
 
139
			fofoIds.add(ticket.getFofoId());
-
 
140
		}
-
 
141
		Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = retailerService.getFofoRetailers(fofoIds);
-
 
142
 
-
 
143
		return fofoIdsAndCustomRetailer;
68
	}
144
	}
69
 
145
 
70
}
146
}