241 lines
8.8 KiB
Plaintext
241 lines
8.8 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.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.time.Instant;
|
|
import java.util.ArrayList;
|
|
import java.util.Calendar;
|
|
import java.util.Date;
|
|
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);
|
|
}
|
|
|
|
//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("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};
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
Date now = new Date();
|
|
Calendar c = Calendar.getInstance();
|
|
c.setTime(now);
|
|
c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 543);
|
|
System.out.println(c.getTime());
|
|
|
|
|
|
// SimpleDateFormat df2Time = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss", VSMUtil.LOCALE_EN);
|
|
// SimpleDateFormat df2 = new SimpleDateFormat("dd/MM/yyyy", VSMUtil.LOCALE_EN);
|
|
// String date = "1544979600000";
|
|
//// String d = (Long.parseLong(date) * 1000)+"";
|
|
// Calendar cal = Calendar.getInstance();
|
|
// cal.setTimeInMillis(Long.parseLong(date));
|
|
// System.out.println(cal.getTime());
|
|
//
|
|
// Date d = new Date(Long.parseLong(date));
|
|
// String dString = df2Time.format(d);
|
|
// System.out.println(d);
|
|
//
|
|
// try {
|
|
// Date d2 = df2Time.parse(dString);
|
|
// System.out.println("after format >>" + d2.toString());
|
|
// } catch (ParseException e) {
|
|
// e.printStackTrace();
|
|
// }
|
|
//
|
|
//// Date d = Instant.ofEpochMilli(Long.parseLong(date));
|
|
//// try {
|
|
//// System.out.println(new Date(d));
|
|
//// } catch (ParseException e) {
|
|
//// e.printStackTrace();
|
|
//// }
|
|
|
|
}
|
|
} |