guoyujia 5 месяцев назад
Родитель
Сommit
2bc479b589

+ 3 - 0
src/main/java/cn/ezhizao/project/business/deptProcess/controller/BizDeptProcessController.java

@@ -18,6 +18,7 @@ import javax.servlet.http.HttpServletResponse;
 import java.util.*;
 import java.util.stream.Collectors;
 
+import cn.ezhizao.project.business.product.service.IBizDayworkService;
 import cn.ezhizao.project.business.product.service.IBizProductionPlanDetailService;
 import cn.ezhizao.project.business.technologicalProcessDetail.domain.BizTechnologicalProcessDetail;
 import cn.ezhizao.project.business.technologicalProcessDetail.service.IBizTechnologicalProcessDetailService;
@@ -44,6 +45,8 @@ public class BizDeptProcessController extends BaseController {
 
     @Resource
     private IBizProductionPlanDetailService bizProductionPlanDetailService;
+    @Resource
+    private IBizDayworkService bizDayworkService;
 
     @Resource
     HttpServletRequest request;

+ 1 - 0
src/main/java/cn/ezhizao/project/business/outsource/domain/BizOutsourcedOrder.java

@@ -74,4 +74,5 @@ public class BizOutsourcedOrder extends BaseEntity
 
     @TableField(exist = false)
     private String keywords;
+    private Long outsourceDeptId;
 }

+ 2 - 0
src/main/java/cn/ezhizao/project/business/outsource/domain/BizOutsourcedOrderDetail.java

@@ -116,4 +116,6 @@ public class BizOutsourcedOrderDetail extends BaseEntity
 
     @TableField(exist = false)
     private List<BizTechnologicalProcessDetail> technologicalProcessDetailList;
+    @TableField(exist = false)
+    private Long productionPlanDetailId;
 }

+ 6 - 1
src/main/java/cn/ezhizao/project/business/outsource/domain/BizOutsourcedOrderDetailProcess.java

@@ -1,5 +1,6 @@
 package cn.ezhizao.project.business.outsource.domain;
 
+import java.math.BigDecimal;
 import java.util.Date;
 
 import cn.ezhizao.framework.aspectj.lang.annotation.Excel;
@@ -95,5 +96,9 @@ public class BizOutsourcedOrderDetailProcess extends BaseEntity
     private String processAlias;
     @ApiModelProperty(value = "工序号")
     private String processCode;
-
+    private String processStepNumber;
+    private Integer productNum;
+    private Integer qualifiedNum;
+    private BigDecimal loss;
+    private Integer productionNum;
 }

+ 613 - 48
src/main/java/cn/ezhizao/project/business/product/controller/BizDayworkController.java

@@ -9,6 +9,8 @@ import cn.ezhizao.framework.web.controller.BaseController;
 import cn.ezhizao.framework.web.domain.AjaxResult;
 import cn.ezhizao.project.business.deptProcess.domain.BizDeptProcess;
 import cn.ezhizao.project.business.equipment.domain.BizEquipmentDetail;
+import cn.ezhizao.project.business.outsource.domain.BizOutsourcedOrderDetailProcess;
+import cn.ezhizao.project.business.outsource.service.IBizOutsourcedOrderDetailProcessService;
 import cn.ezhizao.project.business.process.domain.BizProcess;
 import cn.ezhizao.project.business.product.domain.*;
 import cn.ezhizao.project.business.product.service.*;
@@ -89,59 +91,542 @@ public class BizDayworkController extends BaseController {
     private ISysDeptService sysDeptService;
     @Resource
     private IBizWorkshopService bizWorkshopService;
+    @Resource
+    private IBizReturnReceiptDetailService bizReturnReceiptDetailService;
+    @Resource
+    private IBizOutsourcedOrderDetailProcessService bizOutsourcedOrderDetailProcessService;
+
+    /*
+    @Transactional
+    @GetMapping("/list")
+    public AjaxResult list(BizDaywork bizDaywork) {
+        List<BizDaywork>list = new ArrayList<>();
+        List<BizDaywork> dayworkList = bizDayworkService.getList(bizDaywork);
+        //查询当前工段工序
+        BizDeptProcess bizDeptProcess = new BizDeptProcess();
+        bizDeptProcess.setDeptId(bizDaywork.getDeptId());
+        List<BizDeptProcess> processList = bizDeptProcessService.getList(bizDeptProcess);
+        List<Long> ids = new ArrayList<>();
+        for (BizDeptProcess item: processList
+             ) {
+            ids.add(item.getProcessId());
+        }
+        for (BizDaywork daywork:dayworkList
+             ) {
+            //查询工段下工序有没有未周转的批次
+            List<BizDayworkItem> itemList = bizDayworkItemService.query().eq("deleted", 0).eq("daywork_id", daywork.getId()).in("process_id", ids).lt("status", 4).orderByDesc("create_time").list();
+            if (itemList.size()>0){
+                BizProcess processItem = bizProcessService.query().eq("id", itemList.get(itemList.size() - 1).getProcessId()).one();
+                daywork.setCurrentProcess(processItem);
+                //如果最新的item 只有一条 且状态是未开始,那么整个批次报工为未开始状态
+                if (daywork.getDayworkItemList().size() == 1 && daywork.getDayworkItemList().get(0).getStatus().equals("0")) {
+                    daywork.setStatus(0);
+                    //如果item有多条 且最新的一条状态为工序完成那么批次报工状态为待周转
+                } else if (daywork.getDayworkItemList().size() > 0 && daywork.getDayworkItemList().get(0).getStatus().equals("3")) {
+                    daywork.setStatus(2);
+                    //如果item有多条 且最新的一条状态为待周转那么批次报工状态为周转中
+                } else if (daywork.getDayworkItemList().size() > 0 && daywork.getDayworkItemList().get(0).getStatus().equals("4")) {
+                    daywork.setStatus(3);
+                    //判断item最新的一条是否为最后一道工序且工序已完成
+                } else if( daywork.getDayworkItemList().get(0).getStatus().equals("4") && daywork.getDayworkItemList().get(0).getProcessId().equals(daywork.getProcessSequence().get(daywork.getProcessSequence().size() - 1).getId())){
+                    daywork.setStatus(4);
+                }else {
+                    daywork.setStatus(1);
+                }
+            }
+            list.add(daywork);
+        }
+
+        return success(list);
+    }
+     */
+
+    /**
+     * 查询报工列表
+     */
+    @Transactional
+    @GetMapping("/list")
+    @Log(title = "获取报工列表", businessType = BusinessType.SELECT)
+    public AjaxResult list(BizDaywork bizDaywork) {
+        SysUser user = SecurityUtils.getLoginUser().getUser();
+        Long userId = user.getUserId();
+        Long productionPlanDetailId = bizDaywork.getProductionPlanDetailId();
+        Long deptId = bizDaywork.getDeptId();
+        String keywords = bizDaywork.getKeywords();
+
+        // 如果关键字不为空,则根据关键字匹配批次,后面会根据批次进行daywork过滤
+        List<BizLot> lots = new ArrayList<>();
+        if (!keywords.isEmpty()) {
+            List<BizLot> lotList1 = bizLotService.query()
+                    .like("lot_code", keywords)
+                    .list();
+            List<Long> dayworkCarrierIds = bizDayworkCarrierService.query().like("carrier_code", keywords).eq("process_inspection_id", 0L).eq("is_changed",0).list().stream().map(BizDayworkCarrier::getDayworkId).collect(Collectors.toList());
+            List<BizDaywork> dayworkByCarriers = bizDayworkService.query().in("id", dayworkCarrierIds.isEmpty() ? Collections.singletonList(0L) : dayworkCarrierIds).list();
+            List<BizLot> lotList2 = bizLotService.query().in("id", dayworkByCarriers.isEmpty() ? Collections.singletonList(0L) : dayworkByCarriers.stream().map(BizDaywork::getLotId).collect(Collectors.toList())).list();
+            Set<BizLot> uniqueSet = Stream.of(lotList1, lotList2)
+                    .flatMap(Collection::stream)
+                    .collect(Collectors.toSet());
+            lots = uniqueSet.stream().collect(Collectors.toList());
+            if (lots.isEmpty()) {
+                return success(new ArrayList<>());
+            }
+        }
+        // 获取当前用户的,针对当前部门以及当前生产计划下的报工集合
+        List<BizDayworkItem> myDayworkItems = bizDayworkItemService.query()
+                .eq("dept_id", deptId)
+                .eq("production_plan_detail_id", productionPlanDetailId)
+                .eq("user_id", userId)
+                .list();
+        List<BizProductionPlanDetail> planDetailslanDetails = new ArrayList<>();
+        List<BizDaywork> dayworks = new ArrayList<>();
+        // 定义一个所有的报工集合,用于后续接收所有的某个批次的报工记录
+        List<BizDayworkItem> allDayworkItems = new ArrayList<>();
+        List<BizLot> lotList = new ArrayList<>();
+        if (!myDayworkItems.isEmpty()) {
+            // 将报工记录中的daywork_id,整个到一个List集合中,用于后续的查询
+            List<Long> dayworkIds = myDayworkItems.stream()
+                    .map(BizDayworkItem::getDayworkId)
+                    .collect(Collectors.toList());
+            // 再根据整合后报工明细中对应的 daywork_id 的集合,获取到对应的 daywork 集合
+            if (keywords.isEmpty())
+                dayworks = bizDayworkService.query().in("id", dayworkIds).list();
+            else if (!lots.isEmpty()) {
+                List<Long> lotIds = lots.stream().map(BizLot::getId).collect(Collectors.toList());
+                dayworks = bizDayworkService.query()
+                        .in("id", dayworkIds)
+                        .in("lot_id", lotIds)
+                        .list();
+            }
+            if (dayworks.isEmpty())
+                return success(new ArrayList<>());
+
+            planDetailslanDetails = bizProductionPlanDetailService.query().in("id", dayworks.stream().map(BizDaywork::getProductionPlanDetailId).collect(Collectors.toList())).list();
+            // 根据得到的 daywork 集合,将 daywork_id 整合到集合中
+            List<Long> allDayworkIdList = dayworks.stream().map(BizDaywork::getId).collect(Collectors.toList());
+            // 再根据得到的daywork_id集合,获取所有的报工明细
+            allDayworkItems = bizDayworkItemService.query().in("daywork_id", allDayworkIdList.isEmpty() ? Collections.singletonList(0L) : dayworks.stream().map(BizDaywork::getId).collect(Collectors.toList())).list();
+            // 获取所有lotId
+            List<Long> allLotsIdList = dayworks.stream().map(BizDaywork::getLotId).collect(Collectors.toList());
+            lotList = bizLotService.query().in("id", allLotsIdList.isEmpty() ? Collections.singletonList(0L) : dayworks.stream().map(BizDaywork::getLotId).collect(Collectors.toList())).list();
+        }
+
+        // 定义一个daywork空的list集合,用于存储符合条件(根据daywork的id,获得到对应的最新一条daywork_item,当该条daywork_item的状态值 < 5时,则添加)的daywork
+        List<BizDaywork> dayworkList = new ArrayList<>();
+        // 对之前获取到的 daywork 集合进行过滤,将符合条件的daywork,添加到dayworkList集合中
+        for (BizDaywork item : dayworks) {
+            if (!planDetailslanDetails.isEmpty()) {
+                //设置尾批量
+                item.setLastLotQuantity(planDetailslanDetails.stream().filter(v -> v.getId().equals(item.getProductionPlanDetailId())).collect(Collectors.toList()).get(0).getLastLotQuantity());
+            }
+            //添加批次单批量
+            item.setOneLotQuantity(lotList.stream().filter(v -> v.getId().equals(item.getLotId())).collect(Collectors.toList()).get(0).getProductionQuantity());
+            //拿到批次是否批废信息
+            item.setIsWaste(lotList.stream().filter(v -> v.getId().equals(item.getLotId())).collect(Collectors.toList()).get(0).getIsWaste());
+            // 根据当前的dayworkId,获取相应的daywork_item集合,并根据创建日期进行倒叙排序
+            // 原代码中对报工进行了按当前登录者user_id的判断,这样,就无法真实获取到当前批次的状态,而是当前登录者的报工状态。
+            // 如果该批次是一个人操作的,则没有问题,如果是多人(邀请报工),通过user_id过滤后,就会出现状态不准的情况。
+            // 所以需要将filter中,user_id过滤去掉
+            /*
+            List<BizDayworkItem> currentDayworkItems = allDayworkItems.stream()
+                    .filter(di -> di.getDayworkId().equals(item.getId()) && di.getUserId().equals(userId))
+                    .sorted(Comparator.comparing(BizDayworkItem::getCreateTime).reversed())
+                    .collect(Collectors.toList());
+             */
+            List<BizDayworkItem> currentDayworkItems = allDayworkItems.stream()
+                    .filter(di -> di.getDayworkId().equals(item.getId()))
+                    .sorted(Comparator.comparing(BizDayworkItem::getCreateTime).reversed())
+                    .collect(Collectors.toList());
+            // 获取最后一条报工明细
+            BizDayworkItem latest = currentDayworkItems.get(0);
+            // 获取最后一条非周转报工,通过过滤掉“4”状态的报工明细,获取到最新的一条非“4”状态的报工明细,避免后续的与 < 5 的条件冲突
+            BizDayworkItem latestNoTurnover = currentDayworkItems.stream().filter(v -> v.getStatus().compareTo("4") < 0)
+                    .max(Comparator.comparing(BizDayworkItem::getCreateTime)).orElse(new BizDayworkItem());
+            BizDayworkItem latestProcess = currentDayworkItems.stream().filter(v -> v.getProcessStepNumber().equals(latestNoTurnover.getProcessStepNumber()) && v.getUserId().equals(userId)).findFirst().orElse(null);
+            String status = currentDayworkItems.stream().filter(v -> v.getTechnologicalProcessDetailId().equals(latest.getTechnologicalProcessDetailId()))
+                    .collect(Collectors.toList())
+                    .get(0)
+                    .getStatus();
+            // 原程序中这里的判断条件是:user_id == 当前登录者user_id && status < 5,但这里不应该判断登录者user_id,而是直接判断状态值,
+            // 因为,如果该批次是多人操作的,那么,该批次的报工状态,应该是所有人的,所以,这里不应该判断user_id
+            // if (latest.getUserId().equals(userId) && Integer.parseInt(status) < 5) {
+
+            // 判断最后一道报工记录的部门id,与当前登录者的部门id相同,并且状态 < 5
+            // 状态 == 5 时,说明已经进入周转中,那么该条daywork,将不再页面中显示,所以,通过对status的值的判断,添加到daywork集合中
+            // 最后一条非周转报工的工段为当前工段。
+            //20240806添加isSpecial!=1将最新一条报工为特殊报工的批次删除
+            if (!latestNoTurnover.getIsSpecial().equals(1) && latestNoTurnover.getDeptId().equals(deptId) && Integer.parseInt(status) < 5 && latestProcess != null) {
+                // 获取当前操作者自己的报工记录
+                List<BizDayworkItem> currentMyDayworkItems = myDayworkItems.stream()
+                        .filter(di -> di.getDayworkId().equals(item.getId()))
+                        .sorted(Comparator.comparing(BizDayworkItem::getCreateTime))
+                        .collect(Collectors.toList());
+                // 将获取到的 day_work_item 集合,赋值给daywork中的相对应属性
+                item.setDayworkItemList(currentMyDayworkItems);
+                dayworkList.add(item);
+            }
+        }
+
+        // 如果有报工数据
+        if (!dayworkList.isEmpty()) {
+            // 将符合条件(需要在页面展示的daywork)的 dayworkList 中的 technologicalProcessId,整合到一个List集合中,需要根据这些technologicalProcessId,获取到相应的工艺工序清单
+            System.out.println("有报工数据:" + dayworkList);
+            List<Long> technologicalProcessIds = dayworkList.stream()
+                    .map(BizDaywork::getTechnologicalProcessId)
+                    .collect(Collectors.toList());
+            // 根据 technologicalProcessIds 获取符合条件的所有工艺工序清单
+            List<BizTechnologicalProcessDetail> technologicalProcessDetails = bizTechnologicalProcessDetailService.query()
+                    .in("technological_process_id", technologicalProcessIds).ne("tenant_id", 9)
+                    .list();
+            // 将符合条件的所有工艺工序清单中的工序id(process_id),整合到一个List集合中
+            List<Long> processIds = technologicalProcessDetails.stream()
+                    .map(BizTechnologicalProcessDetail::getProcessId)
+                    .collect(Collectors.toList());
+            // 根据得到的工序id集合,获得相对应的工序集合
+            List<BizTechnologicalProcessDetail> allTechnologicalProcessDetails = bizTechnologicalProcessDetailService.query().in("technological_process_id", technologicalProcessIds).ne("tenant_id", 9).list();
+            List<Long> finalProcessIds = processIds;
+            List<BizTechnologicalProcessDetail> processList = allTechnologicalProcessDetails.stream().filter(ap -> finalProcessIds.contains(ap.getProcessId())).collect(Collectors.toList());
+
+            // 将最终要显示的daywork集合中的daywork_id整合到一个List集合中,用于后续根据daywork_id获取对应的箱号
+            List<Long> dayworkIdList = dayworkList.stream()
+                    .map(BizDaywork::getId)
+                    .collect(Collectors.toList());
+
+            /* ****************************** 获取daywork 与 箱子 carrier 相关 ****************************** */
+            // 根据daywork_id的集合,获取到所有daywork与箱子关联的中间表 biz_daywork_carrier,用于在循环中精确查询匹配的箱子
+            List<BizDayworkCarrier> dayworkCarriers = bizDayworkCarrierService.query()
+                    .eq("process_inspection_id", 0L)
+                    .in("daywork_id", dayworkIdList)
+                    .eq("is_changed", 0)
+                    .list();
+            // 将箱子的id整合到一个List集合中,用于循环中,进行箱子的查询
+            List<Long> carrierIds = dayworkCarriers.stream()
+                    .map(BizDayworkCarrier::getCarrierId)
+                    .collect(Collectors.toList());
+            // 根据箱子id的集合,获取所有的箱子集合
+            List<BizCarrier> carriers = new ArrayList<>();
+            if (!carrierIds.isEmpty()) {
+                carriers = bizCarrierService.query().in("id", carrierIds).list();
+            }
+
+            /* ****************************** 获取与 daywork 相关的所有批次,为了获取每个批次中的投产数 ****************************** */
+            // 直接通过daywork中的 technological_process_id 组成的集合,获取到对应的批次工艺工序清单,解决【正常】与【异常】冲突的问题
+            List<Long> allTechnologicalProcessIds = dayworkList.stream().map(BizDaywork::getTechnologicalProcessId).collect(Collectors.toList());
+
+            List<BizLotTechnologicalProcessDetail> allLotTechnologicalDetails = bizLotTechnologicalProcessDetailService.query()
+                    .in("lot_technological_process_id", allTechnologicalProcessIds)
+                    .list();
+
+            List<BizLotTechnologicalProcessDetail> technologicalDetailList = new ArrayList<>();
+
+            /* ****************************** 获取 daywork 与 【材质】相关 ****************************** */
+            List<BizFurnaceNoInfo> furnaceNoInfos = bizFurnaceNoInfoService.query()
+                    .in("daywork_id", dayworkIdList)
+                    .list();
+            //查询计划单下所有的报工记录
+            List<BizDayworkItem> totalDayworkItemList = bizDayworkItemService.query().eq("production_plan_detail_id", productionPlanDetailId).list();
+
+            // 循环最终要展示的 daywork 集合,根据每个daywork,精确赋予相关数据
+            List<Long> allLotIds = dayworkList.stream().map(BizDaywork::getLotId).collect(Collectors.toList());
+            List<BizLot> allLots = bizLotService.query().in("id", allLotIds).list();
+            List<Long> allDayworkIds = dayworkList.stream().map(BizDaywork::getId).collect(Collectors.toList());
+            //查找被邀请者的id
+            List<BizProductionResourceGroupDetail> protemResourceGroupDetail = bizProductionResourceGroupDetailService.query().in("protem_daywork_id", allDayworkIds.isEmpty() ? Collections.singletonList(0L) : allDayworkIds)
+                    .eq("common_id", userId).eq("common_type", "person").list();
+            List<Long> protemUserIds = protemResourceGroupDetail.stream().map(BizProductionResourceGroupDetail::getCreatorId).distinct().collect(Collectors.toList());
+            protemUserIds.add(0L);
+            List<SysUser> sysUsers = sysUserService.selectUserListByIds(protemUserIds);
+            //查找dayworkList工段所在的车间
+            List<Long> deptIds = dayworkList.stream().map(BizDaywork::getDeptId).collect(Collectors.toList());
+            SysDept dept = new SysDept();
+            dept.setDeptIds(deptIds);
+            List<SysDept> sysDeptList = sysDeptService.selectDeptList(dept);
+            List<Long> workshopIds = sysDeptList.stream().map(SysDept::getWorkshopId).collect(Collectors.toList());
+            List<BizWorkshop> workshopList = bizWorkshopService.query().in("id", workshopIds).list();
+            for (BizDaywork daywork : dayworkList) {
+                //把批次的lot投产数量加到daywork里
+                allLots.stream().filter(l -> l.getId().equals(daywork.getLotId()))
+                        .findFirst()
+                        .ifPresent(lot -> daywork.setProductionQuantity(lot.getProductionQuantity()));
+
+                // 根据当前的 daywork 的 id,获取到 daywork_item 的集合,并根据 daywork_item 的 create_time 进行倒叙
+                // 之所以通过时间倒叙,目的是在后续过程中,通过get(0)的方式,获得最新的一条报工记录
+                List<BizDayworkItem> tempDayworkItems = totalDayworkItemList.stream()
+                        .filter(di -> di.getDayworkId().equals(daywork.getId()))
+                        .sorted(Comparator.comparing(BizDayworkItem::getCreateTime).reversed())
+                        .collect(Collectors.toList());
+                daywork.setDayworkItemList(tempDayworkItems);
+                /* ************************** 配置当前工段车间 ************************** */
+                SysDept sysDept = sysDeptList.stream().filter(v -> v.getDeptId().equals(daywork.getDeptId())).findFirst().orElse(null);
+                System.out.println("daywork:"+daywork);
+                System.out.println("车间列表输出:"+sysDeptList);
+                System.out.println("车间输出:"+sysDept);
+                System.out.println("workshopList:"+workshopList);
+                daywork.setWorkshopName(workshopList.stream().filter(w -> w.getId().equals(sysDept.getWorkshopId())).findFirst().orElse(null).getName());
+                /* ************************** 获取【daywork】所匹配的材质 ************************** */
+                BizFurnaceNoInfo furnaceNoInfo = furnaceNoInfos.stream()
+                        .filter(di -> di.getDayworkId().equals(daywork.getId()))
+                        .findFirst()
+                        .orElse(null);
+                daywork.setFurnaceNoInfo(furnaceNoInfo);
+
+                /* ************************** 以下是获取daywork对应的箱号 ************************** */
+                // 首先获取到该 daywork 对应的箱子的中间表数据
+                List<BizDayworkCarrier> dayworkCarrierList = dayworkCarriers.stream()
+                        .filter(dc -> dc.getDayworkId().equals(daywork.getId()))
+                        .collect(Collectors.toList());
+                // 再将中间表中的箱子id整合到List集合中
+                List<Long> carrierIdList = dayworkCarrierList.stream()
+                        .map(BizDayworkCarrier::getCarrierId)
+                        .collect(Collectors.toList());
+                // 中间表中存储的箱子id(carrier_id),过滤获得到箱子的集合
+                List<BizCarrier> carrierList = carriers.stream()
+                        .filter(c -> carrierIdList.contains(c.getId()))
+                        .collect(Collectors.toList());
+                // 得到箱子的集合后,将所有箱子的编码,整合成一个用中文“,”分割的字符串
+                String carrierCodes = carrierList.stream()
+                        .map(BizCarrier::getCode)
+                        .collect(Collectors.joining(","));
+                daywork.setCarrierName(carrierCodes);
+
+                /* ************************** 以下是为了获得到所在区域 ************************** */
+                //select  place from biz_daywork_item where deleted =0 and daywork_id = #{id} and status =7 order by create_time desc limit 1
+                tempDayworkItems.stream()
+                        .filter(di -> Integer.parseInt(di.getStatus()) == 7)
+                        .max(Comparator.comparing(BizDayworkItem::getCreateTime))
+                        .ifPresent(tempDayworkItem -> daywork.setPlace(tempDayworkItem.getPlace()));
+
+                /* ************************** 以下是为了获得到上一道工序 ************************** */
+                //获得该批的工序
+                //如果该批是废品回用
+                if (daywork.getIsAmend() == 1 || daywork.getIsWasteRecycling() == 1) {
+                    //如果是废品回用,则它的工序从biz_technology_waste_recycling表查
+                    //拿到对应工艺id
+                    //废品回用的工序
+                    List<BizLotTechnologicalProcessDetail> lotTechnologicalDetails = allLotTechnologicalDetails.stream()
+                            .filter(twrd -> twrd.getLotTechnologicalProcessId().equals(daywork.getTechnologicalProcessId()))
+                            .collect(Collectors.toList());
+                    // 将符合条件的所有工序清单中的工序id(process_id),整合到一个List集合中
+                    processIds = lotTechnologicalDetails.stream()
+                            .map(BizLotTechnologicalProcessDetail::getProcessId)
+                            .collect(Collectors.toList());
+                    List<Long> tempProcessIds = processIds;
+                    // 根据得到的工序id集合,获得相对应的工序集合
+                    technologicalDetailList = allLotTechnologicalDetails.stream().filter(ap -> daywork.getTechnologicalProcessId().equals(ap.getLotTechnologicalProcessId()) && tempProcessIds.contains(ap.getProcessId())).collect(Collectors.toList());
+                }
+                // daywork_item的status > 4,表示已经离开当前工段,至少是周转中的状态
+                List<BizDayworkItem> finishedTempDayworkItems = tempDayworkItems.stream()
+                        .filter(di -> Integer.parseInt(di.getStatus()) > 4)
+                        .sorted(Comparator.comparing(BizDayworkItem::getCreateTime).reversed())
+                        .collect(Collectors.toList());
+                if (!finishedTempDayworkItems.isEmpty()) {
+                    BizProcess prevProcess = new BizProcess();
+                    if (daywork.getIsAmend() == 1 || daywork.getIsWasteRecycling() == 1) {
+                        BizLotTechnologicalProcessDetail technologicalDetail = technologicalDetailList.stream()
+                                // 通过get(0)的方式,获得最新的一条报工记录
+                                .filter(tp -> tp.getProcessStepNumber().equals(finishedTempDayworkItems.get(0).getProcessStepNumber()))
+                                .findFirst().orElse(null);
+                        if (technologicalDetail != null) {
+                            prevProcess.setId(technologicalDetail.getProcessId());
+                            prevProcess.setProcessAlias(technologicalDetail.getProcessAlias());
+                            prevProcess.setProcessCode(technologicalDetail.getProcessCode());
+                            prevProcess.setProcessStepNumber(technologicalDetail.getProcessStepNumber());
+                        }
+                    } else {
+                        BizTechnologicalProcessDetail technologicalProcessDetail = processList.stream()
+                                // 通过get(0)的方式,获得最新的一条报工记录
+                                .filter(tp -> tp.getProcessStepNumber().equals(finishedTempDayworkItems.get(0).getProcessStepNumber()))
+                                .findFirst().orElse(null);
+                        if (technologicalProcessDetail != null) {
+                            prevProcess.setId(technologicalProcessDetail.getProcessId());
+                            prevProcess.setProcessAlias(technologicalProcessDetail.getProcessAlias());
+                            prevProcess.setProcessCode(technologicalProcessDetail.getProcessCode());
+                            prevProcess.setProcessStepNumber(technologicalProcessDetail.getProcessStepNumber());
+                        }
+                    }
+                    daywork.setPrevProcess(prevProcess);
+                }
+
+                /* ************************** 以下是为了获得当前 daywork 的当前工序 ************************** */
+                // 如果集合不为空,则获取最后一次报工,对应的工序
+                if (!tempDayworkItems.isEmpty()) {
+                    BizProcess tempProcess = new BizProcess();
+                    if (daywork.getIsAmend() == 1 || daywork.getIsWasteRecycling() == 1) {
+                        BizLotTechnologicalProcessDetail technologicalDetail = technologicalDetailList.stream()
+                                // 通过get(0)的方式,获得最新的一条报工记录
+                                .filter(tp -> tp.getProcessStepNumber().equals(tempDayworkItems.get(0).getProcessStepNumber()))
+                                .findFirst().orElse(null);
+                        if (technologicalDetail != null) {
+                            tempProcess.setId(technologicalDetail.getProcessId());
+                            tempProcess.setProcessAlias(technologicalDetail.getProcessAlias());
+                            tempProcess.setProcessCode(technologicalDetail.getProcessCode());
+                            tempProcess.setProcessStepNumber(technologicalDetail.getProcessStepNumber());
+                        }
+                    } else {
+                        BizTechnologicalProcessDetail technologicalProcessDetail = processList.stream()
+                                // 通过get(0)的方式,获得最新的一条报工记录
+                                .filter(tp -> tp.getTechnologicalProcessId().equals(tempDayworkItems.get(0).getTechnologicalProcessId()) && tp.getProcessStepNumber().equals(tempDayworkItems.get(0).getProcessStepNumber()))
+                                .findFirst().orElse(null);
+                        if (technologicalProcessDetail != null) {
+                            tempProcess.setId(technologicalProcessDetail.getProcessId());
+                            tempProcess.setProcessAlias(technologicalProcessDetail.getProcessAlias());
+                            tempProcess.setProcessCode(technologicalProcessDetail.getProcessCode());
+                            tempProcess.setProcessStepNumber(technologicalProcessDetail.getProcessStepNumber());
+                        }
+                    }
+                    // 最新的一条报工记录对应的工序,就是当前批次的当前工序
+                    daywork.setCurrentProcess(tempProcess);
+                }
 
-    /*
-    @Transactional
-    @GetMapping("/list")
-    public AjaxResult list(BizDaywork bizDaywork) {
-        List<BizDaywork>list = new ArrayList<>();
-        List<BizDaywork> dayworkList = bizDayworkService.getList(bizDaywork);
-        //查询当前工段工序
-        BizDeptProcess bizDeptProcess = new BizDeptProcess();
-        bizDeptProcess.setDeptId(bizDaywork.getDeptId());
-        List<BizDeptProcess> processList = bizDeptProcessService.getList(bizDeptProcess);
-        List<Long> ids = new ArrayList<>();
-        for (BizDeptProcess item: processList
-             ) {
-            ids.add(item.getProcessId());
-        }
-        for (BizDaywork daywork:dayworkList
-             ) {
-            //查询工段下工序有没有未周转的批次
-            List<BizDayworkItem> itemList = bizDayworkItemService.query().eq("deleted", 0).eq("daywork_id", daywork.getId()).in("process_id", ids).lt("status", 4).orderByDesc("create_time").list();
-            if (itemList.size()>0){
-                BizProcess processItem = bizProcessService.query().eq("id", itemList.get(itemList.size() - 1).getProcessId()).one();
-                daywork.setCurrentProcess(processItem);
-                //如果最新的item 只有一条 且状态是未开始,那么整个批次报工为未开始状态
-                if (daywork.getDayworkItemList().size() == 1 && daywork.getDayworkItemList().get(0).getStatus().equals("0")) {
-                    daywork.setStatus(0);
-                    //如果item有多条 且最新的一条状态为工序完成那么批次报工状态为待周转
-                } else if (daywork.getDayworkItemList().size() > 0 && daywork.getDayworkItemList().get(0).getStatus().equals("3")) {
-                    daywork.setStatus(2);
-                    //如果item有多条 且最新的一条状态为待周转那么批次报工状态为周转中
-                } else if (daywork.getDayworkItemList().size() > 0 && daywork.getDayworkItemList().get(0).getStatus().equals("4")) {
-                    daywork.setStatus(3);
-                    //判断item最新的一条是否为最后一道工序且工序已完成
-                } else if( daywork.getDayworkItemList().get(0).getStatus().equals("4") && daywork.getDayworkItemList().get(0).getProcessId().equals(daywork.getProcessSequence().get(daywork.getProcessSequence().size() - 1).getId())){
-                    daywork.setStatus(4);
-                }else {
-                    daywork.setStatus(1);
+                /* ************************** 以下是为了获得当前 daywork 的工艺工序清单 ************************** */
+                List<BizTechnologicalProcessDetail> currentDayworkProcessDetails = new ArrayList<>();
+                List<BizLotTechnologicalProcessDetail> currentLotDayworkDetails = new ArrayList<>();
+                //该批是废品回用
+                if (daywork.getIsAmend() == 1 || daywork.getIsWasteRecycling() == 1) {
+                    //如果是废品回用,则它的工序从biz_technology_waste_recycling表查
+                    //拿到对应工艺id
+                    //废品回用的工序(正序排列
+                    currentLotDayworkDetails = allLotTechnologicalDetails.stream()
+                            .filter(twrd -> twrd.getLotTechnologicalProcessId().equals(daywork.getTechnologicalProcessId()))
+                            .sorted(Comparator.comparing((BizLotTechnologicalProcessDetail::getProcessStepNumber)))
+                            .collect(Collectors.toList());
+                } else {
+                    // 将上面获得到的工艺数据,通过当前工艺主表的id,获得到当前的工艺列表,并根据工序序号,进行正序排列
+                    currentDayworkProcessDetails = technologicalProcessDetails.stream()
+                            .filter(pd -> pd.getTechnologicalProcessId().equals(daywork.getTechnologicalProcessId()) && pd.getTenantId() != 9)
+                            .sorted(Comparator.comparing((BizTechnologicalProcessDetail::getProcessStepNumber)))
+                            .collect(Collectors.toList());
+                }
+
+                /* ************************** 以下是为了获得当前 daywork 的 processSequence ************************** */
+                List<BizProcess> processSequence = new ArrayList<>();
+                //废品回用
+                if (daywork.getIsAmend() == 1 || daywork.getIsWasteRecycling() == 1) {
+                    for (BizLotTechnologicalProcessDetail detail : currentLotDayworkDetails) {
+                        BizProcess newProcess = new BizProcess();
+                        newProcess.setId(detail.getProcessId());
+                        newProcess.setProcessCode(detail.getProcessCode());
+                        newProcess.setProcessAlias(detail.getProcessAlias());
+                        newProcess.setTechnologicalProcessDetailId(detail.getId());
+                        newProcess.setProcessStepNumber(detail.getProcessStepNumber());
+                        processSequence.add(newProcess);
+                    }
+                    daywork.setProcessSequence(processSequence);
+                } else {
+                    for (BizTechnologicalProcessDetail detail : currentDayworkProcessDetails) {
+                        BizProcess newProcess = new BizProcess();
+                        newProcess.setId(detail.getProcessId());
+                        newProcess.setProcessCode(detail.getProcessCode());
+                        newProcess.setProcessAlias(detail.getProcessAlias());
+                        newProcess.setProcessStepNumber(detail.getProcessStepNumber());
+                        newProcess.setTechnologicalProcessDetailId(detail.getId());
+                        processSequence.add(newProcess);
+                    }
+                    daywork.setProcessSequence(processSequence);
+                }
+                /* ************************** 以下是为了获得当前登录这资源组信息,判断邀请报工 ************************** */
+                if (!sysUsers.isEmpty()) {
+                    List<BizProductionResourceGroupDetail> protemDetailList = protemResourceGroupDetail.stream().filter(item -> item.getProtemDayworkId().equals(daywork.getId())).collect(Collectors.toList());
+                    protemDetailList.forEach(item -> {
+                        item.setProtemCreatorName(sysUsers.stream().filter(label -> label.getUserId().equals(item.getCreatorId())).collect(Collectors.toList()).get(0).getNickName());
+                    });
+                    daywork.setProtemResourceGroupDetailList(protemDetailList);
+                }
+
+                /* ************************** 以下是为了获得当前 daywork 的下一道工序 ************************** */
+                // 判断当前工段
+                if (daywork.getCurrentProcess() != null) {
+                    //废品回用
+                    if (daywork.getIsAmend() == 1 || daywork.getIsWasteRecycling() == 1) {
+                        for (int i = 0; i < currentLotDayworkDetails.size(); i++) {
+                            if ((currentLotDayworkDetails.get(i).getProcessId().equals(daywork.getCurrentProcess().getId())
+                                    && currentLotDayworkDetails.get(i).getProcessStepNumber().equals(daywork.getCurrentProcess().getProcessStepNumber()))
+                                    && (i + 1) < currentLotDayworkDetails.size()) {
+                                // 根据工艺单查询下一道工序
+                                BizLotTechnologicalProcessDetail tempDetail = currentLotDayworkDetails.get(i + 1);
+                                BizProcess nextProcess = new BizProcess();
+                                nextProcess.setId(tempDetail.getProcessId());
+                                nextProcess.setProcessCode(tempDetail.getProcessCode());
+                                nextProcess.setProcessAlias(tempDetail.getProcessAlias());
+                                nextProcess.setProcessStepNumber(tempDetail.getProcessStepNumber());
+                                daywork.setNextProcess(nextProcess);
+                                // 先给一个默认的下道序
+                                daywork.setNextDeptProcess(daywork.getNextProcess().getProcessAlias());
+                            }
+                        }
+                    } else {
+                        for (int i = 0; i < currentDayworkProcessDetails.size(); i++) {
+                            if (currentDayworkProcessDetails.get(i).getProcessId().equals(daywork.getCurrentProcess().getId())
+                                    &&
+                                    (i + 1) < currentDayworkProcessDetails.size()) {
+                                // 根据工艺单查询下一道工序
+                                BizTechnologicalProcessDetail tempDetail = currentDayworkProcessDetails.get(i + 1);
+                                BizProcess nextProcess = new BizProcess();
+                                nextProcess.setId(tempDetail.getProcessId());
+                                nextProcess.setProcessCode(tempDetail.getProcessCode());
+                                nextProcess.setProcessAlias(tempDetail.getProcessAlias());
+                                nextProcess.setProcessStepNumber(tempDetail.getProcessStepNumber());
+                                daywork.setNextProcess(nextProcess);
+                                // 先给一个默认的下道序
+                                daywork.setNextDeptProcess(daywork.getNextProcess().getProcessAlias());
+                            }
+                        }
+                    }
+                }
+
+                /* ************************** 以下是为了获得当前 daywork 的状态,用于前端显示 ************************** */
+                //查询工段下工序有没有未周转的批次
+                if (!daywork.getDayworkItemList().isEmpty()) {
+                    boolean foundStatus3 = false;
+                    boolean foundStatus2 = false;
+                    boolean foundStatus1 = false;
+
+                    for (BizDayworkItem item : daywork.getDayworkItemList()) {
+                        if (daywork.getCurrentProcess() != null && item.getProcessStepNumber().equals(daywork.getCurrentProcess().getProcessStepNumber())) {
+                            // 最后一道工序的工序步骤序号
+                            String lastProcessStepNumber = "";
+                            if (daywork.getIsAmend() == 1 || daywork.getIsWasteRecycling() == 1) {
+                                lastProcessStepNumber = currentLotDayworkDetails.get(currentLotDayworkDetails.size() - 1).getProcessStepNumber();
+                            } else {
+                                lastProcessStepNumber = currentDayworkProcessDetails.get(currentDayworkProcessDetails.size() - 1).getProcessStepNumber();
+                            }
+                            // 如果工序为工艺最后一道工序且工序完成 ,那么状态为4 工序完成
+                            if ("3".equals(item.getStatus()) && item.getProcessStepNumber().equals(lastProcessStepNumber)) {
+                                daywork.setStatus(4);
+                                break;
+                            }
+                            //如果item状态为待周转那么批次报工状态为周转中
+                            else if ("4".equals(item.getStatus())) {
+                                daywork.setStatus(3);
+                                foundStatus3 = true;
+                            }
+                            //如果item状态为3待周转那么批次报工状态为待周转
+                            else if ("3".equals(item.getStatus()) && !foundStatus3) {
+                                daywork.setStatus(2);
+                                foundStatus2 = true;
+                            }
+                            //如果item状态为1,2进行中那么批次报工状态为进行中
+                            else if (("1".equals(item.getStatus()) || "2".equals(item.getStatus())) && !foundStatus3 && !foundStatus2) {
+                                daywork.setStatus(1);
+                                foundStatus1 = true;
+                            }
+                        }
+
+                        if (!foundStatus3 && !foundStatus2 && !foundStatus1) {
+                            // 如果最新的 item 只有一条且状态是未开始,那么整个批次报工为未开始状态
+                            if (daywork.getDayworkItemList().size() == 1 && daywork.getDayworkItemList().get(0).getStatus().equals("0")) {
+                                daywork.setStatus(0);
+                            }
+                        }
+                    }
                 }
             }
-            list.add(daywork);
         }
-
-        return success(list);
+        return success(dayworkList);
     }
-     */
-
-    /**
-     * 查询报工列表
-     */
     @Transactional
-    @GetMapping("/list")
+    @GetMapping("/innerList")
     @Log(title = "获取报工列表", businessType = BusinessType.SELECT)
-    public AjaxResult list(BizDaywork bizDaywork) {
+    public AjaxResult innerList(BizDaywork bizDaywork) {
         SysUser user = SecurityUtils.getLoginUser().getUser();
         Long userId = user.getUserId();
         Long productionPlanDetailId = bizDaywork.getProductionPlanDetailId();
@@ -203,7 +688,18 @@ public class BizDayworkController extends BaseController {
             List<Long> allLotsIdList = dayworks.stream().map(BizDaywork::getLotId).collect(Collectors.toList());
             lotList = bizLotService.query().in("id", allLotsIdList.isEmpty() ? Collections.singletonList(0L) : dayworks.stream().map(BizDaywork::getLotId).collect(Collectors.toList())).list();
         }
-
+        List<Long> outsourceOrderDetailIds = new ArrayList<>();
+        for (BizDaywork item : dayworks) {
+                BizDayworkItem lastDayworkItem = allDayworkItems.stream().filter(v -> v.getDayworkId().equals(item.getId()))
+                        .sorted(Comparator.comparing(BizDayworkItem::getProcessStepNumber).reversed())
+                        .sorted(Comparator.comparing(BizDayworkItem::getCreateTime).reversed())
+                        .findFirst().orElse(new BizDayworkItem());
+                outsourceOrderDetailIds.add(lastDayworkItem.getOutsourceDetailId());
+            };
+        //收回单明细
+        List<BizReturnReceiptDetail> returnReceiptDetailList = bizReturnReceiptDetailService.query().in("outsource_detail_id", outsourceOrderDetailIds).list();
+        //发出单工序
+        List<BizOutsourcedOrderDetailProcess> outsourcedDetailProcessList = bizOutsourcedOrderDetailProcessService.query().in("detail_id", outsourceOrderDetailIds).list();
         // 定义一个daywork空的list集合,用于存储符合条件(根据daywork的id,获得到对应的最新一条daywork_item,当该条daywork_item的状态值 < 5时,则添加)的daywork
         List<BizDaywork> dayworkList = new ArrayList<>();
         // 对之前获取到的 daywork 集合进行过滤,将符合条件的daywork,添加到dayworkList集合中
@@ -212,6 +708,12 @@ public class BizDayworkController extends BaseController {
                 //设置尾批量
                 item.setLastLotQuantity(planDetailslanDetails.stream().filter(v -> v.getId().equals(item.getProductionPlanDetailId())).collect(Collectors.toList()).get(0).getLastLotQuantity());
             }
+            //如果内部外协有收回单,则不展示
+            BizDayworkItem lastDayworkItem = allDayworkItems.stream().filter(v -> v.getDayworkId().equals(item.getId()))
+                    .sorted(Comparator.comparing(BizDayworkItem::getProcessStepNumber).reversed())
+                    .sorted(Comparator.comparing(BizDayworkItem::getCreateTime).reversed())
+                    .findFirst().orElse(new BizDayworkItem());
+            List<BizReturnReceiptDetail> returnReceiptDetail = returnReceiptDetailList.stream().filter(v -> v.getOutsourceDetailId().equals(lastDayworkItem.getOutsourceDetailId())).collect(Collectors.toList());
             //添加批次单批量
             item.setOneLotQuantity(lotList.stream().filter(v -> v.getId().equals(item.getLotId())).collect(Collectors.toList()).get(0).getProductionQuantity());
             //拿到批次是否批废信息
@@ -248,7 +750,7 @@ public class BizDayworkController extends BaseController {
             // 状态 == 5 时,说明已经进入周转中,那么该条daywork,将不再页面中显示,所以,通过对status的值的判断,添加到daywork集合中
             // 最后一条非周转报工的工段为当前工段。
             //20240806添加isSpecial!=1将最新一条报工为特殊报工的批次删除
-            if (!latestNoTurnover.getIsSpecial().equals(1) && latestNoTurnover.getDeptId().equals(deptId) && Integer.parseInt(status) < 5 && latestProcess != null) {
+            if (!latestNoTurnover.getIsSpecial().equals(1) && latestNoTurnover.getDeptId().equals(deptId) && Integer.parseInt(status) < 5 && latestProcess != null && returnReceiptDetail.size() == 0) {
                 // 获取当前操作者自己的报工记录
                 List<BizDayworkItem> currentMyDayworkItems = myDayworkItems.stream()
                         .filter(di -> di.getDayworkId().equals(item.getId()))
@@ -260,6 +762,7 @@ public class BizDayworkController extends BaseController {
             }
         }
 
+
         // 如果有报工数据
         if (!dayworkList.isEmpty()) {
             // 将符合条件(需要在页面展示的daywork)的 dayworkList 中的 technologicalProcessId,整合到一个List集合中,需要根据这些technologicalProcessId,获取到相应的工艺工序清单
@@ -573,6 +1076,12 @@ public class BizDayworkController extends BaseController {
                     boolean foundStatus3 = false;
                     boolean foundStatus2 = false;
                     boolean foundStatus1 = false;
+                    daywork.setHasFinishOutsource(false);
+                    //如果干完了发往外协的序,则不显示申请周转按钮
+                    BizOutsourcedOrderDetailProcess lastOutsourcedOrderDetailProcess = outsourcedDetailProcessList.stream().filter(v -> v.getDayworkId().equals(daywork.getId())).sorted(Comparator.comparing(BizOutsourcedOrderDetailProcess::getProcessStepNumber).reversed()).findFirst().orElse(null);
+                    if(daywork.getDayworkItemList().get(0).getProcessStepNumber().equals(lastOutsourcedOrderDetailProcess.getProcessStepNumber()) && daywork.getDayworkItemList().get(0).getStatus().equals("3")){
+                        daywork.setHasFinishOutsource(true);
+                    }
 
                     for (BizDayworkItem item : daywork.getDayworkItemList()) {
                         if (daywork.getCurrentProcess() != null && item.getProcessStepNumber().equals(daywork.getCurrentProcess().getProcessStepNumber())) {
@@ -1233,6 +1742,7 @@ public class BizDayworkController extends BaseController {
         }
     }
 
+
     /**
      * 非首序扫码添加批次
      */
@@ -1327,6 +1837,61 @@ public class BizDayworkController extends BaseController {
 
         return toAjax((updates.isEmpty() || bizDayworkItemService.updateBatchById(updates)) && (updateDaywork.isEmpty() || bizDayworkService.updateBatchById(updateDaywork)) && bizDayworkItemService.saveBatch(adds));
     }
+    @Log(title = "保存信息报工", businessType = BusinessType.INSERT)
+    @Transactional
+    @PostMapping("/showDayworkInnerSave")
+    public AjaxResult addNewInnerDayworkItem(@RequestBody List<BizDayworkItem> dayworkItemList) {
+        // 新建报工明细
+        List<BizDayworkItem> adds = new ArrayList<>();
+        //dayworkID的所有报工
+        List<BizDayworkItem> dayworkItemList1 = bizDayworkItemService.query().in("daywork_id", dayworkItemList.stream().map(BizDayworkItem::getDayworkId).collect(Collectors.toList())).list();
+        // 更新报工明细
+        List<BizDayworkItem> updates = new ArrayList<>();
+        // 更新报工
+        List<BizDaywork> updateDaywork = new ArrayList<>();
+        dayworkItemList.forEach(l -> {
+            l.getDaywork().setProcessQualifiedNum(l.getDaywork().getTemporaryProcessQualifiedNum());
+            if (l.getStatus().equals("4")) {
+                l.setStatus("7");
+                updates.add(l);
+                l.getDaywork().setDeptId(l.getDeptId());
+            }
+            if (l.getStatus().equals("7")) {
+                BizDaywork daywork = l.getDaywork();
+                daywork.setProtemProcessId(l.getProcessId());
+                daywork.setProtemProcessStepNumber(l.getProcessStepNumber());
+                // 如果被邀请人不是本工段内的人,则需要从当前资源组中删除被邀请人
+                bizProductionResourceGroupDetailService.deleTemporanyPeople(daywork);
+            }
+            updateDaywork.add(l.getDaywork());
+
+            BizDayworkItem bizDayworkItem = new BizDayworkItem();
+            bizDayworkItem.setDayworkId(l.getDayworkId());
+            ;
+            if (l.getDaywork().getIsAmend() == 1) {
+                bizDayworkItem.setFormDayworkItemId(1L);
+            }
+            bizDayworkItem.setProcessStepNumber(l.getDaywork().getProcessStepNumber());
+            bizDayworkItem.setProductionPlanDetailId(l.getProductionPlanDetailId());
+            bizDayworkItem.setTechnologicalProcessId(l.getDaywork().getTechnologicalProcessId());
+            SysUser user = SecurityUtils.getLoginUser().getUser();
+            bizDayworkItem.setUserId(user.getUserId());
+            bizDayworkItem.setUserName(user.getUserName());
+            bizDayworkItem.setProdNum(l.getDaywork().getTemporaryProcessQualifiedNum());
+            bizDayworkItem.setNickName(user.getNickName());
+            // 0114 这里要把前段显示的item的processId传进来
+            bizDayworkItem.setProcessId(l.getDaywork().getProcessId());
+            bizDayworkItem.setTechnologicalProcessDetailId(l.getDaywork().getTechnologicalProcessDetailId());
+            bizDayworkItem.setDeptId(l.getDeptId());
+            bizDayworkItem.setIsSort(l.getIsSort());
+            bizDayworkItem.setDeptName(l.getDeptName());
+            bizDayworkItem.setLotId(l.getDaywork().getLotId());
+            bizDayworkItem.setOutsourceDetailId(l.getOutsourceDetailId());
+            adds.add(bizDayworkItem);
+        });
+
+        return toAjax((updates.isEmpty() || bizDayworkItemService.updateBatchById(updates)) && (updateDaywork.isEmpty() || bizDayworkService.updateBatchById(updateDaywork)) && bizDayworkItemService.saveBatch(adds));
+    }
 
 
     /**

+ 351 - 1
src/main/java/cn/ezhizao/project/business/product/controller/BizDayworkItemController.java

@@ -10,6 +10,8 @@ import cn.ezhizao.framework.web.domain.AjaxResult;
 import cn.ezhizao.framework.web.page.TableDataInfo;
 import cn.ezhizao.project.business.deptProcess.domain.BizDeptProcess;
 import cn.ezhizao.project.business.deptProcess.service.IBizDeptProcessService;
+import cn.ezhizao.project.business.outsource.domain.BizOutsourcedOrderDetailProcess;
+import cn.ezhizao.project.business.outsource.service.IBizOutsourcedOrderDetailProcessService;
 import cn.ezhizao.project.business.process.domain.BizProcess;
 import cn.ezhizao.project.business.process.service.IBizProcessService;
 import cn.ezhizao.project.business.product.domain.*;
@@ -40,6 +42,7 @@ import org.springframework.web.server.ServerErrorException;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -108,6 +111,8 @@ public class BizDayworkItemController extends BaseController {
     private IBizDayworkItemExamineService bizDayworkItemExamineService;
     @Resource
     private IBizTakeStockPeriodService bizTakeStockPeriodService;
+    @Resource
+    private IBizOutsourcedOrderDetailProcessService bizOutsourcedOrderDetailProcessService;
     /**
      * 查询报工记录列表
      */
@@ -762,6 +767,195 @@ public class BizDayworkItemController extends BaseController {
 
 
 
+        // 自动派活
+        SysDept sysDept = sysDeptMapper.selectDeptById(bizDayworkItem.getDeptId());
+        if (sysDept.getAutoAllocation() == 1) {
+            // 查资源组
+            List<BizProductionResourceGroup> productionResourceGroupList = bizProductionResourceGroupService.list(new QueryWrapper<BizProductionResourceGroup>().eq("dept_id", bizDayworkItem.getDeptId()));
+
+            //查询是否已经分配资源组
+            BizProductionResourceGroupSubPlan groupSubPlan=new BizProductionResourceGroupSubPlan();
+            groupSubPlan.setDeptId(bizDayworkItem.getDeptId());
+            groupSubPlan.setProductionPlanDetailId(bizDayworkItem.getProductionPlanDetailId());
+            List<BizProductionResourceGroupSubPlan> groupSubPlanList = bizProductionResourceGroupSubPlanService.getList(groupSubPlan);
+            //如果没分配
+            if(groupSubPlanList.isEmpty()){
+                //查产品id
+                BizProductionPlanDetail productionPlanDetail = bizProductionPlanDetailService.getOne(new QueryWrapper<BizProductionPlanDetail>().eq("id", bizDayworkItem.getProductionPlanDetailId()));
+                //存放保存的subPlanList
+                List<BizProductionResourceGroupSubPlan> subPlanList = new ArrayList<>();
+                for (BizProductionResourceGroup info : productionResourceGroupList) {
+                    BizProductionResourceGroupSubPlan subPlan = new BizProductionResourceGroupSubPlan();
+                    subPlan.setProductId(productionPlanDetail.getProductId());
+                    subPlan.setProductionPlanDetailId(bizDayworkItem.getProductionPlanDetailId());
+                    subPlan.setTechnologicalProcessId(bizDayworkItem.getTechnologicalProcessId());
+                    subPlan.setResourceGroupId(info.getId());
+                    subPlan.setDeptId(bizDayworkItem.getDeptId());
+                    subPlan.setResourceGroupCode(info.getCode());
+                    subPlanList.add(subPlan);
+                }
+                bizProductionResourceGroupSubPlanService.saveBatch(subPlanList);
+            }
+
+        }
+        bizDayworkItemRejectService.saveBatch(bizDayworkItem.getRejectList());
+        return toAjax(batch);
+
+    }
+    @Log(title = "新增报工记录", businessType = BusinessType.INSERT)
+    @Transactional
+    @PostMapping("/saveInnerDayworkItem")
+    public AjaxResult saveInnerDayworkItem(@RequestBody BizDayworkItem bizDayworkItem) throws NoSuchFieldException, IllegalAccessException {
+        /** 如果是已完成工序,生成一条空报工记录保存下一道工序 */
+        BizDaywork daywork = new BizDaywork();
+        daywork.setId(bizDayworkItem.getDayworkId());
+
+        List<BizDaywork> list = bizDayworkService.getList(daywork);
+        daywork = list.get(0);
+
+        //如果是修改工单,则获取该工单工序
+        if(daywork.getIsAmend()==1 || daywork.getIsWasteRecycling()==1){
+            List<BizProcess> processList=new ArrayList<>();
+            List<BizLotTechnologicalProcessDetail> bizLotTechnologicalProcessDetail = bizLotTechnologicalProcessDetailService.query().eq("lot_technological_process_id", daywork.getTechnologicalProcessId()).list();
+            bizLotTechnologicalProcessDetail.forEach(item->{
+                BizProcess itemProcess = new BizProcess();
+                itemProcess.setProcessCode(item.getProcessCode());
+                itemProcess.setProcessAlias(item.getProcessAlias());
+                itemProcess.setProcessStepNumber(item.getProcessStepNumber());
+                processList.add(itemProcess);
+            });
+            daywork.setProcessSequence(processList);
+        }else {
+            List<BizProcess> processList=new ArrayList<>();
+            List<BizTechnologicalProcessDetail> bizTechnologicalProcessDetail = bizTechnologicalProcessDetailService.query().eq("technological_process_id", daywork.getTechnologicalProcessId()).ne("tenant_id",9).list();
+            bizTechnologicalProcessDetail.forEach(item->{
+                BizProcess itemProcess = new BizProcess();
+                itemProcess.setProcessCode(item.getProcessCode());
+                itemProcess.setProcessAlias(item.getProcessAlias());
+                itemProcess.setProcessStepNumber(item.getProcessStepNumber());
+                processList.add(itemProcess);
+            });
+            daywork.setProcessSequence(processList);
+        }
+
+        if(daywork.getIsAmend()==1){
+            bizDayworkItem.setFormDayworkItemId(1L);
+        }
+        //并且计算该报工批次的当前工序下的合格数总量
+        BizDayworkItem bizItem = new BizDayworkItem();
+        bizItem.setDayworkId(bizDayworkItem.getDayworkId());
+        bizItem.setProcessId(bizDayworkItem.getProcessId());
+        bizItem.setTechnologicalProcessDetailId(bizDayworkItem.getTechnologicalProcessDetailId());
+        List<BizDayworkItem> itemList = bizDayworkItemService.getList(bizItem);
+        //获取当前工序下的总合格数
+        Integer lot = 0;
+        //如果非手续
+        if (bizDayworkItem.getQualifiedNum() != null) {
+            lot = bizDayworkItem.getQualifiedNum();
+        }
+        for (BizDayworkItem dayworkItem : itemList) {
+            lot += dayworkItem.getQualifiedNum();
+        }
+        // 结束报工校验
+        //如果是手续(上一道序的合格数是0)校验报工批次的单批数
+        if ((bizDayworkItem.getStatus().equals("2") || bizDayworkItem.getStatus().equals("3")) && !bizDayworkItem.getIsPreProcess()) {
+            if (daywork.getProcessQualifiedNum() == 0) {
+                if (lot > (daywork.getOneLotQuantity() * 1.03)) {
+                    return error("该批次合格数已超投入数上限(103%)");
+                }
+            } else {
+                if (lot > (daywork.getProcessQualifiedNum() * 1.03)) {
+                    return error("该批次合格数已超投入数上限(103%)");
+                }
+            }
+        }
+
+        // 已送达状态更改daywork的当前部门
+        if (bizDayworkItem.getStatus().equals("7")) {
+            daywork.setDeptId(bizDayworkItem.getDeptId());
+            daywork.setProcessQualifiedNum(daywork.getTemporaryProcessQualifiedNum());
+            daywork.setProtemProcessStepNumber(bizDayworkItem.getProcessStepNumber());
+            bizDayworkService.updateById(daywork);
+        }
+
+        if (bizDayworkItem.getStatus().equals("5")) {
+            daywork.setProcessQualifiedNum(daywork.getTemporaryProcessQualifiedNum());
+            bizDayworkService.updateById(daywork);
+            daywork.setProtemProcessStepNumber(bizDayworkItem.getProcessStepNumber());
+        }
+        /** 当最后一道序完成时,释放该批次下所有载具 */
+        if (bizDayworkItem.getStatus().equals("3")) {
+            //校验当前序是否还有未完成的报工
+            List<BizDayworkItem> items = bizDayworkItemService.query().eq("daywork_id", bizDayworkItem.getDayworkId()).eq("process_id", bizDayworkItem.getProcessId()).lt("status", 2).ne("id", bizDayworkItem.getId()).list();
+            if (!items.isEmpty()) {
+                return error("当前工序还有其他未完成的报工,不允许工序完成");
+            }
+            //工序结束时将合格数保存
+            daywork.setProtemProcessId(bizDayworkItem.getProcessId());
+            //daywork.setTemporaryProcessQualifiedNum(lot);
+            // 此处在biz_daywork_qualified中间表中,插入一条数据
+            // 记录当前批次,当前工序的投入数、合格数
+
+
+            //判断当前序为最后一道序
+            if (bizDayworkItem.getProcessStepNumber().equals(daywork.getProcessSequence().get(daywork.getProcessSequence().size() - 1).getProcessStepNumber())) {
+                bizDayworkCarrierService.removeByDayworkId(daywork.getId());
+                //最后一道序的时候,把daywork表的status设置为2
+                daywork.setStatus(2);
+            }
+            bizDayworkService.updateById(daywork);
+            //修改发出单报工合格数,投产数及折损率
+            BizOutsourcedOrderDetailProcess outsourcedOrderDetailProcess = bizOutsourcedOrderDetailProcessService.query().eq("daywork_id", bizDayworkItem.getDayworkId()).eq("process_step_number", bizDayworkItem.getProcessStepNumber()).one();
+            outsourcedOrderDetailProcess.setProductionNum(bizDayworkItem.getProdNum());
+            List<BizDayworkItem> currentDayworkItem = bizDayworkItemService.query().eq("daywork_id", bizDayworkItem.getDayworkId()).eq("process_step_number", bizDayworkItem.getProcessStepNumber()).in("status", Arrays.asList("2", "3")).list();
+            int sum = currentDayworkItem.stream().mapToInt(BizDayworkItem::getQualifiedNum).sum() + bizDayworkItem.getQualifiedNum();
+            outsourcedOrderDetailProcess.setQualifiedNum(sum);
+            float percent = ((outsourcedOrderDetailProcess.getProductionNum() - outsourcedOrderDetailProcess.getQualifiedNum()) / (float) outsourcedOrderDetailProcess.getProductionNum()) * 100;
+            outsourcedOrderDetailProcess.setLoss(BigDecimal.valueOf(percent));
+            bizOutsourcedOrderDetailProcessService.updateById(outsourcedOrderDetailProcess);
+        }
+        //如果没有合格数,则投产数量为总数量,上道序的合格数为下到序的投产数
+        if (daywork.getProcessQualifiedNum() == 0) {
+            bizDayworkItem.setProdNum(daywork.getProductionQuantity());
+        } else {
+            bizDayworkItem.setProdNum(daywork.getProcessQualifiedNum());
+        }
+        // 现在等于4的时候就要能扫码开始批次,所以要设置一下部门pc查询计划单分配活
+//        if(bizDayworkItem.getStatus().equals("4")){
+//            daywork.setDeptId(bizDayworkItem.getDeptId());
+//            bizDayworkService.updateById(daywork);
+//        }
+        bizDayworkItem.setLotId(daywork.getLotId());
+        bizDayworkItem.setLotCode(daywork.getLotCode());
+        SysUser user = SecurityUtils.getLoginUser().getUser();
+        bizDayworkItem.setUserId(user.getUserId());
+        bizDayworkItem.setUserName(user.getUserName());
+        bizDayworkItem.setNickName(user.getNickName());
+        String[] statusArr = {"0", "4", "5", "7"};
+        if (Arrays.asList(statusArr).contains(bizDayworkItem.getStatus())) {
+            bizDayworkItem.setWorkingHours(0L);
+        } else {
+            bizDayworkItem.setWorkingHours(bizDayworkItem.getEndTime().getTime() - bizDayworkItem.getStartTime().getTime());
+        }
+        boolean batch = bizDayworkItemService.saveOrUpdate(bizDayworkItem);
+        //先保存item再保存废品原因
+        if ("2".equals(bizDayworkItem.getStatus()) || "3".equals(bizDayworkItem.getStatus())) {
+            for (BizDayworkItemReject item : bizDayworkItem.getRejectList()) {
+                item.setDayworkItemId(bizDayworkItem.getId());
+                item.setDayworkId(bizDayworkItem.getDayworkId());
+                item.setLotId(bizDayworkItem.getLotId());
+                item.setDeptId(bizDayworkItem.getDeptId());
+                item.setProcessId(bizDayworkItem.getProcessId());
+            }
+        }
+
+        //保存箱数
+        List<BizDayworkItem>bizDayworkItems =new ArrayList<>();
+        bizDayworkItems.add(bizDayworkItem);
+        bizDayworkItemService.saveCarrierNum(bizDayworkItems);
+
+
+
         // 自动派活
         SysDept sysDept = sysDeptMapper.selectDeptById(bizDayworkItem.getDeptId());
         if (sysDept.getAutoAllocation() == 1) {
@@ -1097,7 +1291,14 @@ public class BizDayworkItemController extends BaseController {
     public AjaxResult remove(@PathVariable List<Long> ids) {
         return toAjax(bizDayworkItemService.removeBatchByIds(ids));
     }
-   //修改周转信息
+    @PostMapping("/addEquipmentInfo")
+    @Log(title = "新增分选设备信息", businessType = BusinessType.SELECT)
+    public AjaxResult addEquipmentInfo(@RequestBody BizDayworkItem bizDayworkItem) {
+        bizDayworkItemService.updateById(bizDayworkItem);
+        return success();
+    }
+
+    //修改周转信息
     @Transactional
     @PutMapping("/updateTurnoverInfo")
     @Log(title = "修改周转信息", businessType = BusinessType.INSERT)
@@ -1411,5 +1612,154 @@ public class BizDayworkItemController extends BaseController {
         bizDayworkItemExamineService.saveBatch(needAddList);
         return toAjax(batch);
     }
+    @Log(title="内部外协周转申请")
+    @Transactional
+    @PostMapping("/turnoverInner")
+    public AjaxResult turnoverInner(@RequestBody BizDayworkItem bizDayworkItem) throws NoSuchFieldException,IllegalAccessException {
+        //判断当前是否在盘点
+        BizTakeStockPeriod bizTakeStockPeriod = bizTakeStockPeriodService.query().eq("status",1).one();
+        if(bizTakeStockPeriod!=null && bizTakeStockPeriod.getStatus() == 1) {
+            return error("当前在盘点,禁止投产");
+        }
+        // 设置工时
+        // 获取箱子关联的所有批次
+        boolean batch = true;
+//        bizDayworkItem.getCarrierId();
+        // 根据 daywork_item 中的 daywork_id,获取到所有未解绑的【daywork 与 箱子】的集合,通过这个集合,可以知道该批次下绑定了多少个箱子
+        List<BizDayworkCarrier> dayworkCarriers = bizDayworkCarrierService.query().eq("is_changed", 0).eq("process_inspection_id", 0L).eq("daywork_id", bizDayworkItem.getDayworkId()).list();
+        // 再根据上面获得到的数据,通过箱子的id(carrier_id),再进行查找,有多少个批次与该箱子绑定,这是因为存在一箱多批的情况。这样就获得到了所有的批次
+        List<BizDayworkCarrier> allCarries = bizDayworkCarrierService.query().eq("process_inspection_id", 0L).eq("is_changed", 0).in("carrier_id", dayworkCarriers.isEmpty() ? Collections.singletonList(0L) : dayworkCarriers.stream().map(BizDayworkCarrier::getCarrierId).collect(Collectors.toList())).list();
+
+        // 根据获取到的所有批次的id,查询出所有批次的报工信息,并且状态是【"0", "1", "2", "3"】,按状态值倒序、创建日期的倒序,对数据进行排序,得到的数据是还未周转的数据。
+        // 后续会通过该集合,获取某批次的最后一条报工信息
+        List<BizDayworkItem> bizDayworkItems = bizDayworkItemService.query().in("daywork_id", allCarries.isEmpty() ? Collections.singletonList(0L) : allCarries.stream().map(BizDayworkCarrier::getDayworkId).collect(Collectors.toList())).in("status", Arrays.asList("0", "1", "2", "3")).orderByDesc("status").orderByDesc("create_time").list();
+        List<BizDayworkItem> bizDayworkItemsAll = bizDayworkItemService.query().in("daywork_id", allCarries.isEmpty() ? Collections.singletonList(0L) : allCarries.stream().map(BizDayworkCarrier::getDayworkId).collect(Collectors.toList())).orderByDesc("create_time").list();
+        // 根据获取到的所有批次的id,查询出所有批次的报工信息,不需要判断状态
+        List<BizDayworkItem> bizDayworkItemList = bizDayworkItemService.query().in("daywork_id", allCarries.isEmpty() ? Collections.singletonList(0L) : allCarries.stream().map(BizDayworkCarrier::getDayworkId).collect(Collectors.toList())).list();
+        // 获取所有的 daywork 数据集合
+        List<BizDaywork> bizDayworks = bizDayworkService.query().in("id", allCarries.isEmpty() ? Collections.singletonList(0L) : allCarries.stream().map(BizDayworkCarrier::getDayworkId).collect(Collectors.toList())).list();
+        //获取周转工段的周转区
+        List<BizTurnover> turnoverList = bizTurnoverService.query().eq("dept_id", bizDayworkItem.getDeptId()).eq("status", 9).list();
+        // 遍历 daywork 数据集合
+        for (BizDaywork v : bizDayworks) {
+            // 获取该批次的最后一条报工
+            BizDayworkItem lastItem = bizDayworkItems.stream().filter(l -> l.getDayworkId().equals(v.getId())).findFirst().orElse(null);
+            //批次所有报工,判断是否已经周转了,如果周转返回报错信息
+            BizDayworkItem lastItemAll = bizDayworkItemsAll.stream().filter(l -> l.getDayworkId().equals(v.getId())).findFirst().orElse(null);
+            //为了防止该工序已经周转到下一道序,且已经干了,所以判断如果当前processStepNumber和最新一条的步骤是否相同
+            if(lastItemAll != null && (!lastItemAll.getProcessStepNumber().equals(bizDayworkItem.getProcessStepNumber()) || (lastItemAll.getStatus().equals("4") || lastItemAll.getStatus().equals("5") || lastItemAll.getStatus().equals("7")))) {
+                return error( v.getLotCode()+"批次已周转,请勿重复操作");
+            }
+            // 如果最后一条报工信息存在,并且报工状态为:3,则说明该报工已经工序完成
+            if (lastItem != null && lastItem.getStatus().equals("3")) {
+                // 根据当前批次的id,获取该批次下的工序id与最后一条报工的工序id相同的所有报工信息
+                // 因为同一工序可能存在多次报工,所以需要获取该批次下,该工序的所有报工信息,后续会进行合格数的统计
+                List<BizDayworkItem> allItem = bizDayworkItemList.stream().filter(l -> l.getDayworkId().equals(v.getId()) && l.getTechnologicalProcessDetailId().equals(lastItem.getTechnologicalProcessDetailId())).collect(Collectors.toList());
+                // 根据获得到的某工序的报工信息,进行合格数统计
+                Integer lot = allItem.stream().mapToInt(BizDayworkItem::getQualifiedNum).sum();
+
+                // 实例化一个报工信息对象,用于保存【周转】的报工记录
+                BizDayworkItem bizItem = new BizDayworkItem();
+                bizItem.setDayworkId(lastItem.getDayworkId());
+                bizItem.setProcessId(lastItem.getProcessId());
+                bizItem.setTechnologicalProcessDetailId(lastItem.getTechnologicalProcessDetailId());
+                bizItem.setStatus(bizDayworkItem.getStatus());
+                bizItem.setFromDeptId(lastItem.getDeptId());
+                bizItem.setFromDeptName(lastItem.getDeptName());
+                bizItem.setOutsourceDetailId(lastItem.getOutsourceDetailId());
+                // 如果报工状态为:7(已送达)或者4(待周转),则需要设置对应的daywork的当前部门id,以及合格数
+                // 这里的状态值4/7,是由前端传递过来的。
+                if (bizDayworkItem.getStatus().equals("7") || bizDayworkItem.getStatus().equals("4")) {
+                    v.setDeptId(bizDayworkItem.getDeptId());
+                    int sum = bizDayworkItems.stream()
+                            .filter(l -> l.getProcessStepNumber().equals(bizDayworkItem.getProcessStepNumber()))
+                            .mapToInt(BizDayworkItem::getQualifiedNum) // 假设 getNum 返回一个 int 类型的值
+                            .sum();
+                    v.setTemporaryProcessQualifiedNum(sum);
+                    bizDayworkService.updateById(v);
+                }
+                // 周转后如果是车间内的,状态为7,则需要从当前资源组中删除被邀请人
+                if(bizDayworkItem.getStatus().equals("7") || bizDayworkItem.getStatus().equals("5")) {
+                    v.setProtemProcessId(lastItem.getProcessId());
+                    v.setProtemProcessStepNumber(lastItem.getProcessStepNumber());
+                    // 如果被邀请人不是本工段内的人,则需要从当前资源组中删除被邀请人
+                    bizProductionResourceGroupDetailService.deleTemporanyPeople(v);
+                }
+                // 如果是单批单改换,则设置form_daywork_item_id为1,表示没有原来的报工
+                if(v.getIsAmend()==1){
+                    bizItem.setFormDayworkItemId(1L);
+                }
+                bizItem.setLotId(v.getLotId());
+                bizItem.setLotCode(v.getLotCode());
+                SysUser user = SecurityUtils.getLoginUser().getUser();
+                bizItem.setUserId(user.getUserId());
+                bizItem.setUserName(user.getUserName());
+                bizItem.setNickName(user.getNickName());
+                bizItem.setIsSpecial(lastItem.getIsSpecial());
+                bizItem.setSpecialIsFirst(lastItem.getSpecialIsFirst());
+                bizItem.setWorkingHours(0L);
+                bizItem.setDeptId(lastItem.getDeptId());
+                bizItem.setTenantId(lastItem.getTenantId());
+                bizItem.setProductionPlanDetailId(lastItem.getProductionPlanDetailId());
+                bizItem.setProductionPlanId(lastItem.getProductionPlanId());
+                bizItem.setProductionPlanDetailSubDetailId(lastItem.getProductionPlanDetailSubDetailId());
+                bizItem.setProductionPlanDetailSubDetailEquipmentId(lastItem.getProductionPlanDetailSubDetailEquipmentId());
+                bizItem.setQualifiedNum(lot);
+                bizItem.setTechnologicalProcessId(lastItem.getTechnologicalProcessId());
+                bizItem.setProdNum(lot);
+                bizItem.setEquipmentDetailId(lastItem.getEquipmentDetailId());
+                bizItem.setEquipmentDetailCode(lastItem.getEquipmentDetailCode());
+                bizItem.setDeptId(bizDayworkItem.getDeptId());
+                bizItem.setDeptName(bizDayworkItem.getDeptName());
+                bizItem.setStartTime(bizDayworkItem.getStartTime());
+                bizItem.setTurnoverId(bizDayworkItem.getTurnoverId());
+                bizItem.setTurnoverType(bizDayworkItem.getTurnoverType());
+                bizItem.setTurnoverArea(bizDayworkItem.getTurnoverArea());
+                if(bizDayworkItem.getPlaceId()==null){
+                    bizItem.setPlaceId(turnoverList.stream().map(BizTurnover::getId).map(String::valueOf).collect(Collectors.joining("、")));
+                    bizItem.setPlace(turnoverList.stream().map(BizTurnover::getCode).collect(Collectors.joining("、")));
+                }else{
+                    bizItem.setPlaceId(bizDayworkItem.getPlaceId());
+                    bizItem.setPlace(bizDayworkItem.getPlace());
+                }
+
+                bizItem.setProcessStepNumber(lastItem.getProcessStepNumber());
+                bizItem.setOutsourceDetailId(lastItem.getOutsourceDetailId());
+                batch = batch && bizDayworkItemService.saveOrUpdate(bizItem);
+                // 自动派活
+                SysDept sysDept = sysDeptMapper.selectDeptById(bizDayworkItem.getDeptId());
+                if (sysDept.getAutoAllocation() == 1) {
+                    // 查资源组
+                    List<BizProductionResourceGroup> productionResourceGroupList = bizProductionResourceGroupService.list(new QueryWrapper<BizProductionResourceGroup>().eq("dept_id", bizDayworkItem.getDeptId()).eq("is_deactivate", 0));
+
+                    //查询是否已经分配资源组
+                    BizProductionResourceGroupSubPlan groupSubPlan=new BizProductionResourceGroupSubPlan();
+                    groupSubPlan.setDeptId(bizDayworkItem.getDeptId());
+                    groupSubPlan.setProductionPlanDetailId(bizDayworkItem.getProductionPlanDetailId());
+
+                    List<BizProductionResourceGroupSubPlan> groupSubPlanList = bizProductionResourceGroupSubPlanService.getAotList(groupSubPlan);
+                    //如果没分配
+                    if(groupSubPlanList.isEmpty()){
+                        //查产品id
+                        BizProductionPlanDetail productionPlanDetail = bizProductionPlanDetailService.getOne(new QueryWrapper<BizProductionPlanDetail>().eq("id", bizDayworkItem.getProductionPlanDetailId()));
+                        //存放保存的subPlanList
+                        List<BizProductionResourceGroupSubPlan> subPlanList = new ArrayList<>();
+                        for (BizProductionResourceGroup info : productionResourceGroupList) {
+                            BizProductionResourceGroupSubPlan subPlan = new BizProductionResourceGroupSubPlan();
+                            subPlan.setProductId(productionPlanDetail.getProductId());
+                            subPlan.setProductionPlanDetailId(v.getProductionPlanDetailId());
+                            subPlan.setTechnologicalProcessId(v.getTechnologicalProcessId());
+                            subPlan.setResourceGroupId(info.getId());
+                            subPlan.setDeptId(bizDayworkItem.getDeptId());
+                            subPlan.setResourceGroupCode(info.getCode());
+                            subPlanList.add(subPlan);
+                        }
+                        bizProductionResourceGroupSubPlanService.saveBatch(subPlanList);
+                    }
+                }
+            }
+        }
+        return toAjax(batch);
+    }
 
 }

+ 20 - 3
src/main/java/cn/ezhizao/project/business/product/controller/BizLotController.java

@@ -10,9 +10,11 @@ import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
 import cn.ezhizao.framework.web.controller.BaseController;
 import cn.ezhizao.framework.web.domain.AjaxResult;
 import cn.ezhizao.framework.web.page.TableDataInfo;
-import cn.ezhizao.project.business.product.domain.BizLot;
-import cn.ezhizao.project.business.product.domain.BizLotTechnologicalProcess;
-import cn.ezhizao.project.business.product.domain.BizLotTechnologicalProcessDetail;
+import cn.ezhizao.project.business.outsource.domain.BizOutsourcedOrderDetail;
+import cn.ezhizao.project.business.outsource.domain.BizOutsourcedOrderDetailProcess;
+import cn.ezhizao.project.business.outsource.service.IBizOutsourcedOrderDetailProcessService;
+import cn.ezhizao.project.business.outsource.service.IBizOutsourcedOrderDetailService;
+import cn.ezhizao.project.business.product.domain.*;
 import cn.ezhizao.project.business.product.service.*;
 import cn.ezhizao.project.business.technologicalProcess.service.IBizTechnologicalProcessService;
 import cn.ezhizao.project.business.technologicalProcessDetail.domain.BizTechnologicalProcessDetail;
@@ -50,6 +52,12 @@ public class BizLotController extends BaseController {
     private IBizLotTechnologicalProcessDetailService bizLotTechnologicalProcessDetailService;
     @Resource
     private IBizLotTechnologicalProcessService bizLotTechnologicalProcessService;
+    @Resource
+    private IBizOutsourcedOrderDetailProcessService bizOutsourcedOrderDetailProcessService;
+    @Resource
+    private IBizOutsourcedOrderDetailService bizOutsourcedOrderDetailService;
+    @Resource
+    private IBizDayworkItemService bizDayworkItemService;
 
     /**
      * 查询批次号列表
@@ -103,6 +111,15 @@ public class BizLotController extends BaseController {
                 return success(bizTechnologicalProcessDetailService.list(wrapper));
             }
         }
+    @GetMapping("/getInnerNextProcess")
+    @Log(title = "查询批次对应工序", businessType = BusinessType.INSERT)
+    public AjaxResult getInnerNextProcess(BizDaywork daywork) throws NoSuchFieldException, IllegalAccessException {
+        BizOutsourcedOrderDetail outsourcedOrderDetail = bizOutsourcedOrderDetailService.query().eq("daywork_id", daywork.getId()).orderByDesc("create_time").list().get(0);
+        List<BizOutsourcedOrderDetailProcess> outsourcedOrderDetailProcessList = bizOutsourcedOrderDetailProcessService.query().eq("detail_id", outsourcedOrderDetail.getId()).orderByAsc("process_step_number").list();
+        BizDayworkItem lastDayworkItem = bizDayworkItemService.query().eq("daywork_id", daywork.getId()).orderByDesc("process_step_number").list().get(0);
+        BizOutsourcedOrderDetailProcess bizOutsourcedOrderDetailProcess = outsourcedOrderDetailProcessList.stream().filter(v -> v.getProcessStepNumber().compareTo(lastDayworkItem.getProcessStepNumber()) > 0).findFirst().orElse(new BizOutsourcedOrderDetailProcess());
+        return success(bizOutsourcedOrderDetailProcess);
+    }
 
 
     /**

+ 97 - 0
src/main/java/cn/ezhizao/project/business/product/controller/BizProductionPlanDetailController.java

@@ -8,6 +8,10 @@ import cn.ezhizao.framework.web.domain.AjaxResult;
 import cn.ezhizao.framework.web.page.TableDataInfo;
 import cn.ezhizao.project.business.carrierReject.domain.BizCarrierReject;
 import cn.ezhizao.project.business.carrierReject.service.IBizCarrierRejectService;
+import cn.ezhizao.project.business.outsource.domain.BizOutsourcedOrder;
+import cn.ezhizao.project.business.outsource.domain.BizOutsourcedOrderDetail;
+import cn.ezhizao.project.business.outsource.service.IBizOutsourcedOrderDetailService;
+import cn.ezhizao.project.business.outsource.service.IBizOutsourcedOrderService;
 import cn.ezhizao.project.business.product.domain.*;
 import cn.ezhizao.project.business.product.service.*;
 import cn.ezhizao.project.business.resourceGroup.domain.BizProductionResourceGroup;
@@ -16,6 +20,8 @@ import cn.ezhizao.project.business.resourceGroup.domain.BizProductionResourceGro
 import cn.ezhizao.project.business.resourceGroup.service.IBizProductionResourceGroupDetailService;
 import cn.ezhizao.project.business.resourceGroup.service.IBizProductionResourceGroupService;
 import cn.ezhizao.project.business.resourceGroup.service.IBizProductionResourceGroupSubPlanService;
+import cn.ezhizao.project.system.domain.SysDept;
+import cn.ezhizao.project.system.service.ISysDeptService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.transaction.annotation.Transactional;
@@ -58,6 +64,14 @@ public class BizProductionPlanDetailController extends BaseController {
     private IBizDayworkCarrierService bizDayworkCarrierService;
     @Resource
     private IBizDayworkService bizDayworkService;
+    @Resource
+    private IBizOutsourcedOrderDetailService bizOutsourcedOrderDetailService;
+    @Resource
+    private IBizReturnReceiptDetailService bizReturnReceiptDetailService;
+    @Resource
+    private IBizOutsourcedOrderService bizOutsourcedOrderService;
+    @Resource
+    private ISysDeptService sysDeptService;
 
 
 
@@ -198,6 +212,89 @@ public class BizProductionPlanDetailController extends BaseController {
 
         return success(list);
     }
+    @Transactional
+    @PostMapping("/innerList")
+    @Log(title = "查询生产计划明细列表", businessType = BusinessType.SELECT)
+    public AjaxResult innerList(@RequestBody BizProductionPlanDetail bizProductionPlanDetail) throws NoSuchFieldException, IllegalAccessException {
+
+        // 根据资源组id集合,获取到所有的资源组分配的生产计划(生产计划与资源组的中间表)的集合
+        List<BizProductionResourceGroupSubPlan> groupSubPlans = bizProductionResourceGroupSubPlanService.query()
+                .in("dept_id", bizProductionPlanDetail.getDeptId())
+                .eq("deleted",0)
+                .list();
+        if(groupSubPlans.isEmpty()){
+            return success();
+        }
+        /*
+         * 将上面的中间表的集合中的生产计划id取出来,存入一个List集合planDetailIds中
+         * 后面会根据planDetailIds,
+         */
+        List<Long> planDetailIds = groupSubPlans.stream()
+                .map(BizProductionResourceGroupSubPlan::getProductionPlanDetailId)
+                .collect(Collectors.toList());
+        if (planDetailIds.isEmpty()){
+            return null;
+        }
+        //去掉已完成的计划单
+        List<Long> detailIds = new ArrayList<>();
+        List<BizLot> bizLotList = bizLotService.query().in("production_plan_detail_id", planDetailIds).eq("deleted", 0).list();
+        List<BizDaywork> dayworkList = dayworkService.query().in("production_plan_detail_id", planDetailIds).eq("status", 2).list();
+        planDetailIds.forEach(id -> {
+            long lotCount = bizLotList.stream().filter(item -> item.getProductionPlanDetailId().equals(id)).count();
+            long dayworkCount = dayworkList.stream().filter(item -> item.getProductionPlanDetailId().equals(id)).count();
+            if(lotCount > dayworkCount) {
+                detailIds.add(id);
+            }
+        });
+        BizProductionPlanDetail detail = new BizProductionPlanDetail();
+        detail.setPlanDetailIds(detailIds);
+        detail.setKeywords(bizProductionPlanDetail.getKeywords());
+        List<BizProductionPlanDetail> list = bizProductionPlanDetailService.selectNotComplatedList(detail);
+
+        // 将获取到的ProductionPlanDetail集合的id提取到集合中
+        List<Long> tempPlanDetailIds = list.stream()
+                .map(BizProductionPlanDetail::getId)
+                .collect(Collectors.toList());
+
+        List<BizDaywork> allDayworks = dayworkService.query()
+                .in("production_plan_detail_id", tempPlanDetailIds.isEmpty()? Collections.singletonList(0L) :  list.stream()
+                        .map(BizProductionPlanDetail::getId)
+                        .collect(Collectors.toList()))
+                .eq("deleted",0)
+                .list();
+        //内部外协已经收回的批次,则不展示收回单
+            SysDept sysDept = sysDeptService.selectDeptById(bizProductionPlanDetail.getDeptId());
+                List<BizOutsourcedOrderDetail> outsourcedOrderDetailList = bizOutsourcedOrderDetailService.query()
+                        .in("production_plan_detail_id", tempPlanDetailIds.isEmpty() ? Collections.singletonList(0L):tempPlanDetailIds)
+                        .eq("supplier_id", sysDept.getSupplierId())
+                    .list();
+                List<BizReturnReceiptDetail> returnReceiptDetail = bizReturnReceiptDetailService.query()
+                        .in("outsource_detail_id", outsourcedOrderDetailList.isEmpty() ? Collections.singletonList(0L) : outsourcedOrderDetailList.stream().map(BizOutsourcedOrderDetail::getId).collect(Collectors.toList()))
+                        .list();
+                List<BizProductionPlanDetail> newList = new ArrayList<>();
+           for (BizProductionPlanDetail item: list){
+               List<BizOutsourcedOrderDetail> collect = outsourcedOrderDetailList.stream().filter(v -> v.getProductionPlanDetailId().equals(item.getId())).collect(Collectors.toList());
+               if(!collect.isEmpty()){
+                   //该计划单有发出单
+                  for(BizOutsourcedOrderDetail v:collect){
+                      if(!returnReceiptDetail.stream().filter(l-> l.getOutsourceDetailId().equals(v.getId())).collect(Collectors.toList()).isEmpty()){
+                          newList.add(item);
+                      }
+                  }
+               }else{
+                   newList.add(item);
+               }
+            }
+
+        for (BizProductionPlanDetail item: newList) {
+            List<BizDaywork> dayworks = allDayworks.stream()
+                    .filter(d -> d.getProductionPlanDetailId().equals(item.getId()))
+                    .collect(Collectors.toList());
+            item.setDayWorkList(dayworks);
+        }
+
+        return success(newList);
+    }
     @GetMapping("/selectByCarrierCode")
     @Log(title = "查询箱码对应报工", businessType = BusinessType.SELECT)
     public AjaxResult selectByCarrierCode(BizDaywork daywork) {

+ 190 - 0
src/main/java/cn/ezhizao/project/business/product/controller/SortDayworkController.java

@@ -12,6 +12,8 @@ import cn.ezhizao.project.business.inspection.domain.BizProductInspectionInstruc
 import cn.ezhizao.project.business.inspection.service.IBizInspectionCategoryService;
 import cn.ezhizao.project.business.inspection.service.IBizInspectionInstructionService;
 import cn.ezhizao.project.business.inspection.service.IBizProductInspectionInstructionService;
+import cn.ezhizao.project.business.outsource.domain.BizOutsourcedOrderDetailProcess;
+import cn.ezhizao.project.business.outsource.service.IBizOutsourcedOrderDetailProcessService;
 import cn.ezhizao.project.business.packageResourceGroup.domain.BizPackageResourceGroupDetail;
 import cn.ezhizao.project.business.packageResourceGroup.service.IBizPackageResourceGroupDetailService;
 import cn.ezhizao.project.business.process.domain.BizProcess;
@@ -36,6 +38,7 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import javax.management.Query;
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -89,6 +92,8 @@ public class SortDayworkController extends BaseController {
     private IBizInspectionCategoryService bizInspectionCategoryService;
     @Resource
     private IBizTechnologicalProcessDetailDrawingService bizTechnologicalProcessDetailDrawingService;
+    @Resource
+    private IBizOutsourcedOrderDetailProcessService bizOutsourcedOrderDetailProcessService;
     // 修改报工状态为开始
     @PostMapping("/start")
     @Transactional
@@ -405,6 +410,110 @@ public class SortDayworkController extends BaseController {
             }
         return result ? success() : error("结束失败");
     }
+    @PostMapping("finishInner")
+    @Log(title = "结束分选外协报工", businessType = BusinessType.SELECT)
+    @Transactional(rollbackFor = Exception.class)
+    public AjaxResult finishInner(@RequestBody BizDayworkItem bizDayworkItem) {
+        //修改发出单报工合格数,投产数及折损率
+        BizOutsourcedOrderDetailProcess outsourcedOrderDetailProcess = bizOutsourcedOrderDetailProcessService.query().eq("daywork_id", bizDayworkItem.getDayworkId()).eq("process_step_number", bizDayworkItem.getProcessStepNumber()).one();
+        outsourcedOrderDetailProcess.setProductionNum(bizDayworkItem.getProdNum());
+        outsourcedOrderDetailProcess.setQualifiedNum(bizDayworkItem.getQualifiedNum());
+        float percent = ((outsourcedOrderDetailProcess.getProductionNum() - outsourcedOrderDetailProcess.getQualifiedNum()) / (float) outsourcedOrderDetailProcess.getProductionNum()) * 100;
+        outsourcedOrderDetailProcess.setLoss(BigDecimal.valueOf(percent));
+        bizOutsourcedOrderDetailProcessService.updateById(outsourcedOrderDetailProcess);
+        BizDayworkItem item = bizDayworkItemService.getById(bizDayworkItem.getId());
+        BizDayworkItemReject delCondition = new BizDayworkItemReject();
+        delCondition.setDayworkItemId(item.getId());
+        bizDayworkItemRejectService.physicalDelete(delCondition);
+        List<BizDayworkItemReject> rejectList = bizDayworkItem.getRejectList();
+        rejectList.forEach(l -> {
+            l.setDayworkId(item.getDayworkId());
+            l.setDayworkItemId(item.getId());
+            l.setLotId(item.getLotId());
+            l.setUserId(item.getUserId());
+            l.setProductionPlanDetailId(item.getProductionPlanDetailId());
+            l.setProductionPlanDetailSubDetailId(item.getProductionPlanDetailSubDetailId());
+            l.setReason(l.getReason());
+            l.setDeptId(item.getDeptId());
+            l.setProcessId(item.getProcessId());
+        });
+        boolean result = rejectList.isEmpty() || bizDayworkItemRejectService.saveBatch(rejectList);
+        BizProcess process = bizProcessService.query().eq("id", item.getProcessId()).one();
+        Long packageLineId = bizPackageResourceGroupDetailService.query().eq("user_id", item.getUserId()).list().stream().findFirst().orElse(new BizPackageResourceGroupDetail()).getPackageResourceGroupId();
+        item.setRejectNum(bizDayworkItem.getRejectNum());
+        item.setRejectSum(bizDayworkItem.getRejectSum());
+        item.setQualifiedNum(bizDayworkItem.getQualifiedNum());
+        item.setRemark(bizDayworkItem.getRemark());
+        if(item.getStartTime() == null){
+            item.setStartTime(new Date());
+        }
+        item.setStatus("3");
+        item.setEndTime(new Date());
+        item.setIsSort(1);
+        item.setWorkingHours(item.getEndTime().getTime() - item.getStartTime().getTime());
+        boolean returnCarrier;
+        boolean isLatest;
+        BizDaywork bizDaywork = bizDayworkService.getById(item.getDayworkId());
+        bizDaywork.setTemporaryProcessQualifiedNum(bizDayworkItem.getQualifiedNum());
+        if (bizDaywork.getIsAmend().equals(1) || bizDaywork.getIsWasteRecycling().equals(1)) {
+//            List<BizLotTechnologicalProcess> processes = bizLotTechnologicalProcessService.query().eq("lot_id", bizDaywork.getLotId()).list();
+//            List<BizLotTechnologicalProcessDetail> bizLotTechnologicalProcessDetails = bizLotTechnologicalProcessDetailService.query().in("lot_technological_process_id", processes.stream().map(BizLotTechnologicalProcess::getId).collect(Collectors.toList())).list();
+            List<BizLotTechnologicalProcessDetail> bizLotTechnologicalProcessDetails = bizLotTechnologicalProcessDetailService.query().in("lot_technological_process_id", item.getTechnologicalProcessId()).list();
+//            returnCarrier = bizLotTechnologicalProcessDetails.stream().max(Comparator.comparing(BizLotTechnologicalProcessDetail::getProcessStepNumber)).orElse(new BizLotTechnologicalProcessDetail()).getProcessStepNumber().equals(item.getProcessStepNumber());
+            returnCarrier = item.getProcessStepNumber().equals(bizLotTechnologicalProcessDetails.stream().filter(v -> !v.getTenantId().equals(9L)).max(Comparator.comparing(BizLotTechnologicalProcessDetail::getProcessStepNumber)).orElse(new BizLotTechnologicalProcessDetail()).getProcessStepNumber());
+//                    item.getProcessStepNumber().equals(bizLotTechnologicalProcessDetails.stream().max(Comparator.comparing(BizLotTechnologicalProcessDetail::getProcessStepNumber)));
+            isLatest = bizLotTechnologicalProcessDetails.stream().sorted(Comparator.comparing(BizLotTechnologicalProcessDetail::getProcessStepNumber).reversed()).collect(Collectors.toList()).get(0).getProcessStepNumber().equals(item.getProcessStepNumber());
+        } else {
+            List<BizTechnologicalProcessDetail> bizTechnologicalProcessDetails = bizTechnologicalProcessDetailService.query().ne("tenant_id", 9).eq("technological_process_id", item.getTechnologicalProcessId()).list();
+//            returnCarrier = bizTechnologicalProcessDetails.stream().max(Comparator.comparing(BizTechnologicalProcessDetail::getProcessStepNumber)).orElse(new BizTechnologicalProcessDetail()).getProcessStepNumber().equals(item.getProcessStepNumber());
+            returnCarrier = item.getProcessStepNumber().equals(bizTechnologicalProcessDetails.stream().filter(v -> !v.getTenantId().equals(9L)).max(Comparator.comparing(BizTechnologicalProcessDetail::getProcessStepNumber)).orElse(new BizTechnologicalProcessDetail()).getProcessStepNumber());
+            isLatest = bizTechnologicalProcessDetails.stream().sorted(Comparator.comparing(BizTechnologicalProcessDetail::getProcessStepNumber).reversed()).collect(Collectors.toList()).get(0).getProcessStepNumber().equals(item.getProcessStepNumber());
+        }
+        if(isLatest) {
+            bizDaywork.setIsCertificate(1);
+            bizDaywork.setPackageResourceGroupId(packageLineId);
+            //包装线的所有员工
+            String packageResourceGroupDetailUserIds = bizPackageResourceGroupDetailService.query().eq("package_resource_group_id", packageLineId).list().stream()
+                    .map(BizPackageResourceGroupDetail::getUserId)
+                    .map(Object::toString)
+                    .collect(Collectors.joining(","));
+            item.setPackageResourceGroupId(packageLineId);
+            item.setPackageResourceGroupDetailUserId(packageResourceGroupDetailUserIds);
+        }
+        result = result && bizDayworkItemService.updateById(item);
+        //解绑设备,将daywork状态设置为完成
+        if (returnCarrier) {
+            List<BizDayworkCarrier> bizDayworkCarriers = bizDayworkCarrierService.query().eq("daywork_id", item.getDayworkId()).eq("process_inspection_id", 0L).eq("is_changed", 0).list();
+            bizDayworkCarriers.forEach(l -> {
+                l.setIsChanged(1);
+            });
+            //最后一道序结束报工的时候,将daywork主表的status设置为2
+            bizDaywork.setStatus(2);
+            result = result && (bizDayworkCarriers.isEmpty() || bizDayworkCarrierService.updateBatchById(bizDayworkCarriers));
+        }
+        bizDayworkService.updateById(bizDaywork);
+        //零存
+        //判断该批次是否存过
+        List<BizStorageRetrieval> storage = bizStorageRetrievalService.query().eq("lot_id",item.getLotId()).list();
+        Optional.ofNullable(bizDayworkItem.getStorageInfo())
+                .ifPresent(storageInfo -> {
+                    // 对象不为空,执行操作
+                    if(storage.isEmpty()) {
+                        //新增
+                        bizStorageRetrievalService.save(bizDayworkItem.getStorageInfo());
+                    }
+                });
+        //零取
+        List<BizStorageRetrieval> retrievalList = bizStorageRetrievalService.query().eq("retrieval_lot_id",item.getLotId()).list();
+        if( bizDayworkItem.getRetrievalInfo().size() > 0){
+            List<BizStorageRetrieval> needUpdate = bizDayworkItem.getRetrievalInfo().stream().filter(v -> v.getStatus() == 0).collect(Collectors.toList());
+            if(!needUpdate.isEmpty()) {
+                needUpdate.forEach(l -> l.setStatus(1));
+                bizStorageRetrievalService.updateBatchById(needUpdate);
+            }
+        }
+        return result ? success() : error("结束失败");
+    }
 
     @Log(title = "保存分选报工", businessType = BusinessType.INSERT)
     @Transactional
@@ -490,5 +599,86 @@ public class SortDayworkController extends BaseController {
 
         return toAjax((updates.isEmpty() || bizDayworkItemService.updateBatchById(updates)) && (updateDaywork.isEmpty() || bizDayworkService.updateBatchById(updateDaywork)) && bizDayworkItemService.saveBatch(adds));
     }
+    @Log(title = "保存分选报工", businessType = BusinessType.INSERT)
+    @Transactional
+    @PostMapping("/showDayworkSaveInner")
+    public AjaxResult showDayworkSaveInner(@RequestBody List<BizDayworkItem> dayworkItemList) {
+        // 新建报工明细
+        List<BizDayworkItem> adds = new ArrayList<>();
+        //dayworkID的所有报工
+        List<BizDayworkItem> dayworkItemList1 = bizDayworkItemService.query().in("daywork_id", dayworkItemList.stream().map(BizDayworkItem::getDayworkId).collect(Collectors.toList())).list();
+        // 更新报工明细
+        List<BizDayworkItem> updates = new ArrayList<>();
+        // 判断是否是最后一道工序,假设是的话,判断是否有包装线,假设没有则删除该报工。
+        Long technologicalProcessDetailId = dayworkItemList.get(0).getDaywork().getTechnologicalProcessDetailId();
+        boolean isLatest;
+        Long packageLineId = bizPackageResourceGroupDetailService.query().eq("user_id", getLoginUser().getUserId()).list().stream().findFirst().orElse(new BizPackageResourceGroupDetail()).getPackageResourceGroupId();
+        Long technologicalProcessId = dayworkItemList.get(0).getDaywork().getTechnologicalProcessId();
+        BizDaywork bizDaywork = bizDayworkService.getById(dayworkItemList.get(0).getDayworkId());
+        if(bizDaywork.getIsAmend().equals(1) || bizDaywork.getIsWasteRecycling().equals(1)) {
+            List<BizLotTechnologicalProcessDetail> bizLotTechnologicalProcessDetails = bizLotTechnologicalProcessDetailService.query().eq("lot_technological_process_id", technologicalProcessId).ne("tenant_id", 9).orderByDesc("process_step_number").list();
+            isLatest = bizLotTechnologicalProcessDetails.get(0).getId().equals(technologicalProcessDetailId);
+        } else {
+            List<BizTechnologicalProcessDetail> bizTechnologicalProcessDetails = bizTechnologicalProcessDetailService.query().eq("technological_process_id", technologicalProcessId).ne("tenant_id", 9).orderByDesc("process_step_number").list();
+            isLatest = bizTechnologicalProcessDetails.get(0).getId().equals(technologicalProcessDetailId);
+        }
+        List<BizDaywork> dayworkList = dayworkItemList.stream().map(BizDayworkItem::getDaywork).collect(Collectors.toList());
+        List<Long> processIds = dayworkList.stream().map(v -> v.getProcessId()).collect(Collectors.toList());
+        List<BizProcess> processList = bizProcessService.query().in("id", processIds).list();
+        boolean isFx = false;
+        for(int i = 0;i< processList.size();i++) {
+            if (processList.get(i).getProcessAlias().contains("包装")) {
+                isFx = true;
+            }
+        }
+        if (isFx && (packageLineId == null || packageLineId == 0L)) {
+            return error("该员工不在包装线中,不能进行包装");
+        }
+
+        // 更新报工
+        List<BizDaywork> updateDaywork = new ArrayList<>();
+        dayworkItemList.forEach(l -> {
+            l.getDaywork().setProcessQualifiedNum(l.getDaywork().getTemporaryProcessQualifiedNum());
+            if (l.getStatus().equals("4")) {
+                l.setStatus("7");
+                updates.add(l);
+                l.getDaywork().setDeptId(l.getDeptId());
+            }
+            if (l.getStatus().equals("7")) {
+                BizDaywork daywork = l.getDaywork();
+                daywork.setProtemProcessId(l.getProcessId());
+                daywork.setProtemProcessStepNumber(l.getProcessStepNumber());
+                // 如果被邀请人不是本工段内的人,则需要从当前资源组中删除被邀请人
+                bizProductionResourceGroupDetailService.deleTemporanyPeople(daywork);
+            }
+            updateDaywork.add(l.getDaywork());
+
+            BizDayworkItem bizDayworkItem = new BizDayworkItem();
+            bizDayworkItem.setDayworkId(l.getDayworkId());
+            ;
+            if (l.getDaywork().getIsAmend() == 1) {
+                bizDayworkItem.setFormDayworkItemId(1L);
+            }
+            bizDayworkItem.setProcessStepNumber(l.getDaywork().getProcessStepNumber());
+            bizDayworkItem.setProductionPlanDetailId(l.getProductionPlanDetailId());
+            bizDayworkItem.setTechnologicalProcessId(l.getDaywork().getTechnologicalProcessId());
+            SysUser user = SecurityUtils.getLoginUser().getUser();
+            bizDayworkItem.setUserId(user.getUserId());
+            bizDayworkItem.setUserName(user.getUserName());
+            bizDayworkItem.setProdNum(l.getDaywork().getTemporaryProcessQualifiedNum());
+            bizDayworkItem.setNickName(user.getNickName());
+            // 0114 这里要把前段显示的item的processId传进来
+            bizDayworkItem.setProcessId(l.getDaywork().getProcessId());
+            bizDayworkItem.setTechnologicalProcessDetailId(l.getDaywork().getTechnologicalProcessDetailId());
+            bizDayworkItem.setDeptId(l.getDeptId());
+            bizDayworkItem.setIsSort(l.getIsSort());
+            bizDayworkItem.setDeptName(l.getDeptName());
+            bizDayworkItem.setLotId(l.getDaywork().getLotId());
+            bizDayworkItem.setOutsourceDetailId(l.getOutsourceDetailId());
+            adds.add(bizDayworkItem);
+        });
+
+        return toAjax((updates.isEmpty() || bizDayworkItemService.updateBatchById(updates)) && (updateDaywork.isEmpty() || bizDayworkService.updateBatchById(updateDaywork)) && bizDayworkItemService.saveBatch(adds));
+    }
 
 }

+ 2 - 0
src/main/java/cn/ezhizao/project/business/product/domain/BizDaywork.java

@@ -227,4 +227,6 @@ public class BizDaywork extends BaseEntity
     private List<Long> productionPlanDetailIds;
     @TableField(exist = false)
     private String workshopName;
+    @TableField(exist =false)
+    private Boolean hasFinishOutsource;
 }

+ 2 - 0
src/main/java/cn/ezhizao/project/business/product/domain/BizDayworkItem.java

@@ -309,4 +309,6 @@ public class BizDayworkItem extends BaseEntity
 
     private String fromDeptName;
     private Long fromDeptId;
+    //外协发出明细
+    private Long  outsourceDetailId;
 }

+ 18 - 0
src/main/java/cn/ezhizao/project/system/domain/SysDept.java

@@ -113,6 +113,24 @@ public class SysDept extends BaseEntity {
     @TableField(exist = false)
     private Long lotTechnologicalProcessId;
     private Integer isSortPackaging;
+    private Integer isOutsourcing;
+    private Long supplierId;
+
+    public Integer getIsOutsourcing() {
+        return isOutsourcing;
+    }
+
+    public void setIsOutsourcing(Integer isOutsourcing) {
+        this.isOutsourcing = isOutsourcing;
+    }
+
+    public Long getSupplierId() {
+        return supplierId;
+    }
+
+    public void setSupplierId(Long supplierId) {
+        this.supplierId = supplierId;
+    }
 
     public Integer getIsAmend() {
         return isAmend;

+ 1 - 0
src/main/resources/mybatis/system/SysDeptMapper.xml

@@ -109,6 +109,7 @@
 		d.auto_unbind,
 		d.has_quick,
 		d.is_sort_packaging,
+		d.supplier_id,
 		(select dept_name from sys_dept where dept_id = d.parent_id) parent_name
 		from sys_dept d
 		where d.dept_id = #{deptId}