# ServiceRequestCenterChangeDutyUserOperation.java

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

    import cloud.wconnect.commonlib.cons.EmailConfigCons;
    import cloud.wconnect.commonlib.cons.LanguageEnum;
    import cloud.wconnect.commonlib.pojo.dto.NotifyDTO;
    import cloud.wconnect.commonlib.pojo.dto.NotifyIdentityDTO;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.pojo.dto.internationalization.InternationalizationDateTimeDTO;
    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.commonlib.util.InternationalizationUtils;
    import cloud.wconnect.it.cons.FunctionPointEnum;
    import cloud.wconnect.it.cons.servicerequestcenter.ServiceRequestCenterActiveTypeEnum;
    import cloud.wconnect.it.cons.servicerequestcenter.ServiceRequestCenterNotifyEnum;
    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.IServiceRequestCenterPropertyService;
    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.apache.commons.lang3.StringUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.stereotype.Service;
    import org.thymeleaf.TemplateEngine;
    import org.thymeleaf.context.Context;

    import java.util.ArrayList;
    import java.util.Map;

    /**
     * @author: yyt
     * 2025-12-17
     */
    @Service
    @DS("it_manage")
    public class ServiceRequestCenterChangeDutyUserOperation 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;

        @Value("${default.timezone}")
        private String timezone;

        /**
         * 通知
         *
         * @param notifyBodyBO notifyBodyBO
         * @author yyt
         * @date 2025/12/17
         **/
        @Override
        public void notify(ServiceRequestCenterNotifyBodyBO notifyBodyBO) {
            // 通知员工
            ServiceRequestCenter request = serviceRequestCenterService.getById(notifyBodyBO.getRequestId());
            //  收件人、操作人
            int receiverId = request.getDutyUser();
            int operatorId = notifyBodyBO.getOldDutyUser();

            Integer tenantId = notifyBodyBO.getTenantId();
            Integer propertyId = serviceRequestCenterNotifyConfigService.getPropertyIdForEmail(tenantId, request, receiverId);
            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_DUTY_USER.getI18nCode(), language,
                    request.getServiceNumber(), request.getTitle(), serviceRequestCenterNotifyConfigService.getPropertyNameForEmail(tenantId, request));
            notifyDTO.setSubject(subject);

            ArrayList<NotifyIdentityDTO> notifyIdentityDTOs = Lists.newArrayList(new NotifyIdentityDTO()
                    .setTargetType(EmailConfigCons.TARGET_TYPE_TO).setIdentityId(receiverId)
                    .setEmail(StringUtils.EMPTY).setSource(EmailConfigCons.SOURCE_USER));
            notifyDTO.setIdentityList(notifyIdentityDTOs);

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

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

            // 收件人姓名、操作人姓名、创建人姓名、创建日期、描述
            Map<Integer, String> userNameById = userInternalService.getNameMapByIds(tenantId, Lists.newArrayList(receiverId, operatorId, request.getCreatedBy()));
            emailVO.setReceiverName(userNameById.get(receiverId));
            emailVO.setOperatorName(userNameById.get(operatorId));
            emailVO.setCreateName(userNameById.get(request.getCreatedBy()));
            String longDate = InternationalizationDateTimeDTO.LONG_DATE_2;
            emailVO.setCreateDate(InternationalizationUtils.formatDateTime(request.getCreatedTime(), longDate, null, timezone, language));
            emailVO.setDescription(request.getDescription());

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

            notifyInternalService.sendNotify(notifyDTO);
        }

    }