Your Name
2023-03-15 cab3425bb92d01f3494eb25c1f299038dc634c65
service-user/src/main/java/com/java110/user/cmd/examine/UpdateExamineStaffCmd.java
@@ -15,21 +15,33 @@
 */
package com.java110.user.cmd.examine;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.annotation.Java110Transactional;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.core.factory.GenerateCodeFactory;
import com.java110.core.smo.IPhotoSMO;
import com.java110.dto.user.UserDto;
import com.java110.intf.user.IExamineStaffIntroductionV1InnerServiceSMO;
import com.java110.intf.user.IExamineStaffProjectV1InnerServiceSMO;
import com.java110.intf.user.IExamineStaffV1InnerServiceSMO;
import com.java110.intf.user.IUserV1InnerServiceSMO;
import com.java110.po.examineStaff.ExamineStaffPo;
import com.java110.po.examineStaffIntroduction.ExamineStaffIntroductionPo;
import com.java110.po.examineStaffProject.ExamineStaffProjectPo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.StringUtil;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
/**
@@ -51,24 +63,90 @@
    @Autowired
    private IExamineStaffV1InnerServiceSMO examineStaffV1InnerServiceSMOImpl;
    @Autowired
    private IExamineStaffProjectV1InnerServiceSMO examineStaffProjectV1InnerServiceSMOImpl;
    @Autowired
    private IExamineStaffIntroductionV1InnerServiceSMO examineStaffIntroductionV1InnerServiceSMOImpl;
    @Autowired
    private IPhotoSMO photoSMOImpl;
    @Autowired
    private IUserV1InnerServiceSMO userV1InnerServiceSMOImpl;
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "esId", "esId不能为空");
        Assert.hasKeyAndValue(reqJson, "staffId", "staffId不能为空");
        Assert.hasKeyAndValue(reqJson, "communityId", "communityId不能为空");
        if (!reqJson.containsKey("projectIds")) {
            throw new CmdException("没包含考核项目");
        }
        JSONArray projectIds = reqJson.getJSONArray("projectIds");
        if (projectIds == null || projectIds.size() < 1) {
            throw new CmdException("没包含考核项目");
        }
    }
    @Override
    @Java110Transactional
    public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
        UserDto userDto = new UserDto();
        userDto.setUserId(reqJson.getString("staffId"));
        List<UserDto> userDtos = userV1InnerServiceSMOImpl.queryUsers(userDto);
        Assert.listOnlyOne(userDtos, "员工不存在");
        ExamineStaffPo examineStaffPo = BeanConvertUtil.covertBean(reqJson, ExamineStaffPo.class);
        examineStaffPo.setStaffName(userDtos.get(0).getName());
        int flag = examineStaffV1InnerServiceSMOImpl.updateExamineStaff(examineStaffPo);
        if (flag < 1) {
            throw new CmdException("更新数据失败");
        }
        ExamineStaffProjectPo tmpExamineStaffProjectPo = null;
        tmpExamineStaffProjectPo = new ExamineStaffProjectPo();
        tmpExamineStaffProjectPo.setEsId(examineStaffPo.getEsId());
        tmpExamineStaffProjectPo.setCommunityId(examineStaffPo.getCommunityId());
        examineStaffProjectV1InnerServiceSMOImpl.deleteExamineStaffProject(tmpExamineStaffProjectPo);
        JSONArray projectIds = reqJson.getJSONArray("projectIds");
        for (int projectIndex = 0; projectIndex < projectIds.size(); projectIndex++) {
            tmpExamineStaffProjectPo = new ExamineStaffProjectPo();
            tmpExamineStaffProjectPo.setEsId(examineStaffPo.getEsId());
            tmpExamineStaffProjectPo.setCommunityId(examineStaffPo.getCommunityId());
            tmpExamineStaffProjectPo.setProjectId(projectIds.getString(projectIndex));
            tmpExamineStaffProjectPo.setEspId(GenerateCodeFactory.getGeneratorId("11"));
            examineStaffProjectV1InnerServiceSMOImpl.saveExamineStaffProject(tmpExamineStaffProjectPo);
        }
        // todo save examine staff introduction
        if (reqJson.containsKey("introduction") && !StringUtil.isEmpty(reqJson.getString("introduction"))) {
            ExamineStaffIntroductionPo examineStaffIntroductionPo = new ExamineStaffIntroductionPo();
            examineStaffIntroductionPo.setStaffId(reqJson.getString("staffId"));
            examineStaffIntroductionPo.setIntroduction(reqJson.getString("introduction"));
            examineStaffIntroductionPo.setCommunityId(reqJson.getString("communityId"));
            examineStaffIntroductionV1InnerServiceSMOImpl.updateExamineStaffIntroduction(examineStaffIntroductionPo);
        }
        // todo save examine staff face image
        if(reqJson.containsKey("headerImg")) {
            photoSMOImpl.savePhoto(reqJson.getString("headerImg"),
                    examineStaffPo.getEsId(),
                    reqJson.getString("communityId"));
        }
        cmdDataFlowContext.setResponseEntity(ResultVo.success());
    }
}