添加工艺项目相关类

This commit is contained in:
liuchengqian 2022-03-15 21:07:00 +08:00
parent 9c77ac0ccf
commit a8486953bc
11 changed files with 433 additions and 0 deletions

View File

@ -0,0 +1,50 @@
package com.xkrs.controller;
import com.xkrs.model.qo.CraftItemQoDelete;
import com.xkrs.model.qo.CraftItemQoInsert;
import com.xkrs.model.qo.CraftItemQoUpdate;
import com.xkrs.service.CraftItemService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@RestController
public class CraftItemController {
@Resource
private CraftItemService craftItemService;
/**
* 添加工艺项目
*/
@PostMapping("/insertCraftItem")
public String insertCraftItem(@RequestBody CraftItemQoInsert insertQo) {
return craftItemService.insertCraftItem(insertQo);
}
/**
* 删除工艺项目
*/
@PostMapping("/deleteCraftItem")
public String deleteCraftItem(@RequestBody CraftItemQoDelete deleteQo) {
return craftItemService.deleteCraftItem(deleteQo);
}
/**
* 更新工艺项目名称
*/
@PostMapping("/updateCraftItem")
public String updateCraftItem(@RequestBody CraftItemQoUpdate updateQo) {
return craftItemService.updateCraftItem(updateQo);
}
/**
* 查询工艺项目
*/
@GetMapping("/queryCraftItem")
public String queryCraftItem(@RequestParam(required = false, value = "no") String no, @RequestParam(required = false, value = "name") String name) {
return craftItemService.queryCraftItem(no, name);
}
}

View File

@ -0,0 +1,36 @@
package com.xkrs.dao;
import com.xkrs.model.entity.CraftItemEntity;
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;
import org.springframework.stereotype.Component;
import javax.transaction.Transactional;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* 工艺项目Dao
*/
@Component
public interface CraftItemDao extends JpaRepository<CraftItemEntity, Integer>, JpaSpecificationExecutor<CraftItemEntity> {
Optional<CraftItemEntity> findByNo(String no);
/**
* 更新工艺项目名称
*/
@Transactional(rollbackOn = Exception.class)
@Modifying(clearAutomatically = true)
@Query(value = "UPDATE craft_item SET update_time = ?2, name = ?3 WHERE id = ?1", nativeQuery = true)
void updateNameById(Integer id, String updateTime, String name);
/**
* 查询工艺项目
*/
@Query(value = "SELECT id, no, name FROM craft_item WHERE no LIKE %?1% AND name LIKE %?2% ORDER BY create_time ASC", nativeQuery = true)
List<Map<String, Object>> queryCraftItem(String no, String name);
}

View File

@ -0,0 +1,91 @@
package com.xkrs.model.entity;
import javax.persistence.*;
/**
* 工艺项目
*/
@Entity
@Table(name = "craft_item")
public class CraftItemEntity {
/**
* 主键id
*/
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "craft_item_seq_gen")
@SequenceGenerator(name = "craft_item_seq_gen", sequenceName = "craft_item_id_seq", allocationSize = 1)
private Integer id;
/**
* 创建时间
*/
@Column(length = 85, columnDefinition = "varchar(85)")
private String createTime;
/**
* 更新时间
*/
@Column(length = 85, columnDefinition = "varchar(85)")
private String updateTime;
/**
* 编号
*/
@Column(length = 85, columnDefinition = "varchar(85)")
private String no;
/**
* 名称
*/
@Column(length = 85, columnDefinition = "varchar(85)")
private String name;
public CraftItemEntity() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getCreateTime() {
return createTime;
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
public String getUpdateTime() {
return updateTime;
}
public void setUpdateTime(String updateTime) {
this.updateTime = updateTime;
}
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "CraftItemEntity{" + "id=" + id + ", createTime='" + createTime + '\'' + ", updateTime='" + updateTime + '\'' + ", no='" + no + '\'' + ", name='" + name + '\'' + '}';
}
}

View File

@ -0,0 +1,33 @@
package com.xkrs.model.qo;
import com.xkrs.model.va.CraftItemQoDeleteVa;
import javax.validation.constraints.NotBlank;
/**
* 删除工艺项目接收类
*/
public class CraftItemQoDelete {
/**
* 主键id
*/
@NotBlank(message = "{CraftItemEntity.id.blank}", groups = {CraftItemQoDeleteVa.class})
private Integer id;
public CraftItemQoDelete() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Override
public String toString() {
return "CraftItemQoDelete{" + "id=" + id + '}';
}
}

View File

@ -0,0 +1,47 @@
package com.xkrs.model.qo;
import com.xkrs.model.va.CraftItemQoInsertVa;
import javax.validation.constraints.NotBlank;
/**
* 新增工艺项目接收类
*/
public class CraftItemQoInsert {
/**
* 编号
*/
@NotBlank(message = "{CraftItemEntity.no.blank}", groups = {CraftItemQoInsertVa.class})
private String no;
/**
* 名称
*/
@NotBlank(message = "{CraftItemEntity.name.blank}", groups = {CraftItemQoInsertVa.class})
private String name;
public CraftItemQoInsert() {
}
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "CraftItemQoInsert{" + "no='" + no + '\'' + ", name='" + name + '\'' + '}';
}
}

View File

@ -0,0 +1,44 @@
package com.xkrs.model.qo;
import com.xkrs.model.va.CraftItemQoUpdateVa;
import javax.validation.constraints.NotBlank;
public class CraftItemQoUpdate {
/**
* 主键id
*/
@NotBlank(message = "{CraftItemEntity.id.blank}", groups = {CraftItemQoUpdateVa.class})
private Integer id;
/**
* 名称
*/
@NotBlank(message = "{CraftItemEntity.name.blank}", groups = {CraftItemQoUpdateVa.class})
private String name;
public CraftItemQoUpdate() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "CraftItemQoUpdate{" + "id=" + id + ", name='" + name + '\'' + '}';
}
}

View File

@ -0,0 +1,4 @@
package com.xkrs.model.va;
public interface CraftItemQoDeleteVa {
}

View File

@ -0,0 +1,4 @@
package com.xkrs.model.va;
public interface CraftItemQoInsertVa {
}

View File

@ -0,0 +1,4 @@
package com.xkrs.model.va;
public interface CraftItemQoUpdateVa {
}

View File

@ -0,0 +1,29 @@
package com.xkrs.service;
import com.xkrs.model.qo.CraftItemQoDelete;
import com.xkrs.model.qo.CraftItemQoInsert;
import com.xkrs.model.qo.CraftItemQoUpdate;
public interface CraftItemService {
/**
* 添加工艺项目
*/
String insertCraftItem(CraftItemQoInsert insertQo);
/**
* 删除工艺项目
*/
String deleteCraftItem(CraftItemQoDelete deleteQo);
/**
* 更新工艺项目名称
*/
String updateCraftItem(CraftItemQoUpdate updateQo);
/**
* 查询工艺项目
*/
String queryCraftItem(String no, String name);
}

View File

@ -0,0 +1,91 @@
package com.xkrs.service.impl;
import com.xkrs.dao.CraftItemDao;
import com.xkrs.encapsulation.PromptMessageEnum;
import com.xkrs.model.entity.CraftItemEntity;
import com.xkrs.model.qo.CraftItemQoDelete;
import com.xkrs.model.qo.CraftItemQoInsert;
import com.xkrs.model.qo.CraftItemQoUpdate;
import com.xkrs.service.CraftItemService;
import com.xkrs.util.LocalDateUtils;
import com.xkrs.util.LocalStringUtils;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject;
@Service
public class CraftItemServiceImpl implements CraftItemService {
private Locale locale = LocaleContextHolder.getLocale();
@Resource
private CraftItemDao craftItemDao;
/**
* 添加工艺项目
*/
@Override
public String insertCraftItem(CraftItemQoInsert insertQo) {
String no = insertQo.getNo();
String name = insertQo.getName();
Optional<CraftItemEntity> entityByNo = craftItemDao.findByNo(no);
if (entityByNo.isPresent()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "该工艺项目已存在,请勿重复添加!", locale);
}
CraftItemEntity entity = new CraftItemEntity();
entity.setCreateTime(LocalDateUtils.getCurrentSecond());
entity.setUpdateTime("");
entity.setNo(LocalStringUtils.formatEmptyValue(no));
entity.setName(LocalStringUtils.formatEmptyValue(name));
craftItemDao.save(entity);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功!", locale);
}
/**
* 删除工艺项目
*/
@Override
public String deleteCraftItem(CraftItemQoDelete deleteQo) {
Integer id = deleteQo.getId();
Optional<CraftItemEntity> entityById = craftItemDao.findById(id);
if (entityById.isEmpty()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "不存在该工艺项目,请先添加工艺项目!", locale);
}
craftItemDao.deleteById(id);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "删除成功!", locale);
}
/**
* 更新工艺项目名称
*/
@Override
public String updateCraftItem(CraftItemQoUpdate updateQo) {
Integer id = updateQo.getId();
String name = updateQo.getName();
Optional<CraftItemEntity> entityById = craftItemDao.findById(id);
if (entityById.isEmpty()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "不存在该工艺项目,请先添加工艺项目!", locale);
}
craftItemDao.updateNameById(id, LocalDateUtils.getCurrentSecond(), LocalStringUtils.formatEmptyValue(name));
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "更新成功!", locale);
}
/**
* 查询工艺项目
*/
@Override
public String queryCraftItem(String no, String name) {
List<Map<String, Object>> resultList = craftItemDao.queryCraftItem(LocalStringUtils.formatEmptyValue(no), LocalStringUtils.formatEmptyValue(name));
if (resultList == null || resultList.isEmpty()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该工艺项目的信息!", locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, resultList, locale);
}
}