| | |
| | | package com.ycl.controller.depart; |
| | | |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.context.AnalysisContext; |
| | | import com.alibaba.excel.read.listener.ReadListener; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | |
| | | import com.ycl.api.BasePageVO; |
| | | import com.ycl.api.CommonResult; |
| | | import com.ycl.controller.BaseController; |
| | | import com.ycl.dto.UmsDepartDto; |
| | | import com.ycl.entity.depart.UmsDepart; |
| | | import com.ycl.entity.dict.DataDictionary; |
| | | import com.ycl.mapper.depart.UmsDepartMapper; |
| | | import com.ycl.mapper.dict.DataDictionary2Mapper; |
| | | import com.ycl.service.depart.UmsDepartService; |
| | | import com.ycl.service.user.UmsDepartManageService; |
| | | import com.ycl.utils.EasyExcelUtils; |
| | | import com.ycl.utils.auth.UserAuthUtil; |
| | | import com.ycl.vo.depart.DepartVO; |
| | | import com.ycl.vo.depart.UmsDepartVO; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | return CommonResult.success(page); |
| | | } |
| | | |
| | | @ApiOperation("部门导出") |
| | | @PostMapping("/export") |
| | | public void exportDpt(HttpServletResponse response) { |
| | | List<UmsDepartDto> umsDepartDtos = departService.departExp(); |
| | | String sheetName = "部门导出"; |
| | | EasyExcelUtils.export1(response, sheetName, UmsDepartDto.class, umsDepartDtos, "部门导出"); |
| | | } |
| | | |
| | | @Resource |
| | | private UmsDepartMapper sccgDepartMapper; |
| | | @Resource |
| | | private DataDictionary2Mapper dataDictionary2Mapper; |
| | | @ApiOperation("部门导入") |
| | | @PostMapping("/import") |
| | | public CommonResult importDpt(MultipartFile file) throws IOException { |
| | | EasyExcel.read(file.getInputStream()) |
| | | .head(UmsDepartDto.class) |
| | | .registerReadListener(new ReadListener<UmsDepartDto>() { |
| | | @Override |
| | | public void invoke(UmsDepartDto umsDepartDto, AnalysisContext analysisContext) { |
| | | // 不能重复插入 |
| | | String departTypeName = umsDepartDto.getDepartTypeName(); |
| | | UmsDepart one = sccgDepartMapper.selectOne(new LambdaQueryWrapper<UmsDepart>().eq(UmsDepart::getDepartName, departTypeName)); |
| | | if (Objects.nonNull(one)){ |
| | | throw new RuntimeException("该部门已经存在"); |
| | | } |
| | | UmsDepart umsDepart = new UmsDepart(); |
| | | // 设置部门名字 |
| | | umsDepart.setDepartName(umsDepartDto.getDepartTypeName()); |
| | | // 设置部门描述 |
| | | umsDepart.setDepartDes(umsDepartDto.getDepartDes()); |
| | | // 设置部门类型 |
| | | DataDictionary dataDictionary = dataDictionary2Mapper.selectOne(new LambdaQueryWrapper<DataDictionary>().eq(DataDictionary::getName, umsDepartDto.getDepartType())); |
| | | if (Objects.isNull(dataDictionary)){ |
| | | throw new RuntimeException("部门类型不存在"); |
| | | }else { |
| | | umsDepart.setDepartType(new Long(dataDictionary.getId()).intValue()); |
| | | } |
| | | // 设置父id |
| | | UmsDepart two = sccgDepartMapper.selectOne(new LambdaQueryWrapper<UmsDepart>().eq(UmsDepart::getDepartName, umsDepartDto.getParentDepartName())); |
| | | if (Objects.nonNull(two)){ |
| | | umsDepart.setParentId(two.getParentId()); |
| | | } |
| | | int insert = sccgDepartMapper.insert(umsDepart); |
| | | if (insert < 1){ |
| | | throw new RuntimeException("插入失败"); |
| | | } |
| | | } |
| | | @Override |
| | | public void doAfterAllAnalysed(AnalysisContext analysisContext) { |
| | | |
| | | } |
| | | }).sheet().doRead(); |
| | | return CommonResult.success(true, "导入成功"); |
| | | } |
| | | |
| | | @ApiOperation("查询我的部门") |
| | | @GetMapping(value = "/belongDepart") |
| | | public CommonResult<BasePageDTO> belongDepart(BasePageVO params) { |