“djh”
5 天以前 5ca4ab349909030e77354832287f2d6a2c80e119
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package com.gkhy.exam.system.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.exam.common.api.CommonPage;
import com.gkhy.exam.common.api.CommonResult;
import com.gkhy.exam.common.domain.TreeSelect;
import com.gkhy.exam.common.domain.entity.SysDept;
import com.gkhy.exam.common.domain.model.LoginUserDetails;
import com.gkhy.exam.common.exception.ApiException;
import com.gkhy.exam.common.utils.PageUtils;
import com.gkhy.exam.common.utils.SecurityUtils;
import com.gkhy.exam.system.domain.*;
import com.gkhy.exam.system.mapper.*;
import com.gkhy.exam.system.service.CompanyIndustryTemplateService;
import com.gkhy.exam.system.service.ISysDeptService;
import com.gkhy.exam.system.service.StandardizedTemplateService;
import com.gkhy.exam.system.service.SysCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service
public class StandardizedTemplateServiceImpl extends ServiceImpl<StandardizedTemplateMapper, StandardizedTemplate> implements StandardizedTemplateService {
 
    @Autowired
    private StandardizedTemplateMapper standardizedTemplateMapper;
    @Autowired
    private SysCompanyService sysCompanyService;
 
    @Autowired
    private StandardizedQualityMapper standardizedQualityMapper;
 
    @Autowired
    private SysFunctionalDistributionMapper sysFunctionalDistributionMapper;
 
    @Autowired
    private ISysDeptService iSysDeptService;
 
    @Autowired
    private CompanySummaryMapper companySummaryMapper;
    @Autowired
    private CompanyQualityPolicyMapper companyQualityPolicyMapper;
    @Override
    public CommonPage selectStandardizedTemplateList(Integer companyId, Integer templateType) {
        boolean admin = SecurityUtils.adminUser();
        if (!admin){
            if (companyId==null){
                companyId = SecurityUtils.getCompanyId().intValue();
            }
        }
        PageUtils.startPage();
        List<StandardizedTemplate> companyIndustryTemplates = standardizedTemplateMapper.selectStandardizedTemplateList(companyId, templateType);
        return CommonPage.restPage(companyIndustryTemplates);
    }
 
    @Override
    public CommonResult insertStandardizedTemplate(StandardizedTemplate standardizedTemplate) {
        LoginUserDetails loginUser = SecurityUtils.getLoginUser();
 
        SysCompany sysCompany = sysCompanyService.selectCompanyById(standardizedTemplate.getCompanyId().longValue());
        standardizedTemplate.setCompanyName(sysCompany.getName());
        standardizedTemplate.setCreateBy(loginUser.getUsername());
        standardizedTemplate.setCreateTime(LocalDateTime.now());
        int insert = standardizedTemplateMapper.insert(standardizedTemplate);
        if (insert>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
 
    @Override
    public CommonResult updateStandardizedTemplate(StandardizedTemplate standardizedTemplate) {
        LoginUserDetails loginUser = SecurityUtils.getLoginUser();
        SysCompany sysCompany = sysCompanyService.selectCompanyById(standardizedTemplate.getCompanyId().longValue());
        standardizedTemplate.setCompanyName(sysCompany.getName());
        standardizedTemplate.setUpdateBy(loginUser.getUsername());
        standardizedTemplate.setUpdateTime(LocalDateTime.now());
        int update = standardizedTemplateMapper.updateStandardizedTemplateById(standardizedTemplate);
        if (update>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
 
    @Override
    public CommonResult deletedStandardizedTemplate(Integer standardizedTemplateId) {
        StandardizedTemplate standardizedTemplate = new StandardizedTemplate();
        LoginUserDetails loginUser = SecurityUtils.getLoginUser();
        standardizedTemplate.setUpdateBy(loginUser.getUsername());
        standardizedTemplate.setUpdateTime(LocalDateTime.now());
        standardizedTemplate.setDelFlag(1);
        standardizedTemplate.setId(standardizedTemplateId);
        int i = standardizedTemplateMapper.updateById(standardizedTemplate);
        if (i>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
 
    @Override
    public CommonResult selectStandardizedQuality(Integer companyId) {
        boolean admin = SecurityUtils.adminUser();
        LambdaQueryWrapper<StandardizedQuality> lambdaQueryWrapper = Wrappers.<StandardizedQuality>lambdaQuery();
        if (!admin){
            if (companyId==null){
                lambdaQueryWrapper.eq(StandardizedQuality::getCompanyId, SecurityUtils.getCompanyId().intValue());
            }
        }
        lambdaQueryWrapper.eq(StandardizedQuality::getDelFlag, 0);
        return CommonResult.success(standardizedQualityMapper.selectList(lambdaQueryWrapper));
    }
 
    @Override
    public CommonResult insertStandardizedQuality(StandardizedQuality standardizedQuality) {
        LambdaQueryWrapper<StandardizedQuality> eq = new LambdaQueryWrapper<StandardizedQuality>().eq(StandardizedQuality::getCompanyId, standardizedQuality.getCompanyId());
        standardizedQualityMapper.delete(eq);
        LoginUserDetails loginUser = SecurityUtils.getLoginUser();
 
        SysCompany sysCompany = sysCompanyService.selectCompanyById(standardizedQuality.getCompanyId().longValue());
        standardizedQuality.setCompanyName(sysCompany.getName());
        standardizedQuality.setCreateBy(loginUser.getUsername());
        standardizedQuality.setCreateTime(LocalDateTime.now());
        int insert = standardizedQualityMapper.insert(standardizedQuality);
        if (insert>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
 
    @Override
    public CommonResult updateStandardizedQuality(StandardizedQuality standardizedQuality) {
        LoginUserDetails loginUser = SecurityUtils.getLoginUser();
        SysCompany sysCompany = sysCompanyService.selectCompanyById(standardizedQuality.getCompanyId().longValue());
        standardizedQuality.setCompanyName(sysCompany.getName());
        standardizedQuality.setUpdateBy(loginUser.getUsername());
        standardizedQuality.setUpdateTime(LocalDateTime.now());
        int update = standardizedQualityMapper.updateStandardizedQualityById(standardizedQuality);
        if (update>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
 
    @Override
    public CommonResult deletedStandardizedQuality(Integer id) {
        LambdaQueryWrapper<StandardizedQuality> lambdaQueryWrapper = Wrappers.<StandardizedQuality>lambdaQuery()
                .eq(StandardizedQuality::getId, id)
                .eq(StandardizedQuality::getDelFlag, 0);
        StandardizedQuality standardizedQuality = new StandardizedQuality();
        standardizedQuality.setDelFlag(1);
        standardizedQuality.setUpdateBy(SecurityUtils.getUsername());
        standardizedQuality.setUpdateTime(LocalDateTime.now());
        standardizedQualityMapper.update(standardizedQuality, lambdaQueryWrapper);
        return CommonResult.success();
    }
 
    @Override
    public CommonResult getStandardizedQualityByCompanyId(Integer companyId) {
        Map<String, Object> map = new HashMap<>();
        //程序文件
        List<StandardizedTemplate> companyIndustryTemplates = standardizedTemplateMapper.selectStandardizedTemplateList(companyId, 4);
        //职能分配
        List<SysFunctionalDistribution> sysFunctionalDistributions = sysFunctionalDistributionMapper.selectListVo(companyId.longValue());
        //部门
        SysDept sysDept = new SysDept();
        sysDept.setCompanyId(companyId.longValue());
        List<TreeSelect> treeSelects = iSysDeptService.selectDeptTreeList(sysDept);
 
        //公司概况
        List<CompanySummary> companySummaries = companySummaryMapper.selectCompanySummaryList(companyId);
 
        //质量方针
        List<CompanyQualityPolicy> companyQualityPolicies = companyQualityPolicyMapper.selectCompanyQualityPolicyList(companyId);
        //质量方针
        map.put("companyQualityPolicies", companyQualityPolicies);
        //公司概况
        map.put("companySummaries", companySummaries);
        //部门
        map.put("treeSelects", treeSelects);
        //职能分配
        map.put("sysFunctionalDistributions", sysFunctionalDistributions);
        //程序文件
        map.put("companyIndustryTemplates", companyIndustryTemplates);
        return CommonResult.success(map);
    }
}