diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/domain/TbConCheck.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/domain/TbConCheck.java new file mode 100644 index 00000000..2ce2ea3d --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/domain/TbConCheck.java @@ -0,0 +1,78 @@ +/* +* 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 cn.ysk.cashier.cons.domain; + +import lombok.Data; +import cn.hutool.core.bean.BeanUtil; +import io.swagger.annotations.ApiModelProperty; +import cn.hutool.core.bean.copier.CopyOptions; +import javax.persistence.*; +import javax.validation.constraints.*; +import java.sql.Timestamp; +import java.math.BigDecimal; +import java.io.Serializable; + +/** +* @author admin +* @date 2024-07-06 +**/ +@Entity +@Data +@Table(name="tb_con_check") +public class TbConCheck implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "`id`") + @ApiModelProperty(value = "id") + private Integer id; + + @Column(name = "`con_info_id`") + @ApiModelProperty(value = "conInfoId") + private Integer conInfoId; + + @Column(name = "`con_name`") + @ApiModelProperty(value = "conName") + private String conName; + + @Column(name = "`price`") + @ApiModelProperty(value = "price") + private BigDecimal price; + + @Column(name = "`stock_number`") + @ApiModelProperty(value = "stockNumber") + private BigDecimal stockNumber; + + @Column(name = "`lp_num`") + @ApiModelProperty(value = "lpNum") + private BigDecimal lpNum; + + @Column(name = "`lp_amount`") + @ApiModelProperty(value = "lpAmount") + private BigDecimal lpAmount; + + @Column(name = "`ac_stock_number`") + @ApiModelProperty(value = "acStockNumber") + private BigDecimal acStockNumber; + + @Column(name = "`create_time`") + @ApiModelProperty(value = "createTime") + private Timestamp createTime; + + public void copy(TbConCheck source){ + BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); + } +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/repository/TbConCheckRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/repository/TbConCheckRepository.java new file mode 100644 index 00000000..e97539b1 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/repository/TbConCheckRepository.java @@ -0,0 +1,13 @@ +package cn.ysk.cashier.cons.repository; + +import cn.ysk.cashier.cons.domain.TbConCheck; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +/** +* @website https://eladmin.vip +* @author admin +* @date 2024-07-06 +**/ +public interface TbConCheckRepository extends JpaRepository, JpaSpecificationExecutor { +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/rest/TbConCheckController.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/rest/TbConCheckController.java new file mode 100644 index 00000000..106bc4a4 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/rest/TbConCheckController.java @@ -0,0 +1,65 @@ +package cn.ysk.cashier.cons.rest; + +import cn.ysk.cashier.annotation.Log; +import cn.ysk.cashier.cons.domain.TbConCheck; +import cn.ysk.cashier.cons.service.TbConCheckService; +import cn.ysk.cashier.cons.service.dto.TbConCheckQueryCriteria; +import org.springframework.data.domain.Pageable; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import io.swagger.annotations.*; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; + +/** +* @author admin +* @date 2024-07-06 +**/ +@RestController +@RequiredArgsConstructor +@Api(tags = "盘点耗材管理") +@RequestMapping("/api/tbConCheck") +public class TbConCheckController { + + private final TbConCheckService tbConCheckService; + + @Log("导出数据") + @ApiOperation("导出数据") + @GetMapping(value = "/download") + public void exportTbConCheck(HttpServletResponse response, TbConCheckQueryCriteria criteria) throws IOException { + tbConCheckService.download(tbConCheckService.queryAll(criteria), response); + } + + @GetMapping + @Log("查询盘点耗材") + @ApiOperation("查询盘点耗材") + public ResponseEntity queryTbConCheck(TbConCheckQueryCriteria criteria, Pageable pageable){ + return new ResponseEntity<>(tbConCheckService.queryAll(criteria,pageable),HttpStatus.OK); + } + + @PostMapping + @Log("新增盘点耗材") + @ApiOperation("新增盘点耗材") + public ResponseEntity createTbConCheck(@Validated @RequestBody TbConCheck resources) throws Exception { + return new ResponseEntity<>(tbConCheckService.create(resources),HttpStatus.CREATED); + } + + @PutMapping + @Log("修改盘点耗材") + @ApiOperation("修改盘点耗材") + public ResponseEntity updateTbConCheck(@Validated @RequestBody TbConCheck resources){ + tbConCheckService.update(resources); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @DeleteMapping + @Log("删除盘点耗材") + @ApiOperation("删除盘点耗材") + public ResponseEntity deleteTbConCheck(@RequestBody Integer[] ids) { + tbConCheckService.deleteAll(ids); + return new ResponseEntity<>(HttpStatus.OK); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/TbConCheckService.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/TbConCheckService.java new file mode 100644 index 00000000..536a8358 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/TbConCheckService.java @@ -0,0 +1,66 @@ +package cn.ysk.cashier.cons.service; + +import cn.ysk.cashier.cons.domain.TbConCheck; +import cn.ysk.cashier.cons.service.dto.TbConCheckDto; +import cn.ysk.cashier.cons.service.dto.TbConCheckQueryCriteria; +import org.springframework.data.domain.Pageable; +import java.util.Map; +import java.util.List; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; + +/** +* @author admin +* @date 2024-07-06 +**/ +public interface TbConCheckService { + + /** + * 查询数据分页 + * @param criteria 条件 + * @param pageable 分页参数 + * @return Map + */ + Map queryAll(TbConCheckQueryCriteria criteria, Pageable pageable); + + /** + * 查询所有数据不分页 + * @param criteria 条件参数 + * @return List + */ + List queryAll(TbConCheckQueryCriteria criteria); + + /** + * 根据ID查询 + * @param id ID + * @return TbConCheckDto + */ + TbConCheckDto findById(Integer id); + + /** + * 创建 + * @param resources / + * @return TbConCheckDto + */ + TbConCheckDto create(TbConCheck resources) throws Exception; + + /** + * 编辑 + * @param resources / + */ + void update(TbConCheck resources); + + /** + * 多选删除 + * @param ids / + */ + void deleteAll(Integer[] ids); + + /** + * 导出数据 + * @param all 待导出的数据 + * @param response / + * @throws IOException / + */ + void download(List all, HttpServletResponse response) throws IOException; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/dto/TbConCheckDto.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/dto/TbConCheckDto.java new file mode 100644 index 00000000..57db6407 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/dto/TbConCheckDto.java @@ -0,0 +1,47 @@ +/* +* 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 cn.ysk.cashier.cons.service.dto; + +import lombok.Data; +import java.sql.Timestamp; +import java.math.BigDecimal; +import java.io.Serializable; + +/** +* @author admin +* @date 2024-07-06 +**/ +@Data +public class TbConCheckDto implements Serializable { + + private Integer id; + + private Integer conInfoId; + + private String conName; + + private BigDecimal price; + + private BigDecimal stockNumber; + + private BigDecimal lpNum; + + private BigDecimal lpAmount; + + private BigDecimal acStockNumber; + + private Timestamp createTime; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/dto/TbConCheckQueryCriteria.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/dto/TbConCheckQueryCriteria.java new file mode 100644 index 00000000..74f26c62 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/dto/TbConCheckQueryCriteria.java @@ -0,0 +1,18 @@ +package cn.ysk.cashier.cons.service.dto; + +import lombok.Data; +import java.util.List; +import cn.ysk.cashier.annotation.Query; + +/** +* @author admin +* @date 2024-07-06 +**/ +@Data +public class TbConCheckQueryCriteria{ + + @Query + private Integer conInfoId; + + +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConCheckServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConCheckServiceImpl.java new file mode 100644 index 00000000..2bc9b1ad --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConCheckServiceImpl.java @@ -0,0 +1,121 @@ +package cn.ysk.cashier.cons.service.impl; + +import cn.ysk.cashier.cons.domain.TbConCheck; +import cn.ysk.cashier.cons.domain.TbConsInfo; +import cn.ysk.cashier.cons.repository.TbConsInfoRepository; +import cn.ysk.cashier.utils.FileUtil; +import cn.ysk.cashier.utils.PageUtil; +import cn.ysk.cashier.utils.QueryHelp; +import cn.ysk.cashier.utils.ValidationUtil; +import lombok.RequiredArgsConstructor; +import cn.ysk.cashier.cons.repository.TbConCheckRepository; +import cn.ysk.cashier.cons.service.TbConCheckService; +import cn.ysk.cashier.cons.service.dto.TbConCheckDto; +import cn.ysk.cashier.cons.service.dto.TbConCheckQueryCriteria; +import cn.ysk.cashier.cons.service.mapstruct.TbConCheckMapper; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +import java.math.BigDecimal; +import java.sql.Timestamp; +import java.util.*; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; + +/** +* @website https://eladmin.vip +* @description 服务实现 +* @author admin +* @date 2024-07-06 +**/ +@Service +@RequiredArgsConstructor +public class TbConCheckServiceImpl implements TbConCheckService { + + private final TbConCheckRepository tbConCheckRepository; + private final TbConCheckMapper tbConCheckMapper; + + private final TbConsInfoRepository tbConsInfoRepository; + + @Override + public Map queryAll(TbConCheckQueryCriteria criteria, Pageable pageable){ + Page page = tbConCheckRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); + return PageUtil.toPage(page.map(tbConCheckMapper::toDto)); + } + + @Override + public List queryAll(TbConCheckQueryCriteria criteria){ + return tbConCheckMapper.toDto(tbConCheckRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); + } + + @Override + @Transactional + public TbConCheckDto findById(Integer id) { + TbConCheck tbConCheck = tbConCheckRepository.findById(id).orElseGet(TbConCheck::new); + ValidationUtil.isNull(tbConCheck.getId(),"TbConCheck","id",id); + return tbConCheckMapper.toDto(tbConCheck); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public TbConCheckDto create(TbConCheck resources) throws Exception { + TbConsInfo consInfo= tbConsInfoRepository.getById(resources.getConInfoId()); + if(Objects.isNull(consInfo)){ + throw new Exception("耗材信息不存在"); + } + + BigDecimal stonum=consInfo.getStockNumber().subtract(consInfo.getStockConsume()); + + consInfo.setStockConsume(consInfo.getStockConsume().add(resources.getLpNum().negate())); + consInfo.setUpdateTime(new Timestamp(System.currentTimeMillis())); + tbConsInfoRepository.save(consInfo); + + TbConCheck conCheck=new TbConCheck(); + + conCheck.setConInfoId(consInfo.getId()); + conCheck.setConName(consInfo.getConName()); + conCheck.setPrice(consInfo.getPrice()); + conCheck.setAcStockNumber(consInfo.getStockNumber().subtract(consInfo.getStockConsume())); + conCheck.setStockNumber(stonum); + conCheck.setLpNum(resources.getLpNum()); + conCheck.setLpAmount(consInfo.getPrice().multiply(resources.getLpNum())); + conCheck.setCreateTime(new Timestamp(System.currentTimeMillis())); + return tbConCheckMapper.toDto(tbConCheckRepository.save(conCheck)); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(TbConCheck resources) { + TbConCheck tbConCheck = tbConCheckRepository.findById(resources.getId()).orElseGet(TbConCheck::new); + ValidationUtil.isNull( tbConCheck.getId(),"TbConCheck","id",resources.getId()); + tbConCheck.copy(resources); + tbConCheckRepository.save(tbConCheck); + } + + @Override + public void deleteAll(Integer[] ids) { + for (Integer id : ids) { + tbConCheckRepository.deleteById(id); + } + } + + @Override + public void download(List all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (TbConCheckDto tbConCheck : all) { + Map map = new LinkedHashMap<>(); + map.put(" conInfoId", tbConCheck.getConInfoId()); + map.put(" conName", tbConCheck.getConName()); + map.put(" price", tbConCheck.getPrice()); + map.put(" stockNumber", tbConCheck.getStockNumber()); + map.put(" lpNum", tbConCheck.getLpNum()); + map.put(" lpAmount", tbConCheck.getLpAmount()); + map.put(" acStockNumber", tbConCheck.getAcStockNumber()); + map.put(" createTime", tbConCheck.getCreateTime()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/mapstruct/TbConCheckMapper.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/mapstruct/TbConCheckMapper.java new file mode 100644 index 00000000..3c187df5 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/mapstruct/TbConCheckMapper.java @@ -0,0 +1,16 @@ +package cn.ysk.cashier.cons.service.mapstruct; + +import cn.ysk.cashier.base.BaseMapper; +import cn.ysk.cashier.cons.domain.TbConCheck; +import cn.ysk.cashier.cons.service.dto.TbConCheckDto; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** +* @author admin +* @date 2024-07-06 +**/ +@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface TbConCheckMapper extends BaseMapper { + +} \ No newline at end of file