Skip to content

Instantly share code, notes, and snippets.

@SinTeZWh1te
Last active February 28, 2024 08:22
Show Gist options
  • Save SinTeZWh1te/d94ed75862d356488395598fa60aee2f to your computer and use it in GitHub Desktop.
Save SinTeZWh1te/d94ed75862d356488395598fa60aee2f to your computer and use it in GitHub Desktop.
Закрываем статус, меняем веб-меню и группу договора при установке даты закрытия
package ru.test.bgbilling.kernel.scripts.events;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import ru.bitel.bgbilling.kernel.admin.web.common.bean.WebMenuItem;
import ru.bitel.bgbilling.kernel.admin.web.common.service.BGWebService;
import ru.bitel.bgbilling.kernel.container.managed.ServerContext;
import ru.bitel.bgbilling.kernel.contract.api.common.service.ContractStatusService;
import ru.bitel.bgbilling.kernel.contract.basic.server.action.web.ActionNotification;
import ru.bitel.bgbilling.kernel.contract.label.common.service.ContractLabelService;
import ru.bitel.bgbilling.kernel.contract.status.common.bean.ContractStatus;
import ru.bitel.bgbilling.kernel.event.events.system.ContractCloseEvent;
import ru.bitel.bgbilling.kernel.script.server.dev.EventScriptBase;
import ru.bitel.bgbilling.server.util.Setup;
import ru.bitel.common.TimeUtils;
import ru.bitel.common.sql.ConnectionSet;
import java.sql.Connection;
import java.util.List;
/**
* @author sintezwh1te
*/
public class OnContractCloseEvent
extends EventScriptBase<ContractCloseEvent> {
private static final Logger logger = LogManager.getLogger();
private static final int CLOSED_GROUP_LABEL = 4;
private static final int CLOSED_WEB_MENU = 3;
private static final int CLOSED_STATUS = 6;
@Override
public void onEvent(ContractCloseEvent event, Setup setup, ConnectionSet connectionSet) throws Exception {
ServerContext serverContext = ServerContext.get();
Connection con = connectionSet.getConnection();
ContractLabelService contractLabelService = serverContext.getService(ContractLabelService.class, 0);
BGWebService bgWebService = serverContext.getService(BGWebService.class, 0);
ContractStatusService contractStatusService = serverContext.getService(ContractStatusService.class, 0);
if (!event.isCheck()) {
//Получаем предыдущие группы, чтобы проверить что договор не в закрытой группе и к ним добавить закрытую группу.
//Если нужно просто одну закрытую - можно не получать и передать Collections.singletonList(CLOSED_GROUP_LABEL)
List<Integer> contractLabelIds = contractLabelService.getContractLabelIds(event.getContractId());
if (!contractLabelIds.contains(CLOSED_GROUP_LABEL)) {
contractLabelIds.add(CLOSED_GROUP_LABEL);
contractLabelService.setContractLabelIds(event.getContractId(), contractLabelIds);
}
//Устанавливаем веб-меню для закрытых договоров если оно не установлено
for (WebMenuItem webMenuItem : bgWebService.webMenuContractList(event.getContractId())) {
if (webMenuItem.getId() == CLOSED_WEB_MENU && !webMenuItem.isSelected()) {
bgWebService.setWebMenuIdForContract(CLOSED_WEB_MENU, event.getContractId());
}
}
ContractStatus contractStatus = new ContractStatus();
contractStatus.setDateFrom(TimeUtils.getNextDay(event.getDate()));
contractStatus.setStatus(CLOSED_STATUS);
contractStatus.setContractId(event.getContractId());
contractStatus.setComment("Установлен автоматически при закрытии договора");
contractStatusService.contractStatusChange(event.getContractId(), contractStatus, false, true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment