zhongrj
2023-11-11 072106a6169739156311ed71ca33890f27c35b85
src/main/java/org/springblade/modules/place/service/impl/PlaceExtServiceImpl.java
@@ -19,6 +19,8 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.modules.house.entity.HouseTenantEntity;
import org.springblade.modules.house.vo.HouseTenantVO;
import org.springblade.modules.place.entity.PlaceEntity;
import org.springblade.modules.place.entity.PlaceExtEntity;
import org.springblade.modules.place.entity.PlacePractitionerEntity;
@@ -35,8 +37,10 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
 * 场所详情表 服务实现类
@@ -73,12 +77,65 @@
    * @return
    */
   @Override
   public boolean updatePlaceExt(PlaceExtEntity placeExt) {
   @Transactional(rollbackFor = Exception.class)
   public boolean updatePlaceExt(PlaceExtVO placeExt) {
      // 设置参数
      placeExt.setUpdateTime(new Date());
      placeExt.setUpdateUser(AuthUtil.getUserId());
      // 更新
      return updateById(placeExt);
      // 更新从业人员信息
      boolean addFlag = true;
      boolean updateFlag = true;
      boolean removeFlag = true;
      //更新自身
      boolean update = updateById(placeExt);
      // 查询对应已存在的从业人员
      QueryWrapper<PlacePractitionerEntity> wrapper = new QueryWrapper<>();
      wrapper.eq("place_id",placeExt.getPlaceId());
      List<PlacePractitionerEntity> oldList = placePractitionerService.list(wrapper);
      List<PlacePractitionerEntity> list = placeExt.getPlacePractitioner();
      // 申明新增,修改,删除集合
      List<PlacePractitionerEntity> newList = new ArrayList<>();
      List<PlacePractitionerEntity> addList = new ArrayList<>();
      List<PlacePractitionerEntity> updateList = new ArrayList<>();
      List<PlacePractitionerEntity> removeList = new ArrayList<>();
      // 找出需要新增的,否则组成新集合进行比对
      for (PlacePractitionerEntity practitionerEntity : list) {
         practitionerEntity.setPlaceId(placeExt.getPlaceId());
         if (null==practitionerEntity.getId()){
            // 新增
            PlacePractitionerEntity placePractitionerEntity= new PlacePractitionerEntity();
            placePractitionerEntity.setPlaceId(placeExt.getPlaceId());
            placePractitionerEntity.setName(practitionerEntity.getName());
            placePractitionerEntity.setTelephone(practitionerEntity.getTelephone());
            placePractitionerEntity.setTempAddress(practitionerEntity.getTempAddress());
            addList.add(placePractitionerEntity);
         }else {
            newList.add(practitionerEntity);
         }
      }
      // 遍历去差集,判断是新增还是删除还是更新
      // 取旧数据和新提交数据差集--删除
      removeList = oldList.stream().filter(vo -> !newList.stream().map(e ->
         e.getId()).collect(Collectors.toList()).contains(vo.getId())).collect(Collectors.toList());
      // 取旧数据和新提交数据交集--更新
      updateList = newList.stream().filter(vo -> oldList.stream().map(e ->
         e.getId()).collect(Collectors.toList()).contains(vo.getId())).collect(Collectors.toList());
      // 批量新增
      if (addList.size()>0) {
         addFlag = placePractitionerService.saveBatch(addList);
      }
      // 批量修改
      if (updateList.size()>0) {
         updateFlag = placePractitionerService.updateBatchById(updateList);
      }
      // 批量删除
      if (removeList.size()>0) {
         removeFlag = placePractitionerService.removeBatchByIds(removeList);
      }
      // 返回
      return update && addFlag && updateFlag && removeFlag;
   }
   /**