|  |  | 
 |  |  | 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.WarehouseAreaParam; | 
 |  |  | import com.vincent.rsf.server.manager.entity.Loc; | 
 |  |  | import com.vincent.rsf.server.manager.entity.WarehouseAreas; | 
 |  |  | import com.vincent.rsf.server.manager.service.LocService; | 
 |  |  | import com.vincent.rsf.server.manager.service.WarehouseAreasService; | 
 |  |  | import com.vincent.rsf.server.system.controller.BaseController; | 
 |  |  | import io.swagger.annotations.Api; | 
 |  |  | 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.*; | 
 |  |  |  | 
 |  |  | @Api(tags = "仓库库区") | 
 |  |  | @RestController | 
 |  |  | public class WarehouseAreasController extends BaseController { | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private WarehouseAreasService warehouseAreasService; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private LocService locService; | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('manager:warehouseAreas:list')") | 
 |  |  |     @PostMapping("/warehouseAreas/page") | 
 |  |  | 
 |  |  |     @OperationLog("Create 库区信息表") | 
 |  |  |     @PostMapping("/warehouseAreas/save") | 
 |  |  |     public R save(@RequestBody WarehouseAreas warehouseAreas) { | 
 |  |  |  | 
 |  |  |         if (Objects.isNull(warehouseAreas)) { | 
 |  |  |             throw new CoolException("参数不能为空!!"); | 
 |  |  |         } | 
 |  |  |         if (Objects.isNull(warehouseAreas.getName())) { | 
 |  |  |             throw new CoolException("库区名称不能为空!!"); | 
 |  |  |         } | 
 |  |  |         if (Objects.isNull(warehouseAreas.getCode())) { | 
 |  |  |             throw new CoolException("库区编码不能为空!!"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         List<WarehouseAreas> list = warehouseAreasService.list(new LambdaQueryWrapper<WarehouseAreas>().eq(WarehouseAreas::getName, warehouseAreas.getName())); | 
 |  |  |         if (!list.isEmpty()) { | 
 |  |  |             throw new CoolException("库区名称已存在!!"); | 
 |  |  |         } | 
 |  |  |         if (!warehouseAreasService.list(new LambdaQueryWrapper<WarehouseAreas>().eq(WarehouseAreas::getCode, warehouseAreas.getCode())).isEmpty()) { | 
 |  |  |             throw new CoolException("库区编码已存在!!"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         warehouseAreas.setCreateBy(getLoginUserId()); | 
 |  |  |         warehouseAreas.setCreateTime(new Date()); | 
 |  |  |         warehouseAreas.setUpdateBy(getLoginUserId()); | 
 |  |  |         warehouseAreas.setUpdateTime(new Date()); | 
 |  |  |         if (!warehouseAreasService.save(warehouseAreas)) { | 
 |  |  |             return R.error("Save Fail"); | 
 |  |  |         } | 
 |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('manager:warehouseAreas:update')") | 
 |  |  |     @ApiOperation("库区批量修改") | 
 |  |  |     @PostMapping("/warehouseAreas/batch/update") | 
 |  |  |     public R batchUpdate(@RequestBody WarehouseAreaParam params) { | 
 |  |  |         if (Objects.isNull(params)) { | 
 |  |  |             return R.error("参数不能为空!!"); | 
 |  |  |         } | 
 |  |  |         if (Objects.isNull(params.getIds()) &&  params.getIds().isEmpty()) { | 
 |  |  |             return R.error("库区ID不能为空!!"); | 
 |  |  |         } | 
 |  |  |         if (warehouseAreasService.batchUpdate(params, getLoginUserId())) { | 
 |  |  |             return R.ok("修改成功!!"); | 
 |  |  |         } else { | 
 |  |  |             return R.error("修改失败!!"); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('manager:warehouseAreas:update')") | 
 |  |  |     @OperationLog("Update 库区信息表") | 
 |  |  |     @PostMapping("/warehouseAreas/update") | 
 |  |  |     public R update(@RequestBody WarehouseAreas warehouseAreas) { | 
 |  |  |         warehouseAreas.setUpdateBy(getLoginUserId()); | 
 |  |  |         warehouseAreas.setUpdateTime(new Date()); | 
 |  |  |         WarehouseAreas areas = warehouseAreasService.getById(warehouseAreas.getId()); | 
 |  |  |         if (Objects.isNull(areas)) { | 
 |  |  |             throw new CoolException("数据错误:仓库库区不存在!!"); | 
 |  |  |         } | 
 |  |  |         if (!warehouseAreas.getName().equals(areas.getName())) { | 
 |  |  |             List<WarehouseAreas> areasList = warehouseAreasService.list(new LambdaQueryWrapper<WarehouseAreas>().eq(WarehouseAreas::getName, warehouseAreas.getName())); | 
 |  |  |             if (!areasList.isEmpty()) { | 
 |  |  |                 throw new CoolException("名称已存在!!"); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         if (!warehouseAreas.getCode().equals(areas.getCode())) { | 
 |  |  |             List<WarehouseAreas> areasList = warehouseAreasService.list(new LambdaQueryWrapper<WarehouseAreas>().eq(WarehouseAreas::getCode, warehouseAreas.getCode())); | 
 |  |  |             if (!areasList.isEmpty()) { | 
 |  |  |                 throw new CoolException("编码已存在!!"); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         if (!warehouseAreasService.updateById(warehouseAreas)) { | 
 |  |  |             return R.error("Update Fail"); | 
 |  |  |         } | 
 |  |  | 
 |  |  |     @OperationLog("Delete 库区信息表") | 
 |  |  |     @PostMapping("/warehouseAreas/remove/{ids}") | 
 |  |  |     public R remove(@PathVariable Long[] ids) { | 
 |  |  |         List<Loc> locs = locService.list(new LambdaQueryWrapper<Loc>().in(Loc::getAreaId, ids)); | 
 |  |  |         if (!locs.isEmpty()) { | 
 |  |  |             throw new CoolException("当前库有库位绑定,不能执行删除操作!!"); | 
 |  |  |         } | 
 |  |  |         if (!warehouseAreasService.removeByIds(Arrays.asList(ids))) { | 
 |  |  |             return R.error("Delete Fail"); | 
 |  |  |         } |