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.BaseRes; 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(memo = "站点删除") public R delete(@RequestParam String param){ List list = JSONArray.parseArray(param, BasDevp.class); if (Cools.isEmpty(list)){ return R.error(); } for (BasDevp entity : list){ basDevpService.remove(new LambdaQueryWrapper<>(entity).eq(BasDevp::getHostId, getHostId())); } 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); } @RequestMapping(value = "/basDevp/check/column/auth") @ManagerAuth public R query(@RequestBody JSONObject param) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper().eq(BasDevp::getDevNo, param.get("val")); if (null != basDevpService.getOne(wrapper)){ return R.parse(BaseRes.REPEAT).add(getComment(BasDevp.class, String.valueOf(param.get("key")))); } return R.ok(); } }