#68 added ping method
This commit is contained in:
parent
f556b969b4
commit
d921def09d
@ -21,7 +21,6 @@ import springfox.documentation.annotations.ApiIgnore;
|
|||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -58,26 +57,8 @@ public class ConferenceController {
|
|||||||
@GetMapping("/dashboard")
|
@GetMapping("/dashboard")
|
||||||
public void getDashboard(ModelMap modelMap) {
|
public void getDashboard(ModelMap modelMap) {
|
||||||
modelMap.put("conferences", conferenceService.findAllActiveDto());
|
modelMap.put("conferences", conferenceService.findAllActiveDto());
|
||||||
//first, add the regional sales
|
|
||||||
Integer northeastSales = 17089;
|
|
||||||
Integer westSales = 10603;
|
|
||||||
Integer midwestSales = 5223;
|
|
||||||
Integer southSales = 10111;
|
|
||||||
|
|
||||||
modelMap.addAttribute("northeastSales", northeastSales);
|
|
||||||
modelMap.addAttribute("southSales", southSales);
|
|
||||||
modelMap.addAttribute("midwestSales", midwestSales);
|
|
||||||
modelMap.addAttribute("westSales", westSales);
|
|
||||||
|
|
||||||
//now add sales by lure type
|
|
||||||
List<Integer> inshoreSales = Arrays.asList(4074, 3455, 4112);
|
|
||||||
List<Integer> nearshoreSales = Arrays.asList(3222, 3011, 3788);
|
|
||||||
List<Integer> offshoreSales = Arrays.asList(7811, 7098, 6455);
|
|
||||||
|
|
||||||
modelMap.addAttribute("inshoreSales", inshoreSales);
|
|
||||||
modelMap.addAttribute("nearshoreSales", nearshoreSales);
|
|
||||||
modelMap.addAttribute("offshoreSales", offshoreSales);
|
|
||||||
|
|
||||||
|
conferenceService.setChartData(modelMap); // example
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/conference")
|
@GetMapping("/conference")
|
||||||
@ -145,6 +126,15 @@ public class ConferenceController {
|
|||||||
return CONFERENCE_PAGE;
|
return CONFERENCE_PAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/conference", params = "ping")
|
||||||
|
public String ping(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException {
|
||||||
|
if (errors.hasErrors()) {
|
||||||
|
return CONFERENCE_PAGE;
|
||||||
|
}
|
||||||
|
conferenceService.ping(conferenceDto);
|
||||||
|
return CONFERENCE_PAGE;
|
||||||
|
}
|
||||||
|
|
||||||
@ModelAttribute("allParticipation")
|
@ModelAttribute("allParticipation")
|
||||||
public List<ConferenceUser.Participation> getAllParticipation() {
|
public List<ConferenceUser.Participation> getAllParticipation() {
|
||||||
return conferenceService.getAllParticipations();
|
return conferenceService.getAllParticipations();
|
||||||
|
@ -35,7 +35,7 @@ public class Conference extends BaseEntity {
|
|||||||
|
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
private int ping;
|
private int ping = 0;
|
||||||
|
|
||||||
@Column(name = "begin_date")
|
@Column(name = "begin_date")
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
@ -4,6 +4,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.ui.ModelMap;
|
||||||
import ru.ulstu.conference.model.Conference;
|
import ru.ulstu.conference.model.Conference;
|
||||||
import ru.ulstu.conference.model.ConferenceDto;
|
import ru.ulstu.conference.model.ConferenceDto;
|
||||||
import ru.ulstu.conference.model.ConferenceFilterDto;
|
import ru.ulstu.conference.model.ConferenceFilterDto;
|
||||||
@ -12,6 +13,7 @@ import ru.ulstu.conference.repository.ConferenceRepository;
|
|||||||
import ru.ulstu.deadline.service.DeadlineService;
|
import ru.ulstu.deadline.service.DeadlineService;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
import ru.ulstu.paper.service.PaperService;
|
import ru.ulstu.paper.service.PaperService;
|
||||||
|
import ru.ulstu.ping.service.PingService;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.service.UserService;
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
@ -33,17 +35,20 @@ public class ConferenceService {
|
|||||||
private final DeadlineService deadlineService;
|
private final DeadlineService deadlineService;
|
||||||
private final PaperService paperService;
|
private final PaperService paperService;
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
private final PingService pingService;
|
||||||
|
|
||||||
public ConferenceService(ConferenceRepository conferenceRepository,
|
public ConferenceService(ConferenceRepository conferenceRepository,
|
||||||
ConferenceUserService conferenceUserService,
|
ConferenceUserService conferenceUserService,
|
||||||
DeadlineService deadlineService,
|
DeadlineService deadlineService,
|
||||||
PaperService paperService,
|
PaperService paperService,
|
||||||
UserService userService) {
|
UserService userService,
|
||||||
|
PingService pingService) {
|
||||||
this.conferenceRepository = conferenceRepository;
|
this.conferenceRepository = conferenceRepository;
|
||||||
this.conferenceUserService = conferenceUserService;
|
this.conferenceUserService = conferenceUserService;
|
||||||
this.deadlineService = deadlineService;
|
this.deadlineService = deadlineService;
|
||||||
this.paperService = paperService;
|
this.paperService = paperService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
|
this.pingService = pingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConferenceDto getExistConferenceById(Integer id) {
|
public ConferenceDto getExistConferenceById(Integer id) {
|
||||||
@ -141,7 +146,8 @@ public class ConferenceService {
|
|||||||
conference.setTitle(conferenceDto.getTitle());
|
conference.setTitle(conferenceDto.getTitle());
|
||||||
conference.setDescription(conferenceDto.getDescription());
|
conference.setDescription(conferenceDto.getDescription());
|
||||||
conference.setUrl(conferenceDto.getUrl());
|
conference.setUrl(conferenceDto.getUrl());
|
||||||
conference.setPing(0);
|
Integer pingCount = conferenceDto.getPing() - conference.getPing(); // for notification
|
||||||
|
conference.setPing(conference.getPing());
|
||||||
conference.setBeginDate(conferenceDto.getBeginDate());
|
conference.setBeginDate(conferenceDto.getBeginDate());
|
||||||
conference.setEndDate(conferenceDto.getEndDate());
|
conference.setEndDate(conferenceDto.getEndDate());
|
||||||
conference.setPapers(conferenceDto.getPapers());
|
conference.setPapers(conferenceDto.getPapers());
|
||||||
@ -173,4 +179,35 @@ public class ConferenceService {
|
|||||||
public List<Conference> findAllActive() {
|
public List<Conference> findAllActive() {
|
||||||
return conferenceRepository.findAllActive(new Date());
|
return conferenceRepository.findAllActive(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ping(ConferenceDto conferenceDto) throws IOException {
|
||||||
|
pingService.addPing(findOne(conferenceDto.getId()));
|
||||||
|
// conferenceDto.setPing(conferenceDto.getPing() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Conference findOne(Integer conferenceId) {
|
||||||
|
return conferenceRepository.findOne(conferenceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChartData(ModelMap modelMap) {
|
||||||
|
//first, add the regional sales
|
||||||
|
Integer northeastSales = 17089;
|
||||||
|
Integer westSales = 10603;
|
||||||
|
Integer midwestSales = 5223;
|
||||||
|
Integer southSales = 10111;
|
||||||
|
|
||||||
|
modelMap.addAttribute("northeastSales", northeastSales);
|
||||||
|
modelMap.addAttribute("southSales", southSales);
|
||||||
|
modelMap.addAttribute("midwestSales", midwestSales);
|
||||||
|
modelMap.addAttribute("westSales", westSales);
|
||||||
|
|
||||||
|
//now add sales by lure type
|
||||||
|
List<Integer> inshoreSales = Arrays.asList(4074, 3455, 4112);
|
||||||
|
List<Integer> nearshoreSales = Arrays.asList(3222, 3011, 3788);
|
||||||
|
List<Integer> offshoreSales = Arrays.asList(7811, 7098, 6455);
|
||||||
|
|
||||||
|
modelMap.addAttribute("inshoreSales", inshoreSales);
|
||||||
|
modelMap.addAttribute("nearshoreSales", nearshoreSales);
|
||||||
|
modelMap.addAttribute("offshoreSales", offshoreSales);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package ru.ulstu.ping.model;
|
package ru.ulstu.ping.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.sun.istack.internal.Nullable;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import ru.ulstu.conference.model.Conference;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
@ -24,6 +26,11 @@ public class Ping extends BaseEntity {
|
|||||||
@JoinColumn(name = "users_id")
|
@JoinColumn(name = "users_id")
|
||||||
private User user;
|
private User user;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@ManyToOne(optional = false)
|
||||||
|
@JoinColumn(name = "conference_id")
|
||||||
|
private Conference conference;
|
||||||
|
|
||||||
public Ping() {
|
public Ping() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,10 +41,12 @@ public class Ping extends BaseEntity {
|
|||||||
|
|
||||||
public Ping(@JsonProperty("id") Integer id,
|
public Ping(@JsonProperty("id") Integer id,
|
||||||
@JsonProperty("date") Date date,
|
@JsonProperty("date") Date date,
|
||||||
@JsonProperty("user") User user) {
|
@JsonProperty("user") User user,
|
||||||
|
@JsonProperty("conference") Conference conference) {
|
||||||
setId(id);
|
setId(id);
|
||||||
this.date = date;
|
this.date = date;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
|
this.conference = conference;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getDate() {
|
public Date getDate() {
|
||||||
@ -55,4 +64,12 @@ public class Ping extends BaseEntity {
|
|||||||
public void setUser(User user) {
|
public void setUser(User user) {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Conference getConference() {
|
||||||
|
return conference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConference(Conference conference) {
|
||||||
|
this.conference = conference;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,30 @@
|
|||||||
package ru.ulstu.ping.service;
|
package ru.ulstu.ping.service;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import ru.ulstu.conference.model.Conference;
|
||||||
|
import ru.ulstu.ping.model.Ping;
|
||||||
import ru.ulstu.ping.repository.PingRepository;
|
import ru.ulstu.ping.repository.PingRepository;
|
||||||
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class PingService {
|
public class PingService {
|
||||||
private final PingRepository pingRepository;
|
private final PingRepository pingRepository;
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
public PingService(PingRepository pingRepository) {
|
public PingService(PingRepository pingRepository,
|
||||||
|
UserService userService) {
|
||||||
this.pingRepository = pingRepository;
|
this.pingRepository = pingRepository;
|
||||||
|
this.userService = userService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void addPing(Conference conference) throws IOException {
|
||||||
|
Ping newPing = new Ping(new Date(), userService.getCurrentUser());
|
||||||
|
newPing.setConference(conference);
|
||||||
|
pingRepository.save(newPing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group d-flex justify-content-end">
|
<div class="form-group d-flex justify-content-between flex-wrap">
|
||||||
|
<input type="hidden" th:value="*{ping}" th:name="ping"/>
|
||||||
|
<input id="pingButton" class="btn btn-primary"
|
||||||
|
type="submit" name="ping" value="Ping участникам"/>
|
||||||
<input type="hidden" th:value="*{disabledTakePart}" th:name="disabledTakePart"/>
|
<input type="hidden" th:value="*{disabledTakePart}" th:name="disabledTakePart"/>
|
||||||
<input id="take-part" class="btn btn-primary"
|
<input id="take-part" class="btn btn-primary"
|
||||||
type="submit" name="takePart" value="Принять участие"
|
type="submit" name="takePart" value="Принять участие"
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
</th:block>
|
</th:block>
|
||||||
</div>
|
</div>
|
||||||
<hr/>
|
<hr/>
|
||||||
|
<!--chart example-->
|
||||||
<nav>
|
<nav>
|
||||||
<div class="nav nav-tabs" id="nav-tab" role="tablist">
|
<div class="nav nav-tabs" id="nav-tab" role="tablist">
|
||||||
<a class="nav-item nav-link active" id="nav-main-tab" data-toggle="tab"
|
<a class="nav-item nav-link active" id="nav-main-tab" data-toggle="tab"
|
||||||
@ -41,10 +42,13 @@
|
|||||||
<div id="salesByRegion" style="width:100%; height:400px;"></div>
|
<div id="salesByRegion" style="width:100%; height:400px;"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<!--chart example-->
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<script th:inline="javascript">
|
<script th:inline="javascript">
|
||||||
/*<![CDATA[*/
|
/*<![CDATA[*/
|
||||||
|
|
||||||
|
// chart example
|
||||||
$(function () {
|
$(function () {
|
||||||
Highcharts.setOptions({
|
Highcharts.setOptions({
|
||||||
lang: {
|
lang: {
|
||||||
@ -62,12 +66,7 @@
|
|||||||
var salesByRegionChart = Highcharts.chart('salesByRegion', {
|
var salesByRegionChart = Highcharts.chart('salesByRegion', {
|
||||||
chart: {
|
chart: {
|
||||||
type: 'pie',
|
type: 'pie',
|
||||||
margin: 40,
|
margin: 40
|
||||||
options3d: {
|
|
||||||
enabled: true,
|
|
||||||
alpha: 45,
|
|
||||||
beta: 0
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
title: {
|
title: {
|
||||||
text: 'Sales by Region'
|
text: 'Sales by Region'
|
||||||
@ -105,13 +104,7 @@
|
|||||||
var salesByTypeChart = Highcharts.chart('salesByType', {
|
var salesByTypeChart = Highcharts.chart('salesByType', {
|
||||||
chart: {
|
chart: {
|
||||||
type: 'column',
|
type: 'column',
|
||||||
margin: 75,
|
margin: 75
|
||||||
options3d: {
|
|
||||||
enabled: true,
|
|
||||||
alpha: 15,
|
|
||||||
beta: 15,
|
|
||||||
depth: 110
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
title: {
|
title: {
|
||||||
text: 'Sales by Lure Type'
|
text: 'Sales by Lure Type'
|
||||||
@ -149,8 +142,6 @@
|
|||||||
}
|
}
|
||||||
/*]]>*/
|
/*]]>*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
Reference in New Issue
Block a user