| | |
| | | import com.zy.asrs.entity.TaskLog; |
| | | import com.zy.asrs.service.TaskLogService; |
| | | import com.zy.common.web.BaseController; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Slf4j |
| | | @RestController |
| | | public class TaskLogController extends BaseController { |
| | | |
| | |
| | | @RequestParam(required = false) String orderByType, |
| | | @RequestParam(required = false) String condition, |
| | | @RequestParam Map<String, Object> param) { |
| | | EntityWrapper<TaskLog> wrapper = new EntityWrapper<>(); |
| | | excludeTrash(param); |
| | | convert(param, wrapper); |
| | | allLike(TaskLog.class, param.keySet(), wrapper, condition); |
| | | if (!Cools.isEmpty(orderByField)) { |
| | | wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType)); |
| | | try { |
| | | log.info("TaskLog查询请求,参数:curr={}, limit={}, param={}", curr, limit, param); |
| | | EntityWrapper<TaskLog> wrapper = new EntityWrapper<>(); |
| | | excludeTrash(param); |
| | | convert(param, wrapper); |
| | | allLike(TaskLog.class, param.keySet(), wrapper, condition); |
| | | if (!Cools.isEmpty(orderByField)) { |
| | | wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType)); |
| | | } |
| | | wrapper.orderBy("appe_time",false); |
| | | Page<TaskLog> page = taskLogService.selectPage(new Page<>(curr, limit), wrapper); |
| | | log.info("TaskLog查询成功,返回{}条记录", page.getRecords().size()); |
| | | return R.ok(page); |
| | | } catch (Exception e) { |
| | | log.error("TaskLog查询失败", e); |
| | | e.printStackTrace(); |
| | | return R.error("查询失败:" + e.getMessage()); |
| | | } |
| | | return R.ok(taskLogService.selectPage(new Page<>(curr, limit), wrapper)); |
| | | } |
| | | |
| | | private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper) { |
| | | for (Map.Entry<String, Object> entry : map.entrySet()) { |
| | | String val = String.valueOf(entry.getValue()); |
| | | if (Cools.isEmpty(val) || "null".equals(val)) { |
| | | continue; |
| | | } |
| | | 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])); |
| | | } else if (val.contains(",") && !val.equals("null")) { |
| | | // 多值查询:工作状态等多选用 IN(与 AGV 任务管理一致) |
| | | String[] values = val.split(","); |
| | | List<Object> valueList = new ArrayList<>(); |
| | | for (String v : values) { |
| | | v = v.trim(); |
| | | if (!Cools.isEmpty(v) && !v.equals("null")) { |
| | | try { |
| | | valueList.add(Long.parseLong(v)); |
| | | } catch (NumberFormatException e) { |
| | | valueList.add(v); |
| | | } |
| | | } |
| | | } |
| | | if (!valueList.isEmpty()) { |
| | | wrapper.in(entry.getKey(), valueList); |
| | | } |
| | | } else { |
| | | wrapper.like(entry.getKey(), val); |
| | | } |