智慧保安后台管理-外网项目备份
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
194
195
196
197
198
199
200
201
202
203
204
205
206
package org.springblade.modules.equipage.controller;
 
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.apache.commons.codec.Charsets;
import org.springblade.common.excel.RowWriteHandler;
import org.springblade.common.utils.arg;
import org.springblade.core.excel.util.ExcelUtil;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.FTP.FtpUtil;
import org.springblade.modules.equipage.entity.Car;
import org.springblade.modules.equipage.excel.CarExcel;
import org.springblade.modules.equipage.excel.CarImporter;
import org.springblade.modules.equipage.service.CarService;
import org.springblade.modules.equipage.vo.CarVo;
import org.springblade.modules.system.service.MyAsyncService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * @author zhongrj
 * @time 2021-07-06
 * @desc 车辆控制层
 */
@RestController
@AllArgsConstructor
@RequestMapping("/car")
public class CarController {
 
    private final CarService carService;
    private final MyAsyncService myAsyncService;
 
    /**
     * 自定义分页
     *
     * @param query page,size
     * @param car   车辆信息对象
     */
    @GetMapping("/page")
    public R<IPage<CarVo>> page(CarVo car, Query query) {
        IPage<CarVo> pages = carService.selectCarPage(Condition.getPage(query), car);
        return R.data(pages);
    }
 
    /**
     * 新增
     *
     * @param car 车辆信息对象
     */
    @PostMapping("/save")
    @ApiOperation(value = "新增", notes = "传入car")
    public R save(@RequestBody Car car) {
        return R.status(carService.save(car));
    }
 
    /**
     * 修改
     *
     * @param car 车辆信息对象
     */
    @PostMapping("/update")
    public R update(@RequestBody Car car) {
        return R.status(carService.updateById(car));
    }
 
    /**
     * 新增或修改
     *
     * @param car 车辆信息对象
     */
    @PostMapping("/submit")
    public R submit(@RequestBody Car car) throws Exception {
        boolean status = false;
        if (null == car.getId()) {
            car.setDateForProduction(new Date());
            //新增
            status = carService.save(car);
            if (status) {
                //数据同步
                String s1 =
                    "insert into sys_car(id,car_number,number_type,car_type,dept_id," +
                        "person_in_charge,brand,date_for_production,umweltsatz,mode,jurisdiction) " +
                        "values(" + "'" + car.getId() + "'" + "," +
                        "'" + car.getCarNumber() + "'" + "," +
                        "'" + car.getNumberType() + "'" + "," +
                        "'" + car.getCarType() + "'" + "," +
                        "'" + car.getDeptId() + "'" + "," +
                        "'" + car.getPersonInCharge() + "'" + "," +
                        "'" + car.getBrand() + "'" + "," +
                        "'" + new SimpleDateFormat("yyyy-MM-dd").format(car.getDateForProduction()) + "'" + "," +
                        "'" + car.getUmweltsatz() + "'" + "," +
                        "'" + car.getMode() + "'" + "," +
                        "'" + car.getJurisdiction() + "'" + ")";
                //FtpUtil.sqlFileUpload(s1);
                myAsyncService.dataSync(s1);
            }
 
        } else {
            //修改
            status = carService.updateById(car);
            if (status) {
                //内网同步
                String s1 =
                    "update sys_car set car_number = " + "'" + car.getCarNumber() + "'" +
                        ",number_type = " + "'" + car.getNumberType() + "'" +
                        ",car_type = " + "'" + car.getCarType() + "'" +
                        ",dept_id = " + "'" + car.getDeptId() + "'" +
                        ",person_in_charge = " + "'" + car.getJurisdiction() + "'" +
                        ",brand = " + "'" + car.getBrand() + "'" +
                        ",date_for_production = " + "'" + new SimpleDateFormat("yyyy-MM-dd").format(car.getDateForProduction()) + "'" +
                        ",umweltsatz = " + "'" + car.getUmweltsatz() + "'" +
                        ",mode = " + "'" + car.getMode() + "'" +
                        ",jurisdiction = " + "'" + car.getJurisdiction() + "'" +
                        " " + "where id = " + "'" + car.getId() + "'";
                //FtpUtil.sqlFileUpload(s1);
                myAsyncService.dataSync(s1);
            }
        }
        return R.status(status);
    }
 
    /**
     * 删除
     *
     * @param ids 车辆信息ids 数组
     */
    @PostMapping("/remove")
    public R remove(@ApiParam(value = "主键集合") @RequestParam String ids) {
        //内网删除
        List<Long> list = Func.toLongList(ids);
        list.forEach(id -> {
            //内网同步
            String s1 = "delete from sys_car where id = " + "'" + id + "'";
            //FtpUtil.sqlFileUpload(s1);
            myAsyncService.dataSync(s1);
        });
        return R.status(carService.removeByIds(Func.toLongList(ids)));
    }
 
    /**
     * 详情
     *
     * @param car 车辆信息对象
     */
    @GetMapping("/detail")
    @ApiOperation(value = "详情", notes = "传入car")
    public R<CarVo> detail(Car car) {
        CarVo detail = carService.selectCarInfo(car);
        return R.data(detail);
    }
 
    /**
     * 导入车辆信息, excel
     */
    @PostMapping("import-car")
    public R importCar(MultipartFile file, Integer isCovered, String deptId) {
        CarImporter carImporter = new CarImporter(carService, false, deptId);
        ExcelUtil.save(file, carImporter, CarExcel.class);
        return R.success("操作成功");
    }
 
    /**
     * 车辆导出模板
     */
    @GetMapping("export-template-car")
    @ApiOperation(value = "导出模板")
    public void exportSecurity(HttpServletResponse response) throws IOException {
        List<CarExcel> list = new ArrayList<>();
        CarExcel carExcel1 = new CarExcel();
        carExcel1.setDeptId("xxx保安公司");
        carExcel1.setBrand("****");
        carExcel1.setCarNumber("赣A415225");
        carExcel1.setMode("X54512545");
        carExcel1.setPersonInCharge("张三");
        carExcel1.setUmweltsatz("国IV");
        list.add(carExcel1);
        String fileName = null;
        try {
            response.setContentType("application/vnd.ms-excel");
            response.setCharacterEncoding(org.apache.commons.codec.Charsets.UTF_8.name());
            fileName = URLEncoder.encode("车辆导入数据模板" + DateUtil.time(), Charsets.UTF_8.name());
            response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
 
            //修改单元格格式为文本格式
            EasyExcel.write(response.getOutputStream(), CarExcel.class).sheet("车辆数据表").registerWriteHandler(new RowWriteHandler()).doWrite(list);
        } catch (Throwable var6) {
            throw var6;
        }
    }
 
}