evoToK3Cloud/ruoyi-system/src/main/java/com/ruoyi/system/controller/EleMaterialsController.java

544 lines
23 KiB
Java

package com.ruoyi.system.controller;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.Future;
import java.util.concurrent.ExecutionException;
import com.alibaba.fastjson.JSONObject;
import com.kingdee.bos.webapi.entity.SuccessEntity;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.excel.ExcelResult;
import com.ruoyi.common.utils.JdUtils;
import com.ruoyi.system.domain.EleMaterials;
import com.ruoyi.system.domain.ImMaterial;
import com.ruoyi.system.domain.dto.*;
import com.ruoyi.system.domain.vo.ExcelVo;
import com.ruoyi.system.mapper.ImMaterialMapper;
import com.ruoyi.system.runner.JdUtil;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.EleMaterialsVo;
import com.ruoyi.system.domain.bo.EleMaterialsBo;
import com.ruoyi.system.service.IEleMaterialsService;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;
/**
* 电器物料管理
*
* @author tzy
* @date 2024-12-28
*/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/materials")
public class EleMaterialsController extends BaseController {
private final IEleMaterialsService iEleMaterialsService;
private final ImMaterialMapper materialMapper;
private static final Logger log = LoggerFactory.getLogger(EleMaterialsController.class);
/**
* 查询电器物料管理列表
*/
@SaCheckPermission("system:materials:list")
@GetMapping("/list")
public TableDataInfo<EleMaterialsVo> list(EleMaterialsBo bo, PageQuery pageQuery) {
return iEleMaterialsService.queryPageList(bo, pageQuery);
}
/**
* 导出电器物料管理列表
*/
@SaCheckPermission("system:materials:export")
@Log(title = "电器物料管理", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(EleMaterialsBo bo, HttpServletResponse response) {
List<EleMaterialsVo> list = iEleMaterialsService.queryList(bo);
ExcelUtil.exportExcel(list, "电器物料管理", EleMaterialsVo.class, response);
}
/**
* 获取电器物料管理详细信息
*
* @param id 主键
*/
@SaCheckPermission("system:materials:query")
@GetMapping("/{id}")
public R<EleMaterialsVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
return R.ok(iEleMaterialsService.queryById(id));
}
/**
* 新增电器物料管理
*/
@SaCheckPermission("system:materials:add")
@Log(title = "电器物料管理", businessType = BusinessType.INSERT)
@RepeatSubmit()
@PostMapping()
public R<Void> add(@Validated(AddGroup.class) @RequestBody EleMaterialsBo bo) {
return toAjax(iEleMaterialsService.insertByBo(bo));
}
/**
* 修改电器物料管理
*/
@SaCheckPermission("system:materials:edit")
@Log(title = "电器物料管理", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PutMapping()
public R<Void> edit(@Validated(EditGroup.class) @RequestBody EleMaterialsBo bo) {
return toAjax(iEleMaterialsService.updateByBo(bo));
}
/**
* 删除电器物料管理
*
* @param ids 主键串
*/
@SaCheckPermission("system:materials:remove")
@Log(title = "电器物料管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
return toAjax(iEleMaterialsService.deleteWithValidByIds(Arrays.asList(ids), true));
}
/**
* 将物料上传至金蝶
*/
@SaCheckPermission("system:materials:addToK3")
@Log(title = "将物料上传至金蝶", businessType = BusinessType.INSERT)
@RepeatSubmit()
@PostMapping("/addToK3")
public R<List<EleMaterials>> addToK3() {
return iEleMaterialsService.addToJindie();
}
@Log(title = "电器物料导入", businessType = BusinessType.IMPORT)
@SaCheckPermission("system:materials:importData")
@PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ExcelVo importData(@RequestParam("file") MultipartFile file, HttpServletResponse response) throws Exception {
String originalFilename = file.getOriginalFilename();
log.info("读取文件名: " + originalFilename);
// 确保文件不为空
if (file.isEmpty()) {
throw new RuntimeException("上传的文件为空");
}
// 导入 Excel 数据
ExcelResult<EleMaterialsVo> eleMaterialsVoExcelResult = ExcelUtil.importExcelSheet1(file.getInputStream(),
EleMaterialsVo.class, true);
// 检查导入结果
if (eleMaterialsVoExcelResult.getList() == null || eleMaterialsVoExcelResult.getList().isEmpty()) {
throw new RuntimeException("导入的 Excel 文件没有有效数据");
}
// 返回导入结果
ExcelVo jsonObject = new ExcelVo();
jsonObject.setList(eleMaterialsVoExcelResult.getList());
return jsonObject;
}
@SaCheckPermission("system:materials:exportData")
@Log(title = "电器物料数据导出", businessType = BusinessType.EXPORT)
@PostMapping(value = "/exportData")
public void importData1(@RequestBody ExcelVo excelVo, HttpServletResponse response) throws Exception {
// 把 result 返回
try {
// 保存数据并导出 Excel
if (iEleMaterialsService.saveData(excelVo.getList(), response)) {
log.info("上传物料成功");
} else {
log.error("导入失败");
}
} catch (Exception e) {
log.error("导出 Excel 文件时发生错误: ", e);
// 这里可以选择记录日志或处理其他逻辑,但不要发送错误响应
}
}
@Log(title = "禁用物料", businessType = BusinessType.IMPORT)
@SaCheckPermission("system:materials:importDataTime")
@PostMapping(value = "/importMA", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public R<Void> importMA(@RequestParam("file") MultipartFile file) throws Exception {
String originalFilename = file.getOriginalFilename();
log.info("读取文件名: " + originalFilename);
ExcelResult<EleMaterialsVo> result = ExcelUtil.importExcelSheet1(file.getInputStream(), EleMaterialsVo.class,
true);
List<EleMaterialsVo> list = result.getList();
for (EleMaterialsVo processRouteVo : list) {
ArrayList<SuccessEntity> jinyong = JdUtils.jinyong(processRouteVo.getMaterialCode());
}
return R.ok("更新成功");
}
@Log(title = "禁用子项中包含的物料", businessType = BusinessType.IMPORT)
@SaCheckPermission("system:materials:importDataTime")
@PostMapping(value = "/importMA1", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public R<Void> importMA1(@RequestParam("file") MultipartFile file) throws Exception {
String originalFilename = file.getOriginalFilename();
log.info("读取文件名: " + originalFilename);
ExcelResult<EleMaterialsVo> result = ExcelUtil.importExcelSheet1(file.getInputStream(), EleMaterialsVo.class,
true);
List<EleMaterialsVo> list = result.getList();
// 创建一个固定大小的线程池
ExecutorService executorService = Executors.newFixedThreadPool(10); // 可以根据需要调整线程数
for (EleMaterialsVo processRouteVo : list) {
executorService.submit(() -> {
log.info("查询对应的bom中包含的子项物料=====>: " + processRouteVo.getMaterialCode());
List<JinYongDTO> jinyong = JdUtil.getFuji(processRouteVo.getMaterialCode());
log.info("查询对应的父级物料清单bom: " + jinyong);
for (JinYongDTO jinYongDTO : jinyong) {
String fNumber = jinYongDTO.getFNumber(); // 确保使用正确的字段名
// 调用金蝶接口用料订单禁用
try {
JdUtil.jtestForbidMaterial(fNumber);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
// 关闭线程池并等待所有任务完成
executorService.shutdown();
try {
if (!executorService.awaitTermination(60, TimeUnit.MINUTES)) {
executorService.shutdownNow(); // 超时后强制关闭
}
} catch (InterruptedException e) {
executorService.shutdownNow();
Thread.currentThread().interrupt(); // 保留中断状态
}
return R.ok("更新成功");
}
@Log(title = "更新工时", businessType = BusinessType.IMPORT)
@SaCheckPermission("system:materials:updaDateGongshi")
@PostMapping(value = "/updaDateGongshi", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public R<Void> updaDateGongshi(@RequestParam("file") MultipartFile file) throws Exception {
String originalFilename = file.getOriginalFilename();
ExcelResult<EleMaterialsVo> result = ExcelUtil.importExcelSheet1(file.getInputStream(), EleMaterialsVo.class,
true);
List<EleMaterialsVo> list = result.getList();
// 创建固定大小的线程池
ExecutorService executor = Executors.newFixedThreadPool(10); // 可以根据需要调整线程数
for (EleMaterialsVo processRouteVo : list) {
executor.submit(() -> {
List<JdEntry> entryID = JdUtil.getEntryID(processRouteVo.getMaterialCode());
for (JdEntry jdEntry : entryID) {
int FMATERIALID = jdEntry.getFMATERIALID();
int fEntryId = jdEntry.getFEntryId();
log.info("FMATERIALID: " + FMATERIALID);
log.info("fEntryId: " + fEntryId);
log.info("物料编码: " + processRouteVo.getMaterialValue());
log.info("工时: " + processRouteVo.getMaterialCode());
try {
JdUtil.atestSaveMaterial(FMATERIALID, fEntryId, processRouteVo.getMaterialCode(),
Double.parseDouble(processRouteVo.getMaterialValue()));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
// 关闭线程池
executor.shutdown();
while (!executor.isTerminated()) {
// 等待所有任务完成
}
return R.ok("更新成功");
}
@Log(title = "更新货主信息", businessType = BusinessType.IMPORT)
@SaCheckPermission("system:route:updateHuoZhu")
@PostMapping(value = "/updateHuoZhu", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public R<Void> updateHuoZhu(@RequestParam("file") MultipartFile file) throws Exception {
String originalFilename = file.getOriginalFilename();
log.info("读取文件名: " + originalFilename);
ExcelResult<JdVMIVo> result = ExcelUtil.importExcelSheet1(file.getInputStream(), JdVMIVo.class, true);
List<JdVMIVo> list = result.getList();
// 创建固定大小的线程池
ExecutorService executor = Executors.newFixedThreadPool(10); // 可以根据需要调整线程数
for (JdVMIVo vmi : list) {
executor.submit(() -> {
List<JdHuoZhu> entryID = JdUtil.getFID(vmi.getMaterialCode());
for (JdHuoZhu jdEntryVmi : entryID) {
int fmaterialid = jdEntryVmi.getFID();
int fEntryId1 = jdEntryVmi.getFTreeEntityFENTRYID();
try {
JdUtil.updateHuozhu(fmaterialid, fEntryId1, vmi.getMaterialCode());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
// 关闭线程池
executor.shutdown();
while (!executor.isTerminated()) {
// 等待所有任务完成
}
return R.ok("更新成功");
}
@Log(title = "更新VMI仓位", businessType = BusinessType.IMPORT)
@SaCheckPermission("system:route:updaDateCangwei")
@PostMapping(value = "/updaDateCangwei", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public R<Void> updaDateCangwei(@RequestParam("file") MultipartFile file) throws Exception {
String originalFilename = file.getOriginalFilename();
log.info("读取文件名: " + originalFilename);
ExcelResult<JdVMIVo> result = ExcelUtil.importExcelSheet1(file.getInputStream(), JdVMIVo.class, true);
List<JdVMIVo> list = result.getList();
// 创建固定大小的线程池
ExecutorService executor = Executors.newFixedThreadPool(10);
list.forEach(vmi -> executor.submit(() -> {
log.info("===============>开始查询物料编码: " + vmi.getMaterialCode() + "的entryID");
List<JdEntryVmi> entryID = JdUtil.getEntryID2(vmi.getMaterialCode());
entryID.forEach(jdEntryVmi -> {
int fmaterialid = jdEntryVmi.getFMATERIALID();
int fEntryId1 = jdEntryVmi.getFEntryId1();
int fEntryId3 = jdEntryVmi.getFEntryId3();
try {
log.info("=====================>开始更新 " + vmi.getMaterialCode() + " 的VMI仓位");
JdUtil.updateVMI(fmaterialid, fEntryId1, fEntryId3, vmi.getFStockId(), vmi.getFStockPlaceId());
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}));
// 关闭线程池并等待所有任务完成
executor.shutdown();
try {
if (!executor.awaitTermination(60, TimeUnit.MINUTES)) {
executor.shutdownNow(); // 超时后强制关闭
}
} catch (InterruptedException e) {
executor.shutdownNow();
Thread.currentThread().interrupt(); // 保留中断状态
}
return R.ok("更新成功");
}
@Log(title = "更新安全库存-最大订货量", businessType = BusinessType.IMPORT)
@SaCheckPermission("system:route:updaDateKuCun")
@PostMapping(value = "/updateKuCun", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public R<Void> updateKuCun(@RequestParam("file") MultipartFile file) throws Exception {
String originalFilename = file.getOriginalFilename();
log.info("读取文件名: " + originalFilename);
ExcelResult<JDSafeStockDTO> result = ExcelUtil.importExcelSheet1(file.getInputStream(), JDSafeStockDTO.class,
true);
List<JDSafeStockDTO> list = result.getList();
// 创建固定大小的线程池
ExecutorService executor = Executors.newFixedThreadPool(10); // 可以根据需要调整线程数
list.forEach(vmi -> executor.submit(() -> {
log.info("===============>开始查询物料编码: " + vmi.getMaterialCode() + "的entryID");
List<SubHeadEntityDTO> entryID = JdUtil.getSubHeadEntity1Id(vmi.getMaterialCode());
entryID.forEach(jdEntryVmi -> {
int fmaterialid = jdEntryVmi.getFMATERIALID();
int fEntryId1 = jdEntryVmi.getFEntryId1();
int fMaxPOQty = vmi.getFMinPOQty();
int FSafeStock = vmi.getFSafeStock();
try {
log.info("=====================>开始更新 " + vmi.getMaterialCode() + " 的安全库存");
JdUtil.updateKunCun(fmaterialid, fEntryId1, fMaxPOQty, FSafeStock);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}));
// 关闭线程池并等待所有任务完成
executor.shutdown();
try {
if (!executor.awaitTermination(60, TimeUnit.MINUTES)) {
executor.shutdownNow(); // 超时后强制关闭
}
} catch (InterruptedException e) {
executor.shutdownNow();
Thread.currentThread().interrupt(); // 保留中断状态
}
return R.ok("更新成功");
}
@Log(title = "更新安全库存", businessType = BusinessType.IMPORT)
@SaCheckPermission("system:route:updateFOldNumber")
@PostMapping(value = "/updateFOldNumber", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public R<Void> updateFOldNumber(@RequestParam("file") MultipartFile file) throws Exception {
String originalFilename = file.getOriginalFilename();
log.info("读取文件名: {}", originalFilename);
ExcelResult<JDMaterialOldNumber> result = ExcelUtil.importExcelSheet1(file.getInputStream(), JDMaterialOldNumber.class, true);
List<JDMaterialOldNumber> list = result.getList();
// 创建固定大小的线程池
ExecutorService executor = Executors.newFixedThreadPool(10); // 可以根据需要调整线程数
try {
List<Future<Void>> futures = new ArrayList<>();
for (JDMaterialOldNumber vmi : list) {
futures.add(executor.submit(() -> {
JdUtil.updateOldFuNumber(vmi.getFMATERIALID(), vmi.getFNumber(), vmi.getFOldNumber());
return null; // 返回值可以是 Void
}));
}
// 等待所有任务完成并处理异常
for (Future<Void> future : futures) {
try {
future.get(); // 获取结果,如果有异常会抛出
} catch (ExecutionException e) {
log.error("更新物料时发生异常: {}", e.getCause().getMessage());
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt(); // 保留中断状态
log.error("线程被中断: {}", e.getMessage());
} finally {
executor.shutdown(); // 确保线程池关闭
try {
if (!executor.awaitTermination(60, TimeUnit.SECONDS)) {
executor.shutdownNow(); // 超时后强制关闭
}
} catch (InterruptedException e) {
executor.shutdownNow();
Thread.currentThread().interrupt(); // 保留中断状态
}
}
return R.ok("更新成功");
}
@Log(title = "更新物料单重", businessType = BusinessType.IMPORT)
@SaCheckPermission("system:route:updateDanzhong")
@PostMapping(value = "/updateDanzhong", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public R<Void> updateDanzhong(@RequestParam("file") MultipartFile file) throws Exception {
String originalFilename = file.getOriginalFilename();
log.info("读取文件名: " + originalFilename);
ExcelResult<JdDanZhong> result = ExcelUtil.importExcelSheet1(file.getInputStream(), JdDanZhong.class, true);
List<JdDanZhong> list = result.getList();
// 创建固定大小的线程池
ExecutorService executor = Executors.newFixedThreadPool(10);
list.forEach(vmi -> executor.submit(() -> {
List<JdEntryVmi> entryID = JdUtil.getEntryID2(vmi.getMaterialCode());
entryID.forEach(jdEntryVmi -> {
int fmaterialid = jdEntryVmi.getFMATERIALID();
try {
log.info("=====================>开始更新 " + vmi.getMaterialCode() + " 的单重");
JdUtil.updateDanzhong(fmaterialid,vmi.getDanzhong() );
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}));
// 关闭线程池并等待所有任务完成
executor.shutdown();
try {
if (!executor.awaitTermination(60, TimeUnit.MINUTES)) {
executor.shutdownNow(); // 超时后强制关闭
}
} catch (InterruptedException e) {
executor.shutdownNow();
Thread.currentThread().interrupt(); // 保留中断状态
}
return R.ok("更新成功");
}
@Log(title = "更新VMI仓位", businessType = BusinessType.IMPORT)
@SaCheckPermission("system:route:updaDateCangwei")
@PostMapping(value = "/updaDateCangwei12", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public R<Void> updaDateCangwei1(@RequestParam("file") MultipartFile file) throws Exception {
String originalFilename = file.getOriginalFilename();
log.info("读取文件名: " + originalFilename);
ExcelResult<JdVMIVo> result = ExcelUtil.importExcelSheet1(file.getInputStream(), JdVMIVo.class, true);
List<JdVMIVo> list = result.getList();
ExecutorService executor = Executors.newFixedThreadPool(10);
list.forEach(vmi -> executor.submit(() -> {
log.info("===============>开始查询物料编码: " + vmi.getMaterialCode() + "的entryID");
List<JdEntryVmi> entryID = JdUtil.getEntryID2(vmi.getMaterialCode());
entryID.forEach(jdEntryVmi -> {
int fmaterialid = jdEntryVmi.getFMATERIALID();
int fEntryId1 = jdEntryVmi.getFEntryId1();
int fEntryId3 = jdEntryVmi.getFEntryId3();
try {
log.info("=====================>开始更新 " + vmi.getMaterialCode() + " 的VMI仓位");
JdUtil.updateVMI(fmaterialid, fEntryId1, fEntryId3, vmi.getFStockId(), vmi.getFStockPlaceId());
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}));
// 关闭线程池并等待所有任务完成
executor.shutdown();
try {
if (!executor.awaitTermination(60, TimeUnit.MINUTES)) {
executor.shutdownNow(); // 超时后强制关闭
}
} catch (InterruptedException e) {
executor.shutdownNow();
Thread.currentThread().interrupt(); // 保留中断状态
}
return R.ok("更新成功");
}
@Log(title = "更新物料单重", businessType = BusinessType.IMPORT)
@SaCheckPermission("system:materials:importEleBom")
@PostMapping(value = "/importEleBom", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public R<Void> importEleBom(@RequestParam("file") MultipartFile file) throws Exception {
String originalFilename = file.getOriginalFilename();
log.info("读取文件名: " + originalFilename);
ExcelResult<JdDanZhong> result = ExcelUtil.importExcelSheet1(file.getInputStream(), JdDanZhong.class, true);
List<JdDanZhong> list = result.getList();
return R.ok("更新成功");
}
}