| | |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | 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.entity.BasCrnpErr; |
| | | import com.zy.asrs.entity.BasCrnpErrLog; |
| | | import com.zy.asrs.service.BasCrnpErrService; |
| | | import com.zy.asrs.service.BasCrnpErrLogService; |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.BaseRes; |
| | |
| | | |
| | | @Autowired |
| | | private BasCrnpErrLogService basCrnpErrLogService; |
| | | @Autowired |
| | | private BasCrnpErrService basCrnpErrService; |
| | | |
| | | @RequestMapping(value = "/basCrnpErrLog/{id}/auth") |
| | | @ManagerAuth |
| | | public R get(@PathVariable("id") String id) { |
| | | return R.ok(basCrnpErrLogService.selectById(String.valueOf(id))); |
| | | BasCrnpErrLog basCrnpErrLog = basCrnpErrLogService.getById(String.valueOf(id)); |
| | | fillErrorName(Collections.singletonList(basCrnpErrLog)); |
| | | return R.ok(basCrnpErrLog); |
| | | } |
| | | |
| | | @RequestMapping(value = "/basCrnpErrLog/list/auth") |
| | |
| | | @RequestParam(required = false)String orderByType, |
| | | @RequestParam(required = false)String condition, |
| | | @RequestParam Map<String, Object> param){ |
| | | EntityWrapper<BasCrnpErrLog> wrapper = new EntityWrapper<>(); |
| | | QueryWrapper<BasCrnpErrLog> wrapper = new QueryWrapper<>(); |
| | | excludeTrash(param); |
| | | convert(param, wrapper); |
| | | allLike(BasCrnpErrLog.class, param.keySet(), wrapper, condition); |
| | | if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} |
| | | return R.ok(basCrnpErrLogService.selectPage(new Page<>(curr, limit), wrapper)); |
| | | if (!Cools.isEmpty(orderByField)){wrapper.orderBy(true, "asc".equals(orderByType), humpToLine(orderByField));} |
| | | Page<BasCrnpErrLog> page = basCrnpErrLogService.page(new Page<>(curr, limit), wrapper); |
| | | fillErrorName(page.getRecords()); |
| | | return R.ok(page); |
| | | } |
| | | |
| | | private <T> void convert(Map<String, Object> map, EntityWrapper<T> 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(entry.getKey(), DateUtils.convert(dates[0])); |
| | | wrapper.le(entry.getKey(), DateUtils.convert(dates[1])); |
| | | wrapper.ge(column, DateUtils.convert(dates[0])); |
| | | wrapper.le(column, DateUtils.convert(dates[1])); |
| | | } else { |
| | | wrapper.like(entry.getKey(), val); |
| | | wrapper.like(column, val); |
| | | } |
| | | } |
| | | } |
| | |
| | | @RequestMapping(value = "/basCrnpErrLog/add/auth") |
| | | @ManagerAuth |
| | | public R add(BasCrnpErrLog basCrnpErrLog) { |
| | | basCrnpErrLogService.insert(basCrnpErrLog); |
| | | basCrnpErrLogService.save(basCrnpErrLog); |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | @ManagerAuth |
| | | public R delete(@RequestParam(value="ids[]") Integer[] ids){ |
| | | for (Integer id : ids){ |
| | | basCrnpErrLogService.deleteById(id); |
| | | basCrnpErrLogService.removeById(id); |
| | | } |
| | | return R.ok(); |
| | | } |
| | |
| | | @RequestMapping(value = "/basCrnpErrLog/export/auth") |
| | | @ManagerAuth |
| | | public R export(@RequestBody JSONObject param){ |
| | | EntityWrapper<BasCrnpErrLog> wrapper = new EntityWrapper<>(); |
| | | QueryWrapper<BasCrnpErrLog> wrapper = new QueryWrapper<>(); |
| | | List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); |
| | | Map<String, Object> map = excludeTrash(param.getJSONObject("basCrnpErrLog")); |
| | | convert(map, wrapper); |
| | | List<BasCrnpErrLog> list = basCrnpErrLogService.selectList(wrapper); |
| | | List<BasCrnpErrLog> list = basCrnpErrLogService.list(wrapper); |
| | | fillErrorName(list); |
| | | return R.ok(exportSupport(list, fields)); |
| | | } |
| | | |
| | | private void fillErrorName(List<BasCrnpErrLog> list){ |
| | | if (list == null || list.isEmpty()){ |
| | | return; |
| | | } |
| | | Set<Integer> errCodes = new HashSet<>(); |
| | | for (BasCrnpErrLog basCrnpErrLog : list){ |
| | | if (basCrnpErrLog != null && basCrnpErrLog.getErrCode() != null){ |
| | | errCodes.add(basCrnpErrLog.getErrCode()); |
| | | } |
| | | } |
| | | if (errCodes.isEmpty()){ |
| | | return; |
| | | } |
| | | Map<Integer, String> errNameMap = new HashMap<>(); |
| | | List<BasCrnpErr> errList = basCrnpErrService.list(new QueryWrapper<BasCrnpErr>().in("error_code", errCodes)); |
| | | for (BasCrnpErr basCrnpErr : errList){ |
| | | if (basCrnpErr.getErrorCode() != null && !Cools.isEmpty(basCrnpErr.getErrName())){ |
| | | errNameMap.put(basCrnpErr.getErrorCode().intValue(), basCrnpErr.getErrName()); |
| | | } |
| | | } |
| | | for (BasCrnpErrLog basCrnpErrLog : list){ |
| | | if (basCrnpErrLog == null || basCrnpErrLog.getErrCode() == null){ |
| | | continue; |
| | | } |
| | | String errName = errNameMap.get(basCrnpErrLog.getErrCode()); |
| | | if (!Cools.isEmpty(errName)){ |
| | | basCrnpErrLog.setError(errName); |
| | | } else if (Cools.isEmpty(basCrnpErrLog.getError())){ |
| | | basCrnpErrLog.setError("未知异常"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @RequestMapping(value = "/basCrnpErrLogQuery/auth") |
| | | @ManagerAuth |
| | | public R query(String condition) { |
| | | EntityWrapper<BasCrnpErrLog> wrapper = new EntityWrapper<>(); |
| | | QueryWrapper<BasCrnpErrLog> wrapper = new QueryWrapper<>(); |
| | | wrapper.like("id", condition); |
| | | Page<BasCrnpErrLog> page = basCrnpErrLogService.selectPage(new Page<>(0, 10), wrapper); |
| | | Page<BasCrnpErrLog> page = basCrnpErrLogService.page(new Page<>(0, 10), wrapper); |
| | | List<Map<String, Object>> result = new ArrayList<>(); |
| | | for (BasCrnpErrLog basCrnpErrLog : page.getRecords()){ |
| | | Map<String, Object> map = new HashMap<>(); |
| | |
| | | @RequestMapping(value = "/basCrnpErrLog/check/column/auth") |
| | | @ManagerAuth |
| | | public R query(@RequestBody JSONObject param) { |
| | | Wrapper<BasCrnpErrLog> wrapper = new EntityWrapper<BasCrnpErrLog>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val")); |
| | | if (null != basCrnpErrLogService.selectOne(wrapper)){ |
| | | QueryWrapper<BasCrnpErrLog> wrapper = new QueryWrapper<BasCrnpErrLog>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val")); |
| | | if (null != basCrnpErrLogService.getOne(wrapper)){ |
| | | return R.parse(BaseRes.REPEAT).add(getComment(BasCrnpErrLog.class, String.valueOf(param.get("key")))); |
| | | } |
| | | return R.ok(); |