Explorar o código

fixed 商户管理、会员管理相关接口优化更新

fushengqian hai 3 meses
pai
achega
8a6a7fb9ae

+ 8 - 15
fuint-application/src/main/java/com/fuint/common/service/impl/PointServiceImpl.java

@@ -27,6 +27,7 @@ import org.apache.commons.lang.StringUtils;
 import com.github.pagehelper.Page;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.PageRequest;
@@ -115,22 +116,14 @@ public class PointServiceImpl extends ServiceImpl<MtPointMapper, MtPoint> implem
 
         List<PointDto> dataList = new ArrayList<>();
         for (MtPoint point : pointList) {
-            MtUser userInfo = memberService.queryMemberById(point.getUserId());
-            if (userInfo != null) {
+             MtUser userInfo = memberService.queryMemberById(point.getUserId());
+             if (userInfo != null) {
                 userInfo.setMobile(CommonUtil.hidePhone(userInfo.getMobile()));
-            }
-            PointDto item = new PointDto();
-            item.setId(point.getId());
-            item.setAmount(point.getAmount());
-            item.setDescription(point.getDescription());
-            item.setCreateTime(point.getCreateTime());
-            item.setUpdateTime(point.getUpdateTime());
-            item.setUserId(point.getUserId());
-            item.setUserInfo(userInfo);
-            item.setOrderSn(point.getOrderSn());
-            item.setOperator(point.getOperator());
-            item.setStatus(point.getStatus());
-            dataList.add(item);
+             }
+             PointDto item = new PointDto();
+             BeanUtils.copyProperties(point, item);
+             item.setUserInfo(userInfo);
+             dataList.add(item);
         }
         PageRequest pageRequest = PageRequest.of(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());
         PageImpl pageImpl = new PageImpl(dataList, pageRequest, pageHelper.getTotal());

+ 20 - 56
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendMemberController.java

@@ -13,6 +13,7 @@ import com.fuint.framework.pagination.PaginationRequest;
 import com.fuint.framework.pagination.PaginationResponse;
 import com.fuint.framework.web.BaseController;
 import com.fuint.framework.web.ResponseObject;
+import com.fuint.module.backendApi.request.MemberSubmitRequest;
 import com.fuint.repository.model.*;
 import com.fuint.utils.StringUtil;
 import io.swagger.annotations.Api;
@@ -247,72 +248,35 @@ public class BackendMemberController extends BaseController {
     @RequestMapping(value = "/save", method = RequestMethod.POST)
     @CrossOrigin
     @PreAuthorize("@pms.hasPermission('member:add')")
-    public ResponseObject save(HttpServletRequest request, @RequestBody Map<String, Object> param) throws BusinessCheckException, ParseException {
-        String token = request.getHeader("Access-Token");
-        AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
-
-        String id = param.get("id").toString();
-        String name = param.get("name") == null ? "" : param.get("name").toString();
-        String gradeId = param.get("gradeId") == null ? "0" :param.get("gradeId").toString();
-        String groupId = param.get("groupId") == null ? "0" :param.get("groupId").toString();
-        String storeId = param.get("storeId") == null ? "0" :param.get("storeId").toString();
-        String userNo = param.get("userNo") == null ? "" : param.get("userNo").toString();
-        String mobile = param.get("mobile") == null ? "" : param.get("mobile").toString();
-        String sex = param.get("sex") == null ? "0" : param.get("sex").toString();
-        String idCard = param.get("idcard") == null ? "" : param.get("idcard").toString();
-        String birthday = param.get("birthday") == null ? "" : param.get("birthday").toString();
-        String address = param.get("address") == null ? "" : param.get("address").toString();
-        String description = param.get("description") == null ? "" : param.get("description").toString();
-        String status = param.get("status") == null ? StatusEnum.ENABLED.getKey() : param.get("status").toString();
-        String startTime = param.get("startTime") == null ? "" : param.get("startTime").toString();
-        String endTime = param.get("endTime") == null ? "" : param.get("endTime").toString();
-
-        if (PhoneFormatCheckUtils.isChinaPhoneLegal(mobile)) {
+    public ResponseObject save(HttpServletRequest request, @RequestBody MemberSubmitRequest memberInfo) throws BusinessCheckException, ParseException {
+        AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(request.getHeader("Access-Token"));
+        if (PhoneFormatCheckUtils.isChinaPhoneLegal(memberInfo.getMobile())) {
             // 重置该手机号
-            memberService.resetMobile(mobile, StringUtil.isEmpty(id) ? 0 : Integer.parseInt(id));
+            memberService.resetMobile(memberInfo.getMobile(), memberInfo.getId());
         }
 
-        MtUser memberInfo;
-        if (StringUtil.isEmpty(id)) {
-            memberInfo = new MtUser();
+        MtUser mtUser;
+        if (memberInfo.getId() == null || memberInfo.getId() <= 0) {
+            mtUser = new MtUser();
         } else {
-            memberInfo = memberService.queryMemberById(Integer.parseInt(id));
+            mtUser = memberService.queryMemberById(memberInfo.getId());
         }
 
         if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
-            memberInfo.setMerchantId(accountInfo.getMerchantId());
-        }
-
-        memberInfo.setName(name);
-        memberInfo.setStatus(status);
-        if (StringUtil.isNotEmpty(groupId)) {
-            memberInfo.setGroupId(Integer.parseInt(groupId));
-        }
-        memberInfo.setGradeId(gradeId);
-        memberInfo.setUserNo(userNo);
-        if (PhoneFormatCheckUtils.isChinaPhoneLegal(mobile)) {
-            memberInfo.setMobile(mobile);
-        }
-        memberInfo.setSex(Integer.parseInt(sex));
-        memberInfo.setIdcard(idCard);
-        memberInfo.setBirthday(birthday);
-        memberInfo.setAddress(address);
-        memberInfo.setDescription(description);
-        memberInfo.setStartTime(DateUtil.parseDate(startTime));
-        memberInfo.setEndTime(DateUtil.parseDate(endTime));
-        memberInfo.setIsStaff(YesOrNoEnum.NO.getKey());
-        if (StringUtil.isNotEmpty(storeId)) {
-            memberInfo.setStoreId(Integer.parseInt(storeId));
-        }
-        TAccount account = accountService.getAccountInfoById(accountInfo.getId());
-        Integer myStoreId = account.getStoreId();
+            mtUser.setMerchantId(accountInfo.getMerchantId());
+        }
+        BeanUtils.copyProperties(memberInfo, mtUser);
+        mtUser.setStartTime(DateUtil.parseDate(memberInfo.getStartTime()));
+        mtUser.setEndTime(DateUtil.parseDate(memberInfo.getEndTime()));
+        mtUser.setIsStaff(YesOrNoEnum.NO.getKey());
+        Integer myStoreId = accountInfo.getStoreId();
         if (myStoreId != null && myStoreId > 0) {
-            memberInfo.setStoreId(myStoreId);
+            mtUser.setStoreId(myStoreId);
         }
-        if (StringUtil.isEmpty(id)) {
-            memberService.addMember(memberInfo, "0");
+        if (mtUser.getId() == null) {
+            memberService.addMember(mtUser, null);
         } else {
-            memberService.updateMember(memberInfo, false);
+            memberService.updateMember(mtUser, false);
         }
         return getSuccessResult(true);
     }

+ 15 - 43
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendMerchantController.java

@@ -7,18 +7,19 @@ import com.fuint.common.enums.MerchantTypeEnum;
 import com.fuint.common.enums.StatusEnum;
 import com.fuint.common.service.MerchantService;
 import com.fuint.common.service.SettingService;
-import com.fuint.common.util.CommonUtil;
 import com.fuint.common.util.TokenUtil;
 import com.fuint.framework.exception.BusinessCheckException;
 import com.fuint.framework.pagination.PaginationRequest;
 import com.fuint.framework.pagination.PaginationResponse;
 import com.fuint.framework.web.BaseController;
 import com.fuint.framework.web.ResponseObject;
+import com.fuint.module.backendApi.request.MerchantSubmitRequest;
 import com.fuint.repository.model.MtMerchant;
 import com.fuint.utils.StringUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
+import org.springframework.beans.BeanUtils;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 import javax.servlet.http.HttpServletRequest;
@@ -158,62 +159,33 @@ public class BackendMerchantController extends BaseController {
     @RequestMapping(value = "/save", method = RequestMethod.POST)
     @CrossOrigin
     @PreAuthorize("@pms.hasPermission('merchant:index')")
-    public ResponseObject saveHandler(HttpServletRequest request, @RequestBody Map<String, Object> params) throws BusinessCheckException {
+    public ResponseObject saveHandler(HttpServletRequest request, @RequestBody MerchantSubmitRequest merchantInfo) throws BusinessCheckException {
         String token = request.getHeader("Access-Token");
         AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
+        Integer merchantId = accountInfo.getMerchantId();
 
-        Integer merchantId = StringUtil.isEmpty(params.get("id").toString()) ? Integer.parseInt("0") : Integer.parseInt(params.get("id").toString());
-        String name = CommonUtil.replaceXSS(params.get("name").toString());
-        String merchantNo = CommonUtil.replaceXSS(params.get("no").toString());
-        String contact = params.get("contact") == null ? "" : CommonUtil.replaceXSS(params.get("contact").toString());
-        String phone = params.get("phone") == null ? "" : CommonUtil.replaceXSS(params.get("phone").toString());
-        String description = params.get("description") == null ? "" : CommonUtil.replaceXSS(params.get("description").toString());
-        String address = params.get("address") == null ? "" : CommonUtil.replaceXSS(params.get("address").toString());
-        String status = params.get("status") == null ? "" : CommonUtil.replaceXSS(params.get("status").toString());
-        String logo = params.get("logo") == null ? "" : CommonUtil.replaceXSS(params.get("logo").toString());
-        String type = params.get("type") == null ? MerchantTypeEnum.RETAIL.getKey() : CommonUtil.replaceXSS(params.get("type").toString());
-        String wxAppId = params.get("wxAppId") == null ? "" : CommonUtil.replaceXSS(params.get("wxAppId").toString());
-        String wxAppSecret = params.get("wxAppSecret") == null ? "" : CommonUtil.replaceXSS(params.get("wxAppSecret").toString());
-        String wxOfficialAppId = params.get("wxOfficialAppId") == null ? "" : CommonUtil.replaceXSS(params.get("wxOfficialAppId").toString());
-        String wxOfficialAppSecret = params.get("wxOfficialAppSecret") == null ? "" : CommonUtil.replaceXSS(params.get("wxOfficialAppSecret").toString());
-
-        MtMerchant merchantInfo = new MtMerchant();
-        merchantInfo.setType(type);
-        merchantInfo.setName(name);
-        merchantInfo.setNo(merchantNo);
-        merchantInfo.setContact(contact);
-        merchantInfo.setPhone(phone);
-        merchantInfo.setDescription(description);
-        merchantInfo.setAddress(address);
-        merchantInfo.setLogo(logo);
-        merchantInfo.setWxAppId(wxAppId);
-        merchantInfo.setWxAppSecret(wxAppSecret);
-        merchantInfo.setWxOfficialAppId(wxOfficialAppId);
-        merchantInfo.setWxOfficialAppSecret(wxOfficialAppSecret);
-        merchantInfo.setStatus(status);
-        if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
-            merchantInfo.setId(accountInfo.getMerchantId());
+        MtMerchant mtMerchant = new MtMerchant();
+        BeanUtils.copyProperties(merchantInfo, mtMerchant);
+        if (merchantId != null && merchantId > 0) {
+            mtMerchant.setId(merchantId);
         }
 
-        if (StringUtil.isEmpty(name)) {
+        if (StringUtil.isEmpty(mtMerchant.getName())) {
             return getFailureResult(201, "商户名称不能为空");
         } else {
-            MtMerchant merchant = merchantService.queryMerchantByName(name);
-            if (null != merchant && !merchant.getId().equals(merchantId)) {
+            MtMerchant merchant = merchantService.queryMerchantByName(mtMerchant.getName());
+            if (merchant != null && !merchant.getId().equals(mtMerchant.getId())) {
                 return getFailureResult(201, "该商户名称已经存在");
             }
         }
-        if (merchantId <= 0 && accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
+
+        if (mtMerchant.getId() == null && merchantId != null && merchantId > 0) {
             return getFailureResult(201, "抱歉,您没有添加商户的权限");
         }
 
-        // 修改商户信息
-        if (merchantId > 0) {
-            merchantInfo.setId(merchantId);
-        }
+        mtMerchant.setOperator(accountInfo.getAccountName());
+        merchantService.saveMerchant(mtMerchant);
 
-        merchantInfo.setOperator(accountInfo.getAccountName());
-        merchantService.saveMerchant(merchantInfo);
         return getSuccessResult(true);
     }
 

+ 61 - 0
fuint-application/src/main/java/com/fuint/module/backendApi/request/MemberSubmitRequest.java

@@ -0,0 +1,61 @@
+package com.fuint.module.backendApi.request;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import java.io.Serializable;
+
+/**
+ * 提交会员信息请求参数
+ *
+ * Created by FSQ
+ * CopyRight https://www.fuint.cn
+ */
+@Data
+public class MemberSubmitRequest implements Serializable {
+
+    @ApiModelProperty(value="会员ID", name="id")
+    private Integer id;
+
+    @ApiModelProperty(value="名称", name="name")
+    private String name;
+
+    @ApiModelProperty(value="会员等级", name="gradeId")
+    private Integer gradeId;
+
+    @ApiModelProperty(value="分组ID", name="groupId")
+    private Integer groupId;
+
+    @ApiModelProperty(value="店铺ID", name="storeId")
+    private Integer storeId;
+
+    @ApiModelProperty(value="会员号", name="userNo")
+    private String userNo;
+
+    @ApiModelProperty(value="手机号", name="mobile")
+    private String mobile;
+
+    @ApiModelProperty(value="性别", name="sex")
+    private Integer sex;
+
+    @ApiModelProperty(value="身份证", name="idcard")
+    private String idcard;
+
+    @ApiModelProperty(value="生日", name="birthday")
+    private String birthday;
+
+    @ApiModelProperty(value="地址", name="address")
+    private String address;
+
+    @ApiModelProperty(value="备注信息", name="description")
+    private String description;
+
+    @ApiModelProperty(value="状态", name="status")
+    private String status;
+
+    @ApiModelProperty(value="会员开始时间", name="startTime")
+    private String startTime;
+
+    @ApiModelProperty(value="会员结束时间", name="endTime")
+    private String endTime;
+
+}

+ 58 - 0
fuint-application/src/main/java/com/fuint/module/backendApi/request/MerchantSubmitRequest.java

@@ -0,0 +1,58 @@
+package com.fuint.module.backendApi.request;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import java.io.Serializable;
+
+/**
+ * 提交商户请求参数
+ *
+ * Created by FSQ
+ * CopyRight https://www.fuint.cn
+ */
+@Data
+public class MerchantSubmitRequest implements Serializable {
+
+    @ApiModelProperty(value="商户ID", name="id")
+    private Integer id;
+
+    @ApiModelProperty(value="商户名称", name="name")
+    private String name;
+
+    @ApiModelProperty(value="商户号", name="no")
+    private String no;
+
+    @ApiModelProperty(value="联系人", name="contact")
+    private String contact;
+
+    @ApiModelProperty(value="手机号", name="phone")
+    private String phone;
+
+    @ApiModelProperty(value="备注信息", name="description")
+    private String description;
+
+    @ApiModelProperty(value="地址", name="address")
+    private String address;
+
+    @ApiModelProperty(value="状态", name="status")
+    private String status;
+
+    @ApiModelProperty(value="图片", name="logo")
+    private String logo;
+
+    @ApiModelProperty(value="类型", name="type")
+    private String type;
+
+    @ApiModelProperty(value="小程序appId", name="wxAppId")
+    private String wxAppId;
+
+    @ApiModelProperty(value="小程序appSecret", name="wxAppSecret")
+    private String wxAppSecret;
+
+    @ApiModelProperty(value="公众号appId", name="wxOfficialAppId")
+    private String wxOfficialAppId;
+
+    @ApiModelProperty(value="公众号AppSecret", name="wxOfficialAppSecret")
+    private String wxOfficialAppSecret;
+
+}