commit
d023557a68
@ -1,28 +1,23 @@
|
||||
package com.ktg.mes.dv.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.ktg.common.constant.UserConstants;
|
||||
import com.ktg.mes.wm.utils.WmBarCodeUtil;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ktg.common.annotation.Log;
|
||||
import com.ktg.common.constant.UserConstants;
|
||||
import com.ktg.common.core.controller.BaseController;
|
||||
import com.ktg.common.core.domain.AjaxResult;
|
||||
import com.ktg.common.core.page.TableDataInfo;
|
||||
import com.ktg.common.enums.BusinessType;
|
||||
import com.ktg.common.utils.SecurityUtils;
|
||||
import com.ktg.common.utils.poi.ExcelUtil;
|
||||
import com.ktg.mes.dv.domain.DvMachinery;
|
||||
import com.ktg.mes.dv.service.IDvMachineryService;
|
||||
import com.ktg.common.utils.poi.ExcelUtil;
|
||||
import com.ktg.common.core.page.TableDataInfo;
|
||||
import com.ktg.mes.wm.utils.WmBarCodeUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备Controller
|
||||
@ -108,4 +103,20 @@ public class DvMachineryController extends BaseController
|
||||
{
|
||||
return toAjax(dvMachineryService.deleteDvMachineryByMachineryIds(machineryIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 依据上传的文件批量更新或新增设备
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('mes:dv:machinery:import')")
|
||||
@Log(title = "设备", businessType = BusinessType.IMPORT)
|
||||
@PostMapping("/importData")
|
||||
public AjaxResult importData(MultipartFile file,
|
||||
@RequestParam(name = "updateSupport", defaultValue = "false") boolean updateSupport) throws Exception {
|
||||
ExcelUtil<DvMachinery> util = new ExcelUtil<>(DvMachinery.class);
|
||||
List<DvMachinery> dvMachineryList = util.importExcel(file.getInputStream());
|
||||
String operName = SecurityUtils.getUsername();
|
||||
String message = dvMachineryService.importMachinery(dvMachineryList, updateSupport, operName);
|
||||
return AjaxResult.success("导入成功,共导入 " + message + " 条数据");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.ktg.mes.dv.domain;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ktg.common.annotation.Excel;
|
||||
import com.ktg.common.core.domain.BaseEntity;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* 设备对象 dv_machinery
|
||||
@ -19,11 +19,11 @@ public class DvMachinery extends BaseEntity
|
||||
private Long machineryId;
|
||||
|
||||
/** 设备类型编码 */
|
||||
@Excel(name = "设备类型编码")
|
||||
@Excel(name = "设备编码")
|
||||
private String machineryCode;
|
||||
|
||||
/** 设备类型名称 */
|
||||
@Excel(name = "设备类型名称")
|
||||
@Excel(name = "设备名称")
|
||||
private String machineryName;
|
||||
|
||||
/** 品牌 */
|
||||
|
@ -1,8 +1,9 @@
|
||||
package com.ktg.mes.dv.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ktg.mes.dv.domain.DvMachinery;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备Mapper接口
|
||||
*
|
||||
@ -20,6 +21,14 @@ public interface DvMachineryMapper
|
||||
public DvMachinery selectDvMachineryByMachineryId(Long machineryId);
|
||||
|
||||
/**
|
||||
* 依据设备编码查询设备
|
||||
*
|
||||
* @param machineryCode 设备编码
|
||||
* @return 设备
|
||||
*/
|
||||
public DvMachinery selectByMachineryCode( String machineryCode);
|
||||
|
||||
/**
|
||||
* 查询设备列表
|
||||
*
|
||||
* @param dvMachinery 设备
|
||||
@ -58,4 +67,5 @@ public interface DvMachineryMapper
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDvMachineryByMachineryIds(Long[] machineryIds);
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
package com.ktg.mes.dv.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ktg.mes.dv.domain.DvMachinery;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备Service接口
|
||||
*
|
||||
@ -58,4 +59,15 @@ public interface IDvMachineryService
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDvMachineryByMachineryId(Long machineryId);
|
||||
|
||||
/**
|
||||
* 依据上传的文件,批量导入或更新设备信息
|
||||
*
|
||||
* @param machineryList 设备信息列表
|
||||
* @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
|
||||
* @param operName 操作用户
|
||||
* @return 结果
|
||||
*/
|
||||
public String importMachinery(List<DvMachinery> machineryList, Boolean isUpdateSupport, String operName);
|
||||
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
package com.ktg.mes.dv.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import com.ktg.common.utils.DateUtils;
|
||||
import com.ktg.mes.dv.domain.DvMachinery;
|
||||
import com.ktg.mes.dv.mapper.DvMachineryMapper;
|
||||
import com.ktg.mes.dv.service.IDvMachineryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ktg.mes.dv.mapper.DvMachineryMapper;
|
||||
import com.ktg.mes.dv.domain.DvMachinery;
|
||||
import com.ktg.mes.dv.service.IDvMachineryService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备Service业务层处理
|
||||
@ -93,4 +94,39 @@ public class DvMachineryServiceImpl implements IDvMachineryService
|
||||
{
|
||||
return dvMachineryMapper.deleteDvMachineryByMachineryId(machineryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 依据上传的文件更新或插入设备信息
|
||||
*/
|
||||
@Override
|
||||
public String importMachinery(List<DvMachinery> machineryList, Boolean isUpdateSupport, String operName) {
|
||||
if (machineryList == null || machineryList.isEmpty()) {
|
||||
return "导入数据为空";
|
||||
}
|
||||
int successCount = 0;
|
||||
int failureCount = 0;
|
||||
for (DvMachinery machinery : machineryList) {
|
||||
// 去除空格
|
||||
String machineryCode = machinery.getMachineryCode().trim();
|
||||
DvMachinery existing = dvMachineryMapper.selectByMachineryCode(machineryCode);
|
||||
if (existing != null) {
|
||||
if (isUpdateSupport) {
|
||||
// 更新数据
|
||||
machinery.setMachineryId(existing.getMachineryId()); // 确保使用现有 ID 进行更新
|
||||
dvMachineryMapper.updateDvMachinery(machinery);
|
||||
successCount++;
|
||||
} else {
|
||||
// 不更新数据
|
||||
failureCount++;
|
||||
}
|
||||
} else {
|
||||
// 新增数据
|
||||
dvMachineryMapper.insertDvMachinery(machinery);
|
||||
successCount++;
|
||||
}
|
||||
}
|
||||
return String.format("操作用户:%s,导入完成,成功 %d 条,失败 %d 条。", operName, successCount, failureCount);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -56,6 +56,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
where machinery_id = #{machineryId}
|
||||
</select>
|
||||
|
||||
<select id="selectByMachineryCode" parameterType="string" resultMap="DvMachineryResult">
|
||||
<include refid="selectDvMachineryVo"/>
|
||||
where machinery_code= #{machineryCode}
|
||||
</select>
|
||||
|
||||
<insert id="insertDvMachinery" parameterType="DvMachinery" useGeneratedKeys="true" keyProperty="machineryId">
|
||||
insert into dv_machinery
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
|
Loading…
Reference in New Issue
Block a user