mirror of https://github.com/elunez/eladmin
新增计量单位
parent
23c827684d
commit
5bcc19a9ba
|
@ -0,0 +1,55 @@
|
||||||
|
package me.zhengjie.modules.wms.bd.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.hibernate.annotations.CreationTimestamp;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 黄星星
|
||||||
|
* @date 2019-07-26
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Data
|
||||||
|
@Table(name="bd_measure_unit")
|
||||||
|
public class MeasureUnit implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID
|
||||||
|
*/
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "id")
|
||||||
|
@NotNull(groups = MeasureUnit.Update.class)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 名称
|
||||||
|
*/
|
||||||
|
@Column(name = "name",nullable = false)
|
||||||
|
@NotBlank
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Boolean status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@Column(name = "create_time")
|
||||||
|
@CreationTimestamp
|
||||||
|
private Timestamp createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
@Column(name = "update_time")
|
||||||
|
@CreationTimestamp
|
||||||
|
private Timestamp updateTime;
|
||||||
|
|
||||||
|
public @interface Update {}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 黄星星
|
||||||
|
* @date 2019-07-26
|
||||||
|
*/
|
||||||
|
public interface MeasureUnitRepository extends JpaRepository<MeasureUnit, Long >, JpaSpecificationExecutor {
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package me.zhengjie.modules.wms.bd.rest;
|
||||||
|
|
||||||
|
import me.zhengjie.aop.log.Log;
|
||||||
|
import me.zhengjie.exception.BadRequestException;
|
||||||
|
import me.zhengjie.modules.wms.bd.domain.MeasureUnit;
|
||||||
|
import me.zhengjie.modules.wms.bd.service.MeasureUnitService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 黄星星
|
||||||
|
* @date 2019-07-27
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("api")
|
||||||
|
public class MeasureUnitController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MeasureUnitService measureUnitService;
|
||||||
|
|
||||||
|
private static final String ENTITY_NAME = "measureUnit";
|
||||||
|
|
||||||
|
@Log("新增计量单位")
|
||||||
|
@PostMapping(value = "/measureUnit")
|
||||||
|
public ResponseEntity create(@Validated @RequestBody MeasureUnit resources){
|
||||||
|
if (resources.getId() != null) {
|
||||||
|
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
|
||||||
|
}
|
||||||
|
return new ResponseEntity(measureUnitService.create(resources), HttpStatus.CREATED);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package me.zhengjie.modules.wms.bd.service;
|
||||||
|
|
||||||
|
import me.zhengjie.modules.wms.bd.domain.MeasureUnit;
|
||||||
|
import me.zhengjie.modules.wms.bd.service.dto.MeasureUnitDTO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 黄星星
|
||||||
|
* @date 2019-07-27
|
||||||
|
*/
|
||||||
|
public interface MeasureUnitService {
|
||||||
|
|
||||||
|
public MeasureUnitDTO create(MeasureUnit resources);
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package me.zhengjie.modules.wms.bd.service.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 黄星星
|
||||||
|
* @date 2019-07-27
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class MeasureUnitDTO {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private Boolean status;
|
||||||
|
|
||||||
|
private Timestamp createTime;
|
||||||
|
|
||||||
|
private Timestamp updateTime;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package me.zhengjie.modules.wms.bd.service.impl;
|
||||||
|
|
||||||
|
import me.zhengjie.modules.wms.bd.domain.MeasureUnit;
|
||||||
|
import me.zhengjie.modules.wms.bd.repository.MeasureUnitRepository;
|
||||||
|
import me.zhengjie.modules.wms.bd.service.MeasureUnitService;
|
||||||
|
import me.zhengjie.modules.wms.bd.service.dto.MeasureUnitDTO;
|
||||||
|
import me.zhengjie.modules.wms.bd.service.mapper.MeasureUnitMapper;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 黄星星
|
||||||
|
* @date 2019-07-27
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||||
|
public class MeasureUnitServiceImpl implements MeasureUnitService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MeasureUnitMapper measureUnitMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MeasureUnitRepository measureUnitRepository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public MeasureUnitDTO create(MeasureUnit resources) {
|
||||||
|
return measureUnitMapper.toDto(measureUnitRepository.save(resources));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package me.zhengjie.modules.wms.bd.service.mapper;
|
||||||
|
|
||||||
|
import me.zhengjie.mapper.EntityMapper;
|
||||||
|
import me.zhengjie.modules.wms.bd.domain.MeasureUnit;
|
||||||
|
import me.zhengjie.modules.wms.bd.service.dto.MeasureUnitDTO;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.ReportingPolicy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 黄星星
|
||||||
|
* @date 2019-07-27
|
||||||
|
*/
|
||||||
|
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||||
|
public interface MeasureUnitMapper extends EntityMapper<MeasureUnitDTO, MeasureUnit> {
|
||||||
|
}
|
Loading…
Reference in New Issue