122 lines
4.9 KiB
Plaintext
122 lines
4.9 KiB
Plaintext
|
package th.co.muangthai.endrprint.controller.service;
|
||
|
|
||
|
import org.apache.log4j.Logger;
|
||
|
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.EndrProvincialPrintForm;
|
||
|
import th.co.muangthai.endrprint.model.bean.master.EndrProvincialPrintBean;
|
||
|
import th.co.muangthai.endrprint.util.SessionUtil;
|
||
|
|
||
|
import java.math.BigDecimal;
|
||
|
import java.util.Date;
|
||
|
import java.util.List;
|
||
|
|
||
|
public class ENDR400Service extends AbstractMasterController {
|
||
|
private Logger log = Logger.getLogger(ENDR400Service.class);
|
||
|
|
||
|
/**
|
||
|
* 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[] insertEndrProvincialPrint(BigDecimal provincialId, BigDecimal serverId) {
|
||
|
log.info("[Start] ENDR400Service.insertEndrProvincialPrint...");
|
||
|
Object[] obj = new Object[2];
|
||
|
MsgErrorForm msgErrorForm = new MsgErrorForm();
|
||
|
msgErrorForm.setErrorFlag(getBigDecimal("0"));
|
||
|
msgErrorForm.setErrorDesc("Save successful");
|
||
|
obj[0] = msgErrorForm;
|
||
|
try {
|
||
|
|
||
|
//Search by all provincialId & all serverId & all statusFlag
|
||
|
List<EndrProvincialPrintForm> EndrProvincialPrintList = commonService.searchEndrProvincialPrintByPkg(
|
||
|
null,
|
||
|
null,
|
||
|
null
|
||
|
);
|
||
|
boolean found = false;
|
||
|
BigDecimal maxId = BigDecimal.ONE;
|
||
|
for (EndrProvincialPrintForm EndrProvincialPrint : EndrProvincialPrintList) {
|
||
|
if (maxId.compareTo(EndrProvincialPrint.getId()) < 0) {
|
||
|
maxId = EndrProvincialPrint.getId();
|
||
|
}
|
||
|
if (EndrProvincialPrint.getProvincialId().equals(provincialId)
|
||
|
&& EndrProvincialPrint.getServerId().equals(serverId)) {
|
||
|
found = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (found) {//Duplicate Data
|
||
|
msgErrorForm.setErrorFlag(getBigDecimal("1"));
|
||
|
msgErrorForm.setErrorDesc("Duplicate Data");
|
||
|
obj[0] = msgErrorForm;
|
||
|
return obj;
|
||
|
} else {//Insert new Endr Provincial Print
|
||
|
String userId = SessionUtil.getUserLoginForm().getUserId();
|
||
|
Date now = new Date();
|
||
|
BigDecimal nextID = maxId.add(BigDecimal.ONE);
|
||
|
EndrProvincialPrintBean saveBean = new EndrProvincialPrintBean();
|
||
|
saveBean.setId(nextID);
|
||
|
saveBean.setProvincialId(provincialId);
|
||
|
saveBean.setServerId(serverId);
|
||
|
saveBean.setCreatedBy(userId);
|
||
|
saveBean.setCreatedDate(now);
|
||
|
saveBean.setUpdatedBy(userId);
|
||
|
saveBean.setUpdatedDate(now);
|
||
|
boolean f = commonService.insertEndrProvincialPrint(saveBean);
|
||
|
|
||
|
if (f) {
|
||
|
//Reload Data **all provincialId & all serverID & all status
|
||
|
obj[1] = commonService.searchEndrProvincialPrintByPkg(
|
||
|
null,
|
||
|
null,
|
||
|
null
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
log.info("[END] ENDR400Service.insertEndrProvincialPrint...");
|
||
|
} catch (Exception e) {
|
||
|
msgErrorForm.setErrorFlag(getBigDecimal("1"));
|
||
|
msgErrorForm.setErrorDesc("Data not found ,Invalid team");
|
||
|
log.error(e.toString(), e);
|
||
|
}
|
||
|
obj[0] = msgErrorForm;
|
||
|
return obj;
|
||
|
}
|
||
|
|
||
|
public Object[] deleteEndrProvincialPrint(EndrProvincialPrintBean endrProvincialPrintBean) {
|
||
|
Object[] obj = new Object[2];
|
||
|
MsgErrorForm msgErrorForm = new MsgErrorForm();
|
||
|
msgErrorForm.setErrorFlag(getBigDecimal("0"));
|
||
|
msgErrorForm.setErrorDesc("delete successful");
|
||
|
obj[0] = msgErrorForm;
|
||
|
try {
|
||
|
boolean f = commonService.deleteEndrProvincialPrint(endrProvincialPrintBean);
|
||
|
if (!f) {
|
||
|
msgErrorForm.setErrorFlag(getBigDecimal("1"));
|
||
|
msgErrorForm.setErrorDesc("delete failure");
|
||
|
obj[0] = msgErrorForm;
|
||
|
return obj;
|
||
|
} else {
|
||
|
//Reload Data **all provincialId & allserverID & all status
|
||
|
obj[1] = commonService.searchEndrProvincialPrintByPkg(
|
||
|
null,
|
||
|
null,
|
||
|
null
|
||
|
);
|
||
|
}
|
||
|
} catch (Exception e) {
|
||
|
msgErrorForm.setErrorFlag(getBigDecimal("1"));
|
||
|
msgErrorForm.setErrorDesc("delete failure " + e.toString());
|
||
|
log.error(e.toString(), e);
|
||
|
}
|
||
|
obj[0] = msgErrorForm;
|
||
|
return obj;
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|