|
|
@@ -4,7 +4,11 @@ import java.util.List;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.JSONValidator;
|
|
|
+import com.jeesite.common.collect.ListUtils;
|
|
|
import com.jeesite.common.codec.EncodeUtils;
|
|
|
import com.jeesite.common.lang.DateUtils;
|
|
|
import com.jeesite.common.utils.excel.ExcelExport;
|
|
|
@@ -17,6 +21,7 @@ import org.springframework.ui.Model;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
@@ -95,37 +100,69 @@ public class MesMaterialController extends BaseController {
|
|
|
*/
|
|
|
@PostMapping(value = "saveMaterial")
|
|
|
@ResponseBody
|
|
|
- public String saveMaterial(@Validated MesMaterial mesMaterial) {
|
|
|
-// if (StringUtils.isBlank(mesMaterial.getTitle())) {
|
|
|
-// return renderResult(Global.FALSE, text("部件名称不能为空!"));
|
|
|
-// }
|
|
|
-// if (StringUtils.isBlank(mesMaterial.getSpec())) {
|
|
|
-// return renderResult(Global.FALSE, text("部件规格不能为空!"));
|
|
|
-// }
|
|
|
- if (StringUtils.isBlank(mesMaterial.getErpSn())) {
|
|
|
+ public String saveMaterial(@RequestBody String body) {
|
|
|
+ if (StringUtils.isBlank(body)) {
|
|
|
+ return renderResult(Global.FALSE, text("参数错误!"));
|
|
|
+ }
|
|
|
+ List<JSONObject> items = parseMaterialList(body.trim());
|
|
|
+ if (items.isEmpty()) {
|
|
|
+ return renderResult(Global.FALSE, text("参数错误!"));
|
|
|
+ }
|
|
|
+ for (JSONObject obj : items) {
|
|
|
+ String err = doSaveOneMaterial(obj);
|
|
|
+ if (err != null) {
|
|
|
+ return err;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return renderResult(Global.TRUE, text("保存物料表成功!"));
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<JSONObject> parseMaterialList(String jsonStr) {
|
|
|
+ List<JSONObject> list = ListUtils.newArrayList();
|
|
|
+ if (jsonStr.startsWith("{")) {
|
|
|
+ list.add(JSON.parseObject(jsonStr));
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ JSONArray arr = JSON.parseArray(jsonStr);
|
|
|
+ for (int i = 0; i < arr.size(); i++) {
|
|
|
+ Object item = arr.get(i);
|
|
|
+ if (item instanceof JSONArray) {
|
|
|
+ JSONArray inner = (JSONArray) item;
|
|
|
+ for (int j = 0; j < inner.size(); j++) {
|
|
|
+ list.add(inner.getJSONObject(j));
|
|
|
+ }
|
|
|
+ } else if (item instanceof JSONObject) {
|
|
|
+ list.add((JSONObject) item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String doSaveOneMaterial(JSONObject obj) {
|
|
|
+ String erpSn = obj.getString("erpSn");
|
|
|
+ if (StringUtils.isBlank(erpSn)) {
|
|
|
return renderResult(Global.FALSE, text("ERP编码不能为空!"));
|
|
|
}
|
|
|
-// if (StringUtils.isBlank(mesMaterial.getUnit())) {
|
|
|
-// return renderResult(Global.FALSE, text("单位不能为空!"));
|
|
|
-// }
|
|
|
-// if (StringUtils.isBlank(mesMaterial.getHouse())) {
|
|
|
-// return renderResult(Global.FALSE, text("仓库不能为空!"));
|
|
|
-// }
|
|
|
-// if (StringUtils.isBlank(mesMaterial.getLocation())) {
|
|
|
-// return renderResult(Global.FALSE, text("库位不能为空!"));
|
|
|
-// }
|
|
|
- MesMaterial oldmm=new MesMaterial();
|
|
|
- oldmm.setErpSn(mesMaterial.getErpSn());
|
|
|
+ MesMaterial mesMaterial = new MesMaterial();
|
|
|
+ mesMaterial.setErpSn(erpSn);
|
|
|
+ mesMaterial.setTitle(obj.getString("title"));
|
|
|
+ mesMaterial.setSpec(obj.getString("spec"));
|
|
|
+ mesMaterial.setUnit(obj.getString("unit"));
|
|
|
+ mesMaterial.setHouse(obj.getString("house"));
|
|
|
+ mesMaterial.setLocation(obj.getString("location"));
|
|
|
+
|
|
|
+ MesMaterial oldmm = new MesMaterial();
|
|
|
+ oldmm.setErpSn(erpSn);
|
|
|
List<MesMaterial> list = mesMaterialService.findList(oldmm);
|
|
|
- if(!list.isEmpty()){
|
|
|
- MesMaterial mm=list.get(0);
|
|
|
+ if (!list.isEmpty()) {
|
|
|
+ MesMaterial mm = list.get(0);
|
|
|
mm.setHouse(mesMaterial.getHouse());
|
|
|
mm.setLocation(mesMaterial.getLocation());
|
|
|
mesMaterialService.update(mm);
|
|
|
- return renderResult(Global.TRUE, text("保存物料表成功!"));
|
|
|
+ return null;
|
|
|
}
|
|
|
mesMaterialService.save(mesMaterial);
|
|
|
- return renderResult(Global.TRUE, text("保存物料表成功!"));
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
/**
|