|
|
@@ -8,15 +8,19 @@ import lombok.RequiredArgsConstructor;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.main.domain.MainBackCategory;
|
|
|
import org.dromara.main.domain.MainBackClause;
|
|
|
import org.dromara.main.domain.bo.MainBackClauseBo;
|
|
|
import org.dromara.main.domain.vo.MainBackClauseVo;
|
|
|
+import org.dromara.main.mapper.MainBackCategoryMapper;
|
|
|
import org.dromara.main.mapper.MainBackClauseMapper;
|
|
|
import org.dromara.main.service.IMainBackClauseService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.Collection;
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
@Service
|
|
|
@@ -24,6 +28,8 @@ public class MainBackClauseServiceImpl implements IMainBackClauseService {
|
|
|
|
|
|
private final MainBackClauseMapper baseMapper;
|
|
|
|
|
|
+ private final MainBackCategoryMapper categoryMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 查询背调条款分页列表
|
|
|
*/
|
|
|
@@ -78,6 +84,7 @@ public class MainBackClauseServiceImpl implements IMainBackClauseService {
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
if (flag) {
|
|
|
bo.setId(add.getId());
|
|
|
+ updateCategoryPrice(bo.getCategoryId());
|
|
|
}
|
|
|
return flag;
|
|
|
}
|
|
|
@@ -88,7 +95,12 @@ public class MainBackClauseServiceImpl implements IMainBackClauseService {
|
|
|
@Override
|
|
|
public Boolean updateByBo(MainBackClauseBo bo) {
|
|
|
MainBackClause update = MapstructUtils.convert(bo, MainBackClause.class);
|
|
|
- return baseMapper.updateById(update) > 0;
|
|
|
+
|
|
|
+ boolean flag=baseMapper.updateById(update)>0;
|
|
|
+ if(flag) {
|
|
|
+ updateCategoryPrice(bo.getCategoryId());
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -99,6 +111,33 @@ public class MainBackClauseServiceImpl implements IMainBackClauseService {
|
|
|
if (isValid) {
|
|
|
// 这里可以添加删除前的业务校验逻辑
|
|
|
}
|
|
|
- return baseMapper.deleteByIds(ids) > 0;
|
|
|
+ boolean flag=baseMapper.deleteBatchIds(ids) > 0;
|
|
|
+ if(flag){
|
|
|
+ updateCategoryPrice(ids.stream().findFirst().orElse(null));
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateCategoryPrice(Long categoryId) {
|
|
|
+ if (categoryId == null) return;
|
|
|
+
|
|
|
+ // 1. 查询该类别下所有的条款
|
|
|
+ LambdaQueryWrapper<MainBackClause> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.eq(MainBackClause::getCategoryId, categoryId);
|
|
|
+ List<MainBackClause> clauses = baseMapper.selectList(lqw);
|
|
|
+
|
|
|
+ // 2. 聚合计出总价
|
|
|
+ BigDecimal totalPrice = clauses.stream()
|
|
|
+ .map(MainBackClause::getPrice)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+
|
|
|
+ // 3. 更新对应的分类表价格
|
|
|
+ MainBackCategory updateCategory = new MainBackCategory();
|
|
|
+ updateCategory.setId(categoryId);
|
|
|
+ updateCategory.setPrice(totalPrice);
|
|
|
+ categoryMapper.updateById(updateCategory);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|