mirror of https://github.com/elunez/eladmin
swagger
parent
403e47ea5f
commit
9d1e6783ff
|
@ -3,6 +3,8 @@ package me.zhengjie.modules.wms.bd.repository;
|
|||
import me.zhengjie.modules.wms.bd.domain.MeasureUnit;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
/**
|
||||
* @author 黄星星
|
||||
|
@ -16,4 +18,40 @@ public interface MeasureUnitRepository extends JpaRepository<MeasureUnit, Long >
|
|||
* @return
|
||||
*/
|
||||
MeasureUnit findByIdAndStatusTrue(long id);
|
||||
|
||||
/**
|
||||
* 根据name查询状态正常的计量单位
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
MeasureUnit findByNameAndStatusTrue(String name);
|
||||
|
||||
/**
|
||||
* 根据name查询状态删除的计量单位
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
MeasureUnit findByNameAndStatusFalse(String name);
|
||||
|
||||
|
||||
@Modifying
|
||||
@Query(value = "update bd_measure_unit set status = 1 where id = ?1",nativeQuery = true)
|
||||
void updateStatusToTrue(long id);
|
||||
|
||||
/**
|
||||
* 删除计量单位(逻辑删除)
|
||||
* @param id
|
||||
*/
|
||||
@Modifying
|
||||
@Query(value = "update bd_measure_unit set status = 0 where id = ?1",nativeQuery = true)
|
||||
void deleteMeasureUnit(long id);
|
||||
|
||||
/**
|
||||
* 修改计量单位名称
|
||||
* @param name
|
||||
* @param id
|
||||
*/
|
||||
@Modifying
|
||||
@Query(value = "update bd_measure_unit set name = ?1 where id = ?2",nativeQuery = true)
|
||||
void updateNameById(String name, long id);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public interface WareHouseRepository extends JpaRepository<WareHouse, Long >, Jp
|
|||
WareHouse findByNameAndWareHouseCodeAndStatusFalse(String name, String wareHouseCode);
|
||||
|
||||
/**
|
||||
* 删除仓库
|
||||
* 删除仓库(逻辑删除)
|
||||
* @param id
|
||||
*/
|
||||
@Modifying
|
||||
|
|
|
@ -36,6 +36,15 @@ public class MeasureUnitController {
|
|||
return new ResponseEntity(measureUnitService.create(resources), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@Log("修改计量单位")
|
||||
@PostMapping(value = "/measureUnit/update")
|
||||
public ResponseEntity updateMeasureUnit(@RequestBody MeasureUnit resources){
|
||||
if (resources.getId() == null) {
|
||||
throw new BadRequestException("主键不能为空");
|
||||
}
|
||||
return new ResponseEntity(measureUnitService.create(resources), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@Log("查看计量单位详情")
|
||||
@GetMapping(value = "/measureUnit/{id}")
|
||||
public ResponseEntity getMessureUnit(@PathVariable Long id){
|
||||
|
|
|
@ -12,6 +12,8 @@ public interface MeasureUnitService {
|
|||
|
||||
MeasureUnitDTO create(MeasureUnit resources);
|
||||
|
||||
MeasureUnitDTO updateMeasureUnit(MeasureUnit measureUnit);
|
||||
|
||||
MeasureUnitDTO findById(long id);
|
||||
|
||||
void delete(Long id);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package me.zhengjie.modules.wms.bd.service.impl;
|
||||
|
||||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.modules.wms.bd.domain.MeasureUnit;
|
||||
import me.zhengjie.modules.wms.bd.repository.MeasureUnitRepository;
|
||||
import me.zhengjie.modules.wms.bd.service.MeasureUnitService;
|
||||
|
@ -14,7 +15,9 @@ import org.springframework.data.domain.Pageable;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
|
@ -34,9 +37,53 @@ public class MeasureUnitServiceImpl implements MeasureUnitService {
|
|||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public MeasureUnitDTO create(MeasureUnit resources) {
|
||||
resources.getName();
|
||||
resources.setStatus(true);
|
||||
return measureUnitMapper.toDto(measureUnitRepository.save(resources));
|
||||
/**
|
||||
* 查看状态正常的情况下该计量单位是否存在,如果存在,则提示计量单位已存在
|
||||
* 查看删除状态下该名字的计量单位,如果计量单位存在,则修改计量单位状态
|
||||
* 否则直接插入新的记录
|
||||
*/
|
||||
MeasureUnit byNameAndStatusTrue = measureUnitRepository.findByNameAndStatusTrue(resources.getName());
|
||||
if(null != byNameAndStatusTrue){
|
||||
throw new BadRequestException("该计量单位已经存在");
|
||||
}
|
||||
MeasureUnit byNameAndStatusFalse = measureUnitRepository.findByNameAndStatusFalse(resources.getName());
|
||||
if(null != byNameAndStatusFalse){
|
||||
resources.setStatus(true);
|
||||
measureUnitRepository.updateStatusToTrue(resources.getId());
|
||||
Optional<MeasureUnit> measureUnitOptional = measureUnitRepository.findById(resources.getId());
|
||||
MeasureUnit measureUnit = measureUnitOptional.get();
|
||||
return measureUnitMapper.toDto(measureUnit);
|
||||
}else{
|
||||
resources.getName();
|
||||
resources.setStatus(true);
|
||||
MeasureUnit measureUnit = measureUnitRepository.save(resources);
|
||||
return measureUnitMapper.toDto(measureUnit);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MeasureUnitDTO updateMeasureUnit(MeasureUnit measureUnit) {
|
||||
/**
|
||||
* 修改的名称不能为空
|
||||
* 查看修改后的name对应的状态为true的计量单位是否存在,如果存在,则提示计量单位已存在
|
||||
* 修改计量单位名称
|
||||
* 备注:
|
||||
* 如果修改后的name对应的状态为false的计量单位存在,则会有冗余数据
|
||||
*/
|
||||
String name = measureUnit.getName();
|
||||
if(StringUtils.isEmpty(name)){
|
||||
throw new BadRequestException("计量单位名称不能为空");
|
||||
}
|
||||
|
||||
MeasureUnit byNameAndStatusTrue = measureUnitRepository.findByNameAndStatusTrue(name);
|
||||
if(null != byNameAndStatusTrue){
|
||||
throw new BadRequestException("计量单位已存在");
|
||||
}
|
||||
|
||||
measureUnitRepository.updateNameById(measureUnit.getName(), measureUnit.getId());
|
||||
|
||||
Optional<MeasureUnit> measureUnitOptional = measureUnitRepository.findById(measureUnit.getId());
|
||||
return measureUnitMapper.toDto(measureUnitOptional.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -50,7 +97,8 @@ public class MeasureUnitServiceImpl implements MeasureUnitService {
|
|||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Long id) {
|
||||
measureUnitRepository.deleteById(id);
|
||||
//逻辑删除
|
||||
measureUnitRepository.deleteMeasureUnit(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -60,12 +60,12 @@ generator:
|
|||
enabled: false
|
||||
|
||||
#如果生产环境要开启swagger,需要配置请求地址
|
||||
#springfox:
|
||||
# documentation:
|
||||
# swagger:
|
||||
# v2:
|
||||
# host: # 接口域名或外网ip
|
||||
springfox:
|
||||
documentation:
|
||||
swagger:
|
||||
v2:
|
||||
host: 47.93.55.102
|
||||
|
||||
#是否开启 swagger-ui
|
||||
swagger:
|
||||
enabled: false
|
||||
enabled: true
|
Loading…
Reference in New Issue