初始版本
This commit is contained in:
@@ -0,0 +1,173 @@
|
||||
package com.vverp.controller.admin;
|
||||
|
||||
import com.vverp.entity.Admin;
|
||||
import com.vverp.entity.AdminPurchase;
|
||||
import com.vverp.entity.AdminPurchaseProductType;
|
||||
import com.vverp.entity.ProductType;
|
||||
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.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RequestMapping("admin/adminPurchase")
|
||||
@Controller("adminAdminPurchase")
|
||||
public class AdminPurchaseController extends BaseController{
|
||||
|
||||
@Resource
|
||||
private AdminPurchaseService adminPurchaseService;
|
||||
@Resource
|
||||
private AdminService adminService;
|
||||
@Resource
|
||||
private ProductTypeService productTypeService;
|
||||
@Resource
|
||||
private AdminPurchaseProductTypeService adminPurchaseProductTypeService;
|
||||
@Resource
|
||||
private ProgressService progressService;
|
||||
|
||||
@RequestMapping("list")
|
||||
public String list(ModelMap modelMap, Pageable pageable,Long progressId){
|
||||
Admin admin = adminService.getCurrent();
|
||||
if (admin.getNowProgress() == null){
|
||||
modelMap.addAttribute("company",true);
|
||||
}else {
|
||||
modelMap.addAttribute("company",false);
|
||||
}
|
||||
Page<AdminPurchase> page = adminPurchaseService.findPageView(pageable,progressId == null?admin.getNowProgress():progressId);
|
||||
Map<Long,String> map = new HashMap<>();
|
||||
for (AdminPurchase adminPurchase : page.getContent()){
|
||||
String name = "";
|
||||
for (AdminPurchaseProductType adminPurchaseProductType : adminPurchase.getAdminPurchaseProductTypeList()){
|
||||
if (adminPurchaseProductType.getProductType().getTypeDescribe() != null) {
|
||||
name += "<span>" + adminPurchaseProductType.getProductType().getName() + "(" + adminPurchaseProductType.getProductType().getTypeDescribe() + ");</span><br>";
|
||||
}else {
|
||||
name += "<span>" + adminPurchaseProductType.getProductType().getName() + ";</span><br>";
|
||||
}
|
||||
}
|
||||
map.put(adminPurchase.getId(),name);
|
||||
}
|
||||
modelMap.addAttribute("map",map);
|
||||
modelMap.addAttribute("page",page);
|
||||
modelMap.addAttribute("progressId",progressId);
|
||||
modelMap.addAttribute("progressList",progressService.findAll());
|
||||
return "adminPurchase/list";
|
||||
}
|
||||
|
||||
@RequestMapping("add")
|
||||
public String add(ModelMap modelMap){
|
||||
Admin admin = adminService.getCurrent();
|
||||
modelMap.addAttribute("progressId",admin.getNowProgress());
|
||||
modelMap.addAttribute("adminList",adminService.findAll());
|
||||
modelMap.addAttribute("productTypeList",productTypeService.findAll());
|
||||
return "adminPurchase/add";
|
||||
}
|
||||
|
||||
@RequestMapping("edit")
|
||||
public String edit(ModelMap modelMap, Long id){
|
||||
Admin admin = adminService.getCurrent();
|
||||
modelMap.addAttribute("progressId",admin.getNowProgress());
|
||||
AdminPurchase adminPurchase = adminPurchaseService.find(id);
|
||||
List<Long> ids = new ArrayList<>();
|
||||
for (AdminPurchaseProductType adminPurchaseProductType : adminPurchase.getAdminPurchaseProductTypeList()){
|
||||
ids.add(adminPurchaseProductType.getProductType().getId());
|
||||
}
|
||||
modelMap.addAttribute("ids",ids);
|
||||
modelMap.addAttribute("adminList",adminService.findAll());
|
||||
modelMap.addAttribute("adminPurchase",adminPurchase);
|
||||
modelMap.addAttribute("productTypeList",productTypeService.findAll());
|
||||
return "adminPurchase/edit";
|
||||
}
|
||||
|
||||
@RequestMapping("save")
|
||||
@ResponseBody
|
||||
public RespData save(AdminPurchase adminPurchase,Long[] productTypeIds){
|
||||
try {
|
||||
adminPurchaseService.saveEntity(adminPurchase,productTypeIds);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return RespData.error(e.getMessage());
|
||||
}
|
||||
return RespData.success();
|
||||
}
|
||||
|
||||
@RequestMapping("update")
|
||||
@ResponseBody
|
||||
public RespData update(AdminPurchase adminPurchase,Long[] productTypeIds){
|
||||
// if (adminPurchase.getAdmin()==null || adminPurchase.getAdmin().getId() == null){
|
||||
// return RespData.error("员工不能为空");
|
||||
// }
|
||||
// if (adminPurchase.getProductType()==null || adminPurchase.getProductType().getId() == null){
|
||||
// return RespData.error("可采购类别不能为空");
|
||||
// }
|
||||
// Admin admin = adminService.find(adminPurchase.getAdmin().getId());
|
||||
// adminPurchase.setAdmin(admin);
|
||||
// ProductType productType = productTypeService.find(adminPurchase.getProductType().getId());
|
||||
// adminPurchase.setProductType(productType);
|
||||
try {
|
||||
adminPurchaseService.updateEntity(adminPurchase,productTypeIds);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return RespData.error(e.getMessage());
|
||||
}
|
||||
return RespData.success();
|
||||
}
|
||||
|
||||
@RequestMapping("delete")
|
||||
@ResponseBody
|
||||
public Message delete(Long ids){
|
||||
adminPurchaseService.delete(ids);
|
||||
return Message.success("删除成功");
|
||||
}
|
||||
|
||||
@RequestMapping("dialog/addFile")
|
||||
public String dialogAddFile(ModelMap modelMap){
|
||||
Admin admin = adminService.getCurrent();
|
||||
modelMap.addAttribute("progressId",admin.getNowProgress());
|
||||
return "adminPurchase/dialog/addFile";
|
||||
}
|
||||
|
||||
@RequestMapping("/import")
|
||||
@ResponseBody
|
||||
public RespData importExcel(MultipartFile file,Long progressId) {
|
||||
try {
|
||||
adminPurchaseService.importExcel(file,progressId);
|
||||
return RespData.success();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return RespData.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 导入模板
|
||||
// */
|
||||
// @RequestMapping("/exportTemplate")
|
||||
// public void exportTemplate(HttpServletResponse response) {
|
||||
// adminPurchaseService.exportTemplate(response);
|
||||
// }
|
||||
//
|
||||
// @RequestMapping("import")
|
||||
// @ResponseBody
|
||||
// public RespData importExcel(MultipartFile file) {
|
||||
// try {
|
||||
// adminPurchaseService.importExcel(file);
|
||||
// return RespData.success();
|
||||
// } catch (RuntimeException e) {
|
||||
// return RespData.error(e.getMessage());
|
||||
// } catch (Exception e) {
|
||||
// return RespData.error("导入失败");
|
||||
// }
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user