|
@@ -0,0 +1,191 @@
|
|
|
+package com.huimv.manager.modular.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.huimv.manager.enums.AdminTypeEnum;
|
|
|
+import com.huimv.manager.enums.AuthExceptionEnum;
|
|
|
+import com.huimv.manager.exception.AuthException;
|
|
|
+import com.huimv.manager.exception.RRException;
|
|
|
+import com.huimv.manager.modular.entity.MobileUser;
|
|
|
+import com.huimv.manager.modular.repository.MobileUnitRepository;
|
|
|
+import com.huimv.manager.modular.repository.MobileUserRepository;
|
|
|
+import com.huimv.manager.modular.service.MobileUserService;
|
|
|
+import com.huimv.manager.result.R;
|
|
|
+import com.huimv.manager.result.Result;
|
|
|
+import com.huimv.manager.result.ResultStatus;
|
|
|
+import com.huimv.manager.util.JwtUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.DigestUtils;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author yinhao
|
|
|
+ * @Date 2021/4/19 18:11
|
|
|
+ * @Description
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class MobileUserServiceImpl implements MobileUserService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MobileUserRepository mobileUserRepository;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R login(String account, String password, String code) {
|
|
|
+// String account = loginParam.getAccount();
|
|
|
+// String password = loginParam.getPassword();
|
|
|
+ if (StringUtils.isEmpty(code)) {
|
|
|
+ throw new AuthException(AuthExceptionEnum.CONSTANT_EMPTY_ERROR);
|
|
|
+ }
|
|
|
+ if (ObjectUtil.hasEmpty(account, password)) {
|
|
|
+ throw new AuthException(AuthExceptionEnum.ACCOUNT_PWD_EMPTY);
|
|
|
+ }
|
|
|
+
|
|
|
+ MobileUser mobileUser = mobileUserRepository.findByAccount(account);
|
|
|
+ if (mobileUser == null) {
|
|
|
+ throw new AuthException(AuthExceptionEnum.ACCOUNT_PWD_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!mobileUser.getGrantClass().equals(AdminTypeEnum.ADMIN.getCode())) {
|
|
|
+ throw new RRException("对不起,你不是管理员,不能登录此系统!", 401);
|
|
|
+ }
|
|
|
+
|
|
|
+ String inputPwdMd5 = DigestUtils.md5DigestAsHex(password.getBytes());
|
|
|
+ if (!inputPwdMd5.equals(mobileUser.getPassword())) {
|
|
|
+ throw new AuthException(AuthExceptionEnum.ACCOUNT_PWD_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ String token = JwtUtils.getJwtToken(mobileUser.getId());
|
|
|
+ mobileUser.setPassword("");
|
|
|
+ return Objects.requireNonNull(R.ok().put("token", token)).put("mobileUser", mobileUser);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ MobileUnitRepository mobileUnitRepository;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result add(MobileUser entity){
|
|
|
+
|
|
|
+
|
|
|
+ if (entity == null){
|
|
|
+ return new Result(10002, ResultStatus.addNull);
|
|
|
+ }
|
|
|
+
|
|
|
+ String account = entity.getAccount();
|
|
|
+ MobileUser mobileUser = mobileUserRepository.findByAccount(account);
|
|
|
+ if (mobileUser != null) {
|
|
|
+ return new Result(10001,"账号已存在,添加失败!");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ String ycgApi = mobileUnitRepository.findByShortNameLike("油车港").get(0).getApi();
|
|
|
+ String wyApi = mobileUnitRepository.findByShortNameLike("武义").get(0).getApi();
|
|
|
+ String wjjApi = mobileUnitRepository.findByShortNameLike("王江泾").get(0).getApi();
|
|
|
+
|
|
|
+ entity.setPassword(DigestUtils.md5DigestAsHex("123456".getBytes()));
|
|
|
+ mobileUserRepository.save(entity);
|
|
|
+
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ Integer id = mobileUserRepository.findID();
|
|
|
+ Integer grantClass = entity.getGrantClass();
|
|
|
+
|
|
|
+ if (grantClass ==null){
|
|
|
+ return new Result(10000,"msg");
|
|
|
+ }
|
|
|
+ Long start = System.currentTimeMillis();
|
|
|
+
|
|
|
+ restTemplate.getForEntity(ycgApi+"/video/mobileUser/register?account="+start+"&id="+id+"&password=123456",null);
|
|
|
+ restTemplate.getForEntity(wyApi+"/video/mobileUser/register?account="+start+"&id="+id+"&password=123456",null);
|
|
|
+ restTemplate.getForEntity(wjjApi+"/video/mobileUser/register?account="+start+"&id="+id+"&password=123456",null);
|
|
|
+
|
|
|
+ return new Result(10000,ResultStatus.addSuccess);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error(e.getMessage(),e);
|
|
|
+ return new Result(10001,ResultStatus.addFailed);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result remove(Integer[] ids) {
|
|
|
+ if (ids == null || ids.length==0){
|
|
|
+ return new Result(10002,ResultStatus.deleteNull);
|
|
|
+ }
|
|
|
+ String ycgApi = mobileUnitRepository.findByShortNameLike("油车港").get(0).getApi();
|
|
|
+ String wyApi = mobileUnitRepository.findByShortNameLike("武义").get(0).getApi();
|
|
|
+ String wjjApi = mobileUnitRepository.findByShortNameLike("王江泾").get(0).getApi();
|
|
|
+
|
|
|
+
|
|
|
+// RestTemplate restTemplate = new RestTemplate();
|
|
|
+// restTemplate.getForEntity(wjjApi+"/video/mobileUser/remove?ids="+ids,null);
|
|
|
+// restTemplate.getForEntity(wyApi+"/video/mobileUser/remove?ids="+ids,null);
|
|
|
+// restTemplate.getForEntity(ycgApi+"/video/mobileUser/remove?ids="+ids,null);
|
|
|
+
|
|
|
+
|
|
|
+ try {
|
|
|
+ for (Integer id : ids) {
|
|
|
+ mobileUserRepository.deleteById(id);
|
|
|
+ }
|
|
|
+ return new Result(10000,ResultStatus.deleteSuccess);
|
|
|
+ }catch (Exception e){
|
|
|
+ return new Result(10001,ResultStatus.deleteFailed);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result update(MobileUser entity) {
|
|
|
+ if (entity == null){
|
|
|
+ return new Result(10002,ResultStatus.updateNull);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ mobileUserRepository.save(entity);
|
|
|
+ return new Result(10000,ResultStatus.updateSuccess);
|
|
|
+ }catch (Exception e){
|
|
|
+ return new Result(10001,ResultStatus.updateFailed);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result findAll(String name , Integer pageNum , Integer pageSize) {
|
|
|
+ try {
|
|
|
+ Map map = new HashMap();
|
|
|
+ int size = mobileUserRepository.findAll().size() ;
|
|
|
+ Integer startPage = (pageNum-1) * pageSize;
|
|
|
+ List<MobileUser> all = mobileUserRepository.findAll(name,startPage,pageSize);
|
|
|
+ map.put("total",size);
|
|
|
+ map.put("totalPageNum",(size + pageSize - 1) / pageSize);
|
|
|
+ map.put("data",all);
|
|
|
+
|
|
|
+ return new Result(10000,ResultStatus.findSuccess,map);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error(e.getMessage(),e);
|
|
|
+ return new Result(10001,ResultStatus.findFailed,null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result findAllById(Integer id) {
|
|
|
+ try {
|
|
|
+ MobileUser entity = mobileUserRepository.findById(id).get();
|
|
|
+ return new Result(10000,ResultStatus.findSuccess,entity);
|
|
|
+ }catch (Exception e){
|
|
|
+ return new Result(10001,ResultStatus.findFailed,null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public MobileUser findById(Integer id) {
|
|
|
+ return mobileUserRepository.findById(id).orElse(null);
|
|
|
+ }
|
|
|
+}
|