package com.zy.asrs.wms.controller; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.zy.asrs.common.wms.entity.BasDevp; import com.zy.asrs.common.wms.service.BasDevpService; import com.zy.asrs.framework.annotations.ManagerAuth; import com.zy.asrs.framework.common.Cools; import com.zy.asrs.framework.common.R; import com.zy.asrs.framework.domain.KeyValueVo; import com.zy.asrs.framework.common.DateUtils; import com.zy.asrs.common.web.BaseController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.*; @RestController public class BasDevpController extends BaseController { @Autowired private BasDevpService basDevpService; @RequestMapping(value = "/basDevp/{id}/auth") @ManagerAuth public R get(@PathVariable("id") String id) { return R.ok(basDevpService.getById(String.valueOf(id))); } @RequestMapping(value = "/basDevp/page/auth") @ManagerAuth public R page(@RequestParam(defaultValue = "1") Integer curr, @RequestParam(defaultValue = "10") Integer limit, @RequestParam(required = false) String condition, @RequestParam(required = false) String timeRange, @RequestParam Map param) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(BasDevp::getHostId, getHostId()); if (!Cools.isEmpty(condition)) { wrapper.like(BasDevp::getDevNo, condition); } if (!Cools.isEmpty(timeRange)) { String[] range = timeRange.split(RANGE_TIME_LINK); wrapper.ge(BasDevp::getAppeTime, DateUtils.convert(range[0])); wrapper.le(BasDevp::getAppeTime, DateUtils.convert(range[1])); } return R.ok(basDevpService.page(new Page<>(curr, limit), wrapper)); } @RequestMapping(value = "/basDevp/add/auth") @ManagerAuth public R add(BasDevp basDevp) { basDevp.setHostId(getHostId()); basDevpService.save(basDevp); return R.ok(); } @RequestMapping(value = "/basDevp/update/auth") @ManagerAuth public R update(BasDevp basDevp){ if (Cools.isEmpty(basDevp) || null==basDevp.getDevNo()){ return R.error(); } basDevpService.updateById(basDevp); return R.ok(); } @RequestMapping(value = "/basDevp/delete/auth") @ManagerAuth public R delete(@RequestParam(value="ids[]") Long[] ids){ for (Long id : ids){ basDevpService.removeById(id); } return R.ok(); } @RequestMapping(value = "/basDevpQuery/auth") @ManagerAuth public R query(String condition) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(BasDevp::getHostId, getHostId()); wrapper.like(BasDevp::getDevNo, condition); Page page = basDevpService.page(new Page<>(0, 10), wrapper); List> result = new ArrayList<>(); for (BasDevp basDevp : page.getRecords()){ Map map = new HashMap<>(); map.put("id", basDevp.getDevNo()); map.put("value", basDevp.getDevNo()); result.add(map); } return R.ok(result); } @RequestMapping("/basDevp/all/get/kv") @ManagerAuth public R getDataKV(@RequestParam(required = false) String condition) { List vos = new ArrayList<>(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(BasDevp::getHostId, getHostId()); if (!Cools.isEmpty(condition)) { wrapper.like(BasDevp::getDevNo, condition); } basDevpService.page(new Page<>(1, 30), wrapper).getRecords().forEach(item -> vos.add(new KeyValueVo(String.valueOf(item.getDevNo()), item.getDevNo().longValue()))); return R.ok().add(vos); } }