package com.ruoyi.management.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.page.PageDTO;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.management.domain.SlGoodsShelf;
import com.ruoyi.management.domain.SlStoreManagement;
import com.ruoyi.management.domain.dto.QStoreManagementQuery;
import com.ruoyi.management.domain.dto.StoreManagementDTO;
import com.ruoyi.management.domain.dto.StoreManagementQuery;
import com.ruoyi.management.mapper.SlGoodsShelfMapper;
import com.ruoyi.management.service.SlStoreManagementService;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.feignClient.SysUserClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
*
* 仓库管理 前端控制器
*
*
* @author hjl
* @since 2024-06-25
*/
@RestController
@RequestMapping("/sl-store-management")
@Api(value = "仓库管理接口", tags = "仓库管理接口", description = "仓库管理接口")
public class SlStoreManagementController {
@Resource
private TokenService tokenService;
@Resource
private SlStoreManagementService slStoreManagementService;
@Resource
private SlGoodsShelfMapper slGoodsShelfMapper;
@Resource
private SysUserClient sysUserClient;
@PostMapping("/isHaveCKZY/{id}")
@ApiOperation(value = "远程调用 根据用户id 判断是否有出库审核管理菜单权限和转移管理菜单权限")
public R isHaveCKZY(@PathVariable("id") String id) {
if (id.equals("1")){
return R.ok("1");
}
SysUser data = sysUserClient.getSysUser(Long.parseLong(id)).getData();
if (data!=null){
if (data.getUserType().equals("00")){
return R.ok("1");
}
}
List list = slStoreManagementService.list(new QueryWrapper()
.eq("del_flag", "0"));
List res = new ArrayList<>();
for (SlStoreManagement slStoreManagement : list) {
if (Arrays.asList(slStoreManagement.getDirectorId().split(",")).contains(id) || Arrays.asList(slStoreManagement.getAdministratorId().split(",")).contains(id) || Arrays.asList(slStoreManagement.getCompetentId().split(",")).contains(id)) {
res.add(slStoreManagement);
}
}
if (!res.isEmpty()){
return R.ok("1");
}else{
return R.ok("0");
}
}
@PostMapping("/getStoreManagementList")
@ApiOperation(value = "分页获取仓库管理")
public R> getStoreManagementList(@RequestBody StoreManagementQuery storeManagementQuery) {
tokenService.getLoginUser();
return R.ok(slStoreManagementService.getStoreManagementList(storeManagementQuery));
}
@PostMapping("/addStoreManagement")
@ApiOperation(value = "添加/修改仓库管理")
public AjaxResult addStoreManagement(@RequestBody StoreManagementDTO storeManagementDTO) {
tokenService.getLoginUser();
return slStoreManagementService.addStoreManagement(storeManagementDTO);
}
@ApiOperation("删除仓库管理")
@DeleteMapping("/{id}")
public R> delStoreManagement(
@ApiParam(name = "id", value = "仓库管理id", required = true) @PathVariable("id") Long id) {
tokenService.getLoginUser();
List slGoodsShelves = slGoodsShelfMapper.selectList(new QueryWrapper()
.eq("store_management_id", id)
.eq("del_flag", "0"));
if (!slGoodsShelves.isEmpty()){
return R.fail("删除失败,当前仓库有货架");
}
SlStoreManagement byId = slStoreManagementService.getById(id);
byId.setDelFlag("1");
slStoreManagementService.updateById(byId);
return R.ok();
}
@GetMapping("/getStoreManagementOne/{id}")
@ApiOperation(value = "仓库管理詳情")
public R getStoreManagementOne( @ApiParam(name = "id", value = "仓库管理id", required = true) @PathVariable("id") Long id) {
tokenService.getLoginUser();
return R.ok(slStoreManagementService.getById(id));
}
@PostMapping("/QueryStoreManagementList")
@ApiOperation(value = "根据条件仓库管理列表")
public R> QueryStoreManagementList(@RequestBody QStoreManagementQuery StoreManagementQuery) {
tokenService.getLoginUser();
return R.ok(slStoreManagementService.QueryStoreManagementList(StoreManagementQuery));
}
}