javacodeadmin/ruoyi-system/src/main/java/com/ruoyi/system/controller/QuoteMaterialController.java

156 lines
6.3 KiB
Java

package com.ruoyi.system.controller;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson2.JSON;
import com.ruoyi.system.domain.QuoteType;
import com.ruoyi.system.service.IQuoteMaterialTypeService;
import com.ruoyi.system.service.IServiceGoodsService;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.QuoteMaterial;
import com.ruoyi.system.service.IQuoteMaterialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
* 项目报价--物料信息Controller
*
* @author ruoyi
* @date 2025-05-13
*/
@RestController
@RequestMapping("/system/QuoteMaterial")
public class QuoteMaterialController extends BaseController
{
@Autowired
private IQuoteMaterialService quoteMaterialService;
@Autowired
private IServiceGoodsService serviceGoodsService;
@Autowired
private IQuoteMaterialTypeService quoteMaterialTypeService;
/**
* 查询项目报价--物料信息列表
*/
@PreAuthorize("@ss.hasPermi('system:QuoteMaterial:list')")
@GetMapping("/list")
public TableDataInfo list(QuoteMaterial quoteMaterial)
{
startPage();
if(quoteMaterial.getGoodId()!=null){
quoteMaterial.setGoodId("\""+quoteMaterial.getGoodId()+"\"");
}
List<QuoteMaterial> list = quoteMaterialService.selectQuoteMaterialList(quoteMaterial);
for(QuoteMaterial QuoteMaterialData:list){
List<String> idslist = Arrays.asList(
QuoteMaterialData.getGoodId().replaceAll("[\\[\\]\"]", "").split(", "));
QuoteMaterialData.setServiceName(serviceGoodsService.selectTitlesByIds(idslist));
List<String> typeidslist = Arrays.asList(
QuoteMaterialData.getTypeId().replaceAll("[\\[\\]\"]", "").split(", "));
QuoteMaterialData.setTypeName(quoteMaterialTypeService.selecttypesByIds(typeidslist));
}
return getDataTable(list);
}
/**
* 导出项目报价--物料信息列表
*/
@PreAuthorize("@ss.hasPermi('system:QuoteMaterial:export')")
@Log(title = "项目报价--物料信息", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, QuoteMaterial quoteMaterial)
{
List<QuoteMaterial> list = quoteMaterialService.selectQuoteMaterialList(quoteMaterial);
ExcelUtil<QuoteMaterial> util = new ExcelUtil<QuoteMaterial>(QuoteMaterial.class);
util.exportExcel(response, list, "项目报价--物料信息数据");
}
/**
* 获取项目报价--物料信息详细信息
*/
@PreAuthorize("@ss.hasPermi('system:QuoteMaterial:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
QuoteMaterial quoteMaterial=quoteMaterialService.selectQuoteMaterialById(id);
if (quoteMaterial.getGoodId()!=null){
String str = quoteMaterial.getGoodId();
List<String> stringList = JSON.parseArray(str, String.class);
List<Integer> intList = stringList.stream().map(Integer::parseInt).collect(Collectors.toList());
quoteMaterial.setGoodsintids(intList);
}
return success(quoteMaterial);
}
/**
* 新增项目报价--物料信息
*/
@PreAuthorize("@ss.hasPermi('system:QuoteMaterial:add')")
@Log(title = "项目报价--物料信息", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody QuoteMaterial quoteMaterial)
{
if(quoteMaterial.getGoodsintids().size()>0){
List<Integer> intList =quoteMaterial.getGoodsintids();
// 先转成字符串List
List<String> strList = intList.stream().map(String::valueOf).collect(Collectors.toList());
// 再转成json字符串
String json = JSON.toJSONString(strList);
quoteMaterial.setGoodId(json.replaceAll("\",\"", "\", \""));
//String withSpace = compact.replaceAll("\",\"", "\", \"");
}
return toAjax(quoteMaterialService.insertQuoteMaterial(quoteMaterial));
}
/**
* 修改项目报价--物料信息
*/
@PreAuthorize("@ss.hasPermi('system:QuoteMaterial:edit')")
@Log(title = "项目报价--物料信息", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody QuoteMaterial quoteMaterial)
{
if(quoteMaterial.getGoodsintids().size()>0){
System.out.println("#########################"+quoteMaterial.getGoodsintids());
List<Integer> intList =quoteMaterial.getGoodsintids();
// 先转成字符串List
List<String> strList = intList.stream().map(String::valueOf).collect(Collectors.toList());
// 再转成json字符串
String json = JSON.toJSONString(strList);
quoteMaterial.setGoodId(json.replaceAll("\",\"", "\", \""));
//String withSpace = compact.replaceAll("\",\"", "\", \"");
System.out.println("#########################"+json.replaceAll("\",\"", "\", \""));
}
return toAjax(quoteMaterialService.updateQuoteMaterial(quoteMaterial));
}
/**
* 删除项目报价--物料信息
*/
@PreAuthorize("@ss.hasPermi('system:QuoteMaterial:remove')")
@Log(title = "项目报价--物料信息", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(quoteMaterialService.deleteQuoteMaterialByIds(ids));
}
}