| package com.zy.asrs.controller; | 
|   | 
| 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.zy.asrs.entity.WaitPakin; | 
| import com.zy.asrs.entity.WrkDetl; | 
| import com.zy.asrs.entity.WrkMast; | 
| import com.zy.asrs.service.OrderDetlService; | 
| import com.zy.asrs.service.WaitPakinService; | 
| import com.zy.asrs.service.WrkMastService; | 
| 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 | 
| public class WaitPakinController extends BaseController { | 
|   | 
|     @Autowired | 
|     private WaitPakinService waitPakinService; | 
|     @Autowired | 
|     private OrderDetlService orderDetlService; | 
|     @Autowired | 
|     private WrkMastService wrkMastService; | 
|   | 
|     @RequestMapping(value = "/waitPakin/{id}/auth") | 
|     @ManagerAuth | 
|     public R get(@PathVariable("id") String id) { | 
|         return R.ok(waitPakinService.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<WaitPakin> 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(waitPakinService.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(WaitPakin waitPakin) { | 
|         waitPakinService.insert(waitPakin); | 
|         return R.ok(); | 
|     } | 
|   | 
|     @RequestMapping(value = "/waitPakin/update/auth") | 
|     @ManagerAuth | 
|     public R update(WaitPakin waitPakin){ | 
|         if (Cools.isEmpty(waitPakin)){ | 
|             return R.error(); | 
|         } | 
|         waitPakinService.updateById(waitPakin); | 
|         return R.ok(); | 
|     } | 
|   | 
|     @RequestMapping(value = "/waitPakin/delete/auth") | 
|     @ManagerAuth | 
|     @Transactional | 
|     public R delete(@RequestParam String param){ | 
|         List<WaitPakin> list = JSONArray.parseArray(param, WaitPakin.class); | 
|         if (Cools.isEmpty(list)){ | 
|             return R.error("数据为空"); | 
|         } | 
|         for (WaitPakin entity : list){ | 
|             List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("barcode", entity.getZpallet())); | 
|             if(!Cools.isEmpty(wrkMasts) || wrkMasts.size() > 0){ | 
|                 return R.error("条码已生成入库工作档,禁止删除"); | 
|             } | 
|             waitPakinService.delete(new EntityWrapper<>(entity)); | 
|             //订单关联,修改订单作业数量 | 
|             if (!Cools.isEmpty(entity.getOrderNo())) { | 
|                 if (!orderDetlService.decrease(entity.getOrderNo(), entity.getMatnr(), entity.getBatch(), entity.getAnfme())) { | 
|                     return R.error("订单数据回滚失败"); | 
|                 } | 
|             } | 
|         } | 
|         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<WaitPakin> wrapper = new EntityWrapper<>(); | 
|         Map<String, Object> map = excludeTrash(param.getJSONObject("waitPakin")); | 
|         convert(map, wrapper); | 
|         List<WaitPakin> list = waitPakinService.selectList(wrapper); | 
|         return R.ok(exportSupport(list, fields)); | 
|     } | 
|   | 
|     @RequestMapping(value = "/waitPakinQuery/auth") | 
|     @ManagerAuth | 
|     public R query(String condition) { | 
|         EntityWrapper<WaitPakin> wrapper = new EntityWrapper<>(); | 
|         wrapper.like("id", condition); | 
|         Page<WaitPakin> page = waitPakinService.selectPage(new Page<>(0, 10), wrapper); | 
|         List<Map<String, Object>> result = new ArrayList<>(); | 
|         for (WaitPakin 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<WaitPakin> wrapper = new EntityWrapper<WaitPakin>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val")); | 
|         if (null != waitPakinService.selectOne(wrapper)){ | 
|             return R.parse(BaseRes.REPEAT).add(getComment(WaitPakin.class, String.valueOf(param.get("key")))); | 
|         } | 
|         return R.ok(); | 
|     } | 
|   | 
| } |