package com.zy.asrs.controller;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.core.common.DateUtils;
|
import com.zy.asrs.domain.BasMapEditorDoc;
|
import com.zy.asrs.entity.BasMap;
|
import com.zy.asrs.service.BasMapEditorService;
|
import com.zy.asrs.service.BasMapService;
|
import com.core.annotations.ManagerAuth;
|
import com.core.common.BaseRes;
|
import com.core.common.Cools;
|
import com.core.common.R;
|
import com.zy.common.web.BaseController;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import java.io.File;
|
import java.io.IOException;
|
import java.util.*;
|
|
@RestController
|
public class BasMapController extends BaseController {
|
|
@Autowired
|
private BasMapService basMapService;
|
@Autowired
|
private BasMapEditorService basMapEditorService;
|
|
@RequestMapping(value = "/basMap/{id}/auth")
|
@ManagerAuth
|
public R get(@PathVariable("id") String id) {
|
return R.ok(basMapService.getById(String.valueOf(id)));
|
}
|
|
@RequestMapping(value = "/basMap/list/auth")
|
@ManagerAuth
|
public R list(@RequestParam(defaultValue = "1")Integer curr,
|
@RequestParam(defaultValue = "10")Integer limit,
|
@RequestParam(required = false)String orderByField,
|
@RequestParam(required = false)String orderByType,
|
@RequestParam(required = false)String condition,
|
@RequestParam Map<String, Object> param){
|
QueryWrapper<BasMap> wrapper = new QueryWrapper<>();
|
excludeTrash(param);
|
convert(param, wrapper);
|
allLike(BasMap.class, param.keySet(), wrapper, condition);
|
if (!Cools.isEmpty(orderByField)){wrapper.orderBy(true, "asc".equals(orderByType), humpToLine(orderByField));}
|
wrapper.orderBy(true, true, "lev");
|
return R.ok(basMapService.page(new Page<>(curr, limit), wrapper));
|
}
|
|
private <T> void convert(Map<String, Object> map, QueryWrapper<T> wrapper){
|
for (Map.Entry<String, Object> entry : map.entrySet()){
|
String val = String.valueOf(entry.getValue());
|
String column = humpToLine(entry.getKey());
|
if (val.contains(RANGE_TIME_LINK)){
|
String[] dates = val.split(RANGE_TIME_LINK);
|
wrapper.ge(column, DateUtils.convert(dates[0]));
|
wrapper.le(column, DateUtils.convert(dates[1]));
|
} else {
|
wrapper.like(column, val);
|
}
|
}
|
}
|
|
@RequestMapping(value = "/basMap/add/auth")
|
@ManagerAuth
|
public R add(BasMap basMap) {
|
basMapService.save(basMap);
|
return R.ok();
|
}
|
|
@RequestMapping(value = "/basMap/update/auth")
|
@ManagerAuth
|
public R update(BasMap basMap){
|
if (Cools.isEmpty(basMap) || null==basMap.getId()){
|
return R.error();
|
}
|
basMapService.updateById(basMap);
|
return R.ok();
|
}
|
|
@RequestMapping(value = "/basMap/delete/auth")
|
@ManagerAuth
|
public R delete(@RequestParam(value="ids[]") Integer[] ids){
|
for (Integer id : ids){
|
basMapService.removeById(id);
|
}
|
return R.ok();
|
}
|
|
@RequestMapping(value = "/basMap/export/auth")
|
@ManagerAuth
|
public R export(@RequestBody JSONObject param){
|
QueryWrapper<BasMap> wrapper = new QueryWrapper<>();
|
List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class);
|
Map<String, Object> map = excludeTrash(param.getJSONObject("basMap"));
|
convert(map, wrapper);
|
List<BasMap> list = basMapService.list(wrapper);
|
return R.ok(exportSupport(list, fields));
|
}
|
|
@RequestMapping(value = "/basMapQuery/auth")
|
@ManagerAuth
|
public R query(String condition) {
|
QueryWrapper<BasMap> wrapper = new QueryWrapper<>();
|
wrapper.like("id", condition);
|
Page<BasMap> page = basMapService.page(new Page<>(0, 10), wrapper);
|
List<Map<String, Object>> result = new ArrayList<>();
|
for (BasMap basMap : page.getRecords()){
|
Map<String, Object> map = new HashMap<>();
|
map.put("id", basMap.getId());
|
map.put("value", basMap.getId());
|
result.add(map);
|
}
|
return R.ok(result);
|
}
|
|
@RequestMapping(value = "/basMap/check/column/auth")
|
@ManagerAuth
|
public R query(@RequestBody JSONObject param) {
|
QueryWrapper<BasMap> wrapper = new QueryWrapper<BasMap>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val"));
|
if (null != basMapService.getOne(wrapper)){
|
return R.parse(BaseRes.REPEAT).add(getComment(BasMap.class, String.valueOf(param.get("key"))));
|
}
|
return R.ok();
|
}
|
|
@GetMapping("/basMap/lev/{lev}/auth")
|
@ManagerAuth
|
public R getByLev(@PathVariable("lev") Integer lev) {
|
BasMap basMap = basMapService.getOne(new QueryWrapper<BasMap>().eq("lev", lev));
|
if (basMap == null){
|
return R.error("地图不存在");
|
}
|
return R.ok().add(basMap.getData());
|
}
|
|
@GetMapping("/basMap/getLevList")
|
@ManagerAuth
|
public R getLevList() {
|
List<Integer> levList = basMapService.getLevList();
|
return R.ok().add(levList);
|
}
|
|
@PostMapping("/basMap/crn/upload")
|
public R uploadExcel(@RequestParam("file") MultipartFile file) {
|
File tempFile = null;
|
try {
|
tempFile = createTempUploadFile(file);
|
basMapEditorService.importExcelAndPersist(tempFile.getAbsolutePath());
|
} catch (Exception e) {
|
e.printStackTrace();
|
return R.error(e.getMessage());
|
} finally {
|
deleteQuietly(tempFile);
|
}
|
return R.ok();
|
}
|
|
@GetMapping("/basMap/editor/{lev}/auth")
|
@ManagerAuth
|
public R getEditorDoc(@PathVariable("lev") Integer lev) {
|
BasMapEditorDoc doc = basMapEditorService.getEditorDoc(lev);
|
if (doc == null) {
|
return R.error("地图不存在");
|
}
|
return R.ok().add(doc);
|
}
|
|
@PostMapping("/basMap/editor/save/auth")
|
@ManagerAuth
|
public R saveEditorDoc(@RequestBody BasMapEditorDoc doc) {
|
basMapEditorService.saveEditorDoc(doc);
|
return R.ok();
|
}
|
|
@PostMapping("/basMap/editor/importExcel/auth")
|
@ManagerAuth
|
public R importExcelToEditor(@RequestParam("file") MultipartFile file) {
|
File tempFile = null;
|
try {
|
tempFile = createTempUploadFile(file);
|
return R.ok().add(basMapEditorService.importExcelToEditorDocs(tempFile.getAbsolutePath()));
|
} catch (Exception e) {
|
e.printStackTrace();
|
return R.error(e.getMessage());
|
} finally {
|
deleteQuietly(tempFile);
|
}
|
}
|
|
private File createTempUploadFile(MultipartFile file) throws IOException {
|
String originalName = file == null ? null : file.getOriginalFilename();
|
String suffix = ".xlsx";
|
if (!Cools.isEmpty(originalName) && originalName.contains(".")) {
|
suffix = originalName.substring(originalName.lastIndexOf('.'));
|
}
|
File tempFile = File.createTempFile("bas_map_", suffix);
|
file.transferTo(tempFile);
|
return tempFile;
|
}
|
|
private void deleteQuietly(File file) {
|
if (file != null && file.exists()) {
|
file.delete();
|
}
|
}
|
|
}
|