package com.manage.interfaces.webservice.impl;

import com.alibaba.fastjson.JSON;
import com.manage.dao.Power_DeptMapper;
import com.manage.dao.Power_MenuMapper;
import com.manage.dao.Power_UserMapper;
import com.manage.encrypt.Base64;
import com.manage.encrypt.MD5;
import com.manage.entity.PowerUser;
import com.manage.entity.Power_Dept;
import com.manage.entity.Power_Menu;
import com.manage.entity.Power_User;
import com.manage.service.cache.Cache;
import com.manage.service.cache.CacheManager;
import com.manage.interfaces.webservice.PowerWebService;
import com.manage.service.User_Dept_MenuService;
import com.manage.util.Constant;
import com.manage.util.FileUtils;
import com.manage.util.XmlUtils;
import com.manage.vo.Power_UserVo;
import com.manage.vo.Power_UserWebServiceVo;
import com.manage.vo.User_Dept_Menu;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import javax.jws.WebService;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.logging.SimpleFormatter;

@Component
@WebService(serviceName = "PowerWebService",
        targetNamespace = "http://webservice.interfaces.manage.com/",
        endpointInterface = "com.manage.interfaces.webservice.PowerWebService"
)
public class PowerWebServiceImpl implements PowerWebService {
    private final Logger logger = LoggerFactory.getLogger(getClass());
    @Value("${newUserName}")
    private String newUserName;
    @Value("${name}")
    private String name;
    @Value("${deptCode}")
    private String deptCode;
    @Value("${synchronizationSwitch}")
    private String synchronizationSwitch;
    @Value("${deptCTDCode}")
    private String deptCTDCode;
    @Value("${deptCTDDesc}")
    private String deptCTDDesc;
    @Autowired
    Power_MenuMapper powerMenuMapper;
    @Autowired
    User_Dept_MenuService userDeptMenuService;
    @Autowired
    Power_UserMapper powerUserMapper;
    @Autowired
    Power_DeptMapper powerDeptMapper;
    @Override
    public String getInfosByUserId(String token,String sysFlag) {
         Power_UserWebServiceVo userWebServiceVo = new Power_UserWebServiceVo();
        if(StringUtils.isNotBlank(token) && StringUtils.isNotBlank(token) ){
            token = MD5.JM(Base64.decode(token));
            Cache cache = CacheManager.getCacheInfo(token);
            if(cache != null){
                Power_UserVo user = (Power_UserVo) cache.getValue();
                //设置名字
                user.setUserPosition(user.getName());
                List<User_Dept_Menu> menuList = user.getMenuList();
                Set<String> menus = new TreeSet();
                try {
                    for(User_Dept_Menu menu : menuList){
                        if(StringUtils.isNotBlank(menu.getMenuUrl()) && StringUtils.isNotBlank(menu.getSysFlag()) && sysFlag.equals(menu.getSysFlag()) && StringUtils.isNotBlank(menu.getMethod())){
                            menus.add(menu.getMenuUrl());
                        }
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
                BeanUtils.copyProperties(user,userWebServiceVo);
                //可预览信息设置在手机号字段
                userWebServiceVo.setUserTel(user.getShowRecord()+"");
                //可下载信息设置在邮箱字段
                userWebServiceVo.setUserEmail(user.getDownloadRecord()+"");
                //查看打印简要设置在职位字段
                userWebServiceVo.setUserAge(user.getShowPrint());
                //预览显示水印设置在年龄字段
                userWebServiceVo.setUserSex(user.getShowWater());
                userWebServiceVo.setMenus(menus);
            }
        }
        return JSON.toJSONString(userWebServiceVo);
    }

    @Override
    public String tempTest() {
        return "aaaa~~~~~~~~~~~~~~~~~~~~~~~";
    }

    @Override
    public String HIPMessageServer(String code, String xml) {
        if (StringUtils.isNotBlank(synchronizationSwitch) && "1".equals(synchronizationSwitch)) {
            //科室字典信息方法
            if (StringUtils.isNotBlank(code) && "MES0067".equals(code)) {
                departmentInfo(code,xml);
            }
            //医护人员字典信息
            else if (StringUtils.isNotBlank(code) && "MES0072".equals(code)){
                userInfo(code,xml);
            }
            else {
                return "无效的服务编码";
            }
        }
        return "<Response>\n" +
                " <Header>\n" +
                " <SourceSystem></SourceSystem>\n" +
                " <MessageID></MessageID>\n" +
                " </Header>\n" +
                " <Body>\n" +
                " <ResultCode>0</ResultCode>\n" +
                " <ResultContent>成功</ResultContent>\n" +
                " </Body>\n" +
                "</Response>";
    }
    //科室字典信息方法
    private String departmentInfo(String code, String xml){
        if (StringUtils.isBlank(xml)) {
            return "xml不能为空";
        }
        /**
         * <Request>
         *     <Header>
         *         <SourceSystem>30</SourceSystem>
         *         <MessageID></MessageID>
         *     </Header>
         *     <Body>
         *         <CT_CareProvList>
         *             <CT_CareProv>
         *                 <BusinessFieldCode>00001</BusinessFieldCode>
         *                 <CTCP_AdminiLevel></CTCP_AdminiLevel>
         *                 <CTCP_AdminiPosition></CTCP_AdminiPosition>
         *                 <CTCP_ArrivalHosDate></CTCP_ArrivalHosDate>
         *                 <CTCP_BirthDate></CTCP_BirthDate>
         *                 <CTCP_BirthPlace></CTCP_BirthPlace>
         *                 <CTCP_CareProvPositionCode></CTCP_CareProvPositionCode>
         *                 <CTCP_CareProvTypeCode></CTCP_CareProvTypeCode>
         *                 <CTCP_Code>HHZK</CTCP_Code>
         *                 <CTCP_CodesystemCode>CT_CareProv</CTCP_CodesystemCode>
         *                 <CTCP_CreatDate></CTCP_CreatDate>
         *                 <CTCP_CreatTime></CTCP_CreatTime>
         *                 <CTCP_CreditLevel></CTCP_CreditLevel>
         *                 <CTCP_CurrDeptDate></CTCP_CurrDeptDate>
         *                 <CTCP_DegreeCode></CTCP_DegreeCode>
         *                 <CTCP_DeptCode>H222100</CTCP_DeptCode>
         *                 <CTCP_DeptHierarchyCode></CTCP_DeptHierarchyCode>
         *                 <CTCP_Desc>H黄子楷</CTCP_Desc>
         *                 <CTCP_DocPracCatCode></CTCP_DocPracCatCode>
         *                 <CTCP_EducationCode></CTCP_EducationCode>
         *                 <CTCP_Email></CTCP_Email>
         *                 <CTCP_EmployMode></CTCP_EmployMode>
         *                 <CTCP_EmploymentDate></CTCP_EmploymentDate>
         *                 <CTCP_EndDate></CTCP_EndDate>
         *                 <CTCP_ExtranetURL></CTCP_ExtranetURL>
         *                 <CTCP_FamilyNameSpell></CTCP_FamilyNameSpell>
         *                 <CTCP_FirstNameSpell></CTCP_FirstNameSpell>
         *                 <CTCP_FirstSubject></CTCP_FirstSubject>
         *                 <CTCP_FormType></CTCP_FormType>
         *                 <CTCP_HosCode>NFYKDXNFYY</CTCP_HosCode>
         *                 <CTCP_IDCardNO></CTCP_IDCardNO>
         *                 <CTCP_IDCardTypeCode></CTCP_IDCardTypeCode>
         *                 <CTCP_IdentityType></CTCP_IdentityType>
         *                 <CTCP_ImageInfo></CTCP_ImageInfo>
         *                 <CTCP_IntranetURL></CTCP_IntranetURL>
         *                 <CTCP_JobNumber>HHZK</CTCP_JobNumber>
         *                 <CTCP_LearnSource></CTCP_LearnSource>
         *                 <CTCP_MaritalCode></CTCP_MaritalCode>
         *                 <CTCP_Name>H黄子楷</CTCP_Name>
         *                 <CTCP_NationCode></CTCP_NationCode>
         *                 <CTCP_NativePlace></CTCP_NativePlace>
         *                 <CTCP_NurPracCatCode></CTCP_NurPracCatCode>
         *                 <CTCP_OriginalCode></CTCP_OriginalCode>
         *                 <CTCP_OriginalDesc></CTCP_OriginalDesc>
         *                 <CTCP_PassWord></CTCP_PassWord>
         *                 <CTCP_PoliticalAffiliation></CTCP_PoliticalAffiliation>
         *                 <CTCP_PoliticalJoinDate></CTCP_PoliticalJoinDate>
         *                 <CTCP_PositionName></CTCP_PositionName>
         *                 <CTCP_PositionSeqCode></CTCP_PositionSeqCode>
         *                 <CTCP_PositionStatus></CTCP_PositionStatus>
         *                 <CTCP_PracCertiCode></CTCP_PracCertiCode>
         *                 <CTCP_PracCertiRegAddress></CTCP_PracCertiRegAddress>
         *                 <CTCP_PracLevel></CTCP_PracLevel>
         *                 <CTCP_PracStartDateInHos></CTCP_PracStartDateInHos>
         *                 <CTCP_PracStatus></CTCP_PracStatus>
         *                 <CTCP_PracticeArea></CTCP_PracticeArea>
         *                 <CTCP_PracticeEndDate></CTCP_PracticeEndDate>
         *                 <CTCP_PracticeStartDate></CTCP_PracticeStartDate>
         *                 <CTCP_PrescriptionAFlag></CTCP_PrescriptionAFlag>
         *                 <CTCP_PrescriptionFlag></CTCP_PrescriptionFlag>
         *                 <CTCP_PrescriptionMFlag></CTCP_PrescriptionMFlag>
         *                 <CTCP_PrescriptionPFlag></CTCP_PrescriptionPFlag>
         *                 <CTCP_PrescriptionRFlag></CTCP_PrescriptionRFlag>
         *                 <CTCP_PrescriptionSFlag></CTCP_PrescriptionSFlag>
         *                 <CTCP_QualiCertiCode></CTCP_QualiCertiCode>
         *                 <CTCP_RegistResidence></CTCP_RegistResidence>
         *                 <CTCP_Remarks>HHZK</CTCP_Remarks>
         *                 <CTCP_RetireDate></CTCP_RetireDate>
         *                 <CTCP_SexCode></CTCP_SexCode>
         *                 <CTCP_SourceCat></CTCP_SourceCat>
         *                 <CTCP_SpecCertiCode></CTCP_SpecCertiCode>
         *                 <CTCP_SpecializeIn></CTCP_SpecializeIn>
         *                 <CTCP_Spell></CTCP_Spell>
         *                 <CTCP_StaffCat></CTCP_StaffCat>
         *                 <CTCP_StaffLevel></CTCP_StaffLevel>
         *                 <CTCP_StaffTypeCode>护士</CTCP_StaffTypeCode>
         *                 <CTCP_StartDate>2019-05-08</CTCP_StartDate>
         *                 <CTCP_Status>1</CTCP_Status>
         *                 <CTCP_SubjectCat></CTCP_SubjectCat>
         *                 <CTCP_Telephone></CTCP_Telephone>
         *                 <CTCP_TitleEmployDate></CTCP_TitleEmployDate>
         *                 <CTCP_TitleOfTechCode></CTCP_TitleOfTechCode>
         *                 <CTCP_TitleOfTechLevel></CTCP_TitleOfTechLevel>
         *                 <CTCP_UpdateDate></CTCP_UpdateDate>
         *                 <CTCP_UpdateTime></CTCP_UpdateTime>
         *                 <CTCP_UpdateUserCode>无</CTCP_UpdateUserCode>
         *                 <CTCP_UrbanRegiResiFlag></CTCP_UrbanRegiResiFlag>
         *                 <CTCP_Violation></CTCP_Violation>
         *                 <CTCP_WorkInHosReason></CTCP_WorkInHosReason>
         *                 <CTCP_WorkOrgCode></CTCP_WorkOrgCode>
         *                 <CTCP_WorkYears></CTCP_WorkYears>
         *             </CT_CareProv>
         *         </CT_CareProvList>
         *     </Body>
         * </Request>
         */
        try {
            SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
            Map map = new HashMap();
            logger.info("接收到xml数据：" + xml);
            //xml转map
            map = XmlUtils.parseXml2Map(xml, map);
            //获取在xml中节点key
            String cTDCode = deptCTDCode;
            String cTDDesc = deptCTDDesc;
            //获取所要的值
            String deptCode = (String) map.get(cTDCode);
            String deptDesc = (String) map.get(cTDDesc);
            logger.info("解析xml数据：deptCode = " + deptCode + "; deptDesc = " + deptDesc);
            if (StringUtils.isBlank(deptCode)) {
                return "科室编号不能为空";
            }
            Power_Dept dept = new Power_Dept();
            dept.setDeptName(deptDesc);
            dept.setDeptCode(deptCode);
            //查询是否存在
            List<Power_Dept> powerDepts = powerDeptMapper.checkDeptCode(deptCode);
            dept.setUpdater("admin");
            dept.setUpdateDate(fmt.format(new Date()));
            if (!CollectionUtils.isEmpty(powerDepts)) {
                //修改
                Power_Dept powerDept = powerDepts.get(0);
                Integer deptId = powerDept.getDeptId();
                BeanUtils.copyProperties(dept, powerDept);
                powerDept.setDeptId(deptId);
                powerDeptMapper.updateByPrimaryKeySelective(powerDept);
                logger.info("deptDesc = " + deptDesc + "修改成功！");
            } else {
                //新增
                //设置初始值
                dept.setEffective(1);
                dept.setCreateDate(fmt.format(new Date()));
                dept.setCreater("zwh");
                dept.setDictId(1);
                Power_Dept newPowerDapt =new Power_Dept();
                BeanUtils.copyProperties(dept, newPowerDapt);
                powerDeptMapper.insert(newPowerDapt);
                logger.info("deptDesc = " + deptDesc + "插入成功！");
            }
        } catch (BeansException e) {
            e.printStackTrace();
            return e.getMessage();
        }
        //科室编码转科室id
        return "<Response>\n" +
                " <Header>\n" +
                " <SourceSystem></SourceSystem>\n" +
                " <MessageID></MessageID>\n" +
                " </Header>\n" +
                " <Body>\n" +
                " <ResultCode>0</ResultCode>\n" +
                " <ResultContent>成功</ResultContent>\n" +
                " </Body>\n" +
                "</Response>";
    }


    //HIS 用户字典信息方法
    private String userInfo(String code, String xml){
        if (StringUtils.isBlank(xml)) {
            return "xml不能为空";
        }
        /**
         * <Request>
         *     <Header>
         *         <SourceSystem>30</SourceSystem>
         *         <MessageID></MessageID>
         *     </Header>
         *     <Body>
         *         <CT_CareProvList>
         *             <CT_CareProv>
         *                 <BusinessFieldCode>00001</BusinessFieldCode>
         *                 <CTCP_AdminiLevel></CTCP_AdminiLevel>
         *                 <CTCP_AdminiPosition></CTCP_AdminiPosition>
         *                 <CTCP_ArrivalHosDate></CTCP_ArrivalHosDate>
         *                 <CTCP_BirthDate></CTCP_BirthDate>
         *                 <CTCP_BirthPlace></CTCP_BirthPlace>
         *                 <CTCP_CareProvPositionCode></CTCP_CareProvPositionCode>
         *                 <CTCP_CareProvTypeCode></CTCP_CareProvTypeCode>
         *                 <CTCP_Code>HHZK</CTCP_Code>
         *                 <CTCP_CodesystemCode>CT_CareProv</CTCP_CodesystemCode>
         *                 <CTCP_CreatDate></CTCP_CreatDate>
         *                 <CTCP_CreatTime></CTCP_CreatTime>
         *                 <CTCP_CreditLevel></CTCP_CreditLevel>
         *                 <CTCP_CurrDeptDate></CTCP_CurrDeptDate>
         *                 <CTCP_DegreeCode></CTCP_DegreeCode>
         *                 <CTCP_DeptCode>H222100</CTCP_DeptCode>
         *                 <CTCP_DeptHierarchyCode></CTCP_DeptHierarchyCode>
         *                 <CTCP_Desc>H黄子楷</CTCP_Desc>
         *                 <CTCP_DocPracCatCode></CTCP_DocPracCatCode>
         *                 <CTCP_EducationCode></CTCP_EducationCode>
         *                 <CTCP_Email></CTCP_Email>
         *                 <CTCP_EmployMode></CTCP_EmployMode>
         *                 <CTCP_EmploymentDate></CTCP_EmploymentDate>
         *                 <CTCP_EndDate></CTCP_EndDate>
         *                 <CTCP_ExtranetURL></CTCP_ExtranetURL>
         *                 <CTCP_FamilyNameSpell></CTCP_FamilyNameSpell>
         *                 <CTCP_FirstNameSpell></CTCP_FirstNameSpell>
         *                 <CTCP_FirstSubject></CTCP_FirstSubject>
         *                 <CTCP_FormType></CTCP_FormType>
         *                 <CTCP_HosCode>NFYKDXNFYY</CTCP_HosCode>
         *                 <CTCP_IDCardNO></CTCP_IDCardNO>
         *                 <CTCP_IDCardTypeCode></CTCP_IDCardTypeCode>
         *                 <CTCP_IdentityType></CTCP_IdentityType>
         *                 <CTCP_ImageInfo></CTCP_ImageInfo>
         *                 <CTCP_IntranetURL></CTCP_IntranetURL>
         *                 <CTCP_JobNumber>HHZK</CTCP_JobNumber>
         *                 <CTCP_LearnSource></CTCP_LearnSource>
         *                 <CTCP_MaritalCode></CTCP_MaritalCode>
         *                 <CTCP_Name>H黄子楷</CTCP_Name>
         *                 <CTCP_NationCode></CTCP_NationCode>
         *                 <CTCP_NativePlace></CTCP_NativePlace>
         *                 <CTCP_NurPracCatCode></CTCP_NurPracCatCode>
         *                 <CTCP_OriginalCode></CTCP_OriginalCode>
         *                 <CTCP_OriginalDesc></CTCP_OriginalDesc>
         *                 <CTCP_PassWord></CTCP_PassWord>
         *                 <CTCP_PoliticalAffiliation></CTCP_PoliticalAffiliation>
         *                 <CTCP_PoliticalJoinDate></CTCP_PoliticalJoinDate>
         *                 <CTCP_PositionName></CTCP_PositionName>
         *                 <CTCP_PositionSeqCode></CTCP_PositionSeqCode>
         *                 <CTCP_PositionStatus></CTCP_PositionStatus>
         *                 <CTCP_PracCertiCode></CTCP_PracCertiCode>
         *                 <CTCP_PracCertiRegAddress></CTCP_PracCertiRegAddress>
         *                 <CTCP_PracLevel></CTCP_PracLevel>
         *                 <CTCP_PracStartDateInHos></CTCP_PracStartDateInHos>
         *                 <CTCP_PracStatus></CTCP_PracStatus>
         *                 <CTCP_PracticeArea></CTCP_PracticeArea>
         *                 <CTCP_PracticeEndDate></CTCP_PracticeEndDate>
         *                 <CTCP_PracticeStartDate></CTCP_PracticeStartDate>
         *                 <CTCP_PrescriptionAFlag></CTCP_PrescriptionAFlag>
         *                 <CTCP_PrescriptionFlag></CTCP_PrescriptionFlag>
         *                 <CTCP_PrescriptionMFlag></CTCP_PrescriptionMFlag>
         *                 <CTCP_PrescriptionPFlag></CTCP_PrescriptionPFlag>
         *                 <CTCP_PrescriptionRFlag></CTCP_PrescriptionRFlag>
         *                 <CTCP_PrescriptionSFlag></CTCP_PrescriptionSFlag>
         *                 <CTCP_QualiCertiCode></CTCP_QualiCertiCode>
         *                 <CTCP_RegistResidence></CTCP_RegistResidence>
         *                 <CTCP_Remarks>HHZK</CTCP_Remarks>
         *                 <CTCP_RetireDate></CTCP_RetireDate>
         *                 <CTCP_SexCode></CTCP_SexCode>
         *                 <CTCP_SourceCat></CTCP_SourceCat>
         *                 <CTCP_SpecCertiCode></CTCP_SpecCertiCode>
         *                 <CTCP_SpecializeIn></CTCP_SpecializeIn>
         *                 <CTCP_Spell></CTCP_Spell>
         *                 <CTCP_StaffCat></CTCP_StaffCat>
         *                 <CTCP_StaffLevel></CTCP_StaffLevel>
         *                 <CTCP_StaffTypeCode>护士</CTCP_StaffTypeCode>
         *                 <CTCP_StartDate>2019-05-08</CTCP_StartDate>
         *                 <CTCP_Status>1</CTCP_Status>
         *                 <CTCP_SubjectCat></CTCP_SubjectCat>
         *                 <CTCP_Telephone></CTCP_Telephone>
         *                 <CTCP_TitleEmployDate></CTCP_TitleEmployDate>
         *                 <CTCP_TitleOfTechCode></CTCP_TitleOfTechCode>
         *                 <CTCP_TitleOfTechLevel></CTCP_TitleOfTechLevel>
         *                 <CTCP_UpdateDate></CTCP_UpdateDate>
         *                 <CTCP_UpdateTime></CTCP_UpdateTime>
         *                 <CTCP_UpdateUserCode>无</CTCP_UpdateUserCode>
         *                 <CTCP_UrbanRegiResiFlag></CTCP_UrbanRegiResiFlag>
         *                 <CTCP_Violation></CTCP_Violation>
         *                 <CTCP_WorkInHosReason></CTCP_WorkInHosReason>
         *                 <CTCP_WorkOrgCode></CTCP_WorkOrgCode>
         *                 <CTCP_WorkYears></CTCP_WorkYears>
         *             </CT_CareProv>
         *         </CT_CareProvList>
         *     </Body>
         * </Request>
         */
        try {
            SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
            Map map = new HashMap();
            logger.info("接收到xml数据：" + xml);
            //xml转map
            map = XmlUtils.parseXml2Map(xml, map);
            //获取在xml中节点key
            String userNameKey = newUserName;
            String nameKey = name;
            String deptCodeKey = deptCode;
            //获取所要的值
            String userName = (String) map.get(userNameKey);
            String name = (String) map.get(nameKey);
            String deptCode = (String) map.get(deptCodeKey);
            logger.info("解析xml数据：userName = " + userName + "; name= " + name + "; deptCode = " + deptCode);
            if (StringUtils.isBlank(userName)) {
                return "工号不能为空";
            }
            PowerUser user = new PowerUser();
            user.setName(name);
            user.setUserName(userName);
            user.setDeptCode(deptCode);
            user.setDeptId("");
            //设置科室id
            setDeptIdForUser(user);
            //查询是否存在
            List<Power_User> powerUsers = powerUserMapper.checkUserName(userName);
            user.setUpdater("zwh");
            user.setUpdateDate(fmt.format(new Date()));
            if (!CollectionUtils.isEmpty(powerUsers)) {
                //修改
                Power_User powerUser = powerUsers.get(0);
                Integer userId = powerUser.getUserId();
                BeanUtils.copyProperties(user, powerUser);
                powerUser.setUserId(userId);
                powerUserMapper.updateByPrimaryKeySelective(powerUser);
                logger.info("userName = " + userName + "修改成功！");
            } else {
                //新增
                //设置初始值
                user.setEffective(1);
                user.setCreateDate(fmt.format(new Date()));
                user.setCreater("zwh");
                user.setRoleId(1);
                user.setUserPwd("RUZHQEFC");
                Power_User userNew = new Power_User();
                BeanUtils.copyProperties(user, userNew);
                powerUserMapper.insert(userNew);
                logger.info("userName = " + userName + "插入成功！");
            }
        } catch (BeansException e) {
            e.printStackTrace();
            return e.getMessage();
        }
        //科室编码转科室id
        return "<Response>\n" +
                " <Header>\n" +
                " <SourceSystem></SourceSystem>\n" +
                " <MessageID></MessageID>\n" +
                " </Header>\n" +
                " <Body>\n" +
                " <ResultCode>0</ResultCode>\n" +
                " <ResultContent>成功</ResultContent>\n" +
                " </Body>\n" +
                "</Response>";
    }



    //科室编号转科室id
    private void setDeptIdForUser(PowerUser user) {
        if(StringUtils.isBlank(user.getDeptCode())){
            return;
        }
        //根据科室编码查科室id
        List<Integer> deptIds = powerUserMapper.selectDeptIdByDeptCode(user.getDeptCode());
        if(CollectionUtils.isEmpty(deptIds)){
            return;
        }
        user.setDeptId(deptIds.get(0).toString());
    }
    private List<Power_Menu> getPowerMenuMethods(Power_User powerUser, String sysId){
        // 根据用户ID以及系统Id查出所有的用户菜单
        List<Power_Menu> powerUserMenus = powerMenuMapper.selectUserMenuByUserIdAndDictId(powerUser.getUserId(), Integer.parseInt(sysId));
        // 根据用户ID以及系统Id查出所有的角色菜单
        List<Power_Menu> powerRoleMenus = powerMenuMapper.selectRoleMenuByUserIdAndDictId(powerUser.getUserId(), Integer.parseInt(sysId));
        // 当前用户的所有菜单集合
        List<Power_Menu> tempPowerMenus = new ArrayList<>(powerRoleMenus);
        for (Power_Menu powerMenu:powerUserMenus) {
            if(powerMenu.getFlag().equals(Constant.EFFECTIVE_YES)){
                tempPowerMenus.add(powerMenu);
            }else if(powerMenu.getFlag().equals(Constant.EFFECTIVE_NO)){
                tempPowerMenus.remove(powerMenu);
            }
        }

        List<Power_Menu> powerMenus = new ArrayList<>(tempPowerMenus);
        for (Power_Menu powerMenu:tempPowerMenus) {
            for (int i = 0;i<tempPowerMenus.size();i++) {
                if(powerMenu.getParentId().equals(tempPowerMenus.get(i).getMenuId()) && powerMenu.getMethod() != null){
                    powerMenus.get(i).getMethods().add(powerMenu);
                    powerMenus.remove(powerMenu);
                }
            }
        }
        return powerMenus;
    }
}
