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.common.utils.StringUtils; 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.CountTwoDto; 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.format.annotation.DateTimeFormat; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import javax.validation.constraints.NotNull; import java.math.BigDecimal; import java.time.LocalDate; import java.util.ArrayList; import java.util.List; /** *

* 区域表 前端控制器 *

* * @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> getRegionTree(@RequestParam(required = false) String keyword) { List regionTree1 = sysDepartmentService.getRegionTree2(keyword); return R.ok(regionTree1); } @ApiOperation("获取区域树") @PostMapping("/pub/regionTree") @ApiImplicitParam(name = "keyword", value = "关键字", required = false) public R> getRegionTree1(@RequestParam(required = false) String keyword) { List regionTree1 = sysDepartmentService.getRegionTree2(keyword); return R.ok(regionTree1); } @ApiOperation("获取单位详情") @PostMapping("/detail") public R getRegionTree(@RequestParam(required = true) Long id) { return R.ok(sysDepartmentService.getById(id)); } /** * 获取区域树 * * @return */ @ApiOperation(value = "获取全部/区域/医疗机构/处置单位/监管单位树-搜索框用", notes = "0:全部 1:区域 2:医疗机构 3:处置单位 4:监管单位") @PostMapping("/departmentSearchTree") @ApiImplicitParam(name = "type", value = "查询类型", required = true) public R> getDepartmentSearchTree() { return R.ok(sysDepartmentService.getRegionTree2(null)); } @ApiOperation("获取医院监管列表") @PostMapping("/hospita/list") public R> list(String name, Long areaId) { // SysDepartment byId = sysDepartmentService.getMyDepartment(); SysDepartment byId = sysDepartmentService.getById(areaId); List list = sysDepartmentService.lambdaQuery().likeRight(SysDepartment::getTreeCode, byId.getTreeCode()).like(StringUtils.isNotEmpty(name), 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> list2(String name,Long areaId) { SysDepartment byId = sysDepartmentService.getById(areaId); List list = sysDepartmentService.lambdaQuery().likeRight(SysDepartment::getTreeCode, byId.getTreeCode()).like(name!=null,SysDepartment::getDepartmentName,name).eq(SysDepartment::getOrgType, 3).list(); LocalDate now = LocalDate.now(); for (SysDepartment sysDepartment : list) { //获取库存总量 BigDecimal count1 = collectRecordService.lambdaQuery().eq(MwCollectRecord::getReceiveDepartmentId, sysDepartment.getId()).eq(MwCollectRecord::getStatus ,3).list().stream() .map(MwCollectRecord::getWeight) .reduce(BigDecimal.ZERO, BigDecimal::add); //获取接收数量 BigDecimal count2 = collectRecordService.lambdaQuery().ge(MwCollectRecord::getReceiveTime,now.atStartOfDay()).le(MwCollectRecord::getReceiveTime,now.atTime(23,59,59)).eq(MwCollectRecord::getReceiveDepartmentId, sysDepartment.getId()).list().stream() .map(MwCollectRecord::getWeight) .reduce(BigDecimal.ZERO, BigDecimal::add); //获取处置数量 BigDecimal count3 = collectRecordService.lambdaQuery().ge(MwCollectRecord::getDisposalTime,now.atStartOfDay()).le(MwCollectRecord::getDisposalTime,now.atTime(23,59,59)).eq(MwCollectRecord::getReceiveDepartmentId, sysDepartment.getId()).list().stream() .map(MwCollectRecord::getWeight) .reduce(BigDecimal.ZERO, BigDecimal::add); sysDepartment.setCont1(count1); sysDepartment.setCont2(count2); sysDepartment.setCont3(count3); } return R.ok(list); } @ApiOperation("医院暂存间情况") @PostMapping("/room") public R> collecttotal1(@ApiParam("医院id")@RequestParam Long departmentId) { return R.ok(collectRecordService.collectTotal3(departmentId)); } @ApiOperation("医院暂存间情况上") @PostMapping("/up/room") public R collecttotal2(@ApiParam("医院id")@RequestParam Long departmentId) { MwStagingRoom one = roomService.lambdaQuery().eq(MwStagingRoom::getDepartmentId, departmentId).one(); Long count = collectRecordService.lambdaQuery().eq(MwCollectRecord::getStagingRoomId, one.getId()).eq(MwCollectRecord::getStatus, 1).count(); MwCollectRecord one1 = collectRecordService.lambdaQuery().eq(MwCollectRecord::getStagingRoomId, one.getId()).eq(MwCollectRecord::getStatus, 1).orderByDesc(MwCollectRecord::getBoxTime).last("limit 1").one(); if (one1!=null){ one.setBoxTime(one1.getBoxTime()); } one.setCount(count); return R.ok(one); } @ApiOperation(value = "医院转运记录") @PostMapping("/trans") public R> trans(@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)LocalDate date, @ApiParam("医院id")@RequestParam Long departmentId) { // LocalDate now = LocalDate.now().minusDays(7); // if (date!=null){ // now = LocalDate.now(); // } List list = mwCheckoutRecordService.lambdaQuery().ge(MwCheckoutRecord::getCheckoutTime, date.atStartOfDay()).le(MwCheckoutRecord::getCheckoutTime , date.atTime(23,59,59)).eq(MwCheckoutRecord::getDepartmentId, departmentId).orderByDesc(MwCheckoutRecord::getCheckoutTime).list(); List 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 records = mwCheckoutRecordService.totalUp1(mwCheckoutRecord.getId()); checkOutDto.setRecords(records); backList.add(checkOutDto); } return R.ok(backList); } @ApiOperation(value = "处置详情上") @PostMapping("/end/total/up") public R outtotal2(@ApiParam("处置机构id")@RequestParam Long departmentId) { CountTwoDto countTwoDto = new CountTwoDto(); LocalDate now = LocalDate.now(); BigDecimal count = collectRecordService.lambdaQuery().eq(MwCollectRecord::getReceiveDepartmentId, departmentId).ge(MwCollectRecord::getReceiveTime, now.atStartOfDay()).le(MwCollectRecord::getReceiveTime,now.atTime(23,59,59)).list().stream() .map(MwCollectRecord::getWeight) .reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal count1 = collectRecordService.lambdaQuery().eq(MwCollectRecord::getReceiveDepartmentId, departmentId).ge(MwCollectRecord::getDisposalTime, now.atStartOfDay()).le(MwCollectRecord::getDisposalTime,now.atTime(23,59,59)).list().stream() .map(MwCollectRecord::getWeight) .reduce(BigDecimal.ZERO, BigDecimal::add); countTwoDto.setCount(count); countTwoDto.setCount1(count1); return R.ok(countTwoDto); } @ApiOperation(value = "处置详情") @PostMapping("/end/total") public R> outtotal1(@ApiParam("处置机构id")@RequestParam Long departmentId) { return R.ok(mwCheckoutRecordService.totalUp5(departmentId)); } }