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.LocRule; import com.zy.asrs.common.wms.service.LocRuleService; 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 LocRuleController extends BaseController { @Autowired private LocRuleService locRuleService; @RequestMapping(value = "/locRule/{id}/auth") @ManagerAuth public R get(@PathVariable("id") String id) { return R.ok(locRuleService.getById(String.valueOf(id))); } @RequestMapping(value = "/locRule/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(LocRule::getHostId, getHostId()); if (!Cools.isEmpty(condition)) { wrapper.like(LocRule::getId, condition); } if (!Cools.isEmpty(timeRange)) { String[] range = timeRange.split(RANGE_TIME_LINK); wrapper.ge(LocRule::getCreateTime, DateUtils.convert(range[0])); wrapper.le(LocRule::getCreateTime, DateUtils.convert(range[1])); } return R.ok(locRuleService.page(new Page<>(curr, limit), wrapper)); } @RequestMapping(value = "/locRule/add/auth") @ManagerAuth public R add(LocRule locRule) { locRule.setHostId(getHostId()); locRuleService.save(locRule); return R.ok(); } @RequestMapping(value = "/locRule/update/auth") @ManagerAuth public R update(LocRule locRule){ if (Cools.isEmpty(locRule) || null==locRule.getId()){ return R.error(); } locRuleService.updateById(locRule); return R.ok(); } @RequestMapping(value = "/locRule/delete/auth") @ManagerAuth public R delete(@RequestParam(value="ids[]") Long[] ids){ for (Long id : ids){ locRuleService.removeById(id); } return R.ok(); } @RequestMapping(value = "/locRuleQuery/auth") @ManagerAuth public R query(String condition) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(LocRule::getHostId, getHostId()); wrapper.like(LocRule::getId, condition); Page page = locRuleService.page(new Page<>(0, 10), wrapper); List> result = new ArrayList<>(); for (LocRule locRule : page.getRecords()){ Map map = new HashMap<>(); map.put("id", locRule.getId()); map.put("value", locRule.getId()); result.add(map); } return R.ok(result); } @RequestMapping("/locRule/all/get/kv") @ManagerAuth public R getDataKV(@RequestParam(required = false) String condition) { List vos = new ArrayList<>(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(LocRule::getHostId, getHostId()); if (!Cools.isEmpty(condition)) { wrapper.like(LocRule::getId, condition); } locRuleService.page(new Page<>(1, 30), wrapper).getRecords().forEach(item -> vos.add(new KeyValueVo(String.valueOf(item.getId()), item.getId()))); return R.ok().add(vos); } }