| 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.BasBarcode; | 
| import com.zy.asrs.common.wms.service.BasBarcodeService; | 
| 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 BasBarcodeController extends BaseController { | 
|   | 
|     @Autowired | 
|     private BasBarcodeService basBarcodeService; | 
|   | 
|     @RequestMapping(value = "/basBarcode/{id}/auth") | 
|     @ManagerAuth | 
|     public R get(@PathVariable("id") String id) { | 
|         return R.ok(basBarcodeService.getById(String.valueOf(id))); | 
|     } | 
|   | 
|     @RequestMapping(value = "/basBarcode/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<String, Object> param) { | 
|         LambdaQueryWrapper<BasBarcode> wrapper = new LambdaQueryWrapper<>(); | 
|         wrapper.eq(BasBarcode::getHostId, getHostId()); | 
|         if (!Cools.isEmpty(condition)) { | 
|             wrapper.like(BasBarcode::getId, condition); | 
|         } | 
|         if (!Cools.isEmpty(timeRange)) { | 
|             String[] range = timeRange.split(RANGE_TIME_LINK); | 
|             wrapper.ge(BasBarcode::getCreateTime, DateUtils.convert(range[0])); | 
|             wrapper.le(BasBarcode::getCreateTime, DateUtils.convert(range[1])); | 
|         } | 
|         return R.ok(basBarcodeService.page(new Page<>(curr, limit), wrapper)); | 
|     } | 
|   | 
|   | 
|     @RequestMapping(value = "/basBarcode/add/auth") | 
|     @ManagerAuth | 
|     public R add(BasBarcode basBarcode) { | 
|         basBarcode.setHostId(getHostId()); | 
|         basBarcode.setCreateTime(new Date()); | 
|         basBarcodeService.save(basBarcode); | 
|         return R.ok(); | 
|     } | 
|   | 
|     @RequestMapping(value = "/basBarcode/update/auth") | 
|     @ManagerAuth | 
|     public R update(BasBarcode basBarcode){ | 
|         if (Cools.isEmpty(basBarcode) || null==basBarcode.getId()){ | 
|             return R.error(); | 
|         } | 
|         basBarcodeService.updateById(basBarcode); | 
|         return R.ok(); | 
|     } | 
|   | 
|     @RequestMapping(value = "/basBarcode/delete/auth") | 
|     @ManagerAuth | 
|     public R delete(@RequestParam(value="ids[]") Long[] ids){ | 
|          for (Long id : ids){ | 
|             basBarcodeService.removeById(id); | 
|         } | 
|         return R.ok(); | 
|     } | 
|   | 
|     @RequestMapping(value = "/basBarcodeQuery/auth") | 
|     @ManagerAuth | 
|     public R query(String condition) { | 
|         LambdaQueryWrapper<BasBarcode> wrapper = new LambdaQueryWrapper<>(); | 
|         wrapper.eq(BasBarcode::getHostId, getHostId()); | 
|         wrapper.like(BasBarcode::getId, condition); | 
|         Page<BasBarcode> page = basBarcodeService.page(new Page<>(0, 10), wrapper); | 
|         List<Map<String, Object>> result = new ArrayList<>(); | 
|         for (BasBarcode basBarcode : page.getRecords()){ | 
|             Map<String, Object> map = new HashMap<>(); | 
|             map.put("id", basBarcode.getId()); | 
|             map.put("value", basBarcode.getId()); | 
|             result.add(map); | 
|         } | 
|         return R.ok(result); | 
|     } | 
|   | 
|     @RequestMapping("/basBarcode/all/get/kv") | 
|     @ManagerAuth | 
|     public R getDataKV(@RequestParam(required = false) String condition) { | 
|         List<KeyValueVo> vos = new ArrayList<>(); | 
|         LambdaQueryWrapper<BasBarcode> wrapper = new LambdaQueryWrapper<>(); | 
|         wrapper.eq(BasBarcode::getHostId, getHostId()); | 
|         if (!Cools.isEmpty(condition)) { | 
|             wrapper.like(BasBarcode::getId, condition); | 
|         } | 
|         basBarcodeService.page(new Page<>(1, 30), wrapper).getRecords().forEach(item -> vos.add(new KeyValueVo(String.valueOf(item.getId()), item.getId()))); | 
|         return R.ok().add(vos); | 
|     } | 
|   | 
|     @RequestMapping(value = "/basBarcode/generateBarcode/auth") | 
|     @ManagerAuth | 
|     public R generateBarcode(@RequestParam("barcode") String barcode, @RequestParam("num") Integer num) { | 
|         Long hostId = getHostId(); | 
|         Date now = new Date(); | 
|         BasBarcode one = basBarcodeService.getOne(new LambdaQueryWrapper<BasBarcode>().eq(BasBarcode::getBarcode, barcode).eq(BasBarcode::getHostId, hostId)); | 
|         if (one != null) { | 
|             return R.error("条码起始值已存在"); | 
|         } | 
|         int barcodeInt = Integer.parseInt(barcode); | 
|         for (int i = 0; i < num; i++) { | 
|             BasBarcode basBarcode = new BasBarcode(); | 
|             basBarcode.setBarcode(String.valueOf(barcodeInt)); | 
|             basBarcode.setHostId(hostId); | 
|             basBarcode.setCreateTime(now); | 
|             basBarcodeService.save(basBarcode); | 
|             barcodeInt += 1; | 
|         } | 
|         return R.ok(); | 
|     } | 
|   | 
| } |