| package com.zy.asrs.controller; | 
|   | 
| import com.alibaba.fastjson.JSON; | 
| import com.alibaba.fastjson.JSONArray; | 
| import com.alibaba.fastjson.JSONObject; | 
| import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
| import com.baomidou.mybatisplus.mapper.Wrapper; | 
| import com.baomidou.mybatisplus.plugins.Page; | 
| import com.core.annotations.ManagerAuth; | 
| import com.core.common.BaseRes; | 
| import com.core.common.Cools; | 
| import com.core.common.DateUtils; | 
| import com.core.common.R; | 
| import com.core.exception.CoolException; | 
| import com.zy.asrs.entity.AgvBasDevp; | 
| import com.zy.asrs.entity.AgvWaitPakin; | 
| import com.zy.asrs.entity.OrderDetl; | 
| import com.zy.asrs.entity.WaitPakin; | 
| import com.zy.asrs.service.AgvBasDevpService; | 
| import com.zy.asrs.service.AgvWaitPakinService; | 
| import com.zy.asrs.service.OrderDetlService; | 
| import com.zy.common.web.BaseController; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.transaction.annotation.Transactional; | 
| import org.springframework.web.bind.annotation.*; | 
|   | 
| import java.util.ArrayList; | 
| import java.util.HashMap; | 
| import java.util.List; | 
| import java.util.Map; | 
|   | 
| @RestController | 
| @RequestMapping("/agv") | 
| public class AgvWaitPakinController extends BaseController { | 
|   | 
|     @Autowired | 
|     private AgvWaitPakinService agvWaitPakinService; | 
|     @Autowired | 
|     private AgvBasDevpService agvBasDevpService; | 
|     @Autowired | 
|     private OrderDetlService orderDetlService; | 
|   | 
|     @RequestMapping(value = "/waitPakin/{id}/auth") | 
|     @ManagerAuth | 
|     public R get(@PathVariable("id") String id) { | 
|         return R.ok(agvWaitPakinService.selectById(String.valueOf(id))); | 
|     } | 
|   | 
|     @RequestMapping(value = "/waitPakin/list/auth") | 
|     @ManagerAuth | 
|     public R list(@RequestParam(defaultValue = "1")Integer curr, | 
|                   @RequestParam(defaultValue = "10")Integer limit, | 
|                   @RequestParam(required = false)String orderByField, | 
|                   @RequestParam(required = false)String orderByType, | 
|                   @RequestParam Map<String, Object> param){ | 
|         excludeTrash(param); | 
|         EntityWrapper<AgvWaitPakin> wrapper = new EntityWrapper<>(); | 
|         convert(param, wrapper); | 
|         if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} | 
|         else { | 
|             wrapper.orderBy("modi_time", false); | 
|         } | 
|         return R.ok(agvWaitPakinService.selectPage(new Page<>(curr, limit), wrapper)); | 
|     } | 
|   | 
|     private void convert(Map<String, Object> map, EntityWrapper wrapper){ | 
|         for (Map.Entry<String, Object> entry : map.entrySet()){ | 
|             String val = String.valueOf(entry.getValue()); | 
|             if (val.contains(RANGE_TIME_LINK)){ | 
|                 String[] dates = val.split(RANGE_TIME_LINK); | 
|                 wrapper.ge(entry.getKey(), DateUtils.convert(dates[0])); | 
|                 wrapper.le(entry.getKey(), DateUtils.convert(dates[1])); | 
|             } else { | 
|                 wrapper.like(entry.getKey(), val); | 
|             } | 
|         } | 
|     } | 
|   | 
|     @RequestMapping(value = "/waitPakin/add/auth") | 
|     @ManagerAuth | 
|     public R add(AgvWaitPakin waitPakin) { | 
|         agvWaitPakinService.insert(waitPakin); | 
|         return R.ok(); | 
|     } | 
|   | 
|     @RequestMapping(value = "/waitPakin/update/auth") | 
|     @ManagerAuth | 
|     public R update(AgvWaitPakin waitPakin){ | 
|         if (Cools.isEmpty(waitPakin)){ | 
|             return R.error(); | 
|         } | 
|         agvWaitPakinService.updateById(waitPakin); | 
|         return R.ok(); | 
|     } | 
|   | 
|     @RequestMapping(value = "/waitPakin/delete/auth") | 
|     @ManagerAuth | 
|     @Transactional | 
|     public R delete(@RequestParam String param){ | 
|         List<AgvWaitPakin> list = JSONArray.parseArray(param, AgvWaitPakin.class); | 
|         if (Cools.isEmpty(list)){ | 
|             return R.error(); | 
|         } | 
|         for (AgvWaitPakin entity : list){ | 
|             AgvBasDevp agvBasDevp = agvBasDevpService.selectOne(new EntityWrapper<AgvBasDevp>().eq("barcode", entity.getSuppCode())); | 
|   | 
|             if(!Cools.isEmpty(agvBasDevp)){ | 
|                 if(!Cools.eq("F",agvBasDevp.getLocSts())){ | 
|                     throw new CoolException("该入库通知档已经在作业中,无法删除"); | 
|                 } | 
|                 //解绑站点 | 
|                 agvBasDevp.setLocSts("O"); | 
|                 agvBasDevp.setBarcode(""); | 
|                 agvBasDevp.setLocType2(null); | 
|                 agvBasDevpService.update(agvBasDevp,new EntityWrapper<AgvBasDevp>().eq("dev_no",agvBasDevp.getDevNo())); | 
|             } | 
|             agvWaitPakinService.delete(new EntityWrapper<>(entity)); | 
|   | 
|             //订单回滚 | 
|             if(!Cools.isEmpty(entity.getOrderNo())){ | 
|                 String orderNo = entity.getOrderNo(); | 
|                 if(orderNo.contains("{")){ | 
|                     JSONArray orderArray = JSON.parseArray(orderNo); | 
|                     for (Object o : orderArray){ | 
|                         JSONObject jsonobject = (JSONObject) o; | 
|                         OrderDetl orderDetl = orderDetlService.selectByOrderNoAndMatnr(jsonobject.get("orderNo").toString(),entity.getMatnr(),entity.getThreeCode(),entity.getDeadTime()); | 
|                         orderDetl.setQty(orderDetl.getQty() - entity.getAnfme()); | 
|                         orderDetlService.updateById(orderDetl); | 
|                     } | 
|   | 
|                 }else { | 
|                     OrderDetl orderDetl = orderDetlService.selectByOrderNoAndMatnr(entity.getOrderNo(),entity.getMatnr(),entity.getThreeCode(),entity.getDeadTime()); | 
|                     orderDetl.setQty(orderDetl.getQty() - entity.getAnfme()); | 
|                     orderDetlService.updateById(orderDetl); | 
|                 } | 
|             } | 
|   | 
|         } | 
|         return R.ok(); | 
|     } | 
|   | 
|     @RequestMapping(value = "/waitPakin/export/auth") | 
|     @ManagerAuth | 
|     public R export(@RequestBody JSONObject param){ | 
|         List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); | 
|         EntityWrapper<AgvWaitPakin> wrapper = new EntityWrapper<>(); | 
|         Map<String, Object> map = excludeTrash(param.getJSONObject("waitPakin")); | 
|         convert(map, wrapper); | 
|         List<AgvWaitPakin> list = agvWaitPakinService.selectList(wrapper); | 
|         return R.ok(exportSupport(list, fields)); | 
|     } | 
|   | 
|     @RequestMapping(value = "/waitPakinQuery/auth") | 
|     @ManagerAuth | 
|     public R query(String condition) { | 
|         EntityWrapper<AgvWaitPakin> wrapper = new EntityWrapper<>(); | 
|         wrapper.like("id", condition); | 
|         Page<AgvWaitPakin> page = agvWaitPakinService.selectPage(new Page<>(0, 10), wrapper); | 
|         List<Map<String, Object>> result = new ArrayList<>(); | 
|         for (AgvWaitPakin waitPakin : page.getRecords()){ | 
|             Map<String, Object> map = new HashMap<>(); | 
|             map.put("id", waitPakin.getZpallet()); | 
|             map.put("value", waitPakin.getZpallet()); | 
|             result.add(map); | 
|         } | 
|         return R.ok(result); | 
|     } | 
|   | 
|     @RequestMapping(value = "/waitPakin/check/column/auth") | 
|     @ManagerAuth | 
|     public R query(@RequestBody JSONObject param) { | 
|         Wrapper<AgvWaitPakin> wrapper = new EntityWrapper<AgvWaitPakin>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val")); | 
|         if (null != agvWaitPakinService.selectOne(wrapper)){ | 
|             return R.parse(BaseRes.REPEAT).add(getComment(WaitPakin.class, String.valueOf(param.get("key")))); | 
|         } | 
|         return R.ok(); | 
|     } | 
|   | 
| } |