180 lines
7.0 KiB
Plaintext
180 lines
7.0 KiB
Plaintext
package th.co.muangthai.endrprint.controller;
|
|
|
|
import com.google.gson.reflect.TypeToken;
|
|
import org.apache.log4j.Logger;
|
|
|
|
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.ENDR001Service;
|
|
import th.co.muangthai.endrprint.model.bean.form.MsgErrorForm;
|
|
import th.co.muangthai.endrprint.model.bean.form.data.PrintingDataForm;
|
|
import th.co.muangthai.endrprint.model.bean.form.master.EndrProvincialForm;
|
|
import th.co.muangthai.endrprint.model.bean.form.master.PrinterForm;
|
|
import th.co.muangthai.endrprint.model.bean.form.master.TeamForm;
|
|
import th.co.muangthai.endrprint.util.SessionUtil;
|
|
import th.co.muangthai.endrprint.util.VSMUtil;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import java.math.BigDecimal;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* ENDR Print management.
|
|
*/
|
|
@Controller
|
|
public class ENDR001Controller extends ENDR001Service {
|
|
static Logger log = Logger.getLogger(ENDR001Controller.class);
|
|
|
|
/**
|
|
* Load the information/data to start (Master ,ComboBox)
|
|
* @param request
|
|
* @return Object[] search results
|
|
*/
|
|
@RequestMapping(value = "/json/ENDR001LoadData", method = RequestMethod.POST)
|
|
public @ResponseBody
|
|
Object[] loadData(HttpServletRequest request) {
|
|
MsgErrorForm errorForm = new MsgErrorForm();
|
|
errorForm.setDataDefaultOk();
|
|
|
|
List<TeamForm> teamLst = new ArrayList<TeamForm>();
|
|
List<PrinterForm> printerLst = new ArrayList<PrinterForm>();
|
|
EndrProvincialForm provincial = null;
|
|
|
|
try {
|
|
|
|
String userId = SessionUtil.getUserLoginForm().getUserId();
|
|
|
|
if (VSMUtil.isNotEmpty(userId)){
|
|
provincial = commonService.searchProvincialFormPkg(userId);
|
|
|
|
if(commonService.isProvincialFormPkg(provincial)){
|
|
teamLst = commonService.searchProvincialTeamFormPkg(userId);
|
|
printerLst = commonService.searchProvincialPrinterFormPkg(userId);
|
|
}else {
|
|
teamLst = commonService.searchTeamFormPkg(userId);
|
|
printerLst = commonService.searchPrinterFormPkg(userId);
|
|
}
|
|
|
|
} else {
|
|
errorForm.setErrorFlag(getBigDecimal("1"));
|
|
errorForm.setErrorDesc("out of session");
|
|
|
|
teamLst = new ArrayList<TeamForm>();
|
|
printerLst = new ArrayList<PrinterForm>();
|
|
}
|
|
|
|
} catch (Exception ex) {
|
|
errorForm.setDataErrorException(ex);
|
|
log.error(ex.toString(), ex);
|
|
}
|
|
return new Object[]{errorForm ,teamLst ,printerLst};
|
|
}
|
|
|
|
/**
|
|
* ENDR Print information searching regarding the condition
|
|
* @param request
|
|
* @return Object[] search results
|
|
*/
|
|
@RequestMapping(value = "/json/ENDR001SchData", method = RequestMethod.POST)
|
|
public @ResponseBody
|
|
Object[] schData(HttpServletRequest request) {
|
|
MsgErrorForm errorForm = new MsgErrorForm();
|
|
errorForm.setDataDefaultOk();
|
|
|
|
List<PrintingDataForm> lstPrintingData = new ArrayList<PrintingDataForm>();
|
|
|
|
try {
|
|
// รับ Param จาก Pages
|
|
String schFormParam = request.getParameter("schFormParam");
|
|
PrintingDataForm schForm = gsonData.fromJson(schFormParam, PrintingDataForm.class);
|
|
|
|
if (VSMUtil.isEmpty(schForm.getTeam())){
|
|
schForm.setTeam(null);
|
|
}
|
|
schForm.setType("0"); //print
|
|
lstPrintingData = commonService.searchPrintingDataFormPkg(schForm);
|
|
|
|
} catch (Exception ex) {
|
|
errorForm.setDataErrorException(ex);
|
|
log.error(ex.toString(), ex);
|
|
}
|
|
return new Object[]{errorForm ,lstPrintingData};
|
|
}
|
|
|
|
/**
|
|
* Insert ENDR data to temp and update data
|
|
* Save ENDR data to .dat file and transfer file to server by ftp process
|
|
* @param request
|
|
* @return Object[] results
|
|
*/
|
|
@RequestMapping(value = "/json/ENDR001Print", method = RequestMethod.POST)
|
|
public @ResponseBody
|
|
Object[] ENDR001Print(HttpServletRequest request) {
|
|
MsgErrorForm errorForm = new MsgErrorForm();
|
|
errorForm.setDataDefaultOk();
|
|
|
|
try {
|
|
// รับ Param จาก Pages
|
|
String dataFormParam = request.getParameter("dataFormParam");
|
|
String dataPrintParam = request.getParameter("dataPrintParam");
|
|
List<PrintingDataForm> lstPrintingData = gsonData.fromJson(dataFormParam, new TypeToken<List<PrintingDataForm>>(){}.getType());
|
|
PrinterForm pntForm = gsonData.fromJson(dataPrintParam, PrinterForm.class);
|
|
|
|
if (VSMUtil.isNotEmptyLst(lstPrintingData)){
|
|
|
|
BigDecimal serverId = getBigDecimal(pntForm.getServerId());
|
|
BigDecimal sType = getBigDecimal("0"); //0=print ,1=reprint
|
|
Object[] objInsert = insertOrUpdateData(request ,lstPrintingData ,serverId ,sType);
|
|
|
|
errorForm = (MsgErrorForm)objInsert[0];
|
|
}else{
|
|
errorForm.setErrorFlag(getBigDecimal("1"));
|
|
errorForm.setErrorDesc("no data!!!");
|
|
}
|
|
} catch (Exception ex) {
|
|
errorForm.setDataErrorException(ex);
|
|
log.error(ex.toString(), ex);
|
|
}
|
|
return new Object[]{errorForm};
|
|
}
|
|
|
|
/**
|
|
* Insert ENDR data to temp and update data
|
|
* Save ENDR data to .dat file and transfer file to server by ftp process
|
|
* @param request
|
|
* @return Object[] results
|
|
*/
|
|
@RequestMapping(value = "/json/ENDR001RejectPrint", method = RequestMethod.POST)
|
|
public @ResponseBody
|
|
Object[] ENDR001RejectPrint(HttpServletRequest request) {
|
|
MsgErrorForm errorForm = new MsgErrorForm();
|
|
errorForm.setDataDefaultOk();
|
|
|
|
try {
|
|
// รับ Param จาก Pages
|
|
String dataFormParam = request.getParameter("dataFormParam");
|
|
String dataPrintParam = request.getParameter("dataPrintParam");
|
|
List<PrintingDataForm> lstPrintingData = gsonData.fromJson(dataFormParam, new TypeToken<List<PrintingDataForm>>(){}.getType());
|
|
PrinterForm pntForm = gsonData.fromJson(dataPrintParam, PrinterForm.class);
|
|
|
|
if (VSMUtil.isNotEmptyLst(lstPrintingData)){
|
|
|
|
BigDecimal serverId = getBigDecimal(pntForm.getServerId());
|
|
BigDecimal sType = getBigDecimal("0"); //0=reject
|
|
Object[] objInsert = rejectData(request ,lstPrintingData ,serverId ,sType);
|
|
|
|
errorForm = (MsgErrorForm)objInsert[0];
|
|
}else{
|
|
errorForm.setErrorFlag(getBigDecimal("1"));
|
|
errorForm.setErrorDesc("no data!!!");
|
|
}
|
|
} catch (Exception ex) {
|
|
errorForm.setDataErrorException(ex);
|
|
log.error(ex.toString(), ex);
|
|
}
|
|
return new Object[]{errorForm};
|
|
}
|
|
} |