|
|
|
|
@ -1,9 +1,21 @@
|
|
|
|
|
package com.biutag.lan.controller.system; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
|
import com.alibaba.excel.ExcelReader; |
|
|
|
|
import com.alibaba.excel.context.AnalysisContext; |
|
|
|
|
import com.alibaba.excel.read.listener.ReadListener; |
|
|
|
|
import com.alibaba.excel.read.metadata.ReadSheet; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.biutag.aop.NotPower; |
|
|
|
|
import com.biutag.core.AjaxResult; |
|
|
|
|
import com.biutag.core.PageResult; |
|
|
|
|
import com.biutag.entity.system.Dept; |
|
|
|
|
import com.biutag.entity.system.Duty; |
|
|
|
|
import com.biutag.entity.system.PoliceUser; |
|
|
|
|
import com.biutag.enums.DeptTypeEnum; |
|
|
|
|
import com.biutag.lan.aop.Log; |
|
|
|
|
import com.biutag.lan.domain.bo.DutyImport; |
|
|
|
|
import com.biutag.lan.domain.validate.commons.IdValidate; |
|
|
|
|
import com.biutag.lan.domain.validate.commons.PageValidate; |
|
|
|
|
import com.biutag.lan.domain.validate.system.DutyCreateValidate; |
|
|
|
|
@ -11,7 +23,9 @@ import com.biutag.lan.domain.validate.system.DutySearchValidate;
|
|
|
|
|
import com.biutag.lan.domain.validate.system.DutyUpdateValidate; |
|
|
|
|
import com.biutag.lan.domain.vo.system.DutyDetailVo; |
|
|
|
|
import com.biutag.lan.domain.vo.system.DutyListedVo; |
|
|
|
|
import com.biutag.lan.mapper.PoliceUserMapper; |
|
|
|
|
import com.biutag.lan.service.IDutyService; |
|
|
|
|
import com.biutag.mapper.system.DeptMapper; |
|
|
|
|
import com.biutag.validator.annotation.IDMust; |
|
|
|
|
import io.swagger.v3.oas.annotations.Operation; |
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag; |
|
|
|
|
@ -20,6 +34,11 @@ import org.springframework.validation.annotation.Validated;
|
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
|
|
@RestController |
|
|
|
|
@RequestMapping("api/duty") |
|
|
|
|
@Tag(name = "值班管理") |
|
|
|
|
@ -28,6 +47,12 @@ public class DutyController {
|
|
|
|
|
@Resource |
|
|
|
|
IDutyService iDutyService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
DeptMapper deptMapper; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
PoliceUserMapper policeUserMapper; |
|
|
|
|
|
|
|
|
|
@GetMapping("/list") |
|
|
|
|
@Operation(summary = "值班列表") |
|
|
|
|
public AjaxResult<PageResult<DutyListedVo>> list(@Validated PageValidate pageValidate, |
|
|
|
|
@ -71,9 +96,48 @@ public class DutyController {
|
|
|
|
|
@Log(title = "值班导入") |
|
|
|
|
@PostMapping("/import") |
|
|
|
|
@Operation(summary = "值班导入") |
|
|
|
|
public AjaxResult<Void> dataImport(@RequestPart("file") MultipartFile file) { |
|
|
|
|
public AjaxResult<Void> dataImport(@RequestPart("file") MultipartFile file) throws IOException { |
|
|
|
|
List<DutyImport> list = new ArrayList<>(); |
|
|
|
|
ExcelReader excelReader = EasyExcel.read(file.getInputStream(), DutyImport.class, new ReadListener<DutyImport>() { |
|
|
|
|
|
|
|
|
|
return AjaxResult.success(); |
|
|
|
|
@Override |
|
|
|
|
public void invoke(DutyImport data, AnalysisContext analysisContext) { |
|
|
|
|
list.add(data); |
|
|
|
|
} |
|
|
|
|
@Override |
|
|
|
|
public void doAfterAllAnalysed(AnalysisContext analysisContext) { |
|
|
|
|
} |
|
|
|
|
}).build(); |
|
|
|
|
|
|
|
|
|
ReadSheet sheet = EasyExcel.readSheet(0).build(); |
|
|
|
|
excelReader.read(sheet); |
|
|
|
|
excelReader.close(); |
|
|
|
|
List<Duty> dutyList = list.stream().map(item -> { |
|
|
|
|
Duty duty = new Duty(); |
|
|
|
|
String date = DateUtil.format(DateUtil.parse(item.getDate(), "yyyy/MM/dd"), "yyyy-MM-dd"); |
|
|
|
|
duty.setStartTime(date); |
|
|
|
|
duty.setEndTime(date); |
|
|
|
|
duty.setPoliceName(item.getPoliceName()); |
|
|
|
|
duty.setEmpNo(item.getEmpNo()); |
|
|
|
|
duty.setMobile(item.getMobile()); |
|
|
|
|
PoliceUser policeUser = policeUserMapper.selectOne(new LambdaQueryWrapper<PoliceUser>().eq(PoliceUser::getEmpNo, item.getEmpNo())); |
|
|
|
|
if (Objects.isNull(policeUser)) { |
|
|
|
|
throw new RuntimeException(String.format("警号[%s]无该警员信息", item.getEmpNo())); |
|
|
|
|
} |
|
|
|
|
Dept dept = deptMapper.selectById(policeUser.getDataDeptId()); |
|
|
|
|
if (Objects.isNull(dept)) { |
|
|
|
|
throw new RuntimeException("未找到单位信息"); |
|
|
|
|
} |
|
|
|
|
duty.setRoleId(policeUser.getRoleIds()); |
|
|
|
|
duty.setDepartId(String.valueOf(policeUser.getDataDeptId())); |
|
|
|
|
duty.setDepartName(dept.getName()); |
|
|
|
|
duty.setDeptType(dept.getCategory()); |
|
|
|
|
duty.setTypeName(DeptTypeEnum.get(dept.getCategory()).getName()); |
|
|
|
|
duty.setCreateTime(System.currentTimeMillis() / 1000); |
|
|
|
|
return duty; |
|
|
|
|
}).toList(); |
|
|
|
|
iDutyService.saveBatch(dutyList); |
|
|
|
|
return AjaxResult.success(String.format("已导入%s条数据", dutyList.size())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|