Преглед на файлове

舒展 17:12:07
新增修改 打开时查询数据
create
edit

舒展 17:12:20
保存数据
add
update

jz.kai преди 5 години
родител
ревизия
f8e49b5f9a

+ 61 - 17
web/src/main/java/com/jpsoft/smart/modules/base/controller/CompanyInfoController.java

@@ -35,12 +35,12 @@ public class CompanyInfoController {
 
     @ApiOperation(value="创建空记录")
     @GetMapping("create")
-    public MessageResult<CompanyInfo> create(){
-        MessageResult<CompanyInfo> msgResult = new MessageResult<>();
+    public MessageResult<CompanyInfoDTO> create(){
+        MessageResult<CompanyInfoDTO> msgResult = new MessageResult<>();
 
-        CompanyInfo companyInfo = new CompanyInfo();
+        CompanyInfoDTO companyInfoDTO = new CompanyInfoDTO();
 
-        msgResult.setData(companyInfo);
+        msgResult.setData(companyInfoDTO);
         msgResult.setResult(true);
 
         return msgResult;
@@ -48,20 +48,37 @@ public class CompanyInfoController {
     
     @ApiOperation(value="添加信息")
     @PostMapping("add")
-    public MessageResult<CompanyInfo> add(@RequestBody CompanyInfo companyInfo,@RequestAttribute String subject){
-        MessageResult<CompanyInfo> msgResult = new MessageResult<>();
+    public MessageResult<Map> add(@RequestBody CompanyInfoDTO companyInfoDTO,@RequestAttribute String subject){
+        MessageResult<Map> msgResult = new MessageResult<>();
+        Map<String,Object> map = new HashMap<>();
 
         try {
+            CompanyInfo companyInfo = new CompanyInfo();
+            PojoUtils.map(companyInfoDTO, companyInfo);
             companyInfo.setId(UUID.randomUUID().toString());
             companyInfo.setDelFlag(false);
             companyInfo.setCreateBy(subject);
             companyInfo.setCreateTime(new Date());
-            
-            int affectCount = companyInfoService.insert(companyInfo);
+            companyInfoService.insert(companyInfo);
+            map.put("companyInfo",companyInfo);
+
+            CompanyPosition companyPosition = new CompanyPosition();
+            companyPosition.setId(UUID.randomUUID().toString());
+            companyPosition.setCompanyId(companyInfo.getId());
+            companyPosition.setPosition1Name(companyInfoDTO.getPosition1Name());
+            companyPosition.setPosition2Name(companyInfoDTO.getPosition2Name());
+            companyPosition.setPosition3Name(companyInfoDTO.getPosition3Name());
+            companyPosition.setPosition4Name(companyInfoDTO.getPosition4Name());
+            companyPosition.setPosition5Name(companyInfoDTO.getPosition5Name());
+            companyPosition.setDelFlag(false);
+            companyPosition.setCreateBy(subject);
+            companyPosition.setCreateTime(new Date());
+            int affectCount = companyPositionService.insert(companyPosition);
+            map.put("companyPosition",companyPosition);
 
             if (affectCount > 0) {
                 msgResult.setResult(true);
-                msgResult.setData(companyInfo);
+                msgResult.setData(map);
             } else {
                 msgResult.setResult(false);
                 msgResult.setMessage("数据库添加失败");
@@ -79,15 +96,17 @@ public class CompanyInfoController {
 
     @ApiOperation(value="获取信息")
     @GetMapping("edit/{id}")
-    public MessageResult<CompanyInfo> edit(@PathVariable("id") String id){
-        MessageResult<CompanyInfo> msgResult = new MessageResult<>();
+    public MessageResult<CompanyInfoDTO> edit(@PathVariable("id") String id){
+        MessageResult<CompanyInfoDTO> msgResult = new MessageResult<>();
 
         try {
             CompanyInfo companyInfo = companyInfoService.get(id);
+            CompanyInfoDTO companyInfoDTO = new CompanyInfoDTO();
 
             if (companyInfo != null) {
+                PojoUtils.map(companyInfo, companyInfoDTO);
                 msgResult.setResult(true);
-                msgResult.setData(companyInfo);
+                msgResult.setData(companyInfoDTO);
             } else {
                 msgResult.setResult(false);
                 msgResult.setMessage("数据库不存在该记录!");
@@ -105,18 +124,43 @@ public class CompanyInfoController {
 
     @ApiOperation(value="更新")
     @PostMapping("update")
-    public MessageResult<CompanyInfo> update(@RequestBody CompanyInfo companyInfo,@RequestAttribute String subject){
-        MessageResult<CompanyInfo> msgResult = new MessageResult<>();
+    public MessageResult<Map> update(@RequestBody CompanyInfoDTO companyInfoDTO,@RequestAttribute String subject){
+        MessageResult<Map> msgResult = new MessageResult<>();
+        Map<String,Object> map = new HashMap<>();
 
         try {
+            int affectCount = 0;
+            CompanyInfo companyInfo = new CompanyInfo();
+            PojoUtils.map(companyInfoDTO, companyInfo);
             companyInfo.setUpdateBy(subject);
             companyInfo.setUpdateTime(new Date());
-            
-            int affectCount = companyInfoService.update(companyInfo);
+            companyInfoService.update(companyInfo);
+            map.put("companyInfo",companyInfo);
+            affectCount++;
+
+            CompanyPosition companyPosition = new CompanyPosition();
+            Map<String,Object> searchParams1 = new HashMap<>();
+            searchParams1.put("companyId",companyInfo.getId());
+            List<Sort> sortList1 = new ArrayList<>();
+            sortList1.add(new Sort("id_","asc"));
+            Page<CompanyPosition> page1 = companyPositionService.pageSearch(searchParams1,1,1,false,sortList1);
+            if(page1.size() > 0) {
+                companyPosition = page1.get(0);
+                companyPosition.setPosition1Name(companyInfoDTO.getPosition1Name());
+                companyPosition.setPosition2Name(companyInfoDTO.getPosition2Name());
+                companyPosition.setPosition3Name(companyInfoDTO.getPosition3Name());
+                companyPosition.setPosition4Name(companyInfoDTO.getPosition4Name());
+                companyPosition.setPosition5Name(companyInfoDTO.getPosition5Name());
+                companyPosition.setUpdateBy(subject);
+                companyPosition.setUpdateTime(new Date());
+                companyPositionService.update(companyPosition);
+                affectCount++;
+            }
+            map.put("companyPosition",companyPosition);
 
             if (affectCount > 0) {
                 msgResult.setResult(true);
-                msgResult.setData(companyInfo);
+                msgResult.setData(map);
             } else {
                 msgResult.setResult(false);
                 msgResult.setMessage("数据库更新失败");

+ 51 - 0
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonInfoController.java

@@ -653,4 +653,55 @@ public class PersonInfoController {
 
         return msgResult;
     }
+
+    @ApiOperation(value="导出人员")
+    @PostMapping("exportXls")
+    public MessageResult<String> exportXls(HttpServletRequest request, HttpServletResponse response){
+        MessageResult<String> msgResult = new MessageResult<>();
+
+        try {
+            //创建hssfWorkbook
+            HSSFWorkbook workbook = new HSSFWorkbook();
+
+            //创建工作簿
+            HSSFSheet sheet = workbook.createSheet();
+
+            //创建标题
+            HSSFRow row = sheet.createRow(0);
+            HSSFCell cell = row.createCell(0);
+            cell.setCellValue("商品信息汇总");
+
+
+            //todo 将wb保存到oss
+            ByteArrayOutputStream output = new ByteArrayOutputStream();
+            workbook.write(output);
+
+            byte[] buffer = output.toByteArray();
+            ByteArrayInputStream input = new ByteArrayInputStream(buffer);
+
+            String downloadUrl = OSSUtil.upload(ossConfig,"import","error.xls",input);
+
+            //todo 返回导入失败报表下载链接
+            msgResult.setData(downloadUrl);
+
+            //将exal输出到哪个文件夹中
+//            ByteArrayOutputStream out = new ByteArrayOutputStream();
+//            workbook.write(out);
+//            workbook.close();
+//
+//            String fileName = new String("导出数据".getBytes("UTF-8"), "iso-8859-1");
+//            response.setContentType("application/x-msdownload");
+//            response.setHeader("Content-Disposition", "attachment;fileName=" + fileName + ".xls");
+//            response.getOutputStream().write(out.toByteArray());
+//            response.getOutputStream().flush();
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
 }

+ 0 - 90
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonInfoExportController.java

@@ -1,90 +0,0 @@
-package com.jpsoft.smart.modules.base.controller;
-
-import com.github.pagehelper.Page;
-import com.jpsoft.smart.config.OSSConfig;
-import com.jpsoft.smart.modules.base.entity.PersonInfo;
-import com.jpsoft.smart.modules.base.service.PersonInfoService;
-import com.jpsoft.smart.modules.common.dto.MessageResult;
-import com.jpsoft.smart.modules.common.dto.Sort;
-import com.jpsoft.smart.modules.common.utils.CheckIdCard;
-import com.jpsoft.smart.modules.common.utils.OSSUtil;
-import com.jpsoft.smart.modules.common.utils.POIUtils;
-import com.jpsoft.smart.modules.common.utils.PojoUtils;
-import com.jpsoft.smart.modules.sys.entity.User;
-import com.jpsoft.smart.modules.sys.service.UserService;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
-import io.swagger.annotations.ApiOperation;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.poi.hssf.usermodel.HSSFCell;
-import org.apache.poi.hssf.usermodel.HSSFRow;
-import org.apache.poi.hssf.usermodel.HSSFSheet;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.util.*;
-
-@RestController
-@RequestMapping("/base/personInfo")
-@Api(description = "personInfo")
-public class PersonInfoExportController {
-    private Logger logger = LoggerFactory.getLogger(getClass());
-
-    @Autowired
-    private OSSConfig ossConfig;
-    @Autowired
-    private PersonInfoService personInfoService;
-    @Autowired
-    private UserService userService;
-
-    @ApiOperation(value="导出人员")
-    @PostMapping("exportXls")
-    public MessageResult<String> exportXls(HttpServletRequest request, HttpServletResponse response){
-        MessageResult<String> msgResult = new MessageResult<>();
-
-        try {
-            //创建hssfWorkbook
-            HSSFWorkbook workbook = new HSSFWorkbook();
-
-            //创建工作簿
-            HSSFSheet sheet = workbook.createSheet();
-
-            //创建标题
-            HSSFRow row = sheet.createRow(0);
-            HSSFCell cell = row.createCell(0);
-            cell.setCellValue("商品信息汇总");
-
-
-            //将exal输出到哪个文件夹中
-            //FileOutputStream fileOutputStream = new FileOutputStream(new File("C:\\Users\\D.K\\Desktop\\test.xls"));
-            ByteArrayOutputStream out = new ByteArrayOutputStream();
-            workbook.write(out);
-            workbook.close();
-
-            String fileName = new String("导出数据".getBytes("UTF-8"), "iso-8859-1");
-            response.setContentType("application/x-msdownload");
-            response.setHeader("Content-Disposition", "attachment;fileName=" + fileName + ".xls");
-            response.getOutputStream().write(out.toByteArray());
-            response.getOutputStream().flush();
-        }
-        catch(Exception ex){
-            logger.error(ex.getMessage(),ex);
-
-            msgResult.setResult(false);
-            msgResult.setMessage(ex.getMessage());
-        }
-
-        return msgResult;
-    }
-}