luodangjia
2025-01-02 268809bb4d1ace0bbe8ec20262ebb7d7822c8630
medicalWaste-admin/src/main/java/com/sinata/web/controller/applet/AppMwCollectRecordController.java
@@ -4,7 +4,9 @@
import java.util.*;
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.SecurityUtils;
@@ -19,6 +21,7 @@
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@@ -40,6 +43,7 @@
@Api(tags = {"医院工作人员"})
@RequiredArgsConstructor
@RequestMapping("/applet/mwCollectRecord")
public class AppMwCollectRecordController {
    private final MwCollectRecordService collectRecordService;
    @Autowired
@@ -50,13 +54,38 @@
    private final SysDepartmentService departmentService;
    private final MwDisposalRecordService disposalRecordService;
    private final MwDisposalRecordItemService disposalRecordItemService;
    private final MwDisposalHandleRecordService disposalHandleRecordService;
    private final MwDisposalHandleRecordItemService disposalHandleRecordItemService;
    private final MwStagingRoomService roomService;
    private final ISysDictDataService dictDataService;
    @ApiOperation("新增医废记录")
    @ApiOperation(value = "新增医废记录")
    @PostMapping("/add")
    public R<?> add(@Valid @RequestBody MwCollectRecord mwCollectRecord) {
        SysUser  sysUser = SecurityUtils.getLoginUser().getUser();
        MwBox one = boxService.lambdaQuery().eq(MwBox::getBoxNumber, mwCollectRecord.getBoxNumber()).one();
        mwCollectRecord.setBoxId(one.getId());
        MwStagingRoom one1 = roomService.lambdaQuery().eq(MwStagingRoom::getDepartmentId, sysUser.getDepartmentId()).one();
        if (one1==null){
            return R.fail("当前单位没有暂存间");
        }
        mwCollectRecord.setStagingRoomId(one1.getId());
        mwCollectRecord.setDepartmentId(sysUser.getDepartmentId());
        mwCollectRecord.setBoxTime(new Date());
        // 创建一个随机数生成器实例
        Random random = new Random();
        // 生成一个6位数范围内的随机整数(100000 到 999999)
        int randomNumber = 10000000 + random.nextInt(90000000);
        mwCollectRecord.setMedicalWasteNumber(String.valueOf(randomNumber));
        SysDictData medicalWasteType = dictDataService.getById(mwCollectRecord.getWasteType());
        if (medicalWasteType!=null){
            mwCollectRecord.setWasteTypeStr(medicalWasteType.getDictLabel());
        }
        collectRecordService.save(mwCollectRecord);
        return R.ok();
    }
@@ -88,6 +117,8 @@
        for (MwCollectRecord mwCollectRecord : list) {
            mwCollectRecord.setStatus(2);
            mwCollectRecord.setCheckoutUserId(sysUser.getUserId());
            mwCollectRecord.setDriverId(sysUser.getUserId());
            mwCollectRecord.setCarId(sysUser.getCarId());
            boxes.add(mwCollectRecord.getBoxNumber());
            sum= sum.add(mwCollectRecord.getWeight());
        }
@@ -153,17 +184,19 @@
    @ApiOperation(value = "扫码接收列表",tags = "处置人员")
    @PostMapping("/end/down/collect/total")
    public R<List<HospitalCollectTotalUpDto>> tanscollecttotal3(String boxNum) {
    public R<List<HospitalCollectTotalUp1Dto>> tanscollecttotal3(String boxNum) {
        SysUser  sysUser = SecurityUtils.getLoginUser().getUser();
        MwCollectRecord one = collectRecordService.lambdaQuery().eq(MwCollectRecord::getBoxNumber, boxNum).eq(MwCollectRecord::getStatus, 2).last("limit 1").one();
        if (one==null){
            return R.ok();
        }
        //先获取医院ids
        List<MwCollectRecord> list = collectRecordService.lambdaQuery().eq(MwCollectRecord::getStatus,2).eq(MwCollectRecord::getCheckoutUserId, one.getCheckoutUserId()).groupBy(MwCollectRecord::getDepartmentId).list();
        //循环医院,然后放入
        List<HospitalCollectTotalUpDto> list1 = new ArrayList<>();
        List<HospitalCollectTotalUp1Dto> list1 = new ArrayList<>();
        for (MwCollectRecord mwCollectRecord : list) {
            List<CollectTotalUpDto> collectTotalUpDtos = collectRecordService.collectTotal1(null, sysUser.getUserId(), mwCollectRecord.getDepartmentId());
            HospitalCollectTotalUpDto hospitalCollectTotalUpDto = new HospitalCollectTotalUpDto();
            List<CollectDto> collectTotalUpDtos = collectRecordService.getGroup1(null, mwCollectRecord.getDepartmentId());
            HospitalCollectTotalUp1Dto hospitalCollectTotalUpDto = new HospitalCollectTotalUp1Dto();
            hospitalCollectTotalUpDto.setHospitalName(mwCollectRecord.getHospitalName());
            hospitalCollectTotalUpDto.setCollectTotalUpDtos(collectTotalUpDtos);
            list1.add(hospitalCollectTotalUpDto);
@@ -173,16 +206,19 @@
    @ApiOperation(value = "确认接受",tags = "处置人员")
    @PostMapping("/end/down/collect/confirm")
    public R tanscollecttotal4(String boxNum) {
    public R tanscollecttotal4(@RequestParam BoxListDto boxListDto) {
        SysUser  sysUser = SecurityUtils.getLoginUser().getUser();
        SysDepartment byId = departmentService.getById(sysUser.getDepartmentId());
        //将record变为已接受
        List<MwCollectRecord> list = collectRecordService.lambdaQuery().eq(MwCollectRecord::getStatus,2).eq(MwCollectRecord::getBoxNumber, boxNum).list();
        List<MwCollectRecord> list = collectRecordService.lambdaQuery().eq(MwCollectRecord::getStatus,2).eq(MwCollectRecord::getBoxNumber, boxListDto.getBoxNum()).list();
        Set<String> boxes = new HashSet<>();
        BigDecimal receiveQuantity = BigDecimal.ZERO;
        for (MwCollectRecord mwCollectRecord : list) {
            mwCollectRecord.setStatus(3);
            boxes.add(mwCollectRecord.getBoxNumber());
            mwCollectRecord.setReceiveUserId(sysUser.getUserId());
            mwCollectRecord.setReceiveTime(new Date());
            mwCollectRecord.setReceiveDepartmentId(sysUser.getDepartmentId());
            receiveQuantity = receiveQuantity.add(mwCollectRecord.getWeight());
        }
        collectRecordService.updateBatchById(list);
@@ -199,6 +235,8 @@
        mwDisposalRecord.setTotalHandledQuantity(list.size());
        mwDisposalRecord.setDisposalFlag(0);
        mwDisposalRecord.setTotalHandledWeight(receiveQuantity);
        mwDisposalRecord.setDriverId(list.get(0).getDriverId());
        mwDisposalRecord.setCarId(list.get(0).getCarId());
        disposalRecordService.save(mwDisposalRecord);
        //插入子表
        List<MwDisposalRecordItem> items = new ArrayList<>();
@@ -224,18 +262,53 @@
    public R<List<CollectDto>> list2(String boxNumber) {
        SysUser  sysUser = SecurityUtils.getLoginUser().getUser();
        SysDepartment byId = departmentService.getById(sysUser.getDepartmentId());
        List<MwCollectRecord> list = collectRecordService.lambdaQuery().eq(MwCollectRecord::getStatus, 3).eq(MwCollectRecord::getBoxNumber, boxNumber).list();
        //新增处置记录
        MwDisposalHandleRecord mwDisposalHandleRecord  = new MwDisposalHandleRecord();
        mwDisposalHandleRecord.setDepartmentId(byId.getId());
        mwDisposalHandleRecord.setDisposalUnitName(byId.getDepartmentName());
        mwDisposalHandleRecord.setDisposalTime(new Date());
        mwDisposalHandleRecord.setDisposalUserId(sysUser.getUserId());
        mwDisposalHandleRecord.setDriverId(list.get(0).getDriverId());
        mwDisposalHandleRecord.setCarId(list.get(0).getCarId());
        disposalHandleRecordService.save(mwDisposalHandleRecord);
        //将收集记录以及子表改变为已处置
        //将接收记录以及子表变为已处置
        if (!list.isEmpty()) {
            List<Long> ids = new ArrayList<>();
            List<MwDisposalHandleRecordItem> mwDisposalHandleRecordItems = new ArrayList<>();
            for (MwCollectRecord mwCollectRecord : list) {
                    ids.add(mwCollectRecord.getId());
                mwCollectRecord.setStatus(4);
                mwCollectRecord.setDisposalUserId(sysUser.getUserId());
                mwCollectRecord.setDisposalTime(new Date());
                MwDisposalHandleRecordItem mwDisposalHandleRecordItem = new MwDisposalHandleRecordItem();
                mwDisposalHandleRecordItem.setCollectRecordId(mwCollectRecord.getId());
                mwDisposalHandleRecordItem.setDisposalRecordId(mwDisposalHandleRecord.getId());
                mwDisposalHandleRecordItems.add(mwDisposalHandleRecordItem);
            }
            disposalHandleRecordItemService.saveBatch(mwDisposalHandleRecordItems);
            collectRecordService.updateBatchById(list);
            //将接收记录以及子表变为已处置
            List<MwDisposalRecordItem> list1 = disposalRecordItemService.lambdaQuery().in(MwDisposalRecordItem::getCollectRecordId, ids).list();
            if (!list1.isEmpty()){
                List<Long> ids2 = new ArrayList<>();
                for (MwDisposalRecordItem mwDisposalRecordItem : list1) {
                    mwDisposalRecordItem.setDisposalFlag(1);
                    mwDisposalRecordItem.setDisposalUserId(sysUser.getUserId());
                    mwDisposalRecordItem.setDisposalTime(new Date());
                    ids2.add(mwDisposalRecordItem.getId());
                }
                disposalRecordItemService.updateBatchById(list1);
                List<MwDisposalRecord> list2 = disposalRecordService.lambdaQuery().in(MwDisposalRecord::getId, ids2).list();
                for (MwDisposalRecord mwDisposalRecord : list2) {
                    mwDisposalRecord.setDisposalFlag(1);
                    mwDisposalRecord.setDisposalTime(new Date());
                    mwDisposalRecord.setDisposalUserId(sysUser.getUserId());
                }
                disposalRecordService.updateBatchById(list2);
            }
        }
        return R.ok();
    }
@@ -276,13 +349,13 @@
    @ApiOperation("收集统计上")
    @PostMapping("/collect/total")
    public R<List<CollectTotalUpDto>> collecttotal1(LocalDate date) {
    public R<List<CollectTotalUpDto>> collecttotal1(@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)LocalDate date) {
        SysUser  sysUser = SecurityUtils.getLoginUser().getUser();
        return R.ok(collectRecordService.collectTotal(date,sysUser.getDepartmentId()));
    }
    @ApiOperation("收集统计下")
    @PostMapping("/collect/down/total")
    public R<Page<MwCollectRecord>> collecttotal2(LocalDate date,@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
    public R<Page<MwCollectRecord>> collecttotal2(@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)LocalDate date,@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        SysUser  sysUser = SecurityUtils.getLoginUser().getUser();
        Page<MwCollectRecord> page = collectRecordService.lambdaQuery().eq(date!=null,MwCollectRecord::getCollectTime,date).eq(MwCollectRecord::getDepartmentId, sysUser.getDepartmentId()).orderByDesc(MwCollectRecord::getCollectTime).page(Page.of(pageNum, pageSize));
        return R.ok(page);