From 9fd33300bfe8f97a912f802de30f1e472b78fd7e Mon Sep 17 00:00:00 2001 From: lizhenhua <1075222162@qq.com> Date: Fri, 27 Jun 2025 09:03:31 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E6=9C=89=E4=BA=BA=E5=91=98=E5=90=8E?= =?UTF-8?q?=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../owner/controller/OwnerController.java | 106 ++++++++++++++++++ .../material/owner/domain/Ownerdomin.java | 56 +++++++++ .../material/owner/mapper/OwnerMapper.java | 18 +++ .../material/owner/service/OwnerService.java | 18 +++ .../owner/service/impl/OwnerServiceImpl.java | 93 +++++++++++++++ .../mapper/material/owner/OwnerMapper.xml | 46 ++++++++ 6 files changed, 337 insertions(+) create mode 100644 bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/controller/OwnerController.java create mode 100644 bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/domain/Ownerdomin.java create mode 100644 bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/mapper/OwnerMapper.java create mode 100644 bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/service/OwnerService.java create mode 100644 bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/service/impl/OwnerServiceImpl.java create mode 100644 bonus-modules/bonus-material-mall/src/main/resources/mapper/material/owner/OwnerMapper.xml diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/controller/OwnerController.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/controller/OwnerController.java new file mode 100644 index 0000000..bf36a78 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/controller/OwnerController.java @@ -0,0 +1,106 @@ +package com.bonus.material.owner.controller; + + +import com.bonus.common.core.utils.poi.ExcelUtil; +import com.bonus.common.core.web.controller.BaseController; +import com.bonus.common.core.web.domain.AjaxResult; +import com.bonus.common.security.utils.SecurityUtils; +import com.bonus.material.contract.domain.BmContract; +import com.bonus.material.device.domain.dto.DevInfoImpDto; +import com.bonus.material.owner.domain.Ownerdomin; +import com.bonus.material.owner.service.OwnerService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import java.io.UnsupportedEncodingException; +import java.util.List; + +/** + * @Author:lizhenhua + * @Date:2025/6/26- 9:14 + */ +@RestController +@RequestMapping("/owner") +@Api(value = "自有装备管理", tags = "自有装备管理") +public class OwnerController extends BaseController { + @Resource + private OwnerService ownerService; + + @ApiOperation(value = "自有装备管理列表") + @GetMapping("/list") + public AjaxResult list(Ownerdomin ownerdomin) { + startPage(); + List list = ownerService.list(ownerdomin); + return AjaxResult.success(getDataTable(list)); + } + + @ApiOperation(value = "自有装备管理新增") + @PostMapping("/add") + public AjaxResult add(@RequestBody Ownerdomin ownerdomin) throws UnsupportedEncodingException { + Integer i = ownerService.add(ownerdomin); + if (i > 0){ + return AjaxResult.success("新增成功"); + }else { + return AjaxResult.error("新增失败"); + } + } + + @ApiOperation(value = "自有装备管理修改") + @PostMapping("/edit") + public AjaxResult edit(@RequestBody Ownerdomin ownerdomin) throws UnsupportedEncodingException { + Integer i = ownerService.edit(ownerdomin); + if (i > 0){ + return AjaxResult.success("修改成功"); + }else { + return AjaxResult.error("修改失败"); + } + } + @ApiOperation(value = "自有装备管理删除") + @PostMapping("/del") + public AjaxResult del(@RequestBody Ownerdomin ownerdomin) { + Integer i = ownerService.del(ownerdomin); + if (i > 0){ + return AjaxResult.success("删除成功"); + }else { + return AjaxResult.error("删除失败"); + } + } + @ApiOperation(value = "装备批量录入") + @PostMapping("/importData") + public AjaxResult importData(@RequestParam("file") MultipartFile file, + String type) throws Exception { + // 1. 空文件判断 + if (file == null || file.isEmpty()) { + return AjaxResult.error("上传的文件不能为空!"); + } + + // 2. 文件名及格式校验 + String fileName = file.getOriginalFilename(); + if (fileName != null) { + String fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1); + long fileSize = file.getSize(); + if (!fileExtension.equalsIgnoreCase("xls") && !fileExtension.equalsIgnoreCase("xlsx")) { + return AjaxResult.error("文件后缀名必须为 xls 或 xlsx"); + } else if (fileSize > 10 * 1024 * 1024) { + return AjaxResult.error("文件大小不能超过 10MB"); + } + } + + // 3. 读取文件内容并处理 + ExcelUtil util = new ExcelUtil<>(Ownerdomin.class); + List maPropInfoList = util.importExcel(file.getInputStream()); + + if (maPropInfoList == null || maPropInfoList.isEmpty()) { + return AjaxResult.error("导入的数据不能为空!"); + } + + Long userId = SecurityUtils.getLoginUser().getUserid(); + String message = ownerService.importMaProp(maPropInfoList, type, userId); + + return AjaxResult.success(message); + } + +} diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/domain/Ownerdomin.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/domain/Ownerdomin.java new file mode 100644 index 0000000..d4d6c30 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/domain/Ownerdomin.java @@ -0,0 +1,56 @@ +package com.bonus.material.owner.domain; + +import com.bonus.common.biz.domain.BmFileInfo; +import com.bonus.common.core.annotation.Excel; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; +import java.util.List; + +/** + * @Author:liang.chao + * @Date:2024/12/13 - 9:17 + */ +@Data +public class Ownerdomin { + @ApiModelProperty(value = "主键ID") + private Integer id; + + @ApiModelProperty(value = "装备分类") + private String maType; + + @ApiModelProperty(value = "装备名称") + @Excel(name = "装备名称") + private String maName; + + @ApiModelProperty(value = "装备规格") + @Excel(name = "装备规格") + private String maModel; + + @ApiModelProperty(value = "规格id") + private Integer modelId; + + @ApiModelProperty(value = "类型(1租赁 2自有)") + private String type; + + @ApiModelProperty(value = "所属公司") + private Long companyId; + + @ApiModelProperty(value = "创建时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date createTime; + + @ApiModelProperty(value = "装备数量") + @Excel(name = "装备数量") + private Integer maNum; + + @ApiModelProperty(value = "创建人") + private String creator; + + @ApiModelProperty(value = "备注") + @Excel(name = "备注") + private String remark; + +} diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/mapper/OwnerMapper.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/mapper/OwnerMapper.java new file mode 100644 index 0000000..6f468a5 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/mapper/OwnerMapper.java @@ -0,0 +1,18 @@ +package com.bonus.material.owner.mapper; + + +import com.bonus.material.owner.domain.Ownerdomin; + +import java.util.List; + +public interface OwnerMapper { + + + List list(Ownerdomin ownerdomin); + + Integer add(Ownerdomin ownerdomin); + + Integer edit(Ownerdomin ownerdomin); + + Integer del(Ownerdomin ownerdomin); +} diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/service/OwnerService.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/service/OwnerService.java new file mode 100644 index 0000000..841ee43 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/service/OwnerService.java @@ -0,0 +1,18 @@ +package com.bonus.material.owner.service; + +import com.bonus.material.owner.domain.Ownerdomin; + +import java.util.List; + +public interface OwnerService { + + List list(Ownerdomin ownerdomin); + + Integer add(Ownerdomin ownerdomin); + + Integer edit(Ownerdomin ownerdomin); + + Integer del(Ownerdomin ownerdomin); + + String importMaProp(List maPropInfoList, String type, Long userId); +} diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/service/impl/OwnerServiceImpl.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/service/impl/OwnerServiceImpl.java new file mode 100644 index 0000000..38a5f09 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/service/impl/OwnerServiceImpl.java @@ -0,0 +1,93 @@ +package com.bonus.material.owner.service.impl; + +import com.bonus.common.core.exception.ServiceException; +import com.bonus.common.core.utils.StringUtils; +import com.bonus.common.core.utils.bean.BeanUtils; +import com.bonus.common.core.utils.bean.BeanValidators; +import com.bonus.common.security.utils.SecurityUtils; +import com.bonus.material.device.domain.DevInfo; +import com.bonus.material.device.domain.dto.DevInfoImpDto; +import com.bonus.material.owner.domain.Ownerdomin; +import com.bonus.material.owner.mapper.OwnerMapper; +import com.bonus.material.owner.service.OwnerService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import javax.validation.Validator; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class OwnerServiceImpl implements OwnerService { + + @Resource + private OwnerMapper ownerMapper; + + @Resource + protected Validator validator; + + @Override + public List list(Ownerdomin ownerdomin) { + ownerdomin.setCreator(SecurityUtils.getLoginUser().getSysUser().getUserId()+""); + ownerdomin.setCompanyId(SecurityUtils.getLoginUser().getSysUser().getCompanyId()); + List list = ownerMapper.list(ownerdomin); + return list; + } + + @Override + public Integer add(Ownerdomin ownerdomin) { + ownerdomin.setCreator(SecurityUtils.getLoginUser().getSysUser().getUserId()+""); + ownerdomin.setCompanyId(SecurityUtils.getLoginUser().getSysUser().getCompanyId()); + return ownerMapper.add(ownerdomin); + } + + @Override + public Integer edit(Ownerdomin ownerdomin) { + return ownerMapper.edit(ownerdomin); + } + + @Override + public Integer del(Ownerdomin ownerdomin) { + return ownerMapper.del(ownerdomin); + } + + @Override + public String importMaProp(List maPropInfoList, String type, Long userId) { + if (StringUtils.isNull(maPropInfoList) || maPropInfoList.isEmpty()) { + throw new ServiceException("导入的数据不能为空!"); + } + +// 过滤掉空对象或空行 + maPropInfoList = maPropInfoList.stream() + .filter(Objects::nonNull) + .filter(item -> StringUtils.isNotEmpty(item.getMaName())) // 替换为你必须字段 + .collect(Collectors.toList()); + + int failureNum = 0; + StringBuilder failureMsg = new StringBuilder(); + StringBuilder successMsg = new StringBuilder(); + + for (Ownerdomin devInfo : maPropInfoList) { + try { + BeanValidators.validateWithException(validator, devInfo); + devInfo.setCreator(userId + ""); + Ownerdomin ownerdomin = new Ownerdomin(); + BeanUtils.copyProperties(devInfo, ownerdomin); + ownerdomin.setType(type); + ownerdomin.setCompanyId(SecurityUtils.getLoginUser().getSysUser().getCompanyId()); + ownerMapper.add(ownerdomin); + successMsg.append(" 导入成功"); + } catch (Exception e) { + failureNum++; + String msg = " 导入失败:"; + failureMsg.append(msg).append(e.getMessage()); + log.error(msg, e); + } + } + + return successMsg.toString(); + } +} diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/owner/OwnerMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/owner/OwnerMapper.xml new file mode 100644 index 0000000..0f842a5 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/owner/OwnerMapper.xml @@ -0,0 +1,46 @@ + + + + + insert into ma_own_manage( + ma_type, ma_name, model_id, ma_model, ma_num, + creator, remark,company_id,type) + values(#{maType}, #{maName}, #{modelId}, #{maModel}, #{maNum}, #{creator}, #{remark}, #{companyId},#{type}) + + + update ma_own_manage set + ma_type = #{maType}, + ma_name = #{maName}, + model_id = #{modelId}, + ma_model = #{maModel}, + ma_num = #{maNum}, + creator = #{creator}, + remark = #{remark} + where id = #{id} + + + update ma_own_manage set + is_active =1 + where id = #{id} + + + +