/* * Copyright 2019-2020 Zheng Jie * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.youchain.basicdata.rest; import cn.hutool.json.JSONUtil; import cn.hutool.poi.excel.ExcelReader; import cn.hutool.poi.excel.ExcelUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.youchain.annotation.AnonymousAccess; import com.youchain.annotation.Log; import com.youchain.basicdata.domain.Area; import com.youchain.basicdata.domain.Item; import com.youchain.basicdata.domain.Point; import com.youchain.basicdata.repository.ItemRepository; import com.youchain.basicdata.repository.PointRepository; import com.youchain.basicdata.service.AreaService; import com.youchain.basicdata.service.PointService; import com.youchain.basicdata.service.dto.BomAccountQueryCriteria; import com.youchain.basicdata.service.dto.PointDto; import com.youchain.basicdata.service.dto.PointQueryCriteria; import com.youchain.businessdata.returnJson.*; import com.youchain.businessdata.service.InventoryService; import com.youchain.businessdata.service.dto.InventoryDto; import com.youchain.businessdata.service.dto.InventoryQueryCriteria; import com.youchain.config.FileProperties; import com.youchain.exception.BadRequestException; import com.youchain.exception.handler.ApiError; import com.youchain.modules.system.domain.Dept; import com.youchain.utils.*; import lombok.extern.slf4j.Slf4j; import net.dreamlu.mica.core.utils.JsonUtil; import org.springframework.data.domain.Pageable; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import io.swagger.annotations.*; import org.springframework.web.multipart.MultipartFile; import java.io.File; import java.io.IOException; import java.util.*; import java.util.stream.Collectors; import javax.servlet.http.HttpServletResponse; import static org.springframework.http.HttpStatus.BAD_REQUEST; /** * @author liuxue * @website https://eladmin.vip * @date 2023-07-26 **/ @RestController @RequiredArgsConstructor @Api(tags = "ponit管理") @Slf4j @RequestMapping("/api/point") public class PointController { private final PointService pointService; private final InventoryService inventoryService; private final AreaService areaService; private final FileProperties properties; private final ItemRepository itemRepository; private final PointRepository pointRepository; @Log("导出数据") @ApiOperation("导出数据") @GetMapping(value = "/download") @AnonymousAccess public void exportPoint(HttpServletResponse response, PointQueryCriteria criteria) throws Exception { pointService.download(pointService.queryAll(criteria), response); } @Log("导入点位") @PostMapping(value = "/import_point") @ApiOperation("导入点位") @AnonymousAccess public ResponseEntity importPoint(@RequestParam("file") MultipartFile multipartFile) { FileUtil.checkSize(properties.getMaxSize(), multipartFile.getSize()); String suffix = FileUtil.getExtensionName(multipartFile.getOriginalFilename()); String type = FileUtil.getFileType(suffix); File file = FileUtil.upload(multipartFile, properties.getPath().getPath() + type + File.separator); Dept dept = UserUtils.getDept(); //编码、描述、库区、存储类型 ExcelReader reader = ExcelUtil.getReader(file); int i = 0; List> readAll = reader.readAll(); for (i = 1; i < readAll.size(); i++) { String code = readAll.get(i).get("编码").toString().trim(); String types = readAll.get(i).get("存储类型").toString().trim(); String areaCode = readAll.get(i).get("库区").toString().trim(); String itemCode = readAll.get(i).get("品番编码") == null ? "" : readAll.get(i).get("品番编码").toString().trim(); String beatCode = readAll.get(i).get("纳所") == null ? "" : readAll.get(i).get("纳所").toString().trim(); String ccTYPE = readAll.get(i).get("标签类型") == null ? "" : readAll.get(i).get("标签类型").toString().trim(); Area area = areaService.findByCode(areaCode); if (area == null) { throw new BadRequestException(areaCode+"库区不存在"); } Point point = pointService.getPoint(code, null, null, null); Boolean isNew=Boolean.FALSE; if (point == null) { point = new Point(); point.setCode(code); point.setDept(dept); point.setEnabled(true); point.setStatus(BaseStatus.FREE); point.setName(code); isNew=Boolean.TRUE; } String lx = ""; if (types.equals("材管库位")) { lx = BaseStatus.CH; } else if (types.equals("制造库位")) { lx = BaseStatus.ZZKW; }else if (types.equals("缓存库位")) { lx = BaseStatus.HCKW; } point.setType(lx); point.setArea(area); point.setDescription(ccTYPE); point.setItemCode(itemCode); point.setBeatCode(beatCode); if(isNew){ pointService.create(point); }else { pointService.update(point); } } return new ResponseEntity("导入成功", HttpStatus.OK); } @GetMapping @Log("查询point") @ApiOperation("查询point") @AnonymousAccess public ResponseEntity queryPoint(PointQueryCriteria criteria, Pageable pageable) { return new ResponseEntity<>(pointService.queryAll(criteria, pageable), HttpStatus.OK); } @PostMapping("/getPoints") @Log("加载point下拉框") @ApiOperation("加载point下拉框") @AnonymousAccess public ResponseEntity getPointList(@RequestBody(required = false) String type) { return new ResponseEntity<>(pointService.getPointList(type), HttpStatus.OK); } @GetMapping(value = "/queryPointList") @Log("下拉查询点位") @ApiOperation("下拉查询点位") @AnonymousAccess public ResponseEntity queryPointList(PointQueryCriteria criteria) { return new ResponseEntity<>(pointService.queryAll(criteria), HttpStatus.OK); } @GetMapping(value = "/getOutPointAll") @Log("获取出库点位") @ApiOperation("获取出库点位") @AnonymousAccess public ResponseEntity getOutPointAll(PointQueryCriteria criteria) { InventoryQueryCriteria inventoryQueryCriteria = new InventoryQueryCriteria(); if (criteria.getAreaName() != null) { List items = itemRepository.quryOneItemAll(); List itemCode = new ArrayList<>(); for (Item item : items) { itemCode.add(item.getCode()); } inventoryQueryCriteria.setItemCode(itemCode); inventoryQueryCriteria.setAreaName(criteria.getAreaName()); List inventoryDtos = inventoryService.queryAll(inventoryQueryCriteria); List collect = inventoryDtos.stream().map(InventoryDto::getPoint).collect(Collectors.toList()); return new ResponseEntity<>(collect, HttpStatus.OK); } return new ResponseEntity<>(null, HttpStatus.OK); } @GetMapping(value = "/queryKyPointList") @Log("查询可用空闲的点位point") @ApiOperation("查询可用空闲的点位point") @AnonymousAccess public ResponseEntity queryKyPointList(PointQueryCriteria criteria, Pageable pageable) { return new ResponseEntity<>(pointService.queryKyPointList(), HttpStatus.OK); } @PostMapping @Log("新增point") @ApiOperation("新增point") @PreAuthorize("@el.check('super:man')") public ResponseEntity createPoint(@Validated @RequestBody Point resources) { resources.setDept(UserUtils.getDept()); return new ResponseEntity<>(pointService.create(resources), HttpStatus.CREATED); } @PutMapping @Log("修改point") @ApiOperation("修改point") @PreAuthorize("@el.check('super:man')") public ResponseEntity updatePoint(@Validated @RequestBody Point resources) { // if (!Objects.isNull(resources.getPoint())){ // if (resources.getPoint().getId() == null){ // resources.setPoint(null); // } // } pointService.update(resources); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @PutMapping("/updatePoint") @Log("修改point") @ApiOperation("修改point") @PreAuthorize("@el.check('super:man')") public ResponseEntity updatePointOK(@Validated @RequestBody Point resources) { pointService.update(resources); return new ResponseEntity<>(HttpStatus.OK); } @DeleteMapping @Log("删除point") @ApiOperation("删除point") @PreAuthorize("@el.check('super:man')") public ResponseEntity deletePoint(@RequestBody Long[] ids) { pointService.deleteAll(ids); return new ResponseEntity<>(HttpStatus.OK); } @PostMapping("/queryPoint") @Log("光电点位状态查询") @ApiOperation("光电点位状态查询") @AnonymousAccess public ResponseEntity queryPoint(@RequestBody String json) { JSONObject jsonObject = JSON.parseObject(json); String pointCode = jsonObject.getString("pointCode") == null ? "" : jsonObject.getString("pointCode");//输送线、光电编号 pointService.queryPoint(pointCode); return new ResponseEntity<>(HttpStatus.OK); } @GetMapping("/queryPointPrintList") @Log("查询自由货位标签") @ApiOperation("查询自由货位标签") @AnonymousAccess public ResponseEntity queryPointPrintList(PointQueryCriteria criteria){ RedisUtils redisUtils = SpringContextHolder.getBean(RedisUtils.class); redisUtils.del(SecurityUtils.getCurrentUsername()+"_BiaoQian_ZY"); List list=pointRepository.queryPrintAll(criteria.getAreaName()); redisUtils.set(SecurityUtils.getCurrentUsername()+"_BiaoQian_ZY", JsonUtil.toJson(list)); return new ResponseEntity<>(list,HttpStatus.OK); } @GetMapping("/pointPrintBiaoQianList/{type}") @Log("获取Point中库位标签") @ApiOperation("获取Point中库位标签") @AnonymousAccess public ResponseEntity pointPrintBiaoQianList(@PathVariable("type") String type){ RedisUtils redisUtils = SpringContextHolder.getBean(RedisUtils.class); String json=(String)redisUtils.get(SecurityUtils.getCurrentUsername()+type); log.info(SecurityUtils.getCurrentUsername()+type+"-----"+json); List list= JSONUtil.toList(json, PointPrint_BiaoQian_Zy.class); List list2=new ArrayList<>(); for(PointPrint_BiaoQian_Zy zy:list){ zy.setEwm(zy.getCode()); zy.setCode(zy.getCode().substring(0,3)+"-"+zy.getCode().substring(3)); list2.add(zy); } return new ResponseEntity<>( list2,HttpStatus.OK); } }