Subversion Repositories SmartDukaan

Rev

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

Rev 22325 Rev 22328
Line 35... Line 35...
35
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
35
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
36
import com.spice.profitmandi.common.model.ProfitMandiConstants;
36
import com.spice.profitmandi.common.model.ProfitMandiConstants;
37
import com.spice.profitmandi.common.model.ProfitMandiResponse;
37
import com.spice.profitmandi.common.model.ProfitMandiResponse;
38
import com.spice.profitmandi.common.model.ResponseStatus;
38
import com.spice.profitmandi.common.model.ResponseStatus;
39
import com.spice.profitmandi.common.model.UserInfo;
39
import com.spice.profitmandi.common.model.UserInfo;
40
import com.spice.profitmandi.common.solr.model.FofoDealItem;
-
 
41
import com.spice.profitmandi.common.solr.model.FofoDealResponse;
-
 
42
import com.spice.profitmandi.common.web.client.RestClient;
40
import com.spice.profitmandi.common.web.client.RestClient;
43
import com.spice.profitmandi.common.web.util.ResponseSender;
41
import com.spice.profitmandi.common.web.util.ResponseSender;
44
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
42
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
45
import com.spice.profitmandi.service.pricing.PricingService;
43
import com.spice.profitmandi.service.pricing.PricingService;
46
import com.spice.profitmandi.web.res.DealBrands;
44
import com.spice.profitmandi.web.res.DealBrands;
47
import com.spice.profitmandi.web.res.DealObjectResponse;
45
import com.spice.profitmandi.web.res.DealObjectResponse;
48
import com.spice.profitmandi.web.res.DealsResponse;
46
import com.spice.profitmandi.web.res.DealsResponse;
-
 
47
import com.spice.profitmandi.web.res.FofoAvailabilityInfo;
-
 
48
import com.spice.profitmandi.web.res.FofoCatalogResponse;
49
 
49
 
50
import io.swagger.annotations.ApiImplicitParam;
50
import io.swagger.annotations.ApiImplicitParam;
51
import io.swagger.annotations.ApiImplicitParams;
51
import io.swagger.annotations.ApiImplicitParams;
52
import io.swagger.annotations.ApiOperation;
52
import io.swagger.annotations.ApiOperation;
53
 
53
 
Line 135... Line 135...
135
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
135
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
136
	@RequestMapping(value = "/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
136
	@RequestMapping(value = "/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
137
	public ResponseEntity<?> getFofo(HttpServletRequest request, @RequestParam(value = "categoryId") String categoryId,
137
	public ResponseEntity<?> getFofo(HttpServletRequest request, @RequestParam(value = "categoryId") String categoryId,
138
			@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
138
			@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
139
			@RequestParam(value = "sort", required = false) String sort) throws Throwable {
139
			@RequestParam(value = "sort", required = false) String sort) throws Throwable {
140
		List<FofoDealResponse> dealResponse = new ArrayList<>();
140
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
141
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
141
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
142
		if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
142
		if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
143
			List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(userInfo.getUserId());
143
			List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(userInfo.getUserId());
144
			RestClient rc  = new RestClient(SchemeType.HTTP, "dtr", 8984);
144
			RestClient rc  = new RestClient(SchemeType.HTTP, "dtr", 8984);
145
			Map<String, String> params = new HashMap<>();
145
			Map<String, String> params = new HashMap<>();
Line 151... Line 151...
151
			params.put("wt", "json");
151
			params.put("wt", "json");
152
			String response  =rc.get("solr/demo/select", params);
152
			String response  =rc.get("solr/demo/select", params);
153
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
153
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
154
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
154
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
155
			for(int i=0; i < docs.length(); i++) {
155
			for(int i=0; i < docs.length(); i++) {
156
				Map<Integer, FofoDealItem> itemPricing = new HashMap<>();
156
				Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
157
				JSONObject doc = docs.getJSONObject(i);
157
				JSONObject doc = docs.getJSONObject(i);
158
				FofoDealResponse ffdr = new FofoDealResponse();
158
				FofoCatalogResponse ffdr = new FofoCatalogResponse();
159
				ffdr.setCatalogId(doc.getInt("catalogId_i"));
159
				ffdr.setCatalogId(doc.getInt("catalogId_i"));
160
				ffdr.setImageUrl(doc.getString("imageUrl_s"));
160
				ffdr.setImageUrl(doc.getString("imageUrl_s"));
161
				ffdr.setTitle(doc.getString("title_s"));
161
				ffdr.setTitle(doc.getString("title_s"));
162
				for(int j=0; j< doc.getJSONArray("_childDocuments_").length(); j++) {
162
				for(int j=0; j< doc.getJSONArray("_childDocuments_").length(); j++) {
163
					JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
163
					JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
164
					int itemId = childItem.getInt("itemId_i");
164
					int itemId = childItem.getInt("itemId_i");
165
					float sellingPrice = (float)childItem.getDouble("sellingPrice_f");
165
					float sellingPrice = (float)childItem.getDouble("sellingPrice_f");
166
					if(itemPricing.containsKey(itemId)) {
166
					if(fofoAvailabilityInfoMap.containsKey(itemId)) {
167
						if(itemPricing.get(itemId).getSellingPrice() > sellingPrice) {
167
						if(fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
168
							itemPricing.get(itemId).setSellingPrice(sellingPrice);
168
							fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
169
							itemPricing.get(itemId).setMop((float)childItem.getDouble("mop_f"));
169
							fofoAvailabilityInfoMap.get(itemId).setMop((float)childItem.getDouble("mop_f"));
170
						} 
170
						} 
171
					} else {
171
					} else {
172
							FofoDealItem fdi = new FofoDealItem();
172
							FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
173
							fdi.setSellingPrice((float)childItem.getDouble("sellingPrice_f"));
173
							fdi.setSellingPrice((float)childItem.getDouble("sellingPrice_f"));
174
							fdi.setMop((float)childItem.getDouble("mop_f"));
174
							fdi.setMop((float)childItem.getDouble("mop_f"));
175
							fdi.setColor(childItem.has("color_s")?childItem.getString("color_s"): "");
175
							fdi.setColor(childItem.has("color_s")?childItem.getString("color_s"): "");
176
							fdi.setTagId(childItem.getInt("tagId_i"));
176
							fdi.setTagId(childItem.getInt("tagId_i"));
177
							fdi.setItemId(itemId);
177
							fdi.setItem_id(itemId);
-
 
178
							fdi.setAvailability(100);
-
 
179
							fdi.setQuantityStep(1);
-
 
180
							fdi.setMinBuyQuantity(1);
-
 
181
							fdi.setMaxQuantity(100);
178
							itemPricing.put(itemId, fdi);
182
							fofoAvailabilityInfoMap.put(itemId, fdi);
179
					}
183
					}
180
				}
184
				}
181
				ffdr.setItems(new ArrayList<FofoDealItem>(itemPricing.values()));
185
				ffdr.setItems(new ArrayList<FofoAvailabilityInfo>(fofoAvailabilityInfoMap.values()));
182
				dealResponse.add(ffdr);
186
				dealResponse.add(ffdr);
183
			}
187
			}
184
			
188
			
185
		} else {
189
		} else {
186
			return responseSender.badRequest(new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
190
			return responseSender.badRequest(new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));