瀏覽代碼

Merge branch 'refs/heads/改派计划'

yusm 3 天之前
父節點
當前提交
5544c66fb6

+ 36 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/controller/PlanController.java

@@ -65,6 +65,42 @@ public class PlanController {
         return planService.planDetail(id,type);
     }
 
+    /**
+     * 获取我负责/其他工位的工序
+     * @param id
+     * @param type
+     * @param stationType
+     * @param request
+     * @return
+     */
+    @RequestMapping("/planDetailWithStation")
+    public HttpRespMsg planDetailWithStation(Integer id,@RequestParam(defaultValue = "0") Integer type,Integer stationType,HttpServletRequest request){
+        return planService.planDetailWithStation(id,type,stationType,request);
+    }
+
+    /**
+     * 改派工序到别的工位
+     * @param ids
+     * @param stationId
+     * @param request
+     * @return
+     */
+    @RequestMapping("/planDetailTransStation")
+    public HttpRespMsg planDetailTransStation(String ids,Integer stationId, HttpServletRequest request){
+        return planService.planDetailTransStation(ids,stationId,request);
+    }
+
+    /**
+     * 取消改派工序到别的工位
+     * @param ids
+     * @param request
+     * @return
+     */
+    @RequestMapping("/planDetailCancelTransfer")
+    public HttpRespMsg planDetailCancelTransfer(String ids, HttpServletRequest request){
+        return planService.planDetailCancelTransfer(ids,request);
+    }
+
     @RequestMapping("/allocationPlan")
     public HttpRespMsg allocationPlan(String ids,Integer planType){
         return planService.allocationPlan(ids,planType);

+ 11 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/entity/PlanProcedureTotal.java

@@ -86,6 +86,17 @@ public class PlanProcedureTotal extends Model<PlanProcedureTotal> {
     @TableField("total_fill_time")
     private Double totalFillTime;
 
+    /**
+     * 工位
+     */
+    @TableField("station_id")
+    private Integer stationId;
+
+    /**
+     * 是否改派到其他工位, 0未改派,1改派
+     */
+    @TableField("is_transfer")
+    private Integer isTransfer;
 
     @Override
     protected Serializable pkVal() {

+ 5 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/mapper/PlanProcedureTotalMapper.java

@@ -2,6 +2,9 @@ package com.management.platform.mapper;
 
 import com.management.platform.entity.PlanProcedureTotal;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
 
 /**
  * <p>
@@ -13,4 +16,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface PlanProcedureTotalMapper extends BaseMapper<PlanProcedureTotal> {
 
+    @Select("select DISTINCT plan_id from plan_procedure_total where station_id=#{departmentId}")
+    List<Integer> selectPlanIdsWithTransfer(Integer departmentId);
 }

+ 3 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/service/PlanProcedureTotalService.java

@@ -4,6 +4,8 @@ import com.management.platform.entity.PlanProcedureTotal;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.management.platform.util.HttpRespMsg;
 
+import java.util.List;
+
 /**
  * <p>
  *  服务类
@@ -18,4 +20,5 @@ public interface PlanProcedureTotalService extends IService<PlanProcedureTotal>
 
     HttpRespMsg getFillProcedureDetail(Integer id, String createDate, boolean deleteDuplicate);
 
+    List<Integer> selectPlanIdsWithTransfer(Integer departmentId);
 }

+ 6 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/service/PlanService.java

@@ -60,4 +60,10 @@ public interface PlanService extends IService<Plan> {
     HttpRespMsg allocationUser(Integer planId);
 
     HttpRespMsg unReceivePlan(String ids);
+
+    HttpRespMsg planDetailWithStation(Integer id, Integer type, Integer stationType,HttpServletRequest request);
+
+    HttpRespMsg planDetailTransStation(String ids, Integer stationId, HttpServletRequest request);
+
+    HttpRespMsg planDetailCancelTransfer(String ids, HttpServletRequest request);
 }

+ 5 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/service/impl/PlanProcedureTotalServiceImpl.java

@@ -264,6 +264,11 @@ public class PlanProcedureTotalServiceImpl extends ServiceImpl<PlanProcedureTota
         return msg;
     }
 
+    @Override
+    public List<Integer> selectPlanIdsWithTransfer(Integer departmentId) {
+            return planProcedureTotalMapper.selectPlanIdsWithTransfer(departmentId);
+    }
+
     public static void main(String[] args) {
         PlanSteelStampNumber planSteelStampNumber=new PlanSteelStampNumber();
         planSteelStampNumber.setSteelStampNumberStart("3941");

+ 184 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/service/impl/PlanServiceImpl.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.management.platform.entity.*;
@@ -210,6 +211,12 @@ public class PlanServiceImpl extends ServiceImpl<PlanMapper, Plan> implements Pl
                 queryWrapper.in(Plan::getId,planIds);
             }
         }
+        if (user.getDepartmentId()!=null) {
+            List<Integer> planIds = planProcedureTotalService.selectPlanIdsWithTransfer(user.getDepartmentId());
+            if(!planIds.isEmpty()){
+                queryWrapper.or().in(Plan::getId,planIds);
+            }
+        }
         queryWrapper.orderByDesc(Plan::getCreateTime).orderByDesc(Plan::getStartDate);
         IPage<Plan> planIPage = planMapper.selectPage(new Page<>(pageIndex, pageSize), queryWrapper);
         List<Plan> records = planIPage.getRecords();
@@ -507,6 +514,9 @@ public class PlanServiceImpl extends ServiceImpl<PlanMapper, Plan> implements Pl
             }
         }
         if (planProcedureTotals.size() > 0) {
+            if (isNew&&plan.getStationId()!=null){
+                planProcedureTotals.forEach(p -> p.setStationId(plan.getStationId()));
+            }
             planProcedureTotalService.saveOrUpdateBatch(planProcedureTotals);
         }
         List<PlanProcedureTotal> totals = planProcedureTotals.stream().filter(ps -> ps.getPlanId().equals(plan.getId())).collect(Collectors.toList());
@@ -1209,6 +1219,180 @@ public class PlanServiceImpl extends ServiceImpl<PlanMapper, Plan> implements Pl
         return msg;
     }
 
+    @Override
+    public HttpRespMsg planDetailWithStation(Integer id, Integer type, Integer stationType,HttpServletRequest request) {
+        HttpRespMsg msg=new HttpRespMsg();
+        Plan plan = planMapper.selectOne(new QueryWrapper<Plan>().eq("id", id));
+        User userSelect = userMapper.selectById(request.getHeader("token"));
+        Integer companyId = userSelect.getCompanyId();
+        String userId = request.getHeader("token");
+        if(plan!=null){
+            switch (type){
+                case 0:
+                    List<PlanProcedureTotal> procedureTotals=new ArrayList<>();
+                    //看自己工位的
+                    if (stationType==0){
+                        procedureTotals = planProcedureTotalService.list(
+                                new LambdaQueryWrapper<PlanProcedureTotal>()
+                                        .eq(PlanProcedureTotal::getPlanId, plan.getId())
+                                        .eq(PlanProcedureTotal::getStationId,userSelect.getDepartmentId())
+                        );
+                    }
+                    //看其他工位的
+                    else if (stationType==1){
+                        procedureTotals = planProcedureTotalService.list(new QueryWrapper<PlanProcedureTotal>()
+                                .eq("plan_id", plan.getId())
+                                .ne("station_id", userSelect.getDepartmentId()));
+                    }
+                    //全部
+                    else {
+                        procedureTotals = planProcedureTotalService.list(new QueryWrapper<PlanProcedureTotal>().eq("plan_id", plan.getId()));
+                    }
+                    List<Integer> procedureIds = procedureTotals.stream().map(PlanProcedureTotal::getProdProcedureId).distinct().collect(Collectors.toList());
+                    procedureIds.add(-1);
+                    List<ProdProcedure> prodProcedureList = prodProcedureMapper.selectList(new QueryWrapper<ProdProcedure>().in("id",procedureIds));
+                    List<Integer> ids = procedureTotals.stream().map(PlanProcedureTotal::getId).collect(Collectors.toList());
+                    ids.add(-1);
+                    List<ProdProcedureTeam> procedureTeams = prodProcedureTeamService.list(new QueryWrapper<ProdProcedureTeam>().in("plan_procedure_id", ids));
+                    List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
+                    procedureTotals.forEach(ps->{
+                        Optional<ProdProcedure> first = prodProcedureList.stream().filter(pl -> pl.getId().equals(ps.getProdProcedureId())).findFirst();
+                        if(first.isPresent()){
+                            ps.setProdProcedure(first.get());
+                        }
+                        if(procedureTeams.size()>0){
+                            List<ProdProcedureTeam> procedureTeamList = procedureTeams.stream().filter(pt -> pt.getPlanProcedureId().equals(ps.getId())).collect(Collectors.toList());
+                            ps.setTeamIds(procedureTeamList.stream().map(ProdProcedureTeam::getUserId).distinct().collect(Collectors.joining(",")));
+                            procedureTeamList.forEach(pt->{
+                                Optional<User> user = userList.stream().filter(ul -> ul.getId().equals(pt.getUserId())).findFirst();
+                                if(user.isPresent()){
+                                    pt.setUser(user.get());
+                                }
+                            });
+                            ps.setProdProcedureTeamList(procedureTeamList);
+                            if(procedureTeamList.stream().anyMatch(pl->pl.getUserId()!=null&&pl.getStatus()==0&&pl.getUserId().equals(userId))){
+                                ps.setCanReceive(true);
+                            }
+                            if(!StringUtils.isEmpty(ps.getTeamIds())){
+                                String userNames = userList.stream().filter(ul -> Arrays.asList(ps.getTeamIds().split(",")).contains(ul.getId())).collect(Collectors.toList())
+                                        .stream().map(User::getName).collect(Collectors.joining(","));
+                                ps.setTeamNames(userNames);
+                            }
+                            if(procedureTeamList.stream().anyMatch(pl->pl.getProgress()>0&&pl.getStatus()==4)){
+                                ps.setNeedAddCircle(true);
+                            }
+                            if(procedureTeamList.stream().anyMatch(pl->pl.getUserId()!=null&&pl.getUserId().equals(userId)&&pl.getStatus()==1)){
+                                ps.setCancellationReceive(true);
+                            }
+                        }
+                    });
+                    msg.setData(procedureTotals);
+                    break;
+            }
+        }
+        return msg;
+    }
+
+    @Override
+    public HttpRespMsg planDetailTransStation(String ids, Integer stationId, HttpServletRequest request) {
+        HttpRespMsg msg = new HttpRespMsg();
+        if (StringUtils.isEmpty(ids)) {
+            msg.setError("请传递关键信息");
+            return msg;
+        }
+        String token = request.getHeader("Token");
+        User user = userMapper.selectById(token);
+        String[] strings = ids.split(",");
+        List<String> collect = Arrays.stream(strings).collect(Collectors.toList());
+        List<PlanProcedureTotal> totalList = planProcedureTotalService.list(new QueryWrapper<PlanProcedureTotal>().in("id", collect));
+        boolean b = totalList.stream().anyMatch(a -> a.getIsTransfer() == 1);
+        if (b){
+            msg.setError("存在工序已被转派,不能再次转派");
+            return msg;
+        }
+        PlanProcedureTotal procedureTotal = totalList.get(0);
+        Plan plan = planMapper.selectById(procedureTotal.getPlanId());
+        if (!plan.getStationId().equals(user.getDepartmentId())){
+            msg.setError("不是计划初始分配的工位,不能转派");
+            return msg;
+        }
+        boolean update = planProcedureTotalService.update(new UpdateWrapper<PlanProcedureTotal>().set("station_id", stationId).set("is_transfer", 1).in("id", collect));
+        //todo 发送改派通知
+        if (update){
+            List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("department_id", stationId).eq("work_type", "工位长"));
+            List<ProdProcedure> procedureList = prodProcedureMapper.selectList(new QueryWrapper<ProdProcedure>().in("id", totalList.stream().map(PlanProcedureTotal::getProdProcedureId)));
+            String procedureNames = procedureList.stream().map(ProdProcedure::getName).collect(Collectors.joining("|"));
+            if (!userList.isEmpty()){
+                List<WxCorpInfo> wxCorpInfoList = wxCorpInfoService.list(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
+                if(!wxCorpInfoList.isEmpty()){
+                    WxCorpInfo wxCorpInfo = wxCorpInfoList.get(0);
+                    String userIds = userList.stream().map(User::getCorpwxRealUserid).collect(Collectors.joining("|"));
+                    StringBuilder stringBuilder=new StringBuilder();
+                    stringBuilder.append("工序名称:"+procedureNames+"\n"
+                            +"         排产工单号:"+plan.getProductSchedulingNum()+"转派");
+                    wxCorpInfoService.sendWXCorpTemplateMsgWithPLan(wxCorpInfo,userIds,stringBuilder.toString(),"plan/today",null,plan);
+                }
+            }
+        }
+        return msg;
+    }
+
+    @Override
+    public HttpRespMsg planDetailCancelTransfer(String ids, HttpServletRequest request) {
+        HttpRespMsg msg = new HttpRespMsg();
+        if (StringUtils.isEmpty(ids)) {
+            msg.setError("请传递关键信息");
+            return msg;
+        }
+        String token = request.getHeader("Token");
+        User user = userMapper.selectById(token);
+        String[] strings = ids.split(",");
+        List<String> collect = Arrays.stream(strings).collect(Collectors.toList());
+        List<PlanProcedureTotal> totalList = planProcedureTotalService.list(new QueryWrapper<PlanProcedureTotal>().in("id", collect));
+        boolean b = totalList.stream().anyMatch(a -> a.getIsTransfer() != 1);
+        if (b){
+            msg.setError("存在工序未被转派,不能取消转派");
+            return msg;
+        }
+        PlanProcedureTotal procedureTotal = totalList.get(0);
+        Plan plan = planMapper.selectById(procedureTotal.getPlanId());
+        if (!plan.getStationId().equals(user.getDepartmentId())){
+            msg.setError("不是计划初始分配的工位,不能取消转派");
+            return msg;
+        }
+        //todo 改派完之后分配好,不能再去取消改派
+        List<ProdProcedureTeam> teamList = prodProcedureTeamService.list(new QueryWrapper<ProdProcedureTeam>().in("plan_procedure_id", collect));
+        if (!teamList.isEmpty()){
+            msg.setError("已经分配好,不能取消转派");
+            return msg;
+        }
+        boolean update = planProcedureTotalService.update(new UpdateWrapper<PlanProcedureTotal>().set("station_id",null).set("is_transfer", 0).in("id", collect));
+        //todo 发送改派通知
+        if (update){
+            List<Integer> stationList = totalList.stream().distinct().map(PlanProcedureTotal::getStationId).collect(Collectors.toList());
+            if (!stationList.isEmpty()){
+                for (Integer stationId : stationList) {
+                    List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("department_id", stationId).eq("work_type", "工位长"));
+                    List<ProdProcedure> procedureList = prodProcedureMapper.selectList(new QueryWrapper<ProdProcedure>().in("id", totalList.stream().map(PlanProcedureTotal::getProdProcedureId)));
+                    String procedureNames = procedureList.stream().map(ProdProcedure::getName).collect(Collectors.joining("|"));
+                    if (!userList.isEmpty()){
+                        List<WxCorpInfo> wxCorpInfoList = wxCorpInfoService.list(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
+                        if(!wxCorpInfoList.isEmpty()){
+                            WxCorpInfo wxCorpInfo = wxCorpInfoList.get(0);
+                            String userIds = userList.stream().map(User::getCorpwxRealUserid).collect(Collectors.joining("|"));
+                            StringBuilder stringBuilder=new StringBuilder();
+                            stringBuilder.append("工序名称:"+procedureNames+"\n"
+                                    +"         排产工单号:"+plan.getProductSchedulingNum()+"转派");
+                            wxCorpInfoService.sendWXCorpTemplateMsgWithPLan(wxCorpInfo,userIds,stringBuilder.toString(),"plan/today",null,plan);
+                        }
+                    }
+                }
+            }
+        }
+        return msg;
+    }
+
+
     @Override
     public HttpRespMsg deletePeople(Integer id) {
         HttpRespMsg msg=new HttpRespMsg();