Merge remote-tracking branch 'origin/master' into dev

This commit is contained in:
韩鹏辉 2024-07-06 17:39:04 +08:00
commit cfee6f4b43
8 changed files with 424 additions and 0 deletions

View File

@ -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));
}
}

View File

@ -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<TbConCheck, Integer>, JpaSpecificationExecutor<TbConCheck> {
}

View File

@ -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<Object> queryTbConCheck(TbConCheckQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(tbConCheckService.queryAll(criteria,pageable),HttpStatus.OK);
}
@PostMapping
@Log("新增盘点耗材")
@ApiOperation("新增盘点耗材")
public ResponseEntity<Object> createTbConCheck(@Validated @RequestBody TbConCheck resources) throws Exception {
return new ResponseEntity<>(tbConCheckService.create(resources),HttpStatus.CREATED);
}
@PutMapping
@Log("修改盘点耗材")
@ApiOperation("修改盘点耗材")
public ResponseEntity<Object> updateTbConCheck(@Validated @RequestBody TbConCheck resources){
tbConCheckService.update(resources);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@DeleteMapping
@Log("删除盘点耗材")
@ApiOperation("删除盘点耗材")
public ResponseEntity<Object> deleteTbConCheck(@RequestBody Integer[] ids) {
tbConCheckService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
}

View File

@ -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<String,Object>
*/
Map<String,Object> queryAll(TbConCheckQueryCriteria criteria, Pageable pageable);
/**
* 查询所有数据不分页
* @param criteria 条件参数
* @return List<TbConCheckDto>
*/
List<TbConCheckDto> 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<TbConCheckDto> all, HttpServletResponse response) throws IOException;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<String,Object> queryAll(TbConCheckQueryCriteria criteria, Pageable pageable){
Page<TbConCheck> page = tbConCheckRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(tbConCheckMapper::toDto));
}
@Override
public List<TbConCheckDto> 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<TbConCheckDto> all, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (TbConCheckDto tbConCheck : all) {
Map<String,Object> 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);
}
}

View File

@ -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<TbConCheckDto, TbConCheck> {
}