|
|
@@ -0,0 +1,229 @@
|
|
|
+/*
|
|
|
+ * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
|
|
+ *
|
|
|
+ * Redistribution and use in source and binary forms, with or without
|
|
|
+ * modification, are permitted provided that the following conditions are met:
|
|
|
+ *
|
|
|
+ * Redistributions of source code must retain the above copyright notice,
|
|
|
+ * this list of conditions and the following disclaimer.
|
|
|
+ * Redistributions in binary form must reproduce the above copyright
|
|
|
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
+ * documentation and/or other materials provided with the distribution.
|
|
|
+ * Neither the name of the dreamlu.net developer nor the names of its
|
|
|
+ * contributors may be used to endorse or promote products derived from
|
|
|
+ * this software without specific prior written permission.
|
|
|
+ * Author: Chill 庄骞 (smallchill@163.com)
|
|
|
+ */
|
|
|
+package org.springblade.cargo.parities.controller;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import io.swagger.annotations.ApiParam;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springblade.cargo.parities.entity.Parities;
|
|
|
+import org.springblade.cargo.parities.entity.ParitiesItem;
|
|
|
+import org.springblade.cargo.parities.service.IParitiesItemService;
|
|
|
+import org.springblade.cargo.parities.service.IParitiesService;
|
|
|
+import org.springblade.cargo.parities.vo.ParitiesVO;
|
|
|
+import org.springblade.core.boot.ctrl.BladeController;
|
|
|
+import org.springblade.core.mp.support.Condition;
|
|
|
+import org.springblade.core.mp.support.Query;
|
|
|
+import org.springblade.core.secure.utils.SecureUtil;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.utils.Func;
|
|
|
+import org.springblade.system.user.entity.User;
|
|
|
+import org.springblade.system.user.feign.IUserClient;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.validation.Valid;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 汇率管理主表 控制器
|
|
|
+ *
|
|
|
+ * @author BladeX
|
|
|
+ * @since 2022-03-22
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@AllArgsConstructor
|
|
|
+@RequestMapping("/parities")
|
|
|
+@Api(value = "汇率管理主表", tags = "汇率管理主表接口")
|
|
|
+public class ParitiesController extends BladeController {
|
|
|
+
|
|
|
+ private final IParitiesService paritiesService;
|
|
|
+ private final IParitiesItemService paritiesItemService;
|
|
|
+ private final IUserClient userClient;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 详情
|
|
|
+ */
|
|
|
+ @GetMapping("/detail")
|
|
|
+ @ApiOperationSupport(order = 1)
|
|
|
+ @ApiOperation(value = "详情", notes = "传入parities")
|
|
|
+ public R<Parities> detail(Parities parities) {
|
|
|
+ parities.setTenantId(SecureUtil.getTenantId());
|
|
|
+ Parities detail = paritiesService.getOne(Condition.getQueryWrapper(parities));
|
|
|
+ if (detail != null){
|
|
|
+ //获取明细数据
|
|
|
+ LambdaQueryWrapper<ParitiesItem> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(ParitiesItem::getPid,detail.getId());
|
|
|
+ lambdaQueryWrapper.eq(ParitiesItem::getIsDeleted,0);
|
|
|
+ lambdaQueryWrapper.eq(ParitiesItem::getTenantId, SecureUtil.getTenantId());
|
|
|
+ detail.setParitiesItemList(paritiesItemService.list(lambdaQueryWrapper));
|
|
|
+ }
|
|
|
+ return R.data(detail);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页 汇率管理主表
|
|
|
+ */
|
|
|
+ @GetMapping("/list")
|
|
|
+ @ApiOperationSupport(order = 2)
|
|
|
+ @ApiOperation(value = "分页", notes = "传入parities")
|
|
|
+ public R<IPage<Parities>> list(Parities parities, Query query) {
|
|
|
+ parities.setTenantId(SecureUtil.getTenantId());
|
|
|
+ IPage<Parities> pages = paritiesService.page(Condition.getPage(query), Condition.getQueryWrapper(parities));
|
|
|
+ if (CollectionUtils.isNotEmpty(pages.getRecords())){
|
|
|
+ pages.getRecords().stream().forEach(item ->{
|
|
|
+ R<User> create = userClient.userInfoById(item.getCreateUser());
|
|
|
+ if (create.isSuccess() && create.getData() != null){
|
|
|
+ item.setCreateUserName(create.getData().getName());
|
|
|
+ }
|
|
|
+ if (item.getUpdateUser() !=null){
|
|
|
+ R<User> update = userClient.userInfoById(item.getUpdateUser());
|
|
|
+ if (update.isSuccess() && update.getData() != null){
|
|
|
+ item.setUpdateUserName(update.getData().getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return R.data(pages);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 自定义分页 汇率管理主表
|
|
|
+ */
|
|
|
+ @GetMapping("/page")
|
|
|
+ @ApiOperationSupport(order = 3)
|
|
|
+ @ApiOperation(value = "分页", notes = "传入parities")
|
|
|
+ public R<IPage<Parities>> page(Parities parities, Query query) {
|
|
|
+ parities.setTenantId(SecureUtil.getTenantId());
|
|
|
+ IPage<Parities> pages = paritiesService.page(Condition.getPage(query), Condition.getQueryWrapper(parities));
|
|
|
+ if (CollectionUtils.isNotEmpty(pages.getRecords())){
|
|
|
+ pages.getRecords().stream().forEach(item ->{
|
|
|
+ R<User> create = userClient.userInfoById(item.getCreateUser());
|
|
|
+ if (create.isSuccess() && create.getData() != null){
|
|
|
+ item.setCreateUserName(create.getData().getName());
|
|
|
+ }
|
|
|
+ if (item.getUpdateUser() !=null){
|
|
|
+ R<User> update = userClient.userInfoById(item.getUpdateUser());
|
|
|
+ if (update.isSuccess() && update.getData() != null){
|
|
|
+ item.setUpdateUserName(update.getData().getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return R.data(pages);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增 汇率管理主表
|
|
|
+ */
|
|
|
+ @PostMapping("/save")
|
|
|
+ @ApiOperationSupport(order = 4)
|
|
|
+ @ApiOperation(value = "新增", notes = "传入parities")
|
|
|
+ public R save(@Valid @RequestBody Parities parities) {
|
|
|
+ return R.status(paritiesService.save(parities));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改 汇率管理主表
|
|
|
+ */
|
|
|
+ @PostMapping("/update")
|
|
|
+ @ApiOperationSupport(order = 5)
|
|
|
+ @ApiOperation(value = "修改", notes = "传入parities")
|
|
|
+ public R update(@Valid @RequestBody Parities parities) {
|
|
|
+ return R.status(paritiesService.updateById(parities));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增或修改 汇率管理主表
|
|
|
+ */
|
|
|
+ @PostMapping("/submit")
|
|
|
+ @ApiOperationSupport(order = 6)
|
|
|
+ @ApiOperation(value = "新增或修改", notes = "传入parities")
|
|
|
+ public R submit(@Valid @RequestBody Parities parities) {
|
|
|
+ if (StringUtils.isBlank(parities.getCname())){
|
|
|
+ throw new SecurityException("货币名称不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(parities.getCode())){
|
|
|
+ throw new SecurityException("货币币别不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(parities.getAnnual())){
|
|
|
+ throw new SecurityException("汇率年度不能为空");
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<Parities> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(Parities::getCode,parities.getCode());
|
|
|
+ lambdaQueryWrapper.eq(Parities::getAnnual,parities.getAnnual());
|
|
|
+ lambdaQueryWrapper.eq(Parities::getTenantId,SecureUtil.getTenantId());
|
|
|
+ lambdaQueryWrapper.eq(Parities::getIsDeleted,0);
|
|
|
+ Parities serviceOne = paritiesService.getOne(lambdaQueryWrapper);
|
|
|
+ if (parities.getId() ==null && serviceOne !=null){
|
|
|
+ throw new SecurityException("该年度的货币汇率已存在");
|
|
|
+ }
|
|
|
+ if (parities.getId() !=null && serviceOne !=null && parities.getId().longValue() != serviceOne.getId().longValue()){
|
|
|
+ throw new SecurityException("该年度的货币汇率已存在");
|
|
|
+ }
|
|
|
+ return R.data(paritiesService.saveParities(parities));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除 汇率管理主表
|
|
|
+ */
|
|
|
+ @PostMapping("/remove")
|
|
|
+ @ApiOperationSupport(order = 8)
|
|
|
+ @ApiOperation(value = "删除", notes = "传入ids")
|
|
|
+ public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
|
|
|
+ return R.status(paritiesService.removeByIds(Func.toLongList(ids)));
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 新增 汇率管理主表
|
|
|
+ */
|
|
|
+ @PostMapping("/getParities")
|
|
|
+ @ApiOperationSupport(order = 9)
|
|
|
+ @ApiOperation(value = "业务获取汇率", notes = "传入currency 币别 businesDate 业务日期")
|
|
|
+ public R getParities(@Valid @RequestBody ParitiesVO parities) {
|
|
|
+ if (StringUtils.isBlank(parities.getCurrency())){
|
|
|
+ throw new SecurityException("缺少必要的参数币别,请选择币别");
|
|
|
+ }
|
|
|
+ if (parities.getBusinesDate() == null){
|
|
|
+ throw new SecurityException("缺少必要的参数业务日期,请选择业务日期");
|
|
|
+ }
|
|
|
+ return R.data(paritiesService.getParities(parities));
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 业务获取币别
|
|
|
+ */
|
|
|
+ @GetMapping("/getCode")
|
|
|
+ @ApiOperationSupport(order = 10)
|
|
|
+ @ApiOperation(value = "业务获取币别", notes = "传入parities")
|
|
|
+ public R<List<String>> getCode(Parities parities) {
|
|
|
+ parities.setTenantId(SecureUtil.getTenantId());
|
|
|
+ List<Parities> paritiesList = paritiesService.list(Condition.getQueryWrapper(parities));
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ if (CollectionUtils.isNotEmpty(paritiesList)){
|
|
|
+ list = paritiesList.stream().filter(e -> StringUtils.isNotBlank(e.getCode())).map(Parities::getCode).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ return R.data(list);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|