123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- package com.jeeplus.modules.supply.materialLibrary.web;
- import com.jeeplus.common.json.AjaxJson;
- import com.jeeplus.common.utils.StringUtils;
- import com.jeeplus.common.utils.excel.ImportExcel;
- import com.jeeplus.core.persistence.Page;
- import com.jeeplus.core.web.BaseController;
- import com.jeeplus.modules.supply.materialLibrary.entity.MaterialLibrary;
- import com.jeeplus.modules.supply.materialLibrary.service.MaterialLibraryService;
- import com.jeeplus.modules.supply.stockOut.entity.SupplyStockOut;
- import org.apache.shiro.authz.annotation.RequiresPermissions;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.ModelAttribute;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.ResponseBody;
- import org.springframework.web.multipart.MultipartFile;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.io.File;
- import java.io.IOException;
- import java.util.HashMap;
- import java.util.LinkedHashMap;
- import java.util.List;
- import java.util.Map;
- @Controller
- @RequestMapping(value = "${adminPath}/supply/materialLibrary")
- public class MaterialLibraryController extends BaseController {
- @Autowired
- private MaterialLibraryService materialLibraryService;
- @ModelAttribute
- public MaterialLibrary get(@RequestParam(required = false) String id) {
- MaterialLibrary entity = null;
- if (StringUtils.isNotBlank(id)) {
- entity = materialLibraryService.get(id);
- }
- if (entity == null) {
- entity = new MaterialLibrary();
- }
- return entity;
- }
- /**
- * 项目列表页面
- */
- // @RequiresPermissions("supply:materialLibrary:list")
- @RequestMapping(value = {"list", ""})
- public String list(MaterialLibrary materialLibrary,Model model) {
- model.addAttribute("materialLibrary",materialLibrary);
- return "modules/supply/materialLibrary/supplyMaterialLibraryList";
- }
- /**
- * 列表数据
- */
- @ResponseBody
- // @RequiresPermissions("supply:stockOut:list")
- @RequestMapping(value = "data")
- public Map<String, Object> data(MaterialLibrary materialLibrary, HttpServletRequest request, HttpServletResponse response, Model model) {
- Page<MaterialLibrary> page = materialLibraryService.findPage(new Page<MaterialLibrary>(request, response), materialLibrary);
- return getBootstrapData(page);
- }
- /**
- * 删除项目
- */
- @ResponseBody
- // @RequiresPermissions("supply:stockOut:del")
- @RequestMapping(value = "delete")
- public AjaxJson delete(MaterialLibrary materialLibrary) {
- AjaxJson j = new AjaxJson();
- materialLibraryService.delete(materialLibrary); //要自己写吗? 前端传的是id,
- j.setMsg("删除项目成功");
- return j;
- }
- /**
- * 批量删除
- */
- @ResponseBody
- // @RequiresPermissions("supply:stockOut:del")
- @RequestMapping(value = "deleteAll")
- public AjaxJson deleteAll(String ids) {
- AjaxJson j = new AjaxJson();
- String[] idArray = ids.split(",");
- for (String id : idArray) {
- materialLibraryService.delete(materialLibraryService.get(id));
- }
- j.setMsg("删除成功");
- return j;
- }
- /**
- * 导入Excel数据-
- */
- @ResponseBody
- // @RequiresPermissions("supply:stockOut:import")
- @RequestMapping(value = "import")
- public AjaxJson importFile(@RequestParam("file") MultipartFile file) {
- AjaxJson j = new AjaxJson();
- try {
- String repeat = "0"; //repeat:0:第一次交互,1:覆盖,2:不覆盖
- ImportExcel ei = new ImportExcel(file, 1, 0);
- List<MaterialLibrary> list = ei.getDataList(MaterialLibrary.class); //直接用就好了吗,格式啥的用设置吗?
- LinkedHashMap returnMap = materialLibraryService.disposeImportMaterialLibrary(list,file,repeat);
- //放要放的值
- returnMap.put("repeat","0");
- j.setBody(returnMap);
- j.setMsg(returnMap.get("msg").toString());
- } catch (Exception e) {
- j.setSuccess(false);
- j.setMsg("导入项目表单失败!失败信息:" + e.getMessage());
- }
- return j;
- }
- /**
- * 导入Excel数据-覆盖
- */
- @ResponseBody
- // @RequiresPermissions("supply:stockOut:import")
- @RequestMapping(value = "importTwo")
- public AjaxJson importFileTwo(String filePath,String repeat) {
- AjaxJson j = new AjaxJson();
- try {
- File file = new File(filePath);
- MultipartFile file1 = materialLibraryService.transformFile(file);
- ImportExcel ei = new ImportExcel(file, 1, 0);
- List<MaterialLibrary> list = ei.getDataList(MaterialLibrary.class); //直接用就好了吗,格式啥的用设置吗?
- LinkedHashMap returnMap = materialLibraryService.disposeImportMaterialLibrary(list,file1,repeat);
- //如果文件已经使用完毕,则删除
- materialLibraryService.deleteFileContent(file);
- //放要放的值
- j.setBody(returnMap);
- j.setMsg(returnMap.get("msg").toString());
- } catch (Exception e) {
- j.setSuccess(false);
- j.setMsg("导入项目表单失败!失败信息:" + e.getMessage());
- }
- return j;
- }
- }
|