zhou zhou
昨天 1dcfa3702505f0c431757312b5304531029f90f6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package com.vincent.rsf.server.manager.controller;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vincent.rsf.framework.common.Cools;
import com.vincent.rsf.framework.common.R;
import com.vincent.rsf.server.common.utils.ExcelUtil;
import com.vincent.rsf.server.common.annotation.OperationLog;
import com.vincent.rsf.server.common.domain.CursorPageParam;
import com.vincent.rsf.server.common.domain.KeyValVo;
import com.vincent.rsf.server.manager.entity.AsnOrderLog;
import com.vincent.rsf.server.manager.service.AsnOrderLogService;
import com.vincent.rsf.server.manager.utils.buildPageRowsUtils;
import com.vincent.rsf.server.system.controller.BaseController;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
 
import jakarta.servlet.http.HttpServletResponse;
import java.util.*;
 
@RestController
public class AsnOrderLogController extends BaseController {
 
    private static final int DEFAULT_CURSOR_PAGE_SIZE = 20;
 
    @Autowired
    private AsnOrderLogService asnOrderLogService;
 
    @PreAuthorize("hasAuthority('manager:asnOrderLog:list')")
    @PostMapping("/asnOrderLog/page")
    public R page(@RequestBody Map<String, Object> map) {
        // 这里已经不再手写游标分页细节,而是直接复用 BaseController 的通用实现。
        //
        // 当前这几个参数分别表达:
        // 1. map:前端原始请求参数
        // 2. CursorPageParam.class:通用游标参数解析器
        // 3. AsnOrderLog.class:用于通用筛选和 condition 模糊搜索
        // 4. asnOrderLogService:实际执行查询的 service
        // 5. "id":本接口的游标字段,固定按 id desc 做分页
        // 6. DEFAULT_CURSOR_PAGE_SIZE:默认每页大小
        // 7. null:当前没有额外的 where 条件扩展
        // 8. buildPageRowsUtils::userNameMap:结果后处理,批量补 createBy$/updateBy$
        return R.ok().add(cursorPage(
                map,
                CursorPageParam.class,
                AsnOrderLog.class,
                asnOrderLogService,
                "id",
                DEFAULT_CURSOR_PAGE_SIZE,
                null,
                buildPageRowsUtils::userNameMap
        ));
    }
 
    @PreAuthorize("hasAuthority('manager:asnOrderLog:list')")
    @PostMapping("/asnOrderLog/list")
    public R list(@RequestBody Map<String, Object> map) {
        return R.ok().add(buildPageRowsUtils.rowsMap(asnOrderLogService.list()));
    }
 
    @PreAuthorize("hasAuthority('manager:asnOrderLog:list')")
    @PostMapping({"/asnOrderLog/many/{ids}", "/asnOrderLogs/many/{ids}"})
    public R many(@PathVariable Long[] ids) {
        return R.ok().add(buildPageRowsUtils.rowsMap(asnOrderLogService.listByIds(Arrays.asList(ids))));
    }
 
    @PreAuthorize("hasAuthority('manager:asnOrderLog:list')")
    @GetMapping("/asnOrderLog/{id}")
    public R get(@PathVariable("id") Long id) {
        return R.ok().add(buildPageRowsUtils.rowsMap(asnOrderLogService.getById(id)));
    }
 
    @PreAuthorize("hasAuthority('manager:asnOrderLog:save')")
    @OperationLog("Create Asn order logs")
    @PostMapping("/asnOrderLog/save")
    public R save(@RequestBody AsnOrderLog asnOrderLog) {
        asnOrderLog.setCreateBy(getLoginUserId());
        asnOrderLog.setCreateTime(new Date());
        asnOrderLog.setUpdateBy(getLoginUserId());
        asnOrderLog.setUpdateTime(new Date());
        if (!asnOrderLogService.save(asnOrderLog)) {
            return R.error("Save Fail");
        }
        return R.ok("Save Success").add(buildPageRowsUtils.rowsMap(asnOrderLog));
    }
 
    @PreAuthorize("hasAuthority('manager:asnOrderLog:update')")
    @OperationLog("Update Asn order logs")
    @PostMapping("/asnOrderLog/update")
    public R update(@RequestBody AsnOrderLog asnOrderLog) {
        asnOrderLog.setUpdateBy(getLoginUserId());
        asnOrderLog.setUpdateTime(new Date());
        if (!asnOrderLogService.updateById(asnOrderLog)) {
            return R.error("Update Fail");
        }
        return R.ok("Update Success").add(buildPageRowsUtils.rowsMap(asnOrderLog));
    }
 
    @PreAuthorize("hasAuthority('manager:asnOrderLog:remove')")
    @OperationLog("Delete Asn order logs")
    @PostMapping("/asnOrderLog/remove/{ids}")
    public R remove(@PathVariable Long[] ids) {
        if (!asnOrderLogService.removeByIds(Arrays.asList(ids))) {
            return R.error("Delete Fail");
        }
        return R.ok("Delete Success").add(buildPageRowsUtils.rowsMap(ids));
    }
 
    @PreAuthorize("hasAuthority('manager:asnOrderLog:list')")
    @PostMapping("/asnOrderLog/query")
    public R query(@RequestParam(required = false) String condition) {
        List<KeyValVo> vos = new ArrayList<>();
        LambdaQueryWrapper<AsnOrderLog> wrapper = new LambdaQueryWrapper<>();
        if (!Cools.isEmpty(condition)) {
            wrapper.like(AsnOrderLog::getId, condition);
        }
        asnOrderLogService.page(new Page<>(1, 30), wrapper).getRecords().forEach(
                item -> vos.add(new KeyValVo(item.getId(), item.getId()))
        );
        return R.ok().add(buildPageRowsUtils.rowsMap(vos));
    }
 
    @PreAuthorize("hasAuthority('manager:asnOrderLog:list')")
    @PostMapping("/asnOrderLog/export")
    public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception {
        List<AsnOrderLog> orders = new ArrayList<>();
        if (!Objects.isNull(map.get("ids"))) {
            List<Long> ids = JSONArray.parseArray(JSONObject.toJSONString(map.get("ids")), Long.class);
            if (!ids.isEmpty()) {
                orders = asnOrderLogService.list(new LambdaQueryWrapper<AsnOrderLog>().in(AsnOrderLog::getId, ids));
            } else {
                orders = asnOrderLogService.list(new LambdaQueryWrapper<>());
            }
        } else {
            orders = asnOrderLogService.list(new LambdaQueryWrapper<>());
        }
        ExcelUtil.build(ExcelUtil.create(buildPageRowsUtils.rowsMap(orders), AsnOrderLog.class), response);
    }
 
    @ApiOperation("继续收货")
    @PreAuthorize("hasAuthority('manager:asnOrderLog:update')")
    @PostMapping("/asnOrderLog/continue/{id}")
    public R continuRcpt(@PathVariable Long id) {
        if (Objects.isNull(id)) {
            return R.error("参数不能为空!!");
        }
        return asnOrderLogService.continueRecipt(id);
    }
 
}