|
@@ -0,0 +1,371 @@
|
|
|
|
+package com.jpsoft.excellent.modules.base.controller;
|
|
|
|
+
|
|
|
|
+import com.github.pagehelper.Page;
|
|
|
|
+import com.jpsoft.excellent.config.OSSConfig;
|
|
|
|
+import com.jpsoft.excellent.modules.base.entity.Area;
|
|
|
|
+import com.jpsoft.excellent.modules.base.entity.WorkStation;
|
|
|
|
+import com.jpsoft.excellent.modules.base.entity.WorkWindow;
|
|
|
|
+import com.jpsoft.excellent.modules.base.service.AreaService;
|
|
|
|
+import com.jpsoft.excellent.modules.common.utils.OSSUtil;
|
|
|
|
+import com.jpsoft.excellent.modules.common.utils.POIUtils;
|
|
|
|
+import com.jpsoft.excellent.modules.common.utils.PojoUtils;
|
|
|
|
+import com.jpsoft.excellent.modules.common.dto.Sort;
|
|
|
|
+import com.jpsoft.excellent.modules.common.dto.MessageResult;
|
|
|
|
+import com.jpsoft.excellent.modules.base.entity.Office;
|
|
|
|
+import com.jpsoft.excellent.modules.base.service.OfficeService;
|
|
|
|
+import io.swagger.annotations.Api;
|
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
+
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.*;
|
|
|
|
+
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/base/office")
|
|
|
|
+@Api(description = "office")
|
|
|
|
+public class OfficeController {
|
|
|
|
+ private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private OSSConfig ossConfig;
|
|
|
|
+ @Autowired
|
|
|
|
+ private OfficeService officeService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private AreaService areaService;
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="创建空记录")
|
|
|
|
+ @GetMapping("create")
|
|
|
|
+ public MessageResult<Office> create(){
|
|
|
|
+ MessageResult<Office> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ Office office = new Office();
|
|
|
|
+
|
|
|
|
+ msgResult.setData(office);
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="添加信息")
|
|
|
|
+ @PostMapping("add")
|
|
|
|
+ public MessageResult<Office> add(@RequestBody Office office,@RequestAttribute String subject){
|
|
|
|
+ MessageResult<Office> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ office.setId(UUID.randomUUID().toString());
|
|
|
|
+ office.setDelFlag(false);
|
|
|
|
+ office.setCreateBy(subject);
|
|
|
|
+ office.setCreateTime(new Date());
|
|
|
|
+
|
|
|
|
+ int affectCount = officeService.insert(office);
|
|
|
|
+
|
|
|
|
+ if (affectCount > 0) {
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(office);
|
|
|
|
+ } else {
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage("数据库添加失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch(Exception ex){
|
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="获取信息")
|
|
|
|
+ @GetMapping("edit/{id}")
|
|
|
|
+ public MessageResult<Office> edit(@PathVariable("id") String id){
|
|
|
|
+ MessageResult<Office> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ Office office = officeService.get(id);
|
|
|
|
+ Area area = areaService.get(office.getAreaId());
|
|
|
|
+ if(area != null){
|
|
|
|
+ office.setAreaName(area.getName());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (office != null) {
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(office);
|
|
|
|
+ } else {
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage("数据库不存在该记录!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch(Exception ex){
|
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="更新用户")
|
|
|
|
+ @PostMapping("update")
|
|
|
|
+ public MessageResult<Office> update(@RequestBody Office office,@RequestAttribute String subject){
|
|
|
|
+ MessageResult<Office> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ office.setUpdateBy(subject);
|
|
|
|
+ office.setUpdateTime(new Date());
|
|
|
|
+
|
|
|
|
+ int affectCount = officeService.update(office);
|
|
|
|
+
|
|
|
|
+ if (affectCount > 0) {
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(office);
|
|
|
|
+ } else {
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage("数据库更新失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch(Exception ex){
|
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="删除")
|
|
|
|
+ @PostMapping("delete/{id}")
|
|
|
|
+ public MessageResult<Integer> delete(@PathVariable("id") String id,@RequestAttribute String subject){
|
|
|
|
+ MessageResult<Integer> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ Office office = officeService.get(id);
|
|
|
|
+ office.setDelFlag(true);
|
|
|
|
+ office.setUpdateBy(subject);
|
|
|
|
+ office.setUpdateTime(new Date());
|
|
|
|
+
|
|
|
|
+ int affectCount = officeService.update(office);
|
|
|
|
+
|
|
|
|
+ if (affectCount > 0) {
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(affectCount);
|
|
|
|
+ } else {
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage("删除失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch(Exception ex){
|
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="批量删除")
|
|
|
|
+ @PostMapping("batchDelete")
|
|
|
|
+ public MessageResult<Integer> batchDelete(@RequestBody List<String> idList,@RequestAttribute String subject){
|
|
|
|
+ MessageResult<Integer> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ int affectCount = 0;
|
|
|
|
+
|
|
|
|
+ for (String id : idList) {
|
|
|
|
+ Office office = officeService.get(id);
|
|
|
|
+ office.setDelFlag(true);
|
|
|
|
+ office.setUpdateBy(subject);
|
|
|
|
+ office.setUpdateTime(new Date());
|
|
|
|
+
|
|
|
|
+ affectCount += officeService.update(office);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (affectCount > 0) {
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(affectCount);
|
|
|
|
+ } else {
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage("删除失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch(Exception ex){
|
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="列表")
|
|
|
|
+ @RequestMapping(value = "pageList",method = RequestMethod.POST)
|
|
|
|
+ public MessageResult<Map> pageList(
|
|
|
|
+ String areaId, String name,
|
|
|
|
+ @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
|
|
|
|
+ @RequestParam(value="pageSize",defaultValue="20") int pageSize,
|
|
|
|
+ @RequestAttribute String subject){
|
|
|
|
+ MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ Map<String,Object> searchParams = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
|
+ sortList.add(new Sort("name_","asc"));
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isNotEmpty(areaId)) {
|
|
|
|
+ searchParams.put("areaId",areaId);
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotEmpty(name)) {
|
|
|
|
+ searchParams.put("name","%" + name + "%");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Page<Office> page = officeService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
|
|
|
|
+ for(Office office : page.getResult()){
|
|
|
|
+ office.setAreaName(parentFullName(office.getAreaId()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(PojoUtils.pageWrapper(page));
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String parentFullName(String parentId){
|
|
|
|
+ String fullName = "";
|
|
|
|
+
|
|
|
|
+ Area area = areaService.get(parentId);
|
|
|
|
+ if(StringUtils.isNotEmpty(area.getParentId())){
|
|
|
|
+ fullName = parentFullName(area.getParentId()) + "-" + area.getName();
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ fullName = area.getName();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return fullName;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="导入站点")
|
|
|
|
+ @PostMapping("importXls")
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
+ @ApiImplicitParam(name = "uploadFile",value = "上传文件", required = true,paramType="form", dataType = "__file")
|
|
|
|
+ })
|
|
|
|
+ public MessageResult<String> importXls(MultipartFile uploadFile, @RequestAttribute String subject){
|
|
|
|
+ MessageResult<String> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ POIUtils poiUtils = new POIUtils(uploadFile.getInputStream());
|
|
|
|
+ Sheet sheet1 = poiUtils.getSheetAt(0);
|
|
|
|
+
|
|
|
|
+ int affectCount = 0;
|
|
|
|
+ int failCount = 0;
|
|
|
|
+ int validateColIndex = 2;
|
|
|
|
+
|
|
|
|
+ for(int rowIndex=1; rowIndex<=sheet1.getLastRowNum(); rowIndex++){
|
|
|
|
+ try {
|
|
|
|
+ String strArea = poiUtils.getCellValue(0,rowIndex,0).toString();
|
|
|
|
+ String strName = poiUtils.getCellValue(0,rowIndex,1).toString();
|
|
|
|
+
|
|
|
|
+ //单位信息
|
|
|
|
+ Office office = new Office();
|
|
|
|
+ office.setId(UUID.randomUUID().toString());
|
|
|
|
+ office.setDelFlag(false);
|
|
|
|
+ office.setCreateBy(subject);
|
|
|
|
+ office.setCreateTime(new Date());
|
|
|
|
+
|
|
|
|
+ if(StringUtils.isNotEmpty(strArea)){
|
|
|
|
+ Area area = areaService.getByName(strArea);
|
|
|
|
+ if(area != null) {
|
|
|
|
+ office.setAreaId(area.getId());
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("未找到该区域!");
|
|
|
|
+ failCount++;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("请填写区域!");
|
|
|
|
+ failCount++;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(StringUtils.isNotEmpty(strName)){
|
|
|
|
+ office.setName(strName);
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("请填写单位名称!");
|
|
|
|
+ failCount++;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<Office> officeExtant = officeService.listByName(strName);
|
|
|
|
+ if(officeExtant.size() == 0) {
|
|
|
|
+ officeService.insert(office);
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ office = officeExtant.get(0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ affectCount++;
|
|
|
|
+ }
|
|
|
|
+ catch(Exception innerEx){
|
|
|
|
+ logger.error(innerEx.getMessage(),innerEx);
|
|
|
|
+ failCount++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (failCount>0){
|
|
|
|
+ //有导入失败的记录
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage("数据成功导入" + affectCount + "条,有" + failCount + "条数据未导入成功,错误原因请查看报表。");
|
|
|
|
+
|
|
|
|
+ //todo 只保留错误数据的sheet
|
|
|
|
+ Workbook wb = poiUtils.exportErrorXls(0,validateColIndex,1 + affectCount + failCount);
|
|
|
|
+
|
|
|
|
+ //todo 将wb保存到oss
|
|
|
|
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
|
+ wb.write(output);
|
|
|
|
+
|
|
|
|
+ byte[] buffer = output.toByteArray();
|
|
|
|
+ ByteArrayInputStream input = new ByteArrayInputStream(buffer);
|
|
|
|
+
|
|
|
|
+ //格式化holidayInfo
|
|
|
|
+ SimpleDateFormat sim = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
|
+ String fileName = "error" + sim.format(new Date()) + ".xls";
|
|
|
|
+ String downloadUrl = OSSUtil.upload(ossConfig,"excellent",fileName,input);
|
|
|
|
+
|
|
|
|
+ //todo 返回导入失败报表下载链接
|
|
|
|
+ msgResult.setData(downloadUrl);
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setMessage("数据成功导入" + affectCount + "条");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch(Exception ex){
|
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+}
|