Ver Fonte

数据库备份,以防丢失

oyq28 há 1 ano atrás
pai
commit
21e4e4a851

Diff do ficheiro suprimidas por serem muito extensas
+ 1827 - 0
doc/20240315165831.sql


+ 85 - 0
src/main/java/com/imcs/admin/business/controller/BusinessController.java

@@ -68,9 +68,94 @@ public class BusinessController {
         return Result.success();
         return Result.success();
     }
     }
 
 
+    /**
+     * 工艺路径 设置 有效
+     * @param id
+     * @param parentId
+     * @return
+     */
     @GetMapping("/processVersion/status/{id}/{parentId}")
     @GetMapping("/processVersion/status/{id}/{parentId}")
     public Result processVersion(@PathVariable("id") Long id,@PathVariable("parentId") Long parentId){
     public Result processVersion(@PathVariable("id") Long id,@PathVariable("parentId") Long parentId){
         businessService.processVersion(id,parentId);
         businessService.processVersion(id,parentId);
         return Result.success();
         return Result.success();
     }
     }
+
+    /**
+     * 生产排产
+     * @param id
+     * @return
+     */
+    @GetMapping("/orderToProcedure/{id}")
+    public Result orderToProcedure(@PathVariable("id") Long id){
+        businessService.orderToProcedure(id);
+        return Result.success();
+    }
+
+
+    /**
+     * 生产任务 批量审批
+     * @param map
+     * @return
+     */
+    @PostMapping("/productionWorkOrder/batchApplyStatus")
+    public Result batchApplyStatus(@RequestBody Map<String,Object> map){
+        businessService.batchApplyStatus(map);
+        return Result.success();
+    }
+
+    /**
+     * 领料
+     * @param id
+     * @return
+     */
+    @GetMapping("/aProductionWorkOrder/receive/{id}")
+    public Result receive(@PathVariable("id") Long id){
+        businessService.receive(id);
+        return Result.success();
+    }
+
+    /**
+     * 报工
+     * @param id
+     * @return
+     */
+    @PostMapping("/reportAmount/{id}")
+    public Result reportAmount(@RequestBody Map<String,Object> map,@PathVariable Long id){
+        businessService.reportAmount(id,map);
+        return Result.success();
+    }
+
+    /**
+     * 出入库任务
+     * @param id
+     * @return
+     */
+    @GetMapping("/inOut/{id}")
+    public Result inOut(@PathVariable("id") Long id){
+        businessService.inOut(id);
+        return Result.success();
+    }
+
+    /**
+     * 完工入库
+     * @param id
+     * @return
+     */
+    @GetMapping("/productIn/{id}")
+    public Result productIn(@PathVariable("id") Long id){
+        businessService.productIn(id);
+        return Result.success();
+    }
+
+    /**
+     * 报废
+     * @param map
+     * @param id
+     * @return
+     */
+    @PostMapping("/scrapAmount/{id}")
+    public Result scrapAmount(@RequestBody Map<String,Object> map,@PathVariable Long id){
+        businessService.scrapAmount(id,map);
+        return Result.success();
+    }
 }
 }

+ 14 - 0
src/main/java/com/imcs/admin/business/service/BusinessService.java

@@ -15,4 +15,18 @@ public interface BusinessService {
     void productionPreparationTask(Long id);
     void productionPreparationTask(Long id);
 
 
     void processVersion(Long id,Long parentId);
     void processVersion(Long id,Long parentId);
+
+    void orderToProcedure(Long id);
+
+    void batchApplyStatus(Map<String, Object> map);
+
+    void receive(Long id);
+
+    void reportAmount(Long id, Map<String, Object> map);
+
+    void inOut(Long id);
+
+    void productIn(Long id);
+
+    void scrapAmount(Long id, Map<String, Object> map);
 }
 }

+ 294 - 10
src/main/java/com/imcs/admin/business/service/impl/BusinessServiceImpl.java

@@ -1,32 +1,28 @@
 package com.imcs.admin.business.service.impl;
 package com.imcs.admin.business.service.impl;
 
 
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.collection.CollectionUtil;
-import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 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.business.service.BusinessService;
 import com.imcs.admin.common.PageData;
 import com.imcs.admin.common.PageData;
 import com.imcs.admin.common.PageParam;
 import com.imcs.admin.common.PageParam;
 import com.imcs.admin.common.Result;
 import com.imcs.admin.common.Result;
+import com.imcs.admin.common.config.SessionContext;
 import com.imcs.admin.db.service.JdbcDao;
 import com.imcs.admin.db.service.JdbcDao;
 import com.imcs.admin.db.service.JdbcService;
 import com.imcs.admin.db.service.JdbcService;
-import com.imcs.admin.util.DateUtils;
 import com.imcs.admin.util.GenerateSerial;
 import com.imcs.admin.util.GenerateSerial;
+import com.imcs.admin.util.StringUtil;
 import org.apache.commons.collections.map.HashedMap;
 import org.apache.commons.collections.map.HashedMap;
-import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.core.parameters.P;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
-import java.math.BigDecimal;
 import java.util.*;
 import java.util.*;
-import java.util.stream.Collectors;
 
 
+@Transactional(rollbackFor = Exception.class)
 @Service
 @Service
-public class BusinessServiceImpl implements BusinessService {
+public class BusinessServiceImpl implements BusinessService{
     @Resource
     @Resource
     private JdbcDao jdbcDao;
     private JdbcDao jdbcDao;
 
 
@@ -145,4 +141,292 @@ public class BusinessServiceImpl implements BusinessService {
         jdbcService.update("update a_process_version set status = 1 where id = ?",id);
         jdbcService.update("update a_process_version set status = 1 where id = ?",id);
         jdbcService.update("update a_process_version set status = 0 where id != ? and parent_id = ?",id,parentId);
         jdbcService.update("update a_process_version set status = 0 where id != ? and parent_id = ?",id,parentId);
     }
     }
+
+    @Override
+    public void orderToProcedure(Long id) {
+        Map<String, Object> one = jdbcService.findOne("select * from a_production_order where id = ? ", id);
+        Long productId = Long.valueOf(one.get("productId").toString());
+        Long productionId = Long.valueOf(one.get("id").toString());
+        Long salesOrderId = Long.valueOf(one.get("salesOrderId").toString());
+        Integer planAmount = Integer.valueOf(one.get("planAmount").toString());
+        String orderCode = one.get("orderCode").toString();
+        String orderName = one.get("orderName").toString();
+        String productionOrderCode = one.get("productionOrderCode").toString();
+
+        StringBuffer selectProcedureStr=new StringBuffer("\tselect pp.*,p.procedure_code,p.procedure_name from a_process_version pv\n" +
+                "\tleft join a_process_procedure pp on pv.id=pp.parent_id\n" +
+                "\tleft join a_procedure p on p.id=pp.procedure_id\n" +
+                "\t where pv.parent_id = ? and pv.status = 1 order by pp.seq");
+        List<Object> args = new ArrayList<>();
+        args.add(StrUtil.format("{}",productId));
+        PageParam pageParam = new PageParam();
+        pageParam.put("openPage","NO");
+        Result<PageData<Map<String, Object>>> detailQuery = jdbcDao.query(new PageParam(), selectProcedureStr.toString(), args.toArray());
+        List<Map<String, Object>> items = detailQuery.getData().getItems();
+        if(CollectionUtil.isEmpty(items)){
+            throw new RuntimeException("该产品无有效工艺路径");
+        }
+        StringBuffer insertWork=new StringBuffer("INSERT INTO a_production_work_order (`apply_status`, `create_time`, `order_code`, `order_name`, `plan_amount`, " +
+                "`procedure_name`, `process_procedure_id`,`work_device_id`, `seq`, `status`, `work_code`,  `task_type`, `production_order_code`, `work_device`, `sales_order_id`, `production_order_id`, `is_receive`,report_amount,scrap_amount) " +
+                "VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+
+        items.stream().forEach(vo->{
+            String procedureName = vo.get("procedureName").toString();
+            Integer taskType = Integer.valueOf(vo.get("isOutsourcing").toString());
+            if(taskType == 0 && Objects.isNull(vo.get("deviceId"))){
+                throw new RuntimeException(procedureName+"加工工序未绑定设备");
+            }
+
+            Long processProcedureId = Long.valueOf(vo.get("id").toString());
+            Integer seq = Integer.valueOf(vo.get("seq").toString());
+            Long workDeviceId = null;
+            if(!Objects.isNull(vo.get("deviceId")) && StringUtils.isNotBlank(vo.get("deviceId").toString())){
+                String deviceId = vo.get("deviceId").toString();
+                StringBuffer deviceStr=new StringBuffer("select MIN(t.workCount),t.work_device_id from (\n" +
+                        "select count(*) as workCount,work_device_id from a_production_work_order WHERE status in (0,1) and work_device_id IN (?) GROUP BY work_device_id)t order by t.work_device_id limit 1");
+                Map<String, Object> minDevice = jdbcService.findOne(deviceStr.toString(), deviceId);
+                if(minDevice.containsKey("workDeviceId") && !Objects.isNull(minDevice.get("workDeviceId"))){
+                    workDeviceId=Long.valueOf(minDevice.get("workDeviceId").toString());
+                }else{
+                    workDeviceId=Long.valueOf(deviceId.split(",")[0]);
+                }
+            }
+            Map<String, Object> deviceMap=new HashMap<>();
+            String deviceName=null;
+            if(workDeviceId != null){
+                deviceMap = jdbcService.findOne("select * from a_device where id = ? ", workDeviceId);
+                deviceName = deviceMap.get("deviceName").toString();
+            }
+
+            jdbcService.insert("执行insert",insertWork.toString(),0,new Date(),orderCode,orderName,planAmount,procedureName,processProcedureId,taskType == 0 ? workDeviceId : null,seq,0,generateSerial.generateSerialNumber("aProductionWorkOrder"),taskType,productionOrderCode,taskType == 0 ? deviceName : null,salesOrderId,productionId,0,0,0);
+        });
+
+        jdbcService.update("update a_production_order set is_plan = 2 where id = ?",id);
+    }
+
+    @Override
+    public void batchApplyStatus(Map<String, Object> map) {
+        String ids = map.get("ids").toString();
+        String[] idArray = ids.split(",");
+
+        // 构建带有与值数量相同的问号的字符串,用于 SQL 的 IN 子句
+        String placeholders = String.join(",", Collections.nCopies(idArray.length, "?"));
+
+        // 构建更新查询语句
+        String sql = "UPDATE a_production_work_order SET apply_status = 1 WHERE id IN (" + placeholders + ")";
+        jdbcService.update(sql, (Object[]) idArray);
+    }
+
+    @Override
+    public void receive(Long id) {
+        Map<String, Object> one = jdbcService.findOne("select * from a_production_work_order where id = ? ", id);
+        String seq = one.get("seq").toString();
+        String workCode = one.get("workCode").toString();
+        String productionOrderCode = one.get("productionOrderCode").toString();
+        Integer planAmount = Integer.valueOf(one.get("planAmount").toString());
+        Integer taskType = Integer.valueOf(one.get("taskType").toString());
+        Long processProcedureId = Long.valueOf(one.get("processProcedureId").toString());
+        //校验上道工序是否完成  加工工序可以越过质检工序和外协工序,质检和外协不能跳跃任何工序
+        //首道工序无须校验
+        if(!"1".equals(seq)){
+            checkLastProcedure(id,taskType,processProcedureId,productionOrderCode);
+        }
+        Integer isRecevie=null;
+
+        //首道工序
+        if("1".equals(seq)){
+            //TODO 生成领料任务
+            StringBuffer inserInOut=new StringBuffer("INSERT INTO a_material_in_out_record ( in_out_code, work_code, created_at, in_out_type, production_work_order_id, in_out_by, apply_status) \n" +
+                    "VALUES ( ?, ?, ?, ?, ?, ?, ?)");
+            Long inOutId = jdbcService.insert("执行insert", inserInOut.toString(), generateSerial.generateSerialNumber("aMaterialInOutRecordCK"), workCode, new Date(), 0, id, null, 0);
+
+            //查询产品bom
+            StringBuffer selectProcedureStr=new StringBuffer("select pm.*,m.material_code,m.material_name from a_production_work_order pwo \n" +
+                    "left join a_production_order po on pwo.production_order_id=po.id\n" +
+                    "left join a_product_material pm on po.product_id=pm.parent_id\n" +
+                    "left join a_material m on pm.material_id=m.id\n" +
+                    "where pwo.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(), selectProcedureStr.toString(), args.toArray());
+            List<Map<String, Object>> items = detailQuery.getData().getItems();
+            StringBuffer insertInOutDetail=new StringBuffer("INSERT INTO a_material_in_out_record_detail ( material_id, material_code, material_name, amount, material_in_out_record_id,seq) \n" +
+                    "VALUES (?, ?, ?, ?, ?, ?)");
+            for(int i=0;i<items.size();i++){
+                Map<String, Object> vo = items.get(i);
+                Long materialId = Long.valueOf(vo.get("materialId").toString());
+                String materialCode = vo.get("materialCode").toString();
+                String materialName = vo.get("materialName").toString();
+                Integer materialAmount = Integer.valueOf(vo.get("materialAmount").toString());
+                jdbcService.insert("执行insert",insertInOutDetail.toString(),materialId,materialCode,materialName,planAmount*materialAmount,inOutId,i);
+            }
+            isRecevie=1;
+        }else{
+            isRecevie=2;
+        }
+        jdbcService.update("update a_production_work_order set status = 1,is_receive = ?,real_start_date = now(),receive_by = ? where id = ?",isRecevie,getUserId(),id);
+    }
+
+    private void checkLastProcedure(Long recordId, Integer taskType,Long processProcedureId,String productionOrderCode) {
+        //加工工序校验上道加工工序是否完成
+        String sql = null;
+        if(taskType == 0){
+             sql="select * from a_production_work_order where task_type  = 0 and production_order_code = ? order by seq ";
+
+        }else{
+            sql="select * from a_production_work_order where production_order_code = ? order by seq ";
+        }
+
+        List<Map<String, Object>> query = query(sql, new Object[]{productionOrderCode});
+        Map<String, Object> lastProcedure = getLastProcedure(query, recordId);
+
+        //当上到工序就是本工序时
+        if(lastProcedure == null ){
+            return;
+        }
+        Integer status = Integer.valueOf(lastProcedure.get("status").toString());
+        String workCode = lastProcedure.get("workCode").toString();
+        if(status != 2){
+            throw new RuntimeException("上道工序未完成"+",请先完成 "+workCode);
+        }
+
+    }
+
+    @Override
+    public void reportAmount(Long id, Map<String, Object> map) {
+        Integer reportAmount = Integer.valueOf(map.get("amount").toString());
+
+        Map<String, Object> one = jdbcService.findOne("select * from a_production_work_order where id = ?", id);
+        Integer amount=0;
+        Integer seq = Integer.valueOf(one.get("seq").toString());
+        String productionOrderCode=one.get("productionOrderCode").toString();
+        Integer reportAmount1 = Integer.valueOf(one.get("reportAmount").toString());
+        Integer scrapAmount = Integer.valueOf(one.get("scrapAmount").toString());
+        Integer planAmount = 0;
+        if(seq == 1){
+            planAmount = Integer.valueOf(one.get("planAmount").toString());
+        }else{
+            //找出上道工序已完成工序的报工数量
+            String sql="select * from a_production_work_order where status=2 and production_order_code = ? and seq < ? order by seq desc limit 1 ";
+            Map<String, Object> lastProcedure = jdbcService.findOne(sql, productionOrderCode,seq);
+            planAmount = Integer.valueOf(lastProcedure.get("reportAmount").toString());
+        }
+
+
+        if(reportAmount+reportAmount1 > planAmount - scrapAmount){
+            throw new RuntimeException("报工数量超出生产数量,请核对报工数量!!!");
+        }
+
+        StringBuffer insert=new StringBuffer("INSERT INTO a_work_report_record ( production_work_order_id, report_amount, created_at, created_by) " +
+                "VALUES ( ?, ?, ?, ?);");
+        jdbcService.insert("执行insert",insert.toString(),id,reportAmount,new Date(),getUserId());
+        jdbcService.update("update a_production_work_order set report_amount=report_amount + ? where id = ?",reportAmount,id);
+    }
+
+    @Override
+    public void inOut(Long id) {
+        Map<String, Object> one = jdbcService.findOne("select * from a_material_in_out_record where id = ?", id);
+        Long productionWorkOrderId = Long.valueOf(one.get("productionWorkOrderId").toString());
+        jdbcService.update("update a_material_in_out_record set apply_status=1,in_out_by = ? where id = ? ",getUserId(),id);
+        jdbcService.update("update a_production_work_order set is_receive = 2 where id = ?",productionWorkOrderId);
+        String sql="select * from a_material_in_out_record_detail where material_in_out_record_id = ? ";
+        List<Map<String, Object>> query = query(sql, id);
+        for(Map<String, Object> item:query){
+            Long materialId=Long.valueOf(item.get("materialId").toString());
+            Integer amount=Integer.valueOf(item.get("amount").toString());
+            String materialName = item.get("materialName").toString();
+            int update = jdbcService.update("update a_material_store set store_amount=store_amount - ? where parent_id = ?", amount, materialId);
+            if(update <= 0){
+                throw new RuntimeException(materialName+"物料不足");
+            }
+        }
+    }
+
+    @Override
+    public void productIn(Long id) {
+        Map<String, Object> one = jdbcService.findOne("select * from a_production_work_order where production_order_code = (select production_order_code from a_production_work_order where id= ?) order by seq desc limit 1", id);
+        Long endId = Long.valueOf(one.get("id").toString());
+        Long productionOrderId = Long.valueOf(one.get("productionOrderId").toString());
+        Integer reportAmount=Integer.valueOf(one.get("reportAmount").toString());
+        String workCode = one.get("workCode").toString();
+        //最后一道工序入库
+        if(endId == id){
+            Map<String, Object> flag = jdbcService.findOne("select * from a_product_store where parent_id = (select product_id from a_production_order where id = ?)", productionOrderId);
+            Map<String, Object> productIdMap = jdbcService.findOne("select product_id from a_production_order where id = ?", productionOrderId);
+            Integer productId1 = Integer.valueOf(productIdMap.get("productId").toString());
+
+            if(flag == null){
+                String insertProductStore="INSERT INTO a_product_store (parent_id,store_amount) values(?,?)";
+                jdbcService.insert(insertProductStore,productId1,reportAmount);
+            }else{
+                Long productId=Long.valueOf(flag.get("parentId").toString());
+                jdbcService.update("update a_product_store set store_amount=store_amount + ? where parent_id = ?",reportAmount,productId);
+            }
+
+            //入库记录
+            String insert="INSERT INTO a_product_store_record (production_work_order_id, amount, work_code, created_at, apply_status) VALUES (?, ?, ?, ?, ?)";
+            jdbcService.insert("执行sql",insert,id,reportAmount,workCode,new Date(),0);
+        }
+        jdbcService.update("update a_production_work_order set status=2 where id=?",id);
+    }
+
+    @Override
+    public void scrapAmount(Long id, Map<String, Object> map) {
+        Map<String, Object> one = jdbcService.findOne("select * from a_production_work_order where id = ? ", id);
+        String workCode = one.get("workCode").toString();
+        Integer amount = Integer.valueOf(map.get("amount").toString());
+        Integer reportAmount = Integer.valueOf(one.get("reportAmount").toString());
+        Integer planAmount = Integer.valueOf(one.get("planAmount").toString());
+        Integer scrapAmount = Integer.valueOf(one.get("scrapAmount").toString());
+        String scrapReason = map.get("scrapReason").toString();
+        if(reportAmount + amount + scrapAmount > planAmount){
+            throw new RuntimeException("报工数量+报废数量超出生产数量,请核对报废数量!!!");
+        }
+
+
+        String scrap="INSERT INTO a_work_scrap ( scrap_code, work_code, scrap_amount, scrap_person, scrap_reason, apply_status, create_time, production_work_order_id) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?)";
+        jdbcService.insert("执行sql",scrap,generateSerial.generateSerialNumber("aWorkScrap"),workCode,amount,getUserId(),scrapReason,0,new Date(),id);
+        jdbcService.update("update a_production_work_order set scrap_amount=scrap_amount + ? where id = ?",amount,id);
+    }
+
+    public Long getUserId(){
+        Long userId = SessionContext.getSession().getUserId();
+        return userId;
+    }
+
+    public List<Map<String, Object>> query(String sql,Object... arg){
+
+        List<Object> args = new ArrayList<>();
+        for (Object obj:arg){
+            args.add(StrUtil.format("{}",obj));
+        }
+        PageParam pageParam = new PageParam();
+        pageParam.put("openPage","NO");
+        Result<PageData<Map<String, Object>>> detailQuery = jdbcDao.query(new PageParam(), sql, args.toArray());
+        List<Map<String, Object>> items = detailQuery.getData().getItems();
+        return items;
+    }
+
+    public Map<String,Object> getLastProcedure(List<Map<String, Object>> query,Long recordId){
+        int currentIndex = -1;
+        for (int i = 0; i < query.size(); i++) {
+            Map<String, Object> row = query.get(i);
+            Object id = row.get("id"); // 假设 ID 字段名为 id
+            if (id.equals(recordId)) {
+                currentIndex = i;
+                break;
+            }
+        }
+
+// 获取上一条数据
+        Map<String, Object> previousRow = null;
+        if (currentIndex > 0) {
+            previousRow = query.get(currentIndex - 1);
+        } else {
+            // 当前 ID 是第一条数据,无上一条数据
+        }
+        return previousRow;
+    }
 }
 }

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff