refactor(bonus-material): 重构协议信息获取和处理逻辑
- 将 mergerData 和 handleData 方法从控制器移动到服务层 - 优化了数据合并和处理的逻辑 - 使用 StringUtils 和 Objects 类改进了字符串和对象的处理- 调整了方法参数和返回类型,提高了代码的可读性和可维护性
This commit is contained in:
parent
f377f210c5
commit
58d40d964a
|
|
@ -60,7 +60,7 @@ public class ClzSltAgreementInfoController extends BaseController {
|
|||
|
||||
@ApiOperation(value = "往来单位id和标段工程id获取协议信息")
|
||||
@PostMapping("getAgreementInfoById")
|
||||
public AjaxResult getAgreementInfoById(@RequestBody SelectDto dto){
|
||||
public AjaxResult getAgreementInfoById(@RequestBody SelectDto dto) {
|
||||
return clzSltAgreementInfoService.getAgreementInfoById(dto);
|
||||
}
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ public class ClzSltAgreementInfoController extends BaseController {
|
|||
dataList.add(vo);
|
||||
agreementId = info.getAgreementId();
|
||||
}
|
||||
bean = mergerData(bean, dataList,unitNames,projectNames);
|
||||
bean = clzSltAgreementInfoService.mergerData(bean, dataList,unitNames,projectNames);
|
||||
// 根据协议id获取申请时间
|
||||
TmTask tmTask = taskMapper.selectTaskByIdByCl(agreementId);
|
||||
if (tmTask != null) {
|
||||
|
|
@ -88,60 +88,6 @@ public class ClzSltAgreementInfoController extends BaseController {
|
|||
return AjaxResult.success(bean);
|
||||
}
|
||||
|
||||
public MaterialSltInfoVo mergerData(MaterialSltInfoVo vo,List<MaterialSltInfoVo> list,List<String> unitNames,List<String> projectNames){
|
||||
vo.setUnitName(handleData(unitNames));
|
||||
vo.setProjectName(handleData(projectNames));
|
||||
BigDecimal leaseCost = BigDecimal.valueOf(0.00);
|
||||
BigDecimal repairCost = BigDecimal.valueOf(0.00);
|
||||
BigDecimal scrapCost = BigDecimal.valueOf(0.00);
|
||||
BigDecimal loseCost = BigDecimal.valueOf(0.00);
|
||||
BigDecimal reducCost = BigDecimal.valueOf(0.00);
|
||||
//租赁费用列表
|
||||
List<MaterialSltAgreementInfo> leaseList = new ArrayList<>();
|
||||
//维修费用列表
|
||||
List<MaterialSltAgreementInfo> repairList = new ArrayList<>();
|
||||
//报废费用列表
|
||||
List<MaterialSltAgreementInfo> scrapList = new ArrayList<>();
|
||||
//丢失费用列表
|
||||
List<MaterialSltAgreementInfo> loseList = new ArrayList<>();
|
||||
//减免费用列表
|
||||
List<SltAgreementReduce> reductionList = new ArrayList<>();
|
||||
List<SltAgreementRelation> relations = new ArrayList<>();
|
||||
for (MaterialSltInfoVo infoVo : list) {
|
||||
leaseCost = leaseCost.add(infoVo.getLeaseCost());
|
||||
repairCost = repairCost.add(infoVo.getRepairCost());
|
||||
scrapCost = scrapCost.add(infoVo.getScrapCost());
|
||||
loseCost = loseCost.add(infoVo.getLoseCost());
|
||||
reducCost = reducCost.add(infoVo.getReductionCost());
|
||||
leaseList.addAll(infoVo.getLeaseList());
|
||||
repairList.addAll(infoVo.getRepairList());
|
||||
scrapList.addAll(infoVo.getScrapList());
|
||||
loseList.addAll(infoVo.getLoseList());
|
||||
reductionList.addAll(infoVo.getReductionList());
|
||||
relations.addAll(infoVo.getRelations());
|
||||
}
|
||||
vo.setLeaseList(leaseList);
|
||||
vo.setRepairList(repairList);
|
||||
vo.setScrapList(scrapList);
|
||||
vo.setLoseList(loseList);
|
||||
vo.setReductionList(reductionList);
|
||||
vo.setLeaseCost(leaseCost);
|
||||
vo.setRepairCost(repairCost);
|
||||
vo.setScrapCost(scrapCost);
|
||||
vo.setLoseCost(loseCost);
|
||||
vo.setReductionCost(reducCost);
|
||||
vo.setRelations(relations);
|
||||
return vo;
|
||||
}
|
||||
|
||||
public String handleData(List<String> list){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Set<String> set = new HashSet<>(list);
|
||||
for (String str : set) {
|
||||
sb.append(str).append("、");
|
||||
}
|
||||
return StringUtils.removeEnd(sb.toString(), "、");
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交结算清单
|
||||
|
|
|
|||
|
|
@ -28,6 +28,10 @@ public interface ClzSltAgreementInfoService {
|
|||
*/
|
||||
MaterialSltInfoVo getSltInfo(MaterialSltAgreementInfo info);
|
||||
|
||||
MaterialSltInfoVo mergerData(MaterialSltInfoVo vo, List<MaterialSltInfoVo> list, List<String> unitNames, List<String> projectNames);
|
||||
|
||||
String handleData(List<String> list);
|
||||
|
||||
/**
|
||||
* 工程下拉框
|
||||
*
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import com.bonus.material.common.domain.vo.AgreementVo;
|
|||
import com.bonus.material.settlement.domain.SltAgreementReduce;
|
||||
import com.bonus.material.settlement.domain.SltAgreementRelation;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
|
@ -36,8 +37,7 @@ public class ClzSltAgreementInfoServiceImpl implements ClzSltAgreementInfoServic
|
|||
|
||||
/**
|
||||
* 根据条件获取协议结算列表
|
||||
* @param bean
|
||||
* @return
|
||||
* @param bean 查询条件
|
||||
*/
|
||||
@Override
|
||||
public List<MaterialSltAgreementInfo> getSltAgreementInfo4Project(MaterialSltAgreementInfo bean) {
|
||||
|
|
@ -79,16 +79,6 @@ public class ClzSltAgreementInfoServiceImpl implements ClzSltAgreementInfoServic
|
|||
leaseCost = leaseCost.add(lease.getCosts());
|
||||
}
|
||||
}
|
||||
/*for (MaterialSltAgreementInfo repair : repairList) {
|
||||
if(repair.getCosts()!=null && (repair.getPartType().equals("收费"))){
|
||||
repairCost = repairCost.add(repair.getCosts());
|
||||
}
|
||||
}
|
||||
for (MaterialSltAgreementInfo scrap : scrapList) {
|
||||
if(scrap.getCosts()!=null && (scrap.getPartType().equals("收费"))){
|
||||
scrapCost = scrapCost.add(scrap.getCosts());
|
||||
}
|
||||
}*/
|
||||
for (MaterialSltAgreementInfo lose : loseList) {
|
||||
if(lose.getCosts()!=null){
|
||||
loseCost = loseCost.add(lose.getCosts());
|
||||
|
|
@ -109,6 +99,63 @@ public class ClzSltAgreementInfoServiceImpl implements ClzSltAgreementInfoServic
|
|||
return sltInfoVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterialSltInfoVo mergerData(MaterialSltInfoVo vo, List<MaterialSltInfoVo> list, List<String> unitNames, List<String> projectNames) {
|
||||
vo.setUnitName(handleData(unitNames));
|
||||
vo.setProjectName(handleData(projectNames));
|
||||
BigDecimal leaseCost = BigDecimal.valueOf(0.00);
|
||||
BigDecimal repairCost = BigDecimal.valueOf(0.00);
|
||||
BigDecimal scrapCost = BigDecimal.valueOf(0.00);
|
||||
BigDecimal loseCost = BigDecimal.valueOf(0.00);
|
||||
BigDecimal reducCost = BigDecimal.valueOf(0.00);
|
||||
//租赁费用列表
|
||||
List<MaterialSltAgreementInfo> leaseList = new ArrayList<>();
|
||||
//维修费用列表
|
||||
List<MaterialSltAgreementInfo> repairList = new ArrayList<>();
|
||||
//报废费用列表
|
||||
List<MaterialSltAgreementInfo> scrapList = new ArrayList<>();
|
||||
//丢失费用列表
|
||||
List<MaterialSltAgreementInfo> loseList = new ArrayList<>();
|
||||
//减免费用列表
|
||||
List<SltAgreementReduce> reductionList = new ArrayList<>();
|
||||
List<SltAgreementRelation> relations = new ArrayList<>();
|
||||
for (MaterialSltInfoVo infoVo : list) {
|
||||
leaseCost = leaseCost.add(infoVo.getLeaseCost());
|
||||
repairCost = repairCost.add(infoVo.getRepairCost());
|
||||
scrapCost = scrapCost.add(infoVo.getScrapCost());
|
||||
loseCost = loseCost.add(infoVo.getLoseCost());
|
||||
reducCost = reducCost.add(infoVo.getReductionCost());
|
||||
leaseList.addAll(infoVo.getLeaseList());
|
||||
repairList.addAll(infoVo.getRepairList());
|
||||
scrapList.addAll(infoVo.getScrapList());
|
||||
loseList.addAll(infoVo.getLoseList());
|
||||
reductionList.addAll(infoVo.getReductionList());
|
||||
relations.addAll(infoVo.getRelations());
|
||||
}
|
||||
vo.setLeaseList(leaseList);
|
||||
vo.setRepairList(repairList);
|
||||
vo.setScrapList(scrapList);
|
||||
vo.setLoseList(loseList);
|
||||
vo.setReductionList(reductionList);
|
||||
vo.setLeaseCost(leaseCost);
|
||||
vo.setRepairCost(repairCost);
|
||||
vo.setScrapCost(scrapCost);
|
||||
vo.setLoseCost(loseCost);
|
||||
vo.setReductionCost(reducCost);
|
||||
vo.setRelations(relations);
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handleData(List<String> list) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Set<String> set = new HashSet<>(list);
|
||||
for (String str : set) {
|
||||
sb.append(str).append("、");
|
||||
}
|
||||
return StringUtils.removeEnd(sb.toString(), "、");
|
||||
}
|
||||
|
||||
/**
|
||||
* 工程下拉框
|
||||
*
|
||||
|
|
@ -169,7 +216,7 @@ public class ClzSltAgreementInfoServiceImpl implements ClzSltAgreementInfoServic
|
|||
|
||||
@Override
|
||||
public AjaxResult getAgreementInfoById(SelectDto dto) {
|
||||
List<AgreementVo> vo = new ArrayList<>();
|
||||
List<AgreementVo> vo;
|
||||
try {
|
||||
List<AgreementVo> list = clzSltAgreementInfoMapper.getAgreementInfoById(dto.getUnitIds(), Integer.parseInt(dto.getProjectId()));
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
|
|
@ -191,7 +238,7 @@ public class ClzSltAgreementInfoServiceImpl implements ClzSltAgreementInfoServic
|
|||
@Override
|
||||
public int submitCosts(MaterialSltInfoVo sltInfoVo) {
|
||||
try {
|
||||
if(sltInfoVo.getAgreementIds()!=null) {
|
||||
if (sltInfoVo.getAgreementIds() != null) {
|
||||
|
||||
for (Long agreementId : sltInfoVo.getAgreementIds()) {
|
||||
Long id = null;
|
||||
|
|
@ -260,7 +307,7 @@ public class ClzSltAgreementInfoServiceImpl implements ClzSltAgreementInfoServic
|
|||
throw new ServiceException("bm_agreement_info修改失败");
|
||||
}*/
|
||||
}
|
||||
if (sltInfoVo.getLeaseList().size() > 0) {
|
||||
if (!sltInfoVo.getLeaseList().isEmpty()) {
|
||||
List<MaterialSltAgreementInfo> filteredLeaseList = sltInfoVo.getLeaseList().stream()
|
||||
.filter(lease -> lease.getAgreementId().equals(sltInfoVo.getAgreementId()))
|
||||
.collect(Collectors.toList());
|
||||
|
|
@ -284,7 +331,7 @@ public class ClzSltAgreementInfoServiceImpl implements ClzSltAgreementInfoServic
|
|||
clzSltAgreementInfoMapper.insertSltAgreementDetailScrap(filteredScrapList, id);
|
||||
}
|
||||
}*/
|
||||
if (sltInfoVo.getLoseList().size() > 0) {
|
||||
if (!sltInfoVo.getLoseList().isEmpty()) {
|
||||
List<MaterialSltAgreementInfo> filteredLoseList = sltInfoVo.getLoseList().stream()
|
||||
.filter(lease -> lease.getAgreementId().equals(sltInfoVo.getAgreementId()))
|
||||
.collect(Collectors.toList());
|
||||
|
|
@ -302,23 +349,22 @@ public class ClzSltAgreementInfoServiceImpl implements ClzSltAgreementInfoServic
|
|||
|
||||
/**
|
||||
* 获取结算关系列表
|
||||
* @param leaseList
|
||||
* @param repairList
|
||||
* @param scrapList
|
||||
* @param loseList
|
||||
* @param sltInfo
|
||||
* @return
|
||||
* @param leaseList 领料数据
|
||||
* @param repairList 维修数据
|
||||
* @param scrapList 报废数据
|
||||
* @param loseList 丢失数据
|
||||
* @param sltInfo 结算信息
|
||||
* @return 协议费用列表
|
||||
*/
|
||||
private List<SltAgreementRelation> getRelations(List<MaterialSltAgreementInfo> leaseList, List<MaterialSltAgreementInfo> repairList, List<MaterialSltAgreementInfo> scrapList, List<MaterialSltAgreementInfo> loseList, MaterialSltAgreementInfo sltInfo) {
|
||||
List<SltAgreementRelation> relations = new ArrayList<>();
|
||||
// for (SltAgreementInfo info : list) {
|
||||
SltAgreementRelation relation = new SltAgreementRelation();
|
||||
BigDecimal loseCost = BigDecimal.ZERO;
|
||||
BigDecimal leaseCost = BigDecimal.ZERO;
|
||||
BigDecimal scrapCost = BigDecimal.ZERO;
|
||||
BigDecimal repairCost = BigDecimal.ZERO;
|
||||
for (MaterialSltAgreementInfo lease : leaseList) {
|
||||
if (lease.getAgreementId().equals(sltInfo.getAgreementId().toString())) {
|
||||
if (lease.getAgreementId().equals(sltInfo.getAgreementId())) {
|
||||
relation.setAgreementId(String.valueOf(lease.getAgreementId()));
|
||||
relation.setProjectName(lease.getProjectName());
|
||||
relation.setUnitName(lease.getUnitName());
|
||||
|
|
@ -328,19 +374,19 @@ public class ClzSltAgreementInfoServiceImpl implements ClzSltAgreementInfoServic
|
|||
}
|
||||
}
|
||||
for (MaterialSltAgreementInfo repair : repairList) {
|
||||
if (repair.getAgreementId().equals(sltInfo.getAgreementId().toString())) {
|
||||
if (repair.getAgreementId().equals(sltInfo.getAgreementId())) {
|
||||
BigDecimal cost = repair.getCosts();
|
||||
repairCost = repairCost.add(cost);
|
||||
}
|
||||
}
|
||||
for (MaterialSltAgreementInfo scrap : scrapList) {
|
||||
if (scrap.getAgreementId().equals(sltInfo.getAgreementId().toString())) {
|
||||
if (scrap.getAgreementId().equals(sltInfo.getAgreementId())) {
|
||||
BigDecimal cost = scrap.getCosts();
|
||||
scrapCost = scrapCost.add(cost);
|
||||
}
|
||||
}
|
||||
for (MaterialSltAgreementInfo lose : loseList) {
|
||||
if (lose.getAgreementId().equals(sltInfo.getAgreementId().toString())) {
|
||||
if (lose.getAgreementId().equals(sltInfo.getAgreementId())) {
|
||||
//TODO 上面已经set过值,这里为什么还要set值
|
||||
relation.setAgreementId(String.valueOf(lose.getAgreementId()));
|
||||
relation.setProjectName(lose.getProjectName());
|
||||
|
|
@ -355,14 +401,12 @@ public class ClzSltAgreementInfoServiceImpl implements ClzSltAgreementInfoServic
|
|||
relation.setScrapCost(scrapCost);
|
||||
relation.setLoseCost(loseCost);
|
||||
relations.add(relation);
|
||||
// }
|
||||
return relations;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取减免费用列表
|
||||
* @param info
|
||||
* @return
|
||||
* @param info 信息表
|
||||
*/
|
||||
private List<SltAgreementReduce> getReductionList(MaterialSltAgreementInfo info) {
|
||||
SltAgreementReduce bean =new SltAgreementReduce();
|
||||
|
|
@ -372,20 +416,17 @@ public class ClzSltAgreementInfoServiceImpl implements ClzSltAgreementInfoServic
|
|||
|
||||
/**
|
||||
* 获取丢失费用列表
|
||||
* @param info
|
||||
* @return
|
||||
* @param info 信息表
|
||||
*/
|
||||
private List<MaterialSltAgreementInfo> getLoseList(MaterialSltAgreementInfo info) {
|
||||
List<MaterialSltAgreementInfo> loseList = new ArrayList<>();
|
||||
|
||||
List<MaterialSltAgreementInfo> oneOfList = clzSltAgreementInfoMapper.getLoseList(info);
|
||||
loseList.addAll(oneOfList);
|
||||
List<MaterialSltAgreementInfo> loseList = new ArrayList<>(oneOfList);
|
||||
|
||||
for (MaterialSltAgreementInfo bean : loseList) {
|
||||
if (null == bean.getBuyPrice()) {
|
||||
if (Objects.isNull(bean.getBuyPrice())) {
|
||||
bean.setBuyPrice(BigDecimal.valueOf(0.00));
|
||||
}
|
||||
if (null == bean.getNum()) {
|
||||
if (Objects.isNull(bean.getNum())) {
|
||||
bean.setNum(BigDecimal.valueOf(0L));
|
||||
}
|
||||
BigDecimal buyPrice = bean.getBuyPrice();
|
||||
|
|
@ -400,14 +441,11 @@ public class ClzSltAgreementInfoServiceImpl implements ClzSltAgreementInfoServic
|
|||
|
||||
/**
|
||||
* 获取租赁费用列表
|
||||
* @param info
|
||||
* @return
|
||||
* @param info 获取租赁费用列表参数
|
||||
*/
|
||||
private List<MaterialSltAgreementInfo> getLeaseList(MaterialSltAgreementInfo info) {
|
||||
List<MaterialSltAgreementInfo> leaseList = new ArrayList<>();
|
||||
|
||||
List<MaterialSltAgreementInfo> oneOfList = clzSltAgreementInfoMapper.getLeaseList(info);
|
||||
leaseList.addAll(oneOfList);
|
||||
List<MaterialSltAgreementInfo> leaseList = new ArrayList<>(oneOfList);
|
||||
|
||||
for (MaterialSltAgreementInfo bean : leaseList) {
|
||||
if (null == bean.getLeasePrice()) {
|
||||
|
|
@ -415,10 +453,10 @@ public class ClzSltAgreementInfoServiceImpl implements ClzSltAgreementInfoServic
|
|||
}else{
|
||||
bean.setLeasePrice(bean.getLeasePrice().setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
if (null == bean.getNum()) {
|
||||
if (Objects.isNull(bean.getNum())) {
|
||||
bean.setNum(BigDecimal.valueOf(0L));
|
||||
}
|
||||
if (null == bean.getLeaseDays()) {
|
||||
if (Objects.isNull(bean.getLeaseDays())) {
|
||||
bean.setLeaseDay(0L);
|
||||
}
|
||||
BigDecimal leasePrice = bean.getLeasePrice();
|
||||
|
|
|
|||
|
|
@ -129,6 +129,7 @@ public class SltAgreementInfoController extends BaseController {
|
|||
}
|
||||
return AjaxResult.success(bean);
|
||||
}
|
||||
|
||||
public SltInfoVo mergerData(SltInfoVo vo,List<SltInfoVo> list,List<String> unitNames,List<String> projectNames){
|
||||
vo.setUnitName(handleData(unitNames));
|
||||
vo.setProjectName(handleData(projectNames));
|
||||
|
|
|
|||
Loading…
Reference in New Issue