新增计量单位

pull/451/head
starrysky 2019-07-27 08:11:53 +08:00
parent 23c827684d
commit 5bcc19a9ba
7 changed files with 190 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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