package com.ruoyi.web.controller.api;
|
|
|
import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
import com.alibaba.fastjson.JSONObject;
|
import com.ruoyi.common.basic.PageInfo;
|
import com.ruoyi.common.core.domain.BasePage;
|
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.exception.ServiceException;
|
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.system.domain.*;
|
import com.ruoyi.system.dto.MahorImportExcel;
|
import com.ruoyi.system.dto.TechImportExcel;
|
import com.ruoyi.system.service.*;
|
import com.ruoyi.system.vo.SysUserVO;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import javax.annotation.Resource;
|
import java.io.IOException;
|
import java.io.InputStream;
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
/**
|
* <p>
|
* 专业列表 前端控制器
|
* </p>
|
*
|
* @author luodangjia
|
* @since 2024-09-19
|
*/
|
@RestController
|
@RequestMapping("/t-title-major")
|
public class TTitleMajorController {
|
@Resource
|
private TTitleMajorService tTitleMajorService;
|
@Resource
|
private TRegionService regionService;
|
@Resource
|
private TTechnicalTitleService tTechnicalTitleService;
|
//增加专业
|
@ApiOperation(value = "添加",tags = "后台-系统设置-专业列表")
|
@PostMapping(value = "/add")
|
public R add(@RequestBody TTitleMajor tTitleMajor){
|
tTitleMajorService.save(tTitleMajor);
|
return R.ok();
|
}
|
//修改
|
@ApiOperation(value = "编辑",tags = "后台-系统设置-专业列表")
|
@PostMapping(value = "/edit")
|
public R edit(@RequestBody TTitleMajor tTitleMajor){
|
tTitleMajorService.updateById(tTitleMajor);
|
return R.ok();
|
}
|
|
@Resource
|
private TUserChangeDetailService userChangeDetailService;
|
@Resource
|
private TConsultationService consultationService;
|
@Resource
|
private TDeclareNoticeService declareNoticeService;
|
@Resource
|
private TCommitteeTechnicalService committeeTechnicalService;
|
@Resource
|
private TCommitteeService committeeService;
|
@Resource
|
private TInformationService informationService;
|
@Resource
|
private TCourseService courseService;
|
@Resource
|
private TTitleMajorService majorService;
|
//删除
|
@ApiOperation(value = "删除",tags = "后台-系统设置-专业列表")
|
@PostMapping(value = "/deleteById")
|
public R deleteById(Long id){
|
String s = id.toString();
|
//判断是否有关联数据
|
Long count = userChangeDetailService.lambdaQuery().eq(TUserChangeDetail::getMajorId, s).count();
|
if (count>0){
|
return R.fail("当前专业已有用户设为偏好,无法删除");
|
}
|
Long count1 = consultationService.lambdaQuery().eq(TConsultation::getMajorId, s).count();
|
if (count1>0){
|
return R.fail("当前专业已设置咨询,无法删除");
|
}
|
Long count2 = declareNoticeService.lambdaQuery().eq(TDeclareNotice::getMajorId, s).count();
|
if (count2>0){
|
return R.fail("当前专业已设置申报通知,无法删除");
|
}
|
Long count3 = committeeTechnicalService.lambdaQuery().eq(TCommitteeTechnical::getMajorId, s).count();
|
if (count3>0){
|
return R.fail("当前专业已设置委员会可评审职称,无法删除");
|
}
|
Long count4 = committeeService.lambdaQuery().eq(TCommittee::getMajorId, s).count();
|
if (count4>0){
|
return R.fail("当前专业已设置评审委员会,无法删除");
|
}
|
Long count5 = informationService.lambdaQuery().eq(TInformation::getMajorId, s).count();
|
if (count5>0){
|
return R.fail("当前专业已设置资料,无法删除");
|
}
|
|
Long count7 = courseService.lambdaQuery().eq(TCourse::getMajorId, s).count();
|
if (count7>0){
|
return R.fail("当前专业已设置课程,无法删除");
|
}
|
|
tTitleMajorService.removeById(id);
|
return R.ok();
|
}
|
//分页列表
|
@ApiOperation(value = "查询",tags = "后台-系统设置-专业列表")
|
@PostMapping(value = "/pageList")
|
public R pageList(@RequestBody BasePage basePage){
|
PageInfo<TTitleMajor> titleMajorList = tTitleMajorService.pageList(basePage);
|
return R.ok(titleMajorList);
|
}
|
|
|
@ApiOperation(value = "导入",tags = "后台-系统设置-专业列表")
|
@Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
|
@PostMapping("/export")
|
public R export (@RequestParam("file") MultipartFile file) {
|
List<TTitleMajor> tTechnicalTitles = new ArrayList<>();
|
|
|
|
int errorLines = 0;
|
int successLines = 0;
|
ImportParams params = new ImportParams();
|
// params.setTitleRows(1);//标题行数
|
params.setHeadRows(1); //表头行数
|
String msg = null;
|
InputStream inputStream = null;
|
|
List<String> failMsg = new ArrayList<>();
|
|
try {
|
inputStream = file.getInputStream();
|
List<MahorImportExcel> techImportExcels = ExcelImportUtil.importExcel(inputStream, MahorImportExcel.class, params);
|
for (MahorImportExcel techImportExcel : techImportExcels) {
|
|
List<Integer> regionIds;
|
if (techImportExcel.getAddress() == null || StringUtils.isEmpty(techImportExcel.getAddress())) {
|
msg = "第" + techImportExcels.indexOf(techImportExcel) + "行,地区不能为空";
|
failMsg.add(msg);
|
continue;
|
} else {
|
String[] split = techImportExcel.getAddress().split(";");
|
regionIds = new ArrayList<>();
|
for (String s : split) {
|
TRegion region = regionService.lambdaQuery().like(TRegion::getName, s).one();
|
if (region == null) {
|
msg = "第" + techImportExcels.indexOf(techImportExcel) + "行,地区不存在";
|
failMsg.add(msg);
|
} else {
|
regionIds.add(region.getId());
|
}
|
}
|
if (regionIds.size() != split.length) {
|
continue;
|
}
|
|
}
|
TTitleMajor tTechnicalTitle = new TTitleMajor();
|
if (techImportExcel.getTitileName()==null||StringUtils.isEmpty(techImportExcel.getTitileName())){
|
msg = "第" + techImportExcels.indexOf(techImportExcel) + "行,职称名称不能为空";
|
failMsg.add(msg);
|
continue;
|
}else {
|
TTechnicalTitle one = tTechnicalTitleService.lambdaQuery().eq(TTechnicalTitle::getTitileName, techImportExcel.getTitileName()).last("limit 1").one();
|
if (one!=null){
|
tTechnicalTitle.setTechnicalId(one.getId());
|
}else {
|
msg = "第" + techImportExcels.indexOf(techImportExcel) + "行,职称名称不存在";
|
failMsg.add(msg);
|
continue;
|
}
|
}
|
|
|
|
tTechnicalTitle.setRegionIds(StringUtils.join(regionIds, ","));
|
tTechnicalTitle.setMajorName(techImportExcel.getMajorName());
|
tTechnicalTitles.add(tTechnicalTitle);
|
}
|
|
if (failMsg.size()==0){
|
tTitleMajorService.saveBatch(tTechnicalTitles);
|
}else {
|
return R.fail(failMsg.stream().collect(Collectors.joining(",")));
|
}
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
// logger.error("批量购入导入失败:{}",e.getMessage());
|
// importRecordService.removeById(tImportRecord.getId());
|
return R.fail("批量购入导入失败!");
|
}finally {
|
try {
|
inputStream.close();
|
} catch (IOException e) {
|
throw new ServiceException(e.getMessage());
|
}
|
}
|
|
|
return R.ok();
|
}
|
|
|
@ApiOperation(value = "通过职称分类查询专业",tags = "后台-下拉框")
|
@PostMapping(value = "/select")
|
public R<List<TTitleMajor>> select(@RequestParam Long id){
|
return R.ok(tTitleMajorService.lambdaQuery().eq(TTitleMajor::getTechnicalId,id).list());
|
}
|
@Resource
|
private TLevelService levelService;
|
@ApiOperation(value = "类别",tags = "后台-下拉框")
|
@PostMapping(value = "/level/select")
|
public R<List<TLevel>> levelselect(){
|
return R.ok(levelService.list());
|
}
|
|
|
}
|