diff --git a/youchain-system/src/main/java/com/youchain/basicdata/rest/StockController.java b/youchain-system/src/main/java/com/youchain/basicdata/rest/StockController.java index f68174a..d33ce9c 100644 --- a/youchain-system/src/main/java/com/youchain/basicdata/rest/StockController.java +++ b/youchain-system/src/main/java/com/youchain/basicdata/rest/StockController.java @@ -1,18 +1,18 @@ /* -* 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. -*/ + * 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.poi.excel.ExcelReader; @@ -48,13 +48,14 @@ import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletResponse; import javax.transaction.Transactional; + import static org.springframework.http.HttpStatus.BAD_REQUEST; /** -* @website https://eladmin.vip -* @author liuxue -* @date 2023-07-28 -**/ + * @author liuxue + * @website https://eladmin.vip + * @date 2023-07-28 + **/ @RestController @RequiredArgsConstructor @Slf4j @@ -67,6 +68,7 @@ public class StockController { private final FileProperties properties; private final StockTypeService stockTypeService; + @Log("导出数据") @ApiOperation("导出数据") @GetMapping(value = "/download") @@ -78,7 +80,7 @@ public class StockController { @PostMapping(value = "/import_stock") @ApiOperation("容器导入") @AnonymousAccess - public ResponseEntity importStock( @RequestParam("file") MultipartFile multipartFile) { + public ResponseEntity importStock(@RequestParam("file") MultipartFile multipartFile) { FileUtil.checkSize(properties.getMaxSize(), multipartFile.getSize()); String suffix = FileUtil.getExtensionName(multipartFile.getOriginalFilename()); String type = FileUtil.getFileType(suffix); @@ -87,53 +89,53 @@ public class StockController { log.error("--" + file.getPath()); //代码、库区 ExcelReader reader = ExcelUtil.getReader(file); - int i=0; - int edit_len=0; - int new_len=0; - try{ + int i = 0; + int edit_len = 0; + int new_len = 0; + try { List> readAll = reader.readAll(); - for ( i = 0; i < readAll.size(); i++) { - int j=0; - String code=readAll.get(i).get("代码").toString().trim(); - String stockTypeCode=readAll.get(i).get("类型").toString().trim(); - StockType st=stockTypeService.findByCode(stockTypeCode); - if(code==null || code.length()<=0){ + for (i = 0; i < readAll.size(); i++) { + int j = 0; + String code = readAll.get(i).get("代码").toString().trim(); + String stockTypeCode = readAll.get(i).get("类型").toString().trim(); + StockType st = stockTypeService.findByCode(stockTypeCode); + if (code == null || code.length() <= 0) { break; } - if(st==null){ - ApiError apiError = ApiError.errorJosn(BAD_REQUEST.value(),"找不到容器类型"+stockTypeCode); + if (st == null) { + ApiError apiError = ApiError.errorJosn(BAD_REQUEST.value(), "找不到容器类型" + stockTypeCode); return new ResponseEntity(apiError, HttpStatus.valueOf(apiError.getStatus())); } - Stock stock=stockService.findByCode(code,null); - if(stock==null){ - stock=new Stock(); + Stock stock = stockService.findByCode(code, null); + if (stock == null) { + stock = new Stock(); stock.setCode(code); stock.setName(code); - log.error(j+++"====="); + log.error(j++ + "====="); stock.setStatus(BaseStatus.FREE); stock.setEnabled(true); new_len++; stock.setStockType(st); - log.error(j+++"====="); + log.error(j++ + "====="); stock.setDept(UserUtils.getDept()); - log.error(j+++"====="); + log.error(j++ + "====="); stockService.create(stock); - log.error(j+++"====="); - }else{ + log.error(j++ + "====="); + } else { edit_len++; } - log.error(j+++"a====="); + log.error(j++ + "a====="); stock.setStockType(st); stockService.update(stock); - log.error(j+++"a====="); + log.error(j++ + "a====="); } - }catch (Exception e){ - ApiError apiError = ApiError.errorJosn(HttpStatus.BAD_REQUEST.value(), "导入异常---第"+(i+1)+"行:"+e.toString()); + } catch (Exception e) { + ApiError apiError = ApiError.errorJosn(HttpStatus.BAD_REQUEST.value(), "导入异常---第" + (i + 1) + "行:" + e.toString()); return new ResponseEntity(apiError, HttpStatus.valueOf(apiError.getStatus())); } - ApiError apiError = ApiError.errorJosn(HttpStatus.OK.value(), "导入成功:"+(i)+"行 新增("+new_len+")修改("+edit_len+")"); + ApiError apiError = ApiError.errorJosn(HttpStatus.OK.value(), "导入成功:" + (i) + "行 新增(" + new_len + ")修改(" + edit_len + ")"); return new ResponseEntity(apiError, HttpStatus.valueOf(apiError.getStatus())); } @@ -142,33 +144,33 @@ public class StockController { @Log("查询stock") @ApiOperation("查询stock") @PreAuthorize("@el.check('super:man')") - public ResponseEntity queryStock(StockQueryCriteria criteria, Pageable pageable){ - return new ResponseEntity<>(stockService.queryAll(criteria,pageable),HttpStatus.OK); + public ResponseEntity queryStock(StockQueryCriteria criteria, Pageable pageable) { + return new ResponseEntity<>(stockService.queryAll(criteria, pageable), HttpStatus.OK); } @Log("查询可用空闲的容器stock") @ApiOperation("查询可用空闲的容器stock") @GetMapping(value = "/queryKyStockList") @PreAuthorize("@el.check('super:man')") - public ResponseEntity queryKyStockList(StockQueryCriteria criteria, Pageable pageable){ - return new ResponseEntity<>(stockService.queryKyStockList("124"),HttpStatus.OK); + public ResponseEntity queryKyStockList(StockQueryCriteria criteria) { + return new ResponseEntity<>(stockService.queryKyStockList(criteria.getCode()), HttpStatus.OK); } @PostMapping @Log("新增stock") @ApiOperation("新增stock") @PreAuthorize("@el.check('super:man')") - public ResponseEntity createStock(@Validated @RequestBody Stock resources){ + public ResponseEntity createStock(@Validated @RequestBody Stock resources) { resources.setDept(UserUtils.getDept()); resources.setEnabled(true); - return new ResponseEntity<>(stockService.create(resources),HttpStatus.CREATED); + return new ResponseEntity<>(stockService.create(resources), HttpStatus.CREATED); } @PutMapping @Log("修改stock") @ApiOperation("修改stock") @PreAuthorize("@el.check('super:man')") - public ResponseEntity updateStock(@Validated @RequestBody Stock resources){ + public ResponseEntity updateStock(@Validated @RequestBody Stock resources) { stockService.update(resources); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @@ -177,7 +179,7 @@ public class StockController { @Log("修改stock") @ApiOperation("修改stock") @PreAuthorize("@el.check('super:man')") - public ResponseEntity updateStockOK(@Validated @RequestBody Stock resources){ + public ResponseEntity updateStockOK(@Validated @RequestBody Stock resources) { stockService.update(resources); return new ResponseEntity<>(HttpStatus.OK); } @@ -186,7 +188,7 @@ public class StockController { @Log("批量修改stock的状态") @ApiOperation("批量修改stock的状态") @PreAuthorize("@el.check('super:man')") - public ResponseEntity updateStockStatus(@Validated @RequestBody List stockList){ + public ResponseEntity updateStockStatus(@Validated @RequestBody List stockList) { for (Stock s : stockList) { stockService.update(s); } diff --git a/youchain-system/src/main/java/com/youchain/businessdata/domain/Asn.java b/youchain-system/src/main/java/com/youchain/businessdata/domain/Asn.java index cd6086f..558d020 100644 --- a/youchain-system/src/main/java/com/youchain/businessdata/domain/Asn.java +++ b/youchain-system/src/main/java/com/youchain/businessdata/domain/Asn.java @@ -51,8 +51,7 @@ public class Asn extends BaseEntity implements Serializable { private String code; @OneToOne - @JoinColumn(name = "`area_id`",nullable = false) - @NotNull + @JoinColumn(name = "`area_id`") @ApiModelProperty(value = "库区") private Area area; @@ -61,7 +60,7 @@ public class Asn extends BaseEntity implements Serializable { private String status; @Column(name = "`cus_code`") - @ApiModelProperty(value = "客户订单号") + @ApiModelProperty(value = "SAP接口号") private String cusCode; @Column(name = "`related_bill1`") @@ -106,11 +105,11 @@ public class Asn extends BaseEntity implements Serializable { private String fromTel; @Column(name = "`order_quantity`") - @ApiModelProperty(value = "订单数量") + @ApiModelProperty(value = "待收数量") private Double orderQuantity; @Column(name = "`received_quantity`") - @ApiModelProperty(value = "收货数量") + @ApiModelProperty(value = "已收数量") private Double receivedQuantity; @Column(name = "`putaway_quantity`") @@ -136,14 +135,14 @@ public class Asn extends BaseEntity implements Serializable { private String description; @Column(name = "`zl_by`") - @ApiModelProperty(value = "整理人") + @ApiModelProperty(value = "SAP收货人") private String zlBy; @Column(name = "`zl_date`") @ApiModelProperty(value = "整理日期") private Timestamp zlDate; @Column(name = "`cy_by`") - @ApiModelProperty(value = "抽样人") + @ApiModelProperty(value = "申请人") private String cyBy; @Column(name = "`cy_date`") diff --git a/youchain-system/src/main/java/com/youchain/businessdata/domain/AsnDetail.java b/youchain-system/src/main/java/com/youchain/businessdata/domain/AsnDetail.java index 45129ce..43c077f 100644 --- a/youchain-system/src/main/java/com/youchain/businessdata/domain/AsnDetail.java +++ b/youchain-system/src/main/java/com/youchain/businessdata/domain/AsnDetail.java @@ -50,7 +50,7 @@ public class AsnDetail extends BaseEntity implements Serializable { @OneToOne @JoinColumn(name = "`asn_id`") - @ApiModelProperty(value = "订单序号") + @ApiModelProperty(value = "入库单") private Asn asn; @OneToOne diff --git a/youchain-system/src/main/java/com/youchain/businessdata/rest/AsnController.java b/youchain-system/src/main/java/com/youchain/businessdata/rest/AsnController.java index 366c660..d4a9e83 100644 --- a/youchain-system/src/main/java/com/youchain/businessdata/rest/AsnController.java +++ b/youchain-system/src/main/java/com/youchain/businessdata/rest/AsnController.java @@ -25,6 +25,7 @@ import com.youchain.businessdata.repository.AsnRepository; import com.youchain.businessdata.service.AsnService; import com.youchain.businessdata.service.dto.AsnQueryCriteria; import com.youchain.exception.BadRequestException; +import com.youchain.exception.handler.ApiResult; import com.youchain.utils.BizStatus; import com.youchain.utils.CodeUtils; import com.youchain.utils.SecurityUtils; @@ -76,7 +77,7 @@ public class AsnController { @ApiOperation("查询最大单号") @AnonymousAccess public ResponseEntity maxNo(@RequestParam("code") String code) { - return new ResponseEntity<>(codeUtils.getCode_yyMMdd(code,3), HttpStatus.OK); + return new ResponseEntity<>(codeUtils.getCode_yyMMdd(code, 3), HttpStatus.OK); } @@ -89,7 +90,6 @@ public class AsnController { } - @GetMapping("/getIdByAsn") @Log("查询asn") @ApiOperation("查询asn") @@ -132,6 +132,22 @@ public class AsnController { return new ResponseEntity<>(HttpStatus.OK); } + @DeleteMapping(value = "/deleteAsnAndDetail") + @Log("删除入库单和入库明细") + @ApiOperation("删除入库单和入库明细") + @PreAuthorize("@el.check('super:man')") + public ResponseEntity deleteAsnAndDetail(@RequestBody Long[] ids) { + try { + for (Long id : ids) { + asnService.deleteAsnAndDetail(id); + } + return new ResponseEntity<>(ApiResult.success("删除成功", null), HttpStatus.OK); + } catch (Exception e) { + return new ResponseEntity<>(ApiResult.fail(HttpStatus.BAD_REQUEST.value(), e.getMessage(), null), HttpStatus.BAD_REQUEST); + } + + } + @PostMapping("/zlRegister") @Log("入库整理登记") @ApiOperation("入库整理登记") @@ -140,21 +156,21 @@ public class AsnController { @DuplicateSubmission(5) public ResponseEntity zlRegister(@RequestBody Long[] ids) { for (Long id : ids) { - Asn asn=asnService.getEntity(id); - BillType bt=asn.getBillType(); - if(bt.getBezl()){ - if(!asn.getStatus().equals(BizStatus.OPEN)){ - throw new BadRequestException(asn.getCode()+"状态不正确,打开状态才能操作"); + Asn asn = asnService.getEntity(id); + BillType bt = asn.getBillType(); + if (bt.getBezl()) { + if (!asn.getStatus().equals(BizStatus.OPEN)) { + throw new BadRequestException(asn.getCode() + "状态不正确,打开状态才能操作"); } asn.setZlBy(SecurityUtils.getCurrentUsername()); asn.setZlDate(new Timestamp(new Date().getTime())); asn.setStatus(BizStatus.ZL); asnService.update(asn); - }else{ - throw new BadRequestException(asn.getCode()+"不需要整理"); + } else { + throw new BadRequestException(asn.getCode() + "不需要整理"); } } - return new ResponseEntity<>("操作成功",HttpStatus.OK); + return new ResponseEntity<>("操作成功", HttpStatus.OK); } @PostMapping("/cyRegister") @@ -165,25 +181,26 @@ public class AsnController { @DuplicateSubmission(5) public ResponseEntity cyRegister(@RequestBody Long[] ids) { for (Long id : ids) { - Asn asn=asnService.getEntity(id); - BillType bt=asn.getBillType(); - if(bt.getBezl()&&asn.getZlBy()==null){ - throw new BadRequestException(asn.getCode()+"该单子还未整理,请先整理"); + Asn asn = asnService.getEntity(id); + BillType bt = asn.getBillType(); + if (bt.getBezl() && asn.getZlBy() == null) { + throw new BadRequestException(asn.getCode() + "该单子还未整理,请先整理"); } - if(bt.getBecy()){ - if(!asn.getStatus().equals(BizStatus.OPEN)&&!asn.getStatus().equals(BizStatus.ZL)){ - throw new BadRequestException(asn.getCode()+"状态不正确,打开或整理状态才能操作"); + if (bt.getBecy()) { + if (!asn.getStatus().equals(BizStatus.OPEN) && !asn.getStatus().equals(BizStatus.ZL)) { + throw new BadRequestException(asn.getCode() + "状态不正确,打开或整理状态才能操作"); } asn.setCyBy(SecurityUtils.getCurrentUsername()); asn.setCyDate(new Timestamp(new Date().getTime())); asn.setStatus(BizStatus.CY); asnService.update(asn); - }else{ - throw new BadRequestException(asn.getCode()+"不需要抽样"); + } else { + throw new BadRequestException(asn.getCode() + "不需要抽样"); } } - return new ResponseEntity<>("操作成功",HttpStatus.OK); + return new ResponseEntity<>("操作成功", HttpStatus.OK); } + @PostMapping("/zjRegister") @Log("入库质检登记") @ApiOperation("入库质检登记") @@ -192,26 +209,26 @@ public class AsnController { @DuplicateSubmission(5) public ResponseEntity zjRegister(@RequestBody Long[] ids) { for (Long id : ids) { - Asn asn=asnService.getEntity(id); - BillType bt=asn.getBillType(); - if(bt.getBezl()&&asn.getZlBy()==null){ - throw new BadRequestException(asn.getCode()+"该单子还未整理,请先整理"); + Asn asn = asnService.getEntity(id); + BillType bt = asn.getBillType(); + if (bt.getBezl() && asn.getZlBy() == null) { + throw new BadRequestException(asn.getCode() + "该单子还未整理,请先整理"); } - if(bt.getBecy()&&asn.getCyBy()==null){ - throw new BadRequestException(asn.getCode()+"该单子还未抽样,请先抽样"); + if (bt.getBecy() && asn.getCyBy() == null) { + throw new BadRequestException(asn.getCode() + "该单子还未抽样,请先抽样"); } - if(bt.getBezj()){ - if(!asn.getStatus().equals(BizStatus.OPEN)&&!asn.getStatus().equals(BizStatus.ZL)&&!asn.getStatus().equals(BizStatus.CY)){ - throw new BadRequestException(asn.getCode()+"状态不正确,打开或整理或抽样状态才能操作"); + if (bt.getBezj()) { + if (!asn.getStatus().equals(BizStatus.OPEN) && !asn.getStatus().equals(BizStatus.ZL) && !asn.getStatus().equals(BizStatus.CY)) { + throw new BadRequestException(asn.getCode() + "状态不正确,打开或整理或抽样状态才能操作"); } asn.setZjBy(SecurityUtils.getCurrentUsername()); asn.setZjDate(new Timestamp(new Date().getTime())); asn.setStatus(BizStatus.ZJ); asnService.update(asn); - }else{ - throw new BadRequestException(asn.getCode()+"不需要质检"); + } else { + throw new BadRequestException(asn.getCode() + "不需要质检"); } } - return new ResponseEntity<>("操作成功",HttpStatus.OK); + return new ResponseEntity<>("操作成功", HttpStatus.OK); } -} \ No newline at end of file +} diff --git a/youchain-system/src/main/java/com/youchain/businessdata/rest/AsnDetailController.java b/youchain-system/src/main/java/com/youchain/businessdata/rest/AsnDetailController.java index fc2b388..7420d14 100644 --- a/youchain-system/src/main/java/com/youchain/businessdata/rest/AsnDetailController.java +++ b/youchain-system/src/main/java/com/youchain/businessdata/rest/AsnDetailController.java @@ -149,9 +149,6 @@ public class AsnDetailController { @ApiOperation("新增asn_detail") @PreAuthorize("@el.check('super:man')") public ResponseEntity createAsnDetail(@Validated @RequestBody AsnDetail asnDetail) { - if(asnDetail.getAsn()==null){ - return new ResponseEntity<>(ApiResult.fail(HttpStatus.BAD_REQUEST.value(), "请先提交入库单!", null),HttpStatus.BAD_REQUEST); - } asnDetail.setStatus(BizStatus.OPEN); asnDetail.setDept(UserUtils.getDept()); if (asnDetail.getRemark() == null && asnDetail.getAsn().getDescription() != null) { diff --git a/youchain-system/src/main/java/com/youchain/businessdata/service/AsnService.java b/youchain-system/src/main/java/com/youchain/businessdata/service/AsnService.java index 01d4314..94f312b 100644 --- a/youchain-system/src/main/java/com/youchain/businessdata/service/AsnService.java +++ b/youchain-system/src/main/java/com/youchain/businessdata/service/AsnService.java @@ -82,4 +82,10 @@ public interface AsnService { * @throws Exception / */ void download(List all, HttpServletResponse response) throws Exception, Exception; -} \ No newline at end of file + + /** + * 删除asn和asnDetail + * @param id + */ + void deleteAsnAndDetail(Long id); +} diff --git a/youchain-system/src/main/java/com/youchain/businessdata/service/impl/AsnServiceImpl.java b/youchain-system/src/main/java/com/youchain/businessdata/service/impl/AsnServiceImpl.java index 41186d3..0208772 100644 --- a/youchain-system/src/main/java/com/youchain/businessdata/service/impl/AsnServiceImpl.java +++ b/youchain-system/src/main/java/com/youchain/businessdata/service/impl/AsnServiceImpl.java @@ -19,6 +19,7 @@ import com.youchain.businessdata.domain.Asn; import com.youchain.businessdata.domain.AsnDetail; import com.youchain.businessdata.repository.AsnDetailRepository; import com.youchain.businessdata.service.AsnDetailService; +import com.youchain.exception.BadRequestException; import com.youchain.utils.*; import lombok.RequiredArgsConstructor; import com.youchain.businessdata.repository.AsnRepository; @@ -147,4 +148,18 @@ public class AsnServiceImpl implements AsnService { } FileUtil.downloadExcel(list, response); } -} \ No newline at end of file + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteAsnAndDetail(Long id) { + Asn asn = asnRepository.findById(id).get(); + if (!BizStatus.OPEN.equals(asn.getStatus())) { + throw new BadRequestException("该单据状态不允许删除"); + } + List asnDetails = asnDetailRepository.queryByAsnId(id); + for (AsnDetail asnDetail : asnDetails) { + asnDetailRepository.delete(asnDetail); + } + asnRepository.delete(asn); + } +}