310 lines
13 KiB
Plaintext
310 lines
13 KiB
Plaintext
package com.sercurityControl.proteam.controller;
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.securityControl.common.core.utils.StringUtils;
|
|
import com.securityControl.common.core.utils.poi.ExcelUtil;
|
|
import com.securityControl.common.log.annotation.Log;
|
|
import com.securityControl.common.log.enums.BusinessType;
|
|
import com.securityControl.common.log.enums.OperationType;
|
|
import com.securityControl.common.security.utils.SecurityUtils;
|
|
import com.sercurityControl.proteam.domain.vo.ReturnCodeEntity;
|
|
import com.sercurityControl.proteam.domain.vo.SupeConsUserVo;
|
|
import com.sercurityControl.proteam.service.ManageService;
|
|
import com.sercurityControl.proteam.util.BaseController;
|
|
import com.sercurityControl.proteam.util.DateTimeHelper;
|
|
import com.sercurityControl.proteam.util.ImportExcelHelper;
|
|
import com.sercurityControl.proteam.util.ResultModel;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.poi.util.IOUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
|
|
|
import javax.servlet.ServletOutputStream;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.net.URLEncoder;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* 监理单位 、施工单位维护信息层
|
|
*/
|
|
@RestController
|
|
@Slf4j
|
|
@RequestMapping("/sys/manage/")
|
|
public class ManageController extends BaseController {
|
|
|
|
@Autowired
|
|
private ManageService service;
|
|
|
|
/**
|
|
* 分页查询
|
|
*
|
|
* @param supeConsUserVo
|
|
* @return
|
|
*/
|
|
@PostMapping("getPageInfo")
|
|
@Log(title = "单位管理", menu = "施工单位管理->监理单位管理", businessType = BusinessType.QUERY, grade = OperationType.QUERY_BUSINESS, details = "施工单位-监理单位")
|
|
public Map<String, Object> getPageInfo(SupeConsUserVo supeConsUserVo) {
|
|
PageHelper.startPage(supeConsUserVo.getPage(), supeConsUserVo.getLimit());
|
|
List<SupeConsUserVo> deviceList = service.getPageInfo(supeConsUserVo);
|
|
PageInfo<SupeConsUserVo> pageInfo = new PageInfo<SupeConsUserVo>(deviceList);
|
|
System.out.println("输出分页后的数据:" + pageInfo.getList());
|
|
Map<String, Object> map = new HashMap<String, Object>(16);
|
|
map.put("code", 200);
|
|
map.put("msg", "");
|
|
map.put("count", pageInfo.getTotal());
|
|
map.put("curr", supeConsUserVo.getPage());
|
|
map.put("limit", supeConsUserVo.getLimit());
|
|
map.put("data", pageInfo.getList());
|
|
return map;
|
|
}
|
|
|
|
@PostMapping("insertData")
|
|
@Log(title = "单位管理", menu = "施工单位管理->监理单位管理", businessType = BusinessType.INSERT, details = "施工单位-监理单位", grade = OperationType.ADD_BUSINESS)
|
|
public ReturnCodeEntity insertData(SupeConsUserVo supeConsUserVo) {
|
|
ReturnCodeEntity entity = new ReturnCodeEntity();
|
|
try {
|
|
entity = service.insertData(supeConsUserVo);
|
|
} catch (Exception e) {
|
|
entity.setCode("202");
|
|
entity.setMsg("解析异常,请联系管理员");
|
|
}
|
|
return entity;
|
|
}
|
|
|
|
@PostMapping("updateData")
|
|
@Log(title = "单位管理", menu = "施工单位管理->监理单位管理", businessType = BusinessType.UPDATE, details = "施工单位-监理单位", grade = OperationType.UPDATE_BUSINESS)
|
|
public ReturnCodeEntity updateData(SupeConsUserVo deviceVo) {
|
|
ReturnCodeEntity entity = new ReturnCodeEntity();
|
|
try {
|
|
entity = service.updateData(deviceVo);
|
|
} catch (Exception e) {
|
|
entity.setCode("202");
|
|
entity.setMsg("解析异常,请联系管理员");
|
|
}
|
|
return entity;
|
|
}
|
|
|
|
/**
|
|
* 删除角色
|
|
*
|
|
* @param
|
|
* @return
|
|
*/
|
|
@PostMapping("deleteData")
|
|
@Log(title = "单位管理", menu = "施工单位管理->监理单位管理", businessType = BusinessType.DELETE, details = "删除单位", grade = OperationType.DELETE_BUSINESS)
|
|
public ReturnCodeEntity deleteData(String keyId) {
|
|
ReturnCodeEntity entity = new ReturnCodeEntity();
|
|
try {
|
|
entity = service.deleteData(keyId);
|
|
} catch (Exception e) {
|
|
entity.setCode("202");
|
|
entity.setMsg("解析异常,请联系管理员");
|
|
}
|
|
return entity;
|
|
}
|
|
|
|
/**
|
|
* 查看详情
|
|
*
|
|
* @param
|
|
* @return
|
|
*/
|
|
@PostMapping("getDataDetail")
|
|
@Log(title = "单位管理", menu = "施工单位管理->监理单位管理", businessType = BusinessType.QUERY, details = "查看单位详情", grade = OperationType.QUERY_BUSINESS)
|
|
public SupeConsUserVo getDataDetail(String keyId) {
|
|
SupeConsUserVo supeConsUserVo = null;
|
|
try {
|
|
supeConsUserVo = service.getDataDetail(keyId);
|
|
return supeConsUserVo;
|
|
} catch (Exception e) {
|
|
log.error(e.toString(), e);
|
|
}
|
|
return supeConsUserVo;
|
|
}
|
|
|
|
/**
|
|
* 导出
|
|
*
|
|
* @param response
|
|
* @param supeConsUserVo
|
|
*/
|
|
@GetMapping("exportDevice")
|
|
public void exportDevice(HttpServletResponse response, SupeConsUserVo supeConsUserVo) {
|
|
List<SupeConsUserVo> studentsList = service.getPageInfo(supeConsUserVo);
|
|
ExcelUtil<SupeConsUserVo> util = new ExcelUtil<SupeConsUserVo>(SupeConsUserVo.class);
|
|
util.exportExcel(response, studentsList, "施工单位");
|
|
}
|
|
|
|
|
|
/**
|
|
* 下拉选查询
|
|
*
|
|
* @param
|
|
* @return
|
|
*/
|
|
@PostMapping("getSelected")
|
|
public List<SupeConsUserVo> getSelected(SupeConsUserVo supeConsUserVo) {
|
|
try {
|
|
List<SupeConsUserVo> studentsList = service.getPageInfo(supeConsUserVo);
|
|
return studentsList;
|
|
} catch (Exception e) {
|
|
log.error(e.toString(), e);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @param request
|
|
* @param response
|
|
* @description 监理单位/施工单位 模板下载
|
|
* @author cwchen
|
|
* @date 2024/1/23 11:07
|
|
*/
|
|
@GetMapping("downLoadExcelModel")
|
|
public void downLoadExcelModel(HttpServletRequest request, HttpServletResponse response) {
|
|
InputStream inputStream = null;
|
|
ServletOutputStream servletOutputStream = null;
|
|
try {
|
|
String path = "download/" + "unit_model.xlsx";
|
|
inputStream = this.getClass().getClassLoader().getResourceAsStream(path);
|
|
response.setContentType("application/vnd.ms-excel");
|
|
response.addHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
|
response.addHeader("charset", "utf-8");
|
|
response.addHeader("Pragma", "no-cache");
|
|
String encodeName = URLEncoder.encode("gt_model.xlsx", StandardCharsets.UTF_8.toString());
|
|
response.setHeader("Content-Disposition", "attachment; filename=\"" + encodeName + "\"; filename*=utf-8''" + encodeName);
|
|
servletOutputStream = response.getOutputStream();
|
|
IOUtils.copy(inputStream, servletOutputStream);
|
|
response.flushBuffer();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
} finally {
|
|
try {
|
|
if (servletOutputStream != null) {
|
|
servletOutputStream.close();
|
|
}
|
|
if (inputStream != null) {
|
|
inputStream.close();
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
|
|
@PostMapping("/importExcel")
|
|
@Log(title = "监理/施工单位数据导入", menu = "监理/施工单位数据导入", businessType = BusinessType.IMPORT, details = "监理/施工单位数据导入", grade = OperationType.IMPORT_BUSINESS)
|
|
public void importExcel(MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
|
|
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
|
|
MultipartHttpServletRequest multiReq = multipartResolver.resolveMultipart(request);
|
|
// 1.施工单位 2.监理单位
|
|
String type = multiReq.getParameter("type");
|
|
Long userId = SecurityUtils.getLoginUser().getUserid();
|
|
String nowTime = DateTimeHelper.getNowTime();
|
|
try {
|
|
List<JSONObject> lstObj = (List<JSONObject>) ImportExcelHelper.readExcel(file, SupeConsUserVo.class);
|
|
List<SupeConsUserVo> list = new ArrayList<>();
|
|
List<JSONObject> lstError = new ArrayList<>();
|
|
if (lstObj != null && lstObj.size() > 0) {
|
|
list = new ArrayList<>();
|
|
lstError = new ArrayList<>();
|
|
for (JSONObject obj : lstObj) {
|
|
if (StringUtils.isBlank(obj.getString("name"))) {
|
|
JSONObject error = new JSONObject();
|
|
error.put("errorRow", obj.getString("rowNo"));
|
|
error.put("errorLine", "单位名称");
|
|
error.put("errorData", "");
|
|
error.put("errorMsg", "单位名称不能为空");
|
|
lstError.add(error);
|
|
continue;
|
|
}
|
|
if (StringUtils.isNotBlank(obj.getString("name")) && obj.getString("name").length() > 200) {
|
|
JSONObject error = new JSONObject();
|
|
error.put("errorRow", obj.getString("rowNo"));
|
|
error.put("errorLine", "单位名称");
|
|
error.put("errorData", obj.getString("name"));
|
|
error.put("errorMsg", "单位名称超过200个字符");
|
|
lstError.add(error);
|
|
continue;
|
|
}
|
|
if (StringUtils.isBlank(obj.getString("code"))) {
|
|
JSONObject error = new JSONObject();
|
|
error.put("errorRow", obj.getString("rowNo"));
|
|
error.put("errorLine", "单位编码");
|
|
error.put("errorData", "");
|
|
error.put("errorMsg", "单位编码不能为空");
|
|
lstError.add(error);
|
|
continue;
|
|
}
|
|
if (StringUtils.isNotBlank(obj.getString("code")) && obj.getString("code").length() > 200) {
|
|
JSONObject error = new JSONObject();
|
|
error.put("errorRow", obj.getString("rowNo"));
|
|
error.put("errorLine", "单位编码");
|
|
error.put("errorData", obj.getString("code"));
|
|
error.put("errorMsg", "单位编码超过200个字符");
|
|
lstError.add(error);
|
|
continue;
|
|
}
|
|
if (StringUtils.isNotBlank(obj.getString("remarks")) && obj.getString("remarks").length() > 200) {
|
|
JSONObject error = new JSONObject();
|
|
error.put("errorRow", obj.getString("rowNo"));
|
|
error.put("errorLine", "备注");
|
|
error.put("errorData", obj.getString("remarks"));
|
|
error.put("errorMsg", "备注超过200个字符");
|
|
lstError.add(error);
|
|
continue;
|
|
}
|
|
SupeConsUserVo vo = new SupeConsUserVo();
|
|
vo.setName(obj.getString("name"));
|
|
vo.setCode(obj.getString("code"));
|
|
vo.setRemarks(obj.getString("remarks"));
|
|
vo.setType(type);
|
|
vo.setCreateTime(nowTime);
|
|
vo.setCreateUser(userId + "");
|
|
list.add(vo);
|
|
}
|
|
}
|
|
ResultModel resultModel = new ResultModel();
|
|
if (lstError != null && lstError.size() > 0) {
|
|
resultModel.setSuccess(false);
|
|
resultModel.setStatus(200);
|
|
resultModel.setMsg("导入成功");
|
|
resultModel.setData(lstError);
|
|
} else if (lstError.size() == 0) {
|
|
service.addSuperConsData(list);
|
|
resultModel.setSuccess(true);
|
|
resultModel.setStatus(200);
|
|
resultModel.setMsg("导入成功");
|
|
resultModel.setData(null);
|
|
}
|
|
sendJson(response, resultModel);
|
|
} catch (Exception ex) {
|
|
ex.printStackTrace();
|
|
resultModel = new ResultModel();
|
|
resultModel.setSuccess(false);
|
|
resultModel.setStatus(1000);
|
|
resultModel.setMsg("服务异常");
|
|
try {
|
|
sendJson(response, resultModel);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|