SysUserService.java 12.2 KB
package cn.csbr.app.service;

import cn.csbr.app.config.FxConfigure;
import cn.csbr.app.exception.AuthException;
import cn.csbr.app.gui.GUIContext;
import cn.csbr.springboot.dao.mapper.SysOrgMapper;
import cn.csbr.springboot.dao.mapper.SysUserFingerMapper;
import cn.csbr.springboot.dao.mapper.SysUserMapper;
import cn.csbr.springboot.dao.model.SysOrg;
import cn.csbr.springboot.dao.model.SysUser;
import cn.csbr.springboot.dao.model.SysUserFinger;
import cn.hutool.core.date.DateTime;
import com.alibaba.fastjson.JSON;
import com.csbr.mybatis.CommonMapper;
import com.csbr.util.IdUtils;
import com.sun.xml.internal.xsom.impl.ListSimpleTypeImpl;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 用户信息查询
 * @author liwuji
 * @since 2018-12-10
 */
@Service
public class SysUserService {

    @Autowired
    private CommonMapper commonMapper;
    @Autowired
    private SysUserMapper sysUserMapper;
    @Autowired
    private SysUserFingerMapper sysUserFingerMapper;
    @Autowired
    private GUIContext guiContext;
    @Value("${app.cabinet.group.code}")
    private String cabinetGroupCode;
    private static Logger logger = LoggerFactory.getLogger(SysUserService.class);

    @Autowired
    private SysOrgMapper sysOrgMapper;

    public synchronized void updateUserPassword(SysUser user) {
        logger.info("SysUserService.updateUserPassword修改密码方法入参为" + JSON.toJSONString(user));
        String sql = "update sys_user set PWD = '" + user.getPwd() + "',UPDATETIME = '" + new Timestamp(new Date().getTime()) + "',UPDATENAME = '" + user.getUpdatename() + "'where GUID = '" + user.getGuid() + "';";

        commonMapper.update(sql);

    }
    public synchronized void updateUserPassword2(SysUser user) {
        logger.info("SysUserService.updateUserPassword修改密码方法入参为" + JSON.toJSONString(user));
        String sql2 = "update sys_user set PWD = '" + user.getPwd() + "',UPDATETIME = '" + new Timestamp(new Date().getTime()) + "',UPDATENAME = '" + user.getUpdatename() + "'where GUID = '" + user.getGuid() + "';";

        // userMapper.updatePwd(sql2);
    }
    public synchronized boolean updateUserCarid(SysUser user) {
        logger.info("SysUserService.updateUserPassword修改carid方法入参为" + user.getCardId()+"|"+user.getLoginuser());
        String sql = "update sys_user set cardid = '" + user.getCardId() + "',UPDATETIME = '" + new Timestamp(new Date().getTime()) + "',UPDATENAME = '" + user.getUpdatename() + "'where GUID = '" + user.getLoginuser() + "';";
        System.out.println("准备上传");
        commonMapper.update(sql);
        System.out.println("上传完成");
        Map m= commonMapper.queryOne("SELECT cardid FROM sys_user WHERE GUID='"+user.getLoginuser()+"'");
        System.out.println("SELECT cardid FROM sys_user WHERE GUID='"+user.getLoginuser()+"'");
        logger.info("1111"+ user.getLoginuser().toString() );
        if(m!=null&&m.size()<=0)
            return false;

        System.out.println(m.get("cardid"));
        return m.get("cardid")==null?false:m.get("cardid").equals(user.getCardId());
    }

    public synchronized void updateUserstate(SysUser user) {
        logger.info("SysUserService.updateUserstate修改状态方法入参为" + JSON.toJSONString(user));
        int res = sysUserMapper.updateByPrimaryKeySelective(user);
        if (res <= 0) {
            throw new AuthException("修改失败,请稍后重试");
        }
    }

    public synchronized SysUser findUser(SysUser user) {
        logger.info("SysUserService.findUser查询用户信息入参为:" + JSON.toJSONString(user));
        logger.info("sysMapper对象为"+sysUserMapper);
        //构建SysUser类型的通用查询对象
        Example example = new Example(SysUser.class);
        example.createCriteria().andEqualTo("fingerprint", user.getFingerprint());
        List<SysUser> userList = sysUserMapper.selectByExample(example);
        logger.info("查询到的对象为1"+userList);
        if(CollectionUtils.isEmpty(userList)) {
            return null;
        }
        return userList.get(0);
    }
    @Autowired
    private FxConfigure fxConfigure;
    public synchronized List<SysUserFinger> findUserFingerByUserid(SysUser user) {
        logger.info("SysUserService.findUser查询用户信息入参为:" + JSON.toJSONString(user));
        logger.info("sysMapper对象为"+sysUserMapper);
        //构建SysUser类型的通用查询对象
        Example example = new Example(SysUserFinger.class);
        example.createCriteria().andEqualTo("userguid", user.getGuid()).andEqualTo("orgguid",user.getOrgguid())
        .andEqualTo("groupcode",fxConfigure.getCabinetGroupCode());
        List<SysUserFinger> userList = sysUserFingerMapper.selectByExample(example);
        //logger.info("查询到的对象为1"+userList);
        if(CollectionUtils.isEmpty(userList)) {
            return null;
        }
        return userList;
       // return userList.get(0);
    }
    public synchronized SysUser findUserByCardId(SysUser user) {
        logger.info("SysUserService.findUser查询用户信息入参为:" + JSON.toJSONString(user));
        logger.info("sysMapper对象为"+sysUserMapper);
        //构建SysUser类型的通用查询对象

        //String sql = " select ta.* from sys_user ta where bizstate='Y' and cardid="+"'"+user.getCardId()+"'"+"  exists (select 'x' from sys_store_org tb where ta.orgguid=tb.deptguid and tb.storeguid="+"'"+guiContext.getStoreguid()+"'"+") ";
        String sql="select u.* from sys_user u,sys_store_org s where bizstate = 'Y' AND cardid = "+"'"+user.getCardId()+"'"+" and u.orgguid = s.deptguid AND s.storeguid = '"+guiContext.getStoreguid()+"'";
        System.out.println("card:"+sql);
        List<Map> maps = commonMapper.queryList(sql);
        List<SysUser> userList = new ArrayList<SysUser>();
        for (Map map : maps) {
            SysUser sysUser = JSON.parseObject(JSON.toJSONString(map), SysUser.class);
            userList.add(sysUser);
        }
        logger.info("查询到的对象为2"+userList);
        if(CollectionUtils.isEmpty(userList)) {
            guiContext.setDooropenUser(null);
            return null;
        }

        guiContext.setDooropenUser(userList.get(0));
        return userList.get(0);
    }
    //增加科室与柜子对应关系处理   YYQ 2021/09/09
    public synchronized SysUser findUserByCardId(SysUser user,String CabinetGuid) {
        logger.info("SysUserService.findUser查询用户信息入参为:" + JSON.toJSONString(user));
        logger.info("sysMapper对象为"+sysUserMapper);
        //构建SysUser类型的通用查询对象

        //String sql = " select ta.* from sys_user ta where bizstate='Y' and cardid="+"'"+user.getCardId()+"'"+"  exists (select 'x' from sys_store_org tb where ta.orgguid=tb.deptguid and tb.storeguid="+"'"+guiContext.getStoreguid()+"'"+") ";
        String sql="select u.* from sys_user u,sys_store_org s where bizstate = 'Y' AND cardid = "+"'"+user.getCardId()+"'"+" and u.orgguid = s.deptguid AND s.storeguid = '"+guiContext.getStoreguid()+"'"
                +" and exists (select 'x' from sys_sotre_org_cabinet tb where  u.ORGGUID=tb.DEPTGUID AND TB.CABINETGUID="+"'"+CabinetGuid+"'"+" and tb.storeguid="+"'"+guiContext.getStoreguid()+"'"+") ";

        System.out.println("card:"+sql);
        List<Map> maps = commonMapper.queryList(sql);
        List<SysUser> userList = new ArrayList<SysUser>();
        for (Map map : maps) {
            SysUser sysUser = JSON.parseObject(JSON.toJSONString(map), SysUser.class);
            userList.add(sysUser);
        }
        logger.info("查询到的对象为2"+userList);
        if(CollectionUtils.isEmpty(userList)) {
            guiContext.setDooropenUser(null);
            return null;
        }

        guiContext.setDooropenUser(userList.get(0));
        return userList.get(0);
    }
    public synchronized SysUser findUserByFinger(SysUser user) {
        logger.info("SysUserService.findUser查询用户信息入参为:" + JSON.toJSONString(user));
        logger.info("sysMapper对象为"+sysUserMapper);
        //构建SysUser类型的通用查询对象
        String sql = " select ta.* from sys_user ta where  exists (select 'x' from sys_user_finger tb where ta.GUID=tb.userguid and tb.fingercd="+"'"+user.getFingerprint()+"'"+" and tb.groupcode='"+cabinetGroupCode+"'"
        +" and ta.bizstate='Y' and ta.ORGGUID=tb.orgguid  and tb.storeguid="+"'"+guiContext.getStoreguid()+"'"+") ";
        logger.info(sql);
        List<Map> maps = commonMapper.queryList(sql);
        //logger.info("sql"+sql);
        List<SysUser> sysUserList = new ArrayList<SysUser>();
        for (Map map : maps) {
            SysUser sysUser = JSON.parseObject(JSON.toJSONString(map), SysUser.class);
            sysUserList.add(sysUser);
        }
        logger.info("usercou"+sysUserList.size());
        if(sysUserList.size()>0)
        {return sysUserList.get(0);}
        else
            {return null;}
    }

    //增加科室与柜子对应关系处理   YYQ 202/09/09
    public synchronized SysUser findUserByFinger(SysUser user,String CabinetGuid) {
        logger.info("SysUserService.findUser查询用户信息入参为:" + JSON.toJSONString(user));
        logger.info("sysMapper对象为"+sysUserMapper);
        //构建SysUser类型的通用查询对象
        String sql = " select ta.* from sys_user ta where  exists (select 'x' from sys_user_finger tb where ta.GUID=tb.userguid and tb.fingercd="+"'"+user.getFingerprint()+"'"+" and tb.groupcode='"+cabinetGroupCode+"'"
                +" and ta.bizstate='Y' and ta.ORGGUID=tb.orgguid  and tb.storeguid="+"'"+guiContext.getStoreguid()+"'"+") "
                +" and exists (select 'x' from sys_sotre_org_cabinet tb where  ta.ORGGUID=tb.DEPTGUID AND TB.CABINETGUID="+"'"+CabinetGuid+"'"+" and tb.storeguid="+"'"+guiContext.getStoreguid()+"'"+") ";
        List<Map> maps = commonMapper.queryList(sql);
        logger.info("sql:"+sql);
        List<SysUser> sysUserList = new ArrayList<SysUser>();
        for (Map map : maps) {
            SysUser sysUser = JSON.parseObject(JSON.toJSONString(map), SysUser.class);
            sysUserList.add(sysUser);
        }
        logger.info("usercou"+sysUserList.size());
        if(sysUserList.size()>0)
        {return sysUserList.get(0);}
        else
        {return null;}
    }
    public synchronized int updateFingerTextByGuid(SysUser user){
        logger.info("SysUserService.updateFingerTextByGuid更新指纹信息入参为:" + JSON.toJSONString(user));
        SysUserFinger userFinger=new SysUserFinger();
        SysUser sysUser=sysUserMapper.selectByPrimaryKey(user.getGuid());

        userFinger.setGuid(IdUtils.getUUID());
        userFinger.setStoreguid(guiContext.getStoreguid());
        userFinger.setStorename(guiContext.getStorename());
        userFinger.setOrgguid(sysUser.getOrgguid());
        SysOrg sysOrg=sysOrgMapper.selectByPrimaryKey(sysUser.getOrgguid());
        userFinger.setOrgname(sysOrg.getOrgname());
        userFinger.setFingercd(user.getFingerprint().trim());
        userFinger.setGroupcode(cabinetGroupCode);
        userFinger.setUserguid(user.getGuid());
        userFinger.setUsername(sysUser.getRealname());
        userFinger.setCreatetime(DateTime.now());

        int count=sysUserFingerMapper.insert(userFinger);
         count = sysUserMapper.updateByPrimaryKeySelective(user);
        return count;
    }
    public synchronized SysUser findUserByCheck(String cardid) {
        logger.info("返回用户卡号信息:" + cardid);

        //构建SysUser类型的通用查询对象
        Example example = new Example(SysUser.class);

        example.createCriteria().andEqualTo("cardId", cardid);

        List<SysUser> userList = sysUserMapper.selectByExample(example);
        logger.info("查询到的对象为3"+userList);
        if(CollectionUtils.isEmpty(userList)) {
            return null;
        }
        return userList.get(0);
    }
}