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

183 lines
7.6 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.QuoteCraft;
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, "项目报价--物料信息数据");
}
/**
* 获取服务内容详细信息
* QuoteCraft quoteCraft
*/
@PreAuthorize("@ss.hasPermi('system:QuoteMaterial:query')")
@GetMapping(value = "/selectQuoteMaterialList")
public AjaxResult selectQuoteMaterialList()
{
return success(quoteMaterialService.selectQuoteMaterialList(new QuoteMaterial()));
}
/**
* 获取项目报价--物料信息详细信息
*/
@PreAuthorize("@ss.hasPermi('system:QuoteMaterial:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
QuoteMaterial quoteMaterial=quoteMaterialService.selectQuoteMaterialById(id);
if (quoteMaterial != null) {
if (quoteMaterial.getGoodId() != null) {
String str = quoteMaterial.getGoodId();
List<String> stringList = JSON.parseArray(str, String.class);
List<Long> longList = stringList.stream().map(Long::parseLong).collect(Collectors.toList());
quoteMaterial.setGoodsintids(longList);
}
if (quoteMaterial.getTypeId() != null) {
String typeStr = quoteMaterial.getTypeId();
List<String> typeStringList = JSON.parseArray(typeStr, String.class);
List<Long> typeLongList = typeStringList.stream().map(Long::parseLong).collect(Collectors.toList());
quoteMaterial.setTypeintids(typeLongList);
}
}
return success(quoteMaterial);
}
/**
* 新增项目报价--物料信息
*/
@PreAuthorize("@ss.hasPermi('system:QuoteMaterial:add')")
@Log(title = "项目报价--物料信息", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody QuoteMaterial quoteMaterial)
{
if (quoteMaterial.getGoodsintids() != null && quoteMaterial.getGoodsintids().size() > 0) {
List<Long> longList = quoteMaterial.getGoodsintids();
List<String> strList = longList.stream().map(String::valueOf).collect(Collectors.toList());
String json = JSON.toJSONString(strList);
quoteMaterial.setGoodId(json.replaceAll("\",\"", "\", \""));
}
if (quoteMaterial.getTypeintids() != null && quoteMaterial.getTypeintids().size() > 0) {
List<Long> longList = quoteMaterial.getTypeintids();
List<String> strList = longList.stream().map(String::valueOf).collect(Collectors.toList());
String json = JSON.toJSONString(strList);
quoteMaterial.setTypeId(json.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() != null && quoteMaterial.getGoodsintids().size() > 0) {
List<Long> longList = quoteMaterial.getGoodsintids();
List<String> strList = longList.stream().map(String::valueOf).collect(Collectors.toList());
String json = JSON.toJSONString(strList);
quoteMaterial.setGoodId(json.replaceAll("\",\"", "\", \""));
}
if (quoteMaterial.getTypeintids() != null && quoteMaterial.getTypeintids().size() > 0) {
List<Long> longList = quoteMaterial.getTypeintids();
List<String> strList = longList.stream().map(String::valueOf).collect(Collectors.toList());
String json = JSON.toJSONString(strList);
quoteMaterial.setTypeId(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));
}
}