From acb0762dcc448f8f7d2a9079473d605557e1f0cc Mon Sep 17 00:00:00 2001 From: lapuda <577732344@qq.com> Date: Thu, 16 Jul 2026 15:05:53 +0800 Subject: [PATCH] feat: Refactor company and job management to include company nature - Added companyNature field to Company entity and updated related services and mappers. - Removed jobNature field from Job and ESJobDocument entities as it is no longer needed. - Updated CompanyController to handle current company information and synchronization of account codes. - Enhanced CompanyServiceImpl to manage company nature changes and synchronize related job postings. - Updated SQL migrations to add company nature field and associated business dictionary entries. - Refactored job-related services to ensure they reflect the latest company nature information. --- .../cms/controller/cms/CompanyController.java | 136 +++++++++++++++++- .../com/ruoyi/cms/domain/ESJobDocument.java | 3 - .../main/java/com/ruoyi/cms/domain/Job.java | 4 - .../impl/BussinessDictTypeServiceImpl.java | 1 - .../cms/service/impl/CompanyServiceImpl.java | 28 +++- .../cms/service/impl/ESJobSearchImpl.java | 17 +-- .../cms/service/impl/JobServiceImpl.java | 2 +- .../resources/mapper/app/CompanyMapper.xml | 15 +- .../main/resources/mapper/app/JobMapper.xml | 15 +- .../mapper/rc/PublicJobFairMapper.xml | 2 +- .../common/core/domain/entity/Company.java | 4 + sql/migration_add_company_nature.sql | 77 ++++++++++ sql/migration_add_company_nature_prod.sql | 60 ++++++++ sql/migration_add_company_nature_test.sql | 60 ++++++++ sql/migration_add_job_nature.sql | 29 ---- sql/migration_add_job_nature_prod.sql | 30 ---- sql/migration_add_job_nature_test.sql | 30 ---- 17 files changed, 378 insertions(+), 135 deletions(-) create mode 100644 sql/migration_add_company_nature.sql create mode 100644 sql/migration_add_company_nature_prod.sql create mode 100644 sql/migration_add_company_nature_test.sql delete mode 100644 sql/migration_add_job_nature.sql delete mode 100644 sql/migration_add_job_nature_prod.sql delete mode 100644 sql/migration_add_job_nature_test.sql diff --git a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/controller/cms/CompanyController.java b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/controller/cms/CompanyController.java index d994235..6775ecf 100644 --- a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/controller/cms/CompanyController.java +++ b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/controller/cms/CompanyController.java @@ -3,9 +3,12 @@ package com.ruoyi.cms.controller.cms; import com.ruoyi.cms.domain.query.CompanySearch; import com.ruoyi.cms.domain.query.JobSearch; +import com.ruoyi.cms.mapper.AppUserMapper; import com.ruoyi.cms.util.RoleUtils; import com.ruoyi.cms.util.sensitiveWord.SensitiveWordChecker; +import com.ruoyi.common.core.domain.entity.AppUser; import com.ruoyi.common.core.domain.entity.Company; +import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.cms.service.ICompanyService; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; @@ -13,7 +16,10 @@ import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.poi.ExcelUtil; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ruoyi.system.service.ISysUserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; @@ -38,6 +44,12 @@ public class CompanyController extends BaseController @Autowired private ICompanyService companyService; + @Autowired + private AppUserMapper appUserMapper; + + @Autowired + private ISysUserService sysUserService; + @Autowired SensitiveWordChecker sensitiveWordChecker; @@ -50,10 +62,10 @@ public class CompanyController extends BaseController public TableDataInfo list(CompanySearch company) { if (RoleUtils.isCompanyAdmin()) { - System.out.println("企业社会信用代码============================="+RoleUtils.getCurrentUseridCard()); - if(StringUtils.isNotEmpty(RoleUtils.getCurrentUseridCard())){ - company.setCode(RoleUtils.getCurrentUseridCard()); - }else{ + Company currentCompany = getCurrentCompany(); + if (currentCompany != null) { + company.setCompanyId(currentCompany.getCompanyId()); + } else { return getDataTable(new ArrayList<>()); } } @@ -87,6 +99,21 @@ public class CompanyController extends BaseController return success(companyService.selectCompanyByCompanyId(companyId)); } + /** + * 获取当前企业账号关联的企业信息。 + */ + @ApiOperation("获取当前企业信息") + @PreAuthorize("@ss.hasPermi('cms:company:query')") + @GetMapping("/current") + public AjaxResult getCurrentInfo() + { + Company company = getCurrentCompany(); + if (company == null) { + return AjaxResult.error("未查询到当前企业信息"); + } + return success(companyService.selectCompanyByCompanyId(company.getCompanyId())); + } + /** * 新增公司 */ @@ -115,6 +142,8 @@ public class CompanyController extends BaseController @PutMapping public AjaxResult edit(@RequestBody Company company) { + Company existingCompany = company.getCompanyId() == null + ? null : companyService.selectCompanyByCompanyId(company.getCompanyId()); // 校验描述中的敏感词 List sensitiveWords = sensitiveWordChecker.checkSensitiveWords(company.getDescription()); if (!sensitiveWords.isEmpty()) { @@ -122,7 +151,104 @@ public class CompanyController extends BaseController return AjaxResult.error(errorMsg, sensitiveWords); } // 无敏感词,执行插入 - return toAjax(companyService.updateCompany(company)); + AjaxResult result = toAjax(companyService.updateCompany(company)); + if (result.get("code") instanceof Number && ((Number) result.get("code")).intValue() == 200 + && existingCompany != null && company.getCode() != null + && !java.util.Objects.equals(existingCompany.getCode(), company.getCode())) { + syncAccountCode(existingCompany.getCode(), company.getCode(), null); + } + return result; + } + + /** + * 修改当前企业账号关联的企业信息,企业ID由登录账号确定,不能由前端指定其他企业。 + */ + @ApiOperation("修改当前企业信息") + @PreAuthorize("@ss.hasPermi('cms:company:edit')") + @PutMapping("/current") + public AjaxResult editCurrent(@RequestBody Company company) + { + Company currentCompany = getCurrentCompany(); + if (currentCompany == null) { + return AjaxResult.error("未查询到当前企业信息"); + } + String oldCode = currentCompany.getCode(); + company.setCompanyId(currentCompany.getCompanyId()); + // 将企业和当前企业账号建立稳定的 user_id 关联,信用代码修改后仍能找到企业。 + Long appUserId = RoleUtils.getSysAppuserId(); + if (appUserId != null) { + company.setUserId(appUserId); + } + AjaxResult result = edit(company); + if (result.get("code") instanceof Number && ((Number) result.get("code")).intValue() == 200 + && StringUtils.isEmpty(oldCode) && company.getCode() != null) { + syncAccountCode(oldCode, company.getCode(), SecurityUtils.getLoginUser().getUser()); + } + return result; + } + + private Company getCurrentCompany() + { + if (!RoleUtils.isCompanyAdmin()) { + return null; + } + String currentCode = RoleUtils.getCurrentUseridCard(); + if (StringUtils.isNotEmpty(currentCode)) { + Company company = companyService.queryCodeCompany(currentCode); + if (company != null) { + return company; + } + } + + // 兼容历史数据:部分企业记录没有 company.user_id,先通过 app_user_id 查到企业账号。 + Long appUserId = RoleUtils.getSysAppuserId(); + if (appUserId != null) { + CompanySearch search = new CompanySearch(); + search.setUserId(appUserId); + List companies = companyService.selectCompanyList(search); + if (companies != null && !companies.isEmpty()) { + return companyService.selectCompanyByCompanyId(companies.get(0).getCompanyId()); + } + + // 兼容信用代码已被修改但账号缓存仍是旧值的场景。 + AppUser appUser = appUserMapper.selectById(appUserId); + if (appUser != null && StringUtils.isNotEmpty(appUser.getIdCard())) { + return companyService.queryCodeCompany(appUser.getIdCard()); + } + } + return null; + } + + /** + * 企业修改信用代码后同步 PC/APP 账号关联,避免后续岗位等企业端接口仍使用旧代码。 + */ + private void syncAccountCode(String oldCode, String newCode, SysUser fallbackUser) + { + SysUser currentUser = SecurityUtils.getLoginUser().getUser(); + SysUser sysUser = StringUtils.isNotEmpty(oldCode) + ? sysUserService.selectUserByIdCard(oldCode) : fallbackUser; + if (sysUser != null) { + SysUser updateUser = new SysUser(); + updateUser.setUserId(sysUser.getUserId()); + updateUser.setIdCard(newCode); + sysUserService.updateUserProfile(updateUser); + // 当前请求中的登录对象可能仍是缓存实例,立即更新它以便本次请求链路保持一致。 + if (currentUser != null && java.util.Objects.equals(currentUser.getUserId(), sysUser.getUserId())) { + currentUser.setIdCard(newCode); + } + } + + AppUser appUser = sysUser == null || sysUser.getAppUserId() == null + ? appUserMapper.selectOne(Wrappers.lambdaQuery().eq(AppUser::getIdCard, oldCode) + .eq(AppUser::getDelFlag, "0").last("LIMIT 1")) + : appUserMapper.selectById(sysUser.getAppUserId()); + if (appUser == null && fallbackUser != null && currentUser != null && currentUser.getAppUserId() != null) { + appUser = appUserMapper.selectById(currentUser.getAppUserId()); + } + if (appUser != null) { + appUser.setIdCard(newCode); + appUserMapper.updateById(appUser); + } } /** diff --git a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/domain/ESJobDocument.java b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/domain/ESJobDocument.java index f510706..62003a9 100644 --- a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/domain/ESJobDocument.java +++ b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/domain/ESJobDocument.java @@ -120,9 +120,6 @@ public class ESJobDocument @IndexField(fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_SMART) private String jobCategory; - @ApiModelProperty("岗位性质,对应业务字典 job_nature") - private String jobNature; - @JsonIgnore @ApiModelProperty("学历要求 对应字典education int类型 es方便查询") private Integer education_int; diff --git a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/domain/Job.java b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/domain/Job.java index ceebe52..32a3141 100644 --- a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/domain/Job.java +++ b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/domain/Job.java @@ -148,10 +148,6 @@ public class Job extends BaseEntity @ApiModelProperty("岗位分类") private String jobCategory; - @Excel(name = "岗位性质") - @ApiModelProperty("岗位性质,对应业务字典 job_nature") - private String jobNature; - @TableField(exist = false) @ApiModelProperty("公司性质") private String companyNature; diff --git a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/BussinessDictTypeServiceImpl.java b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/BussinessDictTypeServiceImpl.java index b618adb..f123d05 100644 --- a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/BussinessDictTypeServiceImpl.java +++ b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/BussinessDictTypeServiceImpl.java @@ -242,7 +242,6 @@ public class BussinessDictTypeServiceImpl implements IBussinessDictTypeService filed.put("data_source","数据来源"); filed.put("job_url","岗位url连接"); filed.put("job_category",jobTitleMapper.selectList(null).stream().map(JobTitle::getJobName).collect(Collectors.toList())); - filed.put("job_nature",this.selectDictDataByType("job_nature").stream().map(BussinessDictData::getDictLabel).collect(Collectors.toList())); return filed; } } diff --git a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/CompanyServiceImpl.java b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/CompanyServiceImpl.java index 4dbaf88..5cc9f19 100644 --- a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/CompanyServiceImpl.java +++ b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/CompanyServiceImpl.java @@ -155,6 +155,11 @@ public class CompanyServiceImpl extends ServiceImpl impl @Override public int updateCompany(Company company) { + Company existingCompany = company.getCompanyId() == null + ? null : companyMapper.selectById(company.getCompanyId()); + boolean companyNatureChanged = existingCompany != null + && company.getCompanyNature() != null + && !Objects.equals(existingCompany.getCompanyNature(), company.getCompanyNature()); Long count = companyMapper.selectCount(Wrappers.lambdaQuery().eq(Company::getName, company.getName())); if(count>1){ throw new ServiceException(company.getName()+",该公司已存在"); @@ -164,12 +169,23 @@ public class CompanyServiceImpl extends ServiceImpl impl companyContactMapper.update(null,Wrappers.lambdaUpdate() .eq(CompanyContact::getCompanyId, company.getCompanyId()) .set(CompanyContact::getDelFlag, Constants.Del_FLAG_DELETE)); - if(Objects.isNull(company.getCompanyContactList())){return i;} - company.getCompanyContactList().forEach(x -> { - CompanyContact companyContact = new CompanyContact(); - companyContact.setCompanyId(company.getCompanyId()); - companyContactMapper.insert(companyContact); - }); + if(!Objects.isNull(company.getCompanyContactList())){ + company.getCompanyContactList().forEach(x -> { + CompanyContact companyContact = new CompanyContact(); + companyContact.setCompanyId(company.getCompanyId()); + BeanUtils.copyProperties(x, companyContact); + companyContactMapper.insert(companyContact); + }); + } + if (companyNatureChanged) { + List jobIds = jobMapper.selectList(Wrappers.lambdaQuery() + .eq(Job::getCompanyId, company.getCompanyId())) + .stream() + .map(Job::getJobId) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + iesJobSearchService.batchUpdateJob(jobIds); + } } return i; } diff --git a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/ESJobSearchImpl.java b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/ESJobSearchImpl.java index 41972bb..8a159f5 100644 --- a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/ESJobSearchImpl.java +++ b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/ESJobSearchImpl.java @@ -220,9 +220,6 @@ public class ESJobSearchImpl implements IESJobSearchService if (esJobDocument.getLatitude() != null) { esJobDocument.setLatAndLon(esJobDocument.getLatitude().toString() + "," + esJobDocument.getLongitude().toString()); } - if(StringUtil.isEmptyOrNull(job.getCompanyNature())){ - esJobDocument.setCompanyNature("4"); - } if (StringUtils.isNotEmpty(job.getPostingDate())) { Date date = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,job.getPostingDate()); esJobDocument.setPostingDate(date); @@ -927,7 +924,10 @@ public class ESJobSearchImpl implements IESJobSearchService if(job!=null){ if(job.getCompanyId()!=null){ Company company=iCompanyService.selectCompanyByCompanyId(job.getCompanyId()); - job.setCode(company.getCode()); + if (company != null) { + job.setCode(company.getCode()); + job.setCompanyNature(company.getCompanyNature()); + } } } @@ -954,9 +954,6 @@ public class ESJobSearchImpl implements IESJobSearchService if (esJobDocument.getLatitude() != null) { esJobDocument.setLatAndLon(esJobDocument.getLatitude().toString() + "," + esJobDocument.getLongitude().toString()); } - if(StringUtil.isEmptyOrNull(job.getCompanyNature())){ - esJobDocument.setCompanyNature("4"); - } ensureJobDocumentIndexExists(); LambdaEsQueryWrapper lambdaEsQueryWrapper = new LambdaEsQueryWrapper(); @@ -1202,6 +1199,7 @@ public class ESJobSearchImpl implements IESJobSearchService Company company = companyMap.get(job.getCompanyId()); if (company != null) { esDoc.setCode(company.getCode()); + esDoc.setCompanyNature(company.getCompanyNature()); } } @@ -1231,11 +1229,6 @@ public class ESJobSearchImpl implements IESJobSearchService esDoc.setLatAndLon(esDoc.getLatitude() + "," + esDoc.getLongitude()); } - // 企业行业默认值 - if (StringUtil.isEmptyOrNull(job.getCompanyNature())) { - esDoc.setCompanyNature("4"); - } - return esDoc; } diff --git a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/JobServiceImpl.java b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/JobServiceImpl.java index f4f2f38..a30f334 100644 --- a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/JobServiceImpl.java +++ b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/JobServiceImpl.java @@ -456,7 +456,7 @@ public class JobServiceImpl extends ServiceImpl implements IJobSe //添加附件 handleJobFile(job); - // 数据库更新成功后再同步 ES,确保岗位性质等最新字段能立即反映到 PC 岗位卡片。 + // 数据库更新成功后再同步 ES,确保关联企业性质等最新字段能立即反映到 PC 岗位卡片。 if (Integer.valueOf(1).equals(job.getIsPublish()) || (job.getIsPublish() == null && existingJob != null && Integer.valueOf(1).equals(existingJob.getIsPublish()))) { diff --git a/ruoyi-bussiness/src/main/resources/mapper/app/CompanyMapper.xml b/ruoyi-bussiness/src/main/resources/mapper/app/CompanyMapper.xml index 249d7a4..0b70d9e 100644 --- a/ruoyi-bussiness/src/main/resources/mapper/app/CompanyMapper.xml +++ b/ruoyi-bussiness/src/main/resources/mapper/app/CompanyMapper.xml @@ -19,6 +19,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -44,7 +45,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select company_id, name, location, industry, scale, del_flag, create_by, create_time, update_by, update_time, remark,code,description,nature,total_recruitment,registered_address,contact_person,contact_person_phone,is_abnormal,not_pass_reason,status,case when status='2' then update_time else null end reject_time,is_imp_company,imp_company_type,enterprise_type,legal_person,legal_id_card,legal_phone,is_hrs from company + select company_id, name, location, industry, scale, del_flag, create_by, create_time, update_by, update_time, remark,code,description,nature,company_nature,total_recruitment,registered_address,contact_person,contact_person_phone,is_abnormal,not_pass_reason,status,case when status='2' then update_time else null end reject_time,is_imp_company,imp_company_type,enterprise_type,legal_person,legal_id_card,legal_phone,is_hrs from company @@ -99,13 +100,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" INSERT INTO company ( - name, location, industry, scale, code, description, nature, + name, location, industry, scale, code, description, nature, company_nature, create_by, create_time, del_flag ) VALUES ( #{company.name}, #{company.location}, #{company.industry}, #{company.scale}, - #{company.code}, #{company.description}, #{company.nature}, + #{company.code}, #{company.description}, #{company.nature}, #{company.companyNature}, #{company.createBy}, #{company.createTime}, #{company.delFlag} ) @@ -127,9 +128,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and scale = #{scale} and nature = #{nature} + and company_nature = #{companyNature} and code = #{code} and status = #{status} and company_id = #{companyId} + and user_id = #{userId} and is_hrs = #{isHrs} and create_time >= #{startDate} @@ -143,7 +146,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" SELECT * FROM COMPANY WHERE COMPANY_ID IN (select -1 UNION - SELECT COMPANY_ID FROM COMPANY WHERE nature = #{companyNature} + SELECT COMPANY_ID FROM COMPANY WHERE company_nature = #{companyNature} UNION @@ -160,6 +163,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and scale = #{scale} and nature = #{nature} + and company_nature = #{companyNature} and code = #{code} and status = #{status} @@ -176,7 +180,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -363,7 +362,7 @@ select pfj.id as fair_relation_id, j.job_id, j.job_title, j.min_salary, j.max_salary, j.education, j.experience, j.company_name, j.job_location, j.job_location_area_code, j.posting_date, j.vacancies, - j.company_id, j.description, j.job_category, j.job_nature, j.job_address + j.company_id, j.description, j.job_category, j.job_address from public_job_fair_job pfj inner join job j on pfj.job_id = j.job_id where pfj.job_fair_id = #{jobFairId} and pfj.company_id = #{companyId} and pfj.del_flag = '0' and j.del_flag = '0' diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/Company.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/Company.java index a0fe470..c50f55b 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/Company.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/Company.java @@ -54,6 +54,10 @@ public class Company extends BaseEntity @ApiModelProperty("性质") private String nature; + @Excel(name = "企业性质") + @ApiModelProperty("企业性质,对应业务字典 company_nature") + private String companyNature; + @ApiModelProperty("招聘数量") private Integer totalRecruitment; diff --git a/sql/migration_add_company_nature.sql b/sql/migration_add_company_nature.sql new file mode 100644 index 0000000..644f5c8 --- /dev/null +++ b/sql/migration_add_company_nature.sql @@ -0,0 +1,77 @@ +-- 企业性质:企业可维护,PC 岗位卡片通过岗位关联企业读取。 +-- 执行目标:对应环境 HighGo 数据库的 shz schema。 +-- 企业性质非必填,具体字典项由后台“业务字典”维护。 + +BEGIN; + +ALTER TABLE "shz"."company" + ADD COLUMN IF NOT EXISTS "company_nature" VARCHAR(100); + +COMMENT ON COLUMN "shz"."company"."company_nature" + IS '企业性质,对应业务字典 company_nature,非必填'; + +INSERT INTO "shz"."bussiness_dict_type" ( + "dict_id", "dict_name", "dict_type", "status", "create_by", "create_time", "remark" +) +SELECT + (SELECT COALESCE(MAX("dict_id"), 0) + 1 FROM "shz"."bussiness_dict_type"), + '企业性质', + 'company_nature', + '0', + 'system', + CURRENT_TIMESTAMP, + '企业信息及 PC 岗位卡片使用,字典项由业务字典维护' +WHERE NOT EXISTS ( + SELECT 1 + FROM "shz"."bussiness_dict_type" + WHERE "dict_type" = 'company_nature' +); + +-- 历史环境可能已有 company_nature 字典,但名称仍为“企业类型”,统一为需求名称。 +UPDATE "shz"."bussiness_dict_type" +SET "dict_name" = '企业性质', "update_by" = 'system', "update_time" = CURRENT_TIMESTAMP +WHERE "dict_type" = 'company_nature' AND "dict_name" <> '企业性质'; + +-- 企业管理下增加“企业信息”菜单,并将其授权给已有企业管理菜单的角色。 +INSERT INTO "shz"."sys_menu" ( + "menu_name", "parent_id", "order_num", "path", "component", "query", "route_name", + "is_frame", "is_cache", "menu_type", "visible", "status", "perms", "icon", + "create_by", "create_time", "remark", "menu_id" +) +SELECT + '企业信息', parent."menu_id", 2, 'company/info/index', 'Company/Info/index', '', '', + 1, 0, 'C', '0', '0', 'cms:company:query', 'ProfileOutlined', + 'system', CURRENT_TIMESTAMP, '企业用户查看和编辑自身企业信息', ids."menu_id" +FROM ( + SELECT "menu_id" + FROM "shz"."sys_menu" + WHERE "path" = 'company' AND "menu_name" = '企业管理' AND "menu_type" = 'M' + ORDER BY "menu_id" + LIMIT 1 +) parent +CROSS JOIN ( + SELECT COALESCE(MAX("menu_id"), 0) + 1 AS "menu_id" + FROM "shz"."sys_menu" +) ids +WHERE NOT EXISTS ( + SELECT 1 + FROM "shz"."sys_menu" + WHERE "path" = 'company/info/index' +); + +INSERT INTO "shz"."sys_role_menu" ("role_id", "menu_id") +SELECT DISTINCT rm."role_id", target."menu_id" +FROM "shz"."sys_role_menu" rm +JOIN "shz"."sys_menu" parent ON parent."menu_id" = rm."menu_id" +JOIN "shz"."sys_menu" target ON target."parent_id" = parent."menu_id" + AND target."path" = 'company/info/index' +WHERE parent."path" = 'company' + AND parent."menu_type" = 'M' + AND NOT EXISTS ( + SELECT 1 + FROM "shz"."sys_role_menu" existing + WHERE existing."role_id" = rm."role_id" + AND existing."menu_id" = target."menu_id" + ); + +COMMIT; diff --git a/sql/migration_add_company_nature_prod.sql b/sql/migration_add_company_nature_prod.sql new file mode 100644 index 0000000..854837d --- /dev/null +++ b/sql/migration_add_company_nature_prod.sql @@ -0,0 +1,60 @@ +-- 正式库:企业性质字段、业务字典类型及企业信息菜单迁移。 +-- 执行目标:正式 HighGo 数据库的 shz schema。 +-- 企业性质非必填;具体字典项由后台“业务字典”维护。 + +BEGIN; + +ALTER TABLE "shz"."company" + ADD COLUMN IF NOT EXISTS "company_nature" VARCHAR(100); + +COMMENT ON COLUMN "shz"."company"."company_nature" + IS '企业性质,对应业务字典 company_nature,非必填'; + +INSERT INTO "shz"."bussiness_dict_type" ( + "dict_id", "dict_name", "dict_type", "status", "create_by", "create_time", "remark" +) +SELECT + (SELECT COALESCE(MAX("dict_id"), 0) + 1 FROM "shz"."bussiness_dict_type"), + '企业性质', 'company_nature', '0', 'system', CURRENT_TIMESTAMP, + '企业信息及 PC 岗位卡片使用,字典项由业务字典维护' +WHERE NOT EXISTS ( + SELECT 1 FROM "shz"."bussiness_dict_type" WHERE "dict_type" = 'company_nature' +); + +-- 正式库可能已有 company_nature 字典,但名称仍为“企业类型”,统一为需求名称。 +UPDATE "shz"."bussiness_dict_type" +SET "dict_name" = '企业性质', "update_by" = 'system', "update_time" = CURRENT_TIMESTAMP +WHERE "dict_type" = 'company_nature' AND "dict_name" <> '企业性质'; + +INSERT INTO "shz"."sys_menu" ( + "menu_name", "parent_id", "order_num", "path", "component", "query", "route_name", + "is_frame", "is_cache", "menu_type", "visible", "status", "perms", "icon", + "create_by", "create_time", "remark", "menu_id" +) +SELECT + '企业信息', parent."menu_id", 2, 'company/info/index', 'Company/Info/index', '', '', + 1, 0, 'C', '0', '0', 'cms:company:query', 'ProfileOutlined', + 'system', CURRENT_TIMESTAMP, '企业用户查看和编辑自身企业信息', ids."menu_id" +FROM ( + SELECT "menu_id" FROM "shz"."sys_menu" + WHERE "path" = 'company' AND "menu_name" = '企业管理' AND "menu_type" = 'M' + ORDER BY "menu_id" LIMIT 1 +) parent +CROSS JOIN ( + SELECT COALESCE(MAX("menu_id"), 0) + 1 AS "menu_id" FROM "shz"."sys_menu" +) ids +WHERE NOT EXISTS (SELECT 1 FROM "shz"."sys_menu" WHERE "path" = 'company/info/index'); + +INSERT INTO "shz"."sys_role_menu" ("role_id", "menu_id") +SELECT DISTINCT rm."role_id", target."menu_id" +FROM "shz"."sys_role_menu" rm +JOIN "shz"."sys_menu" parent ON parent."menu_id" = rm."menu_id" +JOIN "shz"."sys_menu" target ON target."parent_id" = parent."menu_id" + AND target."path" = 'company/info/index' +WHERE parent."path" = 'company' AND parent."menu_type" = 'M' + AND NOT EXISTS ( + SELECT 1 FROM "shz"."sys_role_menu" existing + WHERE existing."role_id" = rm."role_id" AND existing."menu_id" = target."menu_id" + ); + +COMMIT; diff --git a/sql/migration_add_company_nature_test.sql b/sql/migration_add_company_nature_test.sql new file mode 100644 index 0000000..5a87297 --- /dev/null +++ b/sql/migration_add_company_nature_test.sql @@ -0,0 +1,60 @@ +-- 测试库:企业性质字段、业务字典类型及企业信息菜单迁移。 +-- 执行目标:测试 HighGo 数据库的 shz schema。 +-- 企业性质非必填;具体字典项由后台“业务字典”维护。 + +BEGIN; + +ALTER TABLE "shz"."company" + ADD COLUMN IF NOT EXISTS "company_nature" VARCHAR(100); + +COMMENT ON COLUMN "shz"."company"."company_nature" + IS '企业性质,对应业务字典 company_nature,非必填'; + +INSERT INTO "shz"."bussiness_dict_type" ( + "dict_id", "dict_name", "dict_type", "status", "create_by", "create_time", "remark" +) +SELECT + (SELECT COALESCE(MAX("dict_id"), 0) + 1 FROM "shz"."bussiness_dict_type"), + '企业性质', 'company_nature', '0', 'system', CURRENT_TIMESTAMP, + '企业信息及 PC 岗位卡片使用,字典项由业务字典维护' +WHERE NOT EXISTS ( + SELECT 1 FROM "shz"."bussiness_dict_type" WHERE "dict_type" = 'company_nature' +); + +-- 测试库可能已有 company_nature 字典,但名称仍为“企业类型”,统一为需求名称。 +UPDATE "shz"."bussiness_dict_type" +SET "dict_name" = '企业性质', "update_by" = 'system', "update_time" = CURRENT_TIMESTAMP +WHERE "dict_type" = 'company_nature' AND "dict_name" <> '企业性质'; + +INSERT INTO "shz"."sys_menu" ( + "menu_name", "parent_id", "order_num", "path", "component", "query", "route_name", + "is_frame", "is_cache", "menu_type", "visible", "status", "perms", "icon", + "create_by", "create_time", "remark", "menu_id" +) +SELECT + '企业信息', parent."menu_id", 2, 'company/info/index', 'Company/Info/index', '', '', + 1, 0, 'C', '0', '0', 'cms:company:query', 'ProfileOutlined', + 'system', CURRENT_TIMESTAMP, '企业用户查看和编辑自身企业信息', ids."menu_id" +FROM ( + SELECT "menu_id" FROM "shz"."sys_menu" + WHERE "path" = 'company' AND "menu_name" = '企业管理' AND "menu_type" = 'M' + ORDER BY "menu_id" LIMIT 1 +) parent +CROSS JOIN ( + SELECT COALESCE(MAX("menu_id"), 0) + 1 AS "menu_id" FROM "shz"."sys_menu" +) ids +WHERE NOT EXISTS (SELECT 1 FROM "shz"."sys_menu" WHERE "path" = 'company/info/index'); + +INSERT INTO "shz"."sys_role_menu" ("role_id", "menu_id") +SELECT DISTINCT rm."role_id", target."menu_id" +FROM "shz"."sys_role_menu" rm +JOIN "shz"."sys_menu" parent ON parent."menu_id" = rm."menu_id" +JOIN "shz"."sys_menu" target ON target."parent_id" = parent."menu_id" + AND target."path" = 'company/info/index' +WHERE parent."path" = 'company' AND parent."menu_type" = 'M' + AND NOT EXISTS ( + SELECT 1 FROM "shz"."sys_role_menu" existing + WHERE existing."role_id" = rm."role_id" AND existing."menu_id" = target."menu_id" + ); + +COMMIT; diff --git a/sql/migration_add_job_nature.sql b/sql/migration_add_job_nature.sql deleted file mode 100644 index 1af4fac..0000000 --- a/sql/migration_add_job_nature.sql +++ /dev/null @@ -1,29 +0,0 @@ --- 岗位性质:后台可选、PC 岗位卡片返回的业务字典字段。 --- 岗位性质非必填;字典项由后台“业务字典”维护。 - -BEGIN; - -ALTER TABLE "shz"."job" - ADD COLUMN IF NOT EXISTS "job_nature" VARCHAR(100); - -COMMENT ON COLUMN "shz"."job"."job_nature" - IS '岗位性质,对应业务字典 job_nature,非必填'; - -INSERT INTO "shz"."bussiness_dict_type" ( - "dict_id", "dict_name", "dict_type", "status", "create_by", "create_time", "remark" -) -SELECT - (SELECT COALESCE(MAX("dict_id"), 0) + 1 FROM "shz"."bussiness_dict_type"), - '岗位性质', - 'job_nature', - '0', - 'system', - CURRENT_TIMESTAMP, - '岗位管理使用,字典项由业务字典维护' -WHERE NOT EXISTS ( - SELECT 1 - FROM "shz"."bussiness_dict_type" - WHERE "dict_type" = 'job_nature' -); - -COMMIT; diff --git a/sql/migration_add_job_nature_prod.sql b/sql/migration_add_job_nature_prod.sql deleted file mode 100644 index a39d13b..0000000 --- a/sql/migration_add_job_nature_prod.sql +++ /dev/null @@ -1,30 +0,0 @@ --- 正式库:岗位性质字段及业务字典类型迁移。 --- 执行目标:正式 HighGo 数据库的 shz schema。 --- 岗位性质非必填;具体字典项由后台“业务字典”维护。 - -BEGIN; - -ALTER TABLE "shz"."job" - ADD COLUMN IF NOT EXISTS "job_nature" VARCHAR(100); - -COMMENT ON COLUMN "shz"."job"."job_nature" - IS '岗位性质,对应业务字典 job_nature,非必填'; - -INSERT INTO "shz"."bussiness_dict_type" ( - "dict_id", "dict_name", "dict_type", "status", "create_by", "create_time", "remark" -) -SELECT - (SELECT COALESCE(MAX("dict_id"), 0) + 1 FROM "shz"."bussiness_dict_type"), - '岗位性质', - 'job_nature', - '0', - 'system', - CURRENT_TIMESTAMP, - '岗位管理使用,字典项由业务字典维护' -WHERE NOT EXISTS ( - SELECT 1 - FROM "shz"."bussiness_dict_type" - WHERE "dict_type" = 'job_nature' -); - -COMMIT; diff --git a/sql/migration_add_job_nature_test.sql b/sql/migration_add_job_nature_test.sql deleted file mode 100644 index cf11d33..0000000 --- a/sql/migration_add_job_nature_test.sql +++ /dev/null @@ -1,30 +0,0 @@ --- 测试库:岗位性质字段及业务字典类型迁移。 --- 执行目标:测试 HighGo 数据库的 shz schema。 --- 岗位性质非必填;具体字典项由后台“业务字典”维护。 - -BEGIN; - -ALTER TABLE "shz"."job" - ADD COLUMN IF NOT EXISTS "job_nature" VARCHAR(100); - -COMMENT ON COLUMN "shz"."job"."job_nature" - IS '岗位性质,对应业务字典 job_nature,非必填'; - -INSERT INTO "shz"."bussiness_dict_type" ( - "dict_id", "dict_name", "dict_type", "status", "create_by", "create_time", "remark" -) -SELECT - (SELECT COALESCE(MAX("dict_id"), 0) + 1 FROM "shz"."bussiness_dict_type"), - '岗位性质', - 'job_nature', - '0', - 'system', - CURRENT_TIMESTAMP, - '岗位管理使用,字典项由业务字典维护' -WHERE NOT EXISTS ( - SELECT 1 - FROM "shz"."bussiness_dict_type" - WHERE "dict_type" = 'job_nature' -); - -COMMIT;