package cn.com.goldenwater.dcproj.controller.other; import cn.com.goldenwater.core.web.BaseController; import cn.com.goldenwater.core.web.BaseResponse; import cn.com.goldenwater.dcproj.dto.BisInspOtherPblmDto; import cn.com.goldenwater.dcproj.model.BisInspAllRlationPers; import cn.com.goldenwater.dcproj.model.BisInspOtherPblm; import cn.com.goldenwater.dcproj.model.GwComFile; import cn.com.goldenwater.dcproj.param.BisInspOtherPblmParam; import cn.com.goldenwater.dcproj.param.FileParam; import cn.com.goldenwater.dcproj.service.BisInspAllRlationPersService; import cn.com.goldenwater.dcproj.service.BisInspOtherPblmService; import cn.com.goldenwater.dcproj.service.GwComFileService; import cn.com.goldenwater.dcproj.service.OlBisInspOrgService; 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.commons.lang3.StringUtils; 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.data.redis.core.RedisTemplate; 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.util.LinkedHashMap; import java.util.List; import java.util.Map; import static cn.com.goldenwater.dcproj.utils.impexcel.ExpAndImpUtil.getDateFormatPath; /** * @author lune * @date 2019-7-19 */ @Api(value = "BIS 其他检查问题信息表管理", tags = "BIS 其他检查问题信息表管理") @RestController @RequestMapping("/bis/insp/other/pblm") public class BisInspOtherPblmController extends BaseController { private Logger logger = LoggerFactory.getLogger(getClass()); @Value("${export.templatePath}") private String templatePath; @Value("${impExcel.basePath}") private String impExcelPath; @Autowired private OlBisInspOrgService olBisInspOrgService; @Autowired private BisInspOtherPblmService bisInspOtherPblmService; @Autowired private RedisTemplate redisTemplate; @Autowired private GwComFileService gwComFileService; @Autowired private BisInspAllRlationPersService persService; @ApiOperation(value = "添加/修改其他检查问题信息表") @RequestMapping(value = "", method = RequestMethod.POST) public BaseResponse insert(@ApiParam(name = "bisInspOtherPblm", value = "BisInspOtherPblm", required = true) @RequestBody BisInspOtherPblm bisInspOtherPblm) { if (StringUtils.isBlank(bisInspOtherPblm.getId())) { String uuid = UuidUtil.uuid(); // 生成uuid bisInspOtherPblm.setId(uuid); bisInspOtherPblmService.insert(bisInspOtherPblm); } else { bisInspOtherPblmService.updatePblm(bisInspOtherPblm); } return buildSuccessResponse(bisInspOtherPblm); } @ApiOperation(value = "根据ID删除其他检查问题信息表") @RequestMapping(value = "/del/{id}", method = RequestMethod.GET) public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { int ret = bisInspOtherPblmService.delete(id); return buildSuccessResponse(); } @ApiOperation(value = "根据ID获取其他检查问题信息表(单表)") @RequestMapping(value = "/{id}", method = RequestMethod.GET) public BaseResponse get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { BisInspOtherPblm bisInspOtherPblm = bisInspOtherPblmService.get(id); if (StringUtils.isNotBlank(bisInspOtherPblm.getPersId())) { BisInspAllRlationPers pers = persService.get(bisInspOtherPblm.getPersId()); if (pers != null) { bisInspOtherPblm.setPersName(pers.getPersName()); } } List gwComFiles = gwComFileService.findFileByBiz(bisInspOtherPblm.getId()); bisInspOtherPblm.setGwComFiles(gwComFiles); return buildSuccessResponse(bisInspOtherPblm); } @ApiOperation(value = "获取其他检查问题信息表(列表所有)") @RequestMapping(value = "/list", method = RequestMethod.POST) public BaseResponse> list(@ApiParam(name = "bisInspOtherPblmParam", value = "bisInspOtherPblmParam", required = true) @RequestBody BisInspOtherPblmParam bisInspOtherPblmParam) { List bisInspOtherPblmList = bisInspOtherPblmService.findList(bisInspOtherPblmParam); return buildSuccessResponse(bisInspOtherPblmList); } @ApiOperation(value = "获取其他检查问题信息表(列表--分页)") @RequestMapping(value = "/page", method = RequestMethod.POST) public BaseResponse> page(@ApiParam(name = "bisInspOtherPblmParam", value = "bisInspOtherPblmParam", required = true) @RequestBody BisInspOtherPblmParam bisInspOtherPblmParam) { bisInspOtherPblmParam.setProvince(olBisInspOrgService.getProvince(getCurrentOrgId())); PageInfo bisInspOtherPblmList = bisInspOtherPblmService.findPageInfo(bisInspOtherPblmParam); return buildSuccessResponse(bisInspOtherPblmList); } @ApiOperation(value = "下载飞检模板") @RequestMapping(value = "/downTemplate", method = {RequestMethod.GET, RequestMethod.POST}) public BaseResponse downTemplate(HttpServletResponse response, FileParam param) { try { param.setOrgId(getCurrentOrgId()); param.setProvince(olBisInspOrgService.getProvince(getCurrentOrgId())); List> pblmList = bisInspOtherPblmService.findPblmList(param); ExpAndImpUtil.download(response, pblmList, templatePath + File.separator + param.getFileName(), param.getStartRow(), param.getSheetName()); } catch (Exception e) { return buildFailResponse(e); } return buildSuccessResponse(); } @ApiOperation(value = "上传飞检模板") @RequestMapping(value = "/uploadTemplate", method = RequestMethod.POST) public BaseResponse uploadTemplate(MultipartFile file, FileParam param) { String filaPath = ""; try { filaPath = ExpAndImpUtil.upload(file, getDateFormatPath(impExcelPath)); } catch (Exception e) { return buildFailResponse(e); } return buildSuccessResponse(filaPath); } @ApiOperation(value = "解析文件上传数据") @RequestMapping(value = "/parseUpload", method = RequestMethod.POST) public BaseResponse> parseUpload(FileParam param) { Map map = new LinkedHashMap<>(); try { List> list = ExpAndImpUtil.parseData(param.getPath(), param.getStartRow(), BisInspOtherPblmDto.class); if (list.size() > 0) { String uuid = UuidUtil.uuid(); redisTemplate.opsForList().rightPushAll(uuid, list); map.put("dataId", uuid); } map.put("list", list); } catch (IOException e) { buildFailResponse(e.getMessage()); } return buildSuccessResponse(map); } @ApiOperation(value = "文件数据入库") @RequestMapping(value = "/insertIntoData", method = RequestMethod.POST) public BaseResponse insertIntoData(FileParam param) { if (StringUtils.isBlank(param.getDataId())) { return buildFailResponse(); } List> list = redisTemplate.opsForList().range(param.getDataId(), 0, -1); redisTemplate.delete(param.getDataId()); if (bisInspOtherPblmService.insertIntoData(list) == 0) { return buildFailResponse("问题导入失败"); } return buildSuccessResponse(); } }