package com.zy.asrs.wms.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.zy.asrs.common.domain.entity.StaDesc; import com.zy.asrs.common.sys.service.StaDescService; 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 StaDescController extends BaseController { @Autowired private StaDescService staDescService; @RequestMapping(value = "/staDesc/{id}/auth") @ManagerAuth public R get(@PathVariable("id") String id) { return R.ok(staDescService.getById(String.valueOf(id))); } @RequestMapping(value = "/staDesc/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(StaDesc::getHostId, getHostId()); if (!Cools.isEmpty(condition)) { wrapper.like(StaDesc::getTypeId, condition); } if (!Cools.isEmpty(timeRange)) { String[] range = timeRange.split(RANGE_TIME_LINK); wrapper.ge(StaDesc::getAppeTime, DateUtils.convert(range[0])); wrapper.le(StaDesc::getAppeTime, DateUtils.convert(range[1])); } if (!Cools.isEmpty(param.get("device_no"))) { wrapper.eq(StaDesc::getDeviceNo, param.get("device_no")); } if (!Cools.isEmpty(param.get("device_stn"))) { wrapper.eq(StaDesc::getDeviceStn, param.get("device_stn")); } return R.ok(staDescService.page(new Page<>(curr, limit), wrapper)); } @RequestMapping(value = "/staDesc/add/auth") @ManagerAuth public R add(StaDesc staDesc) { staDesc.setHostId(getHostId()); staDescService.save(staDesc); return R.ok(); } @RequestMapping(value = "/staDesc/update/auth") @ManagerAuth public R update(StaDesc staDesc){ if (Cools.isEmpty(staDesc) || null==staDesc.getTypeId()){ return R.error(); } staDescService.updateById(staDesc); return R.ok(); } @RequestMapping(value = "/staDesc/delete/auth") @ManagerAuth public R delete(@RequestParam(value="ids[]") Long[] ids){ for (Long id : ids){ staDescService.removeById(id); } return R.ok(); } @RequestMapping(value = "/staDescQuery/auth") @ManagerAuth public R query(String condition) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(StaDesc::getHostId, getHostId()); wrapper.like(StaDesc::getTypeId, condition); Page page = staDescService.page(new Page<>(0, 10), wrapper); List> result = new ArrayList<>(); for (StaDesc staDesc : page.getRecords()){ Map map = new HashMap<>(); map.put("id", staDesc.getTypeId()); map.put("value", staDesc.getTypeId()); result.add(map); } return R.ok(result); } @RequestMapping("/staDesc/all/get/kv") @ManagerAuth public R getDataKV(@RequestParam(required = false) String condition) { List vos = new ArrayList<>(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(StaDesc::getHostId, getHostId()); if (!Cools.isEmpty(condition)) { wrapper.like(StaDesc::getTypeId, condition); } staDescService.page(new Page<>(1, 30), wrapper).getRecords().forEach(item -> vos.add(new KeyValueVo(String.valueOf(item.getTypeId()), item.getTypeId()))); return R.ok().add(vos); } }