ENDRPrint_12CRelease/.svn/pristine/a8/a809ba31da22d877b9807f593e84b0cfd54a7c9c.svn-base
2024-08-14 10:58:03 +07:00

177 lines
6.7 KiB
Plaintext

package th.co.muangthai.endrprint.controller;
import org.apache.log4j.Logger;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import th.co.muangthai.endrprint.controller.service.ENDR400Service;
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.form.master.EndrProvincialForm;
import th.co.muangthai.endrprint.model.bean.form.master.EndrProvincialPrintForm;
import th.co.muangthai.endrprint.model.bean.form.master.EndrUserLoginForm;
import th.co.muangthai.endrprint.model.bean.master.EndrPrintServerBean;
import th.co.muangthai.endrprint.model.bean.master.EndrProvincialBean;
import th.co.muangthai.endrprint.model.bean.master.EndrProvincialPrintBean;
import th.co.muangthai.endrprint.util.SessionUtil;
import th.co.muangthai.endrprint.util.VSMUtil;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
/**
* ENDR Print management.
*/
@Controller
public class ENDR400Controller extends ENDR400Service {
static Logger log = Logger.getLogger(ENDR400Controller.class);
/**
* Load the information/data to start (Master ,ComboBox)
*
* @param request
* @return Object[] search results
*/
@RequestMapping(value = "/json/ENDR400LoadData", method = RequestMethod.POST)
public
@ResponseBody
Object[] loadData(HttpServletRequest request) {
log.info("[Start] ENDR400Controller.ENDR400LoadData...");
Object[] obj = new Object[4];
MsgErrorForm errorForm = new MsgErrorForm();
errorForm.setDataDefaultOk();
List<EndrUserLoginForm> lst = new ArrayList<EndrUserLoginForm>();
//master
List<EndrProvincialBean> endrProvincialList = new ArrayList<EndrProvincialBean>();
List<EndrPrintServerBean> endrPrintServerList = new ArrayList<EndrPrintServerBean>();
try {
String userId = SessionUtil.getUserLoginForm().getUserId();
if (VSMUtil.isNotEmpty(userId)) {
lst = commonService.searchLstUserLoginBeanFormPkg(null, null, null, null);
} else {
errorForm.setErrorFlag(getBigDecimal("1"));
errorForm.setErrorDesc("out of session");
}
//load Master
// EndrPrintServerForm endrPrintServerForm = new EndrPrintServerForm();
// endrPrintServerForm.setStatusFlag(BigDecimal.ONE);
endrProvincialList = commonService.searchEndrProvincialByBean(new EndrProvincialForm());
endrPrintServerList = commonService.searchEndrPrintServerByBean(new EndrPrintServerForm());
obj[0] = errorForm;
obj[1] = lst;
obj[2] = endrProvincialList;
obj[3] = endrPrintServerList;
log.info("[End] ENDR400Controller.ENDR400LoadData...");
} catch (Exception ex) {
errorForm.setDataErrorException(ex);
log.error(ex.toString(), ex);
obj[0] = errorForm;
}
return obj;
}
/**
* ENDR Print information searching regarding the condition
*
* @param request
* @return Object[] search results
*/
@RequestMapping(value = "/json/ENDR400SchData", method = RequestMethod.POST)
public
@ResponseBody
Object[] schData(HttpServletRequest request) {
log.info("[Start] ENDR400Controller.ENDR400LoadData...");
MsgErrorForm errorForm = new MsgErrorForm();
errorForm.setDataDefaultOk();
List<EndrProvincialPrintForm> endrProvincialPrintList = new ArrayList<EndrProvincialPrintForm>();
try {
String schFormParam = request.getParameter("schFormParam");
log.info("parse JSON To EndrProvincialPrintForm");
EndrProvincialPrintForm endrProvincialPrintForm = gsonData.fromJson(schFormParam, EndrProvincialPrintForm.class);
log.info("call searchEndrProvincialPrintByPkg");
//Load Mapping Data By getProvincialId & getServerId & all StatusFlag
endrProvincialPrintList = commonService.searchEndrProvincialPrintByPkg(
endrProvincialPrintForm.getProvincialId(),
endrProvincialPrintForm.getServerId(),
null
);
log.info("[End] ENDR400Controller.ENDR400LoadData...");
} catch (Exception ex) {
errorForm.setDataErrorException(ex);
log.error(ex.toString(), ex);
}
return new Object[]{errorForm, endrProvincialPrintList};
}
/**
* ENDR400InsertData
*
* @param request
* @return Object[] search results
*/
@RequestMapping(value = "/json/ENDR400InsertData", method = RequestMethod.POST)
public
@ResponseBody
Object[] ENDR400InsertData(HttpServletRequest request) {
log.info("[Start] ENDR400Controller.ENDR400InsertData...");
Object[] obj = new Object[4];
MsgErrorForm errorForm = new MsgErrorForm();
errorForm.setDataDefaultOk();
String insertFormParam = request.getParameter("insertFormParam");
log.info("parse JSON To EndrProvincialPrintForm");
EndrProvincialPrintForm insertForm = gsonData.fromJson(insertFormParam, EndrProvincialPrintForm.class);
try {
obj = insertEndrProvincialPrint(insertForm.getProvincialId(), insertForm.getServerId());
log.info("[End] ENDR400Controller.ENDR400InsertData...");
} catch (Exception ex) {
errorForm.setDataErrorException(ex);
log.error(ex.toString(), ex);
obj[0] = errorForm;
}
return obj;
}
@RequestMapping(value = "/json/ENDR400DeleteData", method = RequestMethod.POST)
public
@ResponseBody
Object[] ENDR400DeleteData(HttpServletRequest request) {
Object[] obj = new Object[2];
MsgErrorForm errorForm = new MsgErrorForm();
errorForm.setDataDefaultOk();
String deleteFormParam = request.getParameter("deleteFormParam");
EndrProvincialPrintForm deleteForm = gsonData.fromJson(deleteFormParam, EndrProvincialPrintForm.class);
EndrProvincialPrintBean bean = new EndrProvincialPrintBean();
BeanUtils.copyProperties(deleteForm, bean);
try {
obj = deleteEndrProvincialPrint(bean);
} catch (Exception ex) {
errorForm.setDataErrorException(ex);
log.error(ex.toString(), ex);
obj[0] = errorForm;
}
return obj;
}
}