|
@@ -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();
|