luodangjia
2025-01-01 196ac84b6ec0dd05304dd6577f169f7fbf5fe726
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package com.sinata.web.controller.applet;
 
import com.sinata.common.core.domain.R;
import com.sinata.common.core.domain.entity.SysUser;
import com.sinata.common.utils.SecurityUtils;
import com.sinata.system.domain.*;
import com.sinata.system.domain.dto.CheckOutDto;
import com.sinata.system.domain.dto.CollectTotalUpDto;
import com.sinata.system.domain.dto.SysDepartmentDTO;
import com.sinata.system.domain.vo.SysDepartmentVO;
import com.sinata.system.mapper.SysDepartmentMapper;
import com.sinata.system.service.*;
import com.sinata.web.controller.tool.CapacityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
 
/**
 * <p>
 * 区域表 前端控制器
 * </p>
 *
 * @author mitao
 * @since 2024-12-02
 */
@Api(tags = {"监管人员"})
@RestController
@Validated
@RequestMapping("/applet/sysDepartment")
@RequiredArgsConstructor
public class AppDepartmentController {
    private final SysDepartmentService sysDepartmentService;
    private final MwStagingRoomService roomService;
    private final MwCollectRecordService collectRecordService;
    private final MwCheckoutRecordService mwCheckoutRecordService;
    private final ISysUserService userService;
    private final MwTransitCarService carService;
 
    /**
     * 获取区域树
     * @return
     */
    @ApiOperation("获取区域树")
    @PostMapping("/regionTree")
    @ApiImplicitParam(name = "keyword", value = "关键字", required = false)
    public R<List<SysDepartmentVO>> getRegionTree(@RequestParam(required = false) String keyword) {
        return R.ok(sysDepartmentService.getRegionTree(keyword));
    }
 
    /**
     * 获取区域树
     *
     * @return
     */
    @ApiOperation(value = "获取全部/区域/医疗机构/处置单位/监管单位树-搜索框用", notes = "0:全部 1:区域 2:医疗机构 3:处置单位 4:监管单位")
    @PostMapping("/departmentSearchTree")
    @ApiImplicitParam(name = "type", value = "查询类型", required = true)
    public R<List<SysDepartmentVO>> getDepartmentSearchTree(@RequestParam(value = "type", required = true) @NotNull(message = "类型不能为空") Integer type) {
        return R.ok(sysDepartmentService.listByType(type));
    }
 
    @ApiOperation("获取医院监管列表")
    @PostMapping("/hospita/list")
    public R<List<SysDepartment>> list(String name) {
        List<SysDepartment> list = sysDepartmentService.lambdaQuery().like(name!=null,SysDepartment::getDepartmentName,name).eq(SysDepartment::getOrgType, 2).list();
        for (SysDepartment sysDepartment : list) {
            //获取医院暂存间信息
            MwStagingRoom one = roomService.lambdaQuery().eq(MwStagingRoom::getDepartmentId, sysDepartment.getId()).one();
            if (one != null) {
                continue;
            }
            //获取存了多少数量
            Long count = collectRecordService.lambdaQuery().eq(MwCollectRecord::getDepartmentId, sysDepartment.getId()).eq(MwCollectRecord::getStatus, 1).count();
            //计算百分率
            Integer maxCapacity = one.getMaxCapacity();
            String percentage = CapacityUtil.calculatePercentage(count, maxCapacity);
            sysDepartment.setMaxCapacity(one.getMaxCapacity());
            sysDepartment.setNowCapacity(count.intValue());
            sysDepartment.setPercentage(percentage);
 
        }
        return R.ok(list);
    }
 
 
 
    @ApiOperation("获取处置监管列表")
    @PostMapping("/end/list")
    public R<List<SysDepartment>> list2(String name) {
        List<SysDepartment> list = sysDepartmentService.lambdaQuery().like(name!=null,SysDepartment::getDepartmentName,name).eq(SysDepartment::getOrgType, 3).list();
        LocalDate now = LocalDate.now();
        for (SysDepartment sysDepartment : list) {
            //获取库存总量
            Long count1 = collectRecordService.lambdaQuery().eq(MwCollectRecord::getReceiveDepartmentId, sysDepartment.getId()).eq(MwCollectRecord::getStatus, 3).groupBy(MwCollectRecord::getBoxNumber).count();
            //获取接收数量
            Long count2 = collectRecordService.lambdaQuery().eq(MwCollectRecord::getReceiveTime,now).eq(MwCollectRecord::getReceiveDepartmentId, sysDepartment.getId()).eq(MwCollectRecord::getStatus, 3).groupBy(MwCollectRecord::getBoxNumber).count();
            //获取处置数量
            Long count3 = collectRecordService.lambdaQuery().eq(MwCollectRecord::getReceiveTime,now).eq(MwCollectRecord::getReceiveDepartmentId, sysDepartment.getId()).eq(MwCollectRecord::getStatus, 4).groupBy(MwCollectRecord::getBoxNumber).count();
            sysDepartment.setCont1(count1);
            sysDepartment.setCont2(count2);
            sysDepartment.setCont3(count3);
        }
        return R.ok(list);
    }
 
 
 
    @ApiOperation("医院暂存间情况")
    @PostMapping("/room")
    public R<List<CollectTotalUpDto>> collecttotal1(@ApiParam("医院id")@RequestParam Long departmentId) {
        return R.ok(collectRecordService.collectTotal3(departmentId));
    }
 
    @ApiOperation(value = "医院转运记录")
    @PostMapping("/trans")
    public R<List<CheckOutDto>> trans(LocalDate date,@ApiParam("医院id")@RequestParam Long departmentId) {
        LocalDate now = LocalDate.now().minusDays(7);
        if (date!=null){
            now = LocalDate.now();
        }
        List<MwCheckoutRecord> list = mwCheckoutRecordService.lambdaQuery().ge(date ==null,MwCheckoutRecord::getCheckoutTime, now).eq(MwCheckoutRecord::getDepartmentId, departmentId).orderByDesc(MwCheckoutRecord::getCheckoutTime).list();
        List<CheckOutDto> backList = new ArrayList<>();
        for (MwCheckoutRecord mwCheckoutRecord : list) {
            CheckOutDto checkOutDto = new CheckOutDto();
            SysUser byId = userService.getById(mwCheckoutRecord.getDriverId());
            checkOutDto.setDriverName(byId.getNickName());
            MwTransitCar byId1 = carService.getById(mwCheckoutRecord.getCarId());
            checkOutDto.setLicensePlateNumber(byId1.getLicensePlateNumber());
            checkOutDto.setCheckoutTime(mwCheckoutRecord.getCheckoutTime());
            List<CollectTotalUpDto> records =  mwCheckoutRecordService.totalUp1(mwCheckoutRecord.getId());
            checkOutDto.setRecords(records);
            backList.add(checkOutDto);
        }
        return R.ok(backList);
    }
 
    @ApiOperation(value = "处置详情")
    @PostMapping("/end/total")
    public R<List<CollectTotalUpDto>> outtotal1(@ApiParam("处置机构id")@RequestParam Long departmentId) {
        return R.ok(mwCheckoutRecordService.totalUp5(departmentId));
    }
 
 
 
 
 
}