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.BaseParam; import com.vincent.rsf.server.common.domain.KeyValVo; import com.vincent.rsf.server.common.domain.PageParam; import com.vincent.rsf.server.manager.entity.AsnOrder; import com.vincent.rsf.server.manager.entity.AsnOrderLog; import com.vincent.rsf.server.manager.service.AsnOrderLogService; 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 javax.servlet.http.HttpServletResponse; import java.util.*; @RestController public class AsnOrderLogController extends BaseController { @Autowired private AsnOrderLogService asnOrderLogService; @PreAuthorize("hasAuthority('manager:asnOrderLog:list')") @PostMapping("/asnOrderLog/page") public R page(@RequestBody Map map) { BaseParam baseParam = buildParam(map, BaseParam.class); PageParam pageParam = new PageParam<>(baseParam, AsnOrderLog.class); return R.ok().add(asnOrderLogService.page(pageParam, pageParam.buildWrapper(true))); } @PreAuthorize("hasAuthority('manager:asnOrderLog:list')") @PostMapping("/asnOrderLog/list") public R list(@RequestBody Map map) { return R.ok().add(asnOrderLogService.list()); } @PreAuthorize("hasAuthority('manager:asnOrderLog:list')") @PostMapping({"/asnOrderLog/many/{ids}", "/asnOrderLogs/many/{ids}"}) public R many(@PathVariable Long[] ids) { return R.ok().add(asnOrderLogService.listByIds(Arrays.asList(ids))); } @PreAuthorize("hasAuthority('manager:asnOrderLog:list')") @GetMapping("/asnOrderLog/{id}") public R get(@PathVariable("id") Long id) { return R.ok().add(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(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(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(ids); } @PreAuthorize("hasAuthority('manager:asnOrderLog:list')") @PostMapping("/asnOrderLog/query") public R query(@RequestParam(required = false) String condition) { List vos = new ArrayList<>(); LambdaQueryWrapper 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(vos); } @PreAuthorize("hasAuthority('manager:asnOrderLog:list')") @PostMapping("/asnOrderLog/export") public void export(@RequestBody Map map, HttpServletResponse response) throws Exception { List orders = new ArrayList<>(); if (!Objects.isNull(map.get("ids"))) { List ids = JSONArray.parseArray(JSONObject.toJSONString(map.get("ids")), Long.class); if (!ids.isEmpty()) { orders = asnOrderLogService.list(new LambdaQueryWrapper().in(AsnOrderLog::getId, ids)); } else { orders = asnOrderLogService.list(new LambdaQueryWrapper<>()); } } else { orders = asnOrderLogService.list(new LambdaQueryWrapper<>()); } ExcelUtil.build(ExcelUtil.create(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); } }