自有人员后台

This commit is contained in:
lizhenhua 2025-06-27 09:03:31 +08:00
parent 77c688fd5f
commit 9fd33300bf
6 changed files with 337 additions and 0 deletions

View File

@ -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;
/**
* @Authorlizhenhua
* @Date2025/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<Ownerdomin> 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<Ownerdomin> util = new ExcelUtil<>(Ownerdomin.class);
List<Ownerdomin> 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);
}
}

View File

@ -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;
/**
* @Authorliang.chao
* @Date2024/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;
}

View File

@ -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<Ownerdomin> list(Ownerdomin ownerdomin);
Integer add(Ownerdomin ownerdomin);
Integer edit(Ownerdomin ownerdomin);
Integer del(Ownerdomin ownerdomin);
}

View File

@ -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<Ownerdomin> list(Ownerdomin ownerdomin);
Integer add(Ownerdomin ownerdomin);
Integer edit(Ownerdomin ownerdomin);
Integer del(Ownerdomin ownerdomin);
String importMaProp(List<Ownerdomin> maPropInfoList, String type, Long userId);
}

View File

@ -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<Ownerdomin> list(Ownerdomin ownerdomin) {
ownerdomin.setCreator(SecurityUtils.getLoginUser().getSysUser().getUserId()+"");
ownerdomin.setCompanyId(SecurityUtils.getLoginUser().getSysUser().getCompanyId());
List<Ownerdomin> 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<Ownerdomin> 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();
}
}

View File

@ -0,0 +1,46 @@
<?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.bonus.material.owner.mapper.OwnerMapper">
<insert id="add">
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})
</insert>
<update id="edit">
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>
<update id="del">
update ma_own_manage set
is_active =1
where id = #{id}
</update>
<select id="list" resultType="com.bonus.material.owner.domain.Ownerdomin">
select id, ma_type as maType, ma_name as maName, model_id as modelId,ma_model as maModel,
ma_num as maNum, create_time as createTime, creator, remark
from ma_own_manage
<where>
is_active = 0
<if test="type!= null and type != ''">
and type like concat('%', #{type}, '%')
</if>
<if test="maModel!= null and maModel != ''">
and ma_model like concat('%', #{maModel}, '%')
</if>
<if test="maName != null and maName != ''">
and ma_name like concat('%', #{maName}, '%')
</if>
</where>
</select>
</mapper>