|
|
@@ -1,10 +1,5 @@
|
|
|
package com.awspaas.user.apps.donenow_ivt.controller;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
-
|
|
|
import com.actionsoft.bpms.bo.engine.BO;
|
|
|
import com.actionsoft.bpms.bpmn.engine.model.run.delegate.ProcessInstance;
|
|
|
import com.actionsoft.bpms.bpmn.engine.model.run.delegate.TaskInstance;
|
|
|
@@ -18,342 +13,344 @@ import com.actionsoft.sdk.local.SDK;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.awspaas.user.apps.donenow_ivt.constant.IVTConstant;
|
|
|
import com.awspaas.user.apps.donenow_ivt.utils.BigDecimalUtil;
|
|
|
-
|
|
|
import me.chanjar.weixin.common.util.StringUtils;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
@Controller
|
|
|
public class IVTController extends BaseController {
|
|
|
|
|
|
- @Mapping("com.awspaas.user.apps.donenow_ivt.queryprice")
|
|
|
- public String queryprice(String ids,UserContext uc,String unitcost) {
|
|
|
- System.out.println("unitcost:"+unitcost);
|
|
|
- if(StringUtils.isBlank(ids)){
|
|
|
- return "";
|
|
|
- }
|
|
|
- if(StringUtils.isBlank(unitcost)){
|
|
|
- unitcost= "0";
|
|
|
- }
|
|
|
- String[] arr= ids.split(",");
|
|
|
- List<BO> list=SDK.getBOAPI().query(IVTConstant.BO_EU_DNIVT_SERVICE) .addQuery("ID IN ('"+org.apache.commons.lang3.StringUtils.join(arr, "','")+"')", null).list();
|
|
|
- String unitPriceTotal="0";
|
|
|
- String unitCostTotal="0";
|
|
|
-
|
|
|
- for (BO bo : list) {
|
|
|
- unitPriceTotal=BigDecimalUtil.add(unitPriceTotal, bo.getString("UNIT_PRICE"));
|
|
|
- unitCostTotal=BigDecimalUtil.add(unitCostTotal, bo.getString("UNIT_COST"));
|
|
|
- }
|
|
|
- JSONObject json=new JSONObject();
|
|
|
- //String discount=BigDecimalUtil.sub(totalPrice, unitcost);
|
|
|
- json.put("unitPriceTotal", unitPriceTotal);
|
|
|
- json.put("unitCostTotal",unitCostTotal );
|
|
|
- //json.put("percent",BigDecimalUtil.div(discount, totalPrice));
|
|
|
- return success(json);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- * 根据产品ID查找对应的数据
|
|
|
- */
|
|
|
- @Mapping("com.awspaas.user.apps.donenow_ivt.queryproduct")
|
|
|
- public String queryproduct(String id,UserContext uc) {
|
|
|
- BO detail=SDK.getBOAPI().query(IVTConstant.BO_EU_DNIVT_PRODUCT).detailById(id);
|
|
|
- if(null==detail) {
|
|
|
- return fail("未找到对应的产品");
|
|
|
- }
|
|
|
- return success(detail.asMap());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- * 变更原因保存
|
|
|
- * 类型:手工修改库存1485
|
|
|
- */
|
|
|
- @Mapping("com.awspaas.user.apps.donenow_ivt.updatereason")
|
|
|
- public String updatereason(String commitmsg,UserContext uc,String productBindId) {
|
|
|
- //仓库产品
|
|
|
- System.out.println("updatereason bindId:"+productBindId);
|
|
|
- System.out.println("commitmsg:"+commitmsg);
|
|
|
- System.out.println("UserContext:"+uc.getUID());
|
|
|
-
|
|
|
- BO detail = SDK.getBOAPI().query(IVTConstant.BO_EU_DNIVT_WAREHOUSE_PRODUCT).bindId(productBindId).detail();
|
|
|
-
|
|
|
- ProcessInstance createBOProcessInstance = SDK.getProcessAPI().createBOProcessInstance(IVTConstant.obj_e15a8fedeaeb43dc85aa258a7e1cffcf, uc.getUID(), "");
|
|
|
-
|
|
|
- //BO productDetail=SDK.getBOAPI().query(IVTConstant.BO_EU_DNIVT_PRODUCT).detailById(productId);
|
|
|
- //产品移库1485
|
|
|
- BO bo=new BO();
|
|
|
- bo.set("PRODUCT_ID",detail.getString("PRODUCT_ID") );
|
|
|
- bo.set("NOTES",commitmsg );
|
|
|
- bo.set("QUANTITY",detail.getString("QUANTITY") );
|
|
|
- bo.set("TYPE_ID",1485 );
|
|
|
- bo.setBindId(createBOProcessInstance.getId());
|
|
|
- SDK.getBOAPI().create(IVTConstant.BO_EU_DNIVT_TRANSFER, bo, createBOProcessInstance, uc);
|
|
|
-
|
|
|
- return success("");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- * 产品复制并新增
|
|
|
- */
|
|
|
- @Mapping("com.awspaas.user.apps.donenow_ivt.productcopy")
|
|
|
- public String productcopy(String bindId,UserContext uc,String tableName) {
|
|
|
- BO detail=SDK.getBOAPI().query(tableName).detailByBindId(bindId);
|
|
|
- if(null==detail) {
|
|
|
- return fail("未找到对应的数据");
|
|
|
- }
|
|
|
- String processDefId=DBSql.getString("select processdefid from wfc_process where id=?",new Object[] {bindId});
|
|
|
- ProcessInstance createBOProcessInstance = SDK.getProcessAPI().createBOProcessInstance(processDefId, uc.getUID(), "");
|
|
|
- BO bo=new BO();
|
|
|
- bo.setAll(detail.asMap());
|
|
|
- bo.setId(UUIDGener.getUUID());
|
|
|
- bo.setBindId(createBOProcessInstance.getId());
|
|
|
- SDK.getBOAPI().create(tableName, bo, createBOProcessInstance, uc);
|
|
|
- //TaskInstance taskInst = SDK.getProcessAPI().start(createBOProcessInstance).fetchActiveTasks().get(0);
|
|
|
- String url = SDK.getFormAPI().getFormURL("", uc.getSessionId(), createBOProcessInstance.getId(), "", 1, "", "", "");
|
|
|
- url=SDK.getPortalAPI().getPortalUrl()+"/r"+url.substring(1);
|
|
|
- return url;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- * 采购审批通过
|
|
|
- */
|
|
|
- @Mapping("com.awspaas.user.apps.donenow_ivt.productcostapproval")
|
|
|
- public String productcostapproval(String ids,UserContext uc,String type) {
|
|
|
- if(StringUtils.isEmpty(ids)) {
|
|
|
- return fail("数据id不允许为空");
|
|
|
-
|
|
|
- }
|
|
|
- ids="'"+ids.substring(0, ids.length()-1).replace(",", "','")+"'";
|
|
|
- List<BO> list=SDK.getBOAPI().query(IVTConstant.BO_EU_DNCTT_CONTRACT_COST).addQuery(" ID IN ("+ids+")", null).list();
|
|
|
- System.out.println("ids:"+ids);
|
|
|
- System.out.println("list.size:"+list.size());
|
|
|
-
|
|
|
- for(BO bo:list) {
|
|
|
-
|
|
|
- bo.set("STATUS_ID", type);
|
|
|
- SDK.getBOAPI().update(IVTConstant.BO_EU_DNCTT_CONTRACT_COST, bo);
|
|
|
- }
|
|
|
- return success("");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- * 采购接收打开选择数据的临时表单
|
|
|
- */
|
|
|
- @Mapping("com.awspaas.user.apps.donenow_ivt.receiveorder")
|
|
|
- public String receiveorder(String ids,UserContext uc,String type) {
|
|
|
- if(StringUtils.isEmpty(ids)) {
|
|
|
- return fail("数据id不允许为空");
|
|
|
-
|
|
|
- }
|
|
|
- ids="'"+ids.substring(0, ids.length()-1).replace(",", "','")+"'";
|
|
|
- List<BO> list=SDK.getBOAPI().query(IVTConstant.BO_EU_DNCTT_CONTRACT_COST).addQuery(" ID IN ("+ids+")", null).list();
|
|
|
- System.out.println("ids:"+ids);
|
|
|
- System.out.println("list.size:"+list.size());
|
|
|
-
|
|
|
- for(BO bo:list) {
|
|
|
-
|
|
|
- bo.set("STATUS_ID", type);
|
|
|
- SDK.getBOAPI().update(IVTConstant.BO_EU_DNCTT_CONTRACT_COST, bo);
|
|
|
- }
|
|
|
- return success("");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- *采购项接收
|
|
|
- */
|
|
|
- @Mapping("com.awspaas.user.apps.donenow_ivt.purchasereceive")
|
|
|
- public String purchasereceive(String ids,UserContext uc,String bindId) {
|
|
|
- System.out.print("idsids:"+ids);
|
|
|
- System.out.print("bindId:"+bindId);
|
|
|
-
|
|
|
- if(StringUtils.isNotBlank(ids)) {
|
|
|
-
|
|
|
- ids=ids.substring(0, ids.length()-1);
|
|
|
-
|
|
|
- }else if(StringUtils.isNotBlank(bindId)) {
|
|
|
- ids=DBSql.getString("SELECT GROUP_CONCAT(ID) from bo_eu_dnivt_order_product WHERE BINDID=?",new Object[] {bindId});
|
|
|
- }else {
|
|
|
- return fail("采购订单ID不能为空");
|
|
|
- }
|
|
|
- ids="'"+ids.replace(",", "','")+"'";
|
|
|
- System.out.print("idsids:"+ids);
|
|
|
-
|
|
|
- //采购接收查询SQL
|
|
|
- String sql=" select op.CONTRACT_COST_ID,a.IS_SERIALIZED,o.CREATEDATE,o.FREIGHT_COST,op.WAREHOUSE_ID,op.product_id,op.id,c.id as contract_id,p.id as project_id,t.id as task_id,op.product_id," +
|
|
|
- " ifnull(c.account_id,ifnull(p.account_id,t.account_id))as account_id,b.opportunity_id," +
|
|
|
- " o.vendor_account_id,if(c.name is not null,'contract',if(p.name is not null,'project'," +
|
|
|
- " 'ticket'))parent_type,op.name as product_name,(select name from bo_eu_dncrm_account where " +
|
|
|
- " id=ifnull(c.account_id,ifnull(p.account_id,t.account_id))) account_name," +
|
|
|
- " (select name from bo_eu_dncrm_opportunity where id=b.opportunity_id)oppo_name," +
|
|
|
- " ifnull(c.name,ifnull(p.name,t.no))contrac_project_task_name,op.quantity,op.unit_cost*op.quantity as " +
|
|
|
- " total_cost,ifnull((select sum(ifnull(quantity,0)) from bo_eu_dnivt_warehouse_product where " +
|
|
|
- " product_id=op.product_Id ),0)as on_hand,ifnull((select sum(x.quantity) from bo_eu_dnivt_reserve x," +
|
|
|
- " bo_eu_dncrm_quote_item y where x.quote_item_id=y.id and y.object_id=op.product_id ),0)+" +
|
|
|
- " ifnull((select sum(x.quantity) from bo_eu_dnctt_contract_cost_product x,bo_eu_dnctt_contract_cost y " +
|
|
|
- " where x.status_id=2157 and x.contract_cost_id=y.id and y.product_id=op.product_id),0) as reserve_pick_num," +
|
|
|
- " ifnull((select sum(ifnull(quantity,0)) from bo_eu_dnivt_warehouse_product where product_id=op.product_Id ),0) " +
|
|
|
- " -ifnull((select sum(x.quantity) from bo_eu_dnivt_reserve x,bo_eu_dncrm_quote_item y where x.quote_item_id=y.id and y.object_id=op.product_id ),0)" +
|
|
|
- " -ifnull((select sum(x.quantity) from bo_eu_dnctt_contract_cost_product x,bo_eu_dnctt_contract_cost y " +
|
|
|
- " where x.status_id=2157 and x.contract_cost_id=y.id and y.product_id=op.product_id),0) as aviable_num," +
|
|
|
- " (select y.name from bo_eu_dncrm_account y where y.id=o.vendor_account_id)vendor, " +
|
|
|
- " a.manu_product_no as manu_product_no,a.sku,location_id as ship_to, op.estimated_arrival_date," +
|
|
|
- " o.purchase_order_no" +
|
|
|
- " from bo_eu_dnivt_order_product op " +
|
|
|
- " left join bo_eu_dnivt_order o on op.order_id=o.id" +
|
|
|
- " left join bo_eu_dnivt_product a on op.product_id=a.id" +
|
|
|
- " left join bo_eu_dnctt_contract_cost b on op.contract_cost_id=b.id " +
|
|
|
- " LEFT join bo_eu_dnctt_contract c on c.id=b.contract_id " +
|
|
|
- " LEFT join bo_eu_dnpro_project p on p.id=b.project_id " +
|
|
|
- " LEFT join bo_eu_dnsdk_task t on t.id=b.task_id " +
|
|
|
- " left join bo_eu_dncrm_sales_order so on b.opportunity_id=so.opportunity_id " +
|
|
|
- " where 1=1 AND op.id IN ("+ids+")";
|
|
|
- System.out.print("SSSSQL:"+sql);
|
|
|
- List<RowMap> maps = DBSql.getMaps(sql, new Object[] {});
|
|
|
- if(maps.size()==0) {
|
|
|
- return fail("未找到对应数据");
|
|
|
- }
|
|
|
- ProcessInstance createBOProcessInstance = SDK.getProcessAPI().createBOProcessInstance(IVTConstant.obj_3121af9039dc454aa776f9bdadf6b239, uc.getUID(), "");
|
|
|
- //校验是否是同一个采购订单
|
|
|
- Set<String> set=new HashSet<String>();
|
|
|
- List<BO> list=new ArrayList<BO>();
|
|
|
- for(RowMap map:maps){
|
|
|
- if(StringUtils.isNotBlank(map.getString("purchase_order_no"))&&StringUtils.isNotBlank(map.getString("purchase_order_no").trim())) {
|
|
|
- set.add(map.getString("purchase_order_no"));
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- if(set.size()>1) {
|
|
|
- System.out.println("setsetset:"+set);
|
|
|
-
|
|
|
- return fail("一次只能接收同一个采购订单的采购项");
|
|
|
- }
|
|
|
- for(RowMap map:maps){
|
|
|
- String unBack="0";
|
|
|
- BO subBo=new BO();
|
|
|
- set.add(map.getString("purchase_order_no"));
|
|
|
- RowMap rowMap = DBSql.getMap("select ORDER_PRODUCT_ID,sum(QUANTITY_RECEIVED) QUANTITY_RECEIVED from BO_EU_DNIVT_RECEIVE WHERE ORDER_PRODUCT_ID=? group by ORDER_PRODUCT_ID", new Object[] {map.getString("id")});
|
|
|
- if(null!=rowMap) {
|
|
|
- unBack = getUnBack(map.getString("quantity"),rowMap.getString("QUANTITY_RECEIVED"));
|
|
|
- if(Integer.valueOf(unBack)<=0) {
|
|
|
- System.out.println("采购数量小于已接收数量:"+map.getString("quantity")+"-----"+rowMap.getString("QUANTITY_RECEIVED"));
|
|
|
- continue;
|
|
|
- }
|
|
|
- subBo.set("QUANTITY_RECEIVED", rowMap.get("QUANTITY_RECEIVED"));
|
|
|
- subBo.set("QUANTITY_BACKORDERED",unBack);
|
|
|
- }else {
|
|
|
- subBo.set("QUANTITY_RECEIVED", 0);
|
|
|
- subBo.set("QUANTITY_BACKORDERED",map.get("quantity"));
|
|
|
- }
|
|
|
- subBo.set("PRODUCT_NAME", map.get("product_name"));
|
|
|
- subBo.set("IS_SERIALIZED", map.get("IS_SERIALIZED"));
|
|
|
- subBo.set("WAREHOUSE_ID", map.get("WAREHOUSE_ID"));
|
|
|
- subBo.set("ACCOUNT_NAME", map.get("account_name"));
|
|
|
- subBo.set("CONTRAC_PROJECT_TASK_NAME", map.get("contrac_project_task_name"));
|
|
|
- subBo.set("QUANTITY", map.get("quantity"));
|
|
|
- subBo.set("ON_HAND", map.get("on_hand"));
|
|
|
- subBo.set("PRODUCT_ID", map.get("product_id"));
|
|
|
- subBo.set("ORDER_PRODUCT_ID", map.get("id"));
|
|
|
- subBo.set("NOW_COUNT", 0);
|
|
|
- subBo.set("CONTRACT_COST_ID", map.get("CONTRACT_COST_ID"));
|
|
|
- subBo.setBindId(createBOProcessInstance.getId());
|
|
|
- list.add(subBo);
|
|
|
- }
|
|
|
- if(list.size()==0) {
|
|
|
- return fail("采购订单项都已经接收完毕");
|
|
|
- }
|
|
|
- //采购接收主表添加数据
|
|
|
- RowMap rowMap = maps.get(0);
|
|
|
- BO detail = SDK.getBOAPI().query(IVTConstant.BO_EU_DNIVT_ORDER).addQuery("PURCHASE_ORDER_NO=", rowMap.getString("purchase_order_no")).detail();
|
|
|
- if(null==detail) {
|
|
|
- return fail("未找到对应的订单");
|
|
|
- }
|
|
|
- //主表数据
|
|
|
- BO bo=new BO();
|
|
|
- bo.setBindId(createBOProcessInstance.getId());
|
|
|
- bo.setId(UUIDGener.getUUID());
|
|
|
- bo.set("COMPANY", rowMap.getString("vendor"));
|
|
|
- bo.set("PURCHASE_ORDER_NO", rowMap.getString("purchase_order_no"));
|
|
|
- bo.set("SUBMIT_TIME", rowMap.get("CREATEDATE"));
|
|
|
- bo.set("VENDOR_INVOICE_NO", rowMap.get("VENDOR_INVOICE_NO"));
|
|
|
- bo.set("FREIGHT_COST", rowMap.get("FREIGHT_COST"));
|
|
|
- SDK.getBOAPI().create(IVTConstant.BO_EU_DNIVT_RECEIVE_MAIN, bo, createBOProcessInstance, uc);
|
|
|
-
|
|
|
- //子表数据
|
|
|
- SDK.getBOAPI().create(IVTConstant.BO_EU_DNIVT_RECEIVE_SUB, list, createBOProcessInstance, uc);
|
|
|
-
|
|
|
- String url = SDK.getFormAPI().getFormURL("", uc.getSessionId(), createBOProcessInstance.getId(), "", 1, "", "", "");
|
|
|
- url=SDK.getPortalAPI().getPortalUrl()+"/r"+url.substring(1);
|
|
|
- return success(url);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public String getUnBack(String param1, String param2) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
- if(StringUtils.isBlank(param1)) {
|
|
|
- return "0";
|
|
|
- }
|
|
|
- if(StringUtils.isBlank(param2)) {
|
|
|
- param2="0";
|
|
|
- }
|
|
|
- return BigDecimalUtil.sub(param1, param2);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- * 未接收数量复制给本次接收数量
|
|
|
- */
|
|
|
- @Mapping("com.awspaas.user.apps.donenow_ivt.copydata")
|
|
|
- public String receiveorder(String bindId,UserContext uc) {
|
|
|
-
|
|
|
- List<BO> list = SDK.getBOAPI().query(IVTConstant.BO_EU_DNIVT_RECEIVE_SUB).bindId(bindId).list();
|
|
|
- for(BO bo:list) {
|
|
|
- bo.set("BEN_RECEIVE", bo.get("QUANTITY_BACKORDERED"));
|
|
|
- SDK.getBOAPI().update(IVTConstant.BO_EU_DNIVT_RECEIVE_SUB, bo);
|
|
|
- }
|
|
|
-
|
|
|
- return success("");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- * 采购订单发起流程
|
|
|
- */
|
|
|
- @Mapping("com.awspaas.user.apps.donenow_ivt.purchaseorder")
|
|
|
- public String purchaseorder(String bindId,UserContext uc,String ids) {
|
|
|
-
|
|
|
- ids="'"+ids.substring(0, ids.length()-1).replace(",", "','")+"'";
|
|
|
- List<BO> list=SDK.getBOAPI().query(IVTConstant.BO_EU_DNIVT_WAREHOUSE_PRODUCT).addQuery(" BINDID IN ("+ids+")", null).list();
|
|
|
-
|
|
|
- ProcessInstance createBOProcessInstance = SDK.getProcessAPI().createBOProcessInstance(IVTConstant.obj_795cb3601f3a4b919b5896cf5b076a3a, uc.getUID(), "");
|
|
|
- //插入主表数据
|
|
|
- BO bo=new BO();
|
|
|
- bo.setId(UUIDGener.getUUID());
|
|
|
- bo.setBindId(createBOProcessInstance.getId());
|
|
|
- SDK.getBOAPI().create(IVTConstant.BO_EU_DNIVT_ORDER, bo, createBOProcessInstance, uc);
|
|
|
- //开始插入子表数据
|
|
|
- for(BO productBo:list){
|
|
|
- BO subBo=new BO();
|
|
|
- subBo.set("WAREHOUSE_ID", productBo.get("WAREHOUSE_ID"));
|
|
|
- subBo.set("PRODUCT_ID", productBo.get("PRODUCT_ID"));
|
|
|
-
|
|
|
- //用最大库存数减去库存数
|
|
|
- double sub = BigDecimalUtil.sub(BigDecimalUtil.getDouble(productBo.getString("QUANTITY_MAXIMUM")), BigDecimalUtil.getDouble(productBo.getString("QUANTITY")));
|
|
|
- subBo.set("QUANTITY", sub>0?sub:0);
|
|
|
- subBo.setBindId(createBOProcessInstance.getId());
|
|
|
- SDK.getBOAPI().create(IVTConstant.BO_EU_DNIVT_ORDER_PRODUCT, subBo, createBOProcessInstance, uc);
|
|
|
-
|
|
|
- }
|
|
|
- TaskInstance taskInst = SDK.getProcessAPI().start(createBOProcessInstance).fetchActiveTasks().get(0);
|
|
|
- String url = SDK.getFormAPI().getFormURL("", uc.getSessionId(), createBOProcessInstance.getId(), "", 1, "", "", "");
|
|
|
- url=SDK.getPortalAPI().getPortalUrl()+"/r"+url.substring(1);
|
|
|
- return url;
|
|
|
- }
|
|
|
+ @Mapping("com.awspaas.user.apps.donenow_ivt.queryprice")
|
|
|
+ public String queryprice(String ids, UserContext uc, String unitcost) {
|
|
|
+ System.out.println("unitcost:" + unitcost);
|
|
|
+ if (StringUtils.isBlank(ids)) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(unitcost)) {
|
|
|
+ unitcost = "0";
|
|
|
+ }
|
|
|
+ String[] arr = ids.split(",");
|
|
|
+ List<BO> list = SDK.getBOAPI().query(IVTConstant.BO_EU_DNIVT_SERVICE).addQuery("ID IN ('" + org.apache.commons.lang3.StringUtils.join(arr, "','") + "')", null).list();
|
|
|
+ String unitPriceTotal = "0";
|
|
|
+ String unitCostTotal = "0";
|
|
|
+
|
|
|
+ for (BO bo : list) {
|
|
|
+ unitPriceTotal = BigDecimalUtil.add(unitPriceTotal, bo.getString("UNIT_PRICE"));
|
|
|
+ unitCostTotal = BigDecimalUtil.add(unitCostTotal, bo.getString("UNIT_COST"));
|
|
|
+ }
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ //String discount=BigDecimalUtil.sub(totalPrice, unitcost);
|
|
|
+ json.put("unitPriceTotal", unitPriceTotal);
|
|
|
+ json.put("unitCostTotal", unitCostTotal);
|
|
|
+ //json.put("percent",BigDecimalUtil.div(discount, totalPrice));
|
|
|
+ return success(json);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * 根据产品ID查找对应的数据
|
|
|
+ */
|
|
|
+ @Mapping("com.awspaas.user.apps.donenow_ivt.queryproduct")
|
|
|
+ public String queryproduct(String id, UserContext uc) {
|
|
|
+ BO detail = SDK.getBOAPI().query(IVTConstant.BO_EU_DNIVT_PRODUCT).detailById(id);
|
|
|
+ if (null == detail) {
|
|
|
+ return fail("未找到对应的产品");
|
|
|
+ }
|
|
|
+ return success(detail.asMap());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * 变更原因保存
|
|
|
+ * 类型:手工修改库存1485
|
|
|
+ */
|
|
|
+ @Mapping("com.awspaas.user.apps.donenow_ivt.updatereason")
|
|
|
+ public String updatereason(String commitmsg, UserContext uc, String productBindId) {
|
|
|
+ //仓库产品
|
|
|
+ System.out.println("updatereason bindId:" + productBindId);
|
|
|
+ System.out.println("commitmsg:" + commitmsg);
|
|
|
+ System.out.println("UserContext:" + uc.getUID());
|
|
|
+
|
|
|
+ BO detail = SDK.getBOAPI().query(IVTConstant.BO_EU_DNIVT_WAREHOUSE_PRODUCT).bindId(productBindId).detail();
|
|
|
+
|
|
|
+ ProcessInstance createBOProcessInstance = SDK.getProcessAPI().createBOProcessInstance(IVTConstant.obj_e15a8fedeaeb43dc85aa258a7e1cffcf, uc.getUID(), "");
|
|
|
+
|
|
|
+ //BO productDetail=SDK.getBOAPI().query(IVTConstant.BO_EU_DNIVT_PRODUCT).detailById(productId);
|
|
|
+ //产品移库1485
|
|
|
+ BO bo = new BO();
|
|
|
+ bo.set("PRODUCT_ID", detail.getString("PRODUCT_ID"));
|
|
|
+ bo.set("NOTES", commitmsg);
|
|
|
+ bo.set("QUANTITY", detail.getString("QUANTITY"));
|
|
|
+ bo.set("TYPE_ID", 1485);
|
|
|
+ bo.setBindId(createBOProcessInstance.getId());
|
|
|
+ SDK.getBOAPI().create(IVTConstant.BO_EU_DNIVT_TRANSFER, bo, createBOProcessInstance, uc);
|
|
|
+
|
|
|
+ return success("");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * 产品复制并新增
|
|
|
+ */
|
|
|
+ @Mapping("com.awspaas.user.apps.donenow_ivt.productcopy")
|
|
|
+ public String productcopy(String bindId, UserContext uc, String tableName) {
|
|
|
+ BO detail = SDK.getBOAPI().query(tableName).detailByBindId(bindId);
|
|
|
+ if (null == detail) {
|
|
|
+ return fail("未找到对应的数据");
|
|
|
+ }
|
|
|
+ String processDefId = DBSql.getString("select processdefid from wfc_process where id=?", new Object[]{bindId});
|
|
|
+ ProcessInstance createBOProcessInstance = SDK.getProcessAPI().createBOProcessInstance(processDefId, uc.getUID(), "");
|
|
|
+ BO bo = new BO();
|
|
|
+ bo.setAll(detail.asMap());
|
|
|
+ bo.setId(UUIDGener.getUUID());
|
|
|
+ bo.setBindId(createBOProcessInstance.getId());
|
|
|
+ SDK.getBOAPI().create(tableName, bo, createBOProcessInstance, uc);
|
|
|
+ //TaskInstance taskInst = SDK.getProcessAPI().start(createBOProcessInstance).fetchActiveTasks().get(0);
|
|
|
+ String url = SDK.getFormAPI().getFormURL("", uc.getSessionId(), createBOProcessInstance.getId(), "", 1, "", "", "");
|
|
|
+ url = SDK.getPortalAPI().getPortalUrl() + "/r" + url.substring(1);
|
|
|
+ return url;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * 采购审批通过
|
|
|
+ */
|
|
|
+ @Mapping("com.awspaas.user.apps.donenow_ivt.productcostapproval")
|
|
|
+ public String productcostapproval(String ids, UserContext uc, String type) {
|
|
|
+ if (StringUtils.isEmpty(ids)) {
|
|
|
+ return fail("数据id不允许为空");
|
|
|
+
|
|
|
+ }
|
|
|
+ ids = "'" + ids.substring(0, ids.length() - 1).replace(",", "','") + "'";
|
|
|
+ List<BO> list = SDK.getBOAPI().query(IVTConstant.BO_EU_DNCTT_CONTRACT_COST).addQuery(" ID IN (" + ids + ")", null).list();
|
|
|
+ System.out.println("ids:" + ids);
|
|
|
+ System.out.println("list.size:" + list.size());
|
|
|
+
|
|
|
+ for (BO bo : list) {
|
|
|
+
|
|
|
+ bo.set("STATUS_ID", type);
|
|
|
+ SDK.getBOAPI().update(IVTConstant.BO_EU_DNCTT_CONTRACT_COST, bo);
|
|
|
+ }
|
|
|
+ return success("");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * 采购接收打开选择数据的临时表单
|
|
|
+ */
|
|
|
+ @Mapping("com.awspaas.user.apps.donenow_ivt.receiveorder")
|
|
|
+ public String receiveorder(String ids, UserContext uc, String type) {
|
|
|
+ if (StringUtils.isEmpty(ids)) {
|
|
|
+ return fail("数据id不允许为空");
|
|
|
+
|
|
|
+ }
|
|
|
+ ids = "'" + ids.substring(0, ids.length() - 1).replace(",", "','") + "'";
|
|
|
+ List<BO> list = SDK.getBOAPI().query(IVTConstant.BO_EU_DNCTT_CONTRACT_COST).addQuery(" ID IN (" + ids + ")", null).list();
|
|
|
+ System.out.println("ids:" + ids);
|
|
|
+ System.out.println("list.size:" + list.size());
|
|
|
+
|
|
|
+ for (BO bo : list) {
|
|
|
+
|
|
|
+ bo.set("STATUS_ID", type);
|
|
|
+ SDK.getBOAPI().update(IVTConstant.BO_EU_DNCTT_CONTRACT_COST, bo);
|
|
|
+ }
|
|
|
+ return success("");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ *采购项接收
|
|
|
+ */
|
|
|
+ @Mapping("com.awspaas.user.apps.donenow_ivt.purchasereceive")
|
|
|
+ public String purchasereceive(String ids, UserContext uc, String bindId) {
|
|
|
+ System.out.print("idsids:" + ids);
|
|
|
+ System.out.print("bindId:" + bindId);
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(ids)) {
|
|
|
+ ids = ids.substring(0, ids.length() - 1);
|
|
|
+ } else if (StringUtils.isNotBlank(bindId)) {
|
|
|
+ ids = DBSql.getString("SELECT GROUP_CONCAT(ID) from bo_eu_dnivt_order_product WHERE BINDID=?", new Object[]{bindId});
|
|
|
+ } else {
|
|
|
+ return fail("采购订单ID不能为空");
|
|
|
+ }
|
|
|
+ ids = "'" + ids.replace(",", "','") + "'";
|
|
|
+ System.out.print("idsids:" + ids);
|
|
|
+
|
|
|
+ //采购接收查询SQL
|
|
|
+ String sql = " select op.CONTRACT_COST_ID,a.IS_SERIALIZED,o.CREATEDATE,o.FREIGHT_COST,op.WAREHOUSE_ID,op.product_id,op.id,c.id as contract_id,p.id as project_id,t.id as task_id,op.product_id," +
|
|
|
+ " ifnull(c.account_id,ifnull(p.account_id,t.account_id))as account_id,b.opportunity_id," +
|
|
|
+ " o.vendor_account_id,if(c.name is not null,'contract',if(p.name is not null,'project'," +
|
|
|
+ " 'ticket'))parent_type,op.name as product_name,(select name from bo_eu_dncrm_account where " +
|
|
|
+ " id=ifnull(c.account_id,ifnull(p.account_id,t.account_id))) account_name," +
|
|
|
+ " (select name from bo_eu_dncrm_opportunity where id=b.opportunity_id)oppo_name," +
|
|
|
+ " ifnull(c.name,ifnull(p.name,t.no))contrac_project_task_name,op.quantity,op.unit_cost*op.quantity as " +
|
|
|
+ " total_cost,ifnull((select sum(ifnull(quantity,0)) from bo_eu_dnivt_warehouse_product where " +
|
|
|
+ " product_id=op.product_Id ),0)as on_hand,ifnull((select sum(x.quantity) from bo_eu_dnivt_reserve x," +
|
|
|
+ " bo_eu_dncrm_quote_item y where x.quote_item_id=y.id and y.object_id=op.product_id ),0)+" +
|
|
|
+ " ifnull((select sum(x.quantity) from bo_eu_dnctt_contract_cost_product x,bo_eu_dnctt_contract_cost y " +
|
|
|
+ " where x.status_id=2157 and x.contract_cost_id=y.id and y.product_id=op.product_id),0) as reserve_pick_num," +
|
|
|
+ " ifnull((select sum(ifnull(quantity,0)) from bo_eu_dnivt_warehouse_product where product_id=op.product_Id ),0) " +
|
|
|
+ " -ifnull((select sum(x.quantity) from bo_eu_dnivt_reserve x,bo_eu_dncrm_quote_item y where x.quote_item_id=y.id and y.object_id=op.product_id ),0)" +
|
|
|
+ " -ifnull((select sum(x.quantity) from bo_eu_dnctt_contract_cost_product x,bo_eu_dnctt_contract_cost y " +
|
|
|
+ " where x.status_id=2157 and x.contract_cost_id=y.id and y.product_id=op.product_id),0) as aviable_num," +
|
|
|
+ " (select y.name from bo_eu_dncrm_account y where y.id=o.vendor_account_id)vendor, " +
|
|
|
+ " a.manu_product_no as manu_product_no,a.sku,location_id as ship_to, op.estimated_arrival_date," +
|
|
|
+ " o.purchase_order_no" +
|
|
|
+ " from bo_eu_dnivt_order_product op " +
|
|
|
+ " left join bo_eu_dnivt_order o on op.order_id=o.id" +
|
|
|
+ " left join bo_eu_dnivt_product a on op.product_id=a.id" +
|
|
|
+ " left join bo_eu_dnctt_contract_cost b on op.contract_cost_id=b.id " +
|
|
|
+ " LEFT join bo_eu_dnctt_contract c on c.id=b.contract_id " +
|
|
|
+ " LEFT join bo_eu_dnpro_project p on p.id=b.project_id " +
|
|
|
+ " LEFT join bo_eu_dnsdk_task t on t.id=b.task_id " +
|
|
|
+ " left join bo_eu_dncrm_sales_order so on b.opportunity_id=so.opportunity_id " +
|
|
|
+ " where op.isend=1 and o.isend=1 AND op.id IN (" + ids + ")";
|
|
|
+ System.out.print("SSSSQL:" + sql);
|
|
|
+ List<RowMap> maps = DBSql.getMaps(sql, new Object[]{});
|
|
|
+ if (maps.size() == 0) {
|
|
|
+ return fail("请检查采购订单是否未审批!");
|
|
|
+ }
|
|
|
+ ProcessInstance createBOProcessInstance = SDK.getProcessAPI().createBOProcessInstance(IVTConstant.obj_3121af9039dc454aa776f9bdadf6b239, uc.getUID(), "");
|
|
|
+ //校验是否是同一个采购订单
|
|
|
+ Set<String> set = new HashSet<String>();
|
|
|
+ List<BO> list = new ArrayList<BO>();
|
|
|
+ for (RowMap map : maps) {
|
|
|
+ if (StringUtils.isNotBlank(map.getString("purchase_order_no")) && StringUtils.isNotBlank(map.getString("purchase_order_no").trim())) {
|
|
|
+ set.add(map.getString("purchase_order_no"));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if (set.size() > 1) {
|
|
|
+ System.out.println("setsetset:" + set);
|
|
|
+
|
|
|
+ return fail("一次只能接收同一个采购订单的采购项");
|
|
|
+ }
|
|
|
+ for (RowMap map : maps) {
|
|
|
+ String unBack = "0";
|
|
|
+ BO subBo = new BO();
|
|
|
+ set.add(map.getString("purchase_order_no"));
|
|
|
+ RowMap rowMap = DBSql.getMap("select ORDER_PRODUCT_ID,sum(QUANTITY_RECEIVED) QUANTITY_RECEIVED from BO_EU_DNIVT_RECEIVE WHERE ORDER_PRODUCT_ID=? group by ORDER_PRODUCT_ID", new Object[]{map.getString("id")});
|
|
|
+ if (null != rowMap) {
|
|
|
+ unBack = getUnBack(map.getString("quantity"), rowMap.getString("QUANTITY_RECEIVED"));
|
|
|
+ if (Integer.valueOf(unBack) <= 0) {
|
|
|
+ System.out.println("采购数量小于已接收数量:" + map.getString("quantity") + "-----" + rowMap.getString("QUANTITY_RECEIVED"));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ subBo.set("QUANTITY_RECEIVED", rowMap.get("QUANTITY_RECEIVED"));
|
|
|
+ subBo.set("QUANTITY_BACKORDERED", unBack);
|
|
|
+ } else {
|
|
|
+ subBo.set("QUANTITY_RECEIVED", 0);
|
|
|
+ subBo.set("QUANTITY_BACKORDERED", map.get("quantity"));
|
|
|
+ }
|
|
|
+ subBo.set("PRODUCT_NAME", map.get("product_name"));
|
|
|
+ subBo.set("IS_SERIALIZED", map.get("IS_SERIALIZED"));
|
|
|
+ subBo.set("WAREHOUSE_ID", map.get("WAREHOUSE_ID"));
|
|
|
+ subBo.set("ACCOUNT_NAME", map.get("account_name"));
|
|
|
+ subBo.set("CONTRAC_PROJECT_TASK_NAME", map.get("contrac_project_task_name"));
|
|
|
+ subBo.set("QUANTITY", map.get("quantity"));
|
|
|
+ subBo.set("ON_HAND", map.get("on_hand"));
|
|
|
+ subBo.set("PRODUCT_ID", map.get("product_id"));
|
|
|
+ subBo.set("ORDER_PRODUCT_ID", map.get("id"));
|
|
|
+ subBo.set("NOW_COUNT", 0);
|
|
|
+ subBo.set("CONTRACT_COST_ID", map.get("CONTRACT_COST_ID"));
|
|
|
+ subBo.setBindId(createBOProcessInstance.getId());
|
|
|
+ list.add(subBo);
|
|
|
+ }
|
|
|
+ if (list.size() == 0) {
|
|
|
+ return fail("采购订单项都已经接收完毕");
|
|
|
+ }
|
|
|
+ //采购接收主表添加数据
|
|
|
+ RowMap rowMap = maps.get(0);
|
|
|
+ BO detail = SDK.getBOAPI().query(IVTConstant.BO_EU_DNIVT_ORDER).addQuery("PURCHASE_ORDER_NO=", rowMap.getString("purchase_order_no")).detail();
|
|
|
+ if (null == detail) {
|
|
|
+ return fail("未找到对应的订单");
|
|
|
+ }
|
|
|
+ //主表数据
|
|
|
+ BO bo = new BO();
|
|
|
+ bo.setBindId(createBOProcessInstance.getId());
|
|
|
+ bo.setId(UUIDGener.getUUID());
|
|
|
+ bo.set("COMPANY", rowMap.getString("vendor"));
|
|
|
+ bo.set("PURCHASE_ORDER_NO", rowMap.getString("purchase_order_no"));
|
|
|
+ bo.set("SUBMIT_TIME", rowMap.get("CREATEDATE"));
|
|
|
+ bo.set("VENDOR_INVOICE_NO", rowMap.get("VENDOR_INVOICE_NO"));
|
|
|
+ bo.set("FREIGHT_COST", rowMap.get("FREIGHT_COST"));
|
|
|
+ SDK.getBOAPI().create(IVTConstant.BO_EU_DNIVT_RECEIVE_MAIN, bo, createBOProcessInstance, uc);
|
|
|
+
|
|
|
+ //子表数据
|
|
|
+ SDK.getBOAPI().create(IVTConstant.BO_EU_DNIVT_RECEIVE_SUB, list, createBOProcessInstance, uc);
|
|
|
+
|
|
|
+ String url = SDK.getFormAPI().getFormURL("", uc.getSessionId(), createBOProcessInstance.getId(), "", 1, "", "", "");
|
|
|
+ url = SDK.getPortalAPI().getPortalUrl() + "/r" + url.substring(1);
|
|
|
+ return success(url);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public String getUnBack(String param1, String param2) {
|
|
|
+ // TODO Auto-generated method stub
|
|
|
+ if (StringUtils.isBlank(param1)) {
|
|
|
+ return "0";
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(param2)) {
|
|
|
+ param2 = "0";
|
|
|
+ }
|
|
|
+ return BigDecimalUtil.sub(param1, param2);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * 未接收数量复制给本次接收数量
|
|
|
+ */
|
|
|
+ @Mapping("com.awspaas.user.apps.donenow_ivt.copydata")
|
|
|
+ public String receiveorder(String bindId, UserContext uc) {
|
|
|
+
|
|
|
+ List<BO> list = SDK.getBOAPI().query(IVTConstant.BO_EU_DNIVT_RECEIVE_SUB).bindId(bindId).list();
|
|
|
+ for (BO bo : list) {
|
|
|
+ bo.set("BEN_RECEIVE", bo.get("QUANTITY_BACKORDERED"));
|
|
|
+ SDK.getBOAPI().update(IVTConstant.BO_EU_DNIVT_RECEIVE_SUB, bo);
|
|
|
+ }
|
|
|
+
|
|
|
+ return success("");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * 采购订单发起流程
|
|
|
+ */
|
|
|
+ @Mapping("com.awspaas.user.apps.donenow_ivt.purchaseorder")
|
|
|
+ public String purchaseorder(String bindId, UserContext uc, String ids) {
|
|
|
+
|
|
|
+ ids = "'" + ids.substring(0, ids.length() - 1).replace(",", "','") + "'";
|
|
|
+ List<BO> list = SDK.getBOAPI().query(IVTConstant.BO_EU_DNIVT_WAREHOUSE_PRODUCT).addQuery(" BINDID IN (" + ids + ")", null).list();
|
|
|
+
|
|
|
+ ProcessInstance createBOProcessInstance = SDK.getProcessAPI().createBOProcessInstance(IVTConstant.obj_795cb3601f3a4b919b5896cf5b076a3a, uc.getUID(), "");
|
|
|
+ //插入主表数据
|
|
|
+ BO bo = new BO();
|
|
|
+ bo.setId(UUIDGener.getUUID());
|
|
|
+ bo.setBindId(createBOProcessInstance.getId());
|
|
|
+ SDK.getBOAPI().create(IVTConstant.BO_EU_DNIVT_ORDER, bo, createBOProcessInstance, uc);
|
|
|
+ //开始插入子表数据
|
|
|
+ for (BO productBo : list) {
|
|
|
+ BO subBo = new BO();
|
|
|
+ subBo.set("WAREHOUSE_ID", productBo.get("WAREHOUSE_ID"));
|
|
|
+ subBo.set("PRODUCT_ID", productBo.get("PRODUCT_ID"));
|
|
|
+
|
|
|
+ //用最大库存数减去库存数
|
|
|
+ double sub = BigDecimalUtil.sub(BigDecimalUtil.getDouble(productBo.getString("QUANTITY_MAXIMUM")), BigDecimalUtil.getDouble(productBo.getString("QUANTITY")));
|
|
|
+ subBo.set("QUANTITY", sub > 0 ? sub : 0);
|
|
|
+ subBo.setBindId(createBOProcessInstance.getId());
|
|
|
+ SDK.getBOAPI().create(IVTConstant.BO_EU_DNIVT_ORDER_PRODUCT, subBo, createBOProcessInstance, uc);
|
|
|
+
|
|
|
+ }
|
|
|
+ TaskInstance taskInst = SDK.getProcessAPI().start(createBOProcessInstance).fetchActiveTasks().get(0);
|
|
|
+ String url = SDK.getFormAPI().getFormURL("", uc.getSessionId(), createBOProcessInstance.getId(), "", 1, "", "", "");
|
|
|
+ url = SDK.getPortalAPI().getPortalUrl() + "/r" + url.substring(1);
|
|
|
+ return url;
|
|
|
+ }
|
|
|
}
|