package com.artfess.cqlt.controller; import com.artfess.base.annotation.ApiGroup; import com.artfess.base.constants.ApiGroupConsts; import com.artfess.base.exception.RequiredException; import com.artfess.base.model.CommonResult; import com.artfess.base.query.PageList; import com.artfess.base.query.QueryFilter; import com.artfess.base.util.DateUtils; import com.artfess.base.valid.AddGroup; import com.artfess.base.valid.UpdateGroup; import com.artfess.cqlt.manager.QfEnterpriseInfoManager; import com.artfess.cqlt.manager.QfFinanceLeaseDManager; import com.artfess.cqlt.model.QfEnterpriseInfo; import com.artfess.cqlt.model.QfFinanceLeaseD; import com.artfess.cqlt.model.QfFinanceLeaseM; import com.artfess.cqlt.model.QfOperationSalesD; import com.artfess.i18n.util.I18nUtil; import com.artfess.poi.util.ExcelUtil; import com.artfess.poi.util.ExcelUtils; import com.artfess.poi.util.FileDownloadUtil; import com.artfess.poi.util.HeaderNode; import com.artfess.uc.api.impl.util.ContextUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.core.io.ClassPathResource; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import com.artfess.base.controller.BaseController; import com.artfess.cqlt.model.QfFinanceLeaseM; import com.artfess.cqlt.manager.QfFinanceLeaseMManager; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.time.LocalDate; import java.util.Arrays; import java.util.List; import java.util.Map; /** * 资金-融资租赁填报主表 前端控制器 * * @company 阿特菲斯信息技术有限公司 * @author min.wu * @since 2023-03-02 */ @Slf4j @RestController @Api(tags = "资金--融资租赁填报主表") @RequestMapping("/qf/finance/lease/") @ApiGroup(group = {ApiGroupConsts.GROUP_BIZ}) public class QfFinanceLeaseMController extends BaseController { @Autowired private QfFinanceLeaseDManager financePlDManager; @Autowired private QfEnterpriseInfoManager enterpriseInfoManager; @Override @PostMapping("/") @ApiOperation("添加实体的接口") public CommonResult create(@ApiParam(name = "model", value = "实体信息") @RequestBody @Validated({AddGroup.class}) QfFinanceLeaseM t) { t.setFillUser(ContextUtil.getCurrentUserId()); t.setFillDate(LocalDate.now()); t.setFillQuarter(DateUtils.getQuarter(t.getFillMonth())); boolean result = baseService.insertInfo(t); if (!result) { return new CommonResult(false, I18nUtil.getMessage("option.fail", LocaleContextHolder.getLocale()), null); } return new CommonResult(true, I18nUtil.getMessage("option.success", LocaleContextHolder.getLocale()), t.getId()); } @Override @PutMapping("/") @ApiOperation("更新实体") public CommonResult updateById(@ApiParam(name = "model", value = "实体信息") @RequestBody @Validated({UpdateGroup.class}) QfFinanceLeaseM t) { boolean result = baseService.updateInfo(t); if (!result) { return new CommonResult(false, I18nUtil.getMessage("option.fail", LocaleContextHolder.getLocale()), null); } return new CommonResult(true, I18nUtil.getMessage("option.success", LocaleContextHolder.getLocale()), null); } @PutMapping("/updateStatus") @ApiOperation("生效") public CommonResult updateStatus(@ApiParam(name = "model", value = "实体信息") @RequestBody QfFinanceLeaseM t) { boolean result = baseService.updateStatus(t); if (!result) { return new CommonResult(false, I18nUtil.getMessage("option.fail", LocaleContextHolder.getLocale()), null); } return new CommonResult(true, I18nUtil.getMessage("option.success", LocaleContextHolder.getLocale()), null); } @Override @DeleteMapping("/{id}") @ApiOperation("根据id删除") public CommonResult deleteById(@ApiParam(name = "id", value = "实体id") @PathVariable String id) { boolean result = baseService.removeById(id); if (!result) { return new CommonResult(false, I18nUtil.getMessage("delete.fail", LocaleContextHolder.getLocale()), null); } return new CommonResult(true, I18nUtil.getMessage("option.success", LocaleContextHolder.getLocale()), null); } @Override @DeleteMapping("/") @ApiOperation("根据id集合批量删除") public CommonResult deleteByIds(@ApiParam(name = "ids", value = "实体集合") @RequestParam String... ids) { boolean result = baseService.removeByIds(Arrays.asList(ids)); if (!result) { return new CommonResult(false, I18nUtil.getMessage("delete.fail", LocaleContextHolder.getLocale()), null); } return new CommonResult(true, I18nUtil.getMessage("option.success", LocaleContextHolder.getLocale()), null); } /** * @param file * @param mainId * @return */ @ApiOperation(value = "融资租赁数据导入") @PostMapping("/importExcel") public CommonResult importExcel(@RequestParam("file") MultipartFile file, @RequestParam(value = "mainId", required = false) String mainId) { try { ExcelUtils excelUtil = new ExcelUtils<>(QfFinanceLeaseD.class); List list = excelUtil.importExcel(null, file.getInputStream()); boolean result = baseService.importExcel(list, mainId); if (!result) { throw new IllegalArgumentException(I18nUtil.getMessage("import.fail", LocaleContextHolder.getLocale())); } return new CommonResult<>(); } catch (Exception e) { throw new IllegalArgumentException(I18nUtil.getMessage("import.fail", LocaleContextHolder.getLocale()) + "," + e.getMessage()); } } /** * 下载导入模板 * * @param response * @return */ @ApiOperation(value = "下载导入模板") @GetMapping("/downModel") public void downTemplate(HttpServletResponse response) { try { ClassPathResource classPathResource = new ClassPathResource("model/financeLeaseDetail.xlsx"); FileDownloadUtil.fileDownload(response, classPathResource.getInputStream(), "融资租赁模板.xlsx"); } catch (Exception e) { response.setCharacterEncoding("utf-8"); throw new RequiredException(I18nUtil.getMessage("resources.noexist", LocaleContextHolder.getLocale())); } } @ApiOperation(value = "融资租赁数据导出") @PostMapping("/export") public void export(HttpServletRequest request, HttpServletResponse response, @ApiParam(name = "queryFilter", value = "分页查询信息") @RequestBody QueryFilter queryFilter) throws Exception { PageList page = financePlDManager.query(queryFilter); //获取境外企业 Map enterpriseInfoMap = enterpriseInfoManager.getEnterpriseInfoMap(null); page.getRows().forEach(qfFinanceLeaseD -> { //处理企业 if (enterpriseInfoMap.containsKey(qfFinanceLeaseD.getEnterpriseCode())) { QfEnterpriseInfo qfEnterpriseInfo = enterpriseInfoMap.get(qfFinanceLeaseD.getEnterpriseCode()); qfFinanceLeaseD.setEnterpriseName(qfEnterpriseInfo.getName()); qfFinanceLeaseD.setEnterpriseNameEn(qfEnterpriseInfo.getNameEn()); } }); ExcelUtils util = new ExcelUtils(QfFinanceLeaseD.class); util.exportExcel(response, request, page.getRows(), "融资租赁"); } }