| | |
| | | import com.ruoyi.chargingPile.service.TChargingPileService; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.dto.SteategyPassDto; |
| | | import com.ruoyi.common.core.enums.AuditStateEnum; |
| | | import com.ruoyi.common.core.web.domain.AjaxResult; |
| | | import com.ruoyi.common.core.web.domain.BaseDelete; |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | |
| | | import java.time.LocalTime; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | import static com.ruoyi.common.core.context.SecurityContextHolder.getUserId; |
| | | |
| | |
| | | // 添加明细 |
| | | dto.getAccountingStrategyDetails().forEach(detail -> detail.setAccountingStrategyId(dto.getId())); |
| | | accountingStrategyDetailService.saveBatch(dto.getAccountingStrategyDetails()); |
| | | // TODO 硬件 同步策略到充电桩 |
| | | return AjaxResult.ok(dto.getId()); |
| | | } |
| | | |
| | |
| | | @Log(title = "修改计费策略", businessType = BusinessType.UPDATE,operatorType = OperatorType.MANAGE) |
| | | @ApiOperation(tags = {"后台-计费策略", "管理后台-站点管理"},value = "修改计费策略") |
| | | @PostMapping(value = "/update") |
| | | public AjaxResult<Boolean> update(@RequestBody TAccountingStrategyDTO dto) { |
| | | public AjaxResult<String> update(@RequestBody TAccountingStrategyDTO dto) { |
| | | Boolean flag = accountingStrategyDetailService.isStrategy24Hour(dto.getAccountingStrategyDetails()); |
| | | if(flag){ |
| | | return AjaxResult.error("计费模板时间设置有误差"); |
| | | } |
| | | // 判断修改的计费策略是否为已通过 |
| | | if(dto.getAuditStatus() == 3 || dto.getAuditStatus() == 4){ |
| | | // 查询是否有下级审核中的策略 |
| | | TAccountingStrategy children = accountingStrategyService.getOne(Wrappers.lambdaQuery(TAccountingStrategy.class) |
| | | .eq(TAccountingStrategy::getParentId, dto.getId()) |
| | | .ne(TAccountingStrategy::getAuditStatus, Arrays.asList(3,4))); |
| | | if(Objects.nonNull(children)){ |
| | | // 删除计费策略明细信息 |
| | | accountingStrategyDetailService.remove(Wrappers.lambdaQuery(TAccountingStrategyDetail.class) |
| | | .eq(TAccountingStrategyDetail::getAccountingStrategyId, dto.getId())); |
| | | .eq(TAccountingStrategyDetail::getAccountingStrategyId, children.getId())); |
| | | dto.setAuditStatus(1); |
| | | accountingStrategyService.updateById(dto); |
| | | // 添加明细 |
| | | dto.getAccountingStrategyDetails().forEach(detail -> detail.setAccountingStrategyId(dto.getId())); |
| | | // TODO 硬件 同步策略到充电桩 |
| | | return AjaxResult.ok(accountingStrategyDetailService.saveBatch(dto.getAccountingStrategyDetails())); |
| | | accountingStrategyDetailService.saveBatch(dto.getAccountingStrategyDetails()); |
| | | }else { |
| | | Long userId = SecurityUtils.getLoginUser().getUserid(); |
| | | dto.setUserId(userId); |
| | | dto.setAuditStatus(1); |
| | | dto.setId(null); |
| | | dto.setParentId(dto.getId()); |
| | | accountingStrategyService.save(dto); |
| | | // 添加明细 |
| | | List<TAccountingStrategyDetail> accountingStrategyDetails = dto.getAccountingStrategyDetails(); |
| | | accountingStrategyDetails.forEach(detail -> { |
| | | detail.setAccountingStrategyId(dto.getId()); |
| | | detail.setId(null); |
| | | }); |
| | | accountingStrategyDetailService.saveBatch(accountingStrategyDetails); |
| | | } |
| | | }else { |
| | | // 删除计费策略明细信息 |
| | | accountingStrategyDetailService.remove(Wrappers.lambdaQuery(TAccountingStrategyDetail.class) |
| | | .eq(TAccountingStrategyDetail::getAccountingStrategyId, dto.getId())); |
| | | dto.setAuditStatus(1); |
| | | accountingStrategyService.updateById(dto); |
| | | // 添加明细 |
| | | dto.getAccountingStrategyDetails().forEach(detail -> detail.setAccountingStrategyId(dto.getId())); |
| | | accountingStrategyDetailService.saveBatch(dto.getAccountingStrategyDetails()); |
| | | } |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 查看计费策略详情-修改后 |
| | | */ |
| | | @ApiOperation(tags = {"后台-计费策略", "管理后台-站点管理"},value = "查看计费策略详情修改后children的数据") |
| | | @GetMapping(value = "/getDetailChildrenById") |
| | | public AjaxResult<TAccountingStrategyVO> getDetailChildrenById(@RequestParam("id") Integer id) { |
| | | TAccountingStrategyVO accountingStrategyVO = new TAccountingStrategyVO(); |
| | | // 先查询children对象 |
| | | TAccountingStrategy children = accountingStrategyService.getOne(Wrappers.lambdaQuery(TAccountingStrategy.class) |
| | | .eq(TAccountingStrategy::getParentId, id) |
| | | .orderByDesc(TAccountingStrategy::getCreateTime) |
| | | .last("LIMIT 1")); |
| | | if(Objects.nonNull(children)){ |
| | | BeanUtils.copyProperties(children,accountingStrategyVO); |
| | | // 查询用户信息 |
| | | if(null != children.getFirstUserId()){ |
| | | String firstUserName = sysUserClient.getSysUser(children.getFirstUserId()).getData().getNickName(); |
| | | accountingStrategyVO.setFirstUserName(firstUserName); |
| | | } |
| | | if(null != children.getTwoUserId()){ |
| | | String twoUserName = sysUserClient.getSysUser(children.getTwoUserId()).getData().getNickName(); |
| | | accountingStrategyVO.setTwoUserName(twoUserName); |
| | | } |
| | | accountingStrategyVO.setAccountingStrategyDetailList(accountingStrategyDetailService.list(Wrappers.lambdaQuery(TAccountingStrategyDetail.class) |
| | | .eq(TAccountingStrategyDetail::getAccountingStrategyId, children.getId()))); |
| | | }else { |
| | | TAccountingStrategy accountingStrategy = accountingStrategyService.getById(id); |
| | | BeanUtils.copyProperties(accountingStrategy,accountingStrategyVO); |
| | | // 查询用户信息 |
| | | if(null != accountingStrategy.getFirstUserId()){ |
| | | String firstUserName = sysUserClient.getSysUser(accountingStrategy.getFirstUserId()).getData().getNickName(); |
| | | accountingStrategyVO.setFirstUserName(firstUserName); |
| | | } |
| | | if(null != accountingStrategy.getTwoUserId()){ |
| | | String twoUserName = sysUserClient.getSysUser(accountingStrategy.getTwoUserId()).getData().getNickName(); |
| | | accountingStrategyVO.setTwoUserName(twoUserName); |
| | | } |
| | | accountingStrategyVO.setAccountingStrategyDetailList(accountingStrategyDetailService.list(Wrappers.lambdaQuery(TAccountingStrategyDetail.class) |
| | | .eq(TAccountingStrategyDetail::getAccountingStrategyId, id))); |
| | | } |
| | | return AjaxResult.ok(accountingStrategyVO); |
| | | } |
| | | |
| | | /** |
| | | * 删除计费策略 |
| | | */ |
| | | @Log(title = "删除计费策略", businessType = BusinessType.DELETE,operatorType = OperatorType.MANAGE) |
| | | @ApiOperation(tags = {"后台-计费策略"},value = "删除计费策略") |
| | | @DeleteMapping(value = "/deleteById") |
| | | public AjaxResult<Boolean> deleteById(@RequestParam("id") Integer id) { |
| | | // 判断策略是否在使用 |
| | | long count = siteService.count(Wrappers.lambdaQuery(Site.class) |
| | | .eq(Site::getAccountingStrategyId, id)); |
| | | if(count>0){ |
| | | return AjaxResult.error("该计费策略正在使用中,无法删除"); |
| | | } |
| | | // 刪除计费策略明细信息 |
| | | accountingStrategyDetailService.remove(Wrappers.lambdaQuery(TAccountingStrategyDetail.class) |
| | | .eq(TAccountingStrategyDetail::getAccountingStrategyId, id)); |
| | |
| | | @DeleteMapping(value = "/deleteByIds") |
| | | public AjaxResult<Boolean> deleteByIds(@RequestParam String ids) { |
| | | String[] split = ids.split(","); |
| | | // 判断策略是否在使用 |
| | | long count = siteService.count(Wrappers.lambdaQuery(Site.class) |
| | | .in(Site::getAccountingStrategyId, Arrays.asList(split))); |
| | | if(count>0){ |
| | | return AjaxResult.error("该计费策略正在使用中,无法删除"); |
| | | } |
| | | // 刪除计费策略明细信息 |
| | | accountingStrategyDetailService.remove(Wrappers.lambdaQuery(TAccountingStrategyDetail.class) |
| | | .in(TAccountingStrategyDetail::getAccountingStrategyId, Arrays.asList(split))); |