194 lines
7.3 KiB
Java
194 lines
7.3 KiB
Java
package com.vverp.controller.admin;
|
|
|
|
import com.vverp.entity.Admin;
|
|
import com.vverp.entity.ProductType;
|
|
import com.vverp.entity.Supplier;
|
|
import com.vverp.entity.BidArea;
|
|
import com.vverp.moli.util.Message;
|
|
import com.vverp.moli.util.Page;
|
|
import com.vverp.moli.util.Pageable;
|
|
import com.vverp.moli.util.RespData;
|
|
import com.vverp.service.*;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.ui.ModelMap;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
@RequestMapping("admin/bidArea")
|
|
@Controller("adminBidArea")
|
|
public class BidAreaController extends BaseController{
|
|
|
|
@Resource
|
|
private BidAreaService bidAreaService;
|
|
@Resource
|
|
private SupplierService supplierService;
|
|
@Resource
|
|
private ProductTypeService productTypeService;
|
|
|
|
@Resource
|
|
private DiameterService diameterService;
|
|
@Resource
|
|
private WallThicknessService wallThicknessService;
|
|
@Resource
|
|
private MaterialService materialService;
|
|
@Resource
|
|
private SizeStandardService sizeStandardService;
|
|
@Resource
|
|
private EndFaceService endFaceService;
|
|
@Resource
|
|
private PressureLevelService pressureLevelService;
|
|
@Resource
|
|
private AdminService adminService;
|
|
|
|
|
|
@RequestMapping("list")
|
|
public String list(ModelMap modelMap, Pageable pageable, String productTypeChan,String bigType,String smallType){
|
|
Admin admin = adminService.getCurrent();
|
|
Page<BidArea> page = bidAreaService.findPageView(pageable,productTypeChan,admin.getNowProgress(),bigType,smallType);
|
|
// Map<Long,String> typeChan = new HashMap<>();
|
|
// for (BidArea product : page.getContent()){
|
|
// if (product.getProductType() != null) {
|
|
// if (product.getProductType().getParentId() != null){
|
|
// ProductType parent = productTypeService.find(product.getProductType().getParentId());
|
|
// typeChan.put(product.getId(), parent.getName()+"/"+product.getProductType().getName());
|
|
// }else {
|
|
// typeChan.put(product.getId(), product.getProductType().getName());
|
|
// }
|
|
// }else {
|
|
// typeChan.put(product.getId(), "");
|
|
// }
|
|
// }
|
|
modelMap.addAttribute("page",page);
|
|
modelMap.addAttribute("bigType",bigType);
|
|
modelMap.addAttribute("smallType",smallType);
|
|
modelMap.addAttribute("productTypeChan",productTypeChan);
|
|
return "bidArea/list";
|
|
}
|
|
|
|
@RequestMapping("add")
|
|
public String add(ModelMap modelMap){
|
|
Admin admin = adminService.getCurrent();
|
|
modelMap.addAttribute("progressId",admin.getNowProgress());
|
|
modelMap.addAttribute("productTypeList",productTypeService.findListByAttribute("level",1));
|
|
|
|
modelMap.addAttribute("pressureLevelList",pressureLevelService.findAll());
|
|
modelMap.addAttribute("endFaceList",endFaceService.findAll());
|
|
modelMap.addAttribute("materialList",materialService.findAll());
|
|
modelMap.addAttribute("wallThicknessList",wallThicknessService.findAll());
|
|
modelMap.addAttribute("diameterList",diameterService.findAll());
|
|
modelMap.addAttribute("sizeStandardList",sizeStandardService.findAll());
|
|
return "bidArea/add";
|
|
}
|
|
|
|
@RequestMapping("edit")
|
|
public String edit(Long id,ModelMap modelMap){
|
|
BidArea bidArea = bidAreaService.find(id);
|
|
ProductType productType = productTypeService.find(bidArea.getBigTypeId());
|
|
modelMap.addAttribute("bigTypeList",productTypeService.findListByAttribute("level",1));
|
|
if (productType != null) {
|
|
modelMap.addAttribute("smallTypeList", productTypeService.findByParent(productType.getId()));
|
|
}else {
|
|
modelMap.addAttribute("smallTypeList", new ArrayList<>());
|
|
}
|
|
modelMap.addAttribute("bidArea",bidArea);
|
|
modelMap.addAttribute("pressureLevelList",pressureLevelService.findAll());
|
|
modelMap.addAttribute("endFaceList",endFaceService.findAll());
|
|
modelMap.addAttribute("materialList",materialService.findAll());
|
|
modelMap.addAttribute("wallThicknessList",wallThicknessService.findAll());
|
|
modelMap.addAttribute("diameterList",diameterService.findAll());
|
|
modelMap.addAttribute("sizeStandardList",sizeStandardService.findAll());
|
|
return "bidArea/edit";
|
|
}
|
|
|
|
@RequestMapping("save")
|
|
@ResponseBody
|
|
public Message save(BidArea bidArea){
|
|
try {
|
|
bidAreaService.saveEntity(bidArea);
|
|
return Message.success("保存成功");
|
|
}catch (Exception e){
|
|
return Message.error(e.getMessage());
|
|
}
|
|
}
|
|
|
|
@RequestMapping("update")
|
|
@ResponseBody
|
|
public Message update(BidArea bidArea){
|
|
try {
|
|
bidAreaService.updateEntity(bidArea);
|
|
return Message.success("保存成功");
|
|
}catch (Exception e){
|
|
return Message.error(e.getMessage());
|
|
}
|
|
}
|
|
|
|
@RequestMapping("delete")
|
|
@ResponseBody
|
|
public Message delete(Long[] ids){
|
|
bidAreaService.delete(ids);
|
|
return Message.success("删除成功");
|
|
}
|
|
|
|
@RequestMapping("dialog/addFile")
|
|
public String dialogAddFile(ModelMap modelMap){
|
|
modelMap.addAttribute("adminId",adminService.getCurrent().getId());
|
|
return "bidArea/dialog/addFile";
|
|
}
|
|
|
|
@RequestMapping(value = "/uploadExcel")
|
|
@ResponseBody
|
|
public RespData uploadExcel(MultipartFile file,Long adminId) {
|
|
if (file == null) {
|
|
return RespData.error("文件为空");
|
|
}
|
|
//获得文件名
|
|
String fileName = file.getOriginalFilename();
|
|
//判断文件是否是excel文件
|
|
if (!fileName.endsWith("xls") && !fileName.endsWith("xlsx")) {
|
|
return RespData.error("不是excel文件");
|
|
}
|
|
try {
|
|
Map<String,Object> map = bidAreaService.saveFile(file,adminId);
|
|
Integer repeatNum = Integer.valueOf(map.get("repeatNum").toString());
|
|
Integer failNum = Integer.valueOf(map.get("failNum").toString());
|
|
String msg = "导入成功,"+repeatNum+"条已存在";
|
|
map.put("msg",msg);
|
|
if (failNum == 0 && repeatNum ==0){
|
|
return RespData.success(map);
|
|
}
|
|
if (failNum>0) {
|
|
msg = failNum + "条导入失败";
|
|
}
|
|
map.put("msg",msg);
|
|
return RespData.warn(map);
|
|
}catch (Exception e){
|
|
e.printStackTrace();
|
|
return RespData.error(e.getMessage());
|
|
}
|
|
}
|
|
|
|
@RequestMapping("uploadResult")
|
|
public String uploadResult(ModelMap modelMap,Integer successNum, Integer repeatNum, Integer failNum){
|
|
modelMap.addAttribute("successNum",successNum);
|
|
modelMap.addAttribute("repeatNum",repeatNum);
|
|
modelMap.addAttribute("failNum",failNum);
|
|
return "bidArea/dialog/uploadResult";
|
|
}
|
|
|
|
@RequestMapping("exportNotFund")
|
|
public void exportNotFund(HttpServletResponse response) {
|
|
try {
|
|
bidAreaService.exportNotFund(response);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|