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
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
87
88
89
90
91
92
93
94
95
96
97
98
package com.qianwen.smartman.modules.tool.service.impl;
 
import java.util.List;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import com.qianwen.core.log.exception.ServiceException;
import com.qianwen.core.mp.base.BaseServiceImpl;
import com.qianwen.core.mp.support.Condition;
import com.qianwen.core.mp.support.Query;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.common.utils.MessageUtils;
import com.qianwen.smartman.modules.tool.convert.ToolModelConvert;
import com.qianwen.smartman.modules.tool.entity.Tool;
import com.qianwen.smartman.modules.tool.entity.ToolCategory;
import com.qianwen.smartman.modules.tool.entity.ToolModel;
import com.qianwen.smartman.modules.tool.mapper.ToolModelMapper;
import com.qianwen.smartman.modules.tool.service.IToolCategoryService;
import com.qianwen.smartman.modules.tool.service.IToolManageService;
import com.qianwen.smartman.modules.tool.service.IToolModelService;
import com.qianwen.smartman.modules.tool.vo.ToolModelVO;
 
@Service
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/tool/service/impl/ToolModelServiceImpl.class */
public class ToolModelServiceImpl extends BaseServiceImpl<ToolModelMapper, ToolModel> implements IToolModelService {
    @Autowired
    @Lazy
    private IToolCategoryService toolCategoryService;
    @Autowired
    @Lazy
    private IToolManageService toolManageService;
 
 
    @Override // org.springblade.modules.tool.service.IToolModelService
    public IPage<ToolModelVO> page(String keyWord, Long categoryId, Boolean isShowChild, Query query) {
        if (Func.isEmpty(isShowChild)) {
            isShowChild = true;
        }
        List<Long> categoryIdList = this.toolCategoryService.getChildrenIds(Lists.newArrayList(new Long[]{categoryId}), Lists.newArrayList(new Long[]{categoryId}));
        if (!isShowChild.booleanValue()) {
            categoryIdList = Lists.newArrayList(new Long[]{categoryId});
        }
        return ((ToolModelMapper) this.baseMapper).listByIds(Condition.getPage(query), categoryId, categoryIdList, keyWord);
    }
 
    @Override // org.springblade.modules.tool.service.IToolModelService
    public ToolModelVO save(ToolModelVO toolModelVO) {
        checkName(toolModelVO);
        if (Func.isNotEmpty(toolModelVO.getId())) {
            ToolCategory toolCategory = (ToolCategory) this.toolCategoryService.getById(toolModelVO.getToolCategoryId());
            toolModelVO.setToolPrefixCode(toolCategory.getToolPrefixCode());
        }
        ToolModel toolModel = ToolModelConvert.INSTANCE.convert(toolModelVO);
        saveOrUpdate(toolModel);
        return ToolModelConvert.INSTANCE.convert(toolModel);
    }
 
    private void checkName(ToolModelVO toolModelVO) {
        long count = count(Wrappers.<ToolModel>lambdaQuery()
                .ne(Func.isNotEmpty(toolModelVO.getId()), ToolModel::getId, toolModelVO.getId())
                .eq(ToolModel::getToolCategoryId, toolModelVO.getToolCategoryId())
                .eq(ToolModel::getModel, toolModelVO.getModel()));
        /*
        long count = count((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().ne(Func.isNotEmpty(toolModelVO.getId()), (v0) -> {
            return v0.getId();
        }, toolModelVO.getId()).eq((v0) -> {
            return v0.getToolCategoryId();
        }, toolModelVO.getToolCategoryId())).eq((v0) -> {
            return v0.getModel();
        }, toolModelVO.getModel()));*/
        if (count > 0) {
            throw new ServiceException(MessageUtils.message("tool.model.name.already.exists", new Object[0]));
        }
    }
 
    @Override // org.springblade.modules.tool.service.IToolModelService
    public boolean remove(List<Long> ids) {
        long count = this.toolManageService.count(Wrappers.<Tool>lambdaQuery().in(Tool::getToolModelId, ids));
        /*
        long count = this.toolManageService.count((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
            return v0.getToolModelId();
        }, ids));*/
        if (count > 0) {
            throw new ServiceException(MessageUtils.message("tool.model.have.tool.can.not.delete", new Object[0]));
        }
        return removeBatchByIds(ids);
    }
 
    @Override // org.springblade.modules.tool.service.IToolModelService
    public ToolModelVO detail(String id) {
        return ((ToolModelMapper) this.baseMapper).detail(id);
    }
}