|
|
@@ -0,0 +1,220 @@
|
|
|
+package cn.iocoder.yudao.module.pms.controller.admin.iotoperationmeeting;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.ObjUtil;
|
|
|
+import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
+import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotoperationmeeting.vo.IotOperationMeetingPageReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotoperationmeeting.vo.IotOperationMeetingRespVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotoperationmeeting.vo.IotOperationMeetingSaveBatchVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotoperationmeeting.vo.IotOperationMeetingSaveReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotoperationmeetingdetail.vo.IotOperationMeetingDetailPageReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotoperationmeetingdetail.vo.IotOperationMeetingDetailRespVO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotoperationmeeting.IotOperationMeetingDO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotoperationmeetingdetail.IotOperationMeetingDetailDO;
|
|
|
+import cn.iocoder.yudao.module.pms.service.iotoperationmeeting.IotOperationMeetingService;
|
|
|
+import cn.iocoder.yudao.module.pms.service.iotoperationmeetingdetail.IotOperationMeetingDetailService;
|
|
|
+import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
|
|
+import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.Parameter;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import javax.validation.Valid;
|
|
|
+import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
|
|
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
|
|
+import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
|
|
|
+
|
|
|
+@Tag(name = "管理后台 - 生产运营会")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/pms/iot-operation-meeting")
|
|
|
+@Validated
|
|
|
+public class IotOperationMeetingController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IotOperationMeetingService iotOperationMeetingService;
|
|
|
+ @Resource
|
|
|
+ private IotOperationMeetingDetailService iotOperationMeetingDetailService;
|
|
|
+ @Resource
|
|
|
+ private DeptService deptService;
|
|
|
+
|
|
|
+ @PostMapping("/create")
|
|
|
+ @Operation(summary = "创建生产运营会")
|
|
|
+ @PreAuthorize("@ss.hasPermission('pms:iot-operation-meeting:create')")
|
|
|
+ public CommonResult<Long> createIotOperationMeeting(@Valid @RequestBody IotOperationMeetingSaveReqVO createReqVO) {
|
|
|
+ return success(iotOperationMeetingService.createIotOperationMeeting(createReqVO));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/saveBatch")
|
|
|
+ @Operation(summary = "创建生产运营会 主表+明细")
|
|
|
+ @PreAuthorize("@ss.hasPermission('pms:iot-operation-meeting:create')")
|
|
|
+ public CommonResult<Long> saveBatch(@Valid @RequestBody IotOperationMeetingSaveBatchVO saveBatchVO) {
|
|
|
+ return success(iotOperationMeetingService.saveBatch(saveBatchVO));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PutMapping("/update")
|
|
|
+ @Operation(summary = "更新生产运营会")
|
|
|
+ @PreAuthorize("@ss.hasPermission('pms:iot-operation-meeting:update')")
|
|
|
+ public CommonResult<Boolean> updateIotOperationMeeting(@Valid @RequestBody IotOperationMeetingSaveReqVO updateReqVO) {
|
|
|
+ iotOperationMeetingService.updateIotOperationMeeting(updateReqVO);
|
|
|
+ return success(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @DeleteMapping("/delete")
|
|
|
+ @Operation(summary = "删除生产运营会")
|
|
|
+ @Parameter(name = "id", description = "编号", required = true)
|
|
|
+ @PreAuthorize("@ss.hasPermission('pms:iot-operation-meeting:delete')")
|
|
|
+ public CommonResult<Boolean> deleteIotOperationMeeting(@RequestParam("id") Long id) {
|
|
|
+ iotOperationMeetingService.deleteIotOperationMeeting(id);
|
|
|
+ return success(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/get")
|
|
|
+ @Operation(summary = "获得生产运营会")
|
|
|
+ @Parameter(name = "id", description = "编号", required = true, example = "1024")
|
|
|
+ @PreAuthorize("@ss.hasPermission('pms:iot-operation-meeting:query')")
|
|
|
+ public CommonResult<IotOperationMeetingRespVO> getIotOperationMeeting(@RequestParam("id") Long id) {
|
|
|
+ IotOperationMeetingDO iotOperationMeeting = iotOperationMeetingService.getIotOperationMeeting(id);
|
|
|
+ return success(buildMeetingResp(iotOperationMeeting));
|
|
|
+ // return success(BeanUtils.toBean(iotOperationMeeting, IotOperationMeetingRespVO.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询 运营会 对应的明细
|
|
|
+ * @param operationMeeting
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private IotOperationMeetingRespVO buildMeetingResp(IotOperationMeetingDO operationMeeting) {
|
|
|
+ if (ObjUtil.isEmpty(operationMeeting)) {
|
|
|
+ return new IotOperationMeetingRespVO();
|
|
|
+ }
|
|
|
+
|
|
|
+ IotOperationMeetingRespVO meetingResp = BeanUtils.toBean(operationMeeting, IotOperationMeetingRespVO.class);
|
|
|
+ // 设置公司名称
|
|
|
+ Long deptId = operationMeeting.getDeptId();
|
|
|
+ DeptDO dept = deptService.getDept(deptId);
|
|
|
+ if (ObjUtil.isNotEmpty(dept)) {
|
|
|
+ meetingResp.setCompanyName(dept.getName());
|
|
|
+ }
|
|
|
+ // 查询运营会明细
|
|
|
+ IotOperationMeetingDetailPageReqVO pageReqVO = new IotOperationMeetingDetailPageReqVO();
|
|
|
+ pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
|
|
+ pageReqVO.setMeetingId(meetingResp.getId());
|
|
|
+ PageResult<IotOperationMeetingDetailDO> pageDetails = iotOperationMeetingDetailService.getIotOperationMeetingDetailPage(pageReqVO);
|
|
|
+ if (ObjUtil.isNotEmpty(pageDetails)) {
|
|
|
+ List<IotOperationMeetingDetailDO> details = pageDetails.getList();
|
|
|
+ List<IotOperationMeetingDetailRespVO> meetingDetails = BeanUtils.toBean(details, IotOperationMeetingDetailRespVO.class);
|
|
|
+ meetingResp.setDetails(meetingDetails);
|
|
|
+ }
|
|
|
+ return meetingResp;
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/page")
|
|
|
+ @Operation(summary = "获得生产运营会分页")
|
|
|
+ @PreAuthorize("@ss.hasPermission('pms:iot-operation-meeting:query')")
|
|
|
+ public CommonResult<PageResult<IotOperationMeetingRespVO>> getIotOperationMeetingPage(@Valid IotOperationMeetingPageReqVO pageReqVO) {
|
|
|
+ PageResult<IotOperationMeetingDO> pageResult = iotOperationMeetingService.getIotOperationMeetingPage(pageReqVO);
|
|
|
+ return success(new PageResult<>(buildMeetingDetails(pageResult.getList()), pageResult.getTotal()));
|
|
|
+ // return success(BeanUtils.toBean(pageResult, IotOperationMeetingRespVO.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置运营会明细相关的金额 收入 挂账 回款
|
|
|
+ * @param meetings 运营会列表
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<IotOperationMeetingRespVO> buildMeetingDetails(List<IotOperationMeetingDO> meetings) {
|
|
|
+ if (CollUtil.isEmpty(meetings)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ // 查询每个运营会关联的公司
|
|
|
+ Map<Long, DeptDO> deptPair = deptService.getDeptMap(convertList(meetings, IotOperationMeetingDO::getDeptId));
|
|
|
+ List<Long> meetingIds = convertList(meetings, IotOperationMeetingDO::getId);
|
|
|
+ IotOperationMeetingDetailPageReqVO pageReqVO = new IotOperationMeetingDetailPageReqVO();
|
|
|
+ pageReqVO.setMeetingIds(meetingIds);
|
|
|
+ pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
|
|
+ PageResult<IotOperationMeetingDetailDO> pageMeetingDetails = iotOperationMeetingDetailService.getIotOperationMeetingDetailPage(pageReqVO);
|
|
|
+ // 当期收入集合 key运营会id value明细本期收入累加和
|
|
|
+ Map<Long, BigDecimal> currentRevenuePair = new HashMap<>();
|
|
|
+ // 当期挂账集合 key运营会id value明细本期挂账累加和
|
|
|
+ Map<Long, BigDecimal> currentOnAccountPair = new HashMap<>();
|
|
|
+ // 当期回款集合 key运营会id value明细本期回款累加和
|
|
|
+ Map<Long, BigDecimal> currentPaymentPair = new HashMap<>();
|
|
|
+ if (ObjUtil.isNotEmpty(pageMeetingDetails)) {
|
|
|
+ List<IotOperationMeetingDetailDO> details = pageMeetingDetails.getList();
|
|
|
+ // 计算每个运营会明细的本期 收入 挂账 回款 累加和
|
|
|
+ if (CollUtil.isNotEmpty(details)) {
|
|
|
+ details.forEach(detail -> {
|
|
|
+ // 本期收入
|
|
|
+ if (ObjUtil.isNotEmpty(detail.getCurrentRevenue())) {
|
|
|
+ if (currentRevenuePair.containsKey(detail.getMeetingId())) {
|
|
|
+ BigDecimal existRevenue = currentRevenuePair.get(detail.getMeetingId());
|
|
|
+ BigDecimal tempRevenue = existRevenue.add(detail.getCurrentRevenue());
|
|
|
+ currentRevenuePair.put(detail.getMeetingId(), tempRevenue);
|
|
|
+ } else {
|
|
|
+ currentRevenuePair.put(detail.getMeetingId(), detail.getCurrentRevenue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 本期挂账
|
|
|
+ if (ObjUtil.isNotEmpty(detail.getCurrentOnAccount())) {
|
|
|
+ if (currentOnAccountPair.containsKey(detail.getMeetingId())) {
|
|
|
+ BigDecimal existOnAccount = currentOnAccountPair.get(detail.getMeetingId());
|
|
|
+ BigDecimal tempOnAccount = existOnAccount.add(detail.getCurrentOnAccount());
|
|
|
+ currentOnAccountPair.put(detail.getMeetingId(), tempOnAccount);
|
|
|
+ } else {
|
|
|
+ currentOnAccountPair.put(detail.getMeetingId(), detail.getCurrentOnAccount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 本期回款
|
|
|
+ if (ObjUtil.isNotEmpty(detail.getCurrentPayment())) {
|
|
|
+ if (currentPaymentPair.containsKey(detail.getMeetingId())) {
|
|
|
+ BigDecimal existPayment = currentPaymentPair.get(detail.getMeetingId());
|
|
|
+ BigDecimal tempPayment = existPayment.add(detail.getCurrentPayment());
|
|
|
+ currentPaymentPair.put(detail.getMeetingId(), tempPayment);
|
|
|
+ } else {
|
|
|
+ currentPaymentPair.put(detail.getMeetingId(), detail.getCurrentPayment());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 查询每个运营会对应的明细中的 本期 收入 挂账 回款 金额 总和
|
|
|
+ return BeanUtils.toBean(meetings, IotOperationMeetingRespVO.class, (meetingVO) -> {
|
|
|
+ findAndThen(deptPair, meetingVO.getDeptId(), dept -> meetingVO.setCompanyName(dept.getName()));
|
|
|
+ findAndThen(currentRevenuePair, meetingVO.getId(), currentRevenue -> meetingVO.setCurrentRevenue(currentRevenue));
|
|
|
+ findAndThen(currentOnAccountPair, meetingVO.getId(), currentOnAccount -> meetingVO.setCurrentOnAccount(currentOnAccount));
|
|
|
+ findAndThen(currentPaymentPair, meetingVO.getId(), currentPayment -> meetingVO.setCurrentPayment(currentPayment));
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/export-excel")
|
|
|
+ @Operation(summary = "导出生产运营会 Excel")
|
|
|
+ @PreAuthorize("@ss.hasPermission('pms:iot-operation-meeting:export')")
|
|
|
+ @ApiAccessLog(operateType = EXPORT)
|
|
|
+ public void exportIotOperationMeetingExcel(@Valid IotOperationMeetingPageReqVO pageReqVO,
|
|
|
+ HttpServletResponse response) throws IOException {
|
|
|
+ pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
|
|
+ List<IotOperationMeetingDO> list = iotOperationMeetingService.getIotOperationMeetingPage(pageReqVO).getList();
|
|
|
+ // 导出 Excel
|
|
|
+ ExcelUtils.write(response, "生产运营会.xls", "数据", IotOperationMeetingRespVO.class,
|
|
|
+ BeanUtils.toBean(list, IotOperationMeetingRespVO.class));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|