wl
2022-11-14 1349fda00a75a5cb6560c74ba9040ce138dd4883
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
package com.ycl.controller.epuipment;
 
 
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ycl.annotation.LogSave;
import com.ycl.api.CommonResult;
import com.ycl.controller.BaseController;
import com.ycl.entity.dict.DataDictionary;
import com.ycl.entity.equipment.EquipmentBayonet;
import com.ycl.entity.region.SccgRegion;
import com.ycl.service.dict.IDataDictionaryService;
import com.ycl.service.equipment.IEquipmentBayonetService;
import com.ycl.service.region.ISccgRegionService;
import com.ycl.utils.EasyExcelUtils;
import com.ycl.vo.equipment.EquipmentBayonetVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 卡口管理 前端控制器
 * </p>
 *
 * @author wl
 * @since 2022-10-14
 */
@RestController
@RequestMapping("/equipment_bayonet")
@Api(tags = "卡口管理")
public class EquipmentBayonetController extends BaseController {
 
    @Autowired
    IEquipmentBayonetService iEquipmentBayonetService;
    @Autowired
    IDataDictionaryService iDataDictionaryService;
    @Autowired
    ISccgRegionService iSccgRegionService;
 
    @GetMapping("/query")
    @ApiOperation("查询")
    @LogSave
    public CommonResult search(@RequestParam(required = false) Integer size,
                               @RequestParam(required = false) Integer current,
                               @RequestParam(required = false) String bayonetName) {
        Page<EquipmentBayonet> equipmentBayonetPage = new Page<>();
        equipmentBayonetPage.setCurrent(current);
        equipmentBayonetPage.setSize(size);
        return CommonResult.success(iEquipmentBayonetService
                .page(equipmentBayonetPage, new LambdaQueryWrapper<EquipmentBayonet>()
                        .like(StringUtils.isNotBlank(bayonetName), EquipmentBayonet::getBayonetName, bayonetName))
                .getRecords()
                .stream()
                .map(item -> {
                    EquipmentBayonetVO equipmentBayonetVO = new EquipmentBayonetVO();
                    BeanUtils.copyProperties(item, equipmentBayonetVO);
                    equipmentBayonetVO.setFrontEndType(iDataDictionaryService.getOne(new LambdaQueryWrapper<DataDictionary>().eq(DataDictionary::getId, item.getFrontEndType())).getName());
                    equipmentBayonetVO.setInOutCityType(iDataDictionaryService.getOne(new LambdaQueryWrapper<DataDictionary>().eq(DataDictionary::getId, item.getInOutCityType())).getName());
                    equipmentBayonetVO.setBelongArea(iSccgRegionService.getOne(new LambdaQueryWrapper<SccgRegion>().eq(SccgRegion::getId,item.getBelongArea())).getRegionName());
                    return equipmentBayonetVO;
                }).collect(Collectors.toList()));
    }
 
    @PostMapping("/addition")
    @ApiOperation("添加")
    @LogSave(operationType = "卡口管理", contain = "添加卡口")
    public CommonResult add(@RequestBody EquipmentBayonet equipmentBayonet) {
        return CommonResult.success(iEquipmentBayonetService.save(equipmentBayonet));
    }
 
    @PutMapping("/modification")
    @ApiOperation("修改")
    @LogSave(operationType = "卡口管理", contain = "修改卡口")
    public CommonResult modify(@RequestBody EquipmentBayonet equipmentBayonet) {
        return CommonResult.success(iEquipmentBayonetService.updateById(equipmentBayonet));
    }
 
    @GetMapping("/export")
    @ApiOperation("导出")
    @SneakyThrows
    @LogSave(operationType = "卡口管理", contain = "导出卡口")
    public void export(HttpServletResponse response,
                       @RequestParam(required = false) Integer size,
                       @RequestParam(required = false) Integer current,
                       @RequestParam(required = false) String bayonetName) {
        Page<EquipmentBayonet> equipmentBayonetPage = new Page<>();
        equipmentBayonetPage.setCurrent(current);
        equipmentBayonetPage.setSize(size);
        EasyExcelUtils.export(response,"数据",EquipmentBayonetVO.class,iEquipmentBayonetService
                .page(equipmentBayonetPage, new LambdaQueryWrapper<EquipmentBayonet>()
                        .like(StringUtils.isNotBlank(bayonetName), EquipmentBayonet::getBayonetName, bayonetName))
                .getRecords()
                .stream()
                .map(item -> {
                    EquipmentBayonetVO equipmentBayonetVO = new EquipmentBayonetVO();
                    BeanUtils.copyProperties(item, equipmentBayonetVO);
                    equipmentBayonetVO.setFrontEndType(iDataDictionaryService.getOne(new LambdaQueryWrapper<DataDictionary>().eq(DataDictionary::getId, item.getFrontEndType())).getName());
                    equipmentBayonetVO.setInOutCityType(iDataDictionaryService.getOne(new LambdaQueryWrapper<DataDictionary>().eq(DataDictionary::getId, item.getInOutCityType())).getName());
                    return equipmentBayonetVO;
                }).collect(Collectors.toList()));
    }
}