|
@@ -0,0 +1,142 @@
|
|
|
+package com.imcs.admin.business.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.imcs.admin.business.service.BigScreenDetailService;
|
|
|
+import com.imcs.admin.business.service.BusinessService;
|
|
|
+import com.imcs.admin.common.PageData;
|
|
|
+import com.imcs.admin.common.PageParam;
|
|
|
+import com.imcs.admin.common.Result;
|
|
|
+import com.imcs.admin.db.service.JdbcDao;
|
|
|
+import com.imcs.admin.db.service.JdbcService;
|
|
|
+import com.imcs.admin.util.DateUtils;
|
|
|
+import com.imcs.admin.util.GenerateSerial;
|
|
|
+import org.apache.commons.collections.map.HashedMap;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.security.core.parameters.P;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class BusinessServiceImpl implements BusinessService {
|
|
|
+ @Resource
|
|
|
+ private JdbcDao jdbcDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private JdbcService jdbcService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private GenerateSerial generateSerial;
|
|
|
+
|
|
|
+ public static final Map<Integer,String> serialMap=new HashedMap();
|
|
|
+
|
|
|
+ static {
|
|
|
+ serialMap.put(1,"aProductionDesignPreparationTask");
|
|
|
+ serialMap.put(2,"aProductionDesignPreparationTask02");
|
|
|
+ serialMap.put(3,"aProductionDesignPreparationTask03");
|
|
|
+ serialMap.put(4,"aProductionDesignPreparationTask04");
|
|
|
+ serialMap.put(5,"aProductionDesignPreparationTask05");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void salesProductionOrder(Long id) {
|
|
|
+ StringBuffer str=new StringBuffer("select \n" +
|
|
|
+ "so.order_code, so.order_name,m.product_code,m.product_name,sp.sales_amount,so.id as sales_order_id,sp.product_id \n" +
|
|
|
+ "from b_Sales_Order so \n" +
|
|
|
+ "left join a_sales_product sp on so.id=sp.parent_id\n" +
|
|
|
+ "left join a_product m on sp.product_id=m.id where so.id = ?");
|
|
|
+ List<Object> args = new ArrayList<>();
|
|
|
+ args.add(StrUtil.format("{}",id));
|
|
|
+ PageParam pageParam = new PageParam();
|
|
|
+ pageParam.put("openPage","NO");
|
|
|
+ Result<PageData<Map<String, Object>>> detailQuery = jdbcDao.query(new PageParam(), str.toString(), args.toArray());
|
|
|
+ List<Map<String, Object>> items = detailQuery.getData().getItems();
|
|
|
+ items.stream().forEach(vo->{
|
|
|
+ String productCode = vo.get("productCode").toString();
|
|
|
+ String orderCode = vo.get("orderCode").toString();
|
|
|
+ String orderName = vo.get("orderName").toString();
|
|
|
+ String productName = vo.get("productName").toString();
|
|
|
+ Integer salesAmount = Integer.valueOf(vo.get("salesAmount").toString());
|
|
|
+ Long salesOrderId = Long.valueOf(vo.get("salesOrderId").toString());
|
|
|
+ Long productId = Long.valueOf(vo.get("productId").toString());
|
|
|
+ String sql="insert into a_production_order (order_code, production_order_code, order_name, product_name, product_code, plan_amount, status, sales_order_id, product_id,is_issue) values (?,?,?,?,?,?,?,?,?,?)";
|
|
|
+ jdbcService.insert("执行insert",sql,orderCode,generateSerial.generateSerialNumber("aProductionOrder"),orderName,productName,productCode,salesAmount,0,salesOrderId,productId,0);
|
|
|
+ });
|
|
|
+ jdbcService.update("update b_sales_order set is_issue = 1 where id = ?",id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void productionOrder(Long id) {
|
|
|
+ String sql="select * from a_production_order where id = ?";
|
|
|
+ Map<String, Object> one = jdbcService.findOne(sql, id);
|
|
|
+ String orderCode = one.get("orderCode").toString();
|
|
|
+ String orderName = one.get("orderName").toString();
|
|
|
+ String productName = one.get("productName").toString();
|
|
|
+ String productCode = one.get("productCode").toString();
|
|
|
+ String planAmount = one.get("planAmount").toString();
|
|
|
+ String productionOrderCode = one.get("productionOrderCode").toString();
|
|
|
+ Long salesOrderId = Long.valueOf(one.get("salesOrderId").toString());
|
|
|
+ String insertSql="INSERT INTO `imcs_platform`.`a_production_preparation_task` (`order_code`, `order_name`, `task_code`, `product_name`, `product_code`, `amount`,`status`, `created_at`,`production_order_code`, `production_order_id`,sales_order_id) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
|
|
+ jdbcService.insert("执行insert",insertSql,orderCode,orderName,generateSerial.generateSerialNumber("aProductionPreparationTask"),productName,productCode,planAmount,0,new Date(),productionOrderCode,id,salesOrderId);
|
|
|
+ jdbcService.update("update a_production_order set is_issue = 1 where id = ?",id);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void batchSplit(Map<String,Object> map) {
|
|
|
+ String[] ids = map.get("ids").toString().split(",");
|
|
|
+ Integer batchAmount = Integer.valueOf(map.get("batchAmount").toString());
|
|
|
+ for (String item:ids){
|
|
|
+ Map<String, Object> one = jdbcService.findOne("select * from a_production_order where id = ?", item);
|
|
|
+ Integer planAmount = Integer.valueOf(one.get("planAmount").toString());
|
|
|
+ Integer isIssue = Integer.valueOf(one.get("isIssue").toString());
|
|
|
+ Long id = Long.valueOf(one.get("id").toString());
|
|
|
+ String orderCode = one.get("orderCode").toString();
|
|
|
+ String orderName = one.get("orderName").toString();
|
|
|
+ String productName = one.get("productName").toString();
|
|
|
+ String productCode = one.get("productCode").toString();
|
|
|
+ Long salesOrderId = Long.valueOf(one.get("salesOrderId").toString());
|
|
|
+ Long productId = Long.valueOf(one.get("productId").toString());
|
|
|
+ if(planAmount < batchAmount){
|
|
|
+ throw new RuntimeException(orderCode+"数量不足以拆批");
|
|
|
+ }
|
|
|
+ if(planAmount == batchAmount || isIssue == 1){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String sql="INSERT INTO `imcs_platform`.`a_production_order` (`order_code`, `production_order_code`, `order_name`, `product_name`, `product_code`, `plan_amount`, `old_production_order_id`, `status`, `sales_order_id`, `product_id`, `is_issue`,created_at) " +
|
|
|
+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
|
|
|
+ jdbcService.insert("执行insert",sql,orderCode,generateSerial.generateSerialNumber("aProductionOrder"),orderName,productName,productCode,planAmount - batchAmount,id,0,salesOrderId,productId,0,new Date());
|
|
|
+ jdbcService.insert("执行insert",sql,orderCode,generateSerial.generateSerialNumber("aProductionOrder"),orderName,productName,productCode,batchAmount,id,0,salesOrderId,productId,0,new Date());
|
|
|
+ jdbcService.update("update a_production_order set status = 1 where id = ?",id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void productionPreparationTask(Long id) {
|
|
|
+ Map<String, Object> one = jdbcService.findOne("select * from a_production_preparation_task where id = ?", id);
|
|
|
+ String sql="INSERT INTO `imcs_platform`.`a_production_design_preparation_task` ( `order_code`, `order_name`, `task_code`, `product_name`, `product_code`," +
|
|
|
+ " `amount`, `status`, `created_at`, `production_order_code`, `production_order_id`, `task_type`,sales_order_id,production_preparation_task_id) " +
|
|
|
+ "VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?);";
|
|
|
+ String orderCode = one.get("orderCode").toString();
|
|
|
+ String orderName = one.get("orderName").toString();
|
|
|
+ String productName = one.get("productName").toString();
|
|
|
+ String productCode = one.get("productCode").toString();
|
|
|
+ String productionOrderCode = one.get("productionOrderCode").toString();
|
|
|
+ Integer amount = Integer.valueOf(one.get("amount").toString());
|
|
|
+ Long productionOrderId = Long.valueOf(one.get("productionOrderId").toString());
|
|
|
+ Long salesOrderId = Long.valueOf(one.get("salesOrderId").toString());
|
|
|
+ for (int i = 1 ;i <= serialMap.size() ; i++){
|
|
|
+ jdbcService.insert("执行insert",sql,orderCode,orderName,generateSerial.generateSerialNumber(serialMap.get(i)),productName,productCode,amount,0,new Date(),productionOrderCode,productionOrderId,i,salesOrderId,id);
|
|
|
+ }
|
|
|
+ jdbcService.update("update a_production_preparation_task set status = 1 where id = ?",id);
|
|
|
+ }
|
|
|
+}
|