134 lines
5.6 KiB
Plaintext
134 lines
5.6 KiB
Plaintext
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.EndrCodeTabForm;
|
|
import th.co.muangthai.endrprint.model.bean.form.master.EndrProvincialTeamForm;
|
|
import th.co.muangthai.endrprint.model.bean.master.EndrProvincialTeamBean;
|
|
import th.co.muangthai.endrprint.model.bean.master.MstEndrcodeTabBean;
|
|
import th.co.muangthai.endrprint.model.bean.master.MstTeamTabBean;
|
|
import th.co.muangthai.endrprint.util.DateUtil;
|
|
import th.co.muangthai.endrprint.util.SessionUtil;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.sql.Timestamp;
|
|
import java.text.SimpleDateFormat;
|
|
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;
|
|
}
|
|
|
|
}
|