ustcyc
2025-01-07 de5d55508afd27fb2b47e6d4d6fd9984525c222c
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
package com.zhitan.web.controller.basicdata;
 
import com.zhitan.basicdata.domain.FacilityArchives;
import com.zhitan.basicdata.services.IFacilityArchivesService;
import com.zhitan.common.annotation.Log;
import com.zhitan.common.core.controller.BaseController;
import com.zhitan.common.core.domain.AjaxResult;
import com.zhitan.common.core.domain.model.LoginUser;
import com.zhitan.common.core.page.TableDataInfo;
import com.zhitan.common.enums.BusinessType;
import com.zhitan.common.utils.ServletUtils;
import com.zhitan.common.utils.poi.ExcelUtil;
import com.zhitan.framework.web.service.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import java.util.List;
import java.util.UUID;
 
/**
 * 设备档案Controller
 *
 * @author zhaowei
 * @date 2020-02-24
 */
@RestController
@RequestMapping("/facility/archives")
@Api(value = "设备档案controller",tags = {"设备档案管理"})
public class FacilityArchivesController extends BaseController
{
    @Autowired
    private IFacilityArchivesService facilityArchivesService;
    @Autowired
    private TokenService tokenService;
    /**
     * 查询设备档案列表
     */
    @ApiOperation(value = "设备档案列表")
    @PreAuthorize("@ss.hasPermi('facility:archives:list')")
    @GetMapping("/list")
    public TableDataInfo list(FacilityArchives facilityArchives)
    {
        startPage();
        List<FacilityArchives> list = facilityArchivesService.selectFacilityArchivesList(facilityArchives);
        return getDataTable(list);
    }
 
    /**
     * 导出设备档案列表
     */
    @PreAuthorize("@ss.hasPermi('facility:archives:export')")
    @Log(title = "设备档案", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("设备档案列表导出")
    public AjaxResult export(FacilityArchives facilityArchives)
    {
        List<FacilityArchives> list = facilityArchivesService.excelFacilityArchivesList(facilityArchives);
        ExcelUtil<FacilityArchives> util = new ExcelUtil<FacilityArchives>(FacilityArchives.class);
        return util.exportExcel(list, "archives");
    }
 
    /**
     * 获取设备档案详细信息
     */
    @PreAuthorize("@ss.hasPermi('facility:archives:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "根据id获取设备档案详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(facilityArchivesService.selectFacilityArchivesById(id));
    }
 
    /**
     * 新增设备档案
     */
    @PreAuthorize("@ss.hasPermi('facility:archives:add')")
    @Log(title = "设备档案", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增设备档案")
    public AjaxResult add(@RequestBody FacilityArchives facilityArchives)
    {
        FacilityArchives check = facilityArchivesService.selectFacilityArchivesByCode(facilityArchives);
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        //编号唯一性检测
        if(check!=null && check.getCode()!=null && check.getCode().length()>0)
        {
            return  AjaxResult.error(check.getCode()+"编码已存在!");
        }else
        {
            facilityArchives.setId(UUID.randomUUID().toString());
            facilityArchives.setCreateBy(loginUser.getUsername());
            return toAjax(facilityArchivesService.insertFacilityArchives(facilityArchives));
        }
    }
 
    /**
     * 修改设备档案
     */
    @PreAuthorize("@ss.hasPermi('facility:archives:edit')")
    @Log(title = "设备档案", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "编辑设备档案")
    public AjaxResult edit(@RequestBody FacilityArchives facilityArchives)
    {
        //更新时的编码 唯一约束 要判断 id不等于自己,且 code存在重复的,要先去掉自己,否则 自己的修改也报错
        FacilityArchives check = facilityArchivesService.selectFacilityArchivesByCode(facilityArchives);
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        //编号唯一性检测
        if(check!=null && check.getCode()!=null && check.getCode().length()>0)
        {
            return  AjaxResult.error(check.getCode()+"编码已存在!");
        }else
        {
            facilityArchives.setUpdateBy(loginUser.getUsername());
            return toAjax(facilityArchivesService.updateFacilityArchives(facilityArchives));
        }
 
    }
 
    /**
     * 删除设备档案
     */
    @PreAuthorize("@ss.hasPermi('facility:archives:remove')")/**/
    @Log(title = "设备档案", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除设备档案")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(facilityArchivesService.deleteFacilityArchivesByIds(ids));
    }
  /**
     * 检定恢复
     */
    @PreAuthorize("@ss.hasPermi('facility:archives:reset')")
    @Log(title = "设备档案", businessType = BusinessType.UPDATE)
    @PostMapping ("/{ids}")
    @ApiOperation(value = "设备档案检定恢复")
    public AjaxResult reset(@PathVariable String[] ids)
    {
        return toAjax(facilityArchivesService.resetFacilityArchivesByIds(ids));
    }
 
 
    @Log(title = "设备档案维护导入", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('facility:archives:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<FacilityArchives> util = new ExcelUtil<FacilityArchives>(FacilityArchives.class);
        List<FacilityArchives> facilityList = util.importExcel(file.getInputStream());
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        String message = facilityArchivesService.excelImpSave(facilityList,loginUser);
        return AjaxResult.success(message);
    }
 
    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<FacilityArchives> util = new ExcelUtil<FacilityArchives>(FacilityArchives.class);
        return util.importTemplateExcel("设备档案数据");
    }
}