From 9b6f200292a054deae46e05f8de7be24a2f18f3b Mon Sep 17 00:00:00 2001 From: sunyugang Date: Thu, 31 Jul 2025 10:35:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8F=90=E5=87=BA=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=92=8C=E6=96=B0=E9=9C=80=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dw/controller/CjOptionController.java | 14 +- .../dw/controller/CjStudentController.java | 4 +- .../dw/controller/DwQuestionController.java | 14 +- .../dw/controller/XyCheckController.java | 29 ++++ .../com/ruoyi/dw/domain/vo/XyCheckDw.java | 24 ++++ .../com/ruoyi/dw/mapper/CjStudentMapper.java | 4 +- .../com/ruoyi/dw/mapper/XyCheckMapper.java | 10 ++ .../ruoyi/dw/service/ICjStudentService.java | 4 +- .../dw/service/impl/CjStudentServiceImpl.java | 134 +++++++++++++++++- .../resources/mapper/dw/CjStudentMapper.xml | 25 +++- .../resources/mapper/dw/DwAnswerMapper.xml | 5 +- .../resources/mapper/dw/XyCheckMapper.xml | 29 ++++ 12 files changed, 275 insertions(+), 21 deletions(-) create mode 100644 ruoyi-dw/src/main/java/com/ruoyi/dw/controller/XyCheckController.java create mode 100644 ruoyi-dw/src/main/java/com/ruoyi/dw/domain/vo/XyCheckDw.java create mode 100644 ruoyi-dw/src/main/java/com/ruoyi/dw/mapper/XyCheckMapper.java create mode 100644 ruoyi-dw/src/main/resources/mapper/dw/XyCheckMapper.xml diff --git a/ruoyi-dw/src/main/java/com/ruoyi/dw/controller/CjOptionController.java b/ruoyi-dw/src/main/java/com/ruoyi/dw/controller/CjOptionController.java index 6a8209e..96c7de3 100644 --- a/ruoyi-dw/src/main/java/com/ruoyi/dw/controller/CjOptionController.java +++ b/ruoyi-dw/src/main/java/com/ruoyi/dw/controller/CjOptionController.java @@ -4,8 +4,10 @@ import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.domain.entity.SysDept; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.dw.domain.CjOption; @@ -13,6 +15,7 @@ import com.ruoyi.dw.domain.CjStudent; import com.ruoyi.dw.domain.vo.OptionUserVo; import com.ruoyi.dw.service.ICjOptionService; import com.ruoyi.dw.service.ICjStudentService; +import com.ruoyi.system.service.ISysDeptService; import org.apache.poi.ss.usermodel.Workbook; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; @@ -41,6 +44,9 @@ public class CjOptionController extends BaseController @Resource private ICjStudentService cjStudentService; + @Resource + private ISysDeptService sysDeptService; + /** * 查询数据采集选项列表 */ @@ -60,7 +66,13 @@ public class CjOptionController extends BaseController public void export(HttpServletResponse response, @RequestBody OptionUserVo userVo) throws IOException { List listOption = cjOptionService.selectCjOptionByIds(userVo.getOptionId()); - List listStudent = cjStudentService.selectCjStudentByIds(userVo.getStudentId()); + Long deptId = SecurityUtils.getLoginUser().getDeptId(); + String zy = null; + if (deptId.intValue() != 100){ + SysDept dept = sysDeptService.selectDeptById(deptId); + zy = dept.getDeptName(); + } + List listStudent = cjStudentService.selectCjStudentByIds(userVo.getStudentId(),zy); // 设置响应头,通知浏览器下载 ZIP 文件 String zipFileName = "export_data_" + System.currentTimeMillis() + ".zip"; response.setContentType("application/zip"); diff --git a/ruoyi-dw/src/main/java/com/ruoyi/dw/controller/CjStudentController.java b/ruoyi-dw/src/main/java/com/ruoyi/dw/controller/CjStudentController.java index 381c95f..f80bdfa 100644 --- a/ruoyi-dw/src/main/java/com/ruoyi/dw/controller/CjStudentController.java +++ b/ruoyi-dw/src/main/java/com/ruoyi/dw/controller/CjStudentController.java @@ -78,7 +78,7 @@ public class CjStudentController extends BaseController } /** - * 导出采集学生信息列表 + * 导入采集学生信息列表 */ @Log(title = "采集学生信息", businessType = BusinessType.EXPORT) @PostMapping("/importData") @@ -146,7 +146,7 @@ public class CjStudentController extends BaseController public AjaxResult importData(MultipartFile file) { int successNum = cjStudentService.importData(file); if (successNum > 0) { - return AjaxResult.success(); + return AjaxResult.success("导入成功"); }else { return AjaxResult.error("导入失败,请检查信息采集内容是否正确"); } diff --git a/ruoyi-dw/src/main/java/com/ruoyi/dw/controller/DwQuestionController.java b/ruoyi-dw/src/main/java/com/ruoyi/dw/controller/DwQuestionController.java index a486926..6b0ad58 100644 --- a/ruoyi-dw/src/main/java/com/ruoyi/dw/controller/DwQuestionController.java +++ b/ruoyi-dw/src/main/java/com/ruoyi/dw/controller/DwQuestionController.java @@ -4,8 +4,10 @@ import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.domain.entity.SysDept; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.dw.domain.CjOption; @@ -16,6 +18,7 @@ import com.ruoyi.dw.domain.vo.QuestionUserVo; import com.ruoyi.dw.service.ICjStudentService; import com.ruoyi.dw.service.IDwInfoService; import com.ruoyi.dw.service.IDwQuestionService; +import com.ruoyi.system.service.ISysDeptService; import org.apache.poi.ss.usermodel.Workbook; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; @@ -48,6 +51,9 @@ public class DwQuestionController extends BaseController @Resource private IDwInfoService dwInfoService; + @Resource + private ISysDeptService sysDeptService; + /** * 查询调查问卷问题列表 */ @@ -78,7 +84,13 @@ public class DwQuestionController extends BaseController @PostMapping("/export") public void export(HttpServletResponse response, @RequestBody QuestionUserVo questionUserVo) throws IOException { - List listStudent = cjStudentService.selectCjStudentByIds(questionUserVo.getStudentId()); + String zy = null; + Long deptId = SecurityUtils.getLoginUser().getDeptId(); + if (deptId.intValue() != 100){ + SysDept dept = sysDeptService.selectDeptById(deptId); + zy = dept.getDeptName(); + } + List listStudent = cjStudentService.selectCjStudentByIds(questionUserVo.getStudentId(), zy); DwQuestion dwQuestion = new DwQuestion(); dwQuestion.setInfoId(questionUserVo.getInfoId()); List listQuestion = dwQuestionService.selectDwQuestionList(dwQuestion); diff --git a/ruoyi-dw/src/main/java/com/ruoyi/dw/controller/XyCheckController.java b/ruoyi-dw/src/main/java/com/ruoyi/dw/controller/XyCheckController.java new file mode 100644 index 0000000..cf779e7 --- /dev/null +++ b/ruoyi-dw/src/main/java/com/ruoyi/dw/controller/XyCheckController.java @@ -0,0 +1,29 @@ +package com.ruoyi.dw.controller; + +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.dw.mapper.XyCheckMapper; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +@RestController +@RequestMapping("/xy/check") +public class XyCheckController extends BaseController { + + @Resource + private XyCheckMapper xyCheckMapper; + + + /** + * 根据专业关联表统计各个学院的调查问卷数量 + * @return + */ + @GetMapping("/dwCount") + public AjaxResult dwCount() { + return AjaxResult.success(xyCheckMapper.selectXyCheckDw()); + } + +} diff --git a/ruoyi-dw/src/main/java/com/ruoyi/dw/domain/vo/XyCheckDw.java b/ruoyi-dw/src/main/java/com/ruoyi/dw/domain/vo/XyCheckDw.java new file mode 100644 index 0000000..fb3b215 --- /dev/null +++ b/ruoyi-dw/src/main/java/com/ruoyi/dw/domain/vo/XyCheckDw.java @@ -0,0 +1,24 @@ +package com.ruoyi.dw.domain.vo; + +public class XyCheckDw { + + private String xy; + + private Integer dwCount; + + public String getXy() { + return xy; + } + + public void setXy(String xy) { + this.xy = xy; + } + + public Integer getDwCount() { + return dwCount; + } + + public void setDwCount(Integer dwCount) { + this.dwCount = dwCount; + } +} diff --git a/ruoyi-dw/src/main/java/com/ruoyi/dw/mapper/CjStudentMapper.java b/ruoyi-dw/src/main/java/com/ruoyi/dw/mapper/CjStudentMapper.java index 9a97739..da513cd 100644 --- a/ruoyi-dw/src/main/java/com/ruoyi/dw/mapper/CjStudentMapper.java +++ b/ruoyi-dw/src/main/java/com/ruoyi/dw/mapper/CjStudentMapper.java @@ -28,8 +28,10 @@ public interface CjStudentMapper */ public List selectCjStudentList(CjStudent cjStudent); + public CjStudent selectCjStudentByXh(String xh); - public List selectCjStudentByIds(@Param("ids") Long[] ids); + + public List selectCjStudentByIds(@Param("ids") Long[] ids,@Param("zy") String zy); /** diff --git a/ruoyi-dw/src/main/java/com/ruoyi/dw/mapper/XyCheckMapper.java b/ruoyi-dw/src/main/java/com/ruoyi/dw/mapper/XyCheckMapper.java new file mode 100644 index 0000000..0851213 --- /dev/null +++ b/ruoyi-dw/src/main/java/com/ruoyi/dw/mapper/XyCheckMapper.java @@ -0,0 +1,10 @@ +package com.ruoyi.dw.mapper; + +import com.ruoyi.dw.domain.vo.XyCheckDw; + +import java.util.List; + +public interface XyCheckMapper { + + public List selectXyCheckDw(); +} diff --git a/ruoyi-dw/src/main/java/com/ruoyi/dw/service/ICjStudentService.java b/ruoyi-dw/src/main/java/com/ruoyi/dw/service/ICjStudentService.java index 253f285..82b48d3 100644 --- a/ruoyi-dw/src/main/java/com/ruoyi/dw/service/ICjStudentService.java +++ b/ruoyi-dw/src/main/java/com/ruoyi/dw/service/ICjStudentService.java @@ -29,7 +29,7 @@ public interface ICjStudentService public List selectCjStudentList(CjStudent cjStudent); - public List selectCjStudentByIds(Long[] ids); + public List selectCjStudentByIds(Long[] ids ,String zy); /** * 查询荣誉学生信息列表 * @@ -81,6 +81,8 @@ public interface ICjStudentService * @param file * @return */ + public int importDataXcx(MultipartFile file); + public int importData(MultipartFile file); public int importCjStudent(MultipartFile file); diff --git a/ruoyi-dw/src/main/java/com/ruoyi/dw/service/impl/CjStudentServiceImpl.java b/ruoyi-dw/src/main/java/com/ruoyi/dw/service/impl/CjStudentServiceImpl.java index 56ecc09..2032aec 100644 --- a/ruoyi-dw/src/main/java/com/ruoyi/dw/service/impl/CjStudentServiceImpl.java +++ b/ruoyi-dw/src/main/java/com/ruoyi/dw/service/impl/CjStudentServiceImpl.java @@ -1,9 +1,7 @@ package com.ruoyi.dw.service.impl; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -58,8 +56,8 @@ public class CjStudentServiceImpl implements ICjStudentService } @Override - public List selectCjStudentByIds(Long[] ids) { - return cjStudentMapper.selectCjStudentByIds(ids); + public List selectCjStudentByIds(Long[] ids,String zy) { + return cjStudentMapper.selectCjStudentByIds(ids,zy); } @Override @@ -120,8 +118,10 @@ public class CjStudentServiceImpl implements ICjStudentService return cjStudentMapper.confirmCjStudentByIds(ids); } + + @Override - public int importData(MultipartFile file) { + public int importDataXcx(MultipartFile file) { try { Workbook workbook = WorkbookFactory.create(file.getInputStream()); Sheet sheet = workbook.getSheetAt(0); @@ -208,6 +208,128 @@ public class CjStudentServiceImpl implements ICjStudentService return -1; // 没有找到数字 } + @Override + public int importData(MultipartFile file) { + try { + Workbook workbook = WorkbookFactory.create(file.getInputStream()); + Sheet sheet = workbook.getSheetAt(0); + int rows = sheet.getLastRowNum(); + for (int i = 2; i <= rows; i++) { + Row row = sheet.getRow(i); + String xh = row.getCell(3).getStringCellValue().trim(); + boolean isInsert = false; + CjStudent cjStudent = cjStudentMapper.selectCjStudentByXh(xh); + if (cjStudent == null){ + cjStudent = new CjStudent(); + isInsert = true; + } + Cell xmCell = row.getCell(1); + xmCell.setCellType(CellType.STRING); + cjStudent.setXm(xmCell.getStringCellValue().trim()); + Cell xbCell = row.getCell(2); + xbCell.setCellType(CellType.STRING); + cjStudent.setXb(xbCell.getStringCellValue().trim()); + cjStudent.setXh(xh); + Cell xyCell = row.getCell(4); + xyCell.setCellType(CellType.STRING); + cjStudent.setXy(xyCell.getStringCellValue().trim()); + Cell zyCell = row.getCell(5); + zyCell.setCellType(CellType.STRING); + cjStudent.setZy(zyCell.getStringCellValue().trim()); + Cell bjCell = row.getCell(6); + bjCell.setCellType(CellType.STRING); + cjStudent.setBj(bjCell.getStringCellValue().trim()); + Cell bybfCell = row.getCell(7); + bybfCell.setCellType(CellType.STRING); + cjStudent.setBynf(Integer.valueOf(bybfCell.getStringCellValue())); + Cell zgxlCell = row.getCell(8); + zgxlCell.setCellType(CellType.STRING); + cjStudent.setZgyl(zgxlCell.getStringCellValue().trim()); + Cell gzdwCell = row.getCell(9); + gzdwCell.setCellType(CellType.STRING); + cjStudent.setGzdw(gzdwCell.getStringCellValue().trim()); + Cell dwxzCell = row.getCell(10); + dwxzCell.setCellType(CellType.STRING); + cjStudent.setDwxz(dwxzCell.getStringCellValue().trim()); + Cell dwdzCell = row.getCell(11); + dwdzCell.setCellType(CellType.STRING); + cjStudent.setDwdz(dwdzCell.getStringCellValue().trim()); + Cell czdCell = row.getCell(12); + czdCell.setCellType(CellType.STRING); + String czd = czdCell.getStringCellValue().trim(); + Map pac = extractProvinceAndCity(czd); + if (pac != null){ + cjStudent.setSydsh(pac.get("province")); + cjStudent.setSydshi(pac.get("city")); + } + Cell zwjbCell = row.getCell(13); + zwjbCell.setCellType(CellType.STRING); + cjStudent.setZwjb(zwjbCell.getStringCellValue().trim()); + Cell shjzCell = row.getCell(14); + shjzCell.setCellType(CellType.STRING); + cjStudent.setShjz(shjzCell.getStringCellValue().trim()); + Cell dbryCell = row.getCell(15); + dbryCell.setCellType(CellType.STRING); + cjStudent.setDbry(dbryCell.getStringCellValue().trim()); + Cell rysfzsCell = row.getCell(16); + rysfzsCell.setCellType(CellType.STRING); + String rysfzs = rysfzsCell.getStringCellValue().trim(); + if ("是".equals(rysfzs)){ + cjStudent.setRysfzs(1L); + }else { + cjStudent.setRysfzs(0L); + } + Cell sjCell = row.getCell(17); + sjCell.setCellType(CellType.STRING); + cjStudent.setSj(sjCell.getStringCellValue()); + Cell yxCell = row.getCell(18); + yxCell.setCellType(CellType.STRING); + cjStudent.setYx(yxCell.getStringCellValue().trim()); + cjStudent.setSfqr(1L); + if (isInsert) + cjStudentMapper.insertCjStudent(cjStudent); + else + cjStudentMapper.updateCjStudent(cjStudent); + } + return rows-2; + }catch (IOException e) { + return -1; + } + } + + /** + * 根据常驻地获取省市 + * @param address + * @return + */ + private static Map extractProvinceAndCity(String address) { + if (address == null || address.length() < 2) { + return null; + } + + int provinceIndex = address.indexOf("省"); + int cityIndex = -1; + + // 必须有"省",且"省"不能是最后一个字符 + if (provinceIndex == -1 || provinceIndex == address.length() - 1) { + return null; + } + + // 在"省"之后找"市" + cityIndex = address.indexOf("市", provinceIndex + 1); + if (cityIndex == -1) { + return null; + } + + String province = address.substring(0, provinceIndex + 1); // 包含"省" + String city = address.substring(provinceIndex + 1, cityIndex + 1); // 从省后到"市"结束 + + Map result = new HashMap<>(); + result.put("province", province); + result.put("city", city); + return result; + } + @Override public int importCjStudent(MultipartFile file) { try { diff --git a/ruoyi-dw/src/main/resources/mapper/dw/CjStudentMapper.xml b/ruoyi-dw/src/main/resources/mapper/dw/CjStudentMapper.xml index 7fdaf72..06789ae 100644 --- a/ruoyi-dw/src/main/resources/mapper/dw/CjStudentMapper.xml +++ b/ruoyi-dw/src/main/resources/mapper/dw/CjStudentMapper.xml @@ -62,14 +62,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - - WHERE id IN - - #{id} - - + + + id IN + + #{id} + + + and xy = #{zy} + + + + + SELECT + re.xy,re.order_index, + sum( re.dw_count ) as dw_count + FROM + ( + SELECT + xy,order_index, + IFNULL( dw.dw_count, 0 ) AS dw_count + FROM + xy_zy xz + LEFT JOIN ( SELECT answer, count( 0 ) AS dw_count FROM dw_answer WHERE question_id IN ( 3, 43, 71 ) GROUP BY answer ) AS dw ON dw.answer = xz.zy + ) AS re + GROUP BY re.xy,re.order_index + order by re.order_index + + + \ No newline at end of file