|
@@ -0,0 +1,268 @@
|
|
|
|
+package cn.ezhizao.project.business.switchDept.controller;
|
|
|
|
+
|
|
|
|
+import cn.ezhizao.common.utils.SecurityUtils;
|
|
|
|
+import cn.ezhizao.framework.web.controller.BaseController;
|
|
|
|
+import cn.ezhizao.framework.web.domain.AjaxResult;
|
|
|
|
+import cn.ezhizao.project.business.product.domain.*;
|
|
|
|
+import cn.ezhizao.project.business.product.service.*;
|
|
|
|
+import cn.ezhizao.project.business.resourceGroup.domain.BizProductionResourceGroup;
|
|
|
|
+import cn.ezhizao.project.business.resourceGroup.domain.BizProductionResourceGroupSubPlan;
|
|
|
|
+import cn.ezhizao.project.business.resourceGroup.service.IBizProductionResourceGroupService;
|
|
|
|
+import cn.ezhizao.project.business.resourceGroup.service.IBizProductionResourceGroupSubPlanService;
|
|
|
|
+import cn.ezhizao.project.business.technologicalProcessDetail.domain.BizTechnologicalProcessDetail;
|
|
|
|
+import cn.ezhizao.project.system.domain.SysDept;
|
|
|
|
+import cn.ezhizao.project.system.domain.SysUser;
|
|
|
|
+import cn.ezhizao.project.system.mapper.SysDeptMapper;
|
|
|
|
+import cn.ezhizao.project.system.service.ISysDeptService;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Arrays;
|
|
|
|
+import java.util.Collections;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 临时周转controller
|
|
|
|
+ *
|
|
|
|
+ * @author zhuangdezheng
|
|
|
|
+ * @date 2024-04-20
|
|
|
|
+ */
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/business/switch")
|
|
|
|
+public class SwitchController extends BaseController {
|
|
|
|
+ @Resource
|
|
|
|
+ IBizDayworkService dayworkService;
|
|
|
|
+ @Resource
|
|
|
|
+ IBizDayworkItemService dayworkItemService;
|
|
|
|
+ @Resource
|
|
|
|
+ IBizDayworkCarrierService dayworkCarrierService;
|
|
|
|
+ @Resource
|
|
|
|
+ IBizProductionPlanDetailService productionPlanDetailService;
|
|
|
|
+ @Resource
|
|
|
|
+ IBizLotTechnologicalProcessDetailService lotTechnologicalProcessDetailService;
|
|
|
|
+ @Resource
|
|
|
|
+ IBizProductionResourceGroupSubPlanService bizProductionResourceGroupSubPlanService;
|
|
|
|
+ @Resource
|
|
|
|
+ IBizProductionPlanDetailService bizProductionPlanDetailService;
|
|
|
|
+ @Resource
|
|
|
|
+ ISysDeptService sysDeptService;
|
|
|
|
+ @Resource
|
|
|
|
+ SysDeptMapper sysDeptMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ IBizProductionResourceGroupService bizProductionResourceGroupService;
|
|
|
|
+
|
|
|
|
+ @PostMapping("/getDayworkByCarrierCode")
|
|
|
|
+ public AjaxResult getDayworkByCarrierCode(@RequestBody BizDayworkItem bizDayworkItem) {
|
|
|
|
+ List<BizDayworkCarrier> bizDayworkCarriers = dayworkCarrierService.query().eq("carrier_id", bizDayworkItem.getCarrierId()).eq("is_changed", 0).list();
|
|
|
|
+ if (bizDayworkCarriers.isEmpty()) {
|
|
|
|
+ throw new RuntimeException("该载具未绑定任何批次!");
|
|
|
|
+ }
|
|
|
|
+ List<BizDaywork> bizDayworks = dayworkService.query().in("id", bizDayworkCarriers.isEmpty()
|
|
|
|
+ ?
|
|
|
|
+ Collections.singletonList(0L)
|
|
|
|
+ :
|
|
|
|
+ bizDayworkCarriers.stream()
|
|
|
|
+ .map(BizDayworkCarrier::getDayworkId)
|
|
|
|
+ .collect(Collectors.toList())
|
|
|
|
+ )
|
|
|
|
+ .list();
|
|
|
|
+ // 判断是否是在当前工段
|
|
|
|
+ bizDayworks = bizDayworks.stream().filter(v -> v.getDeptId().equals(bizDayworkItem.getDeptId())).collect(Collectors.toList());
|
|
|
|
+ List<BizDayworkItem> allBizDayworkItem = dayworkItemService.query().in("daywork_id", bizDayworks.isEmpty() ? Collections.singletonList(0L) : bizDayworks.stream().map(BizDaywork::getId).collect(Collectors.toList())).orderByDesc("create_time").list();
|
|
|
|
+ bizDayworks.forEach(l -> l.setDayworkItemList(allBizDayworkItem.stream().filter(v -> v.getDayworkId().equals(l.getId())).collect(Collectors.toList())));
|
|
|
|
+ bizDayworks.forEach(l -> l.setDayworkItemList(allBizDayworkItem.stream().filter(v -> v.getDayworkId().equals(l.getId())).collect(Collectors.toList())));
|
|
|
|
+ List<BizDayworkItem> turnoverItems = new ArrayList<>();
|
|
|
|
+ for (BizDaywork bizDaywork : bizDayworks) {
|
|
|
|
+ if (bizDaywork.getDayworkItemList().get(0).getStatus().equals("4")
|
|
|
|
+ || bizDaywork.getDayworkItemList().get(0).getStatus().equals("5")
|
|
|
|
+ || bizDaywork.getDayworkItemList().get(0).getStatus().equals("7")) {
|
|
|
|
+ turnoverItems.add(bizDaywork.getDayworkItemList().get(0));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (turnoverItems.isEmpty()) {
|
|
|
|
+ return success(turnoverItems);
|
|
|
|
+ } else {
|
|
|
|
+ BizDayworkItem conditions = new BizDayworkItem();
|
|
|
|
+ conditions.setIds(turnoverItems.stream().map(BizDayworkItem::getId).collect(Collectors.toList()));
|
|
|
|
+ List<BizDayworkItem> items = dayworkItemService.getList(conditions);
|
|
|
|
+ //拿到生产计划id
|
|
|
|
+ List<Long> productionPlanDetailIds = items.stream().map(BizDayworkItem::getProductionPlanDetailId).collect(Collectors.toList());
|
|
|
|
+ List<BizProductionPlanDetail> bizProductionPlanDetails = productionPlanDetailService.query().in("id", productionPlanDetailIds.isEmpty() ? Collections.singletonList(0L) : productionPlanDetailIds).list();
|
|
|
|
+ //查找批次id
|
|
|
|
+ List<Long> LotTechnologicalProcessesIds = items.stream().filter(v -> v.getDaywork().getIsAmend().equals(1) || v.getDaywork().getIsWasteRecycling().equals(1)).map(BizDayworkItem::getTechnologicalProcessId).collect(Collectors.toList());
|
|
|
|
+ List<BizLotTechnologicalProcessDetail> bizLotTechnologicalProcessDetails = lotTechnologicalProcessDetailService.query().in("lot_technological_process_id", LotTechnologicalProcessesIds.isEmpty() ? Collections.singletonList(0L) : LotTechnologicalProcessesIds).list();
|
|
|
|
+ for (BizDayworkItem item : items) {
|
|
|
|
+ //添加产品描述
|
|
|
|
+ item.setProductDescription(bizProductionPlanDetails.stream().filter(v -> v.getId().equals(item.getProductionPlanDetailId())).collect(Collectors.toList()).get(0).getProductDescription());
|
|
|
|
+ //如果不是正常批次,则工艺重新取
|
|
|
|
+ if (item.getDaywork().getIsAmend().equals(1) || item.getDaywork().getIsWasteRecycling().equals(1)) {
|
|
|
|
+ List<BizLotTechnologicalProcessDetail> processDetail = bizLotTechnologicalProcessDetails.stream().filter(v -> v.getLotId().equals(item.getLotId())).collect(Collectors.toList());
|
|
|
|
+ BizLotTechnologicalProcessDetail process = processDetail.stream().filter(v -> v.getProcessStepNumber().equals(item.getProcessStepNumber())).findFirst().orElse(null);
|
|
|
|
+ BizTechnologicalProcessDetail technologicalProcessDetail = new BizTechnologicalProcessDetail();
|
|
|
|
+ technologicalProcessDetail.setProcessAlias(process.getProcessAlias());
|
|
|
|
+ technologicalProcessDetail.setProcessCode(process.getProcessCode());
|
|
|
|
+ technologicalProcessDetail.setProductDescription(process.getProductDescription());
|
|
|
|
+ technologicalProcessDetail.setProcessStepNumber(process.getProcessStepNumber());
|
|
|
|
+ item.setTechnologicalProcessDetail(technologicalProcessDetail);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return success(items);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @GetMapping("/listAllDepts")
|
|
|
|
+ public AjaxResult listAllDepts() {
|
|
|
|
+ SysDept sysDept = new SysDept();
|
|
|
|
+ sysDept.setIsWorkSection(1);
|
|
|
|
+ List<SysDept> depts = sysDeptService.selectDeptList(sysDept);
|
|
|
|
+ return success(depts);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @PostMapping("/turnoverAll")
|
|
|
|
+ public AjaxResult turnoverAll(@RequestBody BizDayworkItem item) {
|
|
|
|
+ BizDayworkItem conditions = new BizDayworkItem();
|
|
|
|
+ conditions.setIds(item.getIds());
|
|
|
|
+ List<BizDayworkItem> items = dayworkItemService.getList(conditions);
|
|
|
|
+ List<BizDayworkItem> updates = new ArrayList<>();
|
|
|
|
+ List<BizDayworkItem> inserts = new ArrayList<>();
|
|
|
|
+ List<BizDaywork> updateDayworks = new ArrayList<>();
|
|
|
|
+ List<BizProductionResourceGroupSubPlan> addResources = new ArrayList<>();
|
|
|
|
+ SysUser user = SecurityUtils.getLoginUser().getUser();
|
|
|
|
+ SysDept sysDept = sysDeptMapper.selectDeptById(item.getDeptId());
|
|
|
|
+ List<BizProductionResourceGroup> productionResourceGroupList = bizProductionResourceGroupService.list(new QueryWrapper<BizProductionResourceGroup>().eq("dept_id", item.getDeptId()).eq("is_deactivate", 0));
|
|
|
|
+ items.forEach(l -> {
|
|
|
|
+ l.setStatus("7");
|
|
|
|
+ updates.add(l);
|
|
|
|
+ BizDayworkItem bizDayworkItem = new BizDayworkItem();
|
|
|
|
+ bizDayworkItem.setDayworkId(l.getDayworkId());
|
|
|
|
+ bizDayworkItem.setStatus(item.getStatus());
|
|
|
|
+ bizDayworkItem.setDeptId(item.getDeptId());
|
|
|
|
+ bizDayworkItem.setProcessId(l.getProcessId());
|
|
|
|
+ bizDayworkItem.setTechnologicalProcessDetailId(l.getTechnologicalProcessDetailId());
|
|
|
|
+ BizDaywork bizDaywork = l.getDaywork();
|
|
|
|
+ bizDaywork.setDeptId(item.getDeptId());
|
|
|
|
+ bizDayworkItem.setFormDayworkItemId(1L);
|
|
|
|
+ bizDayworkItem.setLotId(l.getLotId());
|
|
|
|
+ bizDayworkItem.setLotCode(l.getLotCode());
|
|
|
|
+ bizDayworkItem.setUserId(user.getUserId());
|
|
|
|
+ bizDayworkItem.setUserName(user.getUserName());
|
|
|
|
+ bizDayworkItem.setNickName(user.getNickName());
|
|
|
|
+ bizDayworkItem.setWorkingHours(0L);
|
|
|
|
+ bizDayworkItem.setTenantId(l.getTenantId());
|
|
|
|
+ bizDayworkItem.setProductionPlanDetailId(l.getProductionPlanDetailId());
|
|
|
|
+ bizDayworkItem.setProductionPlanId(l.getProductionPlanId());
|
|
|
|
+ bizDayworkItem.setProductionPlanDetailSubDetailId(l.getProductionPlanDetailSubDetailId());
|
|
|
|
+ bizDayworkItem.setProductionPlanDetailSubDetailEquipmentId(l.getProductionPlanDetailSubDetailEquipmentId());
|
|
|
|
+ bizDayworkItem.setQualifiedNum(l.getQualifiedNum());
|
|
|
|
+ bizDayworkItem.setTechnologicalProcessId(l.getTechnologicalProcessId());
|
|
|
|
+ bizDayworkItem.setProdNum(l.getProdNum());
|
|
|
|
+ bizDayworkItem.setEquipmentDetailId(l.getEquipmentDetailId());
|
|
|
|
+ bizDayworkItem.setEquipmentDetailCode(l.getEquipmentDetailCode());
|
|
|
|
+ bizDayworkItem.setDeptId(item.getDeptId());
|
|
|
|
+ bizDayworkItem.setDeptName(item.getDeptName());
|
|
|
|
+ bizDayworkItem.setStartTime(item.getStartTime());
|
|
|
|
+ bizDayworkItem.setTurnoverType(item.getTurnoverType());
|
|
|
|
+ bizDayworkItem.setTurnoverArea(item.getTurnoverArea());
|
|
|
|
+ bizDayworkItem.setPlaceId(item.getPlaceId());
|
|
|
|
+ bizDayworkItem.setPlace(item.getPlace());
|
|
|
|
+ bizDayworkItem.setProcessStepNumber(l.getProcessStepNumber());
|
|
|
|
+ updateDayworks.add(bizDaywork);
|
|
|
|
+ inserts.add(bizDayworkItem);
|
|
|
|
+ if (sysDept.getAutoAllocation() == 1) {
|
|
|
|
+ BizProductionResourceGroupSubPlan groupSubPlan=new BizProductionResourceGroupSubPlan();
|
|
|
|
+ groupSubPlan.setDeptId(bizDayworkItem.getDeptId());
|
|
|
|
+ groupSubPlan.setProductionPlanDetailId(bizDayworkItem.getProductionPlanDetailId());
|
|
|
|
+
|
|
|
|
+ List<BizProductionResourceGroupSubPlan> groupSubPlanList = bizProductionResourceGroupSubPlanService.getAotList(groupSubPlan);
|
|
|
|
+ //如果没分配
|
|
|
|
+ if(groupSubPlanList.size()==0) {
|
|
|
|
+ //查产品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(l.getProductionPlanDetailId());
|
|
|
|
+ subPlan.setTechnologicalProcessId(l.getTechnologicalProcessId());
|
|
|
|
+ subPlan.setResourceGroupId(info.getId());
|
|
|
|
+ subPlan.setDeptId(bizDayworkItem.getDeptId());
|
|
|
|
+ subPlan.setResourceGroupCode(info.getCode());
|
|
|
|
+ addResources.add(subPlan);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ return dayworkItemService.updateBatchById(updates) &&
|
|
|
|
+ dayworkItemService.saveBatch(inserts) &&
|
|
|
|
+ dayworkService.updateBatchById(updateDayworks) &&
|
|
|
|
+ (addResources.isEmpty() || bizProductionResourceGroupSubPlanService.saveBatch(addResources))
|
|
|
|
+ ? success() : error();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @PostMapping("/turnoverOutsourceAll")
|
|
|
|
+ public AjaxResult turnoverOutsourceAll(@RequestBody BizDayworkItem item) {
|
|
|
|
+ // 设置工时
|
|
|
|
+ // 获取箱子关联的所有批次
|
|
|
|
+ SysUser user = SecurityUtils.getLoginUser().getUser();
|
|
|
|
+ SysDept sysDept = sysDeptMapper.selectDeptByCode(item.getDeptCode());
|
|
|
|
+ item.setDeptId(sysDept.getDeptId());
|
|
|
|
+ item.setDeptName(sysDept.getDeptName());
|
|
|
|
+ List<BizDayworkItem> addItems = new ArrayList<>();
|
|
|
|
+ List<BizDayworkItem> updateItems = new ArrayList<>();
|
|
|
|
+ List<BizDaywork> updateDayworks = new ArrayList<>();
|
|
|
|
+ // 关联批次的所有最后一条报工
|
|
|
|
+ BizDayworkItem conditions = new BizDayworkItem();
|
|
|
|
+ conditions.setIds(item.getIds());
|
|
|
|
+ List<BizDayworkItem> bizDayworkItems = dayworkItemService.getList(conditions);
|
|
|
|
+ for (BizDayworkItem v : bizDayworkItems) {
|
|
|
|
+// BizDayworkItem lastItem = bizDayworkItems.stream().filter(l -> l.getDayworkId().equals(v.getId())).findFirst().orElse(null);
|
|
|
|
+// if (lastItem != null && lastItem.getStatus().equals("3")) {
|
|
|
|
+// 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(v.getDayworkId());
|
|
|
|
+ bizItem.setProcessId(v.getProcessId());
|
|
|
|
+ bizItem.setTechnologicalProcessDetailId(v.getTechnologicalProcessDetailId());
|
|
|
|
+ bizItem.setStatus(v.getStatus());
|
|
|
|
+ BizDaywork daywork = v.getDaywork();
|
|
|
|
+ daywork.setDeptId(item.getDeptId());
|
|
|
|
+ updateDayworks.add(daywork);
|
|
|
|
+ if(daywork.getIsAmend()==1){
|
|
|
|
+ bizItem.setFormDayworkItemId(1L);
|
|
|
|
+ }
|
|
|
|
+ bizItem.setLotId(v.getLotId());
|
|
|
|
+ bizItem.setLotCode(v.getLotCode());
|
|
|
|
+ bizItem.setUserId(user.getUserId());
|
|
|
|
+ bizItem.setUserName(user.getUserName());
|
|
|
|
+ bizItem.setNickName(user.getNickName());
|
|
|
|
+ bizItem.setWorkingHours(0L);
|
|
|
|
+ bizItem.setTenantId(v.getTenantId());
|
|
|
|
+ bizItem.setProductionPlanDetailId(v.getProductionPlanDetailId());
|
|
|
|
+ bizItem.setProductionPlanId(v.getProductionPlanId());
|
|
|
|
+ bizItem.setProductionPlanDetailSubDetailId(v.getProductionPlanDetailSubDetailId());
|
|
|
|
+ bizItem.setProductionPlanDetailSubDetailEquipmentId(v.getProductionPlanDetailSubDetailEquipmentId());
|
|
|
|
+ bizItem.setQualifiedNum(v.getQualifiedNum());
|
|
|
|
+ bizItem.setTechnologicalProcessId(v.getTechnologicalProcessId());
|
|
|
|
+ bizItem.setProdNum(v.getProdNum());
|
|
|
|
+ bizItem.setDeptId(item.getDeptId());
|
|
|
|
+ bizItem.setDeptName(item.getDeptName());
|
|
|
|
+ bizItem.setStartTime(item.getStartTime());
|
|
|
|
+ bizItem.setTurnoverType(item.getTurnoverType());
|
|
|
|
+ bizItem.setTurnoverArea(item.getTurnoverArea());
|
|
|
|
+ bizItem.setPlaceId(item.getPlaceId());
|
|
|
|
+ bizItem.setPlace(item.getPlace());
|
|
|
|
+ bizItem.setProcessStepNumber(item.getProcessStepNumber());
|
|
|
|
+ addItems.add(bizItem);
|
|
|
|
+ v.setStatus("7");
|
|
|
|
+ updateItems.add(v);
|
|
|
|
+// batch = batch && bizDayworkItemService.saveOrUpdate(bizItem);
|
|
|
|
+
|
|
|
|
+// }
|
|
|
|
+ }
|
|
|
|
+ return dayworkService.updateBatchById(updateDayworks) && dayworkItemService.saveBatch(addItems) && dayworkItemService.updateBatchById(updateItems) ? success("保存成功") : error("保存失败");
|
|
|
|
+ }
|
|
|
|
+}
|