From b5aa692078a2ab38a108ebe5093cc7ed8ec8fba0 Mon Sep 17 00:00:00 2001 From: Burce Date: Fri, 11 Oct 2019 20:22:37 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=8B=9B=E5=95=86]adjust?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../invest/InvestBaseController.java | 34 +++++++++++++++++ .../invest/InvestDemandController.java | 27 ++++++++++++-- .../po/invest/InvestCustomerEntity.java | 3 +- .../domain/vo/invest/InvestDemandQuery.java | 37 +++++++++++++++++++ .../domain/vo/invest/InvestPageQuery.java | 2 + .../iformall/service/invest/InvestHelper.java | 26 +++++++++++++ 6 files changed, 124 insertions(+), 5 deletions(-) create mode 100644 mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestDemandQuery.java diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestBaseController.java b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestBaseController.java index 1280018ef..7ae065a69 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestBaseController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestBaseController.java @@ -5,14 +5,27 @@ import com.iformall.common.ErrorCode; import com.iformall.common.InvestResultData; import com.iformall.controller.base.BaseController; import com.iformall.domain.vo.invest.InvestUserContext; +import com.iformall.enums.EnumCustomerType; import com.iformall.exception.MallinkException; +import com.iformall.service.invest.InvestHelper; import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.WebDataBinder; +import org.springframework.web.bind.annotation.InitBinder; +import java.beans.PropertyEditor; +import java.beans.PropertyEditorSupport; import java.util.function.Function; + @Slf4j public class InvestBaseController extends BaseController { + @InitBinder + public void InitBinder(WebDataBinder dataBinder) { + super.InitBinder(dataBinder); + registerEnumEditor(dataBinder, EnumCustomerType.class, "customerType") ; + } + public InvestResultData execute(T params, Function function) { try { log.debug("[" + getIpAddr() + "] request , params : {}", JSON.toJSONString(params)); @@ -30,4 +43,25 @@ public class InvestBaseController extends BaseController { } } + public R convert(T params, Function function) { + InvestHelper.notNull(params); + return function.apply(params); + } + + private > void registerEnumEditor(WebDataBinder binder, Class clz, String propertyName) { + binder.registerCustomEditor(clz, propertyName, newEnumEditor(clz)); + } + + private > PropertyEditor newEnumEditor(Class clz) { + return new PropertyEditorSupport() { + @Override + public void setAsText(String text) { + try { + setValue(InvestHelper.codeOf(clz, Integer.parseInt(text))); + } catch (Exception NumberFormatException) { + setValue(InvestHelper.valueOf(clz, text)); + } + } + }; + } } diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestDemandController.java b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestDemandController.java index 5fc5f1875..cec76a7ef 100755 --- a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestDemandController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestDemandController.java @@ -3,6 +3,9 @@ package com.iformall.controller.invest; import com.iformall.annotation.SystemServiceLog; import com.iformall.common.InvestResultData; import com.iformall.domain.dto.InvestDemandDto; +import com.iformall.domain.po.invest.InvestCustomerEntity; +import com.iformall.domain.po.invest.InvestDemandEntity; +import com.iformall.domain.vo.invest.InvestDemandQuery; import com.iformall.domain.vo.invest.InvestDemandVo; import com.iformall.domain.vo.invest.InvestPageQuery; import com.iformall.domain.vo.invest.InvestPageResult; @@ -11,6 +14,7 @@ import com.iformall.service.invest.InvestDemandService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -42,11 +46,10 @@ public class InvestDemandController extends InvestBaseController { @SystemServiceLog @ApiOperation(value = "分页列表接口") @GetMapping("/list") - public InvestResultData> list(InvestPageQuery params) { - return execute(params, p -> investBizService.queryPageDemand(p)); + public InvestResultData> list(InvestDemandQuery params) { + return execute(convert(params, this::doConvert), p -> investBizService.queryPageDemand(p)); } - /** * 信息 */ @@ -82,4 +85,22 @@ public class InvestDemandController extends InvestBaseController { return execute(ids, p -> investDemandService.removeByIds(Arrays.asList(p))); } + private InvestPageQuery doConvert(InvestDemandQuery params) { + InvestCustomerEntity customerEntity = new InvestCustomerEntity(); + customerEntity.setId(params.getCustomerId()); + customerEntity.setType(params.getCustomerType()); + customerEntity.setBusinessId(params.getBusinessId()); + + InvestDemandEntity demandEntity = new InvestDemandEntity(); + demandEntity.setOwner(params.getOwner()); + + InvestDemandDto demandDto = new InvestDemandDto(); + demandDto.setCustomer(customerEntity); + demandDto.setDemand(demandEntity); + InvestPageQuery pageQuery = new InvestPageQuery<>(); + BeanUtils.copyProperties(params, pageQuery); + pageQuery.setQueryData(demandDto); + return pageQuery; + } + } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/invest/InvestCustomerEntity.java b/mallinkService/src/main/java/com/iformall/domain/po/invest/InvestCustomerEntity.java index d9ee93d56..68efdd102 100755 --- a/mallinkService/src/main/java/com/iformall/domain/po/invest/InvestCustomerEntity.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/invest/InvestCustomerEntity.java @@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.Version; import com.fasterxml.jackson.annotation.JsonProperty; import com.iformall.common.LogColumn; -import com.iformall.domain.po.invest.InvestBaseEntity; import com.iformall.enums.EnumCustomerRatingType; import com.iformall.enums.EnumCustomerType; import com.iformall.enums.EnumInvestChannel; @@ -69,7 +68,7 @@ public class InvestCustomerEntity extends InvestBaseEntity { */ @io.swagger.annotations.ApiModelProperty(value = "招商渠道:0-无;1-电视;2-广播;3-报纸;4-刊物;5-物联网;6-招商活动;7-中介机构;8-自定义渠道", name = "investChannel") @LogColumn - private EnumInvestChannel investChannel = EnumInvestChannel.NONE; + private EnumInvestChannel investChannel ; /** * 更新时间 diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestDemandQuery.java b/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestDemandQuery.java new file mode 100644 index 000000000..4ba78dcab --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestDemandQuery.java @@ -0,0 +1,37 @@ +package com.iformall.domain.vo.invest; + +import com.iformall.common.LogColumn; +import com.iformall.enums.EnumCustomerType; +import lombok.Data; + +@Data +public class InvestDemandQuery extends InvestPageQuery { + + /** + * 主键ID + */ + @io.swagger.annotations.ApiModelProperty(value = "客户编号", name = "customerId") + private Long customerId; + + /** + * 客户分类:0-潜在客户;1-意向客户;2-合作客户;3-谈判失败 + */ + @io.swagger.annotations.ApiModelProperty(value = "客户分类:0-潜在客户;1-意向客户;2-合作客户;3-谈判失败", name = "customerType") + @LogColumn + private EnumCustomerType customerType; + + /** + * 经营业态 + */ + @LogColumn + @io.swagger.annotations.ApiModelProperty(value = "经营业态", name = "businessId") + private Integer businessId; + + /** + * 负责人 + */ + @io.swagger.annotations.ApiModelProperty(value = "负责人", name = "owner") + @LogColumn + private Long owner; + +} diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestPageQuery.java b/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestPageQuery.java index 47773257e..33cc96340 100644 --- a/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestPageQuery.java +++ b/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestPageQuery.java @@ -1,10 +1,12 @@ package com.iformall.domain.vo.invest; import lombok.Data; +import lombok.NoArgsConstructor; import java.util.List; @Data +@NoArgsConstructor public class InvestPageQuery { public InvestPageQuery(T queryData) { this.queryData = queryData; diff --git a/mallinkService/src/main/java/com/iformall/service/invest/InvestHelper.java b/mallinkService/src/main/java/com/iformall/service/invest/InvestHelper.java index 15b345b56..535e05e43 100644 --- a/mallinkService/src/main/java/com/iformall/service/invest/InvestHelper.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/InvestHelper.java @@ -8,6 +8,7 @@ import com.iformall.exception.MallinkException; import org.apache.commons.compress.utils.Lists; import org.springframework.util.CollectionUtils; +import java.lang.reflect.Method; import java.text.MessageFormat; import java.util.List; import java.util.Objects; @@ -105,4 +106,29 @@ public class InvestHelper { throwException(ErrorCode.INVEST_RESULT_NOT_FOUND, message); } } + + public static > int code(T t) { + try { + Method code = t.getClass().getDeclaredMethod("code"); + Object rs = code.invoke(t); + return (int) rs; + } catch (ReflectiveOperationException e) { + throw new IllegalArgumentException(e); + } + } + + @SuppressWarnings("unchecked") + public static > T codeOf(Class enumType, int code) { + try { + Method method = enumType.getDeclaredMethod("getEnum", Integer.class); + Object rs = method.invoke(null, code); + return (T) rs; + } catch (ReflectiveOperationException e) { + throw new IllegalArgumentException(e); + } + } + + public static > T valueOf(Class enumType, String name) { + return T.valueOf(enumType, name); + } }