潘志宝
2024-09-09 bbc1eeba9c29032add5175f2739782fd204de715
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.iailab.module.model.mcs.sche.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.iailab.framework.common.pojo.PageResult;
import com.iailab.framework.common.service.impl.BaseServiceImpl;
import com.iailab.framework.common.util.object.BeanUtils;
import com.iailab.module.model.mcs.sche.dao.StScheduleModelDao;
import com.iailab.module.model.mcs.sche.entity.StScheduleModelEntity;
import com.iailab.module.model.mcs.sche.service.StScheduleModelParamService;
import com.iailab.module.model.mcs.sche.service.StScheduleModelService;
import com.iailab.module.model.mcs.sche.service.StScheduleModelSettingService;
import com.iailab.module.model.mcs.sche.vo.StScheduleModelPageReqVO;
import com.iailab.module.model.mcs.sche.vo.StScheduleModelSaveReqVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.UUID;
 
/**
 * @author PanZhibao
 * @date 2021年07月20日 14:23
 */
@Service
public class StScheduleModelServiceImpl extends BaseServiceImpl<StScheduleModelDao, StScheduleModelEntity> implements StScheduleModelService {
 
    @Autowired
    private StScheduleModelParamService stScheduleModelParamService;
 
    @Autowired
    private StScheduleModelSettingService stScheduleModelSettingService;
 
    @Override
    public PageResult<StScheduleModelEntity> page(StScheduleModelPageReqVO reqVO) {
        return baseDao.selectPage(reqVO);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(StScheduleModelSaveReqVO reqVO) {
        StScheduleModelEntity entity = BeanUtils.toBean(reqVO, StScheduleModelEntity.class);
        entity.setId(UUID.randomUUID().toString());
        baseDao.insert(entity);
        stScheduleModelParamService.saveList(entity.getId(), reqVO.getParamList());
        stScheduleModelSettingService.saveList(entity.getId(), reqVO.getSettingList());
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(StScheduleModelSaveReqVO reqVO) {
        StScheduleModelEntity entity = BeanUtils.toBean(reqVO, StScheduleModelEntity.class);
        baseDao.updateById(entity);
        stScheduleModelParamService.saveList(entity.getId(), reqVO.getParamList());
        stScheduleModelSettingService.saveList(entity.getId(), reqVO.getSettingList());
    }
 
    @Override
    public StScheduleModelEntity get(String id) {
        return baseDao.selectById(id);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(String id) {
        baseDao.deleteById(id);
        stScheduleModelParamService.deleteByModelId(id);
        stScheduleModelSettingService.deleteByModelId(id);
    }
 
    @Override
    public Long check(StScheduleModelSaveReqVO reqVO) {
        String id = reqVO.getId();
        String modelname = reqVO.getModelName();
        QueryWrapper<StScheduleModelEntity> scheduleModelWrapper = new QueryWrapper<>();
        scheduleModelWrapper.ne(StringUtils.isNotBlank(id), "id", id);
        scheduleModelWrapper.and(wrapper -> wrapper.eq("model_name", modelname));
        return baseDao.selectCount(scheduleModelWrapper);
    }
 
    @Override
    public Long count() {
        QueryWrapper<StScheduleModelEntity> wrapper = new QueryWrapper<>();
        return baseDao.selectCount(wrapper);
    }
}