dbms_init...1

This commit is contained in:
choi.jh 2025-07-02 17:03:34 +09:00
parent 32b4fd1c7e
commit 2719073d23
3 changed files with 52 additions and 66 deletions

View File

@ -90,6 +90,26 @@ abstract class CommonController extends BaseController
{
return $this->_control['form_fields'] ?? [];
}
final protected function setFieldRule(string $field, string $rule): void
{
if (!array_key_exists('field_rules', $this->_control)) {
$this->_control['field_rules'] = [];
}
$this->_control['field_rules'][$field] = $rule;
}
final protected function setFieldRules(array $rules): void
{
$this->_control['field_rules'] = $rules;
}
final protected function getFieldRule(string $field): string
{
return $this->_control['field_rules'][$field] ?? [];
}
final protected function getFieldRules(): array
{
return $this->_control['field_rules'] ?? [];
}
final protected function setIndexFields(array $fields): void
{
$this->_control['index_fields'] = $fields;
@ -122,21 +142,6 @@ abstract class CommonController extends BaseController
{
return $this->_control['batchjob_fields'] ?? [];
}
final protected function setFieldRule(string $field, string $rule): void
{
if (!array_key_exists('field_rules', $this->_control)) {
$this->_control['field_rules'] = [];
}
$this->_control['field_rules'][$field] = $rule;
}
final protected function getFieldRule(string $field): string
{
return $this->_control['field_rules'][$field] ?? [];
}
final protected function getFieldRules(): array
{
return $this->_control['field_rules'] ?? [];
}
final protected function setFilterFieldOption(string $field, array $options): void
{
if (!array_key_exists('filter_optons', $this->_control)) {
@ -144,6 +149,10 @@ abstract class CommonController extends BaseController
}
$this->_control['filter_optons'][$field] = $options;
}
final protected function setFilterFieldOptions(array $options): void
{
$this->_control['filter_optons'] = $options;
}
final protected function getFilterFieldOption(string $field): array
{
return $this->_control['filter_optons'][$field] ?? [];
@ -157,16 +166,16 @@ abstract class CommonController extends BaseController
{ //각 Field 초기화
$this->setAction($action);
$this->setFormFields(array_key_exists('formFields', $fields) ? $fields['formFields'] : $this->getService()->getFormFields());
foreach ($this->getFormFields() as $field) {
$this->setFieldRule($field, $this->getFormFieldRule($this->getAction(), $field));
}
$this->setIndexFields(array_key_exists('indexFields', $fields) ? $fields['indexFields'] : $this->getService()->getIndexFields());
$this->setViewFields(array_key_exists('viewFields', $fields) ? $fields['viewFields'] : $this->getService()->getViewFields());
$this->setFilterFields(array_key_exists('filterFields', $fields) ? $fields['filterFields'] : $this->getService()->getFilterFields());
$this->setBatchJobFields(array_key_exists('batchjobFields', $fields) ? $fields['batchjobFields'] : $this->getService()->getBatchJobFields());
foreach ($this->getViewFields() as $field) {
$this->setFieldRule($field, $this->getFormFieldRule($this->getAction(), $field));
}
foreach ($this->getFilterFields() as $field) {
$this->setFilterFieldOption($field, $this->getFormFieldOption($field));
}
$this->setBatchJobFields(array_key_exists('batchjobFields', $fields) ? $fields['batchjobFields'] : $this->getService()->getBatchJobFields());
}
protected function getFormFieldRule(string $action, string $field): string
{
@ -271,10 +280,6 @@ abstract class CommonController extends BaseController
//각 Field 초기화
// $this->getMyAuth()->pushCurrentUrl($this->request->getUri()->getPath() . ($this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : ""));
$this->initAction(__FUNCTION__);
//FieldRule정의
foreach ($this->getFormFields() as $field) {
$this->setFieldRule($field, $this->getFormFieldRule($this->getAction(), $field));
}
helper(['form']);
//filter_fields에 해당하는 값이 있을 경우 정의
foreach ($this->getFilterFields() as $field) {
@ -302,10 +307,6 @@ abstract class CommonController extends BaseController
try {
//각 Field 초기화
$this->initAction(__FUNCTION__);
//FieldRule정의
foreach ($this->getFormFields() as $field) {
$this->setFieldRule($field, $this->getFormFieldRule($this->getAction(), $field));
}
//입력값정의
$formDatas = [];
foreach ($this->getFormFields() as $field) {
@ -331,10 +332,6 @@ abstract class CommonController extends BaseController
//각 Field 초기화
// $this->getMyAuth()->pushCurrentUrl($this->request->getUri()->getPath() . ($this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : ""));
$this->initAction(__FUNCTION__);
//FieldRule정의
foreach ($this->getFormFields() as $field) {
$this->setFieldRule($field, $this->getFormFieldRule($this->getAction(), $field));
}
helper(['form']);
//filter_fields에 해당하는 값이 있을 경우 정의
foreach ($this->getFilterFields() as $field) {
@ -368,10 +365,6 @@ abstract class CommonController extends BaseController
try {
//각 Field 초기화
$this->initAction(__FUNCTION__);
//FieldRule정의
foreach ($this->getFormFields() as $field) {
$this->setFieldRule($field, $this->getFormFieldRule($this->getAction(), $field));
}
//입력값정의
$formDatas = [];
foreach ($this->getFormFields() as $field) {
@ -401,9 +394,8 @@ abstract class CommonController extends BaseController
//Transaction Start
$this->getService()->getModel()->transStart();
try {
//각 Field 초기화:조건항목 Field는 한개만 존재하므로 Field와 Rule을 정의 필요
//각 Field 초기화:조건항목 Field는 한개만 존재하므로 Field와 Rule을 정의
$this->setAction(__FUNCTION__);
//Field와 Rule을 재정의
$this->setFormFields([$field]);
$this->setFieldRule($field, $this->getFormFieldRule($this->getAction(), $field));
//입력값정의
@ -432,12 +424,10 @@ abstract class CommonController extends BaseController
//Transaction Start
$this->getService()->getModel()->transStart();
try {
//각 Field 초기화: 일괄작업은 선택된 조건항목 Field만 존재하므로 Field와 Rule을 재정의 필요
$this->setAction(__FUNCTION__);
$selectedFields = [];
//getBatchJobFields를 이용해서 선택된 Field 와 값정의
$formDatas = [];
foreach ($this->getService()->getBatchJobFields() as $field) {
//입력한 Field,값정의
$value = $this->request->getPost($field);
if ($value) {
$selectedFields[] = $field;
@ -447,16 +437,17 @@ abstract class CommonController extends BaseController
if (!count($selectedFields)) {
throw new \Exception("변경할 조건항목을 선택하셔야합니다.");
}
//선택된 Fields와 Rules을 재정의
$this->setFormFields([$field]);
foreach ($this->getFormFields() as $field) {
$this->setFieldRule($field, $this->getFormFieldRule($this->getAction(), $field));
}
//변경할 UIDS 정의
$uids = $this->request->getPost('batchjob_uids[]');
if (!is_array($uids) || !count($uids)) {
throw new \Exception("적용할 리스트을 선택하셔야합니다.");
}
//각 Field 초기화: 일괄작업은 선택된 조건항목 Field만 존재하므로 Field와 Rule을 정의
$this->setAction(__FUNCTION__);
$this->setFormFields([$selectedFields]);
foreach ($selectedFields as $field) {
$this->setFieldRule($field, $this->getFormFieldRule($this->getAction(), $field));
}
$entities = [];
foreach ($uids as $uid) {
//기존 Entity 가져오기
@ -467,7 +458,6 @@ abstract class CommonController extends BaseController
$entities[] = $this->batchjob_process($entity, $formDatas);
}
}
$this->entities = $entities;
$this->getService()->getModel()->transCommit();
LogCollector::debug(sprintf("%s에서 총 %s개중 %s개 일괄작업을 완료하였습니다.", __METHOD__, count($uids), count($entities)));

File diff suppressed because one or more lines are too long

View File

@ -146,9 +146,9 @@ abstract class CommonModel extends Model
final protected function save_process(mixed $entity): mixed
{
// 최종 변경사항이 없으면
if (!$entity->hasChanged()) {
return $entity;
}
// if (!$entity->hasChanged()) {
// return $entity;
// }
// 최종 저장 시 오류 발생하면
if (!$this->save($entity)) {
$message = sprintf(
@ -164,11 +164,9 @@ abstract class CommonModel extends Model
public function create(array $formDatas, mixed $entity): mixed
{
LogCollector::debug("입력내용");
LogCollector::debug(var_export($formDatas, true));
// LogCollector::debug("입력내용");
// LogCollector::debug(var_export($formDatas, true));
foreach (array_keys($formDatas) as $field) {
// Field에 맞는 Validation Rule 재정의
$this->setValidationRule($field, $this->getFormFieldRule(__FUNCTION__, $field));
$entity = $this->convertEntityData(__FUNCTION__, $field, $formDatas, $entity);
}
// primaryKey가 자동입력이 아니면
@ -182,25 +180,23 @@ abstract class CommonModel extends Model
$pkField = $this->getPKField();
$entity->$pkField = $this->getInsertID();
}
LogCollector::debug("[{$entity->getPK()}/{$entity->getTitle()}] 입력 후 내용");
LogCollector::debug(var_export($entity->toArray(), true));
// LogCollector::debug("[{$entity->getPK()}/{$entity->getTitle()}] 입력 후 내용");
// LogCollector::debug(var_export($entity->toArray(), true));
return $entity;
}
final public function modify(mixed $entity, array $formDatas): mixed
{
// 저장하기 전에 데이터 값 변경이 필요한 Field
LogCollector::debug("[{$entity->getPK()}/{$entity->getTitle()}] 변경 전 내용");
LogCollector::debug(var_export($formDatas, true));
LogCollector::debug(var_export($entity->toArray(), true));
// LogCollector::debug("[{$entity->getPK()}/{$entity->getTitle()}] 변경 전 내용");
// LogCollector::debug(var_export($formDatas, true));
// LogCollector::debug(var_export($entity->toArray(), true));
foreach (array_keys($formDatas) as $field) {
// Field에 맞는 Validation Rule 재정의
$this->setValidationRule($field, $this->getFormFieldRule(__FUNCTION__, $field));
$entity = $this->convertEntityData(__FUNCTION__, $field, $formDatas, $entity);
}
//수정일추가
$entity->setUpdatedAt(date("Y-m-d H:i:s"));
LogCollector::debug("[{$entity->getPK()}/{$entity->getTitle()}] 변경 후 내용");
LogCollector::debug(var_export($entity->toArray(), true));
// LogCollector::debug("[{$entity->getPK()}/{$entity->getTitle()}] 변경 후 내용");
// LogCollector::debug(var_export($entity->toArray(), true));
return $this->save_process($entity);
}