| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- package cn.com.goldenwater.dcproj.controller.ducha;
- import cn.com.goldenwater.core.web.BaseController;
- import cn.com.goldenwater.core.web.BaseResponse;
- import cn.com.goldenwater.dcproj.model.BisInspBaseNew;
- import cn.com.goldenwater.dcproj.param.BisInspBaseNewParam;
- import cn.com.goldenwater.dcproj.service.BisInspBaseNewService;
- import cn.com.goldenwater.dcproj.util.ReadExcelUtil;
- import cn.com.goldenwater.dcproj.utils.StringUtils;
- import cn.com.goldenwater.dcproj.utils.impexcel.ExpAndImpUtil;
- import cn.com.goldenwater.id.util.UuidUtil;
- import com.github.pagehelper.PageInfo;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import io.swagger.annotations.ApiParam;
- import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.util.Assert;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import javax.servlet.http.HttpServletResponse;
- import java.io.File;
- import java.io.IOException;
- import java.nio.file.Paths;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- /**
- * @author lql
- * @date 2026-1-12
- */
- @Api(value = "通用对象表管理", tags = "通用对象表管理")
- @RestController
- @RequestMapping("/bis/insp/baseNew")
- public class BisInspBaseNewController extends BaseController {
- private Logger logger = LoggerFactory.getLogger(getClass());
- @Value("${export.templatePath}")
- private String templatePath;
- @Autowired
- private BisInspBaseNewService bisInspBaseNewService;
- @ApiOperation(value = "添加通用对象表")
- @RequestMapping(value = "/add", method = RequestMethod.POST)
- public BaseResponse<BisInspBaseNew> insert(@ApiParam(name = "bisInspBaseNew", value = "BisInspBaseNew", required = true) @RequestBody BisInspBaseNew bisInspBaseNew) {
- int ret = bisInspBaseNewService.insert(bisInspBaseNew);
- return buildSuccessResponse(bisInspBaseNew);
- }
- @ApiOperation(value = "根据ID删除通用对象表")
- @RequestMapping(value = "delete", method = RequestMethod.POST)
- public BaseResponse delete(@ApiParam(name = "ids", value = "ids", required = true) @RequestParam String ids) {
- String[] idArray = ids.split(",");
- for (String id : idArray) {
- int ret = bisInspBaseNewService.delete(id);
- }
- return buildSuccessResponse();
- }
- @ApiOperation(value = "更新通用对象表信息")
- @RequestMapping(value = "/update", method = RequestMethod.POST)
- public BaseResponse<BisInspBaseNew> update(@ApiParam(name = "bisInspBaseNew", value = "BisInspBaseNew", required = true) @RequestBody BisInspBaseNew bisInspBaseNew) {
- Assert.notNull(bisInspBaseNew.getId(), "主键id为必填参数");
- int ret = bisInspBaseNewService.update(bisInspBaseNew);
- return buildSuccessResponse(bisInspBaseNew);
- }
- @ApiOperation(value = "根据ID获取通用对象表(单表)")
- @RequestMapping(value = "/{id}", method = RequestMethod.GET)
- public BaseResponse<BisInspBaseNew> get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
- BisInspBaseNew bisInspBaseNew = bisInspBaseNewService.get(id);
- return buildSuccessResponse(bisInspBaseNew);
- }
- @ApiOperation(value = "根据ID获取通用对象表(单表)")
- @RequestMapping(value = "/getByRgstr/{id}", method = RequestMethod.GET)
- public BaseResponse<BisInspBaseNew> getByRgstr(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
- BisInspBaseNew bisInspBaseNew = bisInspBaseNewService.getByRgstrId(id);
- return buildSuccessResponse(bisInspBaseNew);
- }
- @ApiOperation(value = "根据ID获取通用对象表(分页)")
- @RequestMapping(value = "/list", method = RequestMethod.POST)
- public BaseResponse<PageInfo> pageList(@ApiParam(name = "bisInspBaseNewParam", value = "bisInspBaseNewParam", required = true)
- @RequestBody(required = false) BisInspBaseNewParam param) {
- if (StringUtils.isNotBlank(param.getAdCode())) {
- param.setAdCode(param.getAdCode().replace("00", ""));
- }
- PageInfo<BisInspBaseNew> bisInspBaseNew = bisInspBaseNewService.findPageInfo(param);
- return buildSuccessResponse(bisInspBaseNew);
- }
- @ApiOperation(value = "根据ID获取通用对象表(单表)")
- @GetMapping("/getTypes")
- public BaseResponse<List<String>> getTypes() {
- return buildSuccessResponse(bisInspBaseNewService.getTypes());
- }
- @ApiOperation("获取导入模板")
- @GetMapping(value = "/getExl")
- public void getExl(HttpServletResponse response) {
- String path = templatePath + File.separator + "bisInspBaseNews.xlsx";
- try {
- ExpAndImpUtil.downloadFile(response, path, "基础对象表");
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- }
- }
- @ApiOperation("上传 xls 导入数据")
- @RequestMapping(value = "/impExl", method = RequestMethod.POST)
- public BaseResponse<Map<String, Object>> impExl(@RequestParam("file") MultipartFile multfile) throws IOException, InvalidFormatException {
- // 获取文件名
- String fileName = multfile.getOriginalFilename();
- // 获取文件后缀
- String prefix = fileName.substring(fileName.lastIndexOf("."));
- // 用uuid作为文件名,防止生成的临时文件重复
- String uuid = UuidUtil.uuid();
- File file = File.createTempFile(uuid, prefix);
- // MultipartFile to File
- multfile.transferTo(Paths.get(file.getPath()));
- Map<String, Object> map = new HashMap<>(2);
- int shu = 0;
- int success = 0;
- String[][] data = ReadExcelUtil.getData(file, 1);
- try {
- if (data != null && data.length > 0) {
- for (int i = 0; i < data.length; i++) {
- BisInspBaseNew bisInspBaseNew = new BisInspBaseNew();
- bisInspBaseNew.setObjType(data[i][0]);
- bisInspBaseNew.setCode(data[i][1]);
- bisInspBaseNew.setNm(data[i][2]);
- bisInspBaseNew.setEngrType(data[i][3]);
- bisInspBaseNew.setAdCode(data[i][4]);
- bisInspBaseNew.setAdName(data[i][5]);
- bisInspBaseNew.setLoc(data[i][6]);
- if (data[i].length > 7) {
- if (StringUtils.isNotBlank(data[i][7])) {
- bisInspBaseNew.setGdX(Double.valueOf(data[i][7]));
- bisInspBaseNew.setCenterX(Double.valueOf(data[i][7]));
- }
- }
- if (data[i].length > 8) {
- if (StringUtils.isNotBlank(data[i][8])) {
- bisInspBaseNew.setGdY(Double.valueOf(data[i][8]));
- bisInspBaseNew.setCenterY(Double.valueOf(data[i][8]));
- }
- }
- insert(bisInspBaseNew);
- success++;
- }
- }
- } catch (Exception e) {
- shu++;
- logger.error(e.getMessage(), e);
- }
- map.put("false", shu);
- map.put("success", success);
- return buildSuccessResponse(map);
- }
- }
|