package com.ltkj.web.controller.system; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.func.Func; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ltkj.common.core.domain.entity.SysDictData; import com.ltkj.common.utils.SecurityUtils; import com.ltkj.framework.config.MatchUtils; import com.ltkj.hosp.domain.*; import com.ltkj.hosp.service.*; import com.ltkj.hosp.vodomain.ChargeStatisticsVo; import com.ltkj.hosp.vodomain.HzVoDomain; import com.ltkj.system.service.ISysDictDataService; import com.ltkj.system.service.ISysDictTypeService; import com.ltkj.system.service.ISysUserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.apache.poi.hpsf.Decimal; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import com.ltkj.common.annotation.Log; import com.ltkj.common.core.controller.BaseController; import com.ltkj.common.core.domain.AjaxResult; import com.ltkj.common.enums.BusinessType; import com.ltkj.common.utils.poi.ExcelUtil; import com.ltkj.common.core.page.TableDataInfo; /** * 收费员日结Controller * * @author ltkj_赵佳豪&李格 * @date 2023-03-06 */ @RestController @RequestMapping("/hosp/collector") @Api(tags = "收费员日结") public class TjTollCollectorController extends BaseController { @Resource private ITjTollCollectorService tjTollCollectorService; @Resource private ITjTollCollectorDetailService collectorDetailService; @Resource private ITjFlowingWaterService tjFlowingWaterService; @Resource private ITjOrderService tjOrderService; @Resource private ITjCustomerService tjCustomerService; @Resource private ISysDictDataService dictDataService; /** * 查询收费员日结列表 */ @PreAuthorize("@ss.hasPermi('hosp:collector:list')") @GetMapping("/list") @ApiOperation(value = "查询收费员日结列表") public AjaxResult list(@RequestParam(required = false) @ApiParam(value = "收费员id") String tollCollectorId, @RequestParam(required = false) @ApiParam(value = "起始时间") Date accountBeginTime, @RequestParam(required = false) @ApiParam(value = "起始时间") Date accountEndTime, @ApiParam(value = "页码数(默认1)") @RequestParam(defaultValue = "1") Integer pageNum, @ApiParam(value = "显示条数(默认10)") @RequestParam(defaultValue = "10") Integer pageSize) { Page page=new Page<>(pageNum,pageSize); LambdaQueryWrapper wqq = new LambdaQueryWrapper<>(); if (null != tollCollectorId) { wqq.eq(TjTollCollector::getTollCollectorId, tollCollectorId); } if (null != accountBeginTime && null != accountEndTime) { wqq.between(TjTollCollector::getCreateTime, accountBeginTime, accountEndTime); } else { DateTime dateTime = DateUtil.lastWeek(); wqq.between(TjTollCollector::getCreateTime, DateUtil.lastWeek(),DateUtil.date()); } wqq.orderByDesc(TjTollCollector::getCreateTime); Page collectorPage = tjTollCollectorService.page(page, wqq); List list = collectorPage.getRecords(); // List list = tjTollCollectorService.list(wqq); if (null != list && list.size() > 0) { for (TjTollCollector collector : list) { LambdaQueryWrapper wq = new LambdaQueryWrapper<>(); wq.eq(TjTollCollectorDetail::getAccountId, collector.getAccountId()); collector.setTjTollCollectorDetailList(collectorDetailService.list(wq)); } } Map map=new HashMap<>(); map.put("list",list); map.put("total",collectorPage.getTotal()); return AjaxResult.success(map); } /** * 导出收费员日结列表 */ @PreAuthorize("@ss.hasPermi('hosp:collector:export')") @Log(title = "收费员日结", businessType = BusinessType.EXPORT) @PostMapping("/export") @ApiOperation(value = "导出收费员日结列表") public void export(HttpServletResponse response, TjTollCollector tjTollCollector) { List list = tjTollCollectorService.selectTjTollCollectorList(tjTollCollector); ExcelUtil util = new ExcelUtil(TjTollCollector.class); util.exportExcel(response, list, "收费员日结数据"); } /** * 获取收费员日结详细信息 */ @PreAuthorize("@ss.hasPermi('hosp:collector:query')") @GetMapping(value = "/{id}") @ApiOperation(value = "获取收费员日结详细信息") public AjaxResult getInfo(@PathVariable("id") String id) { return success(tjTollCollectorService.selectTjTollCollectorById(id)); } /** * 点击结算 新增收费员日结 */ @PreAuthorize("@ss.hasPermi('hosp:collector:add')") @Log(title = "收费员日结", businessType = BusinessType.INSERT) @PostMapping @ApiOperation(value = "点击结算 新增收费员日结") public AjaxResult add(@RequestBody TjTollCollector tjTollCollector) { String accountId = "JZ" + SecurityUtils.getUsername() + (new SimpleDateFormat("yyMMddHHmmssSSS").format(new Date())); tjTollCollector.setAccountId(accountId); if (tjTollCollectorService.save(tjTollCollector)) { List tjTollCollectorDetailList = tjTollCollector.getTjTollCollectorDetailList(); for (TjTollCollectorDetail collectorDetail : tjTollCollectorDetailList) { collectorDetail.setAccountId(tjTollCollector.getAccountId()); collectorDetailService.save(collectorDetail); } for (String id : tjTollCollector.getIds()) { TjFlowingWater water = tjFlowingWaterService.getById(id); water.setIsCheckout("Y"); tjFlowingWaterService.updateById(water); } return AjaxResult.success(accountId); } return AjaxResult.error("操作失败"); } @PreAuthorize("@ss.hasPermi('hosp:collector:remove')") @DeleteMapping("/removeTjTollCollectorById") @ApiOperation(value = "收费员撤销账单操作接口") public AjaxResult removeTjTollCollectorById(@RequestParam @ApiParam(value = "结账id") String id, @RequestParam @ApiParam(value = "结账员id") String tollCollectorId) { String userId = SecurityUtils.getLoginUser().getUserId(); if (!userId.equals(tollCollectorId)) { return AjaxResult.error("非当前用户禁止操作"); } // LambdaQueryWrapper wqq = new LambdaQueryWrapper<>(); // wqq.orderByDesc(TjTollCollector::getCreateTime); // List list = tjTollCollectorService.list(wqq); // if (null != list && list.size() > 0) { // TjTollCollector collector = list.get(0); // if (null != collector && !collector.getId().equals(id)) { // return AjaxResult.error("请撤销最后一次结账记录"); // } // } String ids = tjTollCollectorService.getTjTollCollectorByLastOne(); if (null != ids && !id.equals(ids)) { return AjaxResult.error("请撤销最后一次结账记录"); } // TjTollCollector collector = tjTollCollectorService.getById(id); TjTollCollector collector = tjTollCollectorService.getTjTollCollectorById(id); if (null != collector) { LambdaQueryWrapper wq = new LambdaQueryWrapper<>(); wq.eq(TjTollCollectorDetail::getAccountId, collector.getAccountId()); collectorDetailService.remove(wq); tjTollCollectorService.removeById(collector); LambdaQueryWrapper wqq1 = new LambdaQueryWrapper<>(); wqq1.eq(TjFlowingWater::getIsCheckout, "Y"); wqq1.between(TjFlowingWater::getUpdateTime, collector.getAccountBeginTime(), collector.getAccountEndTime()); List waterList = tjFlowingWaterService.list(wqq1); for (TjFlowingWater tjFlowingWater : waterList) { tjFlowingWater.setIsCheckout("N"); tjFlowingWaterService.updateById(tjFlowingWater); } return AjaxResult.success("该账单已成功撤销"); } return AjaxResult.success("该账单已撤销"); } /** * 获取最后一次结账时间 */ @GetMapping("/getLastTime") @ApiOperation(value = "获取最后一次结账时间") public AjaxResult getLastTime() { //获取当前登录的操作员 String userId = SecurityUtils.getLoginUser().getUserId(); //根据当前操作员查结帐表中最后一次结账时间 LambdaQueryWrapper wq = new LambdaQueryWrapper<>(); wq.eq(TjTollCollector::getTollCollectorId, userId); wq.orderByDesc(TjTollCollector::getAccountEndTime); List list = tjTollCollectorService.list(wq); if (null != list && list.size() > 0) return success(list.get(0).getAccountEndTime()); return AjaxResult.success("1970-01-01 00:00:00"); } /** * 统计收费员日结 */ @GetMapping("/getList") @ApiOperation(value = "统计收费员日结") public AjaxResult getList(@RequestParam @ApiParam(value = "收费员id") String userId, @RequestParam @ApiParam(value = "开始时间") Date beginTime, @RequestParam @ApiParam(value = "结束时间") Date endTime, @ApiParam(value = "页码数(默认1)") @RequestParam(defaultValue = "1") Integer pageNum, @ApiParam(value = "显示条数(默认10)") @RequestParam(defaultValue = "10") Integer pageSize) { Map map = new HashMap<>(); LambdaQueryWrapper wq = new LambdaQueryWrapper<>(); wq.eq(TjFlowingWater::getTollCollectorId, userId); wq.eq(TjFlowingWater::getIsCheckout, "N"); wq.ne(TjFlowingWater::getPayStasus,0); wq.between(TjFlowingWater::getUpdateTime, beginTime, endTime); Page page =new Page<>(pageNum,pageSize); Page waterPage = tjFlowingWaterService.page(page, wq); List list1 = waterPage.getRecords(); List list = tjFlowingWaterService.list(wq); for (TjFlowingWater tjFlowingWater : list1) { TjOrder tjOrder = tjOrderService.selectTjOrderByOrderId(tjFlowingWater.getOrderId()); TjCustomer customer = tjCustomerService.getById(tjOrder.getUserId()); tjFlowingWater.setCusName(MatchUtils.hideCusName(customer.getCusName())); } map.put("list", list1); map.put("total",waterPage.getTotal()); List> cc = new ArrayList<>(); //统计总集合 //付款方式 Map> m = list.stream().collect(Collectors.groupingBy(TjFlowingWater::getPayType)); BigDecimal zshoukuan = new BigDecimal("0.00"); BigDecimal ztuikuan = new BigDecimal("0.00"); BigDecimal zyingjiao = new BigDecimal("0.00"); for (Map.Entry> entry : m.entrySet()) { //查询付款方式字典 LambdaQueryWrapper wqq = new LambdaQueryWrapper<>(); wqq.eq(SysDictData::getDictType, "dict_pay_type"); wqq.eq(SysDictData::getDictValue, entry.getKey()); SysDictData one = dictDataService.getOne(wqq); if(null==one){ continue; } //收款金额 退款金额 应交款 BigDecimal shoukuan = new BigDecimal("0.00"); BigDecimal tuikuan = new BigDecimal("0.00"); BigDecimal yingjiao = new BigDecimal("0.00"); for (TjFlowingWater tjFlowingWater : entry.getValue()) { if(tjFlowingWater.getPayStasus()!=0 && tjFlowingWater.getPayStasus()!=2){ shoukuan = shoukuan.add(tjFlowingWater.getPaidIn()); } if (tjFlowingWater.getPayStasus()==2) { tuikuan = tuikuan.add(tjFlowingWater.getPaidIn()); } yingjiao = shoukuan.subtract(tuikuan.abs()); } zshoukuan=zshoukuan.add(shoukuan); ztuikuan=ztuikuan.add(tuikuan); zyingjiao=zyingjiao.add(yingjiao); Map aa = new HashMap<>(); ChargeStatisticsVo vo = new ChargeStatisticsVo(); vo.setShoukuan(shoukuan); vo.setTuikuan(tuikuan); if (zyingjiao.compareTo(BigDecimal.valueOf(0))<=0) { vo.setYingjiao(BigDecimal.valueOf(0.00)); }else{ vo.setYingjiao(yingjiao); } aa.put("paytpe", one.getDictValue()); aa.put("vo", vo); cc.add(aa); } map.put("zshoukuan",zshoukuan); map.put("ztuikuan",ztuikuan); if (zyingjiao.compareTo(BigDecimal.valueOf(0))<=0) { map.put("zyingjiao",BigDecimal.valueOf(0.00)); }else{ map.put("zyingjiao",zyingjiao); } map.put("all", cc); return AjaxResult.success(map); } @GetMapping("/getHzList") @ApiOperation(value = "查询汇总列表") public AjaxResult getHzList(@RequestParam(required = false) @ApiParam(value = "结账员") String tollCollector, @RequestParam(required = false) @ApiParam(value = "结账号") String accountId, @RequestParam(required = false) @ApiParam(value = "起始时间") Date accountBeginTime, @RequestParam(required = false) @ApiParam(value = "起始时间") Date accountEndTime, @ApiParam(value = "页码数(默认1)") @RequestParam(defaultValue = "1") Integer pageNum, @ApiParam(value = "显示条数(默认10)") @RequestParam(defaultValue = "10") Integer pageSize) { Page page=new Page<>(pageNum,pageSize); LambdaQueryWrapper wqq = new LambdaQueryWrapper<>(); if (null != accountBeginTime && null != accountEndTime) { wqq.between(TjTollCollector::getCreateTime, accountBeginTime, accountEndTime); } else { wqq.between(TjTollCollector::getCreateTime, DateUtil.lastMonth(),DateUtil.date()); } if(null !=tollCollector){ wqq.like(TjTollCollector::getTollCollector,tollCollector); } if(null !=accountId){ wqq.likeRight(TjTollCollector::getAccountId,accountId); } wqq.orderByDesc(TjTollCollector::getCreateTime); Page collectorPage = tjTollCollectorService.page(page,wqq); List list = collectorPage.getRecords(); List hzVoDomains=new ArrayList<>(); if (null != list && list.size() > 0) { for (TjTollCollector collector : list) { HzVoDomain voDomain=new HzVoDomain(); voDomain.setHzCard(collector.getAccountId()); voDomain.setEndTime(collector.getAccountEndTime()); voDomain.setBegTime(collector.getAccountBeginTime()); voDomain.setHzSj("汇总结账"); voDomain.setHzName(collector.getTollCollector()); voDomain.setAccountId(collector.getAccountId()); voDomain.setTollCollectorDetails(collectorDetailService.getTjTollCollectorDetailLists(collector.getAccountId())); hzVoDomains.add(voDomain); } } Map map=new HashMap<>(); map.put("list",hzVoDomains); map.put("total",collectorPage.getTotal()); return AjaxResult.success(map); } }