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;
......
......@@ -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