246 lines
10 KiB
Java
246 lines
10 KiB
Java
/*
|
|
* 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.JSONArray;
|
|
import cn.hutool.json.JSONUtil;
|
|
import com.youchain.annotation.AnonymousAccess;
|
|
import com.youchain.annotation.Log;
|
|
import com.youchain.basicdata.domain.BigItem;
|
|
import com.youchain.basicdata.domain.BomAccount;
|
|
import com.youchain.basicdata.domain.Item;
|
|
import com.youchain.basicdata.domain.Point;
|
|
import com.youchain.basicdata.repository.BomAccountRepository;
|
|
import com.youchain.basicdata.repository.PointRepository;
|
|
import com.youchain.basicdata.repository.TableConfigRepository;
|
|
import com.youchain.basicdata.service.BomAccountLogService;
|
|
import com.youchain.basicdata.service.BomAccountService;
|
|
import com.youchain.basicdata.service.PointService;
|
|
import com.youchain.basicdata.service.dto.*;
|
|
import com.youchain.basicdata.service.impl.TableConfigServiceImpl;
|
|
import com.youchain.basicdata.service.mapstruct.BomAccountMapper;
|
|
import com.youchain.businessdata.returnJson.BomPrint;
|
|
import com.youchain.businessdata.returnJson.BomPrint_BiaoQian;
|
|
import com.youchain.businessdata.returnJson.BomPrint_BiaoQian2;
|
|
import com.youchain.utils.BaseStatus;
|
|
import com.youchain.utils.RedisUtils;
|
|
import com.youchain.utils.SecurityUtils;
|
|
import com.youchain.utils.SpringContextHolder;
|
|
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 java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
/**
|
|
* @website https://eladmin.vip
|
|
* @author baobinglin
|
|
* @date 2024-01-02
|
|
**/
|
|
@Slf4j
|
|
@RestController
|
|
@RequiredArgsConstructor
|
|
@Api(tags = "bomAccount管理")
|
|
@RequestMapping("/api/bomAccount")
|
|
public class BomAccountController {
|
|
|
|
private final BomAccountService bomAccountService;
|
|
private final BomAccountLogService bomAccountLogService;
|
|
private final BomAccountMapper bomAccountMapper;
|
|
private final PointRepository pointRepository;
|
|
private final PointService pointService;
|
|
private final BomAccountRepository bomAccountRepository;
|
|
|
|
@Log("导出数据")
|
|
@ApiOperation("导出数据")
|
|
@GetMapping(value = "/download")
|
|
@AnonymousAccess
|
|
public void exportBomAccount(HttpServletResponse response, BomAccountQueryCriteria criteria) throws Exception {
|
|
bomAccountService.download(bomAccountService.queryAll(criteria), response);
|
|
}
|
|
|
|
@GetMapping
|
|
@Log("查询bomAccount")
|
|
@ApiOperation("查询bomAccount")
|
|
@AnonymousAccess
|
|
public ResponseEntity<Object> queryBomAccount(BomAccountQueryCriteria criteria, Pageable pageable){
|
|
return new ResponseEntity<>(bomAccountService.queryAll(criteria,pageable),HttpStatus.OK);
|
|
}
|
|
|
|
@GetMapping("/queryBomAccountList")
|
|
@Log("查询bomAccount全部")
|
|
@ApiOperation("查询bomAccount全部")
|
|
@AnonymousAccess
|
|
public ResponseEntity<Object> queryBomAccountList(BomAccountQueryCriteria criteria){
|
|
return new ResponseEntity<>(bomAccountService.queryAll(criteria),HttpStatus.OK);
|
|
}
|
|
|
|
|
|
@GetMapping("/queryBomPrintList")
|
|
@Log("查询bom打印标签")
|
|
@ApiOperation("查询bom打印标签")
|
|
@AnonymousAccess
|
|
public ResponseEntity<Object> queryBomPrintList(BomAccountQueryCriteria criteria){
|
|
RedisUtils redisUtils = SpringContextHolder.getBean(RedisUtils.class);
|
|
redisUtils.del(SecurityUtils.getCurrentUsername()+"_BiaoQian");
|
|
List<BomPrint> list=bomAccountService.queryPrintAll(criteria);
|
|
boolean isok=redisUtils.set(SecurityUtils.getCurrentUsername()+"_BiaoQian", JsonUtil.toJson(list));
|
|
log.info(SecurityUtils.getCurrentUsername()+"_BiaoQian"+"-----isok:"+isok);
|
|
String json=(String)redisUtils.get(SecurityUtils.getCurrentUsername()+"_BiaoQian");
|
|
log.info(SecurityUtils.getCurrentUsername()+"_BiaoQian"+"-----"+json);
|
|
|
|
|
|
List<BomPrint_BiaoQian2> list2= JSONUtil.toList(json, BomPrint_BiaoQian2.class);
|
|
for(BomPrint_BiaoQian2 l:list2){
|
|
log.info(l.getNs());
|
|
}
|
|
|
|
return new ResponseEntity<>(list,HttpStatus.OK);
|
|
}
|
|
|
|
@GetMapping("/bomPrintBiaoQianList")
|
|
@Log("获取Bom中库位标签")
|
|
@ApiOperation("获取Bom中库位标签")
|
|
@AnonymousAccess
|
|
public ResponseEntity<Object> bomPrintBiaoQianList(){
|
|
log.info(SecurityUtils.getCurrentUsername()+"_BiaoQian");
|
|
RedisUtils redisUtils = SpringContextHolder.getBean(RedisUtils.class);
|
|
|
|
String json=(String)redisUtils.get(SecurityUtils.getCurrentUsername()+"_BiaoQian");
|
|
log.info(SecurityUtils.getCurrentUsername()+"_BiaoQian"+"-----"+json);
|
|
|
|
|
|
List<BomPrint_BiaoQian2> list= JSONUtil.toList(json, BomPrint_BiaoQian2.class);
|
|
|
|
List<BomPrint_BiaoQian> list2=new ArrayList<>();
|
|
for(BomPrint_BiaoQian2 l:list){
|
|
BomPrint_BiaoQian bq=new BomPrint_BiaoQian();
|
|
bq.setNs(l.getNs());
|
|
bq.setHw(l.getHw());
|
|
bq.setPm(l.getPm());
|
|
bq.setEwm(l.getEwm());
|
|
bq.setBonded(l.getBonded());
|
|
bq.setSrs(l.getSrs());
|
|
bq.setSupplier(l.getSupplier());
|
|
bq.setJxs(l.getJxs()==null?null:l.getJxs().split(","));
|
|
bq.setTyls(l.getTyls()==null?null:l.getTyls().split(","));
|
|
list2.add(bq);
|
|
}
|
|
return new ResponseEntity<>( list2,HttpStatus.OK);
|
|
}
|
|
|
|
|
|
@GetMapping(value = "/queryBigItemByStationType/{stationType}")
|
|
@Log("根据工位查询bomAccount")
|
|
@ApiOperation("根据工位查询bomAccount")
|
|
@AnonymousAccess
|
|
public ResponseEntity<Object> queryBomAccountByStationType(@PathVariable("stationType") String stationType){
|
|
List<BigItem> bigItems = bomAccountService.queryBigItemByType(stationType);
|
|
return new ResponseEntity<>(bigItems,HttpStatus.OK);
|
|
}
|
|
|
|
@GetMapping(value = "/queryItemByArea/{areaId}")
|
|
@Log("根据库区查询bomAccount品番")
|
|
@ApiOperation("根据库区查询bomAccount品番")
|
|
@AnonymousAccess
|
|
public ResponseEntity<Object> queryItemByArea(@PathVariable("areaId") Long areaId){
|
|
List<BomAccountDto> boms=bomAccountService.queryByArea(areaId);
|
|
return new ResponseEntity<>(boms,HttpStatus.OK);
|
|
}
|
|
|
|
@GetMapping(value = "/queryBomAccountPoints")
|
|
@Log("查询bomAccount品番库位")
|
|
@ApiOperation("查询bomAccount品番库位")
|
|
@AnonymousAccess
|
|
public ResponseEntity<Object> queryBomAccountPoints(){
|
|
List<BomAccountPointDto> boms=bomAccountService.queryBomAccountPoints();
|
|
return new ResponseEntity<>(boms,HttpStatus.OK);
|
|
}
|
|
|
|
@PostMapping
|
|
@Log("新增bomAccount")
|
|
@ApiOperation("新增bomAccount")
|
|
@PreAuthorize("@el.check('super:man')")
|
|
public ResponseEntity<Object> createBomAccount(@Validated @RequestBody BomAccount resources){
|
|
// if(resources.getHPoint().getCode()==null){
|
|
// resources.setHPoint(null);
|
|
// }else{
|
|
// Point point=pointRepository.findByCode(resources.getHPoint().getCode());
|
|
// if (point == null) {
|
|
// point = pointService.createPoint(resources.getHPoint().getCode(), "ZCKW", resources.getRArea(),null);
|
|
// }
|
|
// resources.setHPoint(point);
|
|
// }
|
|
if(resources.getZPoint().getCode()==null){
|
|
resources.setZPoint(null);
|
|
}else{
|
|
Point point=pointRepository.findByCode(resources.getZPoint().getCode());
|
|
if (point == null) {
|
|
point = pointService.createPoint(resources.getZPoint().getCode(), BaseStatus.HCKW, resources.getRArea());
|
|
}
|
|
resources.setZPoint(point);
|
|
}
|
|
BomAccountDto bomAccountDto=bomAccountService.create(resources);
|
|
bomAccountLogService.copyBomAccount(bomAccountDto.getId(),"add");
|
|
return new ResponseEntity<>(bomAccountDto,HttpStatus.CREATED);
|
|
}
|
|
|
|
@PutMapping
|
|
@Log("修改bomAccount")
|
|
@ApiOperation("修改bomAccount")
|
|
@PreAuthorize("@el.check('super:man')")
|
|
public ResponseEntity<Object> updateBomAccount(@Validated @RequestBody BomAccount resources){
|
|
// if(resources.getHPoint().getCode()==null){
|
|
// resources.setHPoint(null);
|
|
// }else{
|
|
// Point point=pointRepository.findByCode(resources.getHPoint().getCode());
|
|
// if (point == null) {
|
|
// point = pointService.createPoint(resources.getHPoint().getCode(), "ZCKW", resources.getRArea(),null);
|
|
// }
|
|
// resources.setHPoint(point);
|
|
// }
|
|
if(resources.getZPoint().getCode()==null){
|
|
resources.setZPoint(null);
|
|
}else{
|
|
Point point=pointRepository.findByCode(resources.getZPoint().getCode());
|
|
if (point == null) {
|
|
point = pointService.createPoint(resources.getZPoint().getCode(), BaseStatus.HCKW, resources.getRArea());
|
|
}
|
|
resources.setZPoint(point);
|
|
}
|
|
bomAccountService.update(resources);
|
|
bomAccountLogService.copyBomAccount(resources.getId(),"update");
|
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
|
}
|
|
|
|
@DeleteMapping
|
|
@Log("删除bomAccount")
|
|
@ApiOperation("删除bomAccount")
|
|
@PreAuthorize("@el.check('super:man')")
|
|
public ResponseEntity<Object> deleteBomAccount(@RequestBody Long[] ids) {
|
|
bomAccountService.deleteAll(ids);
|
|
return new ResponseEntity<>(HttpStatus.OK);
|
|
}
|
|
} |