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.common.DateUtils; import com.zy.asrs.entity.BasArmMastSign; import com.zy.asrs.service.BasArmMastSignService; import com.core.annotations.ManagerAuth; import com.core.common.BaseRes; import com.core.common.Cools; import com.core.common.R; import com.zy.common.web.BaseController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.*; @RestController public class BasArmMastSignController extends BaseController { @Autowired private BasArmMastSignService basArmMastSignService; @RequestMapping(value = "/basArmMastSign/{id}/auth") @ManagerAuth public R get(@PathVariable("id") String id) { return R.ok(basArmMastSignService.selectById(String.valueOf(id))); } @RequestMapping(value = "/basArmMastSign/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(required = false)String condition, @RequestParam Map param){ EntityWrapper wrapper = new EntityWrapper<>(); // ===================== 1. 手动处理 binding_tags 的精确匹配(字符串形式) ===================== if (param.containsKey("create_time")) { String tag = String.valueOf(param.get("create_time")).trim(); if (!tag.isEmpty()) { wrapper.eq("create_time", tag); System.out.println("手动添加精确条件: create_time = " + tag); } // 可选:移除原 param,防止 allLike 再次干扰(如果 allLike 会重复加条件) // param.remove("binding_tags"); } // ===================== 2. 其他原有处理逻辑(模糊搜索等) ===================== excludeTrash(param); convert(param, wrapper); allLike(BasArmMastSign.class, param.keySet(), wrapper, condition); // 排序 if (!Cools.isEmpty(orderByField)) { wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType)); } wrapper.orderBy("create_time", false); // 分页查询 Page page = new Page<>(curr, limit); Page resultPage = basArmMastSignService.selectPage(page, wrapper); // ===================== 3. 返回数据处理(转字符串,防止前端精度丢失) ===================== List> newRecords = new ArrayList<>(); for (BasArmMastSign item : resultPage.getRecords()) { Map map = new HashMap<>(); map.put("id", item.getId() != null ? item.getId().toString() : null); // 建议转字符串 map.put("status", item.getStatus()); map.put("matnr", item.getMatnr()); map.put("sku", item.getSku()); map.put("po", item.getPo()); map.put("upc", item.getUpc()); map.put("supplier", item.getSupplier()); map.put("orderNo", item.getOrderNo()); map.put("createTime", item.getCreateTime() != null ? item.getCreateTime().toString() : null); map.put("status$", item.getStatus$()); newRecords.add(map); } // 构造返回结构 Map resultMap = new HashMap<>(); resultMap.put("total", resultPage.getTotal()); resultMap.put("size", resultPage.getSize()); resultMap.put("current", resultPage.getCurrent()); resultMap.put("pages", resultPage.getPages()); resultMap.put("records", newRecords); return R.ok(resultMap); } private void convert(Map map, EntityWrapper wrapper){ for (Map.Entry 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 if (entry.getKey().equals("create_time")){ long aLong = Long.parseLong(val); wrapper.ge(entry.getKey(), aLong); } else { wrapper.like(entry.getKey(), val); } } } @RequestMapping(value = "/basArmMastSign/add/auth") @ManagerAuth public R add(BasArmMastSign basArmMastSign) { basArmMastSignService.insert(basArmMastSign); return R.ok(); } @RequestMapping(value = "/basArmMastSign/update/auth") @ManagerAuth public R update(BasArmMastSign basArmMastSign){ if (Cools.isEmpty(basArmMastSign) || null==basArmMastSign.getId()){ return R.error(); } basArmMastSignService.updateById(basArmMastSign); return R.ok(); } @RequestMapping(value = "/basArmMastSign/delete/auth") @ManagerAuth public R delete(@RequestParam(value="ids[]") Long[] ids){ for (Long id : ids){ basArmMastSignService.deleteById(id); } return R.ok(); } @RequestMapping(value = "/basArmMastSign/export/auth") @ManagerAuth public R export(@RequestBody JSONObject param){ EntityWrapper wrapper = new EntityWrapper<>(); List fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); Map map = excludeTrash(param.getJSONObject("basArmMastSign")); convert(map, wrapper); List list = basArmMastSignService.selectList(wrapper); return R.ok(exportSupport(list, fields)); } @RequestMapping(value = "/basArmMastSignQuery/auth") @ManagerAuth public R query(String condition) { EntityWrapper wrapper = new EntityWrapper<>(); wrapper.like("id", condition); Page page = basArmMastSignService.selectPage(new Page<>(0, 10), wrapper); List> result = new ArrayList<>(); for (BasArmMastSign basArmMastSign : page.getRecords()){ Map map = new HashMap<>(); map.put("id", basArmMastSign.getId()); map.put("value", basArmMastSign.getId()); result.add(map); } return R.ok(result); } @RequestMapping(value = "/basArmMastSign/check/column/auth") @ManagerAuth public R query(@RequestBody JSONObject param) { Wrapper wrapper = new EntityWrapper().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val")); if (null != basArmMastSignService.selectOne(wrapper)){ return R.parse(BaseRes.REPEAT).add(getComment(BasArmMastSign.class, String.valueOf(param.get("key")))); } return R.ok(); } }