Commit a917fcfd by huluobin

update

parent a037eb85
......@@ -14,6 +14,7 @@ public class CostPlanTempDto {
private String fileName; // 文件名
private BigDecimal amount; // 费用总金额
private String costReason; // 付款理由
private String typeNameDto; // 大类标题
private String kindNameDto; // 小类标题
private String dic; // 币种
......
......@@ -66,7 +66,7 @@ public class CostPlanController {
AxiosUtil.setCors(response, request);
String costPlanNo = request.getParameter("costPlanNo");
List<CostPlanTempDto> tempListByPlanNo = costPlanTempService.getTempListByPlanNo(costPlanNo);
List<CostPlanTempDto> tempListByPlanNo = costPlanTempService.getTempListByPlanNo(costPlanNo).getTemps();
BigDecimal planAmount = new BigDecimal(0);
if (null != tempListByPlanNo && tempListByPlanNo.size() >= 1) {
for (CostPlanTempDto dto : tempListByPlanNo) {
......
......@@ -37,7 +37,7 @@ public class CostPlanNewReceiptController {
Map<String, Object> result = new HashMap<>();
String planNo = request.getParameter("costPlanNo");
CostPlanDomain costPlanDomain = costPlanService.getByPlanNo(planNo);
CostPlanDomain costPlanDomain = costPlanService.getByPlanNo(planNo).getCostPlan();
if (null != costPlanDomain) {
result.put("success", false);
return result;
......@@ -70,7 +70,7 @@ public class CostPlanNewReceiptController {
Map<String, Object> result = new HashMap<>();
String planNo = request.getParameter("costPlanNo");
CostPlanDomain costPlanDomain = costPlanService.getByPlanNo(planNo);
CostPlanDomain costPlanDomain = costPlanService.getByPlanNo(planNo).getCostPlan();
if (null != costPlanDomain) {
result.put("success", false);
return result;
......
package com.blt.other.cost.controller.costplan;
import com.bailuntec.cost.api.dto.CostPlanTempDto;
import com.blt.other.commons.utils.AxiosUtil;
import com.blt.other.commons.utils.CurUtils;
import com.blt.other.commons.utils.PathUtil;
import com.blt.other.cost.dto.CostPlanTempApiDto;
import com.blt.other.cost.service.CostPlanService;
import com.blt.other.cost.service.CostPlanTempService;
import com.blt.other.cost.service.CostTypeKindService;
import com.blt.other.cost.utils.CostFileUtil;
import com.blt.other.database.model.CostPlanDomain;
import com.blt.other.database.model.CostPlanTempDomain;
import com.blt.other.database.model.CostTypeKindDomain;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.InputStreamResource;
......@@ -22,36 +13,25 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Api(tags = "费用计划模版接口")
@Api(tags = "费用计划子项接口")
@RestController
@RequestMapping("/cost/plan/temp")
@Slf4j
public class CostPlanTempController {
@Autowired
private CostPlanTempService costPlanTempService;
@Autowired
private CostTypeKindService costTypeKindService;
@Autowired
private CostPlanService costPlanService;
@ApiOperation("保存无附件费用计划模版")
@ApiOperation("保存无附件费用计划子项")
@PostMapping("/addItem/noFile")
public CostPlanTempApiDto.AddItemResp noFile(CostPlanTempApiDto.AddItemReq req) {
try {
return costPlanTempService.doSave(req);
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
CostPlanTempApiDto.AddItemResp resp = new CostPlanTempApiDto.AddItemResp();
resp.setSuccess(false);
resp.setMsg(ex.getMessage());
......@@ -59,7 +39,7 @@ public class CostPlanTempController {
}
}
@ApiOperation("保存有附件费用计划模版")
@ApiOperation("保存有附件费用计划子项")
@PostMapping("/addItem/file")
public CostPlanTempApiDto.AddItemResp file(CostPlanTempApiDto.AddItemReq req) {
try {
......@@ -72,74 +52,43 @@ public class CostPlanTempController {
}
}
@ApiOperation("获取费用计划编号对应的费用计划模版列表")
@ApiOperation("获取费用计划编号对应的费用计划子项")
@GetMapping("/getCostTempByPlanNo")
public CostPlanTempApiDto.GetCostTempByPlanNoResp getCostTempByPlanNo(@RequestParam String costPlanNo) {
List<CostPlanTempDto> temps = costPlanTempService.getTempListByPlanNo(costPlanNo);
if (null != temps && temps.size() >= 1) {
BigDecimal planAmount = new BigDecimal(0);
BigDecimal cur;
for (CostPlanTempDto tempDto : temps) {
cur = CurUtils.getCur(tempDto.getDic(), "CNY", getExchangeRateApi);
planAmount = planAmount.add(tempDto.getAmount().multiply(cur));
}
result.put("planAmount", planAmount);
}
result.put("success", true);
result.put("temps", temps);
return costPlanTempService.getTempListByPlanNo(costPlanNo);
}
@ApiOperation("删除费用计划模版行项目")
@ApiOperation("删除费用计划子项")
@PostMapping("/deleteItem")
public Map<String, Object> deleteItem(HttpServletResponse response, HttpServletRequest request) {
AxiosUtil.setCors(response, request);
Map<String, Object> result = new HashMap<>();
public CostPlanTempApiDto.DeleteItemResp deleteItem(@RequestParam String costPlanNo,
@RequestParam String tempNo) {
String costPlanNo = request.getParameter("costPlanNo");
String planAmountStr = request.getParameter("planAmount");
BigDecimal planAmount = null;
if (null == planAmountStr || planAmountStr.isEmpty()) {
planAmount = new BigDecimal(0);
} else {
planAmount = new BigDecimal(planAmountStr);
}
String tempNo = request.getParameter("tempNo");
CostPlanTempDomain planTemp = costPlanTempService.getByPlanNoAndTempNo(costPlanNo, tempNo);
Integer deleted = costPlanTempService.deleteItemByPlanNoAndTempNo(costPlanNo, tempNo);
if (null != deleted && deleted >= 0) {
result.put("success", true);
result.put("msg", "已删除");
result.put("deleted", deleted);
if (null != planTemp && null != planTemp.getAmount()) {
planAmount = planAmount.subtract(planTemp.getAmount());
}
result.put("planAmount", planAmount);
}
return result;
BigDecimal planAmount = costPlanTempService.deleteItemByPlanNoAndTempNo(costPlanNo, tempNo);
CostPlanTempApiDto.DeleteItemResp resp = new CostPlanTempApiDto.DeleteItemResp();
resp.setSuccess(true);
resp.setMsg("success");
resp.setPlanAmount(planAmount);
return resp;
}
@ApiOperation("下载费用单项附件")
@GetMapping("download")
public ResponseEntity<InputStreamResource> download(HttpServletRequest request, HttpServletResponse response) throws IOException {
// AxiosUtil.setCors(response,request);
String tempNo = request.getParameter("tempNo");
public ResponseEntity<InputStreamResource> download(@RequestParam String tempNo) throws IOException {
CostPlanTempDomain temp = costPlanTempService.getByTempNo(tempNo);
String filePath = null;
String filePath = temp.getFilePath();
String fileName = null;
if (null != temp) {
filePath = temp.getFilePath();
if (null != filePath) {
String[] split = filePath.split("&");
if (null != split && split.length >= 1) {
if (split.length >= 1) {
fileName = split[split.length - 1];
}
}
}
assert filePath != null;
FileSystemResource file = new FileSystemResource(filePath);
HttpHeaders headers = new HttpHeaders();
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
......@@ -158,134 +107,36 @@ public class CostPlanTempController {
@ApiOperation("根据费用计划模板编号获取费用计划模版")
@GetMapping("/getByTempNo")
public Map<String, Object> getByTempNo(HttpServletResponse response, HttpServletRequest request) {
AxiosUtil.setCors(response, request);
String tempNo = request.getParameter("tempNo");
CostPlanTempDomain byTempNo = costPlanTempService.getByTempNo(tempNo);
Map<String, Object> result = new HashMap<>();
CostPlanTempDto dto = new CostPlanTempDto();
BeanUtils.copyProperties(byTempNo, dto);
dto.setFileName(PathUtil.getFileName(dto.getFilePath()));
CostTypeKindDomain kindByKindNo = costTypeKindService.getKindByKindNo(dto.getKindNo());
if (null != kindByKindNo) {
dto.setTypeNameDto(kindByKindNo.getTypeName());
dto.setKindNameDto(kindByKindNo.getKindName());
}
result.put("tmp", dto);
return result;
public CostPlanTempApiDto.GetByTempNoResp getByTempNo(@RequestParam String tempNo) {
CostPlanTempDomain domain = costPlanTempService.getByTempNo(tempNo);
CostPlanTempApiDto.GetByTempNoResp resp = new CostPlanTempApiDto.GetByTempNoResp();
resp.setTmp(domain.castToDto());
return resp;
}
@ApiOperation("更新费用项(无附件)")
@PostMapping("/resetItem/noFile")
public Map<String, Object> resetNoFile(HttpServletResponse response, HttpServletRequest request) {
AxiosUtil.setCors(response, request);
CostPlanTempDomain domain = createDomain(request);
CostTypeKindDomain kindByKindNo = costTypeKindService.getKindByKindNo(domain.getKindNo());
domain.setTypeNo(kindByKindNo.getTypeNo());
String delecteFile = request.getParameter("delecteFile");
String tempNo = request.getParameter("tempNo");
domain.setTempNo(tempNo);
boolean b = Boolean.parseBoolean(delecteFile);
if (b) {
costPlanTempService.deleteFilePath(domain.getTempNo());
}
Map<String, Object> result = new HashMap<>();
result.put("success", true);
public CostPlanTempApiDto.ResetItemResp resetNoFile(CostPlanTempApiDto.ResetItemReq req) {
// result = checkResetKind(result, domain);
result = chalkResetDec(result, domain);
if (!(boolean) result.get("success")) {
return result;
}
// 同步更新费用计划金额
CostPlanTempDomain byTempNo = costPlanTempService.getByTempNo(tempNo);
Integer update = costPlanTempService.update(domain);
result.put("tmp", domain);
if (null != update && update >= 1) {
List<CostPlanTempDto> tempListByPlanNo = costPlanTempService.getTempListByPlanNo(byTempNo.getCostPlanNo());
if (null != tempListByPlanNo && tempListByPlanNo.size() >= 1) {
CostPlanDomain plan = costPlanService.getByPlanNo(byTempNo.getCostPlanNo());
if (null != plan) {
BigDecimal newAmount = new BigDecimal(0);
for (CostPlanTempDto tmp : tempListByPlanNo) {
newAmount = newAmount.add(tmp.getAmount());
}
plan.setPlanAmount(newAmount);
if (1 == plan.getCostForm() && (null != plan.getIsLend() && 2 == plan.getIsLend())) {
plan.setPayPlanAmount(newAmount.divide(plan.getPayCur(), 4));
}
costPlanService.update(plan);
}
}
result.put("tmp", domain);
}
return result;
CostPlanTempDomain tmp = costPlanTempService.resetItem(req);
CostPlanTempApiDto.ResetItemResp resp = new CostPlanTempApiDto.ResetItemResp();
resp.setSuccess(true);
resp.setTmp(tmp);
return resp;
}
/**
* 修改时判断是否存在相同的付款小类
*
* @param result
* @param domain
* @return
*/
private Map<String, Object> chalkResetDec(Map<String, Object> result, CostPlanTempDomain domain) {
// 改变币种,判断是否存在大类相同,币种不同的情况
CostPlanTempDomain byTempNo = costPlanTempService.getByTempNo(domain.getTempNo());
if (null != byTempNo && null != byTempNo.getTypeNo()) {
if (byTempNo.getTypeNo().equals(domain.getTypeNo())) {
// 大类无变化,改币种
List<CostPlanTempDomain> listByPlanNoAndTypeNo = costPlanTempService.getListByPlanNoAndTypeNo(domain.getCostPlanNo(), domain.getTypeNo());
if (null != listByPlanNoAndTypeNo && listByPlanNoAndTypeNo.size() > 1) {
// 该大类有多条记录,不允许改币种
if (!listByPlanNoAndTypeNo.get(0).getDic().equals(domain.getDic())) {
result.put("success", false);
result.put("msg", "该大类有多条记录,请保持币种一致");
return result;
}
}
} else {
// 修改大类,改币种 / 修改大类,未改币种
List<CostPlanTempDomain> listByPlanNoAndTypeNo = costPlanTempService.getListByPlanNoAndTypeNo(domain.getCostPlanNo(), domain.getTypeNo());
if (null != listByPlanNoAndTypeNo && listByPlanNoAndTypeNo.size() >= 1) {
if (!listByPlanNoAndTypeNo.get(0).getDic().equals(domain.getDic())) {
result.put("success", false);
result.put("msg", "该大类有多条记录,请保持币种一致");
return result;
}
}
}
}
return result;
}
@ApiOperation("更新费用项(有附件)")
@PostMapping("/resetItem/file")
public Map<String, Object> resetFile(HttpServletResponse response, HttpServletRequest request, @RequestParam("fileSelect2") MultipartFile file) {
AxiosUtil.setCors(response, request);
CostPlanTempDomain domain = createDomain(request);
public CostPlanTempApiDto.ResetItemResp resetFile(CostPlanTempApiDto.ResetItemReq req) {
CostPlanTempDomain tmp = costPlanTempService.resetItem(req);
CostPlanTempApiDto.ResetItemResp resp = new CostPlanTempApiDto.ResetItemResp();
resp.setSuccess(true);
resp.setTmp(tmp);
return resp;
String tempNo = request.getParameter("tempNo");
domain.setTempNo(tempNo);
// 文件上传的路径
String filePath = PathUtil.getBasePath() + PathUtil.getPath("cost/" + domain.getTempNo() + "/");
// 调用工具类执行保存,并返回 path
String path = CostFileUtil.upload(file, filePath);
domain.setFilePath(path);
Map<String, Object> result = new HashMap<>();
result.put("success", true);
chalkResetDec(result, domain);
if (!(boolean) result.get("success")) {
return result;
}
Integer update = costPlanTempService.update(domain);
if (null != update && update >= 1) {
result.put("tmp", domain);
}
return result;
}
}
......@@ -2,6 +2,7 @@ package com.blt.other.cost.dto;
import com.bailuntec.cost.api.dto.CostPlanTempDto;
import com.blt.other.database.model.CostPlanTempDomain;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
......@@ -18,6 +19,7 @@ import java.util.List;
*/
public final class CostPlanTempApiDto {
@ApiModel("添加费用计划子项响应结果")
@Data
public static class AddItemResp {
private CostPlanTempDomain tmp;
......@@ -26,6 +28,7 @@ public final class CostPlanTempApiDto {
private BigDecimal plaAmount;
}
@ApiModel("添加费用计划子项响应入参")
@Data
public static class AddItemReq {
// 费用单表 id
......@@ -43,6 +46,7 @@ public final class CostPlanTempApiDto {
private MultipartFile fileSelect;
}
@ApiModel("获取费用计划编号对应的费用计划子项出参")
@Data
public static class GetCostTempByPlanNoResp {
......@@ -50,4 +54,43 @@ public final class CostPlanTempApiDto {
private BigDecimal planAmount;
private Boolean success;
}
@ApiModel("删除费用计划模版行项目出参")
@Data
public static class DeleteItemResp {
private Boolean success;
private String msg;
private BigDecimal planAmount;
}
@ApiModel("根据费用计划模板编号获取费用计划模版出参")
@Data
public static class GetByTempNoResp {
private CostPlanTempDto tmp;
}
@ApiModel("更新费用计划子项入参")
@Data
public static class ResetItemReq {
private Integer id;
private String costPlanNo; // 费用计划编号
private String tempNo; // 计划缓存编号
private String kindNo; // 种类编号
private String filePath; // 文件地址
private BigDecimal amount; // 费用总金额
private String costReason; // 付款理由
private String dic; // 币种
private String typeNo; // 大类编号
private Boolean delecteFile;
private MultipartFile fileSelect2;
}
@ApiModel("更新费用计划子项出参")
@Data
public static class ResetItemResp {
private Boolean success;
private CostPlanTempDomain tmp;
}
}
......@@ -2,7 +2,9 @@ package com.blt.other.cost.service;
import com.blt.other.cost.dto.CostPlanTempApiDto;
import com.blt.other.database.model.CostPlanTempDomain;
import org.springframework.lang.NonNull;
import java.math.BigDecimal;
import java.util.List;
public interface CostPlanTempService {
......@@ -24,19 +26,39 @@ public interface CostPlanTempService {
* </p>
*
* @param costPlanNo 费用编号
* @return
* @return 费用计划行
*/
CostPlanTempApiDto.GetCostTempByPlanNoResp getTempListByPlanNo(String costPlanNo);
Integer deleteItemByPlanNoAndTempNo(String costPlanNo, String tempNo);
CostPlanTempDomain getByTempNo(String tempNo);
Integer update(CostPlanTempDomain domain);
void deleteFilePath(String tempNo);
/**
* <p>
* 根据费用计划单号和计划单项编号删除计划单项
* </p>
*
* @param costPlanNo 计划单号no
* @param tempNo 计划单项no
* @return 删除计划单项后的计划单的总费用
*/
BigDecimal deleteItemByPlanNoAndTempNo(String costPlanNo, String tempNo);
List<CostPlanTempDomain> getListByPlanNoAndTypeNo(String costPlanNo, String typeNo);
/**
* <p>
* 根据费用计划单项编号查询费用计划单项
* * </p>
*
* @param tempNo 用计划单项编号
* @return 费用计划单项
*/
@NonNull
CostPlanTempDomain getByTempNo(@NonNull String tempNo);
CostPlanTempDomain getByPlanNoAndTempNo(String costPlanNo, String tempNo);
/**
* <p>
* 更新费用计划子项
* </p>
*
* @param req req
* @return resp
*/
CostPlanTempDomain resetItem(CostPlanTempApiDto.ResetItemReq req);
}
......@@ -5,9 +5,9 @@ import com.blt.other.commons.utils.CurUtils;
import com.blt.other.commons.utils.PathUtil;
import com.blt.other.cost.dao.CostPlanDao;
import com.blt.other.cost.dao.CostPlanTempDao;
import com.blt.other.cost.dao.CostTypeKindDao;
import com.blt.other.cost.dto.CostPlanTempApiDto;
import com.blt.other.cost.service.CostPlanTempService;
import com.blt.other.cost.service.CostTypeKindService;
import com.blt.other.cost.utils.CostFileUtil;
import com.blt.other.database.model.CostPlanDomain;
import com.blt.other.database.model.CostPlanTempDomain;
......@@ -15,13 +15,15 @@ import com.blt.other.database.model.CostTypeKindDomain;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;
......@@ -30,10 +32,8 @@ public class CostPlanTempServiceImpl implements CostPlanTempService {
@Autowired
private CostPlanTempDao costPlanTempDao;
@Autowired
private CostTypeKindDao costTypeKindDao;
CostTypeKindService costTypeKindService;
@Autowired
private CostPlanDao costPlanDao;
......@@ -60,10 +60,10 @@ public class CostPlanTempServiceImpl implements CostPlanTempService {
* @param costPlanTempDomain 费用计划
*/
private void checkDic(CostPlanTempDomain costPlanTempDomain) {
List<CostPlanTempDomain> checkDict = this.getListByPlanNoAndTypeNo(costPlanTempDomain.getCostPlanNo(),
List<CostPlanTempDomain> checkDict = costPlanTempDao.selectByPlanNoAndTypeNo(costPlanTempDomain.getCostPlanNo(),
costPlanTempDomain.getTypeNo());
if (checkDict.stream().collect(Collectors.groupingBy(CostPlanTempDomain::getTypeNo)).keySet().size() > 1) {
throw new RuntimeException("已存在相同大类,请保持币种一致!")
throw new RuntimeException("已存在相同大类,请保持币种一致!");
}
}
......@@ -104,87 +104,109 @@ public class CostPlanTempServiceImpl implements CostPlanTempService {
@Override
public CostPlanTempApiDto.GetCostTempByPlanNoResp getTempListByPlanNo(String costPlanNo) {
List<CostPlanTempDomain> list = costPlanTempDao.selectListByPlanNo(costPlanNo);
List<CostPlanTempDto> dtoList = null;
if (null != list && list.size() >= 1) {
dtoList = new ArrayList<>();
for (CostPlanTempDomain costPlanTempDomain : list) {
dtoList.add(domainToDto(costPlanTempDomain));
}
}
return dtoList;
List<CostPlanTempDto> temps = list.stream().map(CostPlanTempDomain::castToDto).collect(Collectors.toList());
BigDecimal planAmount = temps.stream()
.map(tempDto -> {
BigDecimal cur = CurUtils.getCur(tempDto.getDic(), "CNY", getExchangeRateApi);
return tempDto.getAmount().multiply(cur);
})
.reduce(BigDecimal.ZERO, BigDecimal::add);
CostPlanTempApiDto.GetCostTempByPlanNoResp resp = new CostPlanTempApiDto.GetCostTempByPlanNoResp();
resp.setPlanAmount(planAmount);
resp.setSuccess(true);
resp.setTemps(temps);
return resp;
}
@Transactional
@Override
public Integer deleteItemByPlanNoAndTempNo(String costPlanNo, String tempNo) {
// CostPlanTempDomain costPlanTempDomain = costPlanTempDao.selectByPlanNoAndKindNo(costPlanNo, kindNo);
public BigDecimal deleteItemByPlanNoAndTempNo(String costPlanNo, String tempNo) {
CostPlanTempDomain costPlanTempDomain = costPlanTempDao.selectByPlanNoAndTempNo(costPlanNo, tempNo);
if (null == costPlanTempDomain || null == costPlanTempDomain.getTempNo()) {
return null;
}
Integer result = costPlanTempDao.deletedByPlanNoAndTempNo(costPlanNo, tempNo);
if (null != result && result >= 0) {
if (costPlanTempDomain != null) {
costPlanTempDao.deletedByPlanNoAndTempNo(costPlanNo, tempNo);
// 删除付款子项目成功,计划单改变总额
CostPlanDomain costPlanDomain = costPlanDao.selectByNo(costPlanTempDomain.getCostPlanNo());
if (null != costPlanDomain && null != costPlanDomain.getCostPlanNo()) {
if (null == costPlanDomain.getPlanAmount()) {
costPlanDomain.setPlanAmount(new BigDecimal(0));
}
if (costPlanDomain != null) {
costPlanDomain.setPlanAmount(costPlanDomain.getPlanAmount().subtract(costPlanTempDomain.getAmount()));
Integer update = costPlanDao.update(costPlanDomain);
costPlanDao.update(costPlanDomain);
return costPlanDomain.getPlanAmount();
}
return result;
throw new RuntimeException("not found");
}
return null;
throw new RuntimeException("not found");
}
@Override
public CostPlanTempDomain getByTempNo(String tempNo) {
@NonNull
public CostPlanTempDomain getByTempNo(@NonNull String tempNo) {
CostPlanTempDomain costPlanTempDomain = costPlanTempDao.selectByNo(tempNo);
if (null != costPlanTempDomain && null != costPlanTempDomain.getId()) {
return costPlanTempDomain;
if (costPlanTempDomain == null) {
throw new RuntimeException("not found");
}
return null;
return costPlanTempDomain;
}
@Override
public Integer update(CostPlanTempDomain domain) {
Integer update = costPlanTempDao.update(domain);
return update;
}
@Transactional(rollbackFor = Exception.class)
@Override
public void deleteFilePath(String tempNo) {
costPlanTempDao.deletedFilePath(tempNo);
}
public CostPlanTempDomain resetItem(CostPlanTempApiDto.ResetItemReq req) {
@Override
public List<CostPlanTempDomain> getListByPlanNoAndTypeNo(String costPlanNo, String typeNo) {
return costPlanTempDao.selectByPlanNoAndTypeNo(costPlanNo, typeNo);
CostTypeKindDomain kindByKindNo = costTypeKindService.getKindByKindNo(req.getKindNo());
req.setTypeNo(kindByKindNo.getTypeNo());
CostPlanTempDomain costPlanTempDomain = new CostPlanTempDomain();
com.bailuntec.common.BeanUtils.copyProperties(req, costPlanTempDomain);
if (req.getDelecteFile()) {
costPlanTempDao.deletedFilePath(req.getTempNo());
}
@Override
public CostPlanTempDomain getByPlanNoAndTempNo(String costPlanNo, String tempNo) {
return costPlanTempDao.selectByPlanNoAndTempNo(costPlanNo, tempNo);
costPlanTempDao.update(costPlanTempDomain);
this.chalkResetDec(costPlanTempDomain.getCostPlanNo());
if (req.getFileSelect2() != null) {
String filePath = PathUtil.getBasePath() + PathUtil.getPath("cost/" + costPlanTempDomain.getTempNo() + "/");
String path = CostFileUtil.upload(req.getFileSelect2(), filePath);
costPlanTempDomain.setFilePath(path);
}
private CostPlanTempDto domainToDto(CostPlanTempDomain costPlanTempDomain) {
CostPlanTempDto dto = new CostPlanTempDto();
BeanUtils.copyProperties(costPlanTempDomain, dto);
CostTypeKindDomain costTypeKindDomain = costTypeKindDao.selectByKindNo(costPlanTempDomain.getKindNo());
if (null != costTypeKindDomain) {
dto.setTypeNameDto(costTypeKindDomain.getTypeName());
dto.setKindNameDto(costTypeKindDomain.getKindName());
// 同步更新费用计划金额
CostPlanDomain plan = costPlanDao.selectByNo(req.getCostPlanNo());
if (plan == null) {
throw new RuntimeException("not found");
}
List<CostPlanTempDomain> tempListByPlanNo = costPlanTempDao.selectListByPlanNo(req.getCostPlanNo());
BigDecimal newAmount = tempListByPlanNo.stream().map(CostPlanTempDomain::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
String filePath = costPlanTempDomain.getFilePath();
if (null != filePath) {
String[] split = filePath.split("&");
if (null != split && split.length >= 1) {
dto.setFileName(split[1]);
plan.setPlanAmount(newAmount);
if (1 == plan.getCostForm() && (null != plan.getIsLend() && 2 == plan.getIsLend())) {
plan.setPayPlanAmount(newAmount.divide(plan.getPayCur(), 4));
}
costPlanDao.update(plan);
return costPlanTempDomain;
}
return dto;
/**
* 修改时判断费用单计划是否存在不相同货币的付款小类
*
* @param costPlanNo 费用单编号
*/
private void chalkResetDec(String costPlanNo) {
List<CostPlanTempDomain> costPlanTempDomainList = costPlanTempDao.selectListByPlanNo(costPlanNo);
Map<String, List<CostPlanTempDomain>> map = costPlanTempDomainList.stream().collect(Collectors.groupingBy(CostPlanTempDomain::getDic)) ;
if (map.keySet().size() > 1) {
throw new RuntimeException("请统一货币单位");
}
}
}
package com.blt.other.database.model;
import com.bailuntec.common.SpringContextUtil;
import com.bailuntec.cost.api.dto.CostPlanTempDto;
import com.blt.other.commons.utils.PathUtil;
import com.blt.other.cost.dao.CostTypeKindDao;
import com.blt.other.cost.model.CostTemplate;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import java.math.BigDecimal;
......@@ -17,5 +23,21 @@ public class CostPlanTempDomain {
private String dic; // 币种
private String typeNo; // 大类编号
public CostPlanTempDto castToDto(){
CostTypeKindDao costTypeKindDao = SpringContextUtil.getBean(CostTypeKindDao.class);
CostPlanTempDto dto = new CostPlanTempDto();
BeanUtils.copyProperties(this, dto);
CostTypeKindDomain costTypeKindDomain = costTypeKindDao.selectByKindNo(this.getKindNo());
if (null != costTypeKindDomain) {
dto.setTypeNameDto(costTypeKindDomain.getTypeName());
dto.setKindNameDto(costTypeKindDomain.getKindName());
}
dto.setFileName(PathUtil.getFileName(dto.getFilePath()));
return dto;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment