添加耗材单位
This commit is contained in:
parent
5226b1719a
commit
f8269e35a3
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* 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-12
|
||||
**/
|
||||
@Entity
|
||||
@Data
|
||||
@Table(name="tb_con_unit")
|
||||
public class TbConUnit implements Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "`id`")
|
||||
@ApiModelProperty(value = "id")
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "`name`",nullable = false)
|
||||
@NotBlank
|
||||
@ApiModelProperty(value = "单位名称")
|
||||
private String name;
|
||||
|
||||
@Column(name = "`value`",nullable = false)
|
||||
@NotNull
|
||||
@ApiModelProperty(value = "单位值")
|
||||
private BigDecimal value;
|
||||
|
||||
|
||||
@Column(name = "`parent_id`",nullable = false)
|
||||
@ApiModelProperty(value = "父级单位值")
|
||||
private Integer parentId;
|
||||
|
||||
|
||||
|
||||
@Column(name = "`is_consume`",nullable = false)
|
||||
@ApiModelProperty(value = "是否按照当前单位消耗 1 是 0 否")
|
||||
private String isConsume;
|
||||
|
||||
|
||||
@Column(name = "`status`",nullable = false)
|
||||
@NotBlank
|
||||
@ApiModelProperty(value = "状态 1 启用 0 禁用")
|
||||
private String status;
|
||||
|
||||
@Column(name = "`create_time`",nullable = false)
|
||||
@NotNull
|
||||
@ApiModelProperty(value = "createTime")
|
||||
private Timestamp createTime;
|
||||
|
||||
@Column(name = "`update_time`")
|
||||
@ApiModelProperty(value = "updateTime")
|
||||
private Timestamp updateTime;
|
||||
|
||||
public void copy(TbConUnit source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package cn.ysk.cashier.cons.repository;
|
||||
|
||||
import cn.ysk.cashier.cons.domain.TbConUnit;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
* @author admin
|
||||
* @date 2024-07-12
|
||||
**/
|
||||
public interface TbConUnitRepository extends JpaRepository<TbConUnit, Integer>, JpaSpecificationExecutor<TbConUnit> {
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
package cn.ysk.cashier.cons.rest;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.ysk.cashier.annotation.Log;
|
||||
import cn.ysk.cashier.cons.domain.TbConUnit;
|
||||
import cn.ysk.cashier.cons.service.TbConUnitService;
|
||||
import cn.ysk.cashier.cons.service.dto.TbConUnitQueryCriteria;
|
||||
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 java.sql.Timestamp;
|
||||
import java.util.Objects;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* @date 2024-07-12
|
||||
**/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "耗材单位添加管理")
|
||||
@RequestMapping("/api/tbConUnit")
|
||||
public class TbConUnitController {
|
||||
|
||||
private final TbConUnitService tbConUnitService;
|
||||
|
||||
@Log("导出数据")
|
||||
@ApiOperation("导出数据")
|
||||
@GetMapping(value = "/download")
|
||||
public void exportTbConUnit(HttpServletResponse response, TbConUnitQueryCriteria criteria) throws IOException {
|
||||
tbConUnitService.download(tbConUnitService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@Log("查询耗材单位添加")
|
||||
@ApiOperation("查询耗材单位添加")
|
||||
public ResponseEntity<Object> queryTbConUnit(TbConUnitQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity<>(tbConUnitService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Log("新增耗材单位添加")
|
||||
@ApiOperation("新增耗材单位添加")
|
||||
public ResponseEntity<Object> createTbConUnit(@Validated @RequestBody TbConUnit resources){
|
||||
|
||||
if(ObjectUtil.isEmpty(resources.getParentId())|| Objects.isNull(resources.getParentId())){
|
||||
resources.setParentId(0);
|
||||
}
|
||||
resources.setStatus("0");
|
||||
resources.setCreateTime(new Timestamp(System.currentTimeMillis()));
|
||||
return new ResponseEntity<>(tbConUnitService.create(resources),HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Log("修改耗材单位添加")
|
||||
@ApiOperation("修改耗材单位添加")
|
||||
public ResponseEntity<Object> updateTbConUnit(@Validated @RequestBody TbConUnit resources){
|
||||
|
||||
resources.setUpdateTime(new Timestamp(System.currentTimeMillis()));
|
||||
tbConUnitService.update(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
@Log("删除耗材单位添加")
|
||||
@ApiOperation("删除耗材单位添加")
|
||||
public ResponseEntity<Object> deleteTbConUnit(@RequestBody Integer[] ids) {
|
||||
tbConUnitService.deleteAll(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@RequestMapping("queryTbConUnitInfo")
|
||||
public ResponseEntity<Object> queryTbConUnitInfo(TbConUnitQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity<>(tbConUnitService.queryAllInfo(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
package cn.ysk.cashier.cons.service;
|
||||
|
||||
import cn.ysk.cashier.cons.domain.TbConUnit;
|
||||
import cn.ysk.cashier.cons.service.dto.TbConUnitDto;
|
||||
import cn.ysk.cashier.cons.service.dto.TbConUnitQueryCriteria;
|
||||
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-12
|
||||
**/
|
||||
public interface TbConUnitService {
|
||||
|
||||
/**
|
||||
* 查询数据分页
|
||||
* @param criteria 条件
|
||||
* @param pageable 分页参数
|
||||
* @return Map<String,Object>
|
||||
*/
|
||||
Map<String,Object> queryAll(TbConUnitQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
* @param criteria 条件参数
|
||||
* @return List<TbConUnitDto>
|
||||
*/
|
||||
List<TbConUnitDto> queryAll(TbConUnitQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
* @param id ID
|
||||
* @return TbConUnitDto
|
||||
*/
|
||||
TbConUnitDto findById(Integer id);
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param resources /
|
||||
* @return TbConUnitDto
|
||||
*/
|
||||
TbConUnitDto create(TbConUnit resources);
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param resources /
|
||||
*/
|
||||
void update(TbConUnit resources);
|
||||
|
||||
/**
|
||||
* 多选删除
|
||||
* @param ids /
|
||||
*/
|
||||
void deleteAll(Integer[] ids);
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
* @param all 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void download(List<TbConUnitDto> all, HttpServletResponse response) throws IOException;
|
||||
|
||||
|
||||
|
||||
Map<String,Object> queryAllInfo(TbConUnitQueryCriteria criteria, Pageable pageable);
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package cn.ysk.cashier.cons.service.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ConUnitPO implements Serializable {
|
||||
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
private BigDecimal value;
|
||||
|
||||
private String isConsume;
|
||||
|
||||
private Timestamp createTime;
|
||||
|
||||
private Timestamp updateTime;
|
||||
|
||||
|
||||
private List<ConUnitPO> childConUnit;
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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 io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.sql.Timestamp;
|
||||
import java.math.BigDecimal;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* @date 2024-07-12
|
||||
**/
|
||||
@Data
|
||||
public class TbConUnitDto implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
|
||||
/** 主单位名称 */
|
||||
private String name;
|
||||
|
||||
/** 主单位值 */
|
||||
private BigDecimal value;
|
||||
|
||||
private Integer parentId;
|
||||
|
||||
private String isConsume;
|
||||
|
||||
/** 状态 1 启用 0 禁用 */
|
||||
private String status;
|
||||
|
||||
private Timestamp createTime;
|
||||
|
||||
private Timestamp updateTime;
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
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-12
|
||||
**/
|
||||
@Data
|
||||
public class TbConUnitQueryCriteria{
|
||||
|
||||
/** 模糊 */
|
||||
@Query(type = Query.Type.INNER_LIKE)
|
||||
private String name;
|
||||
|
||||
/** 精确 */
|
||||
@Query
|
||||
private Integer parentId;
|
||||
|
||||
/** 精确 */
|
||||
@Query
|
||||
private String status;
|
||||
}
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
package cn.ysk.cashier.cons.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.ysk.cashier.cons.domain.TbConUnit;
|
||||
import cn.ysk.cashier.cons.service.dto.ConUnitPO;
|
||||
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.TbConUnitRepository;
|
||||
import cn.ysk.cashier.cons.service.TbConUnitService;
|
||||
import cn.ysk.cashier.cons.service.dto.TbConUnitDto;
|
||||
import cn.ysk.cashier.cons.service.dto.TbConUnitQueryCriteria;
|
||||
import cn.ysk.cashier.cons.service.mapstruct.TbConUnitMapper;
|
||||
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.util.*;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
* @description 服务实现
|
||||
* @author admin
|
||||
* @date 2024-07-12
|
||||
**/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TbConUnitServiceImpl implements TbConUnitService {
|
||||
|
||||
private final TbConUnitRepository tbConUnitRepository;
|
||||
private final TbConUnitMapper tbConUnitMapper;
|
||||
|
||||
@Override
|
||||
public Map<String,Object> queryAll(TbConUnitQueryCriteria criteria, Pageable pageable){
|
||||
Page<TbConUnit> page = tbConUnitRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return PageUtil.toPage(page.map(tbConUnitMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TbConUnitDto> queryAll(TbConUnitQueryCriteria criteria){
|
||||
return tbConUnitMapper.toDto(tbConUnitRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public TbConUnitDto findById(Integer id) {
|
||||
TbConUnit tbConUnit = tbConUnitRepository.findById(id).orElseGet(TbConUnit::new);
|
||||
ValidationUtil.isNull(tbConUnit.getId(),"TbConUnit","id",id);
|
||||
return tbConUnitMapper.toDto(tbConUnit);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public TbConUnitDto create(TbConUnit resources) {
|
||||
return tbConUnitMapper.toDto(tbConUnitRepository.save(resources));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(TbConUnit resources) {
|
||||
TbConUnit tbConUnit = tbConUnitRepository.findById(resources.getId()).orElseGet(TbConUnit::new);
|
||||
ValidationUtil.isNull( tbConUnit.getId(),"TbConUnit","id",resources.getId());
|
||||
tbConUnit.copy(resources);
|
||||
tbConUnitRepository.save(tbConUnit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAll(Integer[] ids) {
|
||||
for (Integer id : ids) {
|
||||
tbConUnitRepository.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(List<TbConUnitDto> all, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (TbConUnitDto tbConUnit : all) {
|
||||
Map<String,Object> map = new LinkedHashMap<>();
|
||||
map.put("主单位名称", tbConUnit.getName());
|
||||
map.put("主单位值", tbConUnit.getValue());
|
||||
map.put("状态 1 启用 0 禁用", tbConUnit.getStatus());
|
||||
map.put(" createTime", tbConUnit.getCreateTime());
|
||||
map.put(" updateTime", tbConUnit.getUpdateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryAllInfo(TbConUnitQueryCriteria criteria, Pageable pageable) {
|
||||
List<ConUnitPO> list=new ArrayList<>();
|
||||
if(ObjectUtil.isEmpty(criteria.getParentId())){
|
||||
criteria.setParentId(0);
|
||||
}
|
||||
Page<TbConUnit> page = tbConUnitRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
if(Objects.nonNull(page)&&Objects.nonNull(page.getContent())){
|
||||
page.getContent().parallelStream().forEach(it->{
|
||||
ConUnitPO po=new ConUnitPO();
|
||||
po.setId(it.getId());
|
||||
po.setName(it.getName());
|
||||
po.setValue(it.getValue());
|
||||
po.setIsConsume(it.getIsConsume());
|
||||
po.setCreateTime(it.getCreateTime());
|
||||
po.setUpdateTime(it.getUpdateTime());
|
||||
|
||||
criteria.setParentId(it.getId());
|
||||
criteria.setName(null);
|
||||
criteria.setStatus(null);
|
||||
Page<TbConUnit> childPage = tbConUnitRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
if(Objects.nonNull(childPage)&&Objects.nonNull(childPage.getContent())){
|
||||
List<ConUnitPO> list1=new ArrayList<>();
|
||||
for (TbConUnit tbConUnit : childPage.getContent()) {
|
||||
ConUnitPO child=new ConUnitPO();
|
||||
child.setId(tbConUnit.getId());
|
||||
child.setName(tbConUnit.getName());
|
||||
child.setValue(tbConUnit.getValue());
|
||||
child.setIsConsume(tbConUnit.getIsConsume());
|
||||
child.setCreateTime(tbConUnit.getCreateTime());
|
||||
child.setUpdateTime(tbConUnit.getUpdateTime());
|
||||
list1.add(child);
|
||||
}
|
||||
po.setChildConUnit(list1);
|
||||
}
|
||||
list.add(po);
|
||||
});
|
||||
}
|
||||
Map<String,Object> map = new LinkedHashMap<>(2);
|
||||
map.put("content",list);
|
||||
map.put("totalElements",page.getTotalPages());
|
||||
return map;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package cn.ysk.cashier.cons.service.mapstruct;
|
||||
|
||||
import cn.ysk.cashier.base.BaseMapper;
|
||||
import cn.ysk.cashier.cons.domain.TbConUnit;
|
||||
import cn.ysk.cashier.cons.service.dto.TbConUnitDto;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* @date 2024-07-12
|
||||
**/
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface TbConUnitMapper extends BaseMapper<TbConUnitDto, TbConUnit> {
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue