1.背景:在大一些的企业中一般会涉及到一些周期性的事件,比如行政采购办公用品,仓库发送在OA审批出货等或者一些其他周期性汇总数据功能。
2.实现原理以及方式:
(1)、通过数据建模直接使用表单转存数据到本地建模底表中,数据自动汇总到建模底表中存储,然后通过增加快捷采购等方式调用后台api开发接口进行下一步操作。
通过表单中工厂不同,汇总到不同的数据建模表单中,再根据授权给不同工厂的行政办公人员进行每月汇总,发起采购申请。
汇总后通过勾选相关采购信息,通过会计按钮直接调用该ss()方法创建相应采购订单批量每月采购办公用品。
<script type="text/javascript">
function ss(){
var ids = ModeList.getCheckedID();
console.log(ids);
var json = {};
json.ids = ids;
json.table = "uf_bgyphz";
json.wfId = "79";
jQuery.ajax({
type:"POST",
url:"/api/officeSuppliesWeb/createPurchaseOrder",
contentType: "application/json",
data:JSON.stringify(json),
async: true,
beforeSend:function(){
ModeList.showLoading(true,'default','正在生成采购申请流程,请稍候...');
},
complete:function(){
ModeList.showLoading(false);
ModeList.clearChecked();
},
success:function(data){
console.log("data:", data);
ModeList.showMessage("执行成功", 3, 2);
ModeList.reloadTableAll();
},
error:function(e){
// 抛弃异常
}
});
};
</script>
后台调用api接口如下:
package com.api.hanhai.web; import com.alibaba.fastjson.JSONObject; import com.api.hanhai.util.ApiData; import com.api.hanhai.util.OfficeSuppliesPurchaseOrderUtil; import hanhai.workflow.entity.PurchaseOrderDetailEntity; import hanhai.workflow.entity.PurchaseOrderMainlEntity; import hanhai.workflow.service.CreatePurchaseOrderService; import weaver.conn.RecordSet; import weaver.general.Util; import weaversj.util.LogInfoUtil; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import java.io.IOException; import java.io.InputStream; import java.util.*; /** * @description: 汇总办公用品申购 * @Author: hzx * @CreateTime: 2023/3/27 */ @Path("/officeSuppliesWeb") public class OfficeSuppliesPurchaseOrderWeb { private static final LogInfoUtil log = new LogInfoUtil("OfficeSuppliesPurchaseOrderWeb"); private static final String info = "【汇总办公用品申购】:>>>>>>>>>>>>>>>>>>>>>>"; @POST @Path("/createPurchaseOrder") @Produces({MediaType.APPLICATION_JSON}) public String createPurchaseOrder(@Context HttpServletRequest request, @Context HttpServletResponse response){ log.logWriter(info + "开始"); ApiData apiData = new ApiData(); InputStream inputStream = null ; try { inputStream = request.getInputStream(); StringBuilder sbd = new StringBuilder(); byte[] b = new byte[4096]; for (int n; (n = inputStream.read(b)) != -1; ){ sbd.append(new String(b, 0, n,"utf-8")); } inputStream.close(); log.logWriter(info + "前端输入参数:"+sbd.toString()); if (sbd.toString() != null){ String params = sbd.toString(); JSONObject jsonObject = JSONObject.parseObject(params); String table = jsonObject.getString("table"); String wfId = jsonObject.getString("wfId"); OfficeSuppliesPurchaseOrderUtil util = new OfficeSuppliesPurchaseOrderUtil(); Map<String,PurchaseOrderMainlEntity> map = new HashMap<>(); RecordSet rs = new RecordSet(); RecordSet rs2 = new RecordSet(); String sql = ""; String ids = jsonObject.getString("ids"); if (ids != null && ids.equals("")){ sql = "SELECT * FROM "+table+" WHERE cgsqlc IS NULL OR cgsqlc = ''"; }else { sql = "SELECT * FROM "+table+" WHERE (cgsqlc IS NULL OR cgsqlc = '') AND id IN("+ids+")"; } log.logWriter(info + " SELECT:"+sql); rs.execute(sql); while (rs.next()){ String id = Util.null2String(rs.getString("id")); String gc = Util.null2String(rs.getString("gc")); String wlms = Util.null2String(rs.getString("wlms")); String sl = Util.null2String(rs.getString("sl")); String cbzx = Util.null2String(rs.getString("cbzx")); Map mapInfo = util.getDisposeInfo(gc); String cgz = (String) mapInfo.get("cgz"); String cgy = (String) mapInfo.get("cgy"); String wlz = (String) mapInfo.get("wlz"); String xzzy = (String) mapInfo.get("xzzy"); if (map.containsKey(gc)){ PurchaseOrderMainlEntity entity = map.get(gc); //相同工厂合并明细表 List<PurchaseOrderDetailEntity> entityList = entity.getDetailEntityList(); PurchaseOrderDetailEntity detail = new PurchaseOrderDetailEntity(); detail.setKmfplx("K"); detail.setWlms(wlms); detail.setSl(sl); detail.setJbjldw("PCS"); detail.setWlz(wlz); detail.setCgz(cgz); String sql2 = "SELECT * FROM uf_gccgzzgx WHERE gc = '"+gc+"'"; log.logWriter(info + " SELECT:"+sql2); rs2.execute(sql2); if (rs2.next()){ detail.setCgzz(Util.null2String(rs2.getString("cgzz"))); } detail.setCbzx(cbzx); detail.setCgy(cgy); detail.setDetId(id); entityList.add(detail); entity.setDetailEntityList(entityList); map.put(gc,entity); }else { //追加 PurchaseOrderMainlEntity mainlEntity = new PurchaseOrderMainlEntity(