郑永安
2023-06-19 59e91a4e9ddaf23cebb12993c774aa899ab22d16
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
package com.gk.firework.Service.ServiceImpl;
 
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gk.firework.Domain.Exception.BusinessException;
import com.gk.firework.Domain.StandardTemplate1;
import com.gk.firework.Domain.UserInfo;
import com.gk.firework.Domain.Utils.Properties;
import com.gk.firework.Domain.Utils.StringUtils;
import com.gk.firework.Domain.Utils.UploadUtil;
import com.gk.firework.Domain.Vo.StandardTemplate1Vo;
import com.gk.firework.Mapper.StandardTemplate1Mapper;
import com.gk.firework.Service.StandardTemplate1Service;
import com.gk.firework.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
 
@Service("standardTemplate1Service")
public class StandardTemplate1ServiceImpl extends ServiceImpl<StandardTemplate1Mapper, StandardTemplate1> implements StandardTemplate1Service {
 
    @Autowired
    private StandardTemplate1Mapper standardTemplate1Mapper;
    @Autowired
    private UserService userService;
 
    @Override
    public IPage selectPage(Page<StandardTemplate1> page, Map filter, UserInfo userInfo) {
 
        UserInfo user = userService.getById(userInfo.getId());
        Map<String, Object> params = new HashMap<>();
        //菜单
        params.put("menu", filter.get("menu"));
        params.put("type", filter.get("type"));
        //可视权限
        {
            params.put("enterprisenumber", user.getCompanynumber());
            params.put("province", user.getProvince());
            params.put("city", user.getCity());
            params.put("district", user.getArea());
            params.put("street", user.getTown());
            params.put("committee", user.getCommunity());
        }
 
        params.put("filterProvince", filter.get("province"));
        params.put("filterCity", filter.get("city"));
        params.put("filterDistrict", filter.get("district"));
        params.put("filterStreet", filter.get("street"));
        params.put("filterCommittee", filter.get("committee"));
        params.put("safetysupervision", filter.get("safetysupervision"));
        params.put("enterprisename", filter.get("enterprisename"));
        List<StandardTemplate1> list = standardTemplate1Mapper.selectPages(page, params);
        return page.setRecords(list);
    }
 
 
    @Override
    @Transactional
    public void addStandard(StandardTemplate1Vo standardTemplate1Vo, UserInfo user) {
 
        if (standardTemplate1Vo.getFile() == null) {
            throw new BusinessException("未上传文件");
        }
        if (StringUtils.isBlank(standardTemplate1Vo.getMenu())) {
            throw new BusinessException("菜单发生错误");
        }
 
        UserInfo userInfo = userService.getById(user.getId());
        StandardTemplate1 template1 = new StandardTemplate1();
        template1.setMenu(standardTemplate1Vo.getMenu());
        template1.setSettime(standardTemplate1Vo.getSettime());
        template1.setEnterprisenumber(userInfo.getCompanynumber());
        template1.setEnterprisename(userInfo.getUsername());
        template1.setName(standardTemplate1Vo.getName());
        template1.setCreatetime(new Date());
        template1.setCreateby(user.getId());
        template1.setCreatebyname(user.getUsername());
        template1.setValidflag(true);
        template1.setType(standardTemplate1Vo.getType());
        template1.setContent(standardTemplate1Vo.getContent());
 
 
        try {
            String name = UploadUtil.uploadFile(standardTemplate1Vo.getFile(), Properties.standardPath);
            template1.setFilename(standardTemplate1Vo.getFile().getOriginalFilename());
            template1.setUrl(Properties.standard + name);
        } catch (Exception e) {
            throw new BusinessException("上传发生错误");
        }
 
        this.save(template1);
 
 
    }
 
    /**
    * @Description: 修改简单模板
    * @date 2021/4/30 16:15
    */
    @Override
    public void modStandard(StandardTemplate1Vo standardTemplate1Vo, UserInfo user) {
 
 
        if (StringUtils.isBlank(standardTemplate1Vo.getMenu())) {
            throw new BusinessException("菜单发生错误");
        }
 
        UserInfo userInfo = userService.getById(user.getId());
        StandardTemplate1 template1 = new StandardTemplate1();
        template1.setId(standardTemplate1Vo.getId());
        template1.setMenu(standardTemplate1Vo.getMenu());
        template1.setSettime(standardTemplate1Vo.getSettime());
        template1.setEnterprisenumber(userInfo.getCompanynumber());
        template1.setEnterprisename(userInfo.getUsername());
        template1.setName(standardTemplate1Vo.getName());
        template1.setCreatetime(new Date());
        template1.setCreateby(user.getId());
        template1.setCreatebyname(user.getUsername());
        template1.setValidflag(true);
        template1.setType(standardTemplate1Vo.getType());
        template1.setContent(standardTemplate1Vo.getContent());
        try {
            if (standardTemplate1Vo.getFile() != null) {
                String name = UploadUtil.uploadFile(standardTemplate1Vo.getFile(), Properties.standardPath);
                template1.setFilename(standardTemplate1Vo.getFile().getOriginalFilename());
                template1.setUrl(Properties.standard + name);
            }
 
        } catch (Exception e) {
            throw new BusinessException("上传发生错误");
        }
 
        this.updateById(template1);
 
    }
 
    /**
    * @Description: 删除简单模板
    * @date 2021/4/30 16:25
    */
    @Override
    public void delStandard(Long id, UserInfo user) {
        LambdaUpdateWrapper<StandardTemplate1> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(StandardTemplate1::getValidflag, false)
                .set(StandardTemplate1::getUpdatetime, new Date())
                .set(StandardTemplate1::getUpdateby, user.getId())
                .set(StandardTemplate1::getUpdatebyname,user.getUsername())
                .eq(StandardTemplate1::getId, id);
        this.update(updateWrapper);
    }
 
 
}