| package doumeemes.api.ext; | 
|   | 
| import doumeemes.api.BaseController; | 
| import doumeemes.core.annotation.excel.ExcelExporter; | 
| import doumeemes.core.annotation.pr.PreventRepeat; | 
| import doumeemes.core.model.ApiResponse; | 
| import doumeemes.core.model.LoginUserInfo; | 
| import doumeemes.core.model.PageData; | 
| import doumeemes.core.model.PageWrap; | 
| import doumeemes.core.utils.Constants; | 
| import doumeemes.dao.business.model.BarcodeParam; | 
| import doumeemes.dao.business.model.Warehouse; | 
| import doumeemes.dao.ext.dto.QueryWStockExtDTO; | 
| import doumeemes.dao.ext.dto.QueryWarehouseExtDTO; | 
| import doumeemes.dao.ext.vo.WStockExtListVO; | 
| import doumeemes.dao.ext.vo.WarehouseExtListVO; | 
| import doumeemes.service.business.BarcodeParamService; | 
| import doumeemes.service.business.WarehouseService; | 
| import doumeemes.service.ext.WStockExtService; | 
| import doumeemes.service.ext.WarehouseExtService; | 
| import io.swagger.annotations.Api; | 
| import io.swagger.annotations.ApiOperation; | 
| import org.apache.shiro.SecurityUtils; | 
| import org.apache.shiro.authz.annotation.RequiresPermissions; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.web.bind.annotation.*; | 
|   | 
| import javax.servlet.http.HttpServletResponse; | 
| import java.util.ArrayList; | 
| import java.util.Date; | 
| import java.util.List; | 
|   | 
| /** | 
|  * 仓库信息接口 | 
|  * @author 江蹄蹄 | 
|  * @date 2022/05/05 11:37 | 
|  */ | 
| @RestController | 
| @RequestMapping("/ext/warehouseExt") | 
| @Api(tags = "仓库信息接口") | 
| public class WarehouseExtController extends BaseController { | 
|   | 
|     @Autowired | 
|     private WarehouseExtService warehouseExtService; | 
|      | 
|     @Autowired | 
|     private WarehouseService warehouseService; | 
|   | 
|     @Autowired | 
|     private WStockExtService wStockExtService; | 
|   | 
|     @Autowired | 
|     private BarcodeParamService barcodeParamService; | 
|   | 
|   | 
|     @PreventRepeat | 
|     @ApiOperation("新建") | 
|     @PostMapping("/create") | 
|     @RequiresPermissions("ext:warehouseext:create") | 
|     public ApiResponse create(@RequestBody Warehouse warehouse) { | 
|   | 
|         //获取二维码规则 | 
|         BarcodeParam queryparam=new BarcodeParam(); | 
|         queryparam.setDepartId(getLoginUser().getCurComDepartment().getId()); | 
|         queryparam.setRootDepartId(getLoginUser().getRootDepartment().getId()); | 
|         queryparam.setType(Constants.BARCODEPARAM_TYPE.warehouse); | 
|         BarcodeParam barcodeParam =barcodeParamService.findOne(queryparam); | 
|         if(barcodeParam==null){ | 
|             return ApiResponse.failed("请先完善二维码篮筐配置"); | 
|         } | 
|         warehouse.setQrcode(barcodeParam.getId()); | 
|   | 
|         Warehouse search=new Warehouse(); | 
|         search.setDeleted(Constants.ZERO); | 
|         search.setRootDepartId(getLoginUser().getRootDepartment().getId()); | 
|         search.setName(warehouse.getName()); | 
|         List<Warehouse> listname= warehouseService.findList(search); | 
|   | 
|         Warehouse search1=new Warehouse(); | 
|         search1.setDeleted(Constants.ZERO); | 
|         search1.setRootDepartId(getLoginUser().getRootDepartment().getId()); | 
|         search1.setCode(warehouse.getCode()); | 
|         List<Warehouse> listcode= warehouseService.findList(search1); | 
|   | 
|         if(listname.size()>0||listcode.size()>0){ | 
|             return ApiResponse.failed("同一组织下编码/名称已存在,不允许添加"); | 
|         } | 
|   | 
|         warehouse.setDeleted(Constants.ZERO); | 
|         warehouse.setCreateTime(new Date()); | 
|         warehouse.setCreateUser(getLoginUser().getId()); | 
|         warehouse.setRootDepartId(getLoginUser().getRootDepartment().getId()); | 
|         warehouse.setDepartId(getLoginUser().getCurComDepartment().getId()); | 
|         warehouse.setStatus( Constants.ONE); | 
|         return ApiResponse.success(warehouseService.create(warehouse)); | 
|     } | 
|   | 
|     @ApiOperation("根据ID删除") | 
|     @GetMapping("/delete/{id}") | 
|     @RequiresPermissions("ext:warehouseext:delete") | 
|     public ApiResponse deleteById(@PathVariable Integer id) { | 
|         Warehouse warehouse=new Warehouse(); | 
|         warehouse.setId(id); | 
|         warehouse.setDeleted(Constants.ONE); | 
|         warehouseService.updateById(warehouse); | 
|         return ApiResponse.success(null); | 
|     } | 
|   | 
|     @ApiOperation("批量删除") | 
|     @GetMapping("/delete/batch") | 
|     @RequiresPermissions("ext:warehouseext:delete") | 
|     public ApiResponse deleteByIds(@RequestParam String ids) { | 
|         String [] idArray = ids.split(","); | 
|         List<Warehouse> idList = new ArrayList<>(); | 
|         for (String id : idArray) { | 
|             Warehouse warehouse=new Warehouse(); | 
|             warehouse.setDeleted(Constants.ONE); | 
|             warehouse.setId(Integer.valueOf(id)); | 
|             idList.add(warehouse); | 
|         } | 
|         warehouseService.updateByIdInBatch(idList); | 
|         return ApiResponse.success(null); | 
|     } | 
|   | 
|     @ApiOperation("根据ID修改") | 
|     @PostMapping("/updateById") | 
|     @RequiresPermissions("ext:warehouseext:update") | 
|     public ApiResponse updateById(@RequestBody Warehouse warehouse) { | 
|         return warehouseService.editUpdateById(warehouse); | 
|     } | 
|   | 
|     @ApiOperation("分页查询") | 
|     @PostMapping("/page") | 
|     @RequiresPermissions("ext:warehouseext:query") | 
|     public ApiResponse<PageData<WarehouseExtListVO>> findPage (@RequestBody PageWrap<QueryWarehouseExtDTO> pageWrap) { | 
|         pageWrap.getModel().setDeleted(Constants.ZERO); | 
|         pageWrap.getModel().setRootDepartId(getLoginUser().getRootDepartment().getId()); | 
|         pageWrap.getModel().setDepartId(getLoginUser().getCurComDepartment().getId()); | 
|         return ApiResponse.success(warehouseExtService.findPage(pageWrap)); | 
|     } | 
|   | 
|   | 
|   | 
|     @ApiOperation("后台根据权限分页查询") | 
|     @PostMapping("/QXpage") | 
|     @RequiresPermissions("ext:warehouseext:query") | 
|     public ApiResponse<PageData<WarehouseExtListVO>> QXpage (@RequestBody PageWrap<QueryWarehouseExtDTO> pageWrap) { | 
|         pageWrap.getModel().setDeleted(Constants.ZERO); | 
|         pageWrap.getModel().setRootDepartId(getLoginUser().getRootDepartment().getId()); | 
|         pageWrap.getModel().setDepartId(getLoginUser().getCurComDepartment().getId()); | 
|         return ApiResponse.success(warehouseExtService.QXpage(pageWrap)); | 
|     } | 
|   | 
|     @ApiOperation("导出Excel") | 
|     @PostMapping("/exportExcel") | 
|     @RequiresPermissions("ext:warehouseext:exportExcel") | 
|     public void exportExcel (@RequestBody PageWrap<QueryWarehouseExtDTO> pageWrap, HttpServletResponse response) { | 
|         ExcelExporter.build(WarehouseExtListVO.class).export(warehouseExtService.findPage(pageWrap).getRecords(), "仓库信息", response); | 
|     } | 
|   | 
|     @ApiOperation("根据ID查询") | 
|     @GetMapping("/{id}") | 
|     @RequiresPermissions("ext:warehouseext:query") | 
|     public ApiResponse findById(@PathVariable Integer id) { | 
|         return ApiResponse.success(warehouseService.findById(id)); | 
|     } | 
|   | 
|   | 
|     @ApiOperation("查询当前主组织下所有数据") | 
|     @PostMapping("/queryAllData") | 
|     @RequiresPermissions("ext:warehouseext:queryAllData") | 
|     public ApiResponse<List<WarehouseExtListVO>> queryAllData (@RequestBody QueryWarehouseExtDTO pageWrap) { | 
|         pageWrap.setDeleted(Constants.ZERO); | 
|         pageWrap.setRootDepartId(getLoginUser().getRootDepartment().getId()); | 
|         pageWrap.setDepartId(getLoginUser().getCurComDepartment().getId()); | 
|         return ApiResponse.success(warehouseExtService.queryAllData(pageWrap)); | 
|     } | 
|   | 
|   | 
|     @ApiOperation("新增货位查询当前权限下的数据") | 
|     @PostMapping("/queryListByJurisdiction") | 
|     public ApiResponse<List<WarehouseExtListVO>> queryListByJurisdiction (@RequestBody QueryWarehouseExtDTO pageWrap) { | 
|         pageWrap.setDeleted(Constants.ZERO); | 
|         pageWrap.setRootDepartId(getLoginUser().getRootDepartment().getId()); | 
|         pageWrap.setDepartId(getLoginUser().getCurComDepartment().getId()); | 
|         return ApiResponse.success(warehouseExtService.queryListByJurisdiction(pageWrap)); | 
|     } | 
|   | 
|     @GetMapping("/upsateStatus") | 
|     @RequiresPermissions("ext:warehouselocationext:upsateStatus") | 
|     public ApiResponse upsateStatus(@RequestParam String  id,@RequestParam String status) { | 
|         Warehouse data=  warehouseService.findById(Integer.valueOf(id)); | 
|   | 
|         QueryWStockExtDTO wStock=new QueryWStockExtDTO(); | 
|         wStock.setDeleted(Constants.ZERO); | 
|         wStock.setRootDepartId(getLoginUser().getRootDepartment().getId()); | 
|         wStock.setWarehouseId(data.getId()); | 
|         wStock.setGreaterZero(Constants.ONE); | 
|        List<WStockExtListVO> list= wStockExtService.getListBynum(wStock); | 
|        if(list.size()>0){ | 
|            return ApiResponse.failed("库存的库存量大于0,不允许失效"); | 
|        } | 
|         data.setStatus(Integer.valueOf(status)); | 
|         warehouseService.updateById(data); | 
|         return ApiResponse.success(null); | 
|     } | 
|   | 
|     @GetMapping("/updateHWStatus") | 
|     @RequiresPermissions("ext:warehouselocationext:updateHWStatus") | 
|     public ApiResponse updateHWStatus(@RequestParam String  id,@RequestParam String useLocation) { | 
|         Warehouse warehouse=new Warehouse(); | 
|         warehouse.setId(Integer.valueOf(id)); | 
|         warehouse.setUseLocation(Integer.valueOf(useLocation)); | 
|        return  warehouseService.updateByCondition(warehouse); | 
|     } | 
|   | 
|   | 
|   | 
|     @ApiOperation("查询公司级组织下仓库绑定的仓位集合") | 
|     @PostMapping("/queryWareHouserAndLocaltion") | 
|     public ApiResponse<List<WarehouseExtListVO>> queryWareHouserAndLocaltion (@RequestBody QueryWarehouseExtDTO pageWrap) { | 
|         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|         pageWrap.setDeleted(Constants.ZERO); | 
|         pageWrap.setRootDepartId(user.getRootDepartment().getId()); | 
| //        if(!Constants.equalsInteger(user.getCurComDepartment().getId(),user.getRootDepartment().getId())){ | 
|             //如果当前选择的公司级组织非根组织信息,只能查看当前选择公司级组织数据 | 
|             pageWrap.setDepartId(user.getCurComDepartment().getId()); | 
| //        } | 
|         return ApiResponse.success(warehouseExtService.queryWareHouserAndLocaltion(pageWrap)); | 
|     } | 
|   | 
| } |