Subversion Repositories SmartDukaan

Rev

Rev 35458 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35458 Rev 37897
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import java.time.LocalDateTime;
3
import com.spice.profitmandi.common.solr.SolrService;
4
import java.util.List;
4
import com.spice.profitmandi.common.web.util.ResponseSender;
5
import java.util.Map;
5
import com.spice.profitmandi.dao.entity.dtr.WebOffer;
6
import java.util.Optional;
6
import com.spice.profitmandi.dao.entity.dtr.WebOfferProduct;
7
import java.util.stream.Collectors;
7
import com.spice.profitmandi.dao.repository.dtr.WebOfferProductRepository;
8
 
-
 
9
import javax.servlet.http.HttpServletRequest;
8
import com.spice.profitmandi.dao.repository.dtr.WebOfferRepository;
10
import org.springframework.transaction.annotation.Transactional;
9
import com.spice.profitmandi.web.service.EmiOfferImportService;
11
 
-
 
12
import org.apache.logging.log4j.LogManager;
10
import org.apache.logging.log4j.LogManager;
13
import org.apache.logging.log4j.Logger;
11
import org.apache.logging.log4j.Logger;
14
import org.json.JSONObject;
12
import org.json.JSONObject;
15
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.beans.factory.annotation.Autowired;
-
 
14
import org.springframework.http.ResponseEntity;
16
import org.springframework.stereotype.Controller;
15
import org.springframework.stereotype.Controller;
-
 
16
import org.springframework.transaction.annotation.Transactional;
17
import org.springframework.ui.Model;
17
import org.springframework.ui.Model;
18
import org.springframework.web.bind.annotation.PathVariable;
-
 
19
import org.springframework.web.bind.annotation.RequestBody;
18
import org.springframework.web.bind.annotation.*;
20
import org.springframework.web.bind.annotation.RequestMapping;
19
import org.springframework.web.multipart.MultipartFile;
21
import org.springframework.web.bind.annotation.RequestMethod;
-
 
22
import org.springframework.web.bind.annotation.RequestParam;
-
 
23
 
20
 
24
import com.spice.profitmandi.common.solr.SolrService;
21
import javax.servlet.http.HttpServletRequest;
25
import com.spice.profitmandi.common.web.util.ResponseSender;
22
import java.time.LocalDate;
26
import com.spice.profitmandi.dao.entity.dtr.WebOffer;
23
import java.time.LocalDateTime;
27
import com.spice.profitmandi.dao.entity.dtr.WebOfferProduct;
24
import java.util.List;
-
 
25
import java.util.Map;
28
import com.spice.profitmandi.dao.repository.dtr.WebOfferProductRepository;
26
import java.util.Optional;
29
import com.spice.profitmandi.dao.repository.dtr.WebOfferRepository;
27
import java.util.stream.Collectors;
30
 
28
 
31
@Controller
29
@Controller
32
@Transactional(rollbackFor = Throwable.class)
30
@Transactional(rollbackFor = Throwable.class)
33
public class WebOffersController {
31
public class WebOffersController {
34
 
32
 
Line 44... Line 42...
44
	WebOfferProductRepository webOfferProductRepository;
42
	WebOfferProductRepository webOfferProductRepository;
45
 
43
 
46
	@Autowired
44
	@Autowired
47
	SolrService solrService;
45
	SolrService solrService;
48
 
46
 
-
 
47
	@Autowired
-
 
48
	EmiOfferImportService emiOfferImportService;
-
 
49
 
49
	@RequestMapping(value = "/web-offers", method = RequestMethod.GET)
50
	@RequestMapping(value = "/web-offers", method = RequestMethod.GET)
50
	public String getOfferListing(HttpServletRequest request, Model model) {
51
	public String getOfferListing(HttpServletRequest request, Model model) {
51
		List<WebOffer> webListing = webOfferRepository.selectAllWebListing(Optional.of(true));
52
		List<WebOffer> webListing = webOfferRepository.selectAllWebListing(Optional.of(true));
52
		model.addAttribute("webListings", webListing);
53
		model.addAttribute("webListings", webListing);
53
		return "web-offer";
54
		return "web-offer";
Line 138... Line 139...
138
			productListing.setRank(webListingProductIds.indexOf(productListing.getId()) + 1);
139
			productListing.setRank(webListingProductIds.indexOf(productListing.getId()) + 1);
139
		});
140
		});
140
		return getWebProductListing(request, model, webListingId);
141
		return getWebProductListing(request, model, webListingId);
141
	}
142
	}
142
 
143
 
-
 
144
	@RequestMapping(value = "/web-offer/import-emi-json", method = RequestMethod.POST)
-
 
145
	@ResponseBody
-
 
146
	public ResponseEntity<EmiOfferImportService.ImportResult> importEmiJson(
-
 
147
			@RequestPart("file") MultipartFile file,
-
 
148
			@RequestParam(value = "startDate", required = false) String startDate,
-
 
149
			@RequestParam(value = "endDate", required = false) String endDate,
-
 
150
			@RequestParam(value = "dryRun", defaultValue = "true") boolean dryRun) throws Exception {
-
 
151
 
-
 
152
		LocalDate today = LocalDate.now();
-
 
153
		LocalDateTime start = (startDate == null || startDate.isEmpty())
-
 
154
				? today.atStartOfDay() : LocalDate.parse(startDate).atStartOfDay();
-
 
155
		LocalDateTime end = (endDate == null || endDate.isEmpty())
-
 
156
				? today.plusDays(30).atTime(23, 59, 59) : LocalDate.parse(endDate).atTime(23, 59, 59);
-
 
157
 
-
 
158
		LOGGER.info("EmiImport: file={} size={} dryRun={} start={} end={}",
-
 
159
				file.getOriginalFilename(), file.getSize(), dryRun, start, end);
-
 
160
 
-
 
161
		EmiOfferImportService.ImportResult result = emiOfferImportService.importFromJson(
-
 
162
				file.getInputStream(), start, end, dryRun);
-
 
163
		return ResponseEntity.ok(result);
-
 
164
	}
-
 
165
 
143
}
166
}