This commit is contained in:
PQZ 2024-09-27 14:37:45 +08:00
commit 90d46c0cc7
25 changed files with 708 additions and 69 deletions

View File

@ -0,0 +1,38 @@
package cn.iocoder.yudao.module.app.banner.controller;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.banner.service.DlBaseBannerService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
/**
* 取banner
*
* @author 小李
* @date 11:05 2024/9/27
**/
@RestController
@RequestMapping("/userClient/banner")
public class BannerAPI {
@Resource
private DlBaseBannerService baseBannerService;
/**
* 不同小程序用不同的banner用type分
*
* @author 小李
* @date 11:07 2024/9/27
* @param type type
**/
@GetMapping("/get")
public CommonResult<?> getBannerByType(@RequestParam("type") String type) {
return success(baseBannerService.getBannerByType(type));
}
}

View File

@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.app.customer;
import cn.iocoder.yudao.framework.common.exception.ServiceException;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.custom.service.CustomerMainService;
import cn.iocoder.yudao.module.custom.vo.CustomerMainSaveReqVO;
import cn.iocoder.yudao.module.system.api.user.dto.UserDTO;
@ -50,6 +52,9 @@ public class CustomerAPI {
@PostMapping("/register")
@Operation(summary = "客户自行注册")
public CommonResult<?> createCustomerMain(@Valid @RequestBody CustomerMainSaveReqVO saveReqVO, HttpServletRequest request) {
// 获取当前登录用户
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
saveReqVO.setUserId(loginUser.getId());
//客户类型统一为私人客户
saveReqVO.setTypeCode("01");
//客户来源统一为04-维修
@ -59,7 +64,7 @@ public class CustomerAPI {
try {
UserDTO userDTO = customerMainService.saveCustomer(saveReqVO,SIGN_CREATE);
//注册并登录
return success(loginService.wxLoginByUserId(userDTO.getId(),userDTO.getUsername()));
return success(userDTO);
}catch (ServiceException e){
return error(e);
}

View File

@ -0,0 +1,84 @@
package cn.iocoder.yudao.module.banner.controller.admin;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.banner.entity.DlBaseBanner;
import cn.iocoder.yudao.module.banner.service.DlBaseBannerService;
import cn.iocoder.yudao.module.banner.vo.DlBannerReqVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
/**
* banner图基础库(DlBaseBanner)表控制层
*
* @author makejava
* @since 2024-09-27 09:09:08
*/
@RestController
@RequestMapping("/base/banner")
public class DlBaseBannerController {
/**
* 服务对象
*/
@Resource
private DlBaseBannerService dlBaseBannerService;
/**
* 分页查询
*
* @author 小李
* @date 9:17 2024/9/27
* @param bannerReqVO 查询对象
* @param pageNo 页码
* @param pageSize 条数
**/
@GetMapping("/page")
public CommonResult<?> queryByPage(DlBannerReqVO bannerReqVO,
@RequestParam(value = "pageNo", defaultValue = "1")Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize) {
Page<DlBaseBanner> page = new Page<>(pageNo, pageSize);
return success(dlBaseBannerService.queryByPage(bannerReqVO, page));
}
/**
* 新增修改
*
* @author 小李
* @date 9:23 2024/9/27
* @param bannerReqVO 请求对象
**/
@PostMapping("/update")
public CommonResult<?> updateBanner(@RequestBody DlBannerReqVO bannerReqVO) {
dlBaseBannerService.updateBanner(bannerReqVO);
return CommonResult.ok();
}
/**
* 通过主键查询单条数据
*
* @author 小李
* @date 9:25 2024/9/27
* @param id 记录ID
**/
@GetMapping("/get")
public CommonResult<?> getBannerById(@RequestParam("id") String id) {
return success(dlBaseBannerService.getBannerById(id));
}
/**
* 删除数据
*
* @author 小李
* @date 9:28 2024/9/27
* @param id 记录ID
**/
@DeleteMapping("/remove")
public CommonResult<?> deleteBannerById(@RequestParam("id") String id) {
dlBaseBannerService.deleteBannerById(id);
return CommonResult.ok();
}
}

View File

@ -0,0 +1,48 @@
package cn.iocoder.yudao.module.banner.entity;
import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* banner图基础库
*
* @author 小李
* @date 9:09 2024/9/27
**/
@TableName(value ="dl_base_banner")
@Data
@EqualsAndHashCode(callSuper = true)
public class DlBaseBanner extends TenantBaseDO {
/**
* 主键标识
*/
@TableId(type = IdType.ASSIGN_ID)
private String id;
/**
* 图片名称
*/
private String title;
/**
* 图片地址
*/
private String url;
/**
* 图片顺序
*/
private String sort;
/**
* 图片类别属于什么服务的表system_service_package表的id
*/
private String typeId;
/** 跳转链接 */
private String toUrl;
}

View File

@ -0,0 +1,32 @@
package cn.iocoder.yudao.module.banner.mapper;
import cn.iocoder.yudao.module.banner.entity.DlBaseBanner;
import cn.iocoder.yudao.module.banner.vo.DlBannerReqVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* 针对表dl_base_banner(banner图基础库)的数据库操作Mapper
*
* @author 小李
* @date 9:11 2024/9/27
**/
@Mapper
public interface DlBaseBannerMapper extends BaseMapper<DlBaseBanner> {
/**
* 分页查询
*
* @author 小李
* @date 9:17 2024/9/27
* @param bannerReqVO 查询对象
**/
IPage<DlBaseBanner> queryByPage(@Param("map") DlBannerReqVO bannerReqVO, Page<DlBaseBanner> page);
}

View File

@ -0,0 +1,63 @@
package cn.iocoder.yudao.module.banner.service;
import cn.iocoder.yudao.module.banner.entity.DlBaseBanner;
import cn.iocoder.yudao.module.banner.vo.DlBannerReqVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* 针对表dl_base_banner(banner图基础库)的数据库操作Service
*
* @author 小李
* @date 9:12 2024/9/27
**/
public interface DlBaseBannerService extends IService<DlBaseBanner> {
/**
* 分页查询
*
* @author 小李
* @date 9:17 2024/9/27
* @param bannerReqVO 查询对象
**/
IPage<DlBaseBanner> queryByPage(DlBannerReqVO bannerReqVO, Page<DlBaseBanner> page);
/**
* 新增修改
*
* @author 小李
* @date 9:23 2024/9/27
* @param bannerReqVO 请求对象
**/
void updateBanner(DlBannerReqVO bannerReqVO);
/**
* 通过主键查询单条数据
*
* @author 小李
* @date 9:25 2024/9/27
* @param id 记录ID
**/
DlBaseBanner getBannerById(String id);
/**
* 删除数据
*
* @author 小李
* @date 9:28 2024/9/27
* @param id 记录ID
**/
void deleteBannerById(String id);
/**
* 不同小程序用不同的banner用type分
*
* @author 小李
* @date 11:07 2024/9/27
* @param type type
**/
List<DlBaseBanner> getBannerByType(String type);
}

View File

@ -0,0 +1,91 @@
package cn.iocoder.yudao.module.banner.service.impl;
import cn.iocoder.yudao.module.banner.entity.DlBaseBanner;
import cn.iocoder.yudao.module.banner.mapper.DlBaseBannerMapper;
import cn.iocoder.yudao.module.banner.service.DlBaseBannerService;
import cn.iocoder.yudao.module.banner.vo.DlBannerReqVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
/**
* 针对表dl_base_banner(banner图基础库)的数据库操作Service实现
*
* @author 小李
* @date 9:21 2024/9/27
**/
@Service
public class DlBaseBannerServiceImpl extends ServiceImpl<DlBaseBannerMapper, DlBaseBanner>
implements DlBaseBannerService {
/**
* 分页查询
*
* @param bannerReqVO 查询对象
* @author 小李
* @date 9:17 2024/9/27
**/
@Override
public IPage<DlBaseBanner> queryByPage(DlBannerReqVO bannerReqVO, Page<DlBaseBanner> page) {
return baseMapper.queryByPage(bannerReqVO, page);
}
/**
* 新增修改
*
* @param bannerReqVO 请求对象
* @author 小李
* @date 9:23 2024/9/27
**/
@Override
public void updateBanner(DlBannerReqVO bannerReqVO) {
baseMapper.insertOrUpdate(bannerReqVO);
}
/**
* 通过主键查询单条数据
*
* @param id 记录ID
* @author 小李
* @date 9:25 2024/9/27
**/
@Override
public DlBaseBanner getBannerById(String id) {
return baseMapper.selectById(id);
}
/**
* 删除数据
*
* @param id 记录ID
* @author 小李
* @date 9:28 2024/9/27
**/
@Override
public void deleteBannerById(String id) {
baseMapper.deleteById(id);
}
/**
* 不同小程序用不同的banner用type分
*
* @param type type
* @author 小李
* @date 11:07 2024/9/27
**/
@Override
public List<DlBaseBanner> getBannerByType(String type) {
List<DlBaseBanner> dlBaseBanners = baseMapper.selectList(new LambdaQueryWrapper<DlBaseBanner>().eq(DlBaseBanner::getTypeId, type));
return dlBaseBanners.stream().sorted(Comparator.comparing(DlBaseBanner::getSort)).collect(Collectors.toList());
}
}

View File

@ -0,0 +1,14 @@
package cn.iocoder.yudao.module.banner.vo;
import cn.iocoder.yudao.module.banner.entity.DlBaseBanner;
import lombok.Data;
/**
* banner图基础库 请求VO
*
* @author 小李
* @date 9:11 2024/9/27
**/
@Data
public class DlBannerReqVO extends DlBaseBanner {
}

View File

@ -0,0 +1,14 @@
package cn.iocoder.yudao.module.banner.vo;
import cn.iocoder.yudao.module.banner.entity.DlBaseBanner;
import lombok.Data;
/**
* banner图基础库 响应VO
*
* @author 小李
* @date 9:11 2024/9/27
**/
@Data
public class DlBannerRespVO extends DlBaseBanner {
}

View File

@ -176,7 +176,7 @@ public class CompanyController {
@GetMapping("/list")
@Operation(summary = "获得企业信息表(每个租户的下属企业信息)")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('company:property-deal:query')")
// @PreAuthorize("@ss.hasPermission('company:property-deal:query')")
public CommonResult<List<Company>> getCompanyList(){
return success(companyService.list());
}

View File

@ -33,6 +33,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@ -221,10 +222,14 @@ public class CustomerMainServiceImpl extends ServiceImpl<CustomerMainMapper, Cus
**/
@Override
public CustomerMainRespVO getUserCustomer() {
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
LambdaQueryWrapper<CustomerMain> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(CustomerMain::getUserId,loginUser.getId()).eq(BaseDO::getDeleted,'0');
CustomerMain customerMain = getOne(lambdaQueryWrapper);
if (ObjectUtils.isEmpty(customerMain)){
return null;
}
return getCustomerById(customerMain.getId());
}

View File

@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.company.service.CompanyService;
import cn.iocoder.yudao.module.custom.service.CustomerBalanceService;
@ -15,10 +16,15 @@ import cn.iocoder.yudao.module.order.vo.*;
import cn.iocoder.yudao.module.order.vo.RepairOrderInfoPageReqVO;
import cn.iocoder.yudao.module.order.vo.RepairOrderInfoRespVO;
import cn.iocoder.yudao.module.order.vo.RepairOrderInfoSaveReqVO;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import cn.iocoder.yudao.module.tickets.entity.Tickets;
import cn.iocoder.yudao.module.tickets.service.TicketsService;
import cn.iocoder.yudao.util.WechatPayConfig;
import cn.iocoder.yudao.util.WechatPayRequest;
import cn.iocoder.yudao.util.WechatPayUrlEnum;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
@ -26,12 +32,17 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.io.IOException;
import java.math.BigDecimal;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SignatureException;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@ -61,6 +72,8 @@ public class RepairOrderInfoServiceImpl extends ServiceImpl<RepairOrderInfoMappe
private WechatPayRequest wechatPayRequest;
@Resource
private TicketsService ticketsService;
@Autowired
private AdminUserService userService;
/**
@ -217,23 +230,41 @@ public class RepairOrderInfoServiceImpl extends ServiceImpl<RepairOrderInfoMappe
*/
@Override
public Map<String,Object> payTransactions(String orderId){
RepairOrderInfo orderInfo = this.getById(orderId);
AdminUserDO user = userService.getUser(orderInfo.getUserId());
// 统一参数封装
Map<String, Object> params = new HashMap<>(8);
params.put("appid", wechatPayConfig.getAppId());
params.put("appid", wechatPayConfig.getRepairAppId());
params.put("mchid", wechatPayConfig.getMchId());
params.put("description", orderInfo.getPayRemark());
params.put("description", "汽修业务");
params.put("out_trade_no", orderInfo.getOrderNo());
params.put("notify_url", wechatPayConfig.getRepairNotifyUrl());
Map<String, Object> amountMap = new HashMap<>(4);
// 金额单位为分
amountMap.put("total", orderInfo.getPayMoney().multiply(BigDecimal.valueOf(100L)).intValue());
amountMap.put("total", orderInfo.getPayMoney().multiply(BigDecimal.valueOf(100L)).longValue());
//人民币
amountMap.put("currency", "CNY");
params.put("amount", amountMap);
// 场景信息
Map<String, Object> sceneInfoMap = new HashMap<>(4);
// 客户端IP
sceneInfoMap.put("payer_client_ip", "127.0.0.1");
// 商户端设备号门店号或收银设备ID
sceneInfoMap.put("device_id", "127.0.0.1");
// 除H5与JSAPI有特殊参数外其他的支付方式都一样
Map<String, Object> payerMap = new HashMap<>(4);
payerMap.put("openid", user.getOpenId());
params.put("payer", payerMap);
params.put("scene_info", sceneInfoMap);
String paramsStr = JSON.toJSONString(params);
String resStr = wechatPayRequest.wechatHttpPost("https://api.mch.weixin.qq.com/v3/pay/transactions/native",paramsStr);
return JSONObject.parseObject(resStr, new TypeReference<Map<String, Object>>(){});
String resStr = wechatPayRequest.wechatHttpPost("https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi",paramsStr);
Map<String, Object> resMap = JSONObject.parseObject(resStr);
//Map<String, Object> signMap = paySignMsg(resMap.get("prepay_id").toString(), wechatPayConfig.getAppId(),null);
return resMap;
}
/**
@ -262,4 +293,24 @@ public class RepairOrderInfoServiceImpl extends ServiceImpl<RepairOrderInfoMappe
public RepairOrderCensusVO census(){
return baseMapper.census();
}
// private Map<String, Object> paySignMsg(String prepayId,String appId,String privateKeyStr) throws IOException, NoSuchAlgorithmException, InvalidKeyException, SignatureException {
// long timeMillis = System.currentTimeMillis();
// String timeStamp = timeMillis/1000+"";
// String nonceStr = timeMillis+"";
// String packageStr = "prepay_id="+prepayId;
// // 公共参数
// Map<String, Object> resMap = new HashMap<>();
// resMap.put("nonceStr",nonceStr);
// resMap.put("timeStamp",timeStamp);
// resMap.put("appId",appId);
// resMap.put("package", packageStr);
// // 使用字段appIdtimeStampnonceStrpackage进行签名
// //从下往上依次生成
// String message = buildMessage(appId, timeStamp, nonceStr, packageStr);
// //签名
// String paySign = sign(message.getBytes("utf-8"), privateKeyStr);
// resMap.put("paySign", paySign);
// resMap.put("signType", "RSA");
// return resMap;
// }
}

View File

@ -123,7 +123,7 @@ public class BaseSupplierController {
**/
@GetMapping("/list")
@Operation(summary = "获得所有供应商")
@PreAuthorize("@ss.hasPermission('supplier:base-supplier:query')")
// @PreAuthorize("@ss.hasPermission('supplier:base-supplier:query')")
public CommonResult<?> getBaseSupplierList(){
return success(baseSupplierService.list());
}

View File

@ -86,9 +86,10 @@ public class WechatPayConfig {
private String jcNotifyUrl="https://www.nuoyunr.com/admin-api/payApi/payNotify";
private String jcRefundNotifyUrl="https://www.nuoyunr.com/admin-api/payApi/refundNotify";
private String repairAppId="wxee677d54037bc5ac";
private String repairAppSecret="774bcddc165287da47b0b72b31f1c0a0";
/**
* 获取商户的私钥文件
* @param keyPemPath

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.banner.mapper.DlBaseBannerMapper">
<resultMap id="BaseResultMap" type="cn.iocoder.yudao.module.banner.entity.DlBaseBanner">
<id property="id" column="id" jdbcType="VARCHAR"/>
<result property="title" column="title" jdbcType="VARCHAR"/>
<result property="url" column="url" jdbcType="VARCHAR"/>
<result property="sort" column="sort" jdbcType="VARCHAR"/>
<result property="typeId" column="type_id" jdbcType="VARCHAR"/>
<result property="toUrl" column="to_url" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_SQL">
select id,
title,
url,
sort,
type_id,
to_url
from dl_base_banner dbb where dbb.deleted = '0'
</sql>
<select id="queryByPage" resultMap="BaseResultMap">
<include refid="Base_SQL" />
<if test="map.typeId != null and map.typeId != ''">
and dbb.type_id = #{map.typeId}
</if>
</select>
</mapper>

View File

@ -198,7 +198,7 @@ public class CompanyStaffController {
**/
@GetMapping("/list")
@Operation(summary = "获取当前登录用户部门下所有员工信息")
@PreAuthorize("@ss.hasPermission('company:staff:query')")
// @PreAuthorize("@ss.hasPermission('company:staff:query')")
public CommonResult<List<CompanyStaff>> getStaffList() {
return success(staffService.getStaffList());
}

View File

@ -0,0 +1,176 @@
package cn.iocoder.yudao.module.app.controller;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.common.CommonErrorCodeConstants;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.security.config.SecurityProperties;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.app.vo.WxLoginBody;
import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
import cn.iocoder.yudao.module.system.api.permission.PermissionApi;
import cn.iocoder.yudao.module.system.api.permission.RoleApi;
import cn.iocoder.yudao.module.system.api.permission.dto.RoleReqDTO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthLoginReqVO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthLoginRespVO;
import cn.iocoder.yudao.module.system.controller.admin.user.LoginBody;
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO;
import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.service.auth.AdminAuthService;
import cn.iocoder.yudao.module.system.service.permission.MenuService;
import cn.iocoder.yudao.module.system.service.permission.RoleService;
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import cn.iocoder.yudao.util.WechatPayConfig;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletRequest;
import java.security.spec.AlgorithmParameterSpec;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.*;
/**
* 登录验证
*
* @author ruoyi
*/
@RestController
@Slf4j
@RequestMapping("/userClient/repair")
public class LoginController {
@Resource
private AdminAuthService loginService;
@Resource
private WechatPayConfig wxConfig;
@Resource
private RestTemplate restTemplate;
@Resource
private SecurityProperties securityProperties;
@PostMapping("/wxLogin")
@TenantIgnore
public CommonResult wxLogin(@RequestBody WxLoginBody wxLoginBody) {
String code = wxLoginBody.getCode();
//秘钥
String encryptedIv = wxLoginBody.getEncryptedIv();
//加密数据
String encryptedData = wxLoginBody.getEncryptedData();
//想微信服务器发送请求获取用户信息
String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + wxConfig.getRepairAppId() + "&secret=" + wxConfig.getRepairAppSecret() + "&js_code=" + code + "&grant_type=authorization_code";
String res = restTemplate.getForObject(url, String.class);
JSONObject jsonObject = JSONObject.parseObject(res);
//获取session_key和openid
String sessionKey = jsonObject.getString("session_key");
String openId = jsonObject.getString("openid");
//解密
String decryptResult = "";
try {
//如果没有绑定微信开放平台解析结果是没有unionid的
decryptResult = decrypt(sessionKey, encryptedIv, encryptedData);
} catch (Exception e) {
e.printStackTrace();
return error(500, "微信登录失败!");
}
if (StringUtils.hasText(decryptResult)) {
//如果解析成功,获取token
AuthLoginRespVO loginVO = loginService.wxLoginJc(decryptResult,openId,wxLoginBody.getInviteId());
Map<String, Object> map = new HashMap<>();
map.put("token", loginVO.getAccessToken());
return success(map);
} else {
return error(500, "微信登录失败!");
}
}
@PostMapping("/logout")
@Operation(summary = "登出系统")
public CommonResult<Boolean> logout(HttpServletRequest request) {
String token = SecurityFrameworkUtils.obtainAuthorization(request,
securityProperties.getTokenHeader(), securityProperties.getTokenParameter());
if (StrUtil.isNotBlank(token)) {
loginService.logout(token,1);
}
return success(true);
}
/**
* AES解密
*/
private String decrypt(String sessionKey,String encryptedIv,String encryptedData) throws Exception{
// 转化为字节数组
byte[] key = Base64.decode(sessionKey);
byte[] iv = Base64.decode(encryptedIv);
byte[] encData = Base64.decode(encryptedData);
// 如果密钥不足16位那么就补足
int base =16;
if (key.length % base !=0) {
int groups = key.length / base +(key.length % base != 0 ? 1 : 0);
byte[] temp = new byte[groups * base];
Arrays.fill(temp,(byte) 0);
System.arraycopy(key,0,temp,0,key.length);
key = temp;
}
// 如果初始向量不足16位也补足
if (iv.length % base !=0) {
int groups = iv.length / base +(iv.length % base != 0 ? 1 : 0);
byte[] temp = new byte[groups * base];
Arrays.fill(temp,(byte) 0);
System.arraycopy(iv,0,temp,0,iv.length);
iv = temp;
}
AlgorithmParameterSpec ivSpec = new IvParameterSpec(iv);
String resultStr = null;
try {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
SecretKeySpec keySpec = new SecretKeySpec(key,"AES");
cipher.init(Cipher.DECRYPT_MODE,keySpec,ivSpec);
resultStr = new String(cipher.doFinal(encData),"UTF-8");
} catch (Exception e){
// logger.info("解析错误");
e.printStackTrace();
}
// 解析加密后的字符串
return resultStr;
}
}

View File

@ -0,0 +1,24 @@
package cn.iocoder.yudao.module.app.vo;
import lombok.Data;
@Data
public class WxLoginBody {
/**
* 临时登陆凭证 code 只能使用一次
*/
private String code;
/**
* 偏移量
*/
private String encryptedIv;
/**
* 加密数据
*/
private String encryptedData;
//邀请码
private Long inviteId;
}

View File

@ -44,7 +44,7 @@ public class RepairProjectController {
**/
@PostMapping("/create")
@Operation(summary = "创建维修项目")
@PreAuthorize("@ss.hasPermission('repair:project:create')")
// @PreAuthorize("@ss.hasPermission('repair:project:create')")
public CommonResult<RepairProject> createRepairProject(@Valid @RequestBody RepairProjectSaveReqVO createReqVO) {
RepairProject repairProject = repairProjectService.saveRepairProject(createReqVO);
return success(repairProject);
@ -60,7 +60,7 @@ public class RepairProjectController {
**/
@PutMapping("/update")
@Operation(summary = "更新维修项目")
@PreAuthorize("@ss.hasPermission('repair:project:update')")
// @PreAuthorize("@ss.hasPermission('repair:project:update')")
public CommonResult<Boolean> updateRepairProject(@Valid @RequestBody RepairProjectSaveReqVO updateReqVO) {
repairProjectService.saveRepairProject(updateReqVO);
return success(true);
@ -77,7 +77,7 @@ public class RepairProjectController {
@DeleteMapping("/delete")
@Operation(summary = "删除维修项目")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('repair:project:delete')")
// @PreAuthorize("@ss.hasPermission('repair:project:delete')")
public CommonResult<Boolean> deleteRepairProject(@RequestParam("id") String id) {
repairProjectService.deleteRepairProject(id);
return success(true);
@ -94,7 +94,7 @@ public class RepairProjectController {
@GetMapping("/get")
@Operation(summary = "获得维修项目")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('repair:project:query')")
// @PreAuthorize("@ss.hasPermission('repair:project:query')")
public CommonResult<RepairProjectRespVO> getRepairProject(@RequestParam("id") String id) {
RepairProject repairProject = repairProjectService.getRepairProject(id);
return success(BeanUtils.toBean(repairProject, RepairProjectRespVO.class));
@ -113,7 +113,7 @@ public class RepairProjectController {
**/
@GetMapping("/page")
@Operation(summary = "获得维修项目分页")
@PreAuthorize("@ss.hasPermission('repair:project:query')")
// @PreAuthorize("@ss.hasPermission('repair:project:query')")
public CommonResult<IPage<?>> getRepairProjectPage(RepairProjectPageReqVO pageReqVO,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {

View File

@ -43,7 +43,7 @@ public class RepairWaresController {
**/
@PostMapping("/create")
@Operation(summary = "创建配件库")
@PreAuthorize("@ss.hasPermission('repair:wares:create')")
// @PreAuthorize("@ss.hasPermission('repair:wares:create')")
public CommonResult<RepairWares> createWares(@Valid @RequestBody RepairWaresSaveReqVO createReqVO) {
return success(waresService.saveWares(createReqVO));
}
@ -58,7 +58,7 @@ public class RepairWaresController {
**/
@PutMapping("/update")
@Operation(summary = "更新配件库")
@PreAuthorize("@ss.hasPermission('repair:wares:update')")
// @PreAuthorize("@ss.hasPermission('repair:wares:update')")
public CommonResult<Boolean> updateWares(@Valid @RequestBody RepairWaresSaveReqVO updateReqVO) {
waresService.saveWares(updateReqVO);
return success(true);
@ -75,7 +75,7 @@ public class RepairWaresController {
@DeleteMapping("/delete")
@Operation(summary = "删除配件库")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('repair:wares:delete')")
// @PreAuthorize("@ss.hasPermission('repair:wares:delete')")
public CommonResult<Boolean> deleteWares(@RequestParam("id") String id) {
waresService.deleteWares(id);
return success(true);
@ -92,7 +92,7 @@ public class RepairWaresController {
@GetMapping("/get")
@Operation(summary = "获得配件库")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('repair:wares:query')")
// @PreAuthorize("@ss.hasPermission('repair:wares:query')")
public CommonResult<RepairWaresRespVO> getWares(@RequestParam("id") String id) {
return success(waresService.getWares(id));
}
@ -109,7 +109,7 @@ public class RepairWaresController {
**/
@GetMapping("/page")
@Operation(summary = "获得配件库分页")
@PreAuthorize("@ss.hasPermission('repair:wares:query')")
// @PreAuthorize("@ss.hasPermission('repair:wares:query')")
public CommonResult<IPage<?>> getWaresPage(RepairWaresPageReqVO pageReqVO,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {

View File

@ -137,7 +137,7 @@ public class YudaoWebSecurityConfigurerAdapter {
"/admin-api/system/auth/loginApp",
"/admin-api/rescue/driverLogin").anonymous()
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
.antMatchers("/admin-api/*/login", "/admin-api/*/wxLogin","/admin-api/*/wxLoginJc","/admin-api/*/wxLoginRescue","/admin-api/*/register","/admin-api/*/registerSmsCode","/admin-api/*/registerPhone","/admin-api/*/loginApp","/admin-api/*/loginSmsCode","/admin-api/*/captchaImage","/admin-api/*/pwdSmsCode","/admin-api/*/updatePwd").permitAll()
.antMatchers("/admin-api/*/login", "/admin-api/*/wxLogin","/admin-api/*/wxLoginJc","/admin-api/*/wxLoginRescue","/admin-api/*/registerSmsCode","/admin-api/*/registerPhone","/admin-api/*/loginApp","/admin-api/*/loginSmsCode","/admin-api/*/captchaImage","/admin-api/*/pwdSmsCode","/admin-api/*/updatePwd").permitAll()
// 公共接口 for 小程序
.antMatchers("/admin-api/system/dict/data/list","/admin-api/system/user/profile/avatar","/admin-api/system/user/profile/updateNickName","/admin-api/system/user/profile/saveUserProfile","/admin-api/system/userCar/getUserCar","/admin-api/system/userFeedback/addFeedbackWx").permitAll()
@ -146,7 +146,7 @@ public class YudaoWebSecurityConfigurerAdapter {
// 微信支付接口
.antMatchers("/admin-api/notify/**").permitAll()
.antMatchers("/userClient/pay/**").permitAll()
.antMatchers("/userClient/weChat/**").permitAll()
.antMatchers("/userClient/weChat/**","/userClient/repair/wxLogin").permitAll()
.antMatchers("/admin-api/websocket/**").permitAll()
// 小程序首页
.antMatchers("/admin-api/system/notice/listWx","/admin-api/system/swiper/listWx","/admin-api/system/shopconfig/listWx").permitAll()

View File

@ -60,6 +60,7 @@ public class AdminUserRespDTO {
* 枚举类 {@link SexEnum}
*/
private Integer sex;
private String repairOpenId;
}

View File

@ -5,6 +5,8 @@ import cn.iocoder.yudao.framework.common.validation.Mobile;
import cn.iocoder.yudao.module.system.framework.operatelog.core.DeptParseFunction;
import cn.iocoder.yudao.module.system.framework.operatelog.core.PostParseFunction;
import cn.iocoder.yudao.module.system.framework.operatelog.core.SexParseFunction;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.mzt.logapi.starter.annotation.DiffLogField;
import io.swagger.v3.oas.annotations.media.Schema;

View File

@ -227,56 +227,12 @@ public class AdminAuthServiceImpl implements AdminAuthService {
public AuthLoginRespVO wxLogin(String decryptResult, String openId, Long inviteId) {
//字符串转json
JSONObject jsonObject = JSONObject.parseObject(decryptResult);
System.out.println(jsonObject);
System.out.println("openId"+openId);
String phoneNumber = jsonObject.getString("phoneNumber");
//还可以获取其他信息
//根据openid判断数据库中是否有该用户
//根据openid查询用户信息
AdminUserDO wxUser = userService.selectUserByPhone(phoneNumber);
//如果查不到则新增查到了则更新
// SysUser user = new SysUser();
// if (wxUser == null) {
// // 新增
// user.setUserName(phoneNumber);
// user.setNickName(phoneNumber);
// user.setPhonenumber(phoneNumber);
// user.setOpenId(openId);
// user.setCreateTime(DateUtils.getNowDate());
// user.setPassword(SecurityUtils.encryptPassword("654321"));
// if (null!=inviteId){
//
// //绑定上级
// user.setInviteId(inviteId);
// //给上级进行积分奖励
// userBalanceService.inviteRewards(inviteId);
// }
// //新增 用户
// userService.insertUser(user);
// }else {
// //更新
// user = wxUser;
// user.setNickName(phoneNumber);
// user.setPhonenumber(phoneNumber);
// user.setUpdateTime(DateUtils.getNowDate());
// user.setOpenId(openId);
// if (ObjectUtil.isEmpty(user.getInviteId())){
// if (null!=inviteId){
// //绑定上级
// user.setInviteId(inviteId);
// //给上级进行积分奖励
// userBalanceService.inviteRewards(inviteId);
// }
// }
// userMapper.updateUser(user);
// }
//组装token信息
// LoginUser loginUser = new LoginUser();
// loginUser.setOpenId(openId);
// //如果有的话设置
// loginUser.setUser(user);
// loginUser.setUserId(user.getUserId());
// 生成token
return createTokenAfterLoginSuccess(wxUser.getId(), wxUser.getUsername(), LoginLogTypeEnum.LOGIN_SOCIAL);
}
@ -419,7 +375,7 @@ public class AdminAuthServiceImpl implements AdminAuthService {
List<RoleDO> jcyh = roleService.getRoleListByCodes(Collections.singletonList("jcyh"));
Set<Long> ids = new HashSet<>();
ids.add(jcyh.get(0).getId());
permissionService.assignUserRole(user.getId(),ids);
// permissionService.assignUserRole(user.getId(),ids);
}else {
//更新
user.setId(wxUser.getId());

View File

@ -3,7 +3,7 @@ spring:
name: yudao-server
profiles:
active: local
active: prod
main:
allow-circular-references: true # 允许循环依赖,因为项目是三层架构,无法避免这个情况。
@ -230,6 +230,7 @@ yudao:
- /admin-api/rescue/loginJcApp
- /admin-api/system/tenant/getListByWebsite
- /admin-api/rescue/loginQx
- /userClient/repair/wxLogin
websocket:
enable: true # websocket的开关
path: /infra/ws # 路径
@ -285,6 +286,7 @@ yudao:
- /userClient/pay/**
- /userClient/weChat/**
- /userClient/**
ignore-tables:
- system_tenant
- system_tenant_package