|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.wms.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONArray; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.zy.asrs.common.utils.TreeUtils; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.entity.Mat; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.entity.OrderDetl; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.service.MatService; | 
|---|
|  |  |  | import com.zy.asrs.framework.annotations.ManagerAuth; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.Cools; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.zy.asrs.framework.domain.KeyValueVo; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.DateUtils; | 
|---|
|  |  |  | import com.zy.asrs.common.web.BaseController; | 
|---|
|  |  |  | import com.zy.asrs.framework.exception.CoolException; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MatService matService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TreeUtils treeUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/mat/{id}/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok(matService.getById(id)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/mat/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R find(@RequestParam("matnr") String matnr) { | 
|---|
|  |  |  | Mat one = matService.getOne(new LambdaQueryWrapper<Mat>() | 
|---|
|  |  |  | .eq(Mat::getMatnr, matnr) | 
|---|
|  |  |  | .eq(Mat::getHostId, getHostId())); | 
|---|
|  |  |  | if (Cools.isEmpty(one)){ | 
|---|
|  |  |  | return R.error("未查询到相关物料"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(one); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/mat/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(required = false) String timeRange, | 
|---|
|  |  |  | @RequestParam Map<String, Object> param) { | 
|---|
|  |  |  | LambdaQueryWrapper<Mat> wrapper = new LambdaQueryWrapper<>(); | 
|---|
|  |  |  | wrapper.eq(Mat::getHostId, getHostId()); | 
|---|
|  |  |  | if (!Cools.isEmpty(condition)) { | 
|---|
|  |  |  | wrapper.like(Mat::getId, condition); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | wrapper.ge(Mat::getCreateTime, DateUtils.convert(range[0])); | 
|---|
|  |  |  | wrapper.le(Mat::getCreateTime, DateUtils.convert(range[1])); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Object tagId = param.get("tag_id"); | 
|---|
|  |  |  | ArrayList<Long> nodes = new ArrayList<>(); | 
|---|
|  |  |  | if (Cools.isEmpty(tagId)) { | 
|---|
|  |  |  | tagId = getOriginTag().getId(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | treeUtils.getTagIdList(Long.parseLong(tagId.toString()), nodes); | 
|---|
|  |  |  | wrapper.in(Mat::getTagId, nodes); | 
|---|
|  |  |  | if (!Cools.isEmpty(param.get("matnr"))) { | 
|---|
|  |  |  | wrapper.eq(Mat::getMatnr, param.get("matnr")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(param.get("maktx"))) { | 
|---|
|  |  |  | wrapper.eq(Mat::getMaktx, param.get("maktx")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(matService.page(new Page<>(curr, limit), wrapper)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/mat/add/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R add(Mat mat) { | 
|---|
|  |  |  | mat.setHostId(getHostId()); | 
|---|
|  |  |  | matService.save(mat); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/mat/delete/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R delete(@RequestParam(value="ids[]") Long[] ids){ | 
|---|
|  |  |  | for (Long id : ids){ | 
|---|
|  |  |  | matService.removeById(id); | 
|---|
|  |  |  | public R delete(@RequestParam String param){ | 
|---|
|  |  |  | List<Mat> list = JSONArray.parseArray(param, Mat.class); | 
|---|
|  |  |  | if (Cools.isEmpty(list)){ | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (Mat entity : list){ | 
|---|
|  |  |  | if (!matService.remove(new LambdaQueryWrapper<>(entity))) { | 
|---|
|  |  |  | throw new CoolException("删除失败,请联系管理员"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | public R query(String condition) { | 
|---|
|  |  |  | LambdaQueryWrapper<Mat> wrapper = new LambdaQueryWrapper<>(); | 
|---|
|  |  |  | wrapper.like(Mat::getId, condition); | 
|---|
|  |  |  | wrapper.eq(Mat::getHostId, getHostId()); | 
|---|
|  |  |  | Page<Mat> page = matService.page(new Page<>(0, 10), wrapper); | 
|---|
|  |  |  | List<Map<String, Object>> result = new ArrayList<>(); | 
|---|
|  |  |  | for (Mat mat : page.getRecords()){ | 
|---|
|  |  |  | 
|---|
|  |  |  | public R getDataKV(@RequestParam(required = false) String condition) { | 
|---|
|  |  |  | List<KeyValueVo> vos = new ArrayList<>(); | 
|---|
|  |  |  | LambdaQueryWrapper<Mat> wrapper = new LambdaQueryWrapper<>(); | 
|---|
|  |  |  | wrapper.eq(Mat::getHostId, getHostId()); | 
|---|
|  |  |  | if (!Cools.isEmpty(condition)) { | 
|---|
|  |  |  | wrapper.like(Mat::getId, condition); | 
|---|
|  |  |  | wrapper.like(Mat::getMatnr, condition); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | matService.page(new Page<>(1, 30), wrapper).getRecords().forEach(item -> vos.add(new KeyValueVo(String.valueOf(item.getId()), item.getId()))); | 
|---|
|  |  |  | matService.page(new Page<>(1, 30), wrapper).getRecords().forEach(item -> vos.add(new KeyValueVo(item.getMatnr(), item.getId()))); | 
|---|
|  |  |  | return R.ok().add(vos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/mat/covert/{id}/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R covert(@PathVariable("id") String id) { | 
|---|
|  |  |  | Mat mat = matService.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getId, id).eq(Mat::getHostId, getHostId())); | 
|---|
|  |  |  | if (mat == null) { | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | OrderDetl orderDetl = new OrderDetl(); | 
|---|
|  |  |  | orderDetl.sync(mat); | 
|---|
|  |  |  | orderDetl.setAnfme(0.0D); | 
|---|
|  |  |  | return R.ok().add(orderDetl); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/mat/list/pda/page/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R pdaPageList(@RequestParam(required = true)Long tagId, | 
|---|
|  |  |  | @RequestParam(defaultValue = "1")Integer curr, | 
|---|
|  |  |  | @RequestParam(defaultValue = "10")Integer limit){ | 
|---|
|  |  |  | LambdaQueryWrapper<Mat> wrapper = new LambdaQueryWrapper<>(); | 
|---|
|  |  |  | wrapper.eq(Mat::getHostId, getHostId()); | 
|---|
|  |  |  | wrapper.orderBy(true, false,Mat::getCreateTime); | 
|---|
|  |  |  | return R.ok().add(matService.page(new Page<>(curr, limit), wrapper)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|