You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
udi-spms-java/src/main/java/com/glxp/api/controller/basic/UdiRlSupController.java

355 lines
18 KiB
Java

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.glxp.api.controller.basic;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageInfo;
import com.glxp.api.annotation.AuthRuleAnnotation;
import com.glxp.api.annotation.Log;
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.BusinessType;
import com.glxp.api.constant.SocketMsgType;
import com.glxp.api.controller.BaseController;
import com.glxp.api.controller.sync.SpsSyncWebSocket;
import com.glxp.api.entity.auth.AuthAdmin;
import com.glxp.api.entity.basic.*;
import com.glxp.api.entity.sync.SocketMsgEntity;
import com.glxp.api.entity.system.CompanyEntity;
import com.glxp.api.exception.JsonException;
import com.glxp.api.req.basic.*;
import com.glxp.api.req.system.CompanyRequest;
import com.glxp.api.req.system.DeleteCompanyFileRequest;
import com.glxp.api.res.PageSimpleResponse;
import com.glxp.api.res.basic.CompanyProductRelevanceResponse;
import com.glxp.api.res.basic.UdiRlSupResponse;
import com.glxp.api.res.basic.UdiRelevanceResponse;
import com.glxp.api.service.auth.AuthAdminService;
import com.glxp.api.service.auth.CustomerInfoService;
import com.glxp.api.service.basic.*;
import com.glxp.api.service.system.ClassifyCodeService;
import com.glxp.api.service.system.CompanyService;
import com.glxp.api.util.IntUtil;
import com.glxp.api.util.SupplementVailUtil;
import com.glxp.api.util.udi.FilterUdiUtils;
import org.springframework.beans.BeanUtils;
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.validation.Valid;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* 供应商关联耗材字典信息
*/
@RestController
public class UdiRlSupController extends BaseController {
@Resource
private AuthAdminService authAdminService;
@Resource
private UdiRlSupService udiRlSupService;
@Resource
private CompanyProductsRelService companyProductsRelService;
@Resource
private BasicCorpService basicUnitMaintainService;
@Resource
private UdiRelevanceService udiRelevanceService;
@Resource
private CompanyService companyService;
@Resource
private CompanyProductRelevanceService companyProductRelevanceService;
@Resource
private SupplementVailUtil supplementVailUtil;
@Resource
private UdiProductService udiProductService;
@Resource
SpsSyncWebSocket webSocketServer;
@Resource
private CustomerInfoService customerInfoService;
@Resource
private IBasicBussinessTypeService basicBussinessTypeService;
@Resource
private com.glxp.api.service.system.ClassifyCodeService classifyCodeService;
@AuthRuleAnnotation("")
@GetMapping("/sale/info/company/product/relevance/filter")
public BaseResponse filterCompanyProductRelevance(CompanyProductRelevanceRequest companyProductRelevanceRequest,
BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
if (StrUtil.isNotEmpty(companyProductRelevanceRequest.getCustomerId())) {
String customerId = getCustomerId();
if (customerId.equals("110")) {
companyProductRelevanceRequest.setCustomerId(null);
}
}
if (ObjectUtil.isNotNull(companyProductRelevanceRequest.getUserFlag())) {
Integer userFlag = companyProductRelevanceRequest.getUserFlag();
//获取 供应商状态为 userFlag 的 customerIds列表
List<Long> customerIds = customerInfoService.selectCustomerIdListByUserFlag(userFlag);
companyProductRelevanceRequest.setCustomerIds(customerIds);
}
companyProductRelevanceRequest.setIsDisable(false);
if (StrUtil.isNotEmpty(companyProductRelevanceRequest.getUdiCode())) {
UdiEntity udiEntity = FilterUdiUtils.getUdi(companyProductRelevanceRequest.getUdiCode());
if (udiEntity != null) {
companyProductRelevanceRequest.setNameCode(udiEntity.getUdi());
companyProductRelevanceRequest.setUnionCode(udiEntity.getUdi());
}
}
//如果输入DI标识精确找到不同层级对应的产品信息
if (StrUtil.isNotEmpty(companyProductRelevanceRequest.getUnionCode())) {
FilterUdiRelRequest filterUdiInfoRequest = new FilterUdiRelRequest();
filterUdiInfoRequest.setNameCode(companyProductRelevanceRequest.getUnionCode());
List<UdiRelevanceResponse> temps = udiRelevanceService.filterUdiGp(filterUdiInfoRequest);
if (temps != null && temps.size() > 0) {
companyProductRelevanceRequest.setOriginUuid(temps.get(0).getOriginUuid());
companyProductRelevanceRequest.setNameCode(filterUdiInfoRequest.getNameCode());
companyProductRelevanceRequest.setUnionCode(null);
}
} else {
//只查找主标识产品信息
companyProductRelevanceRequest.setDiType(1);
}
//校验是否需要扫码
if (StrUtil.isNotEmpty(companyProductRelevanceRequest.getAction())) {
BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(companyProductRelevanceRequest.getAction());
//是否校验产品采购类型 1校验2.无需校验
if (IntUtil.value(bussinessTypeEntity.getVailProductAttributes()) == 1) {
companyProductRelevanceRequest.setPurType(IntUtil.value(bussinessTypeEntity.getActionType()));
}
//是否开启校验扫码 0:不校验1:只允许录入扫码产品2:只允许录入不扫码产品
if (IntUtil.value(bussinessTypeEntity.getCodeCheck()) == 1) {
companyProductRelevanceRequest.setCodeCheck(1);
} else if (IntUtil.value(bussinessTypeEntity.getCodeCheck()) == 2) {
companyProductRelevanceRequest.setCodeCheck(0);
} else {
companyProductRelevanceRequest.setCodeCheck(null);
}
}
List<UdiRlSupResponse> basicInstrumentMaintainRelevanceResponses = null;
basicInstrumentMaintainRelevanceResponses = udiRlSupService.filterUdiGp(companyProductRelevanceRequest);
PageInfo<UdiRlSupResponse> pageInfo;
pageInfo = new PageInfo<>(basicInstrumentMaintainRelevanceResponses);
PageSimpleResponse<UdiRlSupResponse> pageSimpleResponse = new PageSimpleResponse<>();
pageSimpleResponse.setTotal(pageInfo.getTotal());
pageSimpleResponse.setList(basicInstrumentMaintainRelevanceResponses);
return ResultVOUtils.success(pageSimpleResponse);
}
@AuthRuleAnnotation("")
@GetMapping("/sale/info/company/product/corp/filter")
public BaseResponse filterRlCorp(FilterCompanyProductRelevanceRequest filterCompanyProductRelevanceRequest,
BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
if (StrUtil.isEmpty(filterCompanyProductRelevanceRequest.getUdiRlIdFk())) {
return ResultVOUtils.error(500, "请先选择产品!");
}
List<UdiRlSupEntity> companyProductRelevanceEntities =
udiRlSupService.filterCompanyProductRelevance(filterCompanyProductRelevanceRequest);
if (!companyProductRelevanceEntities.isEmpty()) {
List<String> erpIds = new ArrayList<>();
for (UdiRlSupEntity udiRlSupEntity : companyProductRelevanceEntities) {
//过滤,如果默认已经有供应商了,则查出对应供应商即可
if (StrUtil.isNotEmpty(filterCompanyProductRelevanceRequest.getUnitFk())) {
if (udiRlSupEntity.getUnitFk().equals(filterCompanyProductRelevanceRequest.getUnitFk())) {
erpIds.add(udiRlSupEntity.getUnitFk());
}
} else {
erpIds.add(udiRlSupEntity.getUnitFk());
}
}
if (CollUtil.isEmpty(erpIds)) {
return ResultVOUtils.error(500, "该产品未关联供应商");
}
List<BasicCorpEntity> basicUnitMaintainEntities = basicUnitMaintainService.batchSelectByErpIdsAndName(erpIds, filterCompanyProductRelevanceRequest.getKey());
return ResultVOUtils.success(basicUnitMaintainEntities);
}
return ResultVOUtils.error(500, "该产品未关联供应商!");
}
@AuthRuleAnnotation("")
@GetMapping("/spms/info/company/product/filterAll")
public BaseResponse filterAll(FilterCompanyProductRelevanceRequest filterCompanyProductRelevanceRequest,
BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
List<UdiRlSupEntity> companyProductRelevanceEntities =
udiRlSupService.filterCompanyProductRelevance(filterCompanyProductRelevanceRequest);
PageInfo<UdiRlSupEntity> pageInfo;
pageInfo = new PageInfo<>(companyProductRelevanceEntities);
PageSimpleResponse<UdiRlSupEntity> pageSimpleResponse = new PageSimpleResponse<>();
pageSimpleResponse.setTotal(pageInfo.getTotal());
pageSimpleResponse.setList(companyProductRelevanceEntities);
return ResultVOUtils.success(pageSimpleResponse);
}
@AuthRuleAnnotation("")
@GetMapping("/sale/info/companyProductRelevance")
public BaseResponse getCompanyProductRelevanceInfo(CompanyRequest companyRequest) {
UdiRlSupEntity udiRlSupEntity = udiRlSupService.findCompanyProductRelevance(companyRequest.getCustomerId());
if (udiRlSupEntity != null) {
return ResultVOUtils.success(udiRlSupEntity);
}
return ResultVOUtils.error(500, "空");
}
@AuthRuleAnnotation("")
@GetMapping("/sale/info/getCompanyProductRelevance")
public BaseResponse getCompanyProductRelevance(FilterCompanyProductRelevanceRequest filterCompanyProductRelevanceRequest) {
List<UdiRlSupEntity> companyProductRelevanceEntities = udiRlSupService.getCompanyProductRelevance(filterCompanyProductRelevanceRequest);
PageInfo<UdiRlSupEntity> pageInfo = new PageInfo<>(companyProductRelevanceEntities);
PageSimpleResponse<UdiRlSupEntity> pageSimpleResponse = new PageSimpleResponse<>();
pageSimpleResponse.setTotal(pageInfo.getTotal());
pageSimpleResponse.setList(companyProductRelevanceEntities);
return ResultVOUtils.success(pageSimpleResponse);
}
@AuthRuleAnnotation("")
@PostMapping("/sale/info/insertCompanyProductRelevance")
@Log(title = "单据管理", businessType = BusinessType.INSERT)
public BaseResponse insertCompanyProductRelevance(@RequestBody UdiRlSupEntity udiRlSupEntity) {
if (udiRlSupService.findCompanyProductRelevanceByProductUuid(udiRlSupEntity) != null) {
return ResultVOUtils.error(ResultEnum.DATA_REPEAT);
}
udiRlSupEntity.setUnitFk(null);
udiRlSupEntity.setCreateTime(new Date());
udiRlSupEntity.setUpdateTime(new Date());
udiRlSupEntity.setAuditStatus("3");
boolean b = udiRlSupService.insertCompanyProductRelevance(udiRlSupEntity);
return ResultVOUtils.success("成功");
}
@AuthRuleAnnotation("")
@PostMapping("/sale/info/insertFilter")
@Log(title = "单据管理", businessType = BusinessType.INSERT)
public BaseResponse insertFilter(@RequestBody UdiInfoExportRequest udiInfoExportRequest) {
CompanyEntity companyEntity = companyService.findCompany(udiInfoExportRequest.getCustomerId() + "");
if (companyEntity != null) {
if ("110".equals(companyEntity.getUnitIdFk())) {
udiInfoExportRequest.setUnitFk(null);
} else {
udiInfoExportRequest.setUnitFk(companyEntity.getUnitIdFk());
}
}
//查询本企业有没有选择该产品有选择不能选择
CompanyProductRelevanceRequest companyProductRelevanceRequest = new CompanyProductRelevanceRequest();
companyProductRelevanceRequest.setCustomerId(udiInfoExportRequest.getCustomerId() + "");
List<CompanyProductRelevanceResponse> basicInstrumentMaintainRelevanceResponses = null;
companyProductRelevanceRequest.setDiType(1);
basicInstrumentMaintainRelevanceResponses = companyProductRelevanceService.filterUdiGp(companyProductRelevanceRequest);
String rlidStr = udiInfoExportRequest.getRlIds().get(0);
for (CompanyProductRelevanceResponse obj : basicInstrumentMaintainRelevanceResponses) {
String rlid = String.valueOf(obj.getRlId());
if (rlid.equals(rlidStr)) {
return ResultVOUtils.error(999, "该企业已选择该产品,请勿重复选择!");
}
}
String vailResult = supplementVailUtil.vail(udiInfoExportRequest.getSupplementRequest(), SupplementVailUtil.SUP_SELECT);
if (vailResult != null)
return ResultVOUtils.error(500, vailResult);
companyProductsRelService.insertCompanyProducts(udiInfoExportRequest);
UdiRelevanceEntity udiRelevanceEntity = new UdiRelevanceEntity();
udiRelevanceEntity.setId(Long.parseLong(rlidStr));
udiRelevanceEntity.setLockStatus(1);
udiRelevanceEntity.setGroupBuy(udiInfoExportRequest.getSupplementRequest().getGroupBuy());
udiRelevanceEntity.setUpdateTime(new Date());
udiRelevanceService.updateUdiRelevance(udiRelevanceEntity);
UdiProductEntity udiProductEntity = new UdiProductEntity();
BeanUtil.copyProperties(udiInfoExportRequest.getSupplementRequest(), udiProductEntity);
//处理是否需要扫码字段
classifyCodeService.updateRequireScanCode(udiProductEntity);
udiProductEntity.setUpdateTime(new Date());
UdiRelevanceEntity udiRelevanceEntity1 = udiRelevanceService.selectById(Long.valueOf(rlidStr));
UdiProductEntity byUuid = udiProductService.findByUuid(udiRelevanceEntity1.getUuid());
if (byUuid != null) {
byUuid.setCatalogname1(udiProductEntity.getCatalogname1());
byUuid.setCatalogname2(udiProductEntity.getCatalogname2());
byUuid.setCatalogname3(udiProductEntity.getCatalogname3());
byUuid.setYbbm(udiProductEntity.getYbbm());
byUuid.setManufactory(udiProductEntity.getManufactory());
byUuid.setUpdateTime(new Date());
udiProductService.updateUdiInfo(byUuid);
} else {
udiProductEntity.setId(IdUtil.getSnowflakeNextId());
udiProductService.insertUdiInfo(udiProductEntity);
}
// udiProductEntity.setId(IdUtil.getSnowflakeNextId());
// udiProductService.insertUdiInfo(udiProductEntity);
return ResultVOUtils.success("选入成功!");
}
@AuthRuleAnnotation("")
@PostMapping("/sale/info/updateCompanyProductRelevance")
@Log(title = "单据管理", businessType = BusinessType.UPDATE)
public BaseResponse updateCompanyProductRelevance(@RequestBody UdiRlSupEntity udiRlSupEntity) {
udiRlSupEntity.setUpdateTime(new Date());
int b = udiRlSupService.updateCompanyProductRelevance(udiRlSupEntity);
return ResultVOUtils.success("修改成功");
}
@PostMapping("/sale/info/deleteCompanyProductRelevance")
@Log(title = "单据管理", businessType = BusinessType.DELETE)
public BaseResponse deleteCompanyProductRelevance(@RequestBody DeleteCompanyFileRequest deleteCompanyFileRequest) {
boolean b = udiRlSupService.deleteById(deleteCompanyFileRequest.getId());
//推送
BasicDataRequest basicDataRequest = new BasicDataRequest();
basicDataRequest.setDeleteCompanyFileRequest(deleteCompanyFileRequest);
basicDataRequest.setKey("BASIC_MANAGE");
Long userId = getUserId();
BasicDataRequest request = webSocketServer.insert(basicDataRequest, userId + "");
request.setDeleteCompanyFileRequest(deleteCompanyFileRequest);
webSocketServer.sendMessage(SocketMsgEntity.builder().type(SocketMsgType.BASIC_MANAGE_DELETE).content(request).remark("入院物资维护").build(), null);
return ResultVOUtils.success("成功");
}
@AuthRuleAnnotation("")
@PostMapping("/sale/info/company/product/relevance/copyCustomerId")
public BaseResponse copyCustomerId(@RequestBody @Valid CopyCustomerIdRequest copyCustomerIdRequest,
BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
companyProductRelevanceService.copyCustomerId(copyCustomerIdRequest);
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() + "";
}
}