package com.xzx.gc.user.service;
|
|
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.convert.Convert;
|
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageInfo;
|
import com.xzx.gc.common.exception.RestException;
|
import com.xzx.gc.entity.AccountInfo;
|
import com.xzx.gc.entity.JhyInfo;
|
import com.xzx.gc.entity.ScoreDetails;
|
import com.xzx.gc.user.dto.*;
|
import com.xzx.gc.user.mapper.AccountMapper;
|
import com.xzx.gc.user.mapper.JhyInfoMapper;
|
import com.xzx.gc.user.vo.GetScoreNumVo;
|
import com.xzx.gc.user.vo.JhyInfoListVo;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import tk.mybatis.mapper.entity.Example;
|
|
import java.math.BigDecimal;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
@Slf4j
|
@Service
|
@Transactional
|
public class JhyInfoService {
|
|
@Autowired
|
private JhyInfoMapper jhyInfoMapper;
|
@Autowired
|
private AccountMapper accountMapper;
|
|
public void applyJhy(JhyApplyDto applyDto) {
|
JhyInfo mobileIsExist = jhyInfoMapper.selectExistJhyByIndeityOrMobile(applyDto.getMobile(), applyDto.getIdentity());
|
if (mobileIsExist != null) {
|
if (applyDto.getUserId().equals(mobileIsExist.getUserId())) {
|
throw new RestException(-3, "审核中或审核成功, 请勿重复提交");
|
}
|
|
throw new RestException(-3, "手机号/身份证号已注册集物员");
|
}
|
|
jhyInfoMapper.deleteByUserId(applyDto.getUserId());
|
|
log.info("图片地址:{}", applyDto.getCardPos());
|
JhyInfo jhyInfo = new JhyInfo();
|
BeanUtil.copyProperties(applyDto, jhyInfo);
|
jhyInfo.setCreatedTime(new Date());
|
jhyInfo.setIsJhy(JhyInfo.IS_JHY_N);
|
jhyInfo.setCardPos(applyDto.getCardPos());
|
jhyInfo.setStatus(JhyInfo.CHECK_WAIT);
|
jhyInfoMapper.insert(jhyInfo);
|
}
|
|
public int applyStatus(String userId) {
|
JhyInfo jhyInfo = jhyInfoMapper.selectJhyInfoByUserId(userId);
|
if (jhyInfo == null) {
|
return 0;
|
}
|
|
return jhyInfo.getStatus();
|
}
|
|
public int isJhy(String userId) {
|
JhyInfo jhyInfo = jhyInfoMapper.selectJhyInfoByUserId(userId);
|
if (jhyInfo == null) {
|
return 0;
|
}
|
|
if (JhyInfo.CHECK_REFUSE.equals(jhyInfo.getStatus())) {
|
return 0;
|
}
|
|
if (JhyInfo.CHECK_PASS.equals(jhyInfo.getStatus())) {
|
return 1;
|
} else {
|
return 2;
|
}
|
}
|
|
public Map<String, Object> queryList(JhyInfoListDto jhyInfoListDto) {
|
PageHelper.startPage(jhyInfoListDto.getPage(), jhyInfoListDto.getLimit());
|
List<JhyInfoListVo> jhyInfoListVos = jhyInfoMapper.selectJhyInfoList(jhyInfoListDto);
|
PageInfo<JhyInfoListVo> pageInfo = new PageInfo<>(jhyInfoListVos);
|
|
Map<String, Object> data = new HashMap<>();
|
int count = Convert.toInt(pageInfo.getTotal());
|
data.put("data", jhyInfoListVos);
|
data.put("count", count);
|
data.put("code", 0);
|
return data;
|
}
|
|
public void examineJwy(ExamineJwyDto model) {
|
long id = model.getId();
|
JhyInfo jhyInfo = jhyInfoMapper.selectByPrimaryKey(id);
|
Integer type = model.getType();
|
if(1 == type){
|
jhyInfo.setStatus(2);
|
jhyInfo.setIsJhy(1+"");
|
}else if(2 == type){
|
jhyInfo.setStatus(3);
|
jhyInfo.setIsJhy(2+"");
|
}
|
jhyInfoMapper.updateByPrimaryKey(jhyInfo);
|
}
|
|
public void addScoreNum(AddScoreNumDto model) {
|
Example exampleAccount = new Example(AccountInfo.class);
|
Example.Criteria criteriaAccount = exampleAccount.createCriteria();
|
criteriaAccount.andEqualTo("userId",model.getUserId());
|
List<AccountInfo> accountInfos = accountMapper.selectByExample(exampleAccount);
|
if(CollUtil.isNotEmpty(accountInfos)){
|
AccountInfo accountInfo = accountInfos.get(0);
|
Integer collectScore = Integer.parseInt(accountInfo.getCollectScore());
|
// collectScore = collectScore + model.getScore();
|
accountInfo.setCollectScore(model.getScore().toString());
|
accountMapper.updateByPrimaryKey(accountInfo);
|
|
ScoreDetails scoreDetailsRet = new ScoreDetails();
|
scoreDetailsRet.setUserId(model.getUserId());
|
scoreDetailsRet.setType(ScoreDetails.SCORE_TYPE_ADMIN_RECHARGE);
|
scoreDetailsRet.setOriginalScore(new BigDecimal(collectScore));
|
scoreDetailsRet.setCurrentScore(new BigDecimal(model.getScore()));
|
scoreDetailsRet.setChangeScore(new BigDecimal(model.getScore()));
|
scoreDetailsRet.setCreatedTime(new Date());
|
accountMapper.insertScoreDetailsRet(scoreDetailsRet);
|
}
|
}
|
|
public GetScoreNumVo getScoreNum(GetScoreNumDto model) {
|
GetScoreNumVo getScoreNumVo = new GetScoreNumVo();
|
Example exampleAccount = new Example(AccountInfo.class);
|
Example.Criteria criteriaAccount = exampleAccount.createCriteria();
|
criteriaAccount.andEqualTo("userId",model.getUserId());
|
List<AccountInfo> accountInfos = accountMapper.selectByExample(exampleAccount);
|
if(CollUtil.isNotEmpty(accountInfos)){
|
AccountInfo accountInfo = accountInfos.get(0);
|
Integer collectScore = Integer.parseInt(accountInfo.getCollectScore());
|
getScoreNumVo.setScore(new BigDecimal(collectScore));
|
}
|
return getScoreNumVo;
|
}
|
}
|