312 lines
12 KiB
Java
312 lines
12 KiB
Java
package com.ruoyi.system.controller;
|
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.json.JSONArray;
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.JsonArray;
|
|
import com.ruoyi.common.annotation.Log;
|
|
import com.ruoyi.common.annotation.RepeatSubmit;
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
import com.ruoyi.common.core.domain.PageQuery;
|
|
import com.ruoyi.common.core.domain.R;
|
|
import com.ruoyi.common.core.page.TableDataInfo;
|
|
import com.ruoyi.common.core.validate.AddGroup;
|
|
import com.ruoyi.common.core.validate.EditGroup;
|
|
import com.ruoyi.common.enums.BusinessType;
|
|
import com.ruoyi.common.excel.ExcelResult;
|
|
import com.ruoyi.common.utils.JdUtils;
|
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
import com.ruoyi.system.domain.ImMaterial;
|
|
import com.ruoyi.system.domain.bo.ImMaterialBo;
|
|
import com.ruoyi.system.domain.vo.ImMaterialVo;
|
|
import com.ruoyi.system.mapper.ImMaterialMapper;
|
|
import com.ruoyi.system.service.IImMaterialService;
|
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.apache.poi.ss.usermodel.*;
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.validation.constraints.NotEmpty;
|
|
import javax.validation.constraints.NotNull;
|
|
import java.io.FileInputStream;
|
|
import java.io.IOException;
|
|
import java.util.*;
|
|
|
|
/**
|
|
* 物料检索
|
|
*
|
|
* @author ruoyi
|
|
* @date 2024-03-12
|
|
*/
|
|
/*@Validated*/
|
|
@RequiredArgsConstructor
|
|
@RestController
|
|
@RequestMapping("/system/material")
|
|
public class ImMaterialController extends BaseController {
|
|
|
|
private final IImMaterialService iImMaterialService;
|
|
@Resource
|
|
private final ImMaterialMapper imMaterialMapper;
|
|
|
|
/**
|
|
* 查询物料检索列表
|
|
*/
|
|
@SaCheckPermission("system:material:list")
|
|
@GetMapping("/list")
|
|
public TableDataInfo<ImMaterialVo> list(ImMaterialBo bo, PageQuery pageQuery) {
|
|
return iImMaterialService.queryPageList(bo, pageQuery);
|
|
}
|
|
|
|
@GetMapping("/list2")
|
|
public TableDataInfo<ImMaterialVo> list2(ImMaterialBo bo, PageQuery pageQuery) {
|
|
return iImMaterialService.queryPageList(bo, pageQuery);
|
|
}
|
|
|
|
/**
|
|
* 导出物料检索列表
|
|
*/
|
|
@SaCheckPermission("system:material:export")
|
|
@Log(title = "物料检索", businessType = BusinessType.EXPORT)
|
|
@PostMapping("/export")
|
|
public void export(ImMaterialBo bo, HttpServletResponse response) {
|
|
List<ImMaterialVo> list = iImMaterialService.queryList(bo);
|
|
ExcelUtil.exportExcel(list, "物料检索", ImMaterialVo.class, response);
|
|
}
|
|
|
|
/**
|
|
* 获取物料检索详细信息
|
|
*
|
|
* @param id 主键
|
|
*/
|
|
//@SaCheckPermission("system:material:query")
|
|
@GetMapping("/{id}")
|
|
public R<ImMaterialVo> getInfo(@NotNull(message = "主键不能为空")
|
|
@PathVariable Long id) {
|
|
return R.ok(iImMaterialService.queryById(id));
|
|
}
|
|
|
|
/**
|
|
* 新增物料检索
|
|
*/
|
|
@SaCheckPermission("system:material:add")
|
|
@Log(title = "物料检索", businessType = BusinessType.INSERT)
|
|
@RepeatSubmit()
|
|
@PostMapping()
|
|
public R<Void> add(@Validated(AddGroup.class) @RequestBody ImMaterialBo bo) {
|
|
return toAjax(iImMaterialService.insertByBo(bo));
|
|
}
|
|
|
|
/**
|
|
* 修改物料检索
|
|
*/
|
|
@SaCheckPermission("system:material:edit")
|
|
@Log(title = "物料检索", businessType = BusinessType.UPDATE)
|
|
@RepeatSubmit()
|
|
@PutMapping()
|
|
public R<Void> edit(@Validated(EditGroup.class) @RequestBody ImMaterialBo bo) {
|
|
return toAjax(iImMaterialService.updateByBo(bo));
|
|
}
|
|
|
|
/**
|
|
* 删除物料检索
|
|
*
|
|
* @param ids 主键串
|
|
*/
|
|
@SaCheckPermission("system:material:remove")
|
|
@Log(title = "物料检索", businessType = BusinessType.DELETE)
|
|
@DeleteMapping("/{ids}")
|
|
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
|
@PathVariable Long[] ids) {
|
|
return toAjax(iImMaterialService.deleteWithValidByIds(Arrays.asList(ids), true));
|
|
}
|
|
|
|
@PostMapping("/importTemplate")
|
|
public void importTemplate(HttpServletResponse response) {
|
|
ExcelUtil.exportExcel(new ArrayList<>(), "用户数据", ImMaterialBo.class, response);
|
|
}
|
|
@SaCheckPermission("system:problemCreation:export")
|
|
@Log(title = "更新单重", businessType = BusinessType.EXPORT)
|
|
@PostMapping("/export1")
|
|
public void compareAndMerge() throws IOException {
|
|
//读取提供的单重信息
|
|
String pathB = "C:\\Users\\Administrator\\Desktop\\物料编码汇总表.xlsx";
|
|
String outputPath = "D:\\电子档案";
|
|
|
|
try (
|
|
FileInputStream fisB = new FileInputStream(pathB);
|
|
Workbook workbookB = new XSSFWorkbook(fisB);
|
|
) {
|
|
|
|
Sheet sheetB = workbookB.getSheetAt(0);
|
|
|
|
Map<String, Double> bMap = new HashMap<>();
|
|
|
|
for (Row row : sheetB) {
|
|
try {
|
|
Cell materialCell = row.getCell(0);
|
|
Cell weightCell = row.getCell(3);
|
|
|
|
if (materialCell == null || weightCell == null) {
|
|
continue; // 如果单元格为空,则跳过当前行
|
|
}
|
|
|
|
String materialCode;
|
|
Double weight;
|
|
|
|
if (materialCell.getCellType() == CellType.STRING) {
|
|
materialCode = materialCell.getStringCellValue();
|
|
} else {
|
|
continue; // 处理意外的单元格类型
|
|
}
|
|
|
|
if (weightCell.getCellType() == CellType.NUMERIC) {
|
|
weight = weightCell.getNumericCellValue();
|
|
} else {
|
|
continue; // 处理意外的单元格类型
|
|
}
|
|
|
|
bMap.put(materialCode, weight);
|
|
|
|
// 更新数据库中的物料单重(示例)
|
|
// updateMaterialWeight(materialCode, weight); // 实现这个方法
|
|
|
|
} catch (Exception e) {
|
|
// 记录或处理特定的异常
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
// 处理文件IO异常
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
// 更新数据库中物料单重的示例方法
|
|
/* private void updateMaterialWeight(String materialCode, Double weight) {
|
|
ImMaterial materialByCode = iImMaterialService.getMaterialByCode(materialCode);
|
|
if (materialByCode != null) {
|
|
materialByCode.setSingleWeight(BigDecimal.valueOf(weight));
|
|
imMaterialMapper.updateById(materialByCode);
|
|
} else {
|
|
// 处理物料编码不存在的情况
|
|
}
|
|
} catch (Exception e) {
|
|
// 处理数据库操作的异常
|
|
e.printStackTrace();
|
|
}
|
|
}*/
|
|
/**
|
|
* 导入数据
|
|
*
|
|
* @param file 导入文件
|
|
*/
|
|
@Log(title = "物料导入", businessType = BusinessType.IMPORT)
|
|
@SaCheckPermission("system:material:import")
|
|
@PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
public R<Void> importData(@RequestPart("file") MultipartFile file) throws Exception {
|
|
ExcelResult<ImMaterialVo> excelResult = ExcelUtil.importExcel(file.getInputStream(), ImMaterialVo.class, true);
|
|
List<ImMaterialVo> volist = excelResult.getList();
|
|
List<ImMaterial> list = BeanUtil.copyToList(volist, ImMaterial.class);
|
|
|
|
for (ImMaterial imMaterial : list) {
|
|
if (iImMaterialService.selectByCodeAndName(imMaterial.getMaterialCode(),imMaterial.getMaterialName()) != null) {
|
|
if (imMaterial.getMaterialCode().startsWith("009")) {
|
|
imMaterial.setImCategory("标准件");
|
|
//设置对应编码
|
|
imMaterial.setClassificationNumber(imMaterial.getMaterialCode().substring(0,6));
|
|
} else if (imMaterial.getMaterialCode().startsWith("002N") || imMaterial.getMaterialCode().startsWith("002Y")) {
|
|
imMaterial.setImCategory("刀具");
|
|
//设置对应编码
|
|
imMaterial.setClassificationNumber(imMaterial.getMaterialCode().substring(0,6));
|
|
} else if (imMaterial.getMaterialCode().startsWith("015")) {
|
|
imMaterial.setImCategory("原材料");
|
|
//设置对应编码
|
|
imMaterial.setClassificationNumber(imMaterial.getMaterialCode().substring(0,6));
|
|
}else if (imMaterial.getMaterialCode().startsWith("005")) {
|
|
imMaterial.setImCategory("危化品");
|
|
//设置对应编码
|
|
imMaterial.setClassificationNumber(imMaterial.getMaterialCode().substring(0,6));
|
|
}else if (imMaterial.getMaterialCode().startsWith("006")) {
|
|
imMaterial.setImCategory("生产耗材");
|
|
//设置对应编码
|
|
imMaterial.setClassificationNumber(imMaterial.getMaterialCode().substring(0,6));
|
|
}else if (imMaterial.getMaterialCode().startsWith("017")) {
|
|
imMaterial.setImCategory("生产配件");
|
|
//设置对应编码
|
|
imMaterial.setClassificationNumber(imMaterial.getMaterialCode().substring(0,6));
|
|
}else if (imMaterial.getMaterialCode().startsWith("001")) {
|
|
imMaterial.setImCategory("工具");
|
|
//设置对应编码
|
|
imMaterial.setClassificationNumber(imMaterial.getMaterialCode().substring(0,6));
|
|
}else if (imMaterial.getMaterialCode().startsWith("003")) {
|
|
imMaterial.setImCategory("量具");
|
|
//设置对应编码
|
|
imMaterial.setClassificationNumber(imMaterial.getMaterialCode().substring(0,6));
|
|
}else if (imMaterial.getMaterialCode().startsWith("004")) {
|
|
imMaterial.setImCategory("工装");
|
|
//设置对应编码
|
|
imMaterial.setClassificationNumber(imMaterial.getMaterialCode().substring(0,6));
|
|
}else if (imMaterial.getMaterialCode().startsWith("008")) {
|
|
imMaterial.setImCategory("生产维修配件");
|
|
//设置对应编码
|
|
imMaterial.setClassificationNumber(imMaterial.getMaterialCode().substring(0,6));
|
|
}else if (imMaterial.getMaterialCode().startsWith("016")) {
|
|
imMaterial.setImCategory("生产电料");
|
|
//设置对应编码
|
|
imMaterial.setClassificationNumber(imMaterial.getMaterialCode().substring(0,6));
|
|
}
|
|
iImMaterialService.updateByCode(imMaterial);
|
|
//iImMaterialService.selectByCodeAndName(imMaterial.getMaterialCode(),imMaterial.getMaterialName());
|
|
} else {
|
|
imMaterialMapper.insert(imMaterial);
|
|
}
|
|
}
|
|
return R.ok(excelResult.getAnalysis());
|
|
}
|
|
|
|
|
|
|
|
@XxlJob("updateMaterials")
|
|
public void updateMaterials() {
|
|
JSONArray jsonArray = JdUtils.loadMaterial();
|
|
JsonArray jsonArray1 = null;
|
|
if (jsonArray != null) {
|
|
jsonArray1 = new Gson().fromJson(jsonArray.toString(), JsonArray.class);
|
|
}
|
|
iImMaterialService.updateMaterials(jsonArray1);
|
|
}
|
|
|
|
/**
|
|
* 更新库存
|
|
* @return
|
|
*/
|
|
|
|
@GetMapping("/updateInventory")
|
|
public String updateInventory() {
|
|
|
|
List<ImMaterial> imMaterialCodeList = imMaterialMapper.selectList();
|
|
iImMaterialService.updateInventory(imMaterialCodeList);
|
|
return "string";
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 搜索物料信息
|
|
*/
|
|
/**
|
|
* 搜索物料信息
|
|
*/
|
|
@GetMapping("/search")
|
|
public TableDataInfo search(@RequestParam(value = "query", required = false) String query) {
|
|
return iImMaterialService.search(query);
|
|
}
|
|
}
|