Commit 324f972c authored by 覃振观's avatar 覃振观 👶

工作中心保存

parent a86f8c62
...@@ -58,6 +58,8 @@ function updateHandler(data) { ...@@ -58,6 +58,8 @@ function updateHandler(data) {
return; return;
} }
} }
// 更新标识: I 插入; U 修改; D 删除
data.updkz = 'U';
let url = DataUtil.composeURLByParam('/sapWorkCenter/goWorkCenterDetail.do', data); let url = DataUtil.composeURLByParam('/sapWorkCenter/goWorkCenterDetail.do', data);
UICtrl.addTabItem({tabid: 'workCenterEdit' + new Date().getTime(), text: "AAAA", url: url}); UICtrl.addTabItem({tabid: 'workCenterEdit' + new Date().getTime(), text: "AAAA", url: url});
} }
\ No newline at end of file
$(document).ready(function() {
initializeToobarContainer();
});
function save() {
let process = $('#submitForm').formToJSON({ check: true });
if (!process) {
return false;
}
let _self = this;
$('#submitForm').ajaxSubmit({
url: web_app.name + '/sapWorkCenter/saveWorkCenterDetail.ajax',
success: function (data) {
Public.successTip("保存成功!");
_self.close();
}
});
}
function initializeToobarContainer(){
var toolBarOptions= {
dropup: $('#toolBar').data('dropup') === true,//显示更多按钮时 是否向上打开菜单
items: [{
id: 'save',
remark: '保存',
name: 'common.button.save',
icon: 'fa-save',
delay: true,
relation: 'advance',
event: save
}]
};
$('#toolBar').toolBar(toolBarOptions);
//dropup==true 更多按钮向上展示
$('#toolBar').data('dropup',true).removeClass('job-button-fixed-top').addClass('job-button-fixed-bottom');
}
\ No newline at end of file
...@@ -156,6 +156,10 @@ ...@@ -156,6 +156,10 @@
</div> </div>
</div> </div>
</form> </form>
<div id="toolBarCenter" class="panel-footerX" >
<div id="toolBar"></div>
</div>
</div> </div>
</body> </body>
......
package com.huigou.topsun.sap.workcenter.application; package com.huigou.topsun.sap.workcenter.application;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.huigou.util.SDO;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map; import java.util.Map;
...@@ -14,4 +15,8 @@ public interface SapWorkCenterApplication { ...@@ -14,4 +15,8 @@ public interface SapWorkCenterApplication {
ArrayList<Map<String, Object>> findWorkCenter(); ArrayList<Map<String, Object>> findWorkCenter();
String queryWorkCenter() throws JsonProcessingException; String queryWorkCenter() throws JsonProcessingException;
Map<String, Object> saveWorkCenterDetail(SDO sdo);
boolean saveWorkCenter();
} }
...@@ -6,10 +6,10 @@ import com.fasterxml.jackson.core.type.TypeReference; ...@@ -6,10 +6,10 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.huigou.topsun.common.CloseableClientHttpRequest; import com.huigou.topsun.common.CloseableClientHttpRequest;
import com.huigou.topsun.sap.workcenter.domain.SapWorkCenterLog;
import com.huigou.topsun.sap.workcenter.repository.SapWorkCenterRepository; import com.huigou.topsun.sap.workcenter.repository.SapWorkCenterRepository;
import com.huigou.topsun.sap.workcenter.application.SapWorkCenterApplication; import com.huigou.topsun.sap.workcenter.application.SapWorkCenterApplication;
import com.huigou.topsun.sap.workcenter.domain.SapWorkCenter; import com.huigou.topsun.sap.workcenter.domain.SapWorkCenter;
import com.huigou.util.SDO;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.ClientHttpResponse;
...@@ -36,7 +36,7 @@ public class SapWorkCenterApplicationImpl implements SapWorkCenterApplication { ...@@ -36,7 +36,7 @@ public class SapWorkCenterApplicationImpl implements SapWorkCenterApplication {
private final SapWorkCenterRepository rep; private final SapWorkCenterRepository rep;
/*** /***
* description 发送请求到 SAP 系统,获取工作中心数据 * @description 发送请求到 SAP 系统,获取工作中心数据
* @return java.util.ArrayList<java.util.Map < java.lang.String, java.lang.Object>> * @return java.util.ArrayList<java.util.Map < java.lang.String, java.lang.Object>>
* @author qinzhenguan * @author qinzhenguan
* @createDate 2024/1/17 15:44 * @createDate 2024/1/17 15:44
...@@ -72,6 +72,32 @@ public class SapWorkCenterApplicationImpl implements SapWorkCenterApplication { ...@@ -72,6 +72,32 @@ public class SapWorkCenterApplicationImpl implements SapWorkCenterApplication {
return list.size() > 0 ? objectMapper.writeValueAsString(list) : ""; return list.size() > 0 ? objectMapper.writeValueAsString(list) : "";
} }
/***
* @description 发送请求到 SAP 系统,保存工作中心数据
* @param sdo 提交的数据集
* @return java.util.Map<java.lang.String, java.lang.Object>
* @author qinzhenguan
* @createDate 2024/1/18 11:20
*/
@Override
public Map<String, Object> saveWorkCenterDetail(SDO sdo) {
String execute;
HashMap<String, Object> param = new HashMap<>(12);
param.put("data", sdo.getProperties());
try {
execute = execute(param, "http://127.0.0.1:8080/topsun_xt_war/sapWorkCenter/saveWorkCenter.ajax");
} catch (Exception e) {
throw new RuntimeException(e);
}
return null;
}
@Override
public boolean saveWorkCenter() {
System.out.println("GG");
return false;
}
/*** /***
* description 模拟发送请求到 SAP * description 模拟发送请求到 SAP
* @param param 请求体 body * @param param 请求体 body
...@@ -95,9 +121,12 @@ public class SapWorkCenterApplicationImpl implements SapWorkCenterApplication { ...@@ -95,9 +121,12 @@ public class SapWorkCenterApplicationImpl implements SapWorkCenterApplication {
request.addHeader("Content-type", "application/json;charset=utf-8"); request.addHeader("Content-type", "application/json;charset=utf-8");
// ------------------------ body ------------------------ // ------------------------ body ------------------------
JSONObject body = new JSONObject(); //JSONObject body = new JSONObject();
try (OutputStream requestBody = request.getBody()) { if(param != null) {
requestBody.write(body.toString().getBytes()); String bodyText = new ObjectMapper().writeValueAsString(param);
try (OutputStream requestBody = request.getBody()) {
requestBody.write(bodyText.getBytes());
}
} }
// ------------------------ response ------------------------ // ------------------------ response ------------------------
......
...@@ -50,6 +50,14 @@ public class SapWorkCenterLogController extends CommonController { ...@@ -50,6 +50,14 @@ public class SapWorkCenterLogController extends CommonController {
return forward("sapWorkCenterDetail"); return forward("sapWorkCenterDetail");
} }
public String saveWorkCenterDetail() {
SDO sdo = this.getSDO();
Map<String, Object> map = centerServer.saveWorkCenterDetail(sdo);
return toResult(map);
}
/** /**
* description 模拟 SAP 接口 (临时) 能否提供条件查询及分页? * description 模拟 SAP 接口 (临时) 能否提供条件查询及分页?
* @return java.lang.String * @return java.lang.String
...@@ -62,5 +70,11 @@ public class SapWorkCenterLogController extends CommonController { ...@@ -62,5 +70,11 @@ public class SapWorkCenterLogController extends CommonController {
return success(workCenter); return success(workCenter);
} }
@SkipAuth
public String saveWorkCenter() {
boolean isSuccess = centerServer.saveWorkCenter();
return success();
}
} }
\ No newline at end of file
...@@ -27,7 +27,7 @@ public class PersistTool { ...@@ -27,7 +27,7 @@ public class PersistTool {
private EntityManager entityManager; private EntityManager entityManager;
/** /**
* description 持久化数据. <br>&nbsp;&nbsp;&nbsp;&nbsp; * @description 持久化数据. 不执行.flush() 业务代码自行控制提交 <br>&nbsp;&nbsp;&nbsp;&nbsp;
* Entity 时,如果 ID 为空执行 Persist,否则执行 Merge <br>&nbsp;&nbsp;&nbsp;&nbsp; * Entity 时,如果 ID 为空执行 Persist,否则执行 Merge <br>&nbsp;&nbsp;&nbsp;&nbsp;
* List 时,要求数据集格式 : <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * List 时,要求数据集格式 : <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* HashMap {”add“: List< Entity >,”up“: List< Entity >,”del“: List< Entity >} * HashMap {”add“: List< Entity >,”up“: List< Entity >,”del“: List< Entity >}
...@@ -45,15 +45,13 @@ public class PersistTool { ...@@ -45,15 +45,13 @@ public class PersistTool {
} else { } else {
persistEntity(item); persistEntity(item);
} }
entityManager.flush();
entityManager.clear();
} }
} }
/*** /***
* description 持久化 List * description 持久化 List
* @param list 操作的 List * @param list 操作的 List
* @param type 操作类 save, remove * @param type 操作类 save, remove
* @author qinzhenguan * @author qinzhenguan
* @createDate 2023/12/26 16:33 * @createDate 2023/12/26 16:33
*/ */
...@@ -67,10 +65,11 @@ public class PersistTool { ...@@ -67,10 +65,11 @@ public class PersistTool {
} else { } else {
persistEntity(list.get(i)); persistEntity(list.get(i));
} }
if(i % 80 == 0 || i == (list.size() - 1)) { // 这里不执行批量提交, 会导致在此之后 无法回滚此提交的更改
entityManager.flush(); // if(i % 80 == 0 || i == (list.size() - 1)) {
entityManager.clear(); // entityManager.flush();
} // entityManager.clear();
// }
} }
} }
...@@ -89,7 +88,9 @@ public class PersistTool { ...@@ -89,7 +88,9 @@ public class PersistTool {
field.setAccessible(true); field.setAccessible(true);
String id = (String) field.get(entity); String id = (String) field.get(entity);
if(StringUtil.isBlank(id)){ if(StringUtil.isBlank(id)){
//field.set(entity, String.valueOf(Snowflake.nextId())); if(field.getType().equals(BigDecimal.class)) {
field.set(entity, String.valueOf(Snowflake.nextId()));
}
entityManager.persist(entity); entityManager.persist(entity);
} else { } else {
entityManager.merge(entity); entityManager.merge(entity);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment