mitao
2025-02-19 ae7f04be9321ddbe17c46fae8ab05d34e7493f9f
medicalWaste-admin/src/main/java/com/sinata/web/controller/applet/AppMwCollectRecordController.java
@@ -3,13 +3,18 @@
import java.math.BigDecimal;
import java.util.*;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson2.JSONArray;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.sinata.common.core.domain.R;
import com.sinata.common.core.domain.entity.SysDictData;
import com.sinata.common.core.domain.entity.SysUser;
import com.sinata.common.entity.PageDTO;
import com.sinata.common.utils.DateUtils;
import com.sinata.common.utils.SecurityUtils;
import com.sinata.common.utils.StringUtils;
import com.sinata.system.domain.*;
import com.sinata.system.domain.dto.*;
import com.sinata.system.domain.query.MwCollectRecordQuery;
@@ -29,6 +34,7 @@
import javax.validation.Valid;
import java.io.IOException;
import java.time.LocalDate;
import java.util.stream.Collectors;
/**
 * <p>
@@ -59,6 +65,8 @@
    private final MwStagingRoomService roomService;
    private final ISysDictDataService dictDataService;
    private final MwTransitCarService carService;
    private final MwTransitCarCollectPointService mwTransitCarCollectPointService;
    private final MwTransitRouteService transitRouteService;
    @ApiOperation(value = "新增医废记录")
@@ -82,6 +90,7 @@
        mwCollectRecord.setStagingRoomId(one1.getId());
        mwCollectRecord.setDepartmentId(sysUser.getDepartmentId());
        mwCollectRecord.setBoxTime(new Date());
        mwCollectRecord.setCollectUserId(sysUser.getUserId());
        // 创建一个随机数生成器实例
        Random random = new Random();
@@ -160,6 +169,32 @@
        MwBox byId = boxService.getById(list.get(0).getStagingRoomId());
        byId.setLink(2);
        boxService.updateById(byId);
        //查询当前医废收集路线
        Long departmentId = list.get(0).getDepartmentId();
        MwTransitRoute route = transitRouteService.queryRouteByDepartmentId(departmentId);
        if (Objects.nonNull(route)){
            //查询当前车辆已运输路线记录
            MwTransitCarCollectPoint carCollectPoint = mwTransitCarCollectPointService.lambdaQuery().eq(MwTransitCarCollectPoint::getCarId, sysUser.getCarId())
                    .eq(MwTransitCarCollectPoint::getRouteId, route.getId())
                    .eq(MwTransitCarCollectPoint::getTransitDate, DateUtil.format(new Date(), DatePattern.NORM_DATE_PATTERN))
                    .last("LIMIT 1").one();
            List<Long> departmentIdList = new ArrayList<>();
            //如果当前收集医院不是第一家且当前收集医院未被记录
            if (Objects.nonNull(carCollectPoint) && !carCollectPoint.getPointList().contains(departmentId.toString())){
                departmentIdList = JSONArray.parseArray(carCollectPoint.getPointList(), Long.class);
                departmentIdList.add(departmentId);
            }else if (Objects.isNull(carCollectPoint) ){//当前医院为第一个收集的医院
                carCollectPoint = new MwTransitCarCollectPoint();
                carCollectPoint.setCarId(carCollectPoint.getCarId());
                carCollectPoint.setRouteId(route.getId());
                carCollectPoint.setTransitDate(new Date());
                departmentIdList.add(departmentId);
            }
            carCollectPoint.setPointList(JSONArray.toJSONString(departmentIdList));
            mwTransitCarCollectPointService.saveOrUpdate(carCollectPoint);
        }
        return R.ok();
    }
@@ -184,7 +219,9 @@
    public R<List<HospitalCollectTotalUpDto>> tanscollecttotal2(@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)LocalDate date) {
        SysUser  sysUser = SecurityUtils.getLoginUser().getUser();
        //先获取医院ids
        List<MwCollectRecord> list = collectRecordService.lambdaQuery().eq(date!=null,MwCollectRecord::getCheckoutTime,date).eq(MwCollectRecord::getCheckoutUserId, sysUser.getUserId()).groupBy(MwCollectRecord::getDepartmentId).list();
        List<MwCollectRecord> list = collectRecordService.lambdaQuery().ge(MwCollectRecord::getCheckoutTime, date.atStartOfDay())
                .le(MwCollectRecord::getCheckoutTime, date.atTime(23,59,59))
                .eq(MwCollectRecord::getCheckoutUserId, sysUser.getUserId()).groupBy(MwCollectRecord::getDepartmentId).list();
        //循环医院,然后放入
        List<HospitalCollectTotalUpDto> list1 = new ArrayList<>();
        for (MwCollectRecord mwCollectRecord : list) {
@@ -294,10 +331,22 @@
            mwDisposalRecordItem.setDisposalRecordId(mwDisposalRecord.getId());
            items.add(mwDisposalRecordItem);
        }
        disposalRecordItemService.saveBatch(items);
        MwTransitRoute route = transitRouteService.queryRouteByDepartmentId(list.get(0).getDepartmentId());
        if (Objects.nonNull(route)) {
            //查询当前车辆已运输路线记录
            MwTransitCarCollectPoint carCollectPoint = mwTransitCarCollectPointService.lambdaQuery().eq(MwTransitCarCollectPoint::getCarId, sysUser.getCarId())
                    .eq(MwTransitCarCollectPoint::getRouteId, route.getId())
                    .eq(MwTransitCarCollectPoint::getTransitDate, DateUtil.format(new Date(), DatePattern.NORM_DATE_PATTERN))
                    .last("LIMIT 1").one();
            List<Long> departmentIdList = new ArrayList<>();
            if (Objects.nonNull(carCollectPoint)) {
                departmentIdList = JSONArray.parseArray(carCollectPoint.getPointList(), Long.class);
                departmentIdList.add(byId.getId());
                carCollectPoint.setPointList(JSONArray.toJSONString(departmentIdList));
                mwTransitCarCollectPointService.updateById(carCollectPoint);
            }
        }
        return R.ok();
    }
@@ -327,6 +376,11 @@
        mwDisposalHandleRecord.setDriverId(list.get(0).getDriverId());
        mwDisposalHandleRecord.setCarId(list.get(0).getCarId());
        disposalHandleRecordService.save(mwDisposalHandleRecord);
        List<Long> collectIdList = list.stream().map(MwCollectRecord::getId).collect(Collectors.toList());
        //查询收集记录对应的接收记录
        List<MwDisposalRecordItem> disposalRecordItems = disposalRecordItemService.lambdaQuery().in(MwDisposalRecordItem::getCollectRecordId, collectIdList).list();
        Map<Long, Long> disposalRecordItemMap = disposalRecordItems.stream().collect(Collectors.toMap(MwDisposalRecordItem::getCollectRecordId, MwDisposalRecordItem::getDisposalRecordId));
        //将收集记录以及子表改变为已处置
        if (!list.isEmpty()) {
            List<Long> ids = new ArrayList<>();
@@ -338,10 +392,11 @@
                mwCollectRecord.setDisposalTime(new Date());
                MwDisposalHandleRecordItem mwDisposalHandleRecordItem = new MwDisposalHandleRecordItem();
                mwDisposalHandleRecordItem.setCollectRecordId(mwCollectRecord.getId());
                mwDisposalHandleRecordItem.setDisposalRecordId(mwDisposalHandleRecord.getId());
                mwDisposalHandleRecordItem.setDisposalHandleRecordId(mwDisposalHandleRecord.getId());
                mwDisposalHandleRecordItem.setDisposalRecordId(disposalRecordItemMap.getOrDefault(mwCollectRecord.getId(), null));
                mwDisposalHandleRecordItems.add(mwDisposalHandleRecordItem);
            }
//            disposalHandleRecordItemService.saveBatch(mwDisposalHandleRecordItems);
            disposalHandleRecordItemService.saveBatch(mwDisposalHandleRecordItems);
            collectRecordService.updateBatchById(list);
        }
//            //将接收记录以及子表变为已处置
@@ -382,7 +437,6 @@
        //通过车辆id查询列表
        List<CollectCarTotalUpDto> list = collectRecordService.carGroup(byId.getCarId(),name);
        return R.ok(list);
    }
    @ApiOperation(value = "已装车列表详情",tags = "运输人员")
@@ -413,6 +467,9 @@
    public R<List<CollectTotalUpDto>> collecttotal1(@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)LocalDate date) {
        SysUser  sysUser = SecurityUtils.getLoginUser().getUser();
        SysUser byId = userService.getById(sysUser.getUserId());
        if (date==null){
            date = LocalDate.now();
        }
        return R.ok(collectRecordService.collectTotal(date,byId.getDepartmentId()));
    }
    @ApiOperation("收集统计下")
@@ -420,8 +477,12 @@
    public R<Page<MwCollectRecord>> collecttotal2(@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)LocalDate date,@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        SysUser  sysUser = SecurityUtils.getLoginUser().getUser();
        SysUser byId = userService.getById(sysUser.getUserId());
        Page<MwCollectRecord> page = collectRecordService.lambdaQuery().eq(date!=null,MwCollectRecord::getCollectTime,date).eq(MwCollectRecord::getDepartmentId, byId.getDepartmentId()).orderByDesc(MwCollectRecord::getCollectTime).page(Page.of(pageNum, pageSize));
        Page<MwCollectRecord> page = collectRecordService.lambdaQuery()
                .ge(MwCollectRecord::getCreateTime, date.atStartOfDay())
                .le(MwCollectRecord::getCreateTime, date.atTime(23,59,59))
            .eq(MwCollectRecord::getDepartmentId, byId.getDepartmentId())
            .orderByDesc(MwCollectRecord::getCollectTime)
            .page(Page.of(pageNum, pageSize));
        return R.ok(page);
    }