kcw-wx-java/youchain-system/src/main/java/com/youchain/basicdata/rest/PointController.java

292 lines
12 KiB
Java
Raw Normal View History

2025-07-25 11:22:48 +08:00
/*
* 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;
2025-08-21 15:51:29 +08:00
import cn.hutool.json.JSONUtil;
2025-07-25 11:22:48 +08:00
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;
2025-08-21 15:51:29 +08:00
import com.youchain.basicdata.repository.PointRepository;
2025-07-25 11:22:48 +08:00
import com.youchain.basicdata.service.AreaService;
import com.youchain.basicdata.service.PointService;
2025-08-21 15:51:29 +08:00
import com.youchain.basicdata.service.dto.BomAccountQueryCriteria;
2025-07-25 11:22:48 +08:00
import com.youchain.basicdata.service.dto.PointDto;
import com.youchain.basicdata.service.dto.PointQueryCriteria;
2025-08-21 15:51:29 +08:00
import com.youchain.businessdata.returnJson.*;
2025-07-25 11:22:48 +08:00
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;
2025-08-11 18:03:26 +08:00
import com.youchain.exception.BadRequestException;
2025-07-25 11:22:48 +08:00
import com.youchain.exception.handler.ApiError;
import com.youchain.modules.system.domain.Dept;
2025-08-21 15:51:29 +08:00
import com.youchain.utils.*;
2025-07-25 11:22:48 +08:00
import lombok.extern.slf4j.Slf4j;
2025-08-21 15:51:29 +08:00
import net.dreamlu.mica.core.utils.JsonUtil;
2025-07-25 11:22:48 +08:00
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;
2025-08-21 15:51:29 +08:00
import java.util.*;
2025-07-25 11:22:48 +08:00
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;
2025-08-21 15:51:29 +08:00
private final InventoryService inventoryService;
2025-07-25 11:22:48 +08:00
private final AreaService areaService;
private final FileProperties properties;
private final ItemRepository itemRepository;
2025-08-21 15:51:29 +08:00
private final PointRepository pointRepository;
2025-07-25 11:22:48 +08:00
@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<Object> 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<Map<String, Object>> readAll = reader.readAll();
2025-08-29 18:01:11 +08:00
for (i = 1; i < readAll.size(); i++) {
2025-07-25 11:22:48 +08:00
String code = readAll.get(i).get("编码").toString().trim();
String types = readAll.get(i).get("存储类型").toString().trim();
String areaCode = readAll.get(i).get("库区").toString().trim();
2025-08-11 18:03:26 +08:00
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();
2025-08-29 18:01:11 +08:00
String ccTYPE = readAll.get(i).get("标签类型") == null ? "" : readAll.get(i).get("标签类型").toString().trim();
2025-07-25 11:22:48 +08:00
Area area = areaService.findByCode(areaCode);
if (area == null) {
2025-08-11 18:03:26 +08:00
throw new BadRequestException(areaCode+"库区不存在");
2025-07-25 11:22:48 +08:00
}
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 = "";
2025-08-11 18:03:26 +08:00
if (types.equals("材管库位")) {
2025-07-25 11:22:48 +08:00
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);
2025-08-11 18:03:26 +08:00
point.setItemCode(itemCode);
point.setBeatCode(beatCode);
2025-07-25 11:22:48 +08:00
if(isNew){
pointService.create(point);
}else {
pointService.update(point);
}
}
2025-08-11 18:03:26 +08:00
return new ResponseEntity("导入成功", HttpStatus.OK);
2025-07-25 11:22:48 +08:00
}
@GetMapping
@Log("查询point")
@ApiOperation("查询point")
@AnonymousAccess
public ResponseEntity<Object> queryPoint(PointQueryCriteria criteria, Pageable pageable) {
return new ResponseEntity<>(pointService.queryAll(criteria, pageable), HttpStatus.OK);
}
2025-08-29 18:01:11 +08:00
2025-07-25 11:22:48 +08:00
@PostMapping("/getPoints")
@Log("加载point下拉框")
@ApiOperation("加载point下拉框")
@AnonymousAccess
public ResponseEntity<Object> getPointList(@RequestBody(required = false) String type) {
return new ResponseEntity<>(pointService.getPointList(type), HttpStatus.OK);
}
@GetMapping(value = "/queryPointList")
@Log("下拉查询点位")
@ApiOperation("下拉查询点位")
@AnonymousAccess
public ResponseEntity<Object> queryPointList(PointQueryCriteria criteria) {
return new ResponseEntity<>(pointService.queryAll(criteria), HttpStatus.OK);
}
@GetMapping(value = "/getOutPointAll")
@Log("获取出库点位")
@ApiOperation("获取出库点位")
@AnonymousAccess
public ResponseEntity<Object> getOutPointAll(PointQueryCriteria criteria) {
InventoryQueryCriteria inventoryQueryCriteria = new InventoryQueryCriteria();
if (criteria.getAreaName() != null) {
List<Item> items = itemRepository.quryOneItemAll();
List<String> itemCode = new ArrayList<>();
for (Item item : items) {
itemCode.add(item.getCode());
}
inventoryQueryCriteria.setItemCode(itemCode);
inventoryQueryCriteria.setAreaName(criteria.getAreaName());
List<InventoryDto> inventoryDtos = inventoryService.queryAll(inventoryQueryCriteria);
List<PointDto> 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<Object> queryKyPointList(PointQueryCriteria criteria, Pageable pageable) {
return new ResponseEntity<>(pointService.queryKyPointList(), HttpStatus.OK);
}
@PostMapping
@Log("新增point")
@ApiOperation("新增point")
@PreAuthorize("@el.check('super:man')")
public ResponseEntity<Object> 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<Object> 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<Object> 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<Object> deletePoint(@RequestBody Long[] ids) {
pointService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
@PostMapping("/queryPoint")
@Log("光电点位状态查询")
@ApiOperation("光电点位状态查询")
@AnonymousAccess
public ResponseEntity<Object> 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);
}
2025-08-21 15:51:29 +08:00
@GetMapping("/queryPointPrintList")
@Log("查询自由货位标签")
@ApiOperation("查询自由货位标签")
@AnonymousAccess
public ResponseEntity<Object> queryPointPrintList(PointQueryCriteria criteria){
RedisUtils redisUtils = SpringContextHolder.getBean(RedisUtils.class);
redisUtils.del(SecurityUtils.getCurrentUsername()+"_BiaoQian_ZY");
List<PointZyPrint> 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<Object> 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<PointPrint_BiaoQian_Zy> list= JSONUtil.toList(json, PointPrint_BiaoQian_Zy.class);
List<PointPrint_BiaoQian_Zy> 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);
}
2025-07-25 11:22:48 +08:00
}