Commit a917fcfd by huluobin

update

parent a037eb85
...@@ -14,6 +14,7 @@ public class CostPlanTempDto { ...@@ -14,6 +14,7 @@ public class CostPlanTempDto {
private String fileName; // 文件名 private String fileName; // 文件名
private BigDecimal amount; // 费用总金额 private BigDecimal amount; // 费用总金额
private String costReason; // 付款理由 private String costReason; // 付款理由
private String typeNameDto; // 大类标题 private String typeNameDto; // 大类标题
private String kindNameDto; // 小类标题 private String kindNameDto; // 小类标题
private String dic; // 币种 private String dic; // 币种
......
...@@ -66,7 +66,7 @@ public class CostPlanController { ...@@ -66,7 +66,7 @@ public class CostPlanController {
AxiosUtil.setCors(response, request); AxiosUtil.setCors(response, request);
String costPlanNo = request.getParameter("costPlanNo"); String costPlanNo = request.getParameter("costPlanNo");
List<CostPlanTempDto> tempListByPlanNo = costPlanTempService.getTempListByPlanNo(costPlanNo); List<CostPlanTempDto> tempListByPlanNo = costPlanTempService.getTempListByPlanNo(costPlanNo).getTemps();
BigDecimal planAmount = new BigDecimal(0); BigDecimal planAmount = new BigDecimal(0);
if (null != tempListByPlanNo && tempListByPlanNo.size() >= 1) { if (null != tempListByPlanNo && tempListByPlanNo.size() >= 1) {
for (CostPlanTempDto dto : tempListByPlanNo) { for (CostPlanTempDto dto : tempListByPlanNo) {
......
...@@ -37,7 +37,7 @@ public class CostPlanNewReceiptController { ...@@ -37,7 +37,7 @@ public class CostPlanNewReceiptController {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
String planNo = request.getParameter("costPlanNo"); String planNo = request.getParameter("costPlanNo");
CostPlanDomain costPlanDomain = costPlanService.getByPlanNo(planNo); CostPlanDomain costPlanDomain = costPlanService.getByPlanNo(planNo).getCostPlan();
if (null != costPlanDomain) { if (null != costPlanDomain) {
result.put("success", false); result.put("success", false);
return result; return result;
...@@ -70,7 +70,7 @@ public class CostPlanNewReceiptController { ...@@ -70,7 +70,7 @@ public class CostPlanNewReceiptController {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
String planNo = request.getParameter("costPlanNo"); String planNo = request.getParameter("costPlanNo");
CostPlanDomain costPlanDomain = costPlanService.getByPlanNo(planNo); CostPlanDomain costPlanDomain = costPlanService.getByPlanNo(planNo).getCostPlan();
if (null != costPlanDomain) { if (null != costPlanDomain) {
result.put("success", false); result.put("success", false);
return result; return result;
......
...@@ -2,6 +2,7 @@ package com.blt.other.cost.dto; ...@@ -2,6 +2,7 @@ package com.blt.other.cost.dto;
import com.bailuntec.cost.api.dto.CostPlanTempDto; import com.bailuntec.cost.api.dto.CostPlanTempDto;
import com.blt.other.database.model.CostPlanTempDomain; import com.blt.other.database.model.CostPlanTempDomain;
import io.swagger.annotations.ApiModel;
import lombok.Data; import lombok.Data;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -18,6 +19,7 @@ import java.util.List; ...@@ -18,6 +19,7 @@ import java.util.List;
*/ */
public final class CostPlanTempApiDto { public final class CostPlanTempApiDto {
@ApiModel("添加费用计划子项响应结果")
@Data @Data
public static class AddItemResp { public static class AddItemResp {
private CostPlanTempDomain tmp; private CostPlanTempDomain tmp;
...@@ -26,6 +28,7 @@ public final class CostPlanTempApiDto { ...@@ -26,6 +28,7 @@ public final class CostPlanTempApiDto {
private BigDecimal plaAmount; private BigDecimal plaAmount;
} }
@ApiModel("添加费用计划子项响应入参")
@Data @Data
public static class AddItemReq { public static class AddItemReq {
// 费用单表 id // 费用单表 id
...@@ -43,6 +46,7 @@ public final class CostPlanTempApiDto { ...@@ -43,6 +46,7 @@ public final class CostPlanTempApiDto {
private MultipartFile fileSelect; private MultipartFile fileSelect;
} }
@ApiModel("获取费用计划编号对应的费用计划子项出参")
@Data @Data
public static class GetCostTempByPlanNoResp { public static class GetCostTempByPlanNoResp {
...@@ -50,4 +54,43 @@ public final class CostPlanTempApiDto { ...@@ -50,4 +54,43 @@ public final class CostPlanTempApiDto {
private BigDecimal planAmount; private BigDecimal planAmount;
private Boolean success; 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; ...@@ -2,7 +2,9 @@ package com.blt.other.cost.service;
import com.blt.other.cost.dto.CostPlanTempApiDto; import com.blt.other.cost.dto.CostPlanTempApiDto;
import com.blt.other.database.model.CostPlanTempDomain; import com.blt.other.database.model.CostPlanTempDomain;
import org.springframework.lang.NonNull;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
public interface CostPlanTempService { public interface CostPlanTempService {
...@@ -24,19 +26,39 @@ public interface CostPlanTempService { ...@@ -24,19 +26,39 @@ public interface CostPlanTempService {
* </p> * </p>
* *
* @param costPlanNo 费用编号 * @param costPlanNo 费用编号
* @return * @return 费用计划行
*/ */
CostPlanTempApiDto.GetCostTempByPlanNoResp getTempListByPlanNo(String costPlanNo); CostPlanTempApiDto.GetCostTempByPlanNoResp getTempListByPlanNo(String costPlanNo);
Integer deleteItemByPlanNoAndTempNo(String costPlanNo, String tempNo); /**
* <p>
CostPlanTempDomain getByTempNo(String tempNo); * 根据费用计划单号和计划单项编号删除计划单项
* </p>
Integer update(CostPlanTempDomain domain); *
* @param costPlanNo 计划单号no
void deleteFilePath(String tempNo); * @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; ...@@ -5,9 +5,9 @@ import com.blt.other.commons.utils.CurUtils;
import com.blt.other.commons.utils.PathUtil; import com.blt.other.commons.utils.PathUtil;
import com.blt.other.cost.dao.CostPlanDao; import com.blt.other.cost.dao.CostPlanDao;
import com.blt.other.cost.dao.CostPlanTempDao; 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.dto.CostPlanTempApiDto;
import com.blt.other.cost.service.CostPlanTempService; 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.cost.utils.CostFileUtil;
import com.blt.other.database.model.CostPlanDomain; import com.blt.other.database.model.CostPlanDomain;
import com.blt.other.database.model.CostPlanTempDomain; import com.blt.other.database.model.CostPlanTempDomain;
...@@ -15,13 +15,15 @@ import com.blt.other.database.model.CostTypeKindDomain; ...@@ -15,13 +15,15 @@ import com.blt.other.database.model.CostTypeKindDomain;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -30,10 +32,8 @@ public class CostPlanTempServiceImpl implements CostPlanTempService { ...@@ -30,10 +32,8 @@ public class CostPlanTempServiceImpl implements CostPlanTempService {
@Autowired @Autowired
private CostPlanTempDao costPlanTempDao; private CostPlanTempDao costPlanTempDao;
@Autowired @Autowired
private CostTypeKindDao costTypeKindDao; CostTypeKindService costTypeKindService;
@Autowired @Autowired
private CostPlanDao costPlanDao; private CostPlanDao costPlanDao;
...@@ -60,10 +60,10 @@ public class CostPlanTempServiceImpl implements CostPlanTempService { ...@@ -60,10 +60,10 @@ public class CostPlanTempServiceImpl implements CostPlanTempService {
* @param costPlanTempDomain 费用计划 * @param costPlanTempDomain 费用计划
*/ */
private void checkDic(CostPlanTempDomain costPlanTempDomain) { private void checkDic(CostPlanTempDomain costPlanTempDomain) {
List<CostPlanTempDomain> checkDict = this.getListByPlanNoAndTypeNo(costPlanTempDomain.getCostPlanNo(), List<CostPlanTempDomain> checkDict = costPlanTempDao.selectByPlanNoAndTypeNo(costPlanTempDomain.getCostPlanNo(),
costPlanTempDomain.getTypeNo()); costPlanTempDomain.getTypeNo());
if (checkDict.stream().collect(Collectors.groupingBy(CostPlanTempDomain::getTypeNo)).keySet().size() > 1) { 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 { ...@@ -104,87 +104,109 @@ public class CostPlanTempServiceImpl implements CostPlanTempService {
@Override @Override
public CostPlanTempApiDto.GetCostTempByPlanNoResp getTempListByPlanNo(String costPlanNo) { public CostPlanTempApiDto.GetCostTempByPlanNoResp getTempListByPlanNo(String costPlanNo) {
List<CostPlanTempDomain> list = costPlanTempDao.selectListByPlanNo(costPlanNo); List<CostPlanTempDomain> list = costPlanTempDao.selectListByPlanNo(costPlanNo);
List<CostPlanTempDto> dtoList = null;
if (null != list && list.size() >= 1) { List<CostPlanTempDto> temps = list.stream().map(CostPlanTempDomain::castToDto).collect(Collectors.toList());
dtoList = new ArrayList<>();
for (CostPlanTempDomain costPlanTempDomain : list) { BigDecimal planAmount = temps.stream()
dtoList.add(domainToDto(costPlanTempDomain)); .map(tempDto -> {
} BigDecimal cur = CurUtils.getCur(tempDto.getDic(), "CNY", getExchangeRateApi);
} return tempDto.getAmount().multiply(cur);
return dtoList; })
.reduce(BigDecimal.ZERO, BigDecimal::add);
CostPlanTempApiDto.GetCostTempByPlanNoResp resp = new CostPlanTempApiDto.GetCostTempByPlanNoResp();
resp.setPlanAmount(planAmount);
resp.setSuccess(true);
resp.setTemps(temps);
return resp;
} }
@Transactional
@Override @Override
public Integer deleteItemByPlanNoAndTempNo(String costPlanNo, String tempNo) { public BigDecimal deleteItemByPlanNoAndTempNo(String costPlanNo, String tempNo) {
// CostPlanTempDomain costPlanTempDomain = costPlanTempDao.selectByPlanNoAndKindNo(costPlanNo, kindNo);
CostPlanTempDomain costPlanTempDomain = costPlanTempDao.selectByPlanNoAndTempNo(costPlanNo, tempNo); CostPlanTempDomain costPlanTempDomain = costPlanTempDao.selectByPlanNoAndTempNo(costPlanNo, tempNo);
if (null == costPlanTempDomain || null == costPlanTempDomain.getTempNo()) { if (costPlanTempDomain != null) {
return null; costPlanTempDao.deletedByPlanNoAndTempNo(costPlanNo, tempNo);
}
Integer result = costPlanTempDao.deletedByPlanNoAndTempNo(costPlanNo, tempNo);
if (null != result && result >= 0) {
// 删除付款子项目成功,计划单改变总额 // 删除付款子项目成功,计划单改变总额
CostPlanDomain costPlanDomain = costPlanDao.selectByNo(costPlanTempDomain.getCostPlanNo()); CostPlanDomain costPlanDomain = costPlanDao.selectByNo(costPlanTempDomain.getCostPlanNo());
if (null != costPlanDomain && null != costPlanDomain.getCostPlanNo()) { if (costPlanDomain != null) {
if (null == costPlanDomain.getPlanAmount()) {
costPlanDomain.setPlanAmount(new BigDecimal(0));
}
costPlanDomain.setPlanAmount(costPlanDomain.getPlanAmount().subtract(costPlanTempDomain.getAmount())); 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 @Override
public CostPlanTempDomain getByTempNo(String tempNo) { @NonNull
public CostPlanTempDomain getByTempNo(@NonNull String tempNo) {
CostPlanTempDomain costPlanTempDomain = costPlanTempDao.selectByNo(tempNo); CostPlanTempDomain costPlanTempDomain = costPlanTempDao.selectByNo(tempNo);
if (null != costPlanTempDomain && null != costPlanTempDomain.getId()) { if (costPlanTempDomain == null) {
return costPlanTempDomain; 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 @Override
public void deleteFilePath(String tempNo) { public CostPlanTempDomain resetItem(CostPlanTempApiDto.ResetItemReq req) {
costPlanTempDao.deletedFilePath(tempNo);
}
@Override CostTypeKindDomain kindByKindNo = costTypeKindService.getKindByKindNo(req.getKindNo());
public List<CostPlanTempDomain> getListByPlanNoAndTypeNo(String costPlanNo, String typeNo) { req.setTypeNo(kindByKindNo.getTypeNo());
return costPlanTempDao.selectByPlanNoAndTypeNo(costPlanNo, typeNo);
}
@Override CostPlanTempDomain costPlanTempDomain = new CostPlanTempDomain();
public CostPlanTempDomain getByPlanNoAndTempNo(String costPlanNo, String tempNo) { com.bailuntec.common.BeanUtils.copyProperties(req, costPlanTempDomain);
return costPlanTempDao.selectByPlanNoAndTempNo(costPlanNo, tempNo);
} if (req.getDelecteFile()) {
costPlanTempDao.deletedFilePath(req.getTempNo());
}
costPlanTempDao.update(costPlanTempDomain);
this.chalkResetDec(costPlanTempDomain.getCostPlanNo());
private CostPlanTempDto domainToDto(CostPlanTempDomain costPlanTempDomain) { if (req.getFileSelect2() != null) {
CostPlanTempDto dto = new CostPlanTempDto(); String filePath = PathUtil.getBasePath() + PathUtil.getPath("cost/" + costPlanTempDomain.getTempNo() + "/");
BeanUtils.copyProperties(costPlanTempDomain, dto); String path = CostFileUtil.upload(req.getFileSelect2(), filePath);
costPlanTempDomain.setFilePath(path);
}
CostTypeKindDomain costTypeKindDomain = costTypeKindDao.selectByKindNo(costPlanTempDomain.getKindNo());
if (null != costTypeKindDomain) { // 同步更新费用计划金额
dto.setTypeNameDto(costTypeKindDomain.getTypeName()); CostPlanDomain plan = costPlanDao.selectByNo(req.getCostPlanNo());
dto.setKindNameDto(costTypeKindDomain.getKindName()); 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(); plan.setPlanAmount(newAmount);
if (null != filePath) { if (1 == plan.getCostForm() && (null != plan.getIsLend() && 2 == plan.getIsLend())) {
String[] split = filePath.split("&"); plan.setPayPlanAmount(newAmount.divide(plan.getPayCur(), 4));
if (null != split && split.length >= 1) {
dto.setFileName(split[1]);
}
} }
costPlanDao.update(plan);
return dto; return costPlanTempDomain;
}
/**
* 修改时判断费用单计划是否存在不相同货币的付款小类
*
* @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; 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 lombok.Data;
import org.springframework.beans.BeanUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -17,5 +23,21 @@ public class CostPlanTempDomain { ...@@ -17,5 +23,21 @@ public class CostPlanTempDomain {
private String dic; // 币种 private String dic; // 币种
private String typeNo; // 大类编号 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