guoshilong
2023-06-16 fd13a47afef5654fc831947cfc0507312ac0ed78
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package cn.gistack.sm.sjztmd.service.impl;
 
import cn.gistack.sm.sjztmd.entity.AttStBase;
import cn.gistack.sm.sjztmd.mapper.AttStBaseMapper;
import cn.gistack.sm.sjztmd.service.IAttStBaseService;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Condition;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springblade.core.tool.utils.ObjectUtil;
 
import java.util.List;
 
@Service
@DS("zt")
public class AttStBaseServiceImpl extends ServiceImpl<AttStBaseMapper, AttStBase> implements IAttStBaseService {
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateById(AttStBase entity) {
        AttStBase base = new AttStBase();
        if (ObjectUtil.isNotEmpty(entity.getIsMainRain())&&entity.getIsMainRain().equals(1)){
            //设置雨情站为主站
            //获取该水库下的所有雨情站
            base.setResGuid(entity.getResGuid());
            base.setIsPptn(1);
            List<AttStBase> list = list(Condition.getQueryWrapper(base));
            //设置所有雨量站为辅站
            list.forEach(e->{
                e.setIsMainRain(0);
            });
            updateBatchById(list);
            //设置该站为主站
        }else if (ObjectUtil.isNotEmpty(entity.getIsMainRsvr())&&entity.getIsMainRsvr().equals(1)){
            //设置水情站为主站
            //获取该水库下的所有水情站
            base.setResGuid(entity.getResGuid());
            base.setIsRsvr(1);
            List<AttStBase> list = list(Condition.getQueryWrapper(base));
            //设置所有水情站为辅站
            list.forEach(e->{
                e.setIsMainRsvr(0);
            });
            updateBatchById(list);
            //设置该站为主站
        }
        return super.updateById(entity);
    }
}