158 lines
5.9 KiB
Plaintext
158 lines
5.9 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.ENDR002Service;
|
||
|
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.Calendar;
|
||
|
import java.util.List;
|
||
|
|
||
|
/**
|
||
|
* ENDR Print management.
|
||
|
*/
|
||
|
@Controller
|
||
|
public class ENDR002Controller extends ENDR002Service {
|
||
|
static Logger log = Logger.getLogger(ENDR002Controller.class);
|
||
|
|
||
|
/**
|
||
|
* Load the information/data to start (Master ,ComboBox)
|
||
|
*
|
||
|
* @param request
|
||
|
* @return Object[] search results
|
||
|
*/
|
||
|
@RequestMapping(value = "/json/ENDR002LoadData", 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/ENDR002SchData", 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);
|
||
|
}
|
||
|
|
||
|
//add 31/05/2018 แปลง ค.ศ เป็น พ.ศ แบบลูกทุ่ง
|
||
|
if (schForm.getApproveDate() != null) {
|
||
|
Calendar c = Calendar.getInstance();
|
||
|
c.setTime(schForm.getApproveDate());
|
||
|
c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 543);
|
||
|
schForm.setApproveDate(c.getTime());
|
||
|
}
|
||
|
|
||
|
schForm.setType("1"); //reprint
|
||
|
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/ENDR002Reprint", method = RequestMethod.POST)
|
||
|
public
|
||
|
@ResponseBody
|
||
|
Object[] ENDR002Reprint(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("1"); //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};
|
||
|
}
|
||
|
}
|