|  |  |  | 
|---|
|  |  |  | package com.vincent.rsf.server.manager.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONArray; | 
|---|
|  |  |  | 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.vincent.rsf.framework.common.Cools; | 
|---|
|  |  |  | import com.vincent.rsf.framework.common.R; | 
|---|
|  |  |  | import com.vincent.rsf.framework.exception.CoolException; | 
|---|
|  |  |  | 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.controller.params.LocMastInitParam; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.controller.params.LocModifyParams; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.Loc; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.enums.LocStsType; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.LocService; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.controller.BaseController; | 
|---|
|  |  |  | import io.swagger.annotations.Api; | 
|---|
|  |  |  | import io.swagger.annotations.ApiModelProperty; | 
|---|
|  |  |  | import io.swagger.annotations.ApiOperation; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.security.access.prepost.PreAuthorize; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletResponse; | 
|---|
|  |  |  | import javax.validation.Valid; | 
|---|
|  |  |  | import javax.validation.constraints.NotNull; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Api(tags = "库位信息") | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | public class LocController extends BaseController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | public R page(@RequestBody Map<String, Object> map) { | 
|---|
|  |  |  | BaseParam baseParam = buildParam(map, BaseParam.class); | 
|---|
|  |  |  | PageParam<Loc, BaseParam> pageParam = new PageParam<>(baseParam, Loc.class); | 
|---|
|  |  |  | return R.ok().add(locService.page(pageParam, pageParam.buildWrapper(true))); | 
|---|
|  |  |  | List<String> list = new ArrayList<>(); | 
|---|
|  |  |  | list.add("row"); | 
|---|
|  |  |  | list.add("col"); | 
|---|
|  |  |  | list.add("lev"); | 
|---|
|  |  |  | return R.ok().add(locService.page(pageParam, pageParam.buildWrapper(true,list))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:loc:list')") | 
|---|
|  |  |  | @PostMapping("/loc/list") | 
|---|
|  |  |  | public R list(@RequestBody Map<String, Object> map) { | 
|---|
|  |  |  | return R.ok().add(locService.list()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:loc:list')") | 
|---|
|  |  |  | @PostMapping("/loc/areaNoUse/list") | 
|---|
|  |  |  | public R areaNoUselist(@RequestBody Map<String, Object> map) { | 
|---|
|  |  |  | String locCode = map.get("locCode").toString(); | 
|---|
|  |  |  | Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, locCode),false); | 
|---|
|  |  |  | List<Loc> list = locService.list(new LambdaQueryWrapper<Loc>() | 
|---|
|  |  |  | .eq(Loc::getAreaId, loc.getAreaId()) | 
|---|
|  |  |  | .eq(Loc::getChannel,loc.getChannel()) | 
|---|
|  |  |  | .eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | List<String> list1 = list.stream().map(obj -> obj.getCode()).collect(Collectors.toList()); | 
|---|
|  |  |  | return R.ok(list1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:loc:list')") | 
|---|
|  |  |  | 
|---|
|  |  |  | @OperationLog("Create 库位信息表") | 
|---|
|  |  |  | @PostMapping("/loc/save") | 
|---|
|  |  |  | public R save(@RequestBody Loc loc) { | 
|---|
|  |  |  | if (Objects.isNull(loc.getWarehouseId())) { | 
|---|
|  |  |  | throw new CoolException("仓库ID不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Objects.isNull(loc.getAreaId())) { | 
|---|
|  |  |  | throw new CoolException("仓库ID不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Objects.isNull(loc.getTypeIds())) { | 
|---|
|  |  |  | throw new CoolException("库位类型不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String join = StringUtils.join(loc.getTypeIds(), ","); | 
|---|
|  |  |  | loc.setType(join); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | loc.setCreateBy(getLoginUserId()); | 
|---|
|  |  |  | loc.setCreateTime(new Date()); | 
|---|
|  |  |  | loc.setUpdateBy(getLoginUserId()); | 
|---|
|  |  |  | loc.setUpdateTime(new Date()); | 
|---|
|  |  |  | if (!locService.save(loc)) { | 
|---|
|  |  |  | return R.error("Save Fail"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!locService.saveType(loc)) { | 
|---|
|  |  |  | throw new CoolException("库位类型关联关系保存失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("Save Success").add(loc); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:loc:update')") | 
|---|
|  |  |  | @OperationLog("Update 库位信息表") | 
|---|
|  |  |  | @PostMapping("/loc/update") | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public R update(@RequestBody Loc loc) { | 
|---|
|  |  |  | loc.setUpdateBy(getLoginUserId()); | 
|---|
|  |  |  | loc.setUpdateTime(new Date()); | 
|---|
|  |  |  | String join = StringUtils.join(loc.getTypeIds(), ","); | 
|---|
|  |  |  | loc.setType(join); | 
|---|
|  |  |  | if (Objects.isNull(loc.getTypeIds())) { | 
|---|
|  |  |  | throw new CoolException("库位类型不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!locService.updateById(loc)) { | 
|---|
|  |  |  | return R.error("Update Fail"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!locService.updateLoc(loc)) { | 
|---|
|  |  |  | throw new CoolException("库位类型关联关系修改失败!@!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("Update Success").add(loc); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | List<KeyValVo> vos = new ArrayList<>(); | 
|---|
|  |  |  | LambdaQueryWrapper<Loc> wrapper = new LambdaQueryWrapper<>(); | 
|---|
|  |  |  | if (!Cools.isEmpty(condition)) { | 
|---|
|  |  |  | wrapper.like(Loc::getName, condition); | 
|---|
|  |  |  | wrapper.like(Loc::getCode, condition); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | locService.page(new Page<>(1, 30), wrapper).getRecords().forEach( | 
|---|
|  |  |  | item -> vos.add(new KeyValVo(item.getId(), item.getName())) | 
|---|
|  |  |  | item -> vos.add(new KeyValVo(item.getId(), item.getCode())) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | return R.ok().add(vos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:loc:list')") | 
|---|
|  |  |  | @ApiOperation("库位导出") | 
|---|
|  |  |  | @PostMapping("/loc/export") | 
|---|
|  |  |  | public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { | 
|---|
|  |  |  | ExcelUtil.build(ExcelUtil.create(locService.list(), Loc.class), response); | 
|---|
|  |  |  | List<Loc> locs = new ArrayList<>(); | 
|---|
|  |  |  | if (Objects.isNull(map.get("ids"))) { | 
|---|
|  |  |  | locs = locService.list(); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | locs = locService.list(new LambdaQueryWrapper<Loc>().eq(Loc::getStatus, 1)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ExcelUtil.build(ExcelUtil.create(locs, Loc.class), response); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:loc:update')") | 
|---|
|  |  |  | @ApiOperation("库位批量修改") | 
|---|
|  |  |  | @PostMapping("/loc/modify") | 
|---|
|  |  |  | public R batchUpdate(@RequestBody LocModifyParams locs) { | 
|---|
|  |  |  | if (Objects.isNull(locs)) { | 
|---|
|  |  |  | throw new CoolException("参为不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return locService.modifyLocs(locs); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:loc:update')") | 
|---|
|  |  |  | @PostMapping("/loc/batch/area") | 
|---|
|  |  |  | @ApiOperation("库位批量分区") | 
|---|
|  |  |  | public R batchLocArea(@RequestBody LocModifyParams locs) { | 
|---|
|  |  |  | if (Objects.isNull(locs)) { | 
|---|
|  |  |  | throw new CoolException("参数不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | locs.setCreateBy(getLoginUserId()); | 
|---|
|  |  |  | locs.setUpdateBy(getLoginUserId()); | 
|---|
|  |  |  | return locService.batchBindLocs(locs); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:loc:update')") | 
|---|
|  |  |  | @ApiOperation("库位初始化") | 
|---|
|  |  |  | @PostMapping("/loc/init") | 
|---|
|  |  |  | public R initLocInfo(@Valid @RequestBody LocMastInitParam param) { | 
|---|
|  |  |  | if (Objects.isNull(param)) { | 
|---|
|  |  |  | return R.error("初始化信息不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Objects.isNull(param.getTypeIds()) && param.getTypeIds().isEmpty()) { | 
|---|
|  |  |  | return R.error("库位类型不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Objects.isNull(param.getWarehouseId())) { | 
|---|
|  |  |  | return R.error("仓库ID不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Objects.isNull(param.getAreaId())) { | 
|---|
|  |  |  | return R.error("库区ID不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Objects.isNull(param.getStartRow())) { | 
|---|
|  |  |  | return R.error("起始排不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Objects.isNull(param.getEndRow())) { | 
|---|
|  |  |  | return R.error("终止排不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Objects.isNull(param.getStartBay())) { | 
|---|
|  |  |  | return R.error("起始列不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Objects.isNull(param.getEndBay())) { | 
|---|
|  |  |  | return R.error("终止列不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Objects.isNull(param.getStartLev())) { | 
|---|
|  |  |  | return R.error("起始层不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Objects.isNull(param.getEndLev())) { | 
|---|
|  |  |  | return R.error("终止层不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Objects.isNull(param.getChannel())) { | 
|---|
|  |  |  | return R.error("巷道不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return locService.initLocs(param, getLoginUserId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|