ENDRPrint_12CRelease/.svn/pristine/b6/b626aeb56a68c1f5750cac225fd1c587309efed3.svn-base

128 lines
5.3 KiB
Plaintext
Raw Permalink Normal View History

2024-08-14 10:58:03 +07:00
package th.co.muangthai.endrprint.controller.service;
import org.apache.log4j.Logger;
import org.springframework.beans.BeanUtils;
import th.co.muangthai.endrprint.controller.AbstractMasterController;
import th.co.muangthai.endrprint.model.bean.form.MsgErrorForm;
import th.co.muangthai.endrprint.model.bean.form.master.EndrProvincialTeamForm;
import th.co.muangthai.endrprint.model.bean.master.EndrProvincialTeamBean;
import th.co.muangthai.endrprint.util.SessionUtil;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
public class ENDR800Service extends AbstractMasterController {
static Logger log = Logger.getLogger(ENDR800Service.class);
//For insert
public MsgErrorForm saveEndrProvincialTeamNewData(EndrProvincialTeamBean newData) {
MsgErrorForm msgErrorForm = new MsgErrorForm();
msgErrorForm.setDataDefaultOk();
try {
//check Duplicate
EndrProvincialTeamForm schForm = new EndrProvincialTeamForm();
schForm.setProvincialId(newData.getProvincialId());
schForm.setTeam(newData.getTeam());
List<EndrProvincialTeamForm> result = commonService.searchEndrProvincialTeamBeanByBean(schForm);
if (result != null && result.size() > 0) {
msgErrorForm.setErrorFlag(getBigDecimal("1"));
msgErrorForm.setErrorDesc("ข้อมูลนี้มีในระบบแล้ว");
return msgErrorForm;
}
//get Max Id
EndrProvincialTeamBean mstTeamTabBeanMaxId = commonService.getProvincialTeamMaxId();
newData.setId(mstTeamTabBeanMaxId.getId().add(BigDecimal.ONE));//MaxId+1
String userId = SessionUtil.getUserLoginForm().getUserId();
newData.setCreatedBy(userId);
newData.setCreatedDate(new Date());
newData.setUpdatedBy(userId);
newData.setUpdatedDate(new Date());
boolean isInsertSuccessful = commonService.insertEndrProvincialTeam(newData);
if (!isInsertSuccessful) {
msgErrorForm.setErrorFlag(getBigDecimal("1"));
msgErrorForm.setErrorDesc("save Error");
return msgErrorForm;
}
} catch (Exception e) {
msgErrorForm.setErrorFlag(getBigDecimal("1"));
msgErrorForm.setErrorDesc("save Error");
log.error(e.toString(), e);
}
return msgErrorForm;
}
//For Edit
public MsgErrorForm saveEndrProvincialTeamData(EndrProvincialTeamBean newData, EndrProvincialTeamBean oldData) {
MsgErrorForm msgErrorForm = new MsgErrorForm();
msgErrorForm.setDataDefaultOk();
try {
if (!newData.getProvincialId().equals(oldData.getProvincialId()) || !newData.getTeam().equals(oldData.getTeam())) {
//check Duplicate
EndrProvincialTeamForm schForm = new EndrProvincialTeamForm();
schForm.setProvincialId(newData.getProvincialId());
schForm.setTeam(newData.getTeam());
List<EndrProvincialTeamForm> result = commonService.searchEndrProvincialTeamBeanByBean(schForm);
if (result != null && result.size() > 0) {
msgErrorForm.setErrorFlag(getBigDecimal("1"));
msgErrorForm.setErrorDesc("ข้อมูลนี้มีในระบบแล้ว");
return msgErrorForm;
}
}
EndrProvincialTeamBean endrProvincialTeamBean = new EndrProvincialTeamBean();
oldData.setProvincialId(newData.getProvincialId());
oldData.setTeam(newData.getTeam());
BeanUtils.copyProperties(oldData, endrProvincialTeamBean);
String userId = SessionUtil.getUserLoginForm().getUserId();
endrProvincialTeamBean.setUpdatedBy(userId);
endrProvincialTeamBean.setUpdatedDate(new Date());
boolean isInsertSuccessful = commonService.insertEndrProvincialTeam(endrProvincialTeamBean);
if (!isInsertSuccessful) {
msgErrorForm.setErrorFlag(getBigDecimal("1"));
msgErrorForm.setErrorDesc("save Error");
return msgErrorForm;
}
} catch (Exception e) {
msgErrorForm.setErrorFlag(getBigDecimal("1"));
msgErrorForm.setErrorDesc("save Team Error");
log.error(e.toString(), e);
}
return msgErrorForm;
}
public MsgErrorForm deleteEndrProvincialTeamData(EndrProvincialTeamForm endrProvincialTeamForm) {
MsgErrorForm msgErrorForm = new MsgErrorForm();
msgErrorForm.setDataDefaultOk();
try {
EndrProvincialTeamBean deleteBean = new EndrProvincialTeamBean();
BeanUtils.copyProperties(endrProvincialTeamForm, deleteBean);
boolean isDeleteSuccessful = commonService.deleteEndrProvincialTeam(deleteBean);
if (!isDeleteSuccessful) {
msgErrorForm.setErrorFlag(getBigDecimal("1"));
msgErrorForm.setErrorDesc("delete Error");
return msgErrorForm;
}
} catch (Exception e) {
msgErrorForm.setErrorFlag(getBigDecimal("1"));
msgErrorForm.setErrorDesc("delete Team Error");
log.error(e.toString(), e);
}
return msgErrorForm;
}
}