# ServiceRequestCenterChangeTypeOperation.java

    package cloud.wconnect.it.service.servicerequestcenter.notify;

    import cloud.wconnect.commonlib.cons.LanguageEnum;
    import cloud.wconnect.commonlib.pojo.dto.NotifyDTO;
    import cloud.wconnect.commonlib.redis.PropertyI18nRedisService;
    import cloud.wconnect.commonlib.service.NotifyInternalService;
    import cloud.wconnect.commonlib.service.UserInternalService;
    import cloud.wconnect.commonlib.util.EmailUtil;
    import cloud.wconnect.commonlib.util.I18nMessageUtils;
    import cloud.wconnect.it.cons.FunctionPointEnum;
    import cloud.wconnect.it.cons.servicerequestcenter.ServiceRequestCenterActiveTypeEnum;
    import cloud.wconnect.it.cons.servicerequestcenter.ServiceRequestCenterNotifyEnum;
    import cloud.wconnect.it.cons.servicerequestcenter.ServiceRequestCenterTypeEnum;
    import cloud.wconnect.it.entity.servicerequestcenter.ServiceRequestCenter;
    import cloud.wconnect.it.pojo.bo.servicerequestcenter.ServiceRequestCenterNotifyBodyBO;
    import cloud.wconnect.it.pojo.vo.servicerequestcenter.ServiceRequestCenterEmailVO;
    import cloud.wconnect.it.service.servicerequestcenter.IServiceRequestCenterNotifyConfigService;
    import cloud.wconnect.it.service.servicerequestcenter.IServiceRequestCenterService;
    import com.alibaba.fastjson.JSONObject;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.google.common.collect.Lists;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.thymeleaf.TemplateEngine;
    import org.thymeleaf.context.Context;

    import java.util.Map;

    /**
     * @author: yyt
     * 2025-12-17
     */
    @Service
    @DS("it_manage")
    public class ServiceRequestCenterChangeTypeOperation implements IServiceRequestCenterNotifyService {

        @Autowired
        private NotifyInternalService notifyInternalService;
        @Autowired
        private PropertyI18nRedisService propertyI18nRedisService;
        @Autowired
        private UserInternalService userInternalService;
        @Autowired
        private IServiceRequestCenterService serviceRequestCenterService;
        @Autowired
        private IServiceRequestCenterNotifyConfigService serviceRequestCenterNotifyConfigService;
        @Autowired
        private TemplateEngine templateEngine;
        @Autowired
        private I18nMessageUtils i18nMessageUtils;

        /**
         * 通知
         *
         * @param notifyBodyBO notifyBodyBO
         * @author yyt
         * @date 2025/12/17
         **/
        @Override
        public void notify(ServiceRequestCenterNotifyBodyBO notifyBodyBO) {
            // 通知用户
            ServiceRequestCenter request = serviceRequestCenterService.getById(notifyBodyBO.getRequestId());
            Integer tenantId = notifyBodyBO.getTenantId();
            Integer propertyId = serviceRequestCenterNotifyConfigService.getPropertyIdForEmail(tenantId, request, request.getCreatedBy());
            String language = LanguageEnum.ENGLISH.getLanguage();

            NotifyDTO notifyDTO = new NotifyDTO();
            notifyDTO.setPropertyId(propertyId);
            notifyDTO.setFunctionPoint(FunctionPointEnum.SERVICE_REQUEST_CENTER_OPERATION.getFunctionPoint());

            String subject = i18nMessageUtils.message(ServiceRequestCenterNotifyEnum.OPERATION_CHANGE_TYPE.getI18nCode(), language,
                    request.getServiceNumber(), request.getTitle(), serviceRequestCenterNotifyConfigService.getPropertyNameForEmail(tenantId, request));
            notifyDTO.setSubject(subject);

            int receiverId = request.getCreatedBy();
            int operationId = notifyBodyBO.getOperationId();

            notifyDTO.setIdentityList(serviceRequestCenterNotifyConfigService.getNotifyCreator(request));

            int activeType = ServiceRequestCenterActiveTypeEnum.MY_TICKET.getType();
            JSONObject msg = serviceRequestCenterNotifyConfigService.generateLineMsg();
            notifyDTO.setLineContent(Lists.newArrayList(msg));

            // 封装邮件内容
            ServiceRequestCenterEmailVO emailVO = serviceRequestCenterNotifyConfigService.packageCommonEmailContent(notifyBodyBO.getTenantId(), request, activeType, request.getCreatedBy());

            // 收件人姓名、操作人姓名、old type、new type
            Map<Integer, String> userNameById = userInternalService.getNameMapByIds(tenantId, Lists.newArrayList(receiverId, operationId));
            emailVO.setReceiverName(userNameById.get(receiverId));
            emailVO.setOperatorName(userNameById.get(operationId));
            emailVO.setOldTypeStr(i18nMessageUtils.message(ServiceRequestCenterTypeEnum.getI18nCode(notifyBodyBO.getOldType()), language));

            Context context = new Context();
            context.setVariable("emailVO", emailVO);
            String emailContent = templateEngine.process("servicerequestcenter/change-type_" + language, context);
            notifyDTO.setEmailContent(EmailUtil.getFullEmailContent(subject, emailContent, language));

            notifyInternalService.sendNotify(notifyDTO);
        }

    }