doum
2025-09-12 9877679062815a39739c8ca0c02a70acc282f68c
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package com.doumee.service.business.impl;
 
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.CompanyDocumentsMapper;
import com.doumee.dao.business.model.Category;
import com.doumee.dao.business.model.Company;
import com.doumee.dao.business.model.CompanyDocuments;
import com.doumee.dao.business.model.Member;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.service.business.CompanyDocumentsService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.doumee.service.business.third.model.LoginUserInfo;
import com.doumee.service.business.third.model.PageData;
import com.doumee.service.business.third.model.PageWrap;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
/**
 * 隐患区域配置类型信息表Service实现
 * @author 江蹄蹄
 * @date 2025/06/27 16:01
 */
@Service
public class CompanyDocumentsServiceImpl implements CompanyDocumentsService {
 
    @Autowired
    private CompanyDocumentsMapper companyDocumentsMapper;
 
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
 
    @Override
    public Integer create(CompanyDocuments companyDocuments) {
        if(Objects.isNull(companyDocuments)
                || Objects.isNull(companyDocuments.getCompanyId())
                || Objects.isNull(companyDocuments.getCategoryId())
                || StringUtils.isBlank(companyDocuments.getName())
                || StringUtils.isBlank(companyDocuments.getFileurl())
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        companyDocuments.setId(null);
        companyDocuments.setCreateDate(new Date());
        companyDocuments.setCreator(companyDocuments.getLoginUserInfo().getId());
        companyDocuments.setIsdeleted(Constants.ZERO);
        companyDocuments.setStatus(Constants.ZERO);
        companyDocumentsMapper.insert(companyDocuments);
        return companyDocuments.getId();
    }
 
    @Override
    public void deleteById(Integer id, LoginUserInfo user) {
        UpdateWrapper<CompanyDocuments> deleteWrapper = new UpdateWrapper<>();
        deleteWrapper.lambda().set(CompanyDocuments::getIsdeleted,Constants.ONE)
                .eq(CompanyDocuments::getId,id)
                .set(CompanyDocuments::getEditDate,new Date())
                .set(CompanyDocuments::getEditor,user.getId());
        companyDocumentsMapper.update(deleteWrapper);
    }
 
    @Override
    public void delete(CompanyDocuments companyDocuments) {
        UpdateWrapper<CompanyDocuments> deleteWrapper = new UpdateWrapper<>(companyDocuments);
        companyDocumentsMapper.update(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids, LoginUserInfo user) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        companyDocumentsMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void updateById(CompanyDocuments companyDocuments) {
        if(Objects.isNull(companyDocuments)
                || Objects.isNull(companyDocuments.getId())
                || Objects.isNull(companyDocuments.getCompanyId())
                || Objects.isNull(companyDocuments.getCategoryId())
                || StringUtils.isBlank(companyDocuments.getName())
                || StringUtils.isBlank(companyDocuments.getFileurl())
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        companyDocuments.setId(null);
        companyDocuments.setEditDate(new Date());
        companyDocuments.setEditor(companyDocuments.getLoginUserInfo().getId());
        companyDocumentsMapper.updateById(companyDocuments);
    }
 
    @Override
    public void updateByIdInBatch(List<CompanyDocuments> companyDocumentss) {
        if (CollectionUtils.isEmpty(companyDocumentss)) {
            return;
        }
        for (CompanyDocuments companyDocuments: companyDocumentss) {
            this.updateById(companyDocuments);
        }
    }
 
    @Override
    public CompanyDocuments findById(Integer id) {
        CompanyDocuments companyDocuments = companyDocumentsMapper.selectById(id);
        if(Objects.isNull(companyDocuments)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if(StringUtils.isNotBlank(companyDocuments.getFileurl())){
            String path = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_LOCAL_RESOURCE_PATH).getCode()
                    +systemDictDataBiz.queryByCode(Constants.FTP,Constants.COMPANY_DOCUMENTS).getCode();
            companyDocuments.setFileurlFull(path + companyDocuments.getFileurl());
        }
        return companyDocuments;
    }
 
    @Override
    public CompanyDocuments findOne(CompanyDocuments companyDocuments) {
        QueryWrapper<CompanyDocuments> wrapper = new QueryWrapper<>(companyDocuments);
        return companyDocumentsMapper.selectOne(wrapper);
    }
 
    @Override
    public List<CompanyDocuments> findList(CompanyDocuments companyDocuments) {
        QueryWrapper<CompanyDocuments> wrapper = new QueryWrapper<>(companyDocuments);
        return companyDocumentsMapper.selectList(wrapper);
    }
  
    @Override
    public PageData<CompanyDocuments> findPage(PageWrap<CompanyDocuments> pageWrap) {
        IPage<CompanyDocuments> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<CompanyDocuments> queryWrapper = new MPJLambdaWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        CompanyDocuments queryModel = pageWrap.getModel();
        queryWrapper.selectAll(CompanyDocuments.class)
                .selectAs(Company::getName,CompanyDocuments::getCompanyName)
                .selectAs(Category::getName,CompanyDocuments::getCategoryName)
                .selectAs(SystemUser::getRealname,CompanyDocuments::getCreatorName)
                .leftJoin(Company.class,Company::getId,CompanyDocuments::getCompanyId)
                .leftJoin(Category.class,Category::getId,CompanyDocuments::getCategoryId)
                .leftJoin(SystemUser.class,SystemUser::getId,CompanyDocuments::getCreator)
                .eq(CompanyDocuments::getIsdeleted,Constants.ZERO)
                .like(Objects.nonNull(queryModel)&&StringUtils.isNotBlank(queryModel.getName()),CompanyDocuments::getName,queryModel.getName())
                .eq(Objects.nonNull(queryModel)&&Objects.nonNull(queryModel.getCategoryId()),CompanyDocuments::getCategoryId,queryModel.getCategoryId())
                .eq(Objects.nonNull(queryModel)&&Objects.nonNull(queryModel.getCompanyId()),CompanyDocuments::getCompanyId,queryModel.getCompanyId())
                .orderByDesc(CompanyDocuments::getSortnum)
                .orderByDesc(CompanyDocuments::getCreateDate);
        IPage<CompanyDocuments> iPage = companyDocumentsMapper.selectJoinPage(page, CompanyDocuments.class,queryWrapper);
        String path = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_LOCAL_RESOURCE_PATH).getCode()
                +systemDictDataBiz.queryByCode(Constants.FTP,Constants.COMPANY_DOCUMENTS).getCode();
        for (CompanyDocuments companyDocuments:iPage.getRecords()) {
            companyDocuments.setFileurlFull(path + companyDocuments.getFileurl());
        }
        return PageData.from(iPage);
    }
 
    @Override
    public long count(CompanyDocuments companyDocuments) {
        QueryWrapper<CompanyDocuments> wrapper = new QueryWrapper<>(companyDocuments);
        return companyDocumentsMapper.selectCount(wrapper);
    }
}