feat: 添加机台相关功能
This commit is contained in:
parent
9c4f9b96d0
commit
a87ccea064
|
|
@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.*;
|
|||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 机型管理
|
||||
|
|
@ -85,4 +86,13 @@ public class ModelController extends BaseController {
|
|||
return modelControllerService.importFromExcel(response,file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出选中的机型,为空时导出模版
|
||||
* @param ids 选中的id集合
|
||||
*/
|
||||
@PostMapping("export")
|
||||
public void exportSelect(HttpServletResponse response,@RequestBody List<Long> ids) throws Exception {
|
||||
modelControllerService.exportSelect(response,ids);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
package com.nflg.wms.admin.controller;
|
||||
|
||||
import com.nflg.wms.admin.service.WorkbenchControllerService;
|
||||
import com.nflg.wms.common.pojo.ApiResult;
|
||||
import com.nflg.wms.common.pojo.PageData;
|
||||
import com.nflg.wms.common.pojo.qo.EnableQO;
|
||||
import com.nflg.wms.common.pojo.qo.ModelAddQO;
|
||||
import com.nflg.wms.common.pojo.qo.ModelSearchQO;
|
||||
import com.nflg.wms.common.pojo.qo.ModelUpdateQO;
|
||||
import com.nflg.wms.repository.entity.Workbench;
|
||||
import com.nflg.wms.starter.BaseController;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 机台管理
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/workbench")
|
||||
public class WorkbenchController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private WorkbenchControllerService workbenchControllerService;
|
||||
|
||||
/**
|
||||
* 新增机台
|
||||
*/
|
||||
@PostMapping("add")
|
||||
public ApiResult<Void> add(@Valid @RequestBody ModelAddQO request){
|
||||
workbenchControllerService.add(request);
|
||||
return ApiResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新机台
|
||||
*/
|
||||
@PostMapping("update")
|
||||
public ApiResult<Void> update(@Valid @RequestBody ModelUpdateQO request){
|
||||
workbenchControllerService.update(request);
|
||||
return ApiResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除机台
|
||||
*/
|
||||
@PostMapping("delete")
|
||||
public ApiResult<Void> delete(@Valid @NotNull Long id){
|
||||
workbenchControllerService.delete(id);
|
||||
return ApiResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用/禁用机台
|
||||
* @param request 请求参数
|
||||
*/
|
||||
@PostMapping("/enable")
|
||||
public ApiResult<Void> enable(@Valid @RequestBody EnableQO request){
|
||||
workbenchControllerService.enable(request);
|
||||
return ApiResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索机台
|
||||
* @param request 搜索参数
|
||||
*/
|
||||
@PostMapping("search")
|
||||
public ApiResult<PageData<Workbench>> search(@Valid @RequestBody ModelSearchQO request){
|
||||
return ApiResult.success(workbenchControllerService.search(request));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入机台
|
||||
* @param file 文件
|
||||
*/
|
||||
@Transactional
|
||||
@PostMapping("import")
|
||||
public ApiResult importFromExcel(HttpServletResponse response, @RequestParam(value = "file") MultipartFile file) throws IOException {
|
||||
return workbenchControllerService.importFromExcel(response,file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出选中的机台,为空时导出模板
|
||||
* @param ids 选中的id集合
|
||||
*/
|
||||
@PostMapping("export")
|
||||
public void exportSelect(HttpServletResponse response,@RequestBody List<Long> ids) throws Exception {
|
||||
workbenchControllerService.exportSelect(response,ids);
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ import cn.hutool.core.util.StrUtil;
|
|||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.nflg.wms.common.constant.STATE;
|
||||
import com.nflg.wms.common.pojo.ApiResult;
|
||||
import com.nflg.wms.common.pojo.dto.ModelExcelExportDTO;
|
||||
import com.nflg.wms.common.pojo.dto.ModelExcelImportDTO;
|
||||
import com.nflg.wms.common.pojo.qo.EnableQO;
|
||||
import com.nflg.wms.common.pojo.qo.ModelAddQO;
|
||||
|
|
@ -41,6 +42,7 @@ import java.time.LocalDateTime;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class ModelControllerService {
|
||||
|
|
@ -77,14 +79,13 @@ public class ModelControllerService {
|
|||
return modelService.search(request);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public ApiResult importFromExcel(HttpServletResponse response, MultipartFile file) throws IOException {
|
||||
List<ModelExcelImportDTO> data = EecExcelUtil.getExcelContext(file.getInputStream(), ModelExcelImportDTO.class);
|
||||
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(data)).throwMessage("导入文件内容为空");
|
||||
if (updateCheckAndImport(data)) {
|
||||
return ApiResult.success();
|
||||
} else {
|
||||
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
||||
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode(getResultName(file.getOriginalFilename()), StandardCharsets.UTF_8));
|
||||
try(ByteArrayOutputStream osOut = new ByteArrayOutputStream()) {
|
||||
new Workbook()
|
||||
.addSheet(new ListSheet<>(data))
|
||||
|
|
@ -98,11 +99,6 @@ public class ModelControllerService {
|
|||
}
|
||||
}
|
||||
|
||||
private String getResultName(String name){
|
||||
int index=name.lastIndexOf(".");
|
||||
return name.substring(0,index)+"_结果"+"."+name.substring(index+1);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public boolean updateCheckAndImport(List<ModelExcelImportDTO> data) {
|
||||
List<Model> models = new ArrayList<>();
|
||||
|
|
@ -113,9 +109,14 @@ public class ModelControllerService {
|
|||
sb.append("机型编号不能为空;");
|
||||
} else {
|
||||
model = modelService.lambdaQuery().eq(Model::getNo, dto.getNo()).one();
|
||||
if (Objects.isNull( model)){
|
||||
if (Objects.isNull(model)) {
|
||||
model = new Model()
|
||||
.setNo(dto.getNo());
|
||||
.setNo(dto.getNo())
|
||||
.setCreateBy(UserUtil.getUserName())
|
||||
.setCreateTime(LocalDateTime.now());
|
||||
}else {
|
||||
model.setUpdateBy(UserUtil.getUserName());
|
||||
model.setUpdateTime(LocalDateTime.now());
|
||||
}
|
||||
}
|
||||
model.setRemark(dto.getRemark());
|
||||
|
|
@ -128,4 +129,24 @@ public class ModelControllerService {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void exportSelect(HttpServletResponse response,List<Long> ids) throws IOException {
|
||||
List<Model> users = CollectionUtil.isNotEmpty(ids)?modelService.listByIds(ids):new ArrayList<>();
|
||||
List<ModelExcelExportDTO> datas = users.stream().map(model -> {
|
||||
ModelExcelExportDTO dto = new ModelExcelExportDTO();
|
||||
dto.setNo(model.getNo());
|
||||
dto.setRemark(model.getRemark());
|
||||
return dto;
|
||||
}).collect(Collectors.toList());
|
||||
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
||||
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("机型导出.xlsx", StandardCharsets.UTF_8));
|
||||
if (CollectionUtil.isEmpty(datas)){
|
||||
datas.add(new ModelExcelExportDTO()
|
||||
.setNo("(必填)机型编号")
|
||||
.setRemark("备注信息,此行为提示信息,导入时请删除"));
|
||||
}
|
||||
new Workbook()
|
||||
.addSheet(new ListSheet<>(datas))
|
||||
.writeTo(response.getOutputStream());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,152 @@
|
|||
package com.nflg.wms.admin.service;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.nflg.wms.common.constant.STATE;
|
||||
import com.nflg.wms.common.pojo.ApiResult;
|
||||
import com.nflg.wms.common.pojo.dto.WorkbenchExcelExportDTO;
|
||||
import com.nflg.wms.common.pojo.dto.WorkbenchExcelImportDTO;
|
||||
import com.nflg.wms.common.pojo.qo.EnableQO;
|
||||
import com.nflg.wms.common.pojo.qo.ModelAddQO;
|
||||
import com.nflg.wms.common.pojo.qo.ModelSearchQO;
|
||||
import com.nflg.wms.common.pojo.qo.ModelUpdateQO;
|
||||
import com.nflg.wms.common.util.DateTimeUtil;
|
||||
import com.nflg.wms.common.util.EecExcelUtil;
|
||||
import com.nflg.wms.common.util.UserUtil;
|
||||
import com.nflg.wms.common.util.VUtil;
|
||||
import com.nflg.wms.repository.entity.Workbench;
|
||||
import com.nflg.wms.repository.service.IWorkbenchService;
|
||||
import com.nflg.wms.starter.service.FileUploadService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.ttzero.excel.entity.ListSheet;
|
||||
import org.ttzero.excel.entity.Workbook;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class WorkbenchControllerService {
|
||||
|
||||
@Resource
|
||||
private IWorkbenchService workbenchService;
|
||||
|
||||
@Resource
|
||||
private FileUploadService fileUploadService;
|
||||
|
||||
public void add(@Valid ModelAddQO request) {
|
||||
Workbench workbench= Convert.convert(Workbench.class, request);
|
||||
workbench.setCreateBy(UserUtil.getUserName());
|
||||
workbench.setCreateTime(LocalDateTime.now());
|
||||
workbenchService.add(workbench);
|
||||
}
|
||||
|
||||
public void update(@Valid ModelUpdateQO request) {
|
||||
Workbench workbench= Convert.convert(Workbench.class, request);
|
||||
workbench.setUpdateBy(UserUtil.getUserName());
|
||||
workbench.setUpdateTime(LocalDateTime.now());
|
||||
workbenchService.update(workbench);
|
||||
}
|
||||
|
||||
public void delete(@Valid @NotNull Long id) {
|
||||
workbenchService.delete(id);
|
||||
}
|
||||
|
||||
public void enable(@Valid EnableQO request) {
|
||||
workbenchService.enable(request);
|
||||
}
|
||||
|
||||
public IPage<Workbench> search(@Valid ModelSearchQO request) {
|
||||
return workbenchService.search(request);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public ApiResult importFromExcel(HttpServletResponse response, MultipartFile file) throws IOException {
|
||||
List<WorkbenchExcelImportDTO> data = EecExcelUtil.getExcelContext(file.getInputStream(), WorkbenchExcelImportDTO.class);
|
||||
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(data)).throwMessage("导入文件内容为空");
|
||||
if (updateCheckAndImport(data)) {
|
||||
return ApiResult.success();
|
||||
} else {
|
||||
try(ByteArrayOutputStream osOut = new ByteArrayOutputStream()) {
|
||||
new Workbook()
|
||||
.addSheet(new ListSheet<>(data))
|
||||
.writeTo(osOut);
|
||||
try(ByteArrayInputStream isIn = new ByteArrayInputStream(osOut.toByteArray())) {
|
||||
return ApiResult.error(STATE.DataNoCheckPass, "导入文件失败",fileUploadService.upload("temp/" + DateTimeUtil.format(LocalDate.now(),"yyyyMMdd")+"/"+ IdUtil.fastUUID() + ".xlsx", isIn));
|
||||
}
|
||||
}catch (Exception e){
|
||||
return ApiResult.error(STATE.BusinessError, "保存文件出错");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public boolean updateCheckAndImport(List<WorkbenchExcelImportDTO> data) {
|
||||
List<Workbench> workbenches = new ArrayList<>();
|
||||
for (WorkbenchExcelImportDTO dto : data) {
|
||||
Workbench workbench = new Workbench();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (Objects.isNull(dto.getNo())) {
|
||||
sb.append("机型编号不能为空;");
|
||||
} else {
|
||||
workbench = workbenchService.lambdaQuery().eq(Workbench::getNo, dto.getNo()).one();
|
||||
if (Objects.isNull(workbench)) {
|
||||
workbench = new Workbench()
|
||||
.setNo(dto.getNo())
|
||||
.setCreateBy(UserUtil.getUserName())
|
||||
.setCreateTime(LocalDateTime.now());
|
||||
}else {
|
||||
workbench.setUpdateBy(UserUtil.getUserName());
|
||||
workbench.setUpdateTime(LocalDateTime.now());
|
||||
}
|
||||
}
|
||||
workbench.setRemark(dto.getRemark());
|
||||
dto.setError(sb.toString());
|
||||
workbenches.add(workbench);
|
||||
}
|
||||
if (data.stream().noneMatch(it -> StrUtil.isNotBlank(it.getError()))) {
|
||||
workbenchService.saveOrUpdateBatch(workbenches);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void exportSelect(HttpServletResponse response, List<Long> ids) throws IOException {
|
||||
List<Workbench> users = CollectionUtil.isNotEmpty(ids)?workbenchService.listByIds(ids):new ArrayList<>();
|
||||
List<WorkbenchExcelExportDTO> datas = users.stream().map(model -> {
|
||||
WorkbenchExcelExportDTO dto = new WorkbenchExcelExportDTO();
|
||||
dto.setNo(model.getNo());
|
||||
dto.setRemark(model.getRemark());
|
||||
return dto;
|
||||
}).collect(Collectors.toList());
|
||||
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
||||
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("机台导出.xlsx", StandardCharsets.UTF_8));
|
||||
if (CollectionUtil.isEmpty(datas)){
|
||||
datas.add(new WorkbenchExcelExportDTO()
|
||||
.setNo("(必填)机台编号")
|
||||
.setRemark("备注信息,此行为提示信息,导入时请删除"));
|
||||
}
|
||||
new Workbook()
|
||||
.addSheet(new ListSheet<>(datas))
|
||||
.writeTo(response.getOutputStream());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package com.nflg.wms.common.pojo.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.ttzero.excel.annotation.ExcelColumn;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ModelExcelExportDTO {
|
||||
|
||||
/**
|
||||
* 机型编号
|
||||
*/
|
||||
@ExcelColumn("*机型编号")
|
||||
private String no;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@ExcelColumn("备注")
|
||||
private String remark;
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package com.nflg.wms.common.pojo.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.ttzero.excel.annotation.ExcelColumn;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class WorkbenchExcelExportDTO {
|
||||
|
||||
/**
|
||||
* 机台编号
|
||||
*/
|
||||
@ExcelColumn("*机台编号")
|
||||
private String no;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@ExcelColumn("备注")
|
||||
private String remark;
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package com.nflg.wms.common.pojo.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.ttzero.excel.annotation.ExcelColumn;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class WorkbenchExcelImportDTO {
|
||||
|
||||
/**
|
||||
* 机台编号
|
||||
*/
|
||||
@ExcelColumn("*机台编号")
|
||||
private String no;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@ExcelColumn("备注")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
@ExcelColumn("错误信息")
|
||||
private String error;
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ public class Model implements Serializable {
|
|||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,66 @@
|
|||
package com.nflg.wms.repository.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 机台
|
||||
* </p>
|
||||
*
|
||||
* @author 代码生成器生成
|
||||
* @since 2025
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
public class Workbench implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 机台编号
|
||||
*/
|
||||
private String no;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
private Boolean enable;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 最后更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 最后更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.nflg.wms.repository.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nflg.wms.repository.entity.Workbench;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 机台 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author 代码生成器生成
|
||||
* @since 2025
|
||||
*/
|
||||
public interface WorkbenchMapper extends BaseMapper<Workbench> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package com.nflg.wms.repository.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.nflg.wms.common.pojo.qo.EnableQO;
|
||||
import com.nflg.wms.common.pojo.qo.ModelSearchQO;
|
||||
import com.nflg.wms.repository.entity.Workbench;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 机台 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author 代码生成器生成
|
||||
* @since 2025
|
||||
*/
|
||||
public interface IWorkbenchService extends IService<Workbench> {
|
||||
|
||||
void add(Workbench workbench);
|
||||
|
||||
void update(Workbench workbench);
|
||||
|
||||
void delete(@Valid @NotNull Long id);
|
||||
|
||||
void enable(@Valid EnableQO request);
|
||||
|
||||
IPage<Workbench> search(@Valid ModelSearchQO request);
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
@ -46,6 +47,7 @@ public class ModelServiceImpl extends ServiceImpl<ModelMapper, Model> implements
|
|||
VUtil.trueThrowBusinessError(lambdaQuery().eq(Model::getNo, model.getNo()).ne(Model::getId, model.getId()).exists())
|
||||
.throwMessage("机型已存在");
|
||||
Model old = getById(model.getId());
|
||||
VUtil.trueThrowBusinessError(Objects.isNull(old)).throwMessage("机型不存在");
|
||||
updateById(model);
|
||||
Model newModel = getById(model.getId());
|
||||
auditLogService.addUpdate(Model.class, old, newModel, model.getUpdateBy());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,84 @@
|
|||
package com.nflg.wms.repository.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.nflg.wms.common.pojo.qo.EnableQO;
|
||||
import com.nflg.wms.common.pojo.qo.ModelSearchQO;
|
||||
import com.nflg.wms.common.util.UserUtil;
|
||||
import com.nflg.wms.common.util.VUtil;
|
||||
import com.nflg.wms.repository.entity.Workbench;
|
||||
import com.nflg.wms.repository.mapper.WorkbenchMapper;
|
||||
import com.nflg.wms.repository.service.IAuditLogService;
|
||||
import com.nflg.wms.repository.service.IWorkbenchService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 机台 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 代码生成器生成
|
||||
* @since 2025
|
||||
*/
|
||||
@Service
|
||||
public class WorkbenchServiceImpl extends ServiceImpl<WorkbenchMapper, Workbench> implements IWorkbenchService {
|
||||
|
||||
@Resource
|
||||
private IAuditLogService auditLogService;
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void add(Workbench workbench) {
|
||||
VUtil.trueThrowBusinessError(lambdaQuery().eq(Workbench::getNo, workbench.getNo()).exists()).throwMessage("机台已存在");
|
||||
save(workbench);
|
||||
auditLogService.addInsert(Workbench.class,workbench,workbench.getCreateBy());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void update(Workbench workbench) {
|
||||
VUtil.trueThrowBusinessError(lambdaQuery().eq(Workbench::getNo, workbench.getNo()).ne(Workbench::getId, workbench.getId()).exists())
|
||||
.throwMessage("机型已存在");
|
||||
Workbench old = getById(workbench.getId());
|
||||
VUtil.trueThrowBusinessError(Objects.isNull(old)).throwMessage("机台不存在");
|
||||
updateById(workbench);
|
||||
Workbench ninfo = getById(workbench.getId());
|
||||
auditLogService.addUpdate(Workbench.class, old, ninfo, workbench.getUpdateBy());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
Workbench old = getById(id);
|
||||
removeById(id);
|
||||
auditLogService.addDelete(Workbench.class, old, UserUtil.getUserName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable(EnableQO request) {
|
||||
Workbench old = getById(request.getId());
|
||||
lambdaUpdate()
|
||||
.set(Workbench::getEnable, request.getEnable())
|
||||
.set(Workbench::getUpdateBy, UserUtil.getUserName())
|
||||
.set(Workbench::getUpdateTime, LocalDateTime.now())
|
||||
.eq(Workbench::getId, request.getId())
|
||||
.update();
|
||||
Workbench newModel = getById(request.getId());
|
||||
auditLogService.addUpdate(Workbench.class, old, newModel, UserUtil.getUserName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<Workbench> search(ModelSearchQO request) {
|
||||
return lambdaQuery()
|
||||
.like(StrUtil.isNotBlank(request.getNo()),Workbench::getNo, request.getNo())
|
||||
.orderByDesc(Workbench::getId)
|
||||
.page(new Page<>(request.getPage(), request.getPageSize()));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nflg.wms.repository.mapper.WorkbenchMapper">
|
||||
|
||||
</mapper>
|
||||
|
|
@ -33,7 +33,7 @@ public class CodeGeneratorTest {
|
|||
)
|
||||
.strategyConfig(builder -> {
|
||||
builder
|
||||
.addInclude("model") //只生成指定表
|
||||
.addInclude("v_user_supplier") //只生成指定表
|
||||
.entityBuilder().idType(IdType.ASSIGN_ID)
|
||||
.enableLombok()
|
||||
.enableChainModel()
|
||||
|
|
|
|||
Loading…
Reference in New Issue