kitt.admin.service.UserService.java Source code

Java tutorial

Introduction

Here is the source code for kitt.admin.service.UserService.java

Source

package kitt.admin.service;

import kitt.admin.basic.exception.BusinessException;
import kitt.core.domain.*;
import kitt.core.persistence.CompanyMapper;
import kitt.core.persistence.UserMapper;

import kitt.core.service.*;

import kitt.core.service.CODE;
import kitt.core.service.MessageNotice;
import kitt.core.service.SMS;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

/**
 * Created by yimei on 15/7/27.
 */
@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private SMS sms;
    @Autowired
    private CODE code;
    @Autowired
    private CompanyMapper companyMapper;
    @Autowired
    private Session session;

    /**
     * ??
     * @param securephone   ?
     * @return              true or false
     * @throws Exception
     */
    @Transactional
    public boolean doResetPasswordMethod(String securephone) throws Exception {
        String randompwd = code.CreateCode();
        if (userMapper.modifyPasswdByPhone(DigestUtils.md5Hex(randompwd), securephone) == 1) {
            MessageNotice.CommonMessage.noticeUser(securephone, "??" + randompwd);
            return true;
        }
        throw new BusinessException("?????");
    }

    /**
     * ?? ?
     * @param user   
     * @return       success: true or false
     * @return       isactive: ?
     */
    @Transactional
    public Object doDisableEnableAccountMethod(User user) {
        int rows;
        if (user.isIsactive()) {
            rows = userMapper.editUserAccount(false, user.getSecurephone());
        } else {
            rows = userMapper.editUserAccount(true, user.getSecurephone());
        }
        if (rows == 1) {
            boolean activeStatus = userMapper.getUserById(user.getId()).isIsactive();
            return new Object() {
                public boolean isactive = activeStatus;
                public boolean success = true;
            };
        }
        throw new BusinessException("????");
    }

    @Autowired
    private MySupplyerService mySupplyerService;

    /**
     * ?? -- 
     * @param company   ?
     * @param remarks   
     * @return          true or false
     */
    @Transactional
    public boolean doCompanyVerifyPassMethod(Company company, String remarks) {
        CompanyVerify companyVerify = companyMapper.getTheLatestCompanyVerifyByCompanyIdUserIdStatus(
                company.getId(), company.getUserid(), "");
        if (companyVerify != null) {
            String status = EnumCommonString.VerifyPass.value();
            int row1 = companyMapper.setCompVerify(status, session.getAdmin().getUsername(), LocalDateTime.now(),
                    remarks, company.getId(), companyVerify.getId());
            int row2 = companyMapper.setCompanyStatus(status, remarks, company.getId());
            int row3 = userMapper.setUserVerifyStatus(status, LocalDateTime.now(), company.getUserid());
            int row4 = companyMapper.addCompVerSus(new CompVerSus(company.getName(), company.getAddress(),
                    company.getPhone(), company.getFax(), company.getLegalperson(), company.getBusinesslicense(),
                    company.getIdentificationnumber(), company.getOrganizationcode(), company.getOperatinglicense(),
                    company.getUserid(), company.getLegalpersonname(), company.getAccount(),
                    company.getOpeningbank()));
            if (row1 == 1 && row2 == 1 && row3 == 1 && row4 == 1) {
                String phone = userMapper.getUserById(company.getUserid()).getSecurephone();
                final String content = "??????";
                MessageNotice.CommonMessage.noticeUser(phone, content);
                //?
                mySupplyerService.auditSupplyer(phone);
                return true;
            }
        }
        throw new BusinessException("???");

    }

    /**
     * ?? -- ?
     * @param company   ?
     * @param remarks   
     * @return          true of false
     */
    @Transactional
    public boolean doCompanyVerifyNotPassMethod(Company company, String remarks) {
        CompanyVerify companyVerify = companyMapper.getTheLatestCompanyVerifyByCompanyIdUserIdStatus(
                company.getId(), company.getUserid(), "");
        if (companyVerify != null) {
            String status = EnumCommonString.VerifyNotPass.value();
            int row1 = companyMapper.setCompVerify(status, session.getAdmin().getUsername(), LocalDateTime.now(),
                    remarks, company.getId(), companyVerify.getId());
            int row2 = companyMapper.setCompanyStatus(status, remarks, company.getId());
            int row3 = userMapper.setUserVerifyStatus(status, LocalDateTime.now(), company.getUserid());
            if (row1 == 1 && row2 == 1 && row3 == 1) {
                String phone = userMapper.getUserById(company.getUserid()).getSecurephone();
                final String content = "????:" + remarks
                        + ", ?400-960-1180";
                MessageNotice.CommonMessage.noticeUser(phone, content);
                return true;
            }
        }
        throw new BusinessException("???");
    }

    /**
     * ???? ??
     * @param companyc    ? companyc   ?? companyc ? ??
     * @param company     ?
     * @return            true or false
     */
    @Transactional
    public boolean doSaveCompanyInfoMethod(Company companyc, Company company, int userid) {
        int row1;
        if (companyc == null) {
            row1 = companyMapper.addCompany(company);
        } else {
            row1 = companyMapper.modifyCompany(company);
        }
        int row2 = companyMapper.setCompanyStatus("", null, companyMapper.getIdByUserid(userid));
        int row3 = companyMapper.addCompVerify(
                new CompanyVerify("", LocalDateTime.now(), companyMapper.getIdByUserid(userid), userid,
                        "?id=" + session.getAdmin().getId() + ", ??="
                                + session.getAdmin().getUsername() + ", ??="
                                + session.getAdmin().getJobnum()));
        int row4 = userMapper.setUserVerifyStatus("", null, userid);
        if (row1 == 1 && row2 == 1 && row3 == 1 && row4 == 1) {
            mySupplyerService.updateSupplyerForAuditCompanies(company);
            return true;
        }
        throw new BusinessException("??????");
    }

    /**
     * 
     * @param id                  usersid
     * @param traderid            idadmins id
     */
    @Transactional
    public boolean doAddUpdateUserTraderMethod(int id, int traderid) {
        return userMapper.doAddUpdateUserTraderMethod(id, traderid);
    }
}