Pokud má další schvalovatel v pořadí nastaveno schvalování pouze
nadlimitních požadavků a požadavek je pod limitem, schválí se za tohoto schvalovatele automaticky. closes #133
This commit is contained in:
@@ -14,7 +14,7 @@ import org.springframework.security.access.prepost.PostFilter;
|
|||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
public class ReqMaterialServiceImpl extends RequirementBaseServiceImpl<Requirement> implements RequirementService, RequirementBaseService<Requirement>
|
public class ReqMaterialServiceImpl extends RequirementServiceImpl implements RequirementService, RequirementBaseService<Requirement>
|
||||||
{
|
{
|
||||||
@Autowired
|
@Autowired
|
||||||
private RequirementTypeService reqTypeService;
|
private RequirementTypeService reqTypeService;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import org.springframework.security.access.prepost.PostFilter;
|
|||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
public class ReqServicesServiceImpl extends RequirementBaseServiceImpl<Requirement> implements RequirementService, RequirementBaseService<Requirement>
|
public class ReqServicesServiceImpl extends RequirementServiceImpl implements RequirementService, RequirementBaseService<Requirement>
|
||||||
{
|
{
|
||||||
@Autowired
|
@Autowired
|
||||||
private RequirementTypeService reqTypeService;
|
private RequirementTypeService reqTypeService;
|
||||||
|
|||||||
+30
-20
@@ -182,10 +182,7 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected void approve(T entity, User user) {
|
||||||
@Transactional
|
|
||||||
@PreAuthorize("this.canApprove(#entity)")
|
|
||||||
public void approve(T entity) {
|
|
||||||
T e = (T) dao.getById(entity.getId());
|
T e = (T) dao.getById(entity.getId());
|
||||||
|
|
||||||
Workflow wf = getNextWorkflow(e);
|
Workflow wf = getNextWorkflow(e);
|
||||||
@@ -195,7 +192,7 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
|
|||||||
|
|
||||||
Role role = wf.getRole();
|
Role role = wf.getRole();
|
||||||
AuthItem auth = new AuthItem();
|
AuthItem auth = new AuthItem();
|
||||||
auth.setApprover(getLoggedInUser());
|
auth.setApprover(user);
|
||||||
auth.setRole(role);
|
auth.setRole(role);
|
||||||
auth.setAuthDate(new Date());
|
auth.setAuthDate(new Date());
|
||||||
|
|
||||||
@@ -211,27 +208,40 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
|
|||||||
|
|
||||||
super.update(e);
|
super.update(e);
|
||||||
|
|
||||||
this.sendToApprovers(e);
|
if (!autoApprove(entity)) {
|
||||||
|
this.sendToApprovers(e);
|
||||||
|
|
||||||
SettingsData settings = settingsService.getSettings();
|
SettingsData settings = settingsService.getSettings();
|
||||||
MailMessage message = null;
|
MailMessage message = null;
|
||||||
|
|
||||||
if (e.getOwnedBy().getEmail() != null
|
if (e.getOwnedBy().getEmail() != null
|
||||||
&& !e.getOwnedBy().getEmail().isEmpty()
|
&& !e.getOwnedBy().getEmail().isEmpty()
|
||||||
&& e.getOwnedBy().isNotify()) {
|
&& e.getOwnedBy().isNotify()) {
|
||||||
if (e.getState() == RequirementState.APPROVED && settings.getConfReqTemplate() != null) {
|
if (e.getState() == RequirementState.APPROVED && settings.getConfReqTemplate() != null) {
|
||||||
message = messageBuilder.buildMessage(settings.getConfReqTemplate(), e);
|
message = messageBuilder.buildMessage(settings.getConfReqTemplate(), e);
|
||||||
} else if (settings.getAuthReqTemplate() != null) {
|
} else if (settings.getAuthReqTemplate() != null) {
|
||||||
message = messageBuilder.buildMessage(settings.getAuthReqTemplate(), e);
|
message = messageBuilder.buildMessage(settings.getAuthReqTemplate(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
message.setTo(e.getOwnedBy().getEmail());
|
message.setTo(e.getOwnedBy().getEmail());
|
||||||
mailer.send(message);
|
mailer.send(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
@PreAuthorize("this.canApprove(#entity)")
|
||||||
|
public void approve(T entity) {
|
||||||
|
approve(entity, getLoggedInUser());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean autoApprove(T entity) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public boolean canApprove(T entity) {
|
public boolean canApprove(T entity) {
|
||||||
@@ -243,7 +253,7 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Workflow getNextWorkflow(T e) {
|
protected Workflow getNextWorkflow(T e) {
|
||||||
AuthItem authItem = null;
|
AuthItem authItem = null;
|
||||||
if (e.getWorkflow() == null) {
|
if (e.getWorkflow() == null) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -3,8 +3,11 @@ package info.bukova.isspst.services.requirement;
|
|||||||
import info.bukova.isspst.Constants;
|
import info.bukova.isspst.Constants;
|
||||||
import info.bukova.isspst.data.Requirement;
|
import info.bukova.isspst.data.Requirement;
|
||||||
import info.bukova.isspst.data.RequirementState;
|
import info.bukova.isspst.data.RequirementState;
|
||||||
|
import info.bukova.isspst.data.User;
|
||||||
|
import info.bukova.isspst.data.Workflow;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
@@ -26,4 +29,21 @@ public class RequirementServiceImpl extends
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean autoApprove(Requirement entity) {
|
||||||
|
List<User> approvers = this.getNextApprover(entity);
|
||||||
|
Workflow nextWf = this.getNextWorkflow(entity);
|
||||||
|
|
||||||
|
if (approvers == null || approvers.isEmpty() || nextWf == null || nextWf.getLimit() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity.getSumTotal().compareTo(nextWf.getLimit()) == -1) {
|
||||||
|
approve(entity, approvers.get(0));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user