| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.zy.acs.common.constant.CommonConstant; |
| | | import com.zy.acs.common.utils.GsonUtils; |
| | | import com.zy.acs.common.utils.Utils; |
| | | import com.zy.acs.common.utils.QrCodeCodecSupport; |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.framework.common.R; |
| | | import com.zy.acs.framework.exception.CoolException; |
| | |
| | | @OperationLog("Create Code") |
| | | @PostMapping("/code/save") |
| | | public R save(@RequestBody Code code) { |
| | | code.setData(Utils.zeroFill(code.getData(), CommonConstant.QR_CODE_LEN)); |
| | | code.setData(QrCodeCodecSupport.normalize(code.getData())); |
| | | code.setUuid("code".concat(code.getData())); |
| | | code.setCreateBy(getLoginUserId()); |
| | | code.setCreateTime(new Date()); |
| | |
| | | @PostMapping("/code/update") |
| | | public R update(@RequestBody Code code) { |
| | | Code origin = codeService.getById(code.getId()); |
| | | code.setData(Utils.zeroFill(code.getData(), CommonConstant.QR_CODE_LEN)); |
| | | boolean cornerChanged = origin != null |
| | | && code.getCorner() != null |
| | | && !Objects.equals(origin.getCorner(), code.getCorner()); |
| | | code.setData(QrCodeCodecSupport.normalize(code.getData())); |
| | | code.setUpdateBy(getLoginUserId()); |
| | | code.setUpdateTime(new Date()); |
| | | if (!codeService.updateById(code)) { |
| | | return R.error("Update Fail"); |
| | | } |
| | | List<Long> affectedCodeIds = Utils.singletonList(code.getId()); |
| | | affectedCodeIds.addAll(routeService.getAdjacencyNode(code.getId())); |
| | | List<Long> affectedCodeIds = new ArrayList<>(routeService.getAdjacencyNode(code.getId())); |
| | | if (!cornerChanged) { |
| | | affectedCodeIds.add(code.getId()); |
| | | } |
| | | codeService.evictCacheById(code.getId(), origin == null ? null : origin.getData()); |
| | | codeService.refreshCacheById(code.getId()); |
| | | codeService.refreshCornerByCodeIds(affectedCodeIds); |
| | | if (!affectedCodeIds.isEmpty()) { |
| | | codeService.refreshCornerByCodeIds(affectedCodeIds); |
| | | } |
| | | return R.ok("Update Success").add(code); |
| | | } |
| | | |
| | |
| | | @PreAuthorize("hasAuthority('manager:code:list')") |
| | | @PostMapping("/code/export") |
| | | public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | ExcelUtil.build(ExcelUtil.create(codeService.list(), Code.class), response); |
| | | // 1. 提取筛选条件(兼容前端 { filter: {...} } 格式) |
| | | Map<String, Object> filter = map; |
| | | if (map != null && map.containsKey("filter")) { |
| | | Object filterObj = map.get("filter"); |
| | | if (filterObj instanceof Map) { |
| | | filter = (Map<String, Object>) filterObj; |
| | | } |
| | | } |
| | | |
| | | // 2. 构建查询条件(MyBatis-Plus) |
| | | QueryWrapper<Code> wrapper = new QueryWrapper<>(); |
| | | if (filter != null && !filter.isEmpty()) { |
| | | // 根据前端可能传递的字段添加条件(字段名需与数据库列或实体属性对应) |
| | | if (filter.containsKey("corner")) { |
| | | wrapper.eq("corner", filter.get("corner")); |
| | | } |
| | | if (filter.containsKey("condition")) { |
| | | String condition = (String) filter.get("condition"); |
| | | wrapper.and(w -> w.like("data", condition).or().like("uuid", condition)); |
| | | } |
| | | if (filter.containsKey("timeStart")) { |
| | | wrapper.ge("create_time", filter.get("timeStart")); |
| | | } |
| | | if (filter.containsKey("timeEnd")) { |
| | | wrapper.le("create_time", filter.get("timeEnd")); |
| | | } |
| | | if (filter.containsKey("x")) { |
| | | wrapper.eq("x", filter.get("x")); |
| | | } |
| | | if (filter.containsKey("y")) { |
| | | wrapper.eq("y", filter.get("y")); |
| | | } |
| | | if (filter.containsKey("memo")) { |
| | | wrapper.like("memo", filter.get("memo")); |
| | | } |
| | | if (filter.containsKey("status")) { |
| | | wrapper.eq("status", filter.get("status")); |
| | | } |
| | | // 还可以添加其他字段如 data, uuid 等 |
| | | } |
| | | |
| | | // 3. 查询符合条件的数据 |
| | | List<Code> list = codeService.list(wrapper); |
| | | |
| | | // 4. 导出 Excel |
| | | ExcelUtil.build(ExcelUtil.create(list, Code.class), response); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:code:save')") |
| | |
| | | Date now = new Date(); Long userId = getLoginUserId(); |
| | | for (Map<String, Object> map : list) { |
| | | Code code = Cools.convert(map, Code.class); |
| | | code.setData(QrCodeCodecSupport.normalize(code.getData())); |
| | | if (null != codeService.getCacheByData(code.getData())) { |
| | | continue; |
| | | } |
| | | code.setData(Utils.zeroFill(code.getData(), CommonConstant.QR_CODE_LEN)); |
| | | code.setUuid("code".concat(code.getData())); |
| | | // code.setCorner(0); |
| | | code.setScale(GsonUtils.toJson(Cools.add("x", 1).add("y", 1))); |