package com.zy.asrs.controller; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.core.annotations.ManagerAuth; import com.core.common.BaseRes; import com.core.common.Cools; import com.core.common.DateUtils; import com.core.common.R; import com.zy.asrs.entity.BasStationErrLog; import com.zy.asrs.service.BasStationErrLogService; import com.zy.common.web.BaseController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @RestController public class BasStationErrLogController extends BaseController { @Autowired private BasStationErrLogService basStationErrLogService; @RequestMapping(value = "/basStationErrLog/{id}/auth") @ManagerAuth public R get(@PathVariable("id") String id) { return R.ok(basStationErrLogService.getById(String.valueOf(id))); } @RequestMapping(value = "/basStationErrLog/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 param) { QueryWrapper wrapper = new QueryWrapper<>(); excludeTrash(param); convert(param, wrapper); allLike(BasStationErrLog.class, param.keySet(), wrapper, condition); if (!Cools.isEmpty(orderByField)) { wrapper.orderBy(true, "asc".equals(orderByType), humpToLine(orderByField)); } return R.ok(basStationErrLogService.page(new Page<>(curr, limit), wrapper)); } private void convert(Map map, QueryWrapper wrapper) { for (Map.Entry 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 = "/basStationErrLog/add/auth") @ManagerAuth public R add(BasStationErrLog basStationErrLog) { basStationErrLogService.save(basStationErrLog); return R.ok(); } @RequestMapping(value = "/basStationErrLog/update/auth") @ManagerAuth public R update(BasStationErrLog basStationErrLog) { if (Cools.isEmpty(basStationErrLog) || basStationErrLog.getId() == null) { return R.error(); } basStationErrLogService.updateById(basStationErrLog); return R.ok(); } @RequestMapping(value = "/basStationErrLog/delete/auth") @ManagerAuth public R delete(@RequestParam(value = "ids[]") Integer[] ids) { for (Integer id : ids) { basStationErrLogService.removeById(id); } return R.ok(); } @RequestMapping(value = "/basStationErrLog/export/auth") @ManagerAuth public R export(@RequestBody JSONObject param) { QueryWrapper wrapper = new QueryWrapper<>(); List fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); Map map = excludeTrash(param.getJSONObject("basStationErrLog")); convert(map, wrapper); List list = basStationErrLogService.list(wrapper); return R.ok(exportSupport(list, fields)); } @RequestMapping(value = "/basStationErrLogQuery/auth") @ManagerAuth public R query(String condition) { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.like("id", condition); Page page = basStationErrLogService.page(new Page<>(0, 10), wrapper); List> result = new ArrayList<>(); for (BasStationErrLog basStationErrLog : page.getRecords()) { Map map = new HashMap<>(); map.put("id", basStationErrLog.getId()); map.put("value", basStationErrLog.getId()); result.add(map); } return R.ok(result); } @RequestMapping(value = "/basStationErrLog/check/column/auth") @ManagerAuth public R query(@RequestBody JSONObject param) { QueryWrapper wrapper = new QueryWrapper() .eq(humpToLine(String.valueOf(param.get("key"))), param.get("val")); if (null != basStationErrLogService.getOne(wrapper)) { return R.parse(BaseRes.REPEAT).add(getComment(BasStationErrLog.class, String.valueOf(param.get("key")))); } return R.ok(); } }