yangys
2024-04-04 ed4a5236bab800094be4a8378f5098eebe3de6ac
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
package com.qianwen.smartman.modules.system.service.impl;
 
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qianwen.core.log.exception.ServiceException;
import com.qianwen.core.tool.utils.BeanUtil;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.common.utils.Lambda;
import com.qianwen.smartman.modules.system.entity.MetaObjectTypeField;
import com.qianwen.smartman.modules.system.entity.MetaRefObjectType;
import com.qianwen.smartman.modules.system.mapper.MetaObjectTypeFieldMapper;
import com.qianwen.smartman.modules.system.service.IMetaObjectTypeFieldService;
import com.qianwen.smartman.modules.system.vo.MetaObjectTypeFieldVO;
 
@Service
 
public class MetaObjectTypeFieldServiceImpl extends ServiceImpl<MetaObjectTypeFieldMapper, MetaObjectTypeField> implements IMetaObjectTypeFieldService {
    
    @Override // org.springblade.modules.system.service.IMetaObjectTypeFieldService
    @Transactional
    public boolean saveOrUpdate(MetaObjectTypeFieldVO vo) {
        if ("5".equals(vo.getElementType()) && Func.isBlank(vo.getRefObjectTypeId())) {
            throw new ServiceException("元素类型是资料必须填写引用对象");
        }
        if ("4".equals(vo.getElementType()) && Func.isBlank(vo.getEnumType())) {
            throw new ServiceException("元素类型是下拉框必须填写枚举类型");
        }
        if (vo.getObjectId().equals(vo.getRefObjectTypeId())) {
            throw new ServiceException("业务对象不能跟引用对象相同");
        }
        saveOrUpdate(BeanUtil.copy(vo, MetaObjectTypeField.class));
        if (Func.isNotBlank(vo.getRefObjectTypeId())) {
            MetaRefObjectType metaRefObjectType = (new MetaRefObjectType()).selectOne(Lambda.eq(MetaRefObjectType::getObjectTypeId, vo.getObjectId()).eq(MetaRefObjectType::getFieldName, vo.getFCode()));
            /*
            MetaRefObjectType metaRefObjectType = (MetaRefObjectType) new MetaRefObjectType().selectOne((Wrapper) Lambda.eq((v0) -> {
                return v0.getObjectTypeId();
            }, vo.getObjectId()).eq((v0) -> {
                return v0.getFieldName();
            }, vo.getFCode()));*/
            if (metaRefObjectType == null) {
                metaRefObjectType = new MetaRefObjectType();
            }
            metaRefObjectType.setRefObjectTypeId(vo.getRefObjectTypeId());
            metaRefObjectType.setObjectTypeId(vo.getObjectId());
            metaRefObjectType.setFieldName(vo.getFCode());
            metaRefObjectType.insertOrUpdate();
            return true;
        }
        return true;
    }
}