xiao547607 5 years ago
parent
commit
aea909e45e

+ 3 - 0
common/src/main/java/com/jpsoft/campus/modules/base/dto/ApplicationMiddleDTO.java

@@ -126,4 +126,7 @@ public class ApplicationMiddleDTO implements Serializable {
      */
      */
     @ApiModelProperty(value = "删除标示")
     @ApiModelProperty(value = "删除标示")
     private Boolean delFlag;
     private Boolean delFlag;
+
+    @ApiModelProperty(value = "登记人ID")
+    private String personId;
 }
 }

+ 3 - 0
common/src/main/java/com/jpsoft/campus/modules/base/dto/ApplicationPrimaryDTO.java

@@ -124,4 +124,7 @@ public class ApplicationPrimaryDTO implements Serializable {
 
 
     @ApiModelProperty(value = "择校原因")
     @ApiModelProperty(value = "择校原因")
     private String chooseReason;
     private String chooseReason;
+
+    @ApiModelProperty(value = "登记人ID")
+    private String personId;
 }
 }

+ 15 - 1
common/src/main/resources/mapper/base/ApplicationMiddle.xml

@@ -165,13 +165,17 @@
         <result property="updateBy" column="update_by"/>
         <result property="updateBy" column="update_by"/>
         <result property="updateTime" column="update_time"/>
         <result property="updateTime" column="update_time"/>
         <result property="delFlag" column="del_flag"/>
         <result property="delFlag" column="del_flag"/>
+        <result property="personId" column="person_id"/>
+        <result property="address" column="address_"/>
     </resultMap>
     </resultMap>
     <select id="searchDTO" parameterType="hashmap" resultMap="ApplicationMiddleDTOMap">
     <select id="searchDTO" parameterType="hashmap" resultMap="ApplicationMiddleDTOMap">
         <![CDATA[
         <![CDATA[
 			SELECT a.id_,b.name_,b.card_type,b.id_card,
 			SELECT a.id_,b.name_,b.card_type,b.id_card,
 			c.relationship_,a.type_,a.status_,a.student_id ,
 			c.relationship_,a.type_,a.status_,a.student_id ,
 			a.create_time,a.update_time,
 			a.create_time,a.update_time,
-			d.name_ as school_name
+			d.name_ as school_name,
+			a.person_id,
+			b.address_
 			FROM base_application_middle a
 			FROM base_application_middle a
 			LEFT JOIN base_student_info b ON a.student_id = b.id_
 			LEFT JOIN base_student_info b ON a.student_id = b.id_
 			LEFT JOIN base_person_student c ON (a.person_id = c.person_id AND a.student_id = c.student_id)
 			LEFT JOIN base_person_student c ON (a.person_id = c.person_id AND a.student_id = c.student_id)
@@ -209,6 +213,16 @@
 			<if test="searchParams.code != null">
 			<if test="searchParams.code != null">
 				and d.code_ like #{searchParams.code}
 				and d.code_ like #{searchParams.code}
 			</if>
 			</if>
+            <if test="searchParams.startStatus != null">
+                <![CDATA[
+                    AND CONVERT(a.status_,SIGNED) >= #{searchParams.startStatus}
+                ]]>
+            </if>
+            <if test="searchParams.endStatus != null">
+                <![CDATA[
+                    AND CONVERT(a.status_,SIGNED) <= #{searchParams.endStatus}
+                ]]>
+            </if>
             <if test="searchParams.orStatus != null">
             <if test="searchParams.orStatus != null">
                 <foreach item="status" collection="searchParams.orStatus" open="and (" separator="or" close=")">
                 <foreach item="status" collection="searchParams.orStatus" open="and (" separator="or" close=")">
                     a.status_ = #{status}
                     a.status_ = #{status}

+ 7 - 3
common/src/main/resources/mapper/base/ApplicationPrimary.xml

@@ -167,13 +167,17 @@
         <result property="updateBy" column="update_by"/>
         <result property="updateBy" column="update_by"/>
         <result property="updateTime" column="update_time"/>
         <result property="updateTime" column="update_time"/>
         <result property="delFlag" column="del_flag"/>
         <result property="delFlag" column="del_flag"/>
+        <result property="personId" column="person_id"/>
+        <result property="address" column="address_"/>
     </resultMap>
     </resultMap>
     <select id="searchDTO" parameterType="hashmap" resultMap="ApplicationPrimaryDTOMap">
     <select id="searchDTO" parameterType="hashmap" resultMap="ApplicationPrimaryDTOMap">
         <![CDATA[
         <![CDATA[
 			SELECT a.id_,b.name_,b.card_type,b.id_card,
 			SELECT a.id_,b.name_,b.card_type,b.id_card,
 			c.relationship_,a.type_,a.status_,a.student_id ,
 			c.relationship_,a.type_,a.status_,a.student_id ,
 			a.create_time,a.update_time,
 			a.create_time,a.update_time,
-			d.name_ as school_name
+			d.name_ as school_name,
+			a.person_id,
+			b.address_
 			FROM base_application_primary a
 			FROM base_application_primary a
 			LEFT JOIN base_student_info b ON a.student_id = b.id_
 			LEFT JOIN base_student_info b ON a.student_id = b.id_
 			LEFT JOIN base_person_student c ON (a.person_id = c.person_id AND a.student_id = c.student_id)
 			LEFT JOIN base_person_student c ON (a.person_id = c.person_id AND a.student_id = c.student_id)
@@ -213,12 +217,12 @@
             </if>
             </if>
             <if test="searchParams.startStatus != null">
             <if test="searchParams.startStatus != null">
                 <![CDATA[
                 <![CDATA[
-                and a.status_ >= #{searchParams.startStatus}
+                    AND CONVERT(a.status_,SIGNED) >= #{searchParams.startStatus}
                 ]]>
                 ]]>
             </if>
             </if>
             <if test="searchParams.endStatus != null">
             <if test="searchParams.endStatus != null">
                 <![CDATA[
                 <![CDATA[
-                and a.status_ <= #{searchParams.endStatus}
+                    AND CONVERT(a.status_,SIGNED) <= #{searchParams.endStatus}
                 ]]>
                 ]]>
             </if>
             </if>
             <if test="searchParams.orStatus != null">
             <if test="searchParams.orStatus != null">

+ 266 - 0
web/src/main/java/com/jpsoft/campus/modules/base/controller/ApplicationMiddleController.java

@@ -1,12 +1,15 @@
 package com.jpsoft.campus.modules.base.controller;
 package com.jpsoft.campus.modules.base.controller;
 
 
 import com.github.pagehelper.Page;
 import com.github.pagehelper.Page;
+import com.jpsoft.campus.config.OSSConfig;
 import com.jpsoft.campus.modules.base.dto.ApplicationMiddleDTO;
 import com.jpsoft.campus.modules.base.dto.ApplicationMiddleDTO;
+import com.jpsoft.campus.modules.base.dto.ApplicationPrimaryDTO;
 import com.jpsoft.campus.modules.base.dto.AttachmentDTO;
 import com.jpsoft.campus.modules.base.dto.AttachmentDTO;
 import com.jpsoft.campus.modules.base.entity.*;
 import com.jpsoft.campus.modules.base.entity.*;
 import com.jpsoft.campus.modules.base.service.*;
 import com.jpsoft.campus.modules.base.service.*;
 import com.jpsoft.campus.modules.common.dto.Sort;
 import com.jpsoft.campus.modules.common.dto.Sort;
 import com.jpsoft.campus.modules.common.dto.MessageResult;
 import com.jpsoft.campus.modules.common.dto.MessageResult;
+import com.jpsoft.campus.modules.common.utils.OSSUtil;
 import com.jpsoft.campus.modules.common.utils.PojoUtils;
 import com.jpsoft.campus.modules.common.utils.PojoUtils;
 import com.jpsoft.campus.modules.sys.entity.DataDictionary;
 import com.jpsoft.campus.modules.sys.entity.DataDictionary;
 import com.jpsoft.campus.modules.sys.entity.User;
 import com.jpsoft.campus.modules.sys.entity.User;
@@ -14,14 +17,22 @@ import com.jpsoft.campus.modules.sys.service.DataDictionaryService;
 import com.jpsoft.campus.modules.sys.service.UserRoleService;
 import com.jpsoft.campus.modules.sys.service.UserRoleService;
 import com.jpsoft.campus.modules.sys.service.UserService;
 import com.jpsoft.campus.modules.sys.service.UserService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
 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.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.*;
 
 
@@ -51,6 +62,8 @@ public class ApplicationMiddleController {
     private UserService userService;
     private UserService userService;
     @Autowired
     @Autowired
     private UserRoleService userRoleService;
     private UserRoleService userRoleService;
+    @Autowired
+    private OSSConfig ossConfig;
 
 
     @ApiOperation(value="创建空记录")
     @ApiOperation(value="创建空记录")
     @GetMapping("create")
     @GetMapping("create")
@@ -332,6 +345,8 @@ public class ApplicationMiddleController {
             String type,
             String type,
             String nameOrIdCard,
             String nameOrIdCard,
             String schoolId,
             String schoolId,
+            @RequestParam(value="startStatus",defaultValue="") String startStatus,
+            @RequestParam(value="endStatus",defaultValue="") String endStatus,
             @RequestParam(value="delFlag",defaultValue="false") Boolean delFlag,
             @RequestParam(value="delFlag",defaultValue="false") Boolean delFlag,
             @RequestAttribute String subject){
             @RequestAttribute String subject){
         //当前用户ID
         //当前用户ID
@@ -363,6 +378,15 @@ public class ApplicationMiddleController {
                 searchParams.put("cardType",cardType);
                 searchParams.put("cardType",cardType);
             }
             }
 
 
+            //开始
+            if (StringUtils.isNotEmpty(startStatus)) {
+                searchParams.put("startStatus",startStatus);
+            }
+            //结束
+            if (StringUtils.isNotEmpty(endStatus)) {
+                searchParams.put("endStatus",endStatus);
+            }
+
             searchParams.put("delFlag",delFlag);
             searchParams.put("delFlag",delFlag);
 
 
             if(StringUtils.isNotEmpty(schoolId)){
             if(StringUtils.isNotEmpty(schoolId)){
@@ -412,6 +436,8 @@ public class ApplicationMiddleController {
             String type,
             String type,
             String nameOrIdCard,
             String nameOrIdCard,
             String schoolId,
             String schoolId,
+            @RequestParam(value="startStatus",defaultValue="") String startStatus,
+            @RequestParam(value="endStatus",defaultValue="") String endStatus,
             @RequestParam(value="delFlag",defaultValue="false") Boolean delFlag,
             @RequestParam(value="delFlag",defaultValue="false") Boolean delFlag,
             @RequestAttribute String subject){
             @RequestAttribute String subject){
         //当前用户ID
         //当前用户ID
@@ -455,6 +481,15 @@ public class ApplicationMiddleController {
                 searchParams.put("cardType",cardType);
                 searchParams.put("cardType",cardType);
             }
             }
 
 
+            //开始
+            if (StringUtils.isNotEmpty(startStatus)) {
+                searchParams.put("startStatus",startStatus);
+            }
+            //结束
+            if (StringUtils.isNotEmpty(endStatus)) {
+                searchParams.put("endStatus",endStatus);
+            }
+
             searchParams.put("delFlag",delFlag);
             searchParams.put("delFlag",delFlag);
 
 
             if(StringUtils.isNotEmpty(schoolId)){
             if(StringUtils.isNotEmpty(schoolId)){
@@ -784,4 +819,235 @@ public class ApplicationMiddleController {
 
 
         return msgResult;
         return msgResult;
     }
     }
+
+    @ApiOperation(value = "导出")
+    @PostMapping("exportXls")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "name", value = "姓名", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "idCard", value = "身份证", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "phone", value = "手机号", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "parentId", value = "企业编号", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "subordinate", value = "是否查询下级单位", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "position1", value = "一级位置", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "position2", value = "二级位置", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "position3", value = "三级位置", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "position4", value = "四级位置", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "position5", value = "五级位置", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "faceBound", value = "是否同步", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "isUploadPhoto", value = "是否上传照片", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "popedom", value = "用户角色", required = false, paramType = "form", dataType = "String")
+    })
+    public MessageResult<String> exportXls(
+            String tabStatus,
+            String type,
+            String nameOrIdCard,
+            String status,
+            String cardType,
+            String schoolId,
+            @RequestParam(value="categoryId",defaultValue="") String categoryId,
+            @RequestParam(value="startStatus",defaultValue="") String startStatus,
+            @RequestParam(value="endStatus",defaultValue="") String endStatus,
+            @RequestParam(value="delFlag",defaultValue="false") Boolean delFlag,
+            @RequestAttribute String subject) {
+        MessageResult<String> msgResult = new MessageResult<>();
+        User user = userService.get(subject);
+
+
+        try {
+            HSSFWorkbook workbook = new HSSFWorkbook();
+            HSSFSheet sheet = workbook.createSheet();
+            //表头
+            HSSFRow rowTitle = sheet.createRow(0);
+            HSSFCell cellTitle1 = rowTitle.createCell(0);
+            cellTitle1.setCellValue("序号");
+            HSSFCell cellTitle2 = rowTitle.createCell(1);
+            cellTitle2.setCellValue("报名类型");
+            HSSFCell cellTitle3 = rowTitle.createCell(2);
+            cellTitle3.setCellValue("报名学校");
+            HSSFCell cellTitle4 = rowTitle.createCell(3);
+            cellTitle4.setCellValue("学生姓名");
+            HSSFCell cellTitle5 = rowTitle.createCell(4);
+            cellTitle5.setCellValue("证件类型");
+            HSSFCell cellTitle6 = rowTitle.createCell(5);
+            cellTitle6.setCellValue("证件号码");
+            HSSFCell cellTitle7 = rowTitle.createCell(6);
+            cellTitle7.setCellValue("审核状态");
+            HSSFCell cellTitle8 = rowTitle.createCell(7);
+            cellTitle8.setCellValue("申请时间");
+            HSSFCell cellTitle9 = rowTitle.createCell(8);
+            cellTitle9.setCellValue("登记人关系");
+            HSSFCell cellTitle10 = rowTitle.createCell(9);
+            cellTitle10.setCellValue("登记人姓名");
+            HSSFCell cellTitle11 = rowTitle.createCell(10);
+            cellTitle11.setCellValue("登记人手机号码");
+            HSSFCell cellTitle12 = rowTitle.createCell(11);
+            cellTitle12.setCellValue("学生地址");
+
+//            int maxColumn = sheet.getRow(0).getPhysicalNumberOfCells();
+//            for(int i = 1; i < maxColumn; i++) {
+//                //int columnWidth = sheet.getColumnWidth(i) / 256;
+//                sheet.setColumnWidth(i, 12 * 256);
+//            }
+            //学校
+            sheet.setColumnWidth(2, 20 * 256);
+            //身份证
+            sheet.setColumnWidth(5, 24 * 256);
+            //报名时间
+            sheet.setColumnWidth(7, 24 * 256);
+            //登记人手机号
+            sheet.setColumnWidth(10, 15 * 256);
+            //地址
+            sheet.setColumnWidth(11, 30 * 256);
+
+            Map<String,Object> searchParams = new HashMap<>();
+
+            List<Sort> sortList = new ArrayList<>();
+            sortList.add(new Sort("a.create_time","desc"));
+
+            if (StringUtils.isNotEmpty(tabStatus)) {
+                searchParams.put("tabStatus",tabStatus);
+            }
+            if (StringUtils.isNotEmpty(type)) {
+                searchParams.put("type",type);
+            }
+            if (StringUtils.isNotEmpty(status)) {
+                searchParams.put("status",status);
+            }
+            if (StringUtils.isNotEmpty(nameOrIdCard)) {
+                searchParams.put("nameOrIdCard","%" + nameOrIdCard + "%");
+            }
+
+            if (StringUtils.isNotEmpty(cardType)) {
+                searchParams.put("cardType",cardType);
+            }
+
+            searchParams.put("delFlag",delFlag);
+
+            if(StringUtils.isNotEmpty(schoolId)){
+                searchParams.put("code", "%" + schoolId + "%");
+            }else{
+                if (!userService.hasRole(subject,"SYSADMIN")) {
+                    searchParams.put("code", "%" + user.getSchoolId() + "%");
+                }
+            }
+
+            //查询范围
+            //开始
+            if (StringUtils.isNotEmpty(startStatus)) {
+                searchParams.put("startStatus",startStatus);
+            }
+            //结束
+            if (StringUtils.isNotEmpty(endStatus)) {
+                searchParams.put("endStatus",endStatus);
+            }
+
+            if (StringUtils.isNotEmpty(categoryId)) {
+                searchParams.put("categoryId",categoryId);
+            }
+
+            //根据用户和角色查询
+            int count1 = userRoleService.findCountByAIdAndRName(subject,"SYSADMIN");
+            int count2 = userRoleService.findCountByAIdAndRName(subject,"XFLD");
+            int count3 = userRoleService.findCountByAIdAndRName(subject,"XFGZRY");
+
+            if(count1 > 0){
+                //管理员查全部
+            }else if(count2 > 0){
+                //领导查全部
+            }else if(count3 > 0){
+                //工作人员只能查网上初审10和现场初审20
+                List statusList = new ArrayList();
+                statusList.add("10");
+                statusList.add("20");
+                searchParams.put("orStatus",statusList);
+            }
+
+            Page<ApplicationMiddleDTO> page = applicationMiddleService.pageSearchDTO(searchParams,0,100000,true,sortList);
+            List<DataDictionary> relationshipList = dataDictionaryService.findByCatalogName("学生关系");
+            List<DataDictionary> typeNameList = dataDictionaryService.findByCatalogName("报名类型");
+            List<DataDictionary> statusNameList = dataDictionaryService.findByCatalogName("小学招生审核流程");
+            List<DataDictionary> cardTypeList = dataDictionaryService.findByCatalogName("证件类型");
+            for (int i = 0; i < page.size(); i++) {
+                ApplicationMiddleDTO amDTO = page.get(i);
+                String relationship = relationshipList.stream()
+                        .filter(e -> e.getId().equals(amDTO.getRelationship()))
+                        .findFirst().get().getName();
+                String typeName = typeNameList.stream()
+                        .filter(e -> e.getValue().equals(amDTO.getType()))
+                        .findFirst().get().getName();
+                String statusName = statusNameList.stream()
+                        .filter(e -> e.getValue().equals(amDTO.getStatus()))
+                        .findFirst().get().getName();
+                String cardTypeName = cardTypeList.stream()
+                        .filter(e -> e.getValue().equals(amDTO.getCardType()))
+                        .findFirst().get().getName();
+
+                HSSFRow rowContent = sheet.createRow(i + 1);
+                //"序号"
+                HSSFCell cellContent1 = rowContent.createCell(0);
+                cellContent1.setCellValue(i + 1);
+//                "报名类型"
+                HSSFCell cellContent2 = rowContent.createCell(1);
+                cellContent2.setCellValue(typeName);
+//                "报名学校"
+                HSSFCell cellContent3 = rowContent.createCell(2);
+                cellContent3.setCellValue(amDTO.getSchoolName());
+//                "学生姓名"
+                HSSFCell cellContent4 = rowContent.createCell(3);
+                cellContent4.setCellValue(amDTO.getName());
+//                "证件类型"
+                HSSFCell cellContent5 = rowContent.createCell(4);
+                cellContent5.setCellValue(cardTypeName);
+//                "证件号码"
+                HSSFCell cellContent6 = rowContent.createCell(5);
+                cellContent6.setCellValue(amDTO.getIdCard());
+//                "审核状态"
+                HSSFCell cellContent7 = rowContent.createCell(6);
+                cellContent7.setCellValue(statusName);
+//                "申请时间"
+                HSSFCell cellContent8 = rowContent.createCell(7);
+                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+                cellContent8.setCellValue(sdf.format(amDTO.getCreateTime()));
+                //"登记人关系"
+                HSSFCell cellContent9 = rowContent.createCell(8);
+                cellContent9.setCellValue(relationship);
+
+                if(StringUtils.isNotEmpty(amDTO.getPersonId())){
+                    //"登记人姓名"
+                    HSSFCell cellContent10 = rowContent.createCell(9);
+                    PersonInfo pi =personInfoService.get(amDTO.getPersonId());
+                    cellContent10.setCellValue(pi.getName());
+
+                    //"登记人手机号码"
+                    HSSFCell cellContent11 = rowContent.createCell(10);
+                    cellContent11.setCellValue(pi.getPhone());
+                }
+
+                //"学生地址"
+                HSSFCell cellContent12 = rowContent.createCell(11);
+                cellContent12.setCellValue(amDTO.getAddress());
+            }
+
+            //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);
+            msgResult.setResult(true);
+        } catch (Exception ex) {
+            logger.error(ex.getMessage(), ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
 }
 }

+ 243 - 0
web/src/main/java/com/jpsoft/campus/modules/base/controller/ApplicationPrimaryController.java

@@ -1,6 +1,8 @@
 package com.jpsoft.campus.modules.base.controller;
 package com.jpsoft.campus.modules.base.controller;
 
 
+import com.alipay.api.domain.CompanyInfo;
 import com.github.pagehelper.Page;
 import com.github.pagehelper.Page;
+import com.jpsoft.campus.config.OSSConfig;
 import com.jpsoft.campus.modules.base.dto.ApplicationMiddleDTO;
 import com.jpsoft.campus.modules.base.dto.ApplicationMiddleDTO;
 import com.jpsoft.campus.modules.base.dto.ApplicationPrimaryDTO;
 import com.jpsoft.campus.modules.base.dto.ApplicationPrimaryDTO;
 import com.jpsoft.campus.modules.base.dto.AttachmentDTO;
 import com.jpsoft.campus.modules.base.dto.AttachmentDTO;
@@ -8,6 +10,7 @@ import com.jpsoft.campus.modules.base.entity.*;
 import com.jpsoft.campus.modules.base.service.*;
 import com.jpsoft.campus.modules.base.service.*;
 import com.jpsoft.campus.modules.common.dto.Sort;
 import com.jpsoft.campus.modules.common.dto.Sort;
 import com.jpsoft.campus.modules.common.dto.MessageResult;
 import com.jpsoft.campus.modules.common.dto.MessageResult;
+import com.jpsoft.campus.modules.common.utils.OSSUtil;
 import com.jpsoft.campus.modules.common.utils.PojoUtils;
 import com.jpsoft.campus.modules.common.utils.PojoUtils;
 import com.jpsoft.campus.modules.sys.entity.DataDictionary;
 import com.jpsoft.campus.modules.sys.entity.DataDictionary;
 import com.jpsoft.campus.modules.sys.entity.User;
 import com.jpsoft.campus.modules.sys.entity.User;
@@ -15,14 +18,22 @@ import com.jpsoft.campus.modules.sys.service.DataDictionaryService;
 import com.jpsoft.campus.modules.sys.service.UserRoleService;
 import com.jpsoft.campus.modules.sys.service.UserRoleService;
 import com.jpsoft.campus.modules.sys.service.UserService;
 import com.jpsoft.campus.modules.sys.service.UserService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
 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.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.*;
 
 
@@ -54,6 +65,8 @@ public class ApplicationPrimaryController {
     private UserRoleService userRoleService;
     private UserRoleService userRoleService;
     @Autowired
     @Autowired
     private OfferInfoService offerInfoService;
     private OfferInfoService offerInfoService;
+    @Autowired
+    private OSSConfig ossConfig;
 
 
     @ApiOperation(value="创建空记录")
     @ApiOperation(value="创建空记录")
     @GetMapping("create")
     @GetMapping("create")
@@ -1007,4 +1020,234 @@ public class ApplicationPrimaryController {
 
 
         return msgResult;
         return msgResult;
     }
     }
+
+    @ApiOperation(value = "导出")
+    @PostMapping("exportXls")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "name", value = "姓名", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "idCard", value = "身份证", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "phone", value = "手机号", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "parentId", value = "企业编号", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "subordinate", value = "是否查询下级单位", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "position1", value = "一级位置", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "position2", value = "二级位置", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "position3", value = "三级位置", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "position4", value = "四级位置", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "position5", value = "五级位置", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "faceBound", value = "是否同步", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "isUploadPhoto", value = "是否上传照片", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "popedom", value = "用户角色", required = false, paramType = "form", dataType = "String")
+    })
+    public MessageResult<String> exportXls(
+            String tabStatus,
+            String type,
+            String nameOrIdCard,
+            String status,
+            String cardType,
+            String schoolId,
+            @RequestParam(value="categoryId",defaultValue="") String categoryId,
+            @RequestParam(value="startStatus",defaultValue="") String startStatus,
+            @RequestParam(value="endStatus",defaultValue="") String endStatus,
+            @RequestParam(value="delFlag",defaultValue="false") Boolean delFlag,
+            @RequestAttribute String subject) {
+        MessageResult<String> msgResult = new MessageResult<>();
+        User user = userService.get(subject);
+
+
+        try {
+            HSSFWorkbook workbook = new HSSFWorkbook();
+            HSSFSheet sheet = workbook.createSheet();
+            //表头
+            HSSFRow rowTitle = sheet.createRow(0);
+            HSSFCell cellTitle1 = rowTitle.createCell(0);
+            cellTitle1.setCellValue("序号");
+            HSSFCell cellTitle2 = rowTitle.createCell(1);
+            cellTitle2.setCellValue("报名类型");
+            HSSFCell cellTitle3 = rowTitle.createCell(2);
+            cellTitle3.setCellValue("报名学校");
+            HSSFCell cellTitle4 = rowTitle.createCell(3);
+            cellTitle4.setCellValue("学生姓名");
+            HSSFCell cellTitle5 = rowTitle.createCell(4);
+            cellTitle5.setCellValue("证件类型");
+            HSSFCell cellTitle6 = rowTitle.createCell(5);
+            cellTitle6.setCellValue("证件号码");
+            HSSFCell cellTitle7 = rowTitle.createCell(6);
+            cellTitle7.setCellValue("审核状态");
+            HSSFCell cellTitle8 = rowTitle.createCell(7);
+            cellTitle8.setCellValue("申请时间");
+            HSSFCell cellTitle9 = rowTitle.createCell(8);
+            cellTitle9.setCellValue("登记人关系");
+            HSSFCell cellTitle10 = rowTitle.createCell(9);
+            cellTitle10.setCellValue("登记人姓名");
+            HSSFCell cellTitle11 = rowTitle.createCell(10);
+            cellTitle11.setCellValue("登记人手机号码");
+            HSSFCell cellTitle12 = rowTitle.createCell(11);
+            cellTitle12.setCellValue("学生地址");
+
+//            int maxColumn = sheet.getRow(0).getPhysicalNumberOfCells();
+//            for(int i = 1; i < maxColumn; i++) {
+//                //int columnWidth = sheet.getColumnWidth(i) / 256;
+//                sheet.setColumnWidth(i, 12 * 256);
+//            }
+            //学校
+            sheet.setColumnWidth(2, 20 * 256);
+            //身份证
+            sheet.setColumnWidth(5, 24 * 256);
+            //报名时间
+            sheet.setColumnWidth(7, 24 * 256);
+            //登记人手机号
+            sheet.setColumnWidth(10, 15 * 256);
+            //地址
+            sheet.setColumnWidth(11, 30 * 256);
+
+            Map<String,Object> searchParams = new HashMap<>();
+
+            List<Sort> sortList = new ArrayList<>();
+            sortList.add(new Sort("a.create_time","desc"));
+
+            if (StringUtils.isNotEmpty(tabStatus)) {
+                searchParams.put("tabStatus",tabStatus);
+            }
+            if (StringUtils.isNotEmpty(type)) {
+                searchParams.put("type",type);
+            }
+            if (StringUtils.isNotEmpty(status)) {
+                searchParams.put("status",status);
+            }
+            if (StringUtils.isNotEmpty(nameOrIdCard)) {
+                searchParams.put("nameOrIdCard","%" + nameOrIdCard + "%");
+            }
+
+            if (StringUtils.isNotEmpty(cardType)) {
+                searchParams.put("cardType",cardType);
+            }
+
+            searchParams.put("delFlag",delFlag);
+
+            if(StringUtils.isNotEmpty(schoolId)){
+                searchParams.put("code", "%" + schoolId + "%");
+            }else{
+                if (!userService.hasRole(subject,"SYSADMIN")) {
+                    searchParams.put("code", "%" + user.getSchoolId() + "%");
+                }
+            }
+
+            //查询范围
+            //开始
+            if (StringUtils.isNotEmpty(startStatus)) {
+                searchParams.put("startStatus",startStatus);
+            }
+            //结束
+            if (StringUtils.isNotEmpty(endStatus)) {
+                searchParams.put("endStatus",endStatus);
+            }
+
+            if (StringUtils.isNotEmpty(categoryId)) {
+                searchParams.put("categoryId",categoryId);
+            }
+
+            //根据用户和角色查询
+            int count1 = userRoleService.findCountByAIdAndRName(subject,"SYSADMIN");
+            int count2 = userRoleService.findCountByAIdAndRName(subject,"XFLD");
+            int count3 = userRoleService.findCountByAIdAndRName(subject,"XFGZRY");
+
+            if(count1 > 0){
+                //管理员查全部
+            }else if(count2 > 0){
+                //领导查全部
+            }else if(count3 > 0){
+                //工作人员只能查网上初审10和现场初审20
+                List statusList = new ArrayList();
+                statusList.add("10");
+                statusList.add("20");
+                searchParams.put("orStatus",statusList);
+            }
+
+            Page<ApplicationPrimaryDTO> page = applicationPrimaryService.pageSearchDTO(searchParams,0,100000,true,sortList);
+            List<DataDictionary> relationshipList = dataDictionaryService.findByCatalogName("学生关系");
+            List<DataDictionary> typeNameList = dataDictionaryService.findByCatalogName("报名类型");
+            List<DataDictionary> statusNameList = dataDictionaryService.findByCatalogName("小学招生审核流程");
+            List<DataDictionary> cardTypeList = dataDictionaryService.findByCatalogName("证件类型");
+            for (int i = 0; i < page.size(); i++) {
+                ApplicationPrimaryDTO apDTO = page.get(i);
+                String relationship = relationshipList.stream()
+                        .filter(e -> e.getId().equals(apDTO.getRelationship()))
+                        .findFirst().get().getName();
+                String typeName = typeNameList.stream()
+                        .filter(e -> e.getValue().equals(apDTO.getType()))
+                        .findFirst().get().getName();
+                String statusName = statusNameList.stream()
+                        .filter(e -> e.getValue().equals(apDTO.getStatus()))
+                        .findFirst().get().getName();
+                String cardTypeName = cardTypeList.stream()
+                        .filter(e -> e.getValue().equals(apDTO.getCardType()))
+                        .findFirst().get().getName();
+
+                HSSFRow rowContent = sheet.createRow(i + 1);
+                //"序号"
+                HSSFCell cellContent1 = rowContent.createCell(0);
+                cellContent1.setCellValue(i + 1);
+//                "报名类型"
+                HSSFCell cellContent2 = rowContent.createCell(1);
+                cellContent2.setCellValue(typeName);
+//                "报名学校"
+                HSSFCell cellContent3 = rowContent.createCell(2);
+                cellContent3.setCellValue(apDTO.getSchoolName());
+//                "学生姓名"
+                HSSFCell cellContent4 = rowContent.createCell(3);
+                cellContent4.setCellValue(apDTO.getName());
+//                "证件类型"
+                HSSFCell cellContent5 = rowContent.createCell(4);
+                cellContent5.setCellValue(cardTypeName);
+//                "证件号码"
+                HSSFCell cellContent6 = rowContent.createCell(5);
+                cellContent6.setCellValue(apDTO.getIdCard());
+//                "审核状态"
+                HSSFCell cellContent7 = rowContent.createCell(6);
+                cellContent7.setCellValue(statusName);
+//                "申请时间"
+                HSSFCell cellContent8 = rowContent.createCell(7);
+                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+                cellContent8.setCellValue(sdf.format(apDTO.getCreateTime()));
+                //"登记人关系"
+                HSSFCell cellContent9 = rowContent.createCell(8);
+                cellContent9.setCellValue(relationship);
+                if(StringUtils.isNotEmpty(apDTO.getPersonId())){
+                    //"登记人姓名"
+                    HSSFCell cellContent10 = rowContent.createCell(9);
+                    PersonInfo pi =personInfoService.get(apDTO.getPersonId());
+                    cellContent10.setCellValue(pi.getName());
+
+                    //"登记人手机号码"
+                    HSSFCell cellContent11 = rowContent.createCell(10);
+                    cellContent11.setCellValue(pi.getPhone());
+                }
+
+                //"学生地址"
+                HSSFCell cellContent12 = rowContent.createCell(11);
+                cellContent12.setCellValue(apDTO.getAddress());
+            }
+
+            //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);
+            msgResult.setResult(true);
+        } catch (Exception ex) {
+            logger.error(ex.getMessage(), ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
 }
 }