fix(feature/bill): 更新票据管理的添加,修改功能

- 添加dto
This commit is contained in:
vertoryao 2024-01-17 15:49:44 +08:00
parent 21e6a1c05e
commit 93225d1df8
4 changed files with 37 additions and 5 deletions

View File

@ -1,5 +1,7 @@
package com.zsc.edu.bill.common.mapstruct; package com.zsc.edu.bill.common.mapstruct;
import org.mapstruct.MappingTarget;
import java.util.List; import java.util.List;
public interface BaseMapper<D, E> { public interface BaseMapper<D, E> {
@ -7,4 +9,11 @@ public interface BaseMapper<D, E> {
E toEntity(D dto); E toEntity(D dto);
List<D> toDto(List<E> entityList); List<D> toDto(List<E> entityList);
List<E> toEntity(List<D> dtoList); List<E> toEntity(List<D> dtoList);
/**
* 更新实体类
* @param dto
* @param entity
*/
void convert(D dto, @MappingTarget E entity);
} }

View File

@ -1,6 +1,7 @@
package com.zsc.edu.bill.modules.bills.controller; package com.zsc.edu.bill.modules.bills.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zsc.edu.bill.modules.bills.dto.BillDto;
import com.zsc.edu.bill.modules.bills.entity.Bill; import com.zsc.edu.bill.modules.bills.entity.Bill;
import com.zsc.edu.bill.modules.bills.query.BillQuery; import com.zsc.edu.bill.modules.bills.query.BillQuery;
import com.zsc.edu.bill.modules.bills.service.BillService; import com.zsc.edu.bill.modules.bills.service.BillService;
@ -34,17 +35,17 @@ public class BillController {
* @return ture/false * @return ture/false
*/ */
@PostMapping @PostMapping
public Boolean create(Bill bill){ public Boolean create(@RequestBody BillDto dto){
return service.save(bill); return service.create(dto);
} }
/** /**
* 更新票据 * 更新票据
* @return ture/false * @return ture/false
*/ */
@PatchMapping @PatchMapping("/{id}")
public Boolean update(Bill bill){ public Boolean update(@RequestBody BillDto dto, @PathVariable("id") Long id){
return service.updateById(bill); return service.update(dto, id);
} }
/** /**

View File

@ -4,6 +4,7 @@ package com.zsc.edu.bill.modules.bills.service;
import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.zsc.edu.bill.modules.bills.dto.BillDto;
import com.zsc.edu.bill.modules.bills.entity.Bill; import com.zsc.edu.bill.modules.bills.entity.Bill;
import com.zsc.edu.bill.modules.system.query.TicketQuery; import com.zsc.edu.bill.modules.system.query.TicketQuery;
import com.zsc.edu.bill.modules.system.vo.TicketVo; import com.zsc.edu.bill.modules.system.vo.TicketVo;
@ -15,4 +16,7 @@ import com.zsc.edu.bill.modules.system.vo.TicketVo;
*/ */
public interface BillService extends IService<Bill> { public interface BillService extends IService<Bill> {
Boolean create(BillDto dto);
Boolean update(BillDto dto, Long id);
} }

View File

@ -1,13 +1,16 @@
package com.zsc.edu.bill.modules.bills.service.impl; package com.zsc.edu.bill.modules.bills.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zsc.edu.bill.modules.bills.dto.BillDto;
import com.zsc.edu.bill.modules.bills.entity.Bill; import com.zsc.edu.bill.modules.bills.entity.Bill;
import com.zsc.edu.bill.modules.bills.mapper.BillMapper;
import com.zsc.edu.bill.modules.bills.repo.BillRepository; import com.zsc.edu.bill.modules.bills.repo.BillRepository;
import com.zsc.edu.bill.modules.bills.service.BillService; import com.zsc.edu.bill.modules.bills.service.BillService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import java.util.UUID;
/** /**
* @author yao * @author yao
@ -16,6 +19,21 @@ import java.util.List;
@Service @Service
public class BillServiceImpl extends ServiceImpl<BillRepository, Bill> implements BillService { public class BillServiceImpl extends ServiceImpl<BillRepository, Bill> implements BillService {
private final BillMapper mapper;
@Override
public Boolean create(BillDto dto) {
Bill bill = mapper.toEntity(dto);
bill.setUuid(UUID.randomUUID());
return save(bill);
}
@Override
public Boolean update(BillDto dto, Long id) {
Bill bill = getById(id);
mapper.convert(dto, bill);
return updateById(bill);
}
} }