package com.glxp.api.controller.purchase; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.github.pagehelper.PageInfo; import com.glxp.api.annotation.AuthRuleAnnotation; import com.glxp.api.common.enums.ResultEnum; import com.glxp.api.common.res.BaseResponse; import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.constant.ConstantStatus; import com.glxp.api.entity.auth.AuthAdmin; import com.glxp.api.entity.purchase.*; import com.glxp.api.entity.system.SystemPDFModuleEntity; import com.glxp.api.entity.system.SystemPDFTemplateEntity; import com.glxp.api.exception.JsonException; import com.glxp.api.req.inout.InspectionPDFTemplateRequest; import com.glxp.api.req.inout.SystemPDFModuleRequest; import com.glxp.api.req.purchase.*; import com.glxp.api.req.system.DeleteCompanyFileRequest; import com.glxp.api.req.system.FilterPdfModuleRequest; import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.res.purchase.SupProductResponse; import com.glxp.api.service.auth.AuthAdminService; import com.glxp.api.service.purchase.SupCertService; import com.glxp.api.service.purchase.SupCompanyService; import com.glxp.api.service.purchase.SupManufacturerService; import com.glxp.api.service.purchase.SupProductService; import com.glxp.api.service.system.SystemPDFModuleService; import com.glxp.api.service.system.SystemPDFTemplateService; import com.glxp.api.util.JasperUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; @RestController public class SupCertController { @Resource private AuthAdminService authAdminService; @Resource private SupCertService supCertService; @Value("${file_path}") private String filePath; @Resource private SystemPDFTemplateService systemPDFTemplateService; @Resource private SystemPDFModuleService systemPDFModuleService; @AuthRuleAnnotation("") @GetMapping("/sup/company/cert/filter") public BaseResponse filterCompanyCert(FilterSupCertRequest filterSupCertRequest, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); } List supCertEntityList = supCertService.filterCompanyCert(filterSupCertRequest); PageInfo pageInfo; pageInfo = new PageInfo<>(supCertEntityList); PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); pageSimpleResponse.setTotal(pageInfo.getTotal()); pageSimpleResponse.setList(supCertEntityList); return ResultVOUtils.success(pageSimpleResponse); } @AuthRuleAnnotation("") @PostMapping("/sup/info/selectAllCert") public BaseResponse selectAllCert(@RequestBody PostSelCertRequest postSelCertRequest) { String customerId = null; if (StrUtil.isEmpty(postSelCertRequest.getCustomerId())) customerId = getCustomerId(); else { customerId = postSelCertRequest.getCustomerId(); } if (CollUtil.isEmpty(postSelCertRequest.getSupCertSetEntities())) { return ResultVOUtils.error(500, "请选入资质证书!"); } if (postSelCertRequest.getCertType() == null) { return ResultVOUtils.error(500, "参数错误!"); } for (SupCertSetEntity supCertSetEntity : postSelCertRequest.getSupCertSetEntities()) { SupCertEntity supCertEntity = new SupCertEntity(); supCertEntity.setName(supCertSetEntity.getName()); supCertEntity.setManufacturerIdFk(postSelCertRequest.getManufacturerIdFk()); supCertEntity.setProductIdFk(postSelCertRequest.getProductIdFk()); supCertEntity.setCustomerId(customerId); supCertEntity.setType(postSelCertRequest.getCertType()); supCertEntity.setCreateTime(new Date()); supCertEntity.setStatus(0); supCertEntity.setAuditStatus(ConstantStatus.AUDIT_DRAFT); supCertEntity.setUpdateTime(new Date()); boolean b = supCertService.insertCompanyCert(supCertEntity); } return ResultVOUtils.success("成功"); } @AuthRuleAnnotation("") @GetMapping("/sale/info/getCompanyCert") public BaseResponse getCompanyCert(FilterSupCertRequest filterSupCertRequest) { filterSupCertRequest.setCustomerId(getCustomerId()); List companyCertEntities = supCertService.getCompanyCert(filterSupCertRequest); PageInfo pageInfo = new PageInfo<>(companyCertEntities); PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); pageSimpleResponse.setTotal(pageInfo.getTotal()); pageSimpleResponse.setList(companyCertEntities); return ResultVOUtils.success(pageSimpleResponse); } @AuthRuleAnnotation("") @PostMapping("/sup/info/insertCompanyCert") public BaseResponse insertCompanyCert(@RequestBody SupCertEntity supCertEntity) { supCertEntity.setCreateTime(new Date()); supCertEntity.setUpdateTime(new Date()); boolean b = supCertService.insertCompanyCert(supCertEntity); return ResultVOUtils.success("成功"); } @AuthRuleAnnotation("") @PostMapping("/sale/sup/cert/audit") public BaseResponse auditSupCert(@RequestBody SupCertEntity supCertEntity) { supCertEntity.setCreateTime(new Date()); supCertEntity.setUpdateTime(new Date()); boolean b = supCertService.updateCompanyCert(supCertEntity); return ResultVOUtils.success("成功"); } @Resource SupCompanyService supCompanyService; @Resource SupManufacturerService supManufacturerService; @Resource SupProductService supProductService; @AuthRuleAnnotation("") @PostMapping("/sup/info/updateCompanyCert") public BaseResponse updateCompanyCert(@RequestBody PostSupCertRequest postSupCertRequest) { SupCertEntity supCertEntity = new SupCertEntity(); BeanUtils.copyProperties(postSupCertRequest, supCertEntity); if (postSupCertRequest.getRepeatUpload() == 1) { //已审核的重新提交 //1.修改对应的资质信息进入变更审核状态, if (postSupCertRequest.getType() == ConstantStatus.CERT_COMPANY) { SupCompanyEntity supCompanyEntity = supCompanyService.findCompany(supCertEntity.getCustomerId()); supCompanyEntity.setAuditStatus(ConstantStatus.AUDIT_CHANGE); supCompanyEntity.setUpdateTime(new Date()); supCompanyService.modifyCompany(supCompanyEntity); } else if (postSupCertRequest.getType() == ConstantStatus.CERT_MANUFACTURER) { SupManufacturerEntity supManufacturerEntity = supManufacturerService.findManufacturer(supCertEntity.getManufacturerIdFk()); supManufacturerEntity.setAuditStatus(ConstantStatus.AUDIT_CHANGE); supManufacturerEntity.setUpdateTime(new Date()); supManufacturerService.modifyCompany(supManufacturerEntity); } else if (postSupCertRequest.getType() == ConstantStatus.CERT_PRODUCT) { SupProductResponse supProductResponse = supProductService.findByProductId(supCertEntity.getProductIdFk()); SupProductEntity supProductEntity = new SupProductEntity(); supProductEntity.setId(supProductResponse.getId()); supProductEntity.setUpdateTime(new Date()); supProductEntity.setAuditStatus(ConstantStatus.AUDIT_CHANGE); supProductService.modifyRegistration(supProductEntity); } } boolean b = supCertService.updateCompanyCert(supCertEntity); return ResultVOUtils.success("修改成功"); } @AuthRuleAnnotation("") @PostMapping("/sup/info/deleteCompanyCert") public BaseResponse deleteCompanyCert(@RequestBody DeleteCompanyFileRequest deleteCompanyFileRequest, BindingResult bindingResult) { boolean b = supCertService.deleteById(deleteCompanyFileRequest.getId()); String URL = filePath + "/register/file/image2/" + deleteCompanyFileRequest.getFilePath(); File file = new File(URL); if (file.exists() && file.isFile()) { file.delete(); } return ResultVOUtils.success("成功"); } public String getCustomerId() { ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); if (attributes == null) { throw new JsonException(ResultEnum.NOT_NETWORK); } HttpServletRequest request = attributes.getRequest(); String userId = request.getHeader("ADMIN_ID"); AuthAdmin authAdmin = authAdminService.findById(Long.parseLong(userId)); return authAdmin.getCustomerId() + ""; } /** * 校验模板文件 * * @param inspectionPDFTemplateRequest * @return */ @AuthRuleAnnotation("") @PostMapping("/sup/info/verifyTemplateFile") public BaseResponse verifyTemplateFile(@RequestBody InspectionPDFTemplateRequest inspectionPDFTemplateRequest) { if (null == inspectionPDFTemplateRequest) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "参数不能为空!"); } //查询模板文件是否存在 FilterPdfModuleRequest filterPdfModuleRequest = new FilterPdfModuleRequest(); filterPdfModuleRequest.setId(inspectionPDFTemplateRequest.getModuleId()); SystemPDFModuleEntity systemPDFModule = systemPDFModuleService.findSystemPDFModule(filterPdfModuleRequest); if (null == systemPDFModule) { return ResultVOUtils.error(ResultEnum.DATA_NOT, "所属模块错误"); } SystemPDFTemplateEntity systemPDFTemplateEntity = systemPDFTemplateService.selectById(String.valueOf(systemPDFModule.getTemplateId())); if (null == systemPDFTemplateEntity) { return ResultVOUtils.error(ResultEnum.DATA_NOT, "模板错误"); } return ResultVOUtils.success(systemPDFModule.getTemplateId()); } /** * 打印模板单号标签 * * @param purPlanPrintRequest * @param request * @param response * @throws Exception */ @AuthRuleAnnotation("") @PostMapping("/sup/info/printOrder") public void printOrder(@RequestBody purPlanPrintRequest purPlanPrintRequest, HttpServletRequest request, HttpServletResponse response) throws Exception { SystemPDFTemplateEntity systemPDFTemplateEntity = systemPDFTemplateService.selectById(purPlanPrintRequest.getTemplateId()); //打印单号标签 Map data = new HashMap<>(1); List list = new ArrayList<>(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");//定义新的日期格式 //查询配送企业信息 SupCompanyEntity supCompanyEntity = supCompanyService.findCompany(purPlanPrintRequest.getCustomerId()); //查询详情 List selectSupCertList = supCertService.selectSupCertList(purPlanPrintRequest); int i = 1; if (selectSupCertList != null && selectSupCertList.size() > 0) { for (SupCertEntity obj : selectSupCertList) { //组装数据 Map supData = new HashMap<>(); supData.put("companyName", supCompanyEntity.getCompanyName() == null ? ' ' : supCompanyEntity.getCompanyName()); supData.put("creditNum", supCompanyEntity.getCreditNum() == null ? ' ' : supCompanyEntity.getCreditNum()); supData.put("classes", supCompanyEntity.getClasses().equals(1) ? "医院" : "经营企业"); supData.put("area", supCompanyEntity.getArea() == null ? ' ' : supCompanyEntity.getArea()); supData.put("contacts", supCompanyEntity.getContacts() == null ? ' ' : supCompanyEntity.getContacts()); supData.put("detailAddr", supCompanyEntity.getDetailAddr() == null ? ' ' : supCompanyEntity.getDetailAddr()); supData.put("mobile", supCompanyEntity.getMobile() == null ? ' ' : supCompanyEntity.getMobile()); supData.put("email", supCompanyEntity.getEmail() == null ? ' ' : supCompanyEntity.getEmail()); supData.put("index", String.valueOf(i)); supData.put("name", obj.getName() == null ? ' ' : obj.getName()); supData.put("code", obj.getCode() == null ? ' ' : obj.getCode()); supData.put("vaiDate", formatter.format(obj.getVailDate())); supData.put("expireDate", formatter.format(obj.getExpireDate())); supData.put("status", obj.getStatus() == 0 ? "有效" : "失效"); supData.put("auditStatus", getAuditStatus(obj.getAuditStatus())); supData.put("remark", obj.getRemark() == null ? ' ' : obj.getRemark()); supData.put("filePath", "D:/udi/udiwms/udiwmsfile/register/image2/" + obj.getFilePath()); list.add(supData); i++; } } String param = JSON.toJSONString(list); JasperUtils.jasperReport(request, response, param, systemPDFTemplateEntity.getPath(), "pdf"); } /** * 获取详情ids * * @param filterSupCertRequest * @return */ @AuthRuleAnnotation("") @PostMapping("/sup/info/filterCompanyCertIdList") public BaseResponse filterCompanyCertIdList(@RequestBody FilterSupCertRequest filterSupCertRequest) { if (StrUtil.isNotEmpty(filterSupCertRequest.getCustomerId()) && filterSupCertRequest.getType() != null) { List supCertEntityList = supCertService.filterCompanyCert(filterSupCertRequest); List idsList = supCertEntityList.stream().map(SupCertEntity::getId).distinct().collect(Collectors.toList()); return ResultVOUtils.success(idsList); } return ResultVOUtils.error(999, "参数错误"); } public String getAuditStatus(int type) { if (type == 0) { return "草稿"; } else if (type == 1) { return "审核通过"; } else if (type == 2) { return "审核不通过"; } else if (type == 3) { return "申请变更"; } else if (type == 4) { return "申请变更通过"; } else if (type == 5) { return "申请变更不通过"; } else if (type == 6) { return "已提交未审核"; } return ""; } public String getRegisterStatus(String type) { if (type.equals("1")) { return "续存(在营,开业,在册)"; } else if (type.equals("2")) { return "吊销"; } else if (type.equals("3")) { return "注销"; } else if (type.equals("4")) { return "迁出"; } return ""; } /** * 打印生产企业模板单号标签 * * @param purPlanPrintRequest * @param request * @param response * @throws Exception */ @AuthRuleAnnotation("") @PostMapping("/sup/info/printSupCertManufacturer") public void printSupCertManufacturer(@RequestBody purPlanPrintRequest purPlanPrintRequest, HttpServletRequest request, HttpServletResponse response) throws Exception { SystemPDFTemplateEntity systemPDFTemplateEntity = systemPDFTemplateService.selectById(purPlanPrintRequest.getTemplateId()); //打印单号标签 Map data = new HashMap<>(1); List list = new ArrayList<>(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");//定义新的日期格式 FilterSupManufacturerRequest filterSupManufacturerRequest = new FilterSupManufacturerRequest(); filterSupManufacturerRequest.setId(purPlanPrintRequest.getId()); //查询生产企业信息 List supManufacturerEntityList = supManufacturerService.getCompanyByNameAndCode(filterSupManufacturerRequest); SupManufacturerEntity supManufacturerEntity = supManufacturerEntityList.get(0); //查询详情 List selectSupCertList = supCertService.selectSupCertList(purPlanPrintRequest); int i = 1; if (selectSupCertList != null && selectSupCertList.size() > 0) { for (SupCertEntity obj : selectSupCertList) { //组装数据 Map supData = new HashMap<>(); supData.put("customerName", supManufacturerEntity.getSupName() == null ? ' ' : supManufacturerEntity.getSupName()); supData.put("companyName", supManufacturerEntity.getCompanyName() == null ? ' ' : supManufacturerEntity.getCompanyName()); supData.put("companyType", supManufacturerEntity.getCompanyType().equals(1) ? "境内企业" : "境外企业"); supData.put("creditCode", supManufacturerEntity.getCreditCode() == null ? ' ' : supManufacturerEntity.getCreditCode()); supData.put("placeArea", supManufacturerEntity.getPlaceArea() == null ? ' ' : supManufacturerEntity.getPlaceArea()); supData.put("productionArea", supManufacturerEntity.getProductionArea() == null ? ' ' : supManufacturerEntity.getProductionArea()); supData.put("registerStatus", getRegisterStatus(supManufacturerEntity.getRegisterStatus())); supData.put("placeAddress", supManufacturerEntity.getPlaceAddress() == null ? ' ' : supManufacturerEntity.getPlaceAddress()); supData.put("productionAddress", supManufacturerEntity.getProductionAddress() == null ? ' ' : supManufacturerEntity.getProductionAddress()); supData.put("remark1", supManufacturerEntity.getRemark() == null ? ' ' : supManufacturerEntity.getRemark()); supData.put("index", String.valueOf(i)); supData.put("name", obj.getName() == null ? ' ' : obj.getName()); supData.put("code", obj.getCode() == null ? ' ' : obj.getCode()); supData.put("vaiDate", formatter.format(obj.getVailDate())); supData.put("expireDate", formatter.format(obj.getExpireDate())); supData.put("status", obj.getStatus() == 0 ? "有效" : "失效"); supData.put("auditStatus", getAuditStatus(obj.getAuditStatus())); supData.put("remark2", obj.getRemark() == null ? ' ' : obj.getRemark()); supData.put("filePath", "d:/1s/udiwms/register/file/image2/" + obj.getFilePath()); list.add(supData); i++; } } String param = JSON.toJSONString(list); JasperUtils.jasperReport(request, response, param, systemPDFTemplateEntity.getPath(), "pdf"); } /** * 打印生产企业模板单号标签 * * @param purPlanPrintRequest * @param request * @param response * @throws Exception */ @AuthRuleAnnotation("") @PostMapping("/sup/info/printSupCertProduction") public void printSupCertProduction(@RequestBody purPlanPrintRequest purPlanPrintRequest, HttpServletRequest request, HttpServletResponse response) throws Exception { SystemPDFTemplateEntity systemPDFTemplateEntity = systemPDFTemplateService.selectById(purPlanPrintRequest.getTemplateId()); //打印单号标签 Map data = new HashMap<>(1); List list = new ArrayList<>(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");//定义新的日期格式 //查询配送产品信息 SupProductEntity supProductEntity = supProductService.findRegistration(purPlanPrintRequest.getId()); //查询生产企业信息 FilterSupManufacturerRequest filterSupManufacturerRequest = new FilterSupManufacturerRequest(); filterSupManufacturerRequest.setManufacturerId(supProductEntity.getManufacturerIdFk()); List supManufacturerEntityList = supManufacturerService.getCompanyByNameAndCode(filterSupManufacturerRequest); SupManufacturerEntity supManufacturerEntity = supManufacturerEntityList.get(0); //查询详情 List selectSupCertList = supCertService.selectSupCertList(purPlanPrintRequest); int i = 1; if (selectSupCertList != null && selectSupCertList.size() > 0) { for (SupCertEntity obj : selectSupCertList) { //组装数据 Map supData = new HashMap<>(); supData.put("customerName", supManufacturerEntity.getSupName() == null ? ' ' : supManufacturerEntity.getSupName()); supData.put("manufacturerldFk", supManufacturerEntity.getCompanyName() == null ? ' ' : supManufacturerEntity.getCompanyName()); supData.put("recordProductName", supProductEntity.getRecordProductName() == null ? ' ' : supProductEntity.getRecordProductName()); supData.put("recordCode", supProductEntity.getRecordCode() == null ? ' ' : supProductEntity.getRecordCode()); supData.put("recordPeopleName", supProductEntity.getRecordPeopleName() == null ? ' ' : supProductEntity.getRecordPeopleName()); supData.put("hchzsb", supProductEntity.getHchzsb() == null ? ' ' : supProductEntity.getHchzsb()); supData.put("productType", supProductEntity.getProductType() == null ? ' ' : supProductEntity.getProductType()); supData.put("productDirectoryCode", supProductEntity.getProductDirectoryCode() == null ? ' ' : supProductEntity.getProductDirectoryCode()); supData.put("specification", supProductEntity.getSpecification() == null ? ' ' : supProductEntity.getSpecification()); supData.put("cpms", supProductEntity.getCpms() == null ? ' ' : supProductEntity.getCpms()); supData.put("remark1", supProductEntity.getRemark() == null ? ' ' : supProductEntity.getRemark()); supData.put("index", String.valueOf(i)); supData.put("name", obj.getName() == null ? ' ' : obj.getName()); supData.put("code", obj.getCode() == null ? ' ' : obj.getCode()); supData.put("vaiDate", formatter.format(obj.getVailDate())); supData.put("expireDate", formatter.format(obj.getExpireDate())); supData.put("status", obj.getStatus() == 0 ? "有效" : "失效"); supData.put("auditStatus", getAuditStatus(obj.getAuditStatus())); supData.put("remark2", obj.getRemark() == null ? ' ' : obj.getRemark()); supData.put("filePath", "d:/1s/udiwms/register/file/image2/" + obj.getFilePath()); list.add(supData); i++; } } String param = JSON.toJSONString(list); JasperUtils.jasperReport(request, response, param, systemPDFTemplateEntity.getPath(), "pdf"); } //撤回单据 @AuthRuleAnnotation("") @PostMapping("/sale/sup/cert/revoke") public BaseResponse revokeSupCert(@RequestBody SupCertEntity supCertEntity) { supCertEntity.setCreateTime(new Date()); supCertEntity.setUpdateTime(new Date()); boolean b = supCertService.updateCompanyCert(supCertEntity); if (supCertEntity.getType() == ConstantStatus.CERT_COMPANY) { SupCompanyEntity supCompanyEntity = supCompanyService.findCompany(supCertEntity.getCustomerId()); supCompanyEntity.setAuditStatus(ConstantStatus.AUDIT_UN); supCompanyEntity.setUpdateTime(new Date()); supCompanyService.modifyCompany(supCompanyEntity); } else if (supCertEntity.getType() == ConstantStatus.CERT_MANUFACTURER) { SupManufacturerEntity supManufacturerEntity = supManufacturerService.findManufacturer(supCertEntity.getManufacturerIdFk()); supManufacturerEntity.setAuditStatus(ConstantStatus.AUDIT_UN); supManufacturerEntity.setUpdateTime(new Date()); supManufacturerService.modifyCompany(supManufacturerEntity); } else if (supCertEntity.getType() == ConstantStatus.CERT_PRODUCT) { SupProductResponse supProductResponse = supProductService.findByProductId(supCertEntity.getProductIdFk()); SupProductEntity supProductEntity = new SupProductEntity(); supProductEntity.setId(supProductResponse.getId()); supProductEntity.setUpdateTime(new Date()); supProductEntity.setAuditStatus(ConstantStatus.AUDIT_UN); supProductService.modifyRegistration(supProductEntity); } return ResultVOUtils.success("成功"); } }