esoe
1 week ago
42 changed files with 1216 additions and 233 deletions
@ -1,75 +0,0 @@ |
|||||||
package gsp.technologies.main.account; |
|
||||||
|
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
import org.slf4j.Logger; |
|
||||||
import org.slf4j.LoggerFactory; |
|
||||||
import org.springframework.stereotype.Controller; |
|
||||||
import org.springframework.ui.Model; |
|
||||||
import org.springframework.web.bind.annotation.GetMapping; |
|
||||||
import org.springframework.web.bind.annotation.RequestMapping; |
|
||||||
import org.springframework.web.context.request.RequestContextHolder; |
|
||||||
|
|
||||||
import gsp.technologies.main.account.dto.AccountDTO; |
|
||||||
import gsp.technologies.main.course.dto.CourseDTO; |
|
||||||
import gsp.technologies.main.account.dto.OrganizationDTO; |
|
||||||
import gsp.technologies.main.account.dto.PositionDTO; |
|
||||||
import gsp.technologies.main.code.Code; |
|
||||||
|
|
||||||
/** |
|
||||||
* Контроллер формы аккаунта |
|
||||||
* возвращает thymeleaf шаблон |
|
||||||
*/ |
|
||||||
@Controller |
|
||||||
@RequestMapping(path = "/account") |
|
||||||
public class AccountController { |
|
||||||
private static final Logger log = LoggerFactory.getLogger(AccountController.class); |
|
||||||
|
|
||||||
@GetMapping("") |
|
||||||
public String account(Model model) { |
|
||||||
log.info("GET /account"); |
|
||||||
//данные аккаунта (id, organization, position)
|
|
||||||
String id = 1 + ""; |
|
||||||
String code = Code.encode(id); |
|
||||||
OrganizationDTO organization = OrganizationDTO.builder() |
|
||||||
.id(1 + "") |
|
||||||
.name("ГСП-Т") |
|
||||||
.build(); |
|
||||||
PositionDTO position = PositionDTO.builder() |
|
||||||
.id(1 + "") |
|
||||||
.name("Сварщик") |
|
||||||
.organization(organization) |
|
||||||
.build(); |
|
||||||
String sessionid = RequestContextHolder.currentRequestAttributes().getSessionId(); |
|
||||||
List<CourseDTO> courses = List.of( |
|
||||||
CourseDTO.builder() |
|
||||||
.id(1 + "") |
|
||||||
.name("Охрана труда") |
|
||||||
.passed(true) |
|
||||||
.build(), |
|
||||||
CourseDTO.builder() |
|
||||||
.id(2 + "") |
|
||||||
.name("Работы на высоте") |
|
||||||
.passed(false) |
|
||||||
.build(), |
|
||||||
CourseDTO.builder() |
|
||||||
.id(3 + "") |
|
||||||
.name("Первая помощь") |
|
||||||
.passed(true) |
|
||||||
.build() |
|
||||||
); |
|
||||||
AccountDTO account = AccountDTO.builder() |
|
||||||
.id(id) |
|
||||||
.code(code) |
|
||||||
.position(position) |
|
||||||
.sessionid(sessionid) |
|
||||||
.courses(courses) |
|
||||||
.build(); |
|
||||||
|
|
||||||
// log.info("account: {}", account);
|
|
||||||
model.addAttribute("account", account); |
|
||||||
log.info("Акаунт добавлен в модель: {}", account); |
|
||||||
|
|
||||||
return "account"; |
|
||||||
} |
|
||||||
} |
|
@ -1,22 +0,0 @@ |
|||||||
package gsp.technologies.main.account.dto; |
|
||||||
|
|
||||||
import java.io.Serializable; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
import gsp.technologies.main.course.dto.CourseDTO; |
|
||||||
import lombok.AllArgsConstructor; |
|
||||||
import lombok.Builder; |
|
||||||
import lombok.Data; |
|
||||||
import lombok.NoArgsConstructor; |
|
||||||
|
|
||||||
@Builder |
|
||||||
@NoArgsConstructor |
|
||||||
@AllArgsConstructor |
|
||||||
@Data |
|
||||||
public class AccountDTO implements Serializable { |
|
||||||
private String id; |
|
||||||
private String code; |
|
||||||
private PositionDTO position; |
|
||||||
private String sessionid; |
|
||||||
private List<CourseDTO> courses; |
|
||||||
} |
|
@ -1,17 +0,0 @@ |
|||||||
package gsp.technologies.main.account.dto; |
|
||||||
|
|
||||||
import java.io.Serializable; |
|
||||||
|
|
||||||
import lombok.AllArgsConstructor; |
|
||||||
import lombok.Builder; |
|
||||||
import lombok.Data; |
|
||||||
import lombok.NoArgsConstructor; |
|
||||||
|
|
||||||
@NoArgsConstructor |
|
||||||
@AllArgsConstructor |
|
||||||
@Builder |
|
||||||
@Data |
|
||||||
public class OrganizationDTO implements Serializable { |
|
||||||
private String id; |
|
||||||
private String name; //наименование организации
|
|
||||||
} |
|
@ -1,18 +0,0 @@ |
|||||||
package gsp.technologies.main.account.dto; |
|
||||||
|
|
||||||
import java.io.Serializable; |
|
||||||
|
|
||||||
import lombok.AllArgsConstructor; |
|
||||||
import lombok.Builder; |
|
||||||
import lombok.Data; |
|
||||||
import lombok.NoArgsConstructor; |
|
||||||
|
|
||||||
@NoArgsConstructor |
|
||||||
@AllArgsConstructor |
|
||||||
@Builder |
|
||||||
@Data |
|
||||||
public class PositionDTO implements Serializable { |
|
||||||
private String id; |
|
||||||
private String name; |
|
||||||
private OrganizationDTO organization; |
|
||||||
} |
|
@ -0,0 +1,36 @@ |
|||||||
|
package gsp.technologies.main.api.account; |
||||||
|
|
||||||
|
import org.hibernate.annotations.OnDelete; |
||||||
|
import org.hibernate.annotations.OnDeleteAction; |
||||||
|
|
||||||
|
import gsp.technologies.main.api.position.PositionEntity; |
||||||
|
import jakarta.persistence.Entity; |
||||||
|
import jakarta.persistence.FetchType; |
||||||
|
import jakarta.persistence.GeneratedValue; |
||||||
|
import jakarta.persistence.GenerationType; |
||||||
|
import jakarta.persistence.Id; |
||||||
|
import jakarta.persistence.JoinColumn; |
||||||
|
import jakarta.persistence.ManyToOne; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Builder; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.NoArgsConstructor; |
||||||
|
|
||||||
|
@Data |
||||||
|
@AllArgsConstructor |
||||||
|
@NoArgsConstructor |
||||||
|
@Builder |
||||||
|
@Entity |
||||||
|
public class AccountEntity { |
||||||
|
@Id |
||||||
|
@GeneratedValue(strategy=GenerationType.AUTO) |
||||||
|
private Long id; |
||||||
|
|
||||||
|
private String code; |
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.EAGER, optional = false) |
||||||
|
@JoinColumn(name = "position", referencedColumnName = "id") |
||||||
|
@OnDelete(action = OnDeleteAction.CASCADE) |
||||||
|
private PositionEntity position; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,131 @@ |
|||||||
|
package gsp.technologies.main.api.account; |
||||||
|
|
||||||
|
import java.util.Collection; |
||||||
|
|
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.stereotype.Controller; |
||||||
|
import org.springframework.ui.Model; |
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||||
|
|
||||||
|
import gsp.technologies.main.api.course.CourseEntity; |
||||||
|
import gsp.technologies.main.api.organization.OrganizationService; |
||||||
|
import gsp.technologies.main.api.position.PositionEntity; |
||||||
|
import gsp.technologies.main.api.position.PositionService; |
||||||
|
import gsp.technologies.main.api.target.TargetService; |
||||||
|
import gsp.technologies.main.code.Code; |
||||||
|
|
||||||
|
/** |
||||||
|
* Контроллер формы аккаунта |
||||||
|
* возвращает thymeleaf шаблон |
||||||
|
*/ |
||||||
|
@Controller |
||||||
|
@RequestMapping(path = "/account") |
||||||
|
public class AccountFaceController { |
||||||
|
private static final Logger log = LoggerFactory.getLogger(AccountFaceController.class); |
||||||
|
@Autowired |
||||||
|
private OrganizationService organizationService; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private PositionService positionService; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private AccountService accountService; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private TargetService targetService; |
||||||
|
|
||||||
|
public AccountFaceController( |
||||||
|
PositionService positionService |
||||||
|
, OrganizationService organizationService |
||||||
|
, AccountService accountService |
||||||
|
, TargetService targetService |
||||||
|
) { |
||||||
|
this.positionService = positionService; |
||||||
|
this.organizationService = organizationService; |
||||||
|
this.accountService = accountService; |
||||||
|
this.targetService = targetService; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Форма аккаунта: |
||||||
|
* - данные аккаунта (id, organization, position) |
||||||
|
* - список курсов аккаунта |
||||||
|
* |
||||||
|
* @param model |
||||||
|
* @param accountid |
||||||
|
* @param positionid |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@GetMapping("") |
||||||
|
public String account(Model model, |
||||||
|
@RequestParam(name = "accountid", required = false) String accountid, |
||||||
|
@RequestParam(name = "positionid", required = false) String positionid |
||||||
|
) { |
||||||
|
log.info("GET /account"); |
||||||
|
//данные аккаунта (id, organization, position)
|
||||||
|
log.info("accountid: " + accountid); |
||||||
|
log.info("positionid: " + positionid); |
||||||
|
|
||||||
|
if (accountid != null) { |
||||||
|
log.info("accountid: " + accountid); |
||||||
|
try{ |
||||||
|
//передаем в модель данные аккаунта
|
||||||
|
AccountEntity account = accountService.findById(Long.valueOf(accountid)); |
||||||
|
model.addAttribute("account", account); |
||||||
|
|
||||||
|
//передаем в модель перечень доступных курсов
|
||||||
|
Collection<CourseEntity> courses = targetService.findAllByPosition(account.getPosition()); |
||||||
|
model.addAttribute("courses", courses); |
||||||
|
//передаем в модель статусы прохождения курсов
|
||||||
|
|
||||||
|
return "account"; |
||||||
|
} catch (Exception e) { |
||||||
|
StringBuilder msg = new StringBuilder(); |
||||||
|
msg.append("Не удалось получить данные аккаунта: " + e.getMessage()); |
||||||
|
log.error(msg.toString()); |
||||||
|
model.addAttribute("error", msg.toString()); |
||||||
|
return "error"; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (positionid != null) { |
||||||
|
try{ |
||||||
|
log.info("positionid: " + positionid); |
||||||
|
PositionEntity position = positionService.findById(Long.valueOf(positionid)); |
||||||
|
//обработать вход нового пользователя
|
||||||
|
AccountEntity account = AccountEntity.builder() |
||||||
|
.position(position) |
||||||
|
.build(); |
||||||
|
|
||||||
|
//сохранить в базе данных
|
||||||
|
account = accountService.save(account); |
||||||
|
log.info("сохраняем account: " + account); |
||||||
|
|
||||||
|
//получить id аккаунта
|
||||||
|
String code = Code.encode(account.getId() + ""); |
||||||
|
account.setCode(code); |
||||||
|
//обновили аккаунт в базе данных
|
||||||
|
account = accountService.save(account); |
||||||
|
|
||||||
|
model.addAttribute("account", account); |
||||||
|
return "account"; |
||||||
|
} catch (Exception e) { |
||||||
|
StringBuilder msg = new StringBuilder(); |
||||||
|
msg.append("Не удалось получить данные аккаунта: " + e.getMessage()); |
||||||
|
log.error(msg.toString()); |
||||||
|
model.addAttribute("error", msg.toString()); |
||||||
|
return "error"; |
||||||
|
} |
||||||
|
} |
||||||
|
//вернуть страницу ошибки
|
||||||
|
StringBuilder msg = new StringBuilder(); |
||||||
|
msg.append("Не указаны данные для доступа к аккаунту."); |
||||||
|
log.error(msg.toString()); |
||||||
|
model.addAttribute("error", msg.toString()); |
||||||
|
return "error"; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,9 @@ |
|||||||
|
package gsp.technologies.main.api.account; |
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
@Repository |
||||||
|
public interface AccountRepository extends JpaRepository<AccountEntity, Long> { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,20 @@ |
|||||||
|
package gsp.technologies.main.api.account; |
||||||
|
|
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
@Service |
||||||
|
public class AccountService { |
||||||
|
private final AccountRepository repo; |
||||||
|
|
||||||
|
public AccountService(AccountRepository repo) { |
||||||
|
this.repo = repo; |
||||||
|
} |
||||||
|
|
||||||
|
public AccountEntity save(AccountEntity account) { |
||||||
|
return repo.save(account); |
||||||
|
} |
||||||
|
|
||||||
|
public AccountEntity findById(Long id) { |
||||||
|
return repo.findById(id).orElse(null); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,24 @@ |
|||||||
|
package gsp.technologies.main.api.course; |
||||||
|
|
||||||
|
import jakarta.persistence.Entity; |
||||||
|
import jakarta.persistence.GeneratedValue; |
||||||
|
import jakarta.persistence.GenerationType; |
||||||
|
import jakarta.persistence.Id; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Builder; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.NoArgsConstructor; |
||||||
|
|
||||||
|
@Data |
||||||
|
@AllArgsConstructor |
||||||
|
@NoArgsConstructor |
||||||
|
@Builder |
||||||
|
@Entity |
||||||
|
public class CourseEntity { |
||||||
|
@Id |
||||||
|
@GeneratedValue(strategy=GenerationType.AUTO) |
||||||
|
private Long id; |
||||||
|
|
||||||
|
private String name; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,53 @@ |
|||||||
|
package gsp.technologies.main.api.course; |
||||||
|
|
||||||
|
import java.util.Collection; |
||||||
|
|
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.stereotype.Controller; |
||||||
|
import org.springframework.ui.Model; |
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||||
|
|
||||||
|
@Controller |
||||||
|
@RequestMapping(path = "/courses") |
||||||
|
public class CourseFaceController { |
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(CourseFaceController.class); |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private CourseService courseService; |
||||||
|
public CourseFaceController(CourseService courseService) { |
||||||
|
this.courseService = courseService; |
||||||
|
} |
||||||
|
|
||||||
|
@GetMapping("") |
||||||
|
public String course(Model model) { |
||||||
|
log.info("GET /courses"); |
||||||
|
|
||||||
|
Collection <CourseEntity> courses = courseService.findAll(); |
||||||
|
model.addAttribute("courses", courses); |
||||||
|
return "courses/main"; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Создание нового курса |
||||||
|
*/ |
||||||
|
@PostMapping("") |
||||||
|
public String create(@RequestParam(name = "name", required = true) String name) { |
||||||
|
log.info("POST /courses"); |
||||||
|
CourseEntity entity = new CourseEntity(); |
||||||
|
entity.setName(name); |
||||||
|
|
||||||
|
courseService.save(entity); |
||||||
|
|
||||||
|
return "redirect:/courses"; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,9 @@ |
|||||||
|
package gsp.technologies.main.api.course; |
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
@Repository |
||||||
|
public interface CourseRepository extends JpaRepository<CourseEntity, Long> { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,23 @@ |
|||||||
|
package gsp.technologies.main.api.course; |
||||||
|
|
||||||
|
import java.util.Collection; |
||||||
|
|
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
@Service |
||||||
|
public class CourseService { |
||||||
|
private final CourseRepository repo; |
||||||
|
public CourseService(CourseRepository repo) { |
||||||
|
this.repo = repo; |
||||||
|
} |
||||||
|
public Collection<CourseEntity> findAll() { |
||||||
|
return repo.findAll(); |
||||||
|
} |
||||||
|
public CourseEntity save(CourseEntity entity) { |
||||||
|
return repo.save(entity); |
||||||
|
} |
||||||
|
public CourseEntity findById(Long courseid) { |
||||||
|
return repo.findById(courseid).get(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -1,23 +1,98 @@ |
|||||||
package gsp.technologies.main.api.organization; |
package gsp.technologies.main.api.organization; |
||||||
|
|
||||||
|
import java.util.Collection; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
|
||||||
import org.slf4j.Logger; |
import org.slf4j.Logger; |
||||||
import org.slf4j.LoggerFactory; |
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
import org.springframework.stereotype.Controller; |
import org.springframework.stereotype.Controller; |
||||||
|
import org.springframework.ui.Model; |
||||||
import org.springframework.web.bind.annotation.GetMapping; |
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.PathVariable; |
||||||
import org.springframework.web.bind.annotation.RequestMapping; |
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||||
|
|
||||||
|
|
||||||
@Controller |
@Controller |
||||||
@RequestMapping(path = "/organizations") |
@RequestMapping(path = "/organizations") |
||||||
public class OrganizationFaceController { |
public class OrganizationFaceController { |
||||||
private static final Logger log = LoggerFactory.getLogger(OrganizationFaceController.class); |
private static final Logger log = LoggerFactory.getLogger(OrganizationFaceController.class); |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private OrganizationService service; |
||||||
|
|
||||||
|
public OrganizationFaceController(OrganizationService organizationService) { |
||||||
|
this.service = organizationService; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
/** |
/** |
||||||
* Главная страница для работы с перечнем организаций |
* Главная страница для работы с перечнем организаций |
||||||
* @return |
* @return |
||||||
*/ |
*/ |
||||||
@GetMapping("") |
@GetMapping("") |
||||||
public String organizations() { |
public String organizations(Model model) { |
||||||
log.info("GET /organizations"); |
log.info("GET /organizations"); |
||||||
|
// получаем список организаций
|
||||||
|
Collection<OrganizationEntity> organizations = service.findAll(); |
||||||
|
// сортируем по названию
|
||||||
|
organizations = organizations.stream().sorted((o1, o2) -> o1.getName().compareTo(o2.getName())).collect(Collectors.toList()); |
||||||
|
// передаем список организаций в шаблон
|
||||||
|
model.addAttribute("organizations", organizations); |
||||||
|
model.addAttribute("organizationService", service); |
||||||
return "organizations/main"; |
return "organizations/main"; |
||||||
} |
} |
||||||
|
/** |
||||||
|
* Добавление новой организации |
||||||
|
*/ |
||||||
|
@PostMapping("") |
||||||
|
public String create(@RequestParam(name = "name", required = true) String name) { |
||||||
|
log.info("POST /organizations"); |
||||||
|
OrganizationEntity entity = new OrganizationEntity(); |
||||||
|
entity.setName(name); |
||||||
|
|
||||||
|
service.save(entity); |
||||||
|
|
||||||
|
return "redirect:/organizations"; |
||||||
|
} |
||||||
|
/** |
||||||
|
* Удаление организации |
||||||
|
* @param id |
||||||
|
*/ |
||||||
|
@GetMapping("/{id}/delete") |
||||||
|
public String delete(@PathVariable(name = "id", required = true) Long id) { |
||||||
|
log.info("GET /organizations/{id}/delete"); |
||||||
|
service.deleteById(id); |
||||||
|
return "redirect:/organizations"; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Переход к форме редактирования организации |
||||||
|
*/ |
||||||
|
@GetMapping("/{id}/edit") |
||||||
|
public String edit(@PathVariable(name = "id", required = true) Long id, Model model) { |
||||||
|
log.info("GET /organizations/{id}/edit"); |
||||||
|
OrganizationEntity entity = service.findById(id); |
||||||
|
model.addAttribute("organization", entity); |
||||||
|
return "organizations/edit"; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Редакрирование организации |
||||||
|
*/ |
||||||
|
@PostMapping("/{id}/edit") |
||||||
|
public String update(@PathVariable(name = "id", required = true) Long id, @RequestParam(name = "name", required = true) String name) { |
||||||
|
log.info("POST /organizations/{id}/edit"); |
||||||
|
OrganizationEntity entity = new OrganizationEntity(); |
||||||
|
entity.setName(name); |
||||||
|
entity.setId(id); |
||||||
|
service.save(entity); |
||||||
|
return "redirect:/organizations"; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} |
} |
||||||
|
@ -0,0 +1,79 @@ |
|||||||
|
package gsp.technologies.main.api.position; |
||||||
|
|
||||||
|
import java.util.Collection; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
|
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.data.domain.PageRequest; |
||||||
|
import org.springframework.data.domain.Pageable; |
||||||
|
import org.springframework.data.domain.Sort; |
||||||
|
import org.springframework.stereotype.Controller; |
||||||
|
import org.springframework.ui.Model; |
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||||
|
|
||||||
|
import gsp.technologies.main.api.organization.OrganizationEntity; |
||||||
|
import gsp.technologies.main.api.organization.OrganizationService; |
||||||
|
|
||||||
|
@Controller |
||||||
|
@RequestMapping(path = "/positions") |
||||||
|
public class PositionFaceController { |
||||||
|
private static final Logger log = LoggerFactory.getLogger(PositionFaceController.class); |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private OrganizationService organizationService; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private PositionService positionService; |
||||||
|
|
||||||
|
public PositionFaceController(PositionService positionService, OrganizationService organizationService) { |
||||||
|
this.positionService = positionService; |
||||||
|
this.organizationService = organizationService; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Главная страница работы с должностями |
||||||
|
*/ |
||||||
|
@GetMapping("") |
||||||
|
public String positions(Model model) { |
||||||
|
log.info("GET /positions"); |
||||||
|
|
||||||
|
// получаем список организаций
|
||||||
|
Collection<OrganizationEntity> organizations = organizationService.findAll() |
||||||
|
.stream().sorted((o1, o2) -> o1.getName().compareTo(o2.getName())).collect(Collectors.toList()); |
||||||
|
//
|
||||||
|
model.addAttribute("organizations", organizations); |
||||||
|
|
||||||
|
//получаем список должностей
|
||||||
|
int number = 0; |
||||||
|
int size = 100; |
||||||
|
String sortBy = "name"; |
||||||
|
|
||||||
|
Sort sort = Sort.by(sortBy); |
||||||
|
Pageable of = PageRequest.of(number, size, sort); |
||||||
|
|
||||||
|
Collection<PositionEntity> positions = positionService.findAll(of).getContent(); |
||||||
|
model.addAttribute("positions", positions); |
||||||
|
return "positions/main"; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Добавление должности |
||||||
|
*/ |
||||||
|
@PostMapping("") |
||||||
|
public String create( |
||||||
|
@RequestParam(name = "name", required = true) String name, |
||||||
|
@RequestParam(name = "organizationId", required = true) Long organizationId) { |
||||||
|
log.info("POST /positions"); |
||||||
|
PositionEntity entity = new PositionEntity(); |
||||||
|
entity.setName(name); |
||||||
|
entity.setOrganization(organizationService.findById(organizationId)); |
||||||
|
positionService.save(entity); |
||||||
|
return "redirect:/positions"; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,91 @@ |
|||||||
|
package gsp.technologies.main.api.target; |
||||||
|
|
||||||
|
import java.util.Collection; |
||||||
|
import java.util.Collections; |
||||||
|
|
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.stereotype.Controller; |
||||||
|
import org.springframework.ui.Model; |
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||||
|
|
||||||
|
import gsp.technologies.main.api.course.CourseEntity; |
||||||
|
import gsp.technologies.main.api.course.CourseService; |
||||||
|
import gsp.technologies.main.api.organization.OrganizationEntity; |
||||||
|
import gsp.technologies.main.api.organization.OrganizationService; |
||||||
|
import gsp.technologies.main.api.position.PositionEntity; |
||||||
|
import gsp.technologies.main.api.position.PositionService; |
||||||
|
|
||||||
|
@Controller |
||||||
|
@RequestMapping(path = "/targets") |
||||||
|
public class TargetFaceController { |
||||||
|
private static final Logger log = LoggerFactory.getLogger(TargetFaceController.class); |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private TargetService targetService; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private OrganizationService organizationService; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private PositionService positionService; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private CourseService courseService; |
||||||
|
|
||||||
|
public TargetFaceController(TargetService targetService, OrganizationService organizationService, PositionService positionService, CourseService courseService) { |
||||||
|
this.targetService = targetService; |
||||||
|
this.organizationService = organizationService; |
||||||
|
this.positionService = positionService; |
||||||
|
this.courseService = courseService; |
||||||
|
} |
||||||
|
|
||||||
|
@GetMapping("") |
||||||
|
public String targets(Model model) { |
||||||
|
log.info("GET /targets"); |
||||||
|
//передаем в шаблон перечень организаций
|
||||||
|
Collection <OrganizationEntity> organizations = organizationService.findAll(); |
||||||
|
model.addAttribute("organizations", organizations); |
||||||
|
|
||||||
|
//передаем в шаблон перечень должностей
|
||||||
|
Collection <PositionEntity> positions = positionService.findAll(); |
||||||
|
model.addAttribute("positions", positions); |
||||||
|
|
||||||
|
//передаем в шаблон перечень курсов
|
||||||
|
Collection <CourseEntity> courses = courseService.findAll(); |
||||||
|
model.addAttribute("courses", courses); |
||||||
|
|
||||||
|
//передаем в шаблон перечень созданных задачь
|
||||||
|
Collection <TargetEntity> targets = targetService.findAll(); |
||||||
|
model.addAttribute("targets", targets); |
||||||
|
|
||||||
|
return "targets/main"; |
||||||
|
} |
||||||
|
|
||||||
|
@PostMapping("") |
||||||
|
public String create( |
||||||
|
@RequestParam(name = "courseid", required = true) Long courseid, |
||||||
|
@RequestParam(name = "positionid", required = true) Long positionid, |
||||||
|
@RequestParam(name = "questions-count", required = true) Integer questionsCount, |
||||||
|
@RequestParam(name = "questions-limit", required = true) Integer questionsLimit |
||||||
|
){ |
||||||
|
log.info("POST /targets"); |
||||||
|
TargetEntity entity = TargetEntity.builder() |
||||||
|
.course(courseService.findById(courseid)) |
||||||
|
.position(positionService.findById(positionid)) |
||||||
|
.questionsCount(questionsCount) |
||||||
|
.questionsLimit(questionsLimit) |
||||||
|
.build(); |
||||||
|
|
||||||
|
targetService.save(entity); |
||||||
|
return "redirect:/targets"; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,9 @@ |
|||||||
|
package gsp.technologies.main.api.target; |
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
@Repository |
||||||
|
public interface TargetRepository extends JpaRepository<TargetEntity, Long> { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,30 @@ |
|||||||
|
package gsp.technologies.main.api.target; |
||||||
|
|
||||||
|
import java.util.Collection; |
||||||
|
|
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import gsp.technologies.main.api.course.CourseEntity; |
||||||
|
import gsp.technologies.main.api.position.PositionEntity; |
||||||
|
|
||||||
|
@Service |
||||||
|
public class TargetService { |
||||||
|
private final TargetRepository repo; |
||||||
|
|
||||||
|
public TargetService(TargetRepository repo) { |
||||||
|
this.repo = repo; |
||||||
|
} |
||||||
|
|
||||||
|
public Collection<TargetEntity> findAll() { |
||||||
|
return repo.findAll(); |
||||||
|
} |
||||||
|
|
||||||
|
public TargetEntity save(TargetEntity entity) { |
||||||
|
return repo.save(entity); |
||||||
|
} |
||||||
|
|
||||||
|
public Collection<CourseEntity> findAllByPosition(PositionEntity position) { |
||||||
|
repo.findAllByPosition(position); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -1,36 +0,0 @@ |
|||||||
package gsp.technologies.main.course; |
|
||||||
|
|
||||||
import org.slf4j.Logger; |
|
||||||
import org.slf4j.LoggerFactory; |
|
||||||
import org.springframework.stereotype.Controller; |
|
||||||
import org.springframework.ui.Model; |
|
||||||
import org.springframework.web.bind.annotation.PostMapping; |
|
||||||
import org.springframework.web.bind.annotation.RequestMapping; |
|
||||||
import org.springframework.web.bind.annotation.RequestParam; |
|
||||||
|
|
||||||
import gsp.technologies.main.account.dto.AccountDTO; |
|
||||||
import gsp.technologies.main.code.Code; |
|
||||||
|
|
||||||
@Controller |
|
||||||
@RequestMapping(path = "/courses") |
|
||||||
public class CourseController { |
|
||||||
private static final Logger log = LoggerFactory.getLogger(CourseController.class); |
|
||||||
|
|
||||||
@PostMapping("/view") |
|
||||||
public String coursewithdata(Model model, @RequestParam(name = "courseid", required = true) String courseid, @RequestParam(name = "accountid", required = true) String accountid) { |
|
||||||
log.info("GET /courses/view"); |
|
||||||
log.info("Account пришедший в контроллер: {}", accountid); |
|
||||||
|
|
||||||
model.addAttribute("courseid", courseid + ""); |
|
||||||
|
|
||||||
//получить полный аккаунт из репозитория по id
|
|
||||||
AccountDTO acc = AccountDTO.builder() |
|
||||||
.id(accountid) |
|
||||||
.code(Code.encode(accountid)) |
|
||||||
.build(); |
|
||||||
model.addAttribute("account", acc); |
|
||||||
return "course"; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} |
|
@ -1,19 +0,0 @@ |
|||||||
package gsp.technologies.main.course.dto; |
|
||||||
|
|
||||||
import java.io.Serializable; |
|
||||||
|
|
||||||
import lombok.AllArgsConstructor; |
|
||||||
import lombok.Builder; |
|
||||||
import lombok.Data; |
|
||||||
import lombok.NoArgsConstructor; |
|
||||||
|
|
||||||
@NoArgsConstructor |
|
||||||
@AllArgsConstructor |
|
||||||
@Builder |
|
||||||
@Data |
|
||||||
public class CourseDTO implements Serializable { |
|
||||||
|
|
||||||
private String id; |
|
||||||
private String name; |
|
||||||
private Boolean passed; |
|
||||||
} |
|
@ -0,0 +1,25 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" |
||||||
|
xmlns:th="http://www.thymeleaf.org"> |
||||||
|
<head> |
||||||
|
<meta charset="UTF-8"> |
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||||
|
<title>exam-courses</title> |
||||||
|
<script src="https://cdn.jsdelivr.net/npm/@webcomponents/webcomponentsjs@2/webcomponents-loader.min.js"></script> |
||||||
|
<script type="module" src="https://cdn.jsdelivr.net/gh/zerodevx/zero-md@1/src/zero-md.min.js"></script> |
||||||
|
</head> |
||||||
|
<header> |
||||||
|
</header> |
||||||
|
|
||||||
|
<body> |
||||||
|
<h1>Фрагменты для работы с курсами</h1> |
||||||
|
<!-- Добавление нового курса --> |
||||||
|
<div th:insert="~{courses/fragments/main :: create}"></div> |
||||||
|
<!-- Перечень курсов --> |
||||||
|
<div th:insert="~{courses/fragments/main :: list(courses=${courses})}"></div> |
||||||
|
</body> |
||||||
|
|
||||||
|
<footer> |
||||||
|
<div th:insert="~{fragments/common/footer :: copy}"></div> |
||||||
|
</footer> |
||||||
|
</html> |
@ -0,0 +1,26 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" |
||||||
|
xmlns:th="http://www.thymeleaf.org"> |
||||||
|
<head> |
||||||
|
<meta charset="UTF-8"> |
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||||
|
<title>exam-error</title> |
||||||
|
<script src="https://cdn.jsdelivr.net/npm/@webcomponents/webcomponentsjs@2/webcomponents-loader.min.js"></script> |
||||||
|
<script type="module" src="https://cdn.jsdelivr.net/gh/zerodevx/zero-md@1/src/zero-md.min.js"></script> |
||||||
|
</head> |
||||||
|
<header> |
||||||
|
</header> |
||||||
|
<body> |
||||||
|
<div> |
||||||
|
<h1>Выявлена ошибка:</h1> |
||||||
|
<p th:text="${error}"></p> |
||||||
|
</div> |
||||||
|
<form th:action="@{/mainframe}" method="get"> |
||||||
|
<input type="submit" value="ПЕРЕЙТИ НА ГЛАВНУЮ СТРАНИЦУ"> |
||||||
|
</form> |
||||||
|
</body> |
||||||
|
<footer> |
||||||
|
<div th:insert="~{fragments/common/footer :: copy}"></div> |
||||||
|
</footer> |
||||||
|
|
||||||
|
</html> |
@ -0,0 +1,23 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" |
||||||
|
xmlns:th="http://www.thymeleaf.org"> |
||||||
|
<head> |
||||||
|
<meta charset="UTF-8"> |
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||||
|
<title>exam-organizations-edit</title> |
||||||
|
<script src="https://cdn.jsdelivr.net/npm/@webcomponents/webcomponentsjs@2/webcomponents-loader.min.js"></script> |
||||||
|
<script type="module" src="https://cdn.jsdelivr.net/gh/zerodevx/zero-md@1/src/zero-md.min.js"></script> |
||||||
|
</head> |
||||||
|
<header> |
||||||
|
</header> |
||||||
|
|
||||||
|
<body> |
||||||
|
<h1>Фрагменты для работы с данными организаций</h1> |
||||||
|
<!-- Редактирование организации --> |
||||||
|
<div th:insert="~{organizations/fragments/main :: edit(organization=${organization})}"></div> |
||||||
|
</body> |
||||||
|
|
||||||
|
<footer> |
||||||
|
<div th:insert="~{fragments/common/footer :: copy}"></div> |
||||||
|
</footer> |
||||||
|
</html> |
@ -0,0 +1,25 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" |
||||||
|
xmlns:th="http://www.thymeleaf.org"> |
||||||
|
<head> |
||||||
|
<meta charset="UTF-8"> |
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||||
|
<title>exam-positions</title> |
||||||
|
<script src="https://cdn.jsdelivr.net/npm/@webcomponents/webcomponentsjs@2/webcomponents-loader.min.js"></script> |
||||||
|
<script type="module" src="https://cdn.jsdelivr.net/gh/zerodevx/zero-md@1/src/zero-md.min.js"></script> |
||||||
|
</head> |
||||||
|
<header> |
||||||
|
</header> |
||||||
|
|
||||||
|
<body> |
||||||
|
<h1>Фрагменты для работы с данными о должностях</h1> |
||||||
|
<!-- Добавление новой должности --> |
||||||
|
<div th:insert="~{positions/fragments/main :: create(organizations=${organizations})}"></div> |
||||||
|
<!-- Перечень должностей --> |
||||||
|
<div th:insert="~{positions/fragments/main :: list(positions=${positions})}"></div> |
||||||
|
</body> |
||||||
|
|
||||||
|
<footer> |
||||||
|
<div th:insert="~{fragments/common/footer :: copy}"></div> |
||||||
|
</footer> |
||||||
|
</html> |
@ -0,0 +1,56 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" |
||||||
|
xmlns:th="http://www.thymeleaf.org"> |
||||||
|
<head> |
||||||
|
<meta charset="UTF-8"> |
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||||
|
<title>exam-targets</title> |
||||||
|
<script src="https://cdn.jsdelivr.net/npm/@webcomponents/webcomponentsjs@2/webcomponents-loader.min.js"></script> |
||||||
|
<script type="module" src="https://cdn.jsdelivr.net/gh/zerodevx/zero-md@1/src/zero-md.min.js"></script> |
||||||
|
</head> |
||||||
|
<header> |
||||||
|
</header> |
||||||
|
|
||||||
|
<body> |
||||||
|
<h1>Фрагменты для работы с назначением курсов</h1> |
||||||
|
<!-- Добавление новой задачи --> |
||||||
|
<div th:insert="~{targets/fragments/main :: create(organizations=${organizations}, positions=${positions}, courses=${courses})}"></div> |
||||||
|
<!-- Перечень задачь --> |
||||||
|
<div th:insert="~{targets/fragments/main :: list(targets=${targets})}"></div> |
||||||
|
</body> |
||||||
|
|
||||||
|
<footer> |
||||||
|
<div th:insert="~{fragments/common/footer :: copy}"></div> |
||||||
|
</footer> |
||||||
|
<script> |
||||||
|
// Функция для загрузки должностей |
||||||
|
function loadPositions() { |
||||||
|
let organizationSelect = document.getElementById('organization-select'); |
||||||
|
let organizationId = organizationSelect.value; |
||||||
|
let req = new XMLHttpRequest(); |
||||||
|
req.open("GET", "http://localhost:100/api/v1/positions?id=" + organizationId, false); |
||||||
|
req.send(null); |
||||||
|
let positions = JSON.parse(req.responseText); |
||||||
|
console.log(positions); |
||||||
|
let positionSelect = document.getElementById('position-select'); |
||||||
|
positionSelect.innerHTML = ''; |
||||||
|
// поле "должность" в селекте |
||||||
|
let option = document.createElement('option'); |
||||||
|
option.value = 0; |
||||||
|
option.text = "должность"; |
||||||
|
option.disabled = true; |
||||||
|
option.selected = true; |
||||||
|
positionSelect.add(option); |
||||||
|
// Добавление остальных должностей |
||||||
|
for (let i = 0; i < positions.content.length; i++) { |
||||||
|
let option = document.createElement('option'); |
||||||
|
option.value = positions.content[i].id; |
||||||
|
option.text = positions.content[i].name; |
||||||
|
positionSelect.add(option); |
||||||
|
} |
||||||
|
} |
||||||
|
// Загрузка должностей при выборе организации |
||||||
|
let organizationSelect = document.getElementById('organization-select'); |
||||||
|
organizationSelect.addEventListener('change', loadPositions); |
||||||
|
</script> |
||||||
|
</html> |
Loading…
Reference in new issue