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);
|
}
|
|
}
|