Commit 326d9b28 authored by suhuiguang's avatar suhuiguang

feat(jyjc):检验检测业务管理初始代码

1.初始代码提交
parent 41a91ff0
......@@ -45,4 +45,6 @@ public class TZSCommonConstant {
*/
public static final String EQU_CATEGORY_CODE_GDYLRQ = "2100";
public static final String SX_PROVINCE_CODE = "610000";
}
......@@ -47,6 +47,13 @@ public class JyjcOpeningApplication extends BaseEntity {
private List<String> detectionRegion;
/**
* 排除的区域
*/
@TableField(value = "exclusion_region", typeHandler = FastjsonTypeHandler.class)
private List<String> exclusionRegion;
/**
* 检测区域名称(冗余)
*/
@TableField("detection_region_name")
......
package com.yeejoin.amos.boot.module.jyjc.api.model;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class JyjcBizManageModel extends JyjcOpeningApplicationModel {
/**
* 区域停(启)用状态
*/
private String areaStatus;
}
......@@ -39,6 +39,9 @@ public class JyjcOpeningApplicationModel extends BaseModel {
@TableField(value = "detection_region", typeHandler = FastjsonTypeHandler.class)
private List<String> detectionRegion;
@ApiModelProperty(value = "排除的区域编码")
private List<String> exclusionRegion;
@ApiModelProperty(value = "检测区域名称(冗余)")
private String detectionRegionName;
......
package com.yeejoin.amos.boot.module.jyjc.biz.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.module.jyjc.api.model.JyjcBizManageModel;
import com.yeejoin.amos.boot.module.jyjc.biz.service.impl.JyjcBizManageServiceImpl;
import com.yeejoin.amos.boot.module.ymt.api.entity.BaseUnitLicence;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.List;
@RestController
@RequestMapping
@Api(tags = "检验检测业务管理")
@RequiredArgsConstructor
public class JyjcBizManageController extends BaseController {
private final JyjcBizManageServiceImpl jyjcBizManageService;
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/page")
@ApiOperation(httpMethod = "POST", value = "检验检测机构开通业务列表,分页", notes = "检验检测机构开通业务列表,分页")
public ResponseModel<IPage<?>> getManageList(@RequestParam(value = "current") int current,
@RequestParam(value = "size") int size,
@RequestBody JyjcBizManageModel model) {
Page<JyjcBizManageModel> page = new Page<>(current, size);
IPage<?> res = jyjcBizManageService.pageList(page, getSelectedOrgInfo().getCompany(), model);
return ResponseHelper.buildResponse(res);
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PutMapping(value = "/{appSeq}/area-enable")
@ApiOperation(httpMethod = "PUT", value = "企业区域启用", notes = "企业区域启用")
public ResponseModel<Boolean> enableBatch(@PathVariable String appSeq) {
return ResponseHelper.buildResponse(jyjcBizManageService.enable(appSeq, getSelectedOrgInfo().getCompany()));
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PutMapping(value = "/{appSeq}/area-disable")
@ApiOperation(httpMethod = "PUT", value = "企业区域停用", notes = "企业区域停用")
public ResponseModel<Boolean> disableBatch(@PathVariable String appSeq) {
return ResponseHelper.buildResponse(jyjcBizManageService.disable(appSeq, getSelectedOrgInfo().getCompany()));
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/{appSeq}/licence-edit")
@ApiOperation(httpMethod = "PUT", value = "资质停起用", notes = "资质停起用")
public ResponseModel<Boolean> licenceEdit(@PathVariable String appSeq,
@RequestBody List<BaseUnitLicence> licences) {
return ResponseHelper.buildResponse(jyjcBizManageService.licenceEdit(appSeq, licences));
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/{appSeq}/licence-detail")
@ApiOperation(httpMethod = "GET", value = "资质详情", notes = "资质详情")
public ResponseModel<List<BaseUnitLicence>> licenceDetail(@PathVariable String appSeq) {
return ResponseHelper.buildResponse(jyjcBizManageService.licenceDetail(appSeq));
}
}
package com.yeejoin.amos.boot.module.jyjc.biz.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.bo.CompanyBo;
import com.yeejoin.amos.boot.module.common.api.constant.TZSCommonConstant;
import com.yeejoin.amos.boot.module.common.api.dto.BaseEnterpriseCertDto;
import com.yeejoin.amos.boot.module.jyjc.api.common.BizCommonConstant;
import com.yeejoin.amos.boot.module.jyjc.api.entity.JyjcInspectionHistory;
import com.yeejoin.amos.boot.module.jyjc.api.entity.JyjcOpeningApplication;
import com.yeejoin.amos.boot.module.jyjc.api.model.JyjcBizManageModel;
import com.yeejoin.amos.boot.module.jyjc.api.model.JyjcOpeningApplicationModel;
import com.yeejoin.amos.boot.module.ymt.api.entity.BaseUnitLicence;
import com.yeejoin.amos.boot.module.ymt.api.enums.FlowStatusEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Service;
import org.typroject.tyboot.core.rdbms.orm.entity.BaseEntity;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
@Slf4j
public class JyjcBizManageServiceImpl {
private static final String TY = "停用";
private static final String QY = "启用";
private final JyjcOpeningApplicationServiceImpl openingApplicationService;
private final RedissonClient redissonClient;
public IPage<?> pageList(Page<JyjcBizManageModel> page, CompanyBo company, JyjcOpeningApplicationModel model) {
Page<JyjcOpeningApplication> pageApp = new Page<>(page.getCurrent(), page.getSize());
LambdaQueryWrapper<JyjcOpeningApplication> queryWrapper = new LambdaQueryWrapper<>();
this.setIdentify(company, queryWrapper);
queryWrapper.eq(JyjcOpeningApplication::getStatus, FlowStatusEnum.TO_BE_FINISHED.getName());
queryWrapper.like(StringUtils.isNotEmpty(model.getUnitCodeName()), JyjcOpeningApplication::getUnitCodeName, model.getUnitCodeName());
queryWrapper.eq(StringUtils.isNotEmpty(model.getOpenBizType()), JyjcOpeningApplication::getOpenBizType, model.getOpenBizType());
IPage<JyjcOpeningApplication> res = openingApplicationService.page(pageApp, queryWrapper);
List<JyjcBizManageModel> manageModels = res.getRecords().stream().map(r -> {
JyjcBizManageModel bizManageModel = BeanUtil.copyProperties(r, JyjcBizManageModel.class);
setAreaStatusByIdentify(company, r, bizManageModel);
return bizManageModel;
}).collect(Collectors.toList());
page.setRecords(manageModels);
page.setTotal(res.getTotal());
return page;
}
private static void setAreaStatusByIdentify(CompanyBo company, JyjcOpeningApplication r, JyjcBizManageModel bizManageModel) {
if (TZSCommonConstant.SHAN_XI_REGION_CODE.equals(company.getCompanyCode())) {
bizManageModel.setAreaStatus(QY);
} else {
if (r.getExclusionRegion() != null && r.getExclusionRegion().contains(company.getCompanyCode())) {
bizManageModel.setAreaStatus(TY);
} else {
bizManageModel.setAreaStatus(QY);
}
}
}
private void setIdentify(CompanyBo company, LambdaQueryWrapper<JyjcOpeningApplication> queryWrapper) {
if (!TZSCommonConstant.SHAN_XI_REGION_CODE.equals(company.getCompanyCode())) {
queryWrapper.and(w ->
w.like(JyjcOpeningApplication::getDetectionRegion, company.getCompanyCode())
.or()
.like(JyjcOpeningApplication::getExclusionRegion, company.getCompanyCode()));
}
}
public Boolean enable(String appSeq, CompanyBo company) {
log.info("启用企业区域权限, appSeq: {}, company: {}", appSeq, company.getCompanyCode());
String lockKey = "app:region:lock:" + appSeq;
RLock lock = redissonClient.getLock(lockKey);
try {
boolean isLocked = lock.tryLock(0, 180, TimeUnit.SECONDS);
// 解决并发问题:多个人同时操作一个单据
if (!isLocked) {
throw new BadRequest("其他机构同时在操作该业务,请稍后重试!");
}
JyjcOpeningApplication openingApplication = openingApplicationService.getById(appSeq);
List<String> detectionRegion = openingApplication.getDetectionRegion();
Set<String> detectionRegionSet = new HashSet<>(detectionRegion);
detectionRegionSet.add(company.getCompanyCode());
List<String> exclusionRegion = openingApplication.getExclusionRegion();
if (exclusionRegion != null) {
exclusionRegion.remove(company.getCompanyCode());
}
openingApplicationService.update(new LambdaUpdateWrapper<JyjcOpeningApplication>()
.eq(BaseEntity::getSequenceNbr, appSeq)
.set(JyjcOpeningApplication::getDetectionRegion, detectionRegionSet)
.set(JyjcOpeningApplication::getExclusionRegion, exclusionRegion));
} catch (InterruptedException e) {
log.error("启用企业区域失败:{}", e.getMessage(), e);
} finally {
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
lock.unlock();
}
}
return Boolean.TRUE;
}
public Boolean disable(String appSeq, CompanyBo company) {
log.info("禁用企业区域权限, appSeq: {}, company: {}", appSeq, company.getCompanyCode());
String lockKey = "app:region:lock:" + appSeq;
RLock lock = redissonClient.getLock(lockKey);
try {
boolean isLocked = lock.tryLock(0, 180, TimeUnit.SECONDS);
// 解决并发问题:解决并发问题:多个人同时操作一个单据
if (!isLocked) {
throw new BadRequest("其他机构同时在操作该业务,请稍后重试!");
}
JyjcOpeningApplication openingApplication = openingApplicationService.getById(appSeq);
List<String> detectionRegion = openingApplication.getDetectionRegion();
if (detectionRegion != null) {
detectionRegion.remove(company.getCompanyCode());
}
List<String> exclusionRegion = openingApplication.getExclusionRegion();
Set<String> exclusionRegionSet = new HashSet<>(exclusionRegion);
exclusionRegion.add(company.getCompanyCode());
openingApplicationService.update(new LambdaUpdateWrapper<JyjcOpeningApplication>()
.eq(BaseEntity::getSequenceNbr, appSeq)
.set(JyjcOpeningApplication::getDetectionRegion, detectionRegion)
.set(JyjcOpeningApplication::getExclusionRegion, exclusionRegionSet));
} catch (InterruptedException e) {
log.error("禁用企业区域失败:{}", e.getMessage(), e);
} finally {
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
lock.unlock();
}
}
return Boolean.TRUE;
}
public Boolean licenceEdit(String appSeq, List<BaseUnitLicence> licences) {
// openingApplications.forEach(jyjcOpeningApplication -> {
// JyjcInspectionHistory history = inspectionHistoryService.getBySSeq(jyjcOpeningApplication.getSequenceNbr());
// if (history != null) {
// JSONObject hisData = history.getHistoryData();
// List<BaseEnterpriseCertDto> certDtos = hisData.getJSONArray(BizCommonConstant.UNIT_LICENCE_KEY).toJavaList(BaseEnterpriseCertDto.class);
return Boolean.TRUE;
}
public List<BaseUnitLicence> licenceDetail(String appSeq) {
return null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment