ENDRPrint_12CRelease/.svn/pristine/3b/3b756c99b103b23445764333462a1314c024751d.svn-base

90 lines
3.3 KiB
Plaintext
Raw Normal View History

2024-08-14 10:58:03 +07:00
package th.co.muangthai.endrprint.controller.service;
import oracle.sql.TIMESTAMP;
import org.apache.log4j.Logger;
import org.springframework.beans.BeanUtils;
import th.co.muangthai.endrprint.controller.AbstractMasterController;
import th.co.muangthai.endrprint.controller.service.ftp.FTPUtil;
import th.co.muangthai.endrprint.model.bean.form.MsgErrorForm;
import th.co.muangthai.endrprint.model.bean.form.master.EndrPrintServerForm;
import th.co.muangthai.endrprint.model.bean.master.EndrPrintServerBean;
import th.co.muangthai.endrprint.util.SessionUtil;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
public class ENDR300Service extends AbstractMasterController {
private Logger log = Logger.getLogger(ENDR300Service.class);
FTPUtil ftpService = new FTPUtil();
/**
* Insert ENDR data to temp and update data
* Save ENDR data to .dat file and transfer text file to server by ftp process
* Delete text file when transfer text file is complete
*
* @return Object[] results
*/
public Object[] insertOrUpdateData(EndrPrintServerForm endrPrintServerForm) {
log.info("Call ENDR300Service.insertOrUpdateData...");
Object[] obj = new Object[2];
MsgErrorForm msgErrorForm = new MsgErrorForm();
msgErrorForm.setErrorFlag(getBigDecimal("0"));
msgErrorForm.setErrorDesc("Save successful");
obj[0] = msgErrorForm;
try {
if (endrPrintServerForm != null) {
EndrPrintServerBean saveBean = new EndrPrintServerBean();
BeanUtils.copyProperties(endrPrintServerForm, saveBean);
List<EndrPrintServerBean> EndrPrintServerList = commonService.searchEndrPrintServerByBean(new EndrPrintServerForm());
String userId = SessionUtil.getUserLoginForm().getUserId();
Date now = new Date();
if (saveBean.getServerId() == null) {//Insert new EndrPrintServer
BigDecimal nextID = BigDecimal.ONE;
if (EndrPrintServerList.size() > 0) {
BigDecimal lastId = EndrPrintServerList.get(EndrPrintServerList.size() - 1).getServerId();
nextID = lastId.add(BigDecimal.ONE);
}
saveBean.setServerId(nextID);
saveBean.setCreateDate(now);
saveBean.setCreateBy(userId);
saveBean.setUpdateDate(now);
saveBean.setUpdateBy(userId);
} else {//Edit EndrPrintServer
saveBean.setUpdateDate(now);
saveBean.setUpdateBy(userId);
}
boolean f = commonService.insertEndrPrintServer(saveBean);
if (f) {//Reload Data
// obj[1] = commonService.searchEndrPrintServerByBean(new EndrPrintServerForm());
obj[1] = commonService.searchEndrPrintServerFormPkg(new EndrPrintServerForm());
}
}
log.info("[End] ENDR300Service.insertOrUpdateData...");
} catch (Exception e) {
msgErrorForm.setErrorFlag(getBigDecimal("1"));
msgErrorForm.setErrorDesc("Data not found ,Invalid team");
log.error(e.toString(), e);
}
obj[0] = msgErrorForm;
return obj;
}
}