package com.mandi.fendan.controller; import com.mandi.common.XmlUtils; import com.mandi.fendan.persist.SaleBackOrder; import com.mandi.fendan.persist.SalesReturn; import com.mandi.fendan.service.SaleBackOrderService; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.json.JSONArray; import org.json.JSONObject; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.List; @RestController @RequestMapping(value="/api/saleBackOrder",method={RequestMethod.GET,RequestMethod.POST}) public class SaleBackOrderController { private Logger log=Logger.getLogger(SaleBackOrderController.class); @Resource private SaleBackOrderService saleBackOrderService; @RequestMapping(value = "/receive.htm", method = {RequestMethod.POST,RequestMethod.GET }) // public void insertSaleBackOrder(@RequestBody SaleBackOrder saleBackOrder){ public void insertSaleBackOrder(HttpServletRequest req, HttpServletResponse resp){ try { String strInfo = XmlUtils.parseRequst(req); if(StringUtils.isNotBlank(strInfo)){ JSONObject jsonObject = new JSONObject(strInfo); SaleBackOrder convert = convert(jsonObject); saleBackOrderService.saveOrUpdateOrDelete(convert); } } catch (Exception e) { e.printStackTrace(); } } private SaleBackOrder convert(JSONObject jsonObject) throws Exception { SaleBackOrder convert = new SaleBackOrder(); if (StringUtils.isNotBlank(jsonObject.getString("newSalesId"))) { convert.setNewSalesId(jsonObject.getString("newSalesId")); } if (StringUtils.isNotBlank(jsonObject.getString("docNum"))) { convert.setDocNum(jsonObject.getString("docNum")); } if (StringUtils.isNotBlank(jsonObject.getString("docTime"))) { convert.setDocTime(jsonObject.getString("docTime")); } if (StringUtils.isNotBlank(jsonObject.getString("newAccountNo"))) { convert.setNewAccountNo(jsonObject.getString("newAccountNo")); } if (StringUtils.isNotBlank(jsonObject.getString("createdBy"))) { convert.setCreatedBy(jsonObject.getString("createdBy")); } if (StringUtils.isNotBlank(jsonObject.getString("ncDepCode"))) { convert.setNcDepCode(jsonObject.getString("ncDepCode")); } if (StringUtils.isNotBlank(jsonObject.getString("userCode"))) { convert.setUserCode(jsonObject.getString("userCode")); } if (StringUtils.isNotBlank(jsonObject.getString("invoiceNum"))) { convert.setInvoiceNum(jsonObject.getString("invoiceNum")); } if (StringUtils.isNotBlank(jsonObject.getString("docRemark"))) { convert.setDocRemark(jsonObject.getString("docRemark")); } if (StringUtils.isNotBlank(jsonObject.getString("rcDepCode"))) { convert.setRcDepCode(jsonObject.getString("rcDepCode")); } if (StringUtils.isNotBlank(jsonObject.getString("rcLocCompCode"))) { convert.setRcLocCompCode(jsonObject.getString("rcLocCompCode")); } if (StringUtils.isNotBlank(jsonObject.getString("operState"))) { convert.setOperState(jsonObject.getString("operState")); } JSONArray itemList = jsonObject.getJSONArray("itemList"); List salesReturnList = new ArrayList<>(); for(int i=0;i