77 lines
3.0 KiB
Plaintext
77 lines
3.0 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.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) {
|
|
|
|
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());
|
|
}
|
|
|
|
}
|
|
} catch (Exception e) {
|
|
msgErrorForm.setErrorFlag(getBigDecimal("1"));
|
|
msgErrorForm.setErrorDesc("Data not found ,Invalid team");
|
|
log.error(e.toString(), e);
|
|
}
|
|
obj[0] = msgErrorForm;
|
|
return obj;
|
|
}
|
|
|
|
|
|
} |