diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/WxBillActionController.java b/mallinkAdmin/src/main/java/com/iformall/controller/WxBillActionController.java new file mode 100644 index 000000000..131d3aa82 --- /dev/null +++ b/mallinkAdmin/src/main/java/com/iformall/controller/WxBillActionController.java @@ -0,0 +1,48 @@ +package com.iformall.controller; + +import com.github.pagehelper.PageInfo; +import com.iformall.annotation.SystemControllerLog; +import com.iformall.common.ResultData; +import com.iformall.domain.po.WxBillAction; +import com.iformall.service.WxBillActionService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author gongbiao + */ +@Api(description = "账单操作记录") +@RestController +@RequestMapping("wxBillAction") +public class WxBillActionController extends BaseController { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + + @Autowired + private WxBillActionService wxBillActionService; + + @GetMapping("list") + @ApiImplicitParams({ + @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), + @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) + @SystemControllerLog(description = "账单操作记录-列表") + public ResultData list(@ModelAttribute WxBillAction wxBillAction, Integer pageNum, Integer pageSize) { + logger.debug("[" + getIpAddr() + "] WxBillActionController::list"); + if (null == wxBillAction) { + wxBillAction = new WxBillAction(); + } + wxBillAction.setTenantId(getTenantId()); + wxBillAction.setSortColumns(WxBillAction.Field.Id_DESC); + PageInfo result = wxBillActionService.listAsPage(wxBillAction, pageNum, pageSize); + return new ResultData(result); + } + +} \ No newline at end of file diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/WxCarController.java b/mallinkAdmin/src/main/java/com/iformall/controller/WxCarController.java index 7c85da453..3e2f06d0f 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/WxCarController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/WxCarController.java @@ -11,6 +11,7 @@ import com.iformall.domain.vo.WxCouponCarVo; import com.iformall.enums.EnumCarVendor; import com.iformall.enums.EnumCouponStatus; import com.iformall.enums.EnumETCPCode; +import com.iformall.exception.MallinkException; import com.iformall.service.*; import com.iformall.utils.ETCPUtil; import com.iformall.utils.TJDCarUtil; @@ -148,7 +149,13 @@ public class WxCarController extends BaseController { // 1期只有一个虚拟商户,可以写在商场配置里 businessId = objParams.getString("businessId"); } - String ret = etcp.getBCouponList(url, merchantNo, merchantKey, version, parkId, businessId); + String ret = ""; + try { + ret = etcp.getBCouponList(url, merchantNo, merchantKey, version, parkId, businessId); + } catch (MallinkException e) { + return new ResultData(e.getErrorCode(), e.getMessage()); + } + if (ret == null) { logger.error("quanTemplate failed, 优免券模板未发现"); return new ResultData(ErrorCode.ETCP_CMD_FAIL.getCode(), "获取优免券模板异常"); @@ -300,6 +307,7 @@ public class WxCarController extends BaseController { String version = objParams.getString("version"); if (park.getParkingId() == null) { // those code is not supported + /* String lat = objParams.getString("lat"); String lon = objParams.getString("lon"); String radius = objParams.getString("radius"); @@ -323,10 +331,18 @@ public class WxCarController extends BaseController { } } } + */ } if (park.getParkingId() != null) { - String ret = etcp.parkingStatus(url, merchantNo, merchantKey, version, park.getParkingId()); + String ret = ""; + try { + ret = etcp.parkingStatus(url, merchantNo, merchantKey, version, park.getParkingId()); + } catch (MallinkException e) { + logger.error("ETCP failed: " + e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } + JSONObject retObj = JSON.parseObject(ret); if (retObj.getIntValue("code") == EnumETCPCode.SUCCESS.getCode()) { if (retObj.get("data") != null) { diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/WxChartDataController.java b/mallinkAdmin/src/main/java/com/iformall/controller/WxChartDataController.java index dc9583545..092b39106 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/WxChartDataController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/WxChartDataController.java @@ -36,9 +36,12 @@ public class WxChartDataController extends BaseController { }) @SystemControllerLog(description = "报表-图表") public ResultData queryData(@RequestParam Map params) { - logger.debug("[" + getIpAddr() + "] WxChartDataController::queryData"); + String chart = params.get("chart"); + logger.info("[" + getIpAddr() + "] WxChartDataController::queryData chart: " + chart); params.put("tenantId",super.getTenantId()); - return wxChartDataService.queryData(params); + ResultData data = wxChartDataService.queryData(params); + logger.info("[" + getIpAddr() + "] WxChartDataController::queryData chart: " + chart + " end"); + return data; } } diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/WxCreditHistoryController.java b/mallinkAdmin/src/main/java/com/iformall/controller/WxCreditHistoryController.java index b8643ffa6..fbab0538e 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/WxCreditHistoryController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/WxCreditHistoryController.java @@ -45,8 +45,7 @@ public class WxCreditHistoryController extends BaseController @ApiOperation("新增接口") @PostMapping("add") public ResultData add(@RequestBody WxCreditHistory wxCreditHistory) { - //Assert.notNull(wxCreditHistory.getName(), "角色名不能为空"); - //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); + wxCreditHistory.setTenantId(getTenantId()); wxCreditHistoryService.saveOrUpdate(wxCreditHistory); return new ResultData(); } diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/WxScoreRulesController.java b/mallinkAdmin/src/main/java/com/iformall/controller/WxScoreRulesController.java index 58921c54a..3ade4e2b8 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/WxScoreRulesController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/WxScoreRulesController.java @@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("wxScoreRules") -@Api(description = "成长值规则相关接口") +@Api(description = "成长值积分规则相关接口") public class WxScoreRulesController extends BaseController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -35,11 +35,20 @@ public class WxScoreRulesController extends BaseController { @ApiOperation("新增接口") @PostMapping("add") - @SystemControllerLog(description = "成长值-配置-新增") + @SystemControllerLog(description = "成长值-积分-配置-新增") public ResultData add(@RequestBody WxScoreRules wxScoreRules) { logger.debug("[" + getIpAddr() + "] WxScoreRulesController::add"); wxScoreRules.setTenantId(getTenantId()); wxScoreRulesService.saveOrUpdate(wxScoreRules); return new ResultData(); } + + @ApiOperation("积分配置") + @GetMapping("/credit_rules") + @SystemControllerLog(description = "积分-配置") + public ResultData creditRulesList() { + logger.debug("[" + getIpAddr() + "] WxScoreRulesController::list"); + WxScoreRules scoreRules = wxScoreRulesService.getCreditRules(getTenantId()); + return new ResultData(scoreRules); + } } diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/WxShopController.java b/mallinkAdmin/src/main/java/com/iformall/controller/WxShopController.java index 2a015b9b0..3a4b7474e 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/WxShopController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/WxShopController.java @@ -71,8 +71,7 @@ public class WxShopController extends BaseController { public ResultData delete(Long id) { logger.debug("[" + getIpAddr() + "] WxShopController::delete"); Integer isAdmin = getUser().getIsAdmin(); - wxShopService.deleteById(id, isAdmin); - return new ResultData(Result.SUCCESS, "删除成功", null); + return wxShopService.deleteById(id, isAdmin); } @ApiOperation("根据id查询接口") diff --git a/mallinkAdmin/src/main/resources/db/migration/V201904031030__UPDATE_WX_SHOP.sql b/mallinkAdmin/src/main/resources/db/migration/V201904031030__UPDATE_WX_SHOP.sql new file mode 100644 index 000000000..3ed494ce0 --- /dev/null +++ b/mallinkAdmin/src/main/resources/db/migration/V201904031030__UPDATE_WX_SHOP.sql @@ -0,0 +1,2 @@ +ALTER TABLE `wx_shop` +ADD COLUMN `is_del` smallint(2) DEFAULT 0 COMMENT '是否删除1是0否'; \ No newline at end of file diff --git a/mallinkAdmin/src/main/resources/db/migration/V201904031540__ADD_BILL_ACTION.sql b/mallinkAdmin/src/main/resources/db/migration/V201904031540__ADD_BILL_ACTION.sql new file mode 100644 index 000000000..978192cbf --- /dev/null +++ b/mallinkAdmin/src/main/resources/db/migration/V201904031540__ADD_BILL_ACTION.sql @@ -0,0 +1,14 @@ +DROP TABLE IF EXISTS `wx_bill_action` ; +CREATE TABLE `wx_bill_action` ( + `id` bigint(64) NOT NULL COMMENT 'ID', + `tenant_id` varchar(50) NOT NULL COMMENT '租户Id', + `user_id` bigint(64) NOT NULL COMMENT '用户ID', + `user_name` varchar(100) NOT NULL COMMENT '用户名', + `phone` varchar(20) NOT NULL COMMENT '手机号', + `action` smallint(2) NOT NULL COMMENT '动作', + `details` varchar(200) NOT NULL COMMENT '明细', + `createtime` datetime NOT NULL COMMENT '创建时间', + `updatetime` datetime NOT NULL COMMENT '更新时间', + PRIMARY KEY (`id`), + INDEX `id_index` USING BTREE (`id`) comment '' +) ENGINE=`InnoDB` ROW_FORMAT=DYNAMIC COMMENT='账单操作记录' CHECKSUM=0 DELAY_KEY_WRITE=0; \ No newline at end of file diff --git a/mallinkCApi/src/main/java/com/iformall/controller/WxCarController.java b/mallinkCApi/src/main/java/com/iformall/controller/WxCarController.java index a3dd93a82..a568e35c8 100644 --- a/mallinkCApi/src/main/java/com/iformall/controller/WxCarController.java +++ b/mallinkCApi/src/main/java/com/iformall/controller/WxCarController.java @@ -10,6 +10,7 @@ import com.iformall.domain.po.*; import com.iformall.domain.vo.WxCouponOrderCarCVo; import com.iformall.domain.vo.WxMerchantVo; import com.iformall.enums.*; +import com.iformall.exception.MallinkException; import com.iformall.service.*; import com.iformall.utils.ETCPUtil; import com.iformall.utils.TJDCarUtil; @@ -109,16 +110,26 @@ public class WxCarController extends BaseController { String merchantKey = objParams.getString("merchantKey"); String version = objParams.getString("version"); - String ret = etcp.userSignin(url, appId, merchantNo, merchantKey, version, phone); + String ret = ""; + try { + ret = etcp.userSignin(url, appId, merchantNo, merchantKey, version, phone); + } catch (MallinkException e) { + logger.error("ETCP failed: " + e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } JSONObject retObj = JSON.parseObject(ret); if (retObj.getIntValue("code") == EnumETCPCode.SUCCESS.getCode()) { // 获取绑定的车牌 JSONObject dataObj = retObj.getJSONObject("data"); dataObj.put("vendor", EnumCarVendor.CAR_ETCP.getCode()); String etcpToken = dataObj.getString("token"); - JSONObject dataObj1 = syncCarNumbers(user.getId(), user.getTenantId(), park.getVendorType(), - url, merchantNo, merchantKey, version, - etcpToken); + try { + JSONObject dataObj1 = syncCarNumbers(user.getId(), user.getTenantId(), park.getVendorType(), + url, merchantNo, merchantKey, version, + etcpToken); + } catch (MallinkException e) { + logger.error("ETCP cmd error: " + e.getMessage()); + } // c端必须保存此token return new ResultData(dataObj); } else { @@ -152,8 +163,13 @@ public class WxCarController extends BaseController { String etcpToken) { String ret; JSONObject retObj; - ret = etcp.carNum(url, merchantNo, merchantKey, version, etcpToken); /*{"code": 0,"msg": "ok","data": {"number": 3,"carList": ["晋 BMZ105","云 C12345"]}} */ + try { + ret = etcp.carNum(url, merchantNo, merchantKey, version, etcpToken); + } catch (MallinkException e) { + logger.error("ETCP failed: " + e.getMessage()); + throw new MallinkException(e.getErrorCode(), e.getMessage()); + } retObj = JSON.parseObject(ret); JSONObject dataObj1 = retObj.getJSONObject("data"); dataObj1.put("vendor", iVendorType); @@ -251,7 +267,13 @@ public class WxCarController extends BaseController { String merchantKey = objParams.getString("merchantKey"); String version = objParams.getString("version"); - String ret = etcp.bindCar(url, merchantNo, merchantKey, version, etcpToken, carNumber, null); + String ret = ""; + try { + ret = etcp.bindCar(url, merchantNo, merchantKey, version, etcpToken, carNumber, null); + } catch (MallinkException e) { + logger.error("ETCP failed: " + e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } JSONObject retObj = JSON.parseObject(ret); if (retObj.getIntValue("code") == 0) { // 插入车牌 @@ -375,7 +397,14 @@ public class WxCarController extends BaseController { String merchantKey = objParams.getString("merchantKey"); String version = objParams.getString("version"); - String ret = etcp.unbindCar(url, merchantNo, merchantKey, version, etcpToken, carNumber); + String ret = ""; + try { + ret = etcp.unbindCar(url, merchantNo, merchantKey, version, etcpToken, carNumber); + } catch (MallinkException e) { + logger.error("ETCP failed: " + e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } + JSONObject retObj = JSON.parseObject(ret); if (retObj.getIntValue("code") == 0) { try { @@ -497,7 +526,14 @@ public class WxCarController extends BaseController { String merchantKey = objParams.getString("merchantKey"); String version = objParams.getString("version"); - String ret = etcp.orderUnpay(url, appId, merchantNo, merchantKey, version, etcpToken, carNumber); + String ret = ""; + try { + ret = etcp.orderUnpay(url, appId, merchantNo, merchantKey, version, etcpToken, carNumber); + } catch (MallinkException e) { + logger.error("ETCP failed: " + e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } + JSONObject retObj = JSON.parseObject(ret); if (retObj.getIntValue("code") == 0) { JSONObject feeObj = retObj.getJSONArray("data").getJSONObject(0); @@ -667,8 +703,14 @@ public class WxCarController extends BaseController { businessId = objParams.getString("businessId"); } - String ret = etcp.bCouponRecord(url, merchantNo, merchantKey, version, - etcpToken, park.getParkId(), businessId, carNumber, String.valueOf(userCar.getCouponFreeId())); + String ret = ""; + try { + ret = etcp.bCouponRecord(url, merchantNo, merchantKey, version, + etcpToken, park.getParkId(), businessId, carNumber, String.valueOf(userCar.getCouponFreeId())); + } catch (MallinkException e) { + logger.error("ETCP failed: " + e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } JSONObject retObj = JSON.parseObject(ret); if (retObj.getIntValue("code") == EnumETCPCode.SUCCESS.getCode()) { @@ -732,6 +774,7 @@ public class WxCarController extends BaseController { String version = objParams.getString("version"); if (park.getParkingId() == null) { // those code is not supported + /* String lat = objParams.getString("lat"); String lon = objParams.getString("lon"); String radius = objParams.getString("radius"); @@ -755,10 +798,17 @@ public class WxCarController extends BaseController { } } } + */ } if (park.getParkingId() != null) { - String ret = etcp.parkingStatus(url, merchantNo, merchantKey, version, park.getParkingId()); + String ret = ""; + try { + ret = etcp.parkingStatus(url, merchantNo, merchantKey, version, park.getParkingId()); + } catch (MallinkException e) { + logger.error("ETCP failed: " + e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } JSONObject retObj = JSON.parseObject(ret); if (retObj.getIntValue("code") == EnumETCPCode.SUCCESS.getCode()) { diff --git a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java index 2454a7154..ac6a2715e 100644 --- a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java +++ b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java @@ -26,6 +26,7 @@ public enum ErrorCode{ SYS_NUMBER_FORMAT_ERROR(1011, "数字转化异常"), SYS_EXTEND_JSON_ERROR(1012, "JSON格式异常"), SYS_REPEAT_SUBMIT_EXCEPTION(1013, "请勿重复操作"), + REPORT_TYPE_UNKNOWN(1014, "不支持的报表类型"), /** * 数据库 @@ -273,6 +274,8 @@ public enum ErrorCode{ */ MEM_IMPORT_ERR(13000, "模板导入失败,请检查数据,尝试重新导入"), MEM_SCORE_NOT_ENOUGH(13001, "成长值不够扣减值"), + CREDIT_ZERO(13100,"本次操作积分为零"), + CREDIT_NOT_ENOUGH(13101, "积分不够扣减值"), /** * 标签 @@ -330,7 +333,7 @@ public enum ErrorCode{ SHOP_IS_RENT(22001,"商铺已出租"), SHOP_NOT_SELECTED(22002, "未选择商铺"), SHOP_BAN_DELETED(22003, "已出租的商铺无法删除"), - SHOP_DELETED_BY_ADMIN(22004, "超管才能删除此商铺"), + SHOP_DELETED_BY_ADMIN(22004, "仅超级管理员能删除该商铺"), /** diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxBillAction.java b/mallinkService/src/main/java/com/iformall/domain/po/WxBillAction.java new file mode 100644 index 000000000..ac7fcebbe --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxBillAction.java @@ -0,0 +1,199 @@ +package com.iformall.domain.po; + +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Transient; +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** + * @author gongbiao + */ +@Table(name = "wx_bill_action") +public class WxBillAction implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + protected Long id; + + @Transient + protected List ids; + @Transient + protected String sortColumns; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getSortColumns() { + return sortColumns; + } + + public List getIds() { + return ids; + } + + public void setIds(List ids) { + this.ids = ids; + } + + + @io.swagger.annotations.ApiModelProperty(value = "租户ID", name = "tenantId") + private String tenantId; + + @io.swagger.annotations.ApiModelProperty(value = "账单ID", name = "billId") + private Long billId; + + @io.swagger.annotations.ApiModelProperty(value = "用户ID", name = "userId") + private Long userId; + + @io.swagger.annotations.ApiModelProperty(value = "用户名称", name = "userName") + private String userName; + + @io.swagger.annotations.ApiModelProperty(value = "手机号", name = "phone") + private String phone; + + @io.swagger.annotations.ApiModelProperty(value = "动作", name = "action") + private Integer action; + + @io.swagger.annotations.ApiModelProperty(value = "描述", name = "details") + private String details; + + @io.swagger.annotations.ApiModelProperty(value = "创建时间", name = "createtime") + private Date createtime; + + @io.swagger.annotations.ApiModelProperty(value = "更新时间", name = "updatetime") + private Date updatetime; + + public String getTenantId() { + return tenantId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + public Long getBillId() { + return billId; + } + + public void setBillId(Long billId) { + this.billId = billId; + } + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public Integer getAction() { + return action; + } + + public void setAction(Integer action) { + this.action = action; + } + + public String getDetails() { + return details; + } + + public void setDetails(String details) { + this.details = details; + } + + public Date getCreatetime() { + return createtime; + } + + public void setCreatetime(Date createtime) { + this.createtime = createtime; + } + + public Date getUpdatetime() { + return updatetime; + } + + public void setUpdatetime(Date updatetime) { + this.updatetime = updatetime; + } + + public static enum Field { + Id_ASC("`id` ASC"), Id_DESC("`id` DESC"); + private String value; + + Field(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public void setCol(String value) { + this.value = value; + } + + @Override + public String toString() { + return this.getValue(); + } + } + + public void setSortColumns(WxBillAction.Field... fields) { + if (fields == null || fields.length == 0) { + return; + } + for (int k = 0; k < fields.length; k++) { + if (fields[k] == null) { + return; + } + } + StringBuilder sb = new StringBuilder(fields[0].toString()); + for (int k = 1; k < fields.length; k++) { + sb.append(","); + sb.append(fields[k].toString()); + } + this.sortColumns = sb.toString(); + } + + public void setSortColumns(String sortColumns) { + if (sortColumns == null || "".equals(sortColumns.trim())) { + return; + } + if (sortColumns.contains(",")) { + String[] cols = sortColumns.split(","); + List fList = new java.util.ArrayList(); + for (int k = 0; k < cols.length; k++) { + fList.add(Field.valueOf(cols[k])); + } + this.setSortColumns(fList.toArray(new Field[fList.size()])); + } else { + this.setSortColumns(Field.valueOf(sortColumns)); + } + } +} diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCUser.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCUser.java index 5d8f05768..c6fa92034 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxCUser.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCUser.java @@ -157,6 +157,9 @@ public class WxCUser implements Serializable { private Date subsSubscribeTime; @io.swagger.annotations.ApiModelProperty(value="关注订阅号Scene",name="subsSubscribeScene") private String subsSubscribeScene; + /**积分**/ + @io.swagger.annotations.ApiModelProperty(value="积分",name="credit") + private Integer credit; //渠道名称 @@ -488,7 +491,15 @@ public class WxCUser implements Serializable { this.subsSubscribeScene = subsSubscribeScene; } - public static enum Field + public Integer getCredit() { + return credit; + } + + public void setCredit(Integer credit) { + this.credit = credit; + } + + public static enum Field { Id_ASC("`id` ASC"),Id_DESC("`id` DESC") ,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC") @@ -520,7 +531,9 @@ public class WxCUser implements Serializable { ,LoginCount_ASC("`login_count` ASC"),LoginCount_DESC("`login_count` DESC") ,ExtraInfo_ASC("`extra_info` ASC"),ExtraInfo_DESC("`extra_info` DESC") ,IsSubscribe_ASC("`is_subscribe` ASC"),IsSubscribe_DESC("`is_subscribe` DESC") - ; + ,Credit_ASC("`credit` ASC"),Credit_DESC("`credit` DESC") + + ; private String value; Field(String value){ this.value = value; diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCUserBasicInfo.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCUserBasicInfo.java index 0429fbc4b..04868da55 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxCUserBasicInfo.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCUserBasicInfo.java @@ -114,9 +114,12 @@ public class WxCUserBasicInfo implements Serializable { @io.swagger.annotations.ApiModelProperty(value="会员等级",name="level") private String level; + /**积分**/ + @io.swagger.annotations.ApiModelProperty(value="积分",name="credit") + private Integer credit; @Transient - @Excel(name="标签",width = 20,orderNum = "10") + @Excel(name="标签",width = 50,orderNum = "10") private String tagNames; @@ -304,6 +307,14 @@ public class WxCUserBasicInfo implements Serializable { this.carCount = carCount; } + public Integer getCredit() { + return credit; + } + + public void setCredit(Integer credit) { + this.credit = credit; + } + public static enum Field { Id_ASC("`id` ASC"),Id_DESC("`id` DESC") @@ -319,7 +330,9 @@ public class WxCUserBasicInfo implements Serializable { ,UpdateDate_ASC("`update_date` ASC"),UpdateDate_DESC("`update_date` DESC") ,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC") ,Name_ASC("`name` ASC"),Name_DESC("`name` DESC") - ; + ,Credit_ASC("`credit` ASC"),Credit_DESC("`credit` DESC") + + ; private String value; Field(String value){ this.value = value; diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxScoreRules.java b/mallinkService/src/main/java/com/iformall/domain/po/WxScoreRules.java index d300ad929..ff91974f6 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxScoreRules.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxScoreRules.java @@ -2,6 +2,7 @@ package com.iformall.domain.po; import com.alibaba.fastjson.JSONObject; import com.iformall.enums.EnumScoreType; +import lombok.Data; import javax.persistence.*; import java.util.*; @@ -21,6 +22,7 @@ import java.io.Serializable; */ @Table(name = "wx_score_rules") +@Data public class WxScoreRules implements Serializable { private static final long serialVersionUID = 1L; @@ -35,7 +37,11 @@ public class WxScoreRules implements Serializable { " {\"businessId\":3,\"limit\":0,\"step\":1,\"score\":50 ,\"desc\":\"线上交易1元\"}," + " {\"businessId\":4,\"limit\":0,\"step\":1,\"score\":50 ,\"desc\":\"线上交易1元\"}," + " {\"businessId\":5,\"limit\":0,\"step\":1,\"score\":50 ,\"desc\":\"线上交易1元\"}," + - " {\"businessId\":6,\"limit\":0,\"step\":1,\"score\":50 ,\"desc\":\"线上交易1元\"}" + + " {\"businessId\":6,\"limit\":0,\"step\":1,\"score\":50 ,\"desc\":\"线上交易1元\"}," + + " {\"businessId\":7,\"limit\":0,\"step\":1,\"score\":50 ,\"desc\":\"线上交易1元\"}," + + " {\"businessId\":8,\"limit\":0,\"step\":1,\"score\":50 ,\"desc\":\"线上交易1元\"}," + + " {\"businessId\":9,\"limit\":0,\"step\":1,\"score\":50 ,\"desc\":\"线上交易1元\"}," + + " {\"businessId\":10,\"limit\":0,\"step\":1,\"score\":50 ,\"desc\":\"线上交易1元\"}" + "]}," + "{\"id\":3,\"limit\":1,\"step\":1,\"score\":100,\"desc\":\"绑定车牌1个\"}," + "{\"id\":4,\"limit\":0,\"step\":1,\"score\":10 ,\"desc\":\"连接WIFI1次\"}," + @@ -95,6 +101,11 @@ public class WxScoreRules implements Serializable { @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") private Date updateDate; + @io.swagger.annotations.ApiModelProperty(value="1成长值 2积分",name="type") + private Integer type; + + @io.swagger.annotations.ApiModelProperty(value="清除前多少年积分",name="clearYear") + private Integer clearYear; public String getTenantId() { return tenantId; @@ -227,4 +238,5 @@ public class WxScoreRules implements Serializable { this.setSortColumns(Field.valueOf(sortColumns)); } } + } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxShop.java b/mallinkService/src/main/java/com/iformall/domain/po/WxShop.java index 878e050c0..45459b3fd 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxShop.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxShop.java @@ -126,6 +126,17 @@ public class WxShop implements Serializable { @io.swagger.annotations.ApiModelProperty(value = "邮箱", name = "email") private String email; + @io.swagger.annotations.ApiModelProperty(value = "是否删除1是0否", name = " ") + private Integer isDel; + + public Integer getIsDel() { + return isDel; + } + + public void setIsDel(Integer isDel) { + this.isDel = isDel; + } + public String getEmail() { return email; } diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/WxBillAllVo.java b/mallinkService/src/main/java/com/iformall/domain/vo/WxBillAllVo.java new file mode 100644 index 000000000..0d8cc3b38 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/vo/WxBillAllVo.java @@ -0,0 +1,265 @@ +package com.iformall.domain.vo; + +import cn.afterturn.easypoi.excel.annotation.Excel; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @author gongbiao + */ +public class WxBillAllVo { + Long id; + + String tenantId; + + Long merchantId; + + Long shopId; + + //@Excel(name="商铺号",width = 20,orderNum = "1") + String shopNumber; + + //@Excel(name="商户名称",width = 20,orderNum = "2") + String merchantName; + + //@Excel(name="商铺类型",width = 20,orderNum = "3", replace = {"店铺_1","多经点位_2"}) + Integer rentShopType; + + @Excel(name="费用类型",width = 20,orderNum = "4") + String billType; + + @Excel(name="实际应收金额(元)",width = 20,orderNum = "5") + String receivePayStr; + + @Excel(name="实收金额(元)",width = 20,orderNum = "6") + String payStr; + + @Excel(name="欠缴金额(元)",width = 20,orderNum = "7") + String oweStr; + + @Excel(name="缴款截止日期",width = 20,orderNum = "8", format="yyyy-MM-dd") + Date receiveDate; + + @Excel(name="逾期天数",width = 20,orderNum = "9") + Integer expiredDay; + + @Excel(name="账单状态",width = 20,orderNum = "10", replace = {"欠缴_1","待缴_2","已结清_3","未到期_4","已退还_5","失效_6"}) + Integer status; + + Integer billTypeValue; + Integer needPay; + Integer receivePay; + Integer pay; + Integer owe; + Date payDate; + Date starttime; + Date endtime; + + String manager; + String managerPhone; + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getMerchantId() { + return merchantId; + } + + public void setMerchantId(Long merchantId) { + this.merchantId = merchantId; + } + + public Long getShopId() { + return shopId; + } + + public void setShopId(Long shopId) { + this.shopId = shopId; + } + + public Integer getBillTypeValue() { + return billTypeValue; + } + + public void setBillTypeValue(Integer billTypeValue) { + this.billTypeValue = billTypeValue; + } + + public String getBillType() { + return billType; + } + + public void setBillType(String billType) { + this.billType = billType; + } + + public Integer getNeedPay() { + return needPay; + } + + public void setNeedPay(Integer needPay) { + this.needPay = needPay; + } + + public Integer getReceivePay() { + return receivePay; + } + + public void setReceivePay(Integer receivePay) { + this.receivePay = receivePay; + } + + public Integer getPay() { + return pay; + } + + public void setPay(Integer pay) { + this.pay = pay; + } + + public Integer getOwe() { + return owe; + } + + public void setOwe(Integer owe) { + this.owe = owe; + } + + public Date getReceiveDate() { + return receiveDate; + } + + public void setReceiveDate(Date receiveDate) { + this.receiveDate = receiveDate; + } + + public Date getPayDate() { + return payDate; + } + + public void setPayDate(Date payDate) { + this.payDate = payDate; + } + + public Integer getExpiredDay() { + return expiredDay; + } + + public void setExpiredDay(Integer expiredDay) { + this.expiredDay = expiredDay; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + public String getTenantId() { + return tenantId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + public Date getStarttime() { + return starttime; + } + + public void setStarttime(Date starttime) { + this.starttime = starttime; + } + + public Date getEndtime() { + return endtime; + } + + public void setEndtime(Date endtime) { + this.endtime = endtime; + } + + + public Integer getRentShopType() { + return rentShopType; + } + + public void setRentShopType(Integer rentShopType) { + this.rentShopType = rentShopType; + } + + public String getMerchantName() { + return merchantName; + } + + public void setMerchantName(String merchantName) { + this.merchantName = merchantName; + } + + public String getShopNumber() { + return shopNumber; + } + + public void setShopNumber(String shopNumber) { + this.shopNumber = shopNumber; + } + + public String getManager() { + return manager; + } + + public void setManager(String manager) { + this.manager = manager; + } + + public String getManagerPhone() { + return managerPhone; + } + + public void setManagerPhone(String managerPhone) { + this.managerPhone = managerPhone; + } + + + public String getReceivePayStr() { + if(getReceivePay()!=null) { + receivePayStr = new BigDecimal(getReceivePay()).divide(new BigDecimal(100)).toString(); + } + return receivePayStr; + } + + public void setReceivePayStr(String receivePayStr) { + this.receivePayStr = receivePayStr; + } + + public String getPayStr() { + if(getPay()!=null) { + payStr = new BigDecimal(getPay()).divide(new BigDecimal(100)).toString(); + } + return payStr; + } + + public void setPayStr(String payStr) { + this.payStr = payStr; + } + + public String getOweStr() { + if(getOwe()!=null) { + oweStr = new BigDecimal(getOwe()).divide(new BigDecimal(100)).toString(); + } + return oweStr; + } + + public void setOweStr(String oweStr) { + this.oweStr = oweStr; + } +} diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumBillAction.java b/mallinkService/src/main/java/com/iformall/enums/EnumBillAction.java new file mode 100644 index 000000000..d0967c9cf --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/enums/EnumBillAction.java @@ -0,0 +1,39 @@ +package com.iformall.enums; + + +/** + * @author gongbiao + */ + +public enum EnumBillAction { + SELF_SERVICE_PAY(1, "自助缴费"), + UPDATE_BILL(2, "变更账单"), + OFFLINE_PAY(3, "线下缴费"), + DEPOSIT_PAY(4, "押金缴费"), + DEPOSIT_RETURN(5, "押金退款"),; + + public static EnumBillAction getEnum(Integer code) { + for (EnumBillAction value : values()) { + if (value.getCode().equals(code)) { + return value; + } + } + return null; + } + + private Integer code; + private String message; + + EnumBillAction(Integer code, String message) { + this.code = code; + this.message = message; + } + + public Integer getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumBusiness.java b/mallinkService/src/main/java/com/iformall/enums/EnumBusiness.java index 29cbcb08e..0e52ff16b 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumBusiness.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumBusiness.java @@ -12,7 +12,12 @@ public enum EnumBusiness { BUSINESS_ID3(3, "服饰"), BUSINESS_ID4(4, "亲子"), BUSINESS_ID5(5, "超市"), - BUSINESS_ID6(6, "其他"), + BUSINESS_ID6(6, "其它"), + BUSINESS_ID7(7, "美妆"), + BUSINESS_ID8(8, "珠宝"), + BUSINESS_ID9(9, "服务"), + BUSINESS_ID10(10, "家居") + ; public static EnumBusiness getEnum(Integer code) { diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumChart.java b/mallinkService/src/main/java/com/iformall/enums/EnumChart.java index ac74c6d6d..8a5313bbd 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumChart.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumChart.java @@ -13,7 +13,7 @@ public enum EnumChart { HYYHSJ(6, "活跃用户数据"), XSSJ(7, "销售数据"), JDSJ(8, "解单数据"), - JRCNCLL(9, "今日场内车流量"), + JRCNCLL(9, "今日场内车流量"), // 合并至历史车流量 JRYBCPL(10, "今日已绑车牌量"), SSCLL(11, "实时车流量"), LSCLL(12, "历史车流量"), diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumScoreType.java b/mallinkService/src/main/java/com/iformall/enums/EnumScoreType.java index bd99dfa10..8a835cfab 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumScoreType.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumScoreType.java @@ -13,7 +13,9 @@ public enum EnumScoreType { WECHAT_PHONE(6, "微信用户手机授权"), COMPLETE_INFO(7, "完善个人信息"), MEM_IMPORT(8, "会员导入"), - MEM_REDUCE(9, "会员成长值扣减"); + MEM_REDUCE(9, "会员成长值扣减"), + SPEND_CREDIT(10, "消费积分"), + CHANGE_CREDIT(11, "积分兑换"); public static EnumScoreType getEnum(Integer code) { for (EnumScoreType value : values()) { diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxBillActionMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxBillActionMapper.java new file mode 100644 index 000000000..7788f7539 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/mapper/WxBillActionMapper.java @@ -0,0 +1,16 @@ +package com.iformall.mapper; + +import com.iformall.common.CommonMapper; +import com.iformall.domain.po.WxBillAction; +import com.iformall.domain.po.WxShop; + +import java.util.List; + +/** + * @author gongbiao + */ +public interface WxBillActionMapper extends CommonMapper { + + List findList(WxBillAction wxBillAction); + +} diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxBillAllMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxBillAllMapper.java index 34a640333..fdfe9a9c0 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxBillAllMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxBillAllMapper.java @@ -1,6 +1,7 @@ package com.iformall.mapper; import com.iformall.domain.vo.WxBillAll; +import com.iformall.domain.vo.WxBillAllVo; import java.util.List; import java.util.Map; @@ -11,7 +12,7 @@ import java.util.Map; public interface WxBillAllMapper { - List> list(WxBillAll record); + List list(WxBillAll record); Map queryOweInfo(WxBillAll record); diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxCreditHistoryMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxCreditHistoryMapper.java index b4c6ebe59..a6c101581 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxCreditHistoryMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxCreditHistoryMapper.java @@ -2,6 +2,7 @@ package com.iformall.mapper; import java.util.*; import com.iformall.common.CommonMapper; +import com.iformall.domain.po.WxScoreHistory; import com.iformall.domain.vo.WxCreditHistoryVo; import com.iformall.domain.po.WxCreditHistory; @@ -11,5 +12,10 @@ public interface WxCreditHistoryMapper extends CommonMapper findListMore(WxCreditHistory wxCreditHistory); - + int loginCount(WxCreditHistory wxCreditHistory); + + int creditAmount(Long cUserId); + + int countList(WxCreditHistory wxCreditHistory); + } diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxRentContractMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxRentContractMapper.java index ed8154972..e848b0f5f 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxRentContractMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxRentContractMapper.java @@ -9,7 +9,7 @@ import java.util.Map; /** * @author gongbiao */ -public interface WxRentContractMapper extends CommonMapper { +public interface WxRentContractMapper extends CommonMapper { List findList(WxRentContract wxRentContract); @@ -47,4 +47,6 @@ public interface WxRentContractMapper extends CommonMapper getMerchants(WxRentContract wxRentContract); + int selectRentContractCountByShopId(WxRentContract wxRentContract); + } diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxTagsMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxTagsMapper.java index dbb6aafe9..ede14b761 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxTagsMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxTagsMapper.java @@ -4,9 +4,11 @@ import com.iformall.common.CommonMapper; import com.iformall.domain.po.WxTags; import java.util.List; +import java.util.Map; public interface WxTagsMapper extends CommonMapper { List findList(WxTags wxTags); + List findListAll(); List getByName(String name); } diff --git a/mallinkService/src/main/java/com/iformall/service/WxBillActionService.java b/mallinkService/src/main/java/com/iformall/service/WxBillActionService.java new file mode 100644 index 000000000..3c622e393 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/WxBillActionService.java @@ -0,0 +1,10 @@ +package com.iformall.service; + +import com.github.pagehelper.PageInfo; +import com.iformall.domain.po.WxBillAction; + +public interface WxBillActionService { + + PageInfo listAsPage(WxBillAction record, Integer pageIndex, Integer pageSize); + +} diff --git a/mallinkService/src/main/java/com/iformall/service/WxCreditHistoryService.java b/mallinkService/src/main/java/com/iformall/service/WxCreditHistoryService.java index 950597666..7816fdf3c 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxCreditHistoryService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxCreditHistoryService.java @@ -2,6 +2,7 @@ package com.iformall.service; import java.util.*; import com.github.pagehelper.PageInfo; +import com.iformall.common.ResultData; import com.iformall.domain.dto.WxCreditHistoryDto; import com.iformall.domain.po.WxCreditHistory; import com.iformall.domain.vo.WxCreditHistoryVo; @@ -41,7 +42,7 @@ public interface WxCreditHistoryService { * * @param record */ - void saveOrUpdate(WxCreditHistory record); + ResultData saveOrUpdate(WxCreditHistory record); /** * 根据Id删除实体 diff --git a/mallinkService/src/main/java/com/iformall/service/WxScoreRulesService.java b/mallinkService/src/main/java/com/iformall/service/WxScoreRulesService.java index 9d5777d87..d85a30a37 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxScoreRulesService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxScoreRulesService.java @@ -11,6 +11,13 @@ public interface WxScoreRulesService { * @return */ WxScoreRules getScoreRules(String tenantId); + + /** + * 获取租户的积分规则 + * @param tenantId + * @return + */ + WxScoreRules getCreditRules(String tenantId); /** * 保存或更新实体 * diff --git a/mallinkService/src/main/java/com/iformall/service/WxShopService.java b/mallinkService/src/main/java/com/iformall/service/WxShopService.java index 728097b45..9144242b8 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxShopService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxShopService.java @@ -42,7 +42,7 @@ public interface WxShopService { * @param id * @param isAdmin */ - void deleteById(Long id, Integer isAdmin); + ResultData deleteById(Long id, Integer isAdmin); ResultData getbshoplist(String tenantId, String shopNumber); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBillActionServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBillActionServiceImpl.java new file mode 100644 index 000000000..12bb35239 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBillActionServiceImpl.java @@ -0,0 +1,28 @@ +package com.iformall.service.impl; + +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.iformall.domain.po.WxBillAction; +import com.iformall.mapper.WxBillActionMapper; +import com.iformall.service.WxBillActionService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @author gongbiao + */ +@Service +public class WxBillActionServiceImpl implements WxBillActionService { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + WxBillActionMapper wxBillActionMapper; + + @Override + public PageInfo listAsPage(WxBillAction record, Integer pageIndex, Integer pageSize) { + logger.info("查询账单操作记录列表"); + return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxBillActionMapper.findList(record)); + } +} diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java index 9a288a7ef..86c4d3a4a 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java @@ -1,15 +1,16 @@ package com.iformall.service.impl; +import cn.afterturn.easypoi.excel.entity.ExportParams; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.iformall.common.ErrorCode; import com.iformall.common.ResultData; import com.iformall.domain.po.*; import com.iformall.domain.vo.WxBillAll; +import com.iformall.domain.vo.WxBillAllVo; import com.iformall.enums.*; import com.iformall.exception.MallinkException; import com.iformall.mapper.*; -import com.iformall.mq.MqBaseProducer; import com.iformall.service.*; import com.iformall.utils.Constant; import com.iformall.utils.DateUtils; @@ -21,6 +22,7 @@ import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -32,6 +34,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.*; import java.math.BigDecimal; import java.math.RoundingMode; + import java.util.*; import java.util.stream.Collectors; @@ -87,6 +90,9 @@ public class WxBillAllServiceImpl implements WxBillAllService { @Autowired WxBillOtherDepositMapper wxBillOtherDepositMapper; + @Autowired + ExcelService excelService; + @Autowired MqBaseProducer mqBaseProducer; @@ -94,9 +100,8 @@ public class WxBillAllServiceImpl implements WxBillAllService { public Map listAsPage(WxBillAll record, Integer pageIndex, Integer pageSize) { //更新各账单状态 updateBillStatus(record); - PageHelper.startPage(pageIndex, pageSize); - List> billList = wxBillAllMapper.list(record); - PageInfo> pageInfo = new PageInfo<>(billList); + PageInfo pageInfo = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxBillAllMapper.list(record)); + Map result = new HashMap<>(); result.put("pageInfo", pageInfo); return result; @@ -202,6 +207,37 @@ public class WxBillAllServiceImpl implements WxBillAllService { } } + @Override + public void exportBill(HttpServletRequest request, HttpServletResponse response, WxBillAll wxBillAll) { + + Map> billMapList = wxBillAllMapper.list(wxBillAll) + .parallelStream() + .collect(Collectors.groupingBy(WxBillAllVo::getMerchantId)); + + List> list = new ArrayList<>(); + + Iterator>> entries = billMapList.entrySet().iterator(); + while (entries.hasNext()) { + Map.Entry> entry = entries.next(); + Map map = new HashMap<>(); + ExportParams deptExportParams = new ExportParams(); + WxBillAllVo first = ((List)(entry.getValue())).get(0); + deptExportParams.setSheetName(first.getMerchantName()); + deptExportParams.setTitle(first.getMerchantName() + + " (" + + EnumRentShopType.getEnum((Integer)first.getRentShopType()).getMessage() + + "-"+first.getShopNumber() + + ")"); + //deptExportParams.setSecondTitle(); + map.put("title", deptExportParams); + map.put("entity", WxBillAllVo.class); + map.put("data", entry.getValue()); + list.add(map); + } + + excelService.exportExcel(list, "账单数据.xls", response); + } +/* @Override public void exportBill(HttpServletRequest request, HttpServletResponse response, WxBillAll wxBillAll) { //得到当前月 @@ -341,7 +377,7 @@ public class WxBillAllServiceImpl implements WxBillAllService { e.printStackTrace(); } } - +*/ private int updateBillOther(Map bill) { logger.info("updateBillOther params:"+bill.toString()); Object id = bill.get("id"); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCUserBasicInfoServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCUserBasicInfoServiceImpl.java index 5f55f7314..f4799ad98 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCUserBasicInfoServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCUserBasicInfoServiceImpl.java @@ -1,5 +1,6 @@ package com.iformall.service.impl; +import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; @@ -33,6 +34,7 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; @Service public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { @@ -148,6 +150,13 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { public void exportData(WxCUserBasicInfo basicInfo, HttpServletRequest request, HttpServletResponse response) { List list = wxCUserBasicInfoMapper.findVoList(basicInfo); + List tagList = wxTagsMapper.findListAll(); + Map tagMap = tagList.stream().collect(Collectors.toMap(WxTags::getId, WxTags::getName)); + list.stream().filter(u->u.getTags()!=null).forEach(u->{ + List ids = JSONObject.parseArray(u.getTags(), Long.class); + String tagNames = StringUtils.join(ids.stream().map(id->tagMap.get(id)).collect(Collectors.toList()),"/"); + u.setTagNames(tagNames); + }); excelService.exportExcel(list,null,"会员信息",WxCUserBasicInfoVo.class,"会员信息数据.xls",response); } /* @@ -166,8 +175,7 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - WxTags wxTagsQ = new WxTags(); - List tagList = wxTagsMapper.findList(wxTagsQ); + List tagIdList = new ArrayList(); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java index 8903a84ef..3f61e9744 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java @@ -594,7 +594,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { e.printStackTrace(); } } -*/ + public void downFile(String filePath, String filename, String exportFileName, HttpServletResponse response, HttpServletRequest req) throws IOException { try { @@ -624,5 +624,5 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { e.printStackTrace(); } } - +*/ } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxChartServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxChartServiceImpl.java index 4f4546088..f7e679caf 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxChartServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxChartServiceImpl.java @@ -3,6 +3,7 @@ package com.iformall.service.impl; import com.alibaba.fastjson.JSON; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import com.iformall.common.ErrorCode; import com.iformall.common.ResultData; import com.iformall.domain.dto.WxCUserBasicInfoDto; import com.iformall.domain.po.*; @@ -78,1614 +79,2026 @@ public class WxChartServiceImpl implements WxChartDataService { } //出租率 - HashMap datamap = new HashMap<>(); if (chart.equals(EnumChart.CZL.getCode())) { - WxShop wxShop = new WxShop(); - wxShop.setTenantId(tenantId); - wxShop.setStatus(EnumShopStatus.RENT.getCode()); - List yczlist = wxShopMapper.findList(wxShop); - wxShop.setStatus(EnumShopStatus.NOT_RENT.getCode()); - List wczlist = wxShopMapper.findList(wxShop); - //出租与未出租 - int yczsize = yczlist.size(); - int wczsize = wczlist.size(); - int size = yczsize + wczsize; - if (size == 0) { - datamap.put("yczsl", 0); - datamap.put("wczsl", 0); - datamap.put("yczl", 0); - datamap.put("wczl", 0); - } else { - datamap.put("yczsl", yczsize); - datamap.put("wczsl", wczsize); - double yczld = ((double) yczsize / size) * 100; - double dczl = new BigDecimal(yczld).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - double wczld = ((double) wczsize / size) * 100; - double wczl = new BigDecimal(wczld).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - datamap.put("yczl", dczl); - datamap.put("wczl", wczl); - } - return new ResultData(datamap); + return getRentRate(tenantId); } //租金收缴率 if (chart.equals(EnumChart.ZJSJL.getCode())) { - //租金 - Map params = new HashMap<>(); - params.put("tenantId", tenantId); - params.put("startdate", startdate + " 00:00:00"); - params.put("enddate", enddate + " 23:59:59"); - Map payinfo = wxBillRentMapper.queryPayInfo(params); - if (payinfo != null) { - BigDecimal receivepay = (BigDecimal) payinfo.get("receivepay"); - BigDecimal pay = (BigDecimal) payinfo.get("pay"); - if (receivepay.doubleValue() > 0) { - BigDecimal divide = pay.divide(receivepay, 2, BigDecimal.ROUND_HALF_UP); - double zjcjl = divide.multiply(new BigDecimal(100)).doubleValue(); - datamap.put("ysje", receivepay); - datamap.put("ssje", pay); - datamap.put("zjsjl", zjcjl); - } else { - datamap.put("ysje", 0); - datamap.put("ssje", 0); - datamap.put("zjsjl", 0); - } - } else { - datamap.put("ysje", 0); - datamap.put("ssje", 0); - datamap.put("zjsjl", 0); - } - return new ResultData(datamap); + return getRentMoneyRate(tenantId, startdate, enddate); } //昨日报单率 if (chart.equals(EnumChart.ZRBDL.getCode())) { - WxMerchant wxMerchant = new WxMerchant(); - wxMerchant.setTenantId(tenantId); - wxMerchant.setStatus(1); - List merchants = wxMerchantMapper.findList(wxMerchant); - WxMerchantTradeDaily wxMerchantTradeDaily = new WxMerchantTradeDaily(); - wxMerchantTradeDaily.setTenantId(tenantId); - String reportdate = DateUtils.getTimeBefore(1, new Date()); - wxMerchantTradeDaily.setReportDate(reportdate); - List tradelist = wxMerchantTradeDailyMapper.findList(wxMerchantTradeDaily); - int merchantsize = merchants.size(); - int tradesize = tradelist.size(); - if (merchantsize > 0 && tradesize > 0) { - double shsbld = ((double) tradesize / merchantsize) * 100; - double shsbl = new BigDecimal(shsbld).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - datamap.put("shsbl", shsbl); - } else { - datamap.put("shsbl", 0); - } - int shsbjg = tradelist.stream().mapToInt(WxMerchantTradeDaily::getTradeAmt).sum(); - datamap.put("shsbjg", shsbjg); - return new ResultData(datamap); + return getYesterdayTradeRate(tenantId); } //车流数据 if (chart.equals(EnumChart.CLSJ.getCode())) { - HashMap params = new HashMap<>(); - params.put("tenantId", tenantId); - params.put("cmdType", EnumCarCmd.CAR_ETCP_CALLBACK_PARK_OUT.getCode()); - startdate = DateUtils.getTimeBefore(30, new Date()); - String systemTime = DateUtils.getSystemTime("yyyy-MM-dd"); - - List tjTimeList = DateUtils.getTjTimeList(startdate, systemTime, "0"); - - params.put("startdate", startdate + " 00:00:00"); - params.put("enddate", systemTime + " 23:59:59"); - - List> historylist = wxCarCmdLogMapper.queryHistory(params); - - Map collect = historylist.stream().collect(Collectors.toMap(m -> { - return m.get("create_date"); - }, m -> { - return m.get("carcount"); - })); - - Map historymap = new LinkedHashMap<>(); - for (String date : tjTimeList) { - Object o = collect.get(date); - if (o == null) { - historymap.put(date.substring(5).replace("-", "/"), 0L); - } else { - historymap.put(date.substring(5).replace("-", "/"), o); - } - } - datamap.put("history", historymap); - return new ResultData(datamap); + return getCarHistoryAndTodayAndHB(tenantId, false); } //券交易数据 if (chart.equals(EnumChart.QJYSJ.getCode())) { - //couponData - HashMap params = new HashMap<>(); - params.put("tenantId", tenantId); - params.put("startTime", addDay(-30)); - params.put("endTime", addDay(1)); - List couponDatalist = wxCouponOrderMapper.couponDataMap(params); - //查询券领取人数 - startdate = DateUtils.getTimeBefore(30, new Date()); - enddate = DateUtils.getTimeBefore(1, new Date()); - List tjTimeList = DateUtils.getTjTimeList(startdate, enddate, "0"); - List tjList = tjTimeList.stream().map(d -> d.substring(5).replace("-", "/")).collect(Collectors.toList()); - List couponTempDatalist = new LinkedList<>(); - for (String tj : tjList) { - Optional first = couponDatalist.stream().filter(c -> c.getCreateTime().equals(tj)).findFirst(); - if (!first.isPresent()) { - MarkingCouponDataReportVo markingCouponDataReportVo = new MarkingCouponDataReportVo(); - markingCouponDataReportVo.setCreateTime(tj); - markingCouponDataReportVo.setCouponCount(0); - markingCouponDataReportVo.setCouponUserCount(0); - markingCouponDataReportVo.setVerifyCount(0); - markingCouponDataReportVo.setVerifyUserCount(0); - couponTempDatalist.add(markingCouponDataReportVo); - continue; - } - couponTempDatalist.add(first.get()); - } - datamap.put("couponDataMap", couponTempDatalist); - return new ResultData(datamap); + return getCouponSaleAnalysis(tenantId); } //活跃用户数据 if (chart.equals(EnumChart.HYYHSJ.getCode())) { - HashMap params = new HashMap<>(); - Calendar c = Calendar.getInstance(); - c.add(Calendar.DAY_OF_YEAR, -1); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - Date endTime = c.getTime(); - c.add(Calendar.DAY_OF_YEAR, -30); - Date startTime = c.getTime(); - params.put("startTime", startTime); - params.put("endTime", endTime); - params.put("tenantId", tenantId); - List list = wxUserVisitMapper.touchUsersReportList(params); - Map dateMap = new HashMap<>(); - for (TouchUsersReportVo vo : list) { - dateMap.put(vo.getxTime(), vo); - } - List monthVos = new ArrayList<>();//每月uv - for (int i = 29, sortNum = 0; i >= 0; i--) { - c.clear(); - c.setTime(endTime); - c.add(Calendar.DAY_OF_YEAR, -i); - String dayStr = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()); - UserStructureVo vo = new UserStructureVo(); - vo.setName(new SimpleDateFormat("MM/dd").format(c.getTime())); - vo.setSortNum(sortNum++); - if (dateMap.get(dayStr) != null) { - TouchUsersReportVo rv = dateMap.get(dayStr); - Long l = new Long((long) rv.getUv()); - vo.setCount(l); - } else { - vo.setCount(0); - } - monthVos.add(vo); - } - datamap.put("monthVos", monthVos);//月活跃数列表 - return new ResultData(datamap); + // TODO getActiveMemberAnalysis + return getActiveMemberTrade(tenantId); } //销售数据 if (chart.equals(EnumChart.XSSJ.getCode())) { - Calendar c = Calendar.getInstance(); - Date sTime = c.getTime(); - c.add(Calendar.DAY_OF_YEAR, 1); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - Date eTime = c.getTime();//明天0点 - c.add(Calendar.DAY_OF_YEAR, -30);//三十天前 - List datas = wxCouponOrderMapper.queryPriceTotalGroup(tenantId, sTime, eTime); - List monthVos = new ArrayList<>();//周消费金额 - Map dataMap = new HashMap<>(); - for (CUserDateAmountVo v : datas) { - dataMap.put(v.getxTime(), v.getPrice()); - } - for (int i = 29, sortNum = 0; i >= 0; i--) { - c.clear(); - c.setTime(sTime); - c.add(Calendar.DAY_OF_YEAR, -i); - String dateStr = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()); - UserStructureVo vo = new UserStructureVo(); - vo.setName(new SimpleDateFormat("MM/dd").format(c.getTime())); - vo.setSortNum(sortNum++); - if (datamap.get(dateStr) != null) { - int price = dataMap.get(dateStr); - vo.setPrice(price); - } else { - vo.setPrice(0); - } - monthVos.add(vo); - } - datamap.put("monthVos", monthVos);//一月金额列表 - return new ResultData(datamap); + return getSaleAnalysis(tenantId); } //解单数据 if (chart.equals(EnumChart.JDSJ.getCode())) { - WxMerchantTradeDaily wxMerchantTradeDaily = new WxMerchantTradeDaily(); - wxMerchantTradeDaily.setTenantId(tenantId); - - List recordList = wxMerchantTradeDailyMapper.findTotalListOfMonth(wxMerchantTradeDaily); - Map recordMap = recordList.stream().collect(Collectors.toMap(WxMerchantTradeDaily::getReportDate, r -> r)); - - List tradeList = new ArrayList<>(); - Calendar cal = Calendar.getInstance(); - SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd"); - SimpleDateFormat fmtv = new SimpleDateFormat("MM/dd"); - cal.setTime(new Date()); - for (int i = 0; i < 30; i++) { - cal.add(Calendar.DAY_OF_YEAR, -1); - WxMerchantTradeDaily trade = recordMap.get(fmt.format(cal.getTime())); - if (trade != null) { - trade.setReportDate(fmtv.format(cal.getTime())); - tradeList.add(trade); - } else { - trade = new WxMerchantTradeDaily(); - trade.setTradeAmt(0); - trade.setReportDate(fmtv.format(cal.getTime())); - tradeList.add(trade); - } - } - Collections.reverse(tradeList); - return new ResultData(tradeList); - } - //今日场内车流量 - if (chart.equals(EnumChart.JRCNCLL.getCode())) { - HashMap params = new HashMap<>(); - params.put("tenantId", tenantId); - params.put("cmdType", EnumCarCmd.CAR_ETCP_CALLBACK_PARK_OUT.getCode()); - startdate = DateUtils.getTimeBefore(7, new Date()); - String systemTime = DateUtils.getSystemTime("yyyy-MM-dd"); - List tjTimeList = DateUtils.getTjTimeList(startdate, systemTime, "0"); - params.put("startdate", startdate + " 00:00:00"); - params.put("enddate", systemTime + " 23:59:59"); - List> historylist = wxCarCmdLogMapper.queryHistory(params); - Map collect = historylist.stream().collect(Collectors.toMap(m -> { - return m.get("create_date"); - }, m -> { - return m.get("carcount"); - })); - Map historymap = new LinkedHashMap<>(); - for (String date : tjTimeList) { - Object o = collect.get(date); - if (o == null) { - historymap.put(date.substring(5).replace("-", "/"), 0L); - } else { - historymap.put(date.substring(5).replace("-", "/"), o); - } - } - datamap.put("history", historymap); - //今日车流量 - long todaycar = (long) historymap.get(DateUtils.getSystemTime("MM/dd")); - datamap.put("todaycar", todaycar); - //环比 - String yesterday = DateUtils.getTimeBefore(1, new Date()); - long yesterdaycar = (long) historymap.get(yesterday.substring(5).replace("-", "/")); - if (yesterdaycar > 0) { - double hbd = (double) (todaycar - yesterdaycar) / yesterdaycar * 100; - double hb = new BigDecimal(hbd).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - datamap.put("hb", hb + "%"); - } else { - datamap.put("hb", "--"); - } - //上周同期 - String lastweek = DateUtils.getTimeBefore(7, new Date()); - long last = (long) historymap.get(lastweek.substring(5).replace("-", "/")); - if (last > 0) { - double lasthbd = (double) (todaycar - last) / last * 100; - double lasthb = new BigDecimal(lasthbd).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - datamap.put("lasthb", lasthb + "%"); - } else { - datamap.put("lasthb", "--"); - } - return new ResultData(datamap); - + return getMerchantTradeMonthly(tenantId); } + + ///// --- 车流 -- START //今日已绑车牌量 if (chart.equals(EnumChart.JRYBCPL.getCode())) { - String yesterday = DateUtils.getTimeBefore(1, new Date()); - String lastweek = DateUtils.getTimeBefore(7, new Date()); - //绑定车牌 - Map carParams = new HashMap<>(); - carParams.put("tenantId", tenantId); - carParams.put("startdate", DateUtils.getSystemTime("yyyy-MM-dd 00:00:00")); - carParams.put("enddate", DateUtils.getSystemTime("yyyy-MM-dd HH:mm:ss")); - long todaybindcar = wxCUserCarMapper.queryCarCount(carParams); - carParams.put("startdate", yesterday + " 00:00:00"); - carParams.put("enddate", yesterday + " 23:59:59"); - long yesterdaybindcar = wxCUserCarMapper.queryCarCount(carParams); - carParams.put("startdate", lastweek + " 00:00:00"); - carParams.put("enddate", lastweek + " 23:59:59"); - long lastweekbindcar = wxCUserCarMapper.queryCarCount(carParams); - datamap.put("todaybindcar", todaybindcar); - if (yesterdaybindcar > 0) { - double yesterdaybinddhb = (double) (todaybindcar - yesterdaybindcar) / yesterdaybindcar * 100; - double yesterdaybindhb = new BigDecimal(yesterdaybinddhb).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - datamap.put("yesterdaybindhb", yesterdaybindhb + "%"); - } else { - datamap.put("yesterdaybindhb", "--"); - } - if (lastweekbindcar > 0) { - double lastweekbinddhb = (double) (todaybindcar - lastweekbindcar) / lastweekbindcar * 100; - double lastweekbindhb = new BigDecimal(lastweekbinddhb).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - datamap.put("lastweekbindhb", lastweekbindhb + "%"); - } else { - datamap.put("lastweekbindhb", "--"); - } - return new ResultData(datamap); + return getBindCarAnalysis(tenantId); } //实时车流量 if (chart.equals(EnumChart.SSCLL.getCode())) { - String systemTime = DateUtils.getSystemTime("yyyy-MM-dd"); - String yesterday = DateUtils.getTimeBefore(1, new Date()); - String lastweek = DateUtils.getTimeBefore(7, new Date()); - HashMap params = new HashMap<>(); - params.put("tenantId", tenantId); - params.put("cmdType", EnumCarCmd.CAR_ETCP_CALLBACK_PARK_OUT.getCode()); - params.put("startdate", systemTime + " 05:00:00"); - params.put("enddate", DateUtils.getSystemTime("yyyy-MM-dd HH:mm:ss")); - List> todayCarlist = wxCarCmdLogMapper.queryTodayCar(params); - Map todaycollect = todayCarlist.stream().collect(Collectors.toMap(m -> { - return m.get("create_time"); - }, m -> { - return m.get("carcount"); - })); - Calendar instance = Calendar.getInstance(); - instance.add(Calendar.HOUR_OF_DAY, 1); - int hour = instance.get(Calendar.HOUR_OF_DAY); - TreeMap hourMap = new TreeMap<>(); - int startHour = 6; - int endHour = 24; - for (int i = startHour; i < endHour; i++) { - if (i <= hour) { - hourMap.put(i < 10 ? "0" + i + ":00" : i + ":00", 0); - } else { - hourMap.put(i < 10 ? "0" + i + ":00" : i + ":00", ""); - } - } - hourMap.putAll(todaycollect); - datamap.put("todaycardata", hourMap); - params.put("startdate", yesterday + " 05:00:00"); - params.put("enddate", yesterday + " 22:59:59"); - List> yesterdayCarlist = wxCarCmdLogMapper.queryTodayCar(params); - Map yesterdaycollect = yesterdayCarlist.stream().collect(Collectors.toMap(m -> { - return m.get("create_time"); - }, m -> { - return m.get("carcount"); - })); - TreeMap yesterdaytreemap = getTimeTreeMap(); - yesterdaytreemap.putAll(yesterdaycollect); - - datamap.put("yesterdaycardata", yesterdaytreemap); - - params.put("startdate", lastweek + " 05:00:00"); - params.put("enddate", lastweek + " 22:59:59"); - List> lastdayCarlist = wxCarCmdLogMapper.queryTodayCar(params); - Map lastdaycollect = lastdayCarlist.stream().collect(Collectors.toMap(m -> { - return m.get("create_time"); - }, m -> { - return m.get("carcount"); - })); - TreeMap lastdaytreemap = getTimeTreeMap(); - lastdaytreemap.putAll(lastdaycollect); - datamap.put("lastdaycardata", lastdaytreemap); - - return new ResultData(datamap); - - } - //历史车流量 + return getCarDataCurrent(tenantId); + } + // 历史车流量+今日车流量 + 上周同期 if (chart.equals(EnumChart.LSCLL.getCode())) { - HashMap params = new HashMap<>(); - params.put("tenantId", tenantId); - params.put("cmdType", EnumCarCmd.CAR_ETCP_CALLBACK_PARK_OUT.getCode()); - startdate = DateUtils.getTimeBefore(30, new Date()); - String systemTime = DateUtils.getSystemTime("yyyy-MM-dd"); - - List tjTimeList = DateUtils.getTjTimeList(startdate, systemTime, "0"); - - params.put("startdate", startdate + " 00:00:00"); - params.put("enddate", systemTime + " 23:59:59"); - - List> historylist = wxCarCmdLogMapper.queryHistory(params); - - Map collect = historylist.stream().collect(Collectors.toMap(m -> { - return m.get("create_date"); - }, m -> { - return m.get("carcount"); - })); - - Map historymap = new LinkedHashMap<>(); - for (String date : tjTimeList) { - Object o = collect.get(date); - if (o == null) { - historymap.put(date.substring(5).replace("-", "/"), 0L); - } else { - historymap.put(date.substring(5).replace("-", "/"), o); - } - } - datamap.put("history", historymap); - return new ResultData(datamap); - + return getCarHistoryAndTodayAndHB(tenantId, true); } //近一周新增停车会员 if (chart.equals(EnumChart.JYZXXZTCHY.getCode())) { - String oneWeekStartdate = DateUtils.getTimeBefore(7, new Date()); - String oneWeekEndDate = DateUtils.getTimeBefore(1, new Date()); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - WxCUserBasicInfoDto wxCUserBasicInfoDto = new WxCUserBasicInfoDto(); - wxCUserBasicInfoDto.setTenantId(tenantId); - try { - wxCUserBasicInfoDto.setStartTime(sdf.parse(oneWeekStartdate)); - wxCUserBasicInfoDto.setEndTime(sdf.parse(oneWeekEndDate)); - } catch (Exception e) { - e.printStackTrace(); - } - datamap.put("oneWeekNewCarUserCount", wxCUserCarMapper.countUser(wxCUserBasicInfoDto)); - //停车会员总数 - wxCUserBasicInfoDto = new WxCUserBasicInfoDto(); - wxCUserBasicInfoDto.setTenantId(tenantId); - datamap.put("newCarUserSumCount", wxCUserCarMapper.countUser(wxCUserBasicInfoDto)); - - return new ResultData(datamap); + return getCarNewMemberCount(tenantId); } //近一周线上缴费车辆 if (chart.equals(EnumChart.JYZXSJFCL.getCode())) { - HashMap weekParams = new HashMap<>(); - weekParams.put("tenantId", tenantId); - String oneWeekStartdate = DateUtils.getTimeBefore(7, new Date()); - String oneWeekEndDate = DateUtils.getTimeBefore(1, new Date()); - weekParams.put("startdate", oneWeekStartdate + " 00:00:00"); - weekParams.put("enddate", oneWeekEndDate + " 23:59:59"); - weekParams.put("cmdType", EnumCarCmd.CAR_ETCP_CALLBACK_PAY_MANUAL.getCode()); - datamap.put("oneWeekCarPayCount", wxCarCmdLogMapper.queryWeekCarPayCount(weekParams)); - return new ResultData(datamap); + return getCarPayCarCountInWeek(tenantId); } //近一周线上缴费金额 if (chart.equals(EnumChart.JYZXSJFJE.getCode())) { - HashMap weekParams = new HashMap<>(); - weekParams.put("tenantId", tenantId); - String oneWeekStartdate = DateUtils.getTimeBefore(7, new Date()); - String oneWeekEndDate = DateUtils.getTimeBefore(1, new Date()); - weekParams.put("startdate", oneWeekStartdate + " 00:00:00"); - weekParams.put("enddate", oneWeekEndDate + " 23:59:59"); - weekParams.put("cmdType", EnumCarCmd.CAR_ETCP_CALLBACK_PAY_MANUAL.getCode()); - List> weekCarPayHistoryList = wxCarCmdLogMapper.queryWeekCarPay(weekParams); - Map weekCollect = weekCarPayHistoryList.stream().collect(Collectors.toMap(m -> { - return (String) m.get("create_time"); - }, m -> { - return m.get("fee"); - })); - List days = DateUtils.getTjTimeList(oneWeekStartdate, oneWeekEndDate, "0"); - - TreeMap weekMap = new TreeMap<>(); - for (String date : days) { - weekMap.put(date.substring(5, date.length()).replace("-", "/"), "0"); - } - for (String key : weekCollect.keySet()) { - weekMap.put(key, weekCollect.get(key)); - } - datamap.put("oneWeekCarPayFeeCount", weekMap); - return new ResultData(datamap); + return getCarPayCountInWeek(tenantId); } //近一周新增会员数 if (chart.equals(EnumChart.JYZXZHYS.getCode())) { - HashMap weekParams = new HashMap<>(); - weekParams.put("tenantId", tenantId); - String oneWeekStartdate = DateUtils.getTimeBefore(7, new Date()); - String oneWeekEndDate = DateUtils.getTimeBefore(1, new Date()); - weekParams.put("startdate", oneWeekStartdate + " 00:00:00"); - weekParams.put("enddate", oneWeekEndDate + " 23:59:59"); - weekParams.put("cmdType", EnumCarCmd.CAR_ETCP_CALLBACK_PAY_MANUAL.getCode()); - List> carCountHistory = wxCUserCarMapper.queryCarCountHistory(weekParams); - Map weekCarCollect = carCountHistory.stream().collect(Collectors.toMap(m -> { - return (String) m.get("create_time"); - }, m -> { - return m.get("count"); - })); - List days = DateUtils.getTjTimeList(oneWeekStartdate, oneWeekEndDate, "0"); - TreeMap weekCarMap = new TreeMap<>(); - for (String date : days) { - weekCarMap.put(date.substring(5, date.length()).replace("-", "/"), "0"); - } - for (String key : weekCarCollect.keySet()) { - weekCarMap.put(key, weekCarCollect.get(key)); - } - datamap.put("oneWeekNewCarUserHistory", weekCarMap); + return getCarNewMemberCountInWeek(tenantId); } + //// --- 车流 -- END //昨日触达用户 if (chart.equals(EnumChart.ZRCDYH.getCode())) { - //查询UV PV - HashMap params = new HashMap<>(); - params.put("tenantId", tenantId); - params.put("startTime", addDay(-1)); - params.put("endTime", addDay(1)); - List wxUserVisitList = wxUserVisitMapper.touchUsersReportData(params); - TouchUsersReportVo touchUsersReportVo = new TouchUsersReportVo(); - if (!wxUserVisitList.isEmpty()) { - touchUsersReportVo = wxUserVisitList.get(0); - } else { - touchUsersReportVo.setPv(0); - touchUsersReportVo.setUv(0); - touchUsersReportVo.setCouponCount(0); - touchUsersReportVo.setUserCount(0); - touchUsersReportVo.setVerifyCount(0); - touchUsersReportVo.setVerifyUserCount(0); - touchUsersReportVo.setxTime(DateUtils.getSystemTime("MM/dd")); - } - datamap.put("yesterday", touchUsersReportVo); - return new ResultData(datamap); + return getTodayTouchUser(tenantId); } //今日券交易数据 if (chart.equals(EnumChart.JRQJYSJ.getCode())) { - //今日领取券数 - //查询coupon order表 - int todayCouponCount = wxCouponOrderMapper.findCountByDateLimit(tenantId, addDay(0), addDay(1)); - int yesterdayCount = wxCouponOrderMapper.findCountByDateLimit(tenantId, addDay(-1), addDay(0)); - int lastWeekCount = wxCouponOrderMapper.findCountByDateLimit(tenantId, addDay(-7), addDay(-6)); - NumberFormat nf = NumberFormat.getPercentInstance(); - nf.setMinimumFractionDigits(2);//控制保留小数点后几位,2:表示保留2位小数点 - String couponUpDay = "--"; - if (yesterdayCount != 0) { - couponUpDay = nf.format((todayCouponCount - yesterdayCount) / (float) yesterdayCount); - } - String couponUpWeek = "--"; - if (lastWeekCount != 0) { - couponUpWeek = nf.format((todayCouponCount - lastWeekCount) / (float) lastWeekCount); - } - datamap.put("couponUpDay", couponUpDay);//比昨日提升 - datamap.put("couponUpWeek", couponUpWeek);//比上周提升 - datamap.put("todayCouponCount", todayCouponCount);//今日领取数 - return new ResultData(datamap); + return getTodayCouponCount(tenantId); } //今日场景营销 if (chart.equals(EnumChart.JRCJYX.getCode())) { - int todaySceneCount = wxCouponActionLogMapper.getCountByDateLimit(tenantId, addDay(0), addDay(1)); - int yesterdayCount = wxCouponActionLogMapper.getCountByDateLimit(tenantId, addDay(-1), addDay(0)); - int lastWeekCount = wxCouponActionLogMapper.getCountByDateLimit(tenantId, addDay(-7), addDay(-6)); - NumberFormat nf = NumberFormat.getPercentInstance(); - nf.setMinimumFractionDigits(2);//控制保留小数点后几位,2:表示保留2位小数点 - String sceneDownDay = "--"; - if (yesterdayCount != 0) { - sceneDownDay = nf.format((yesterdayCount - todaySceneCount) / (float) yesterdayCount); - } - String sceneUpWeek = "--"; - if (lastWeekCount != 0) { - sceneUpWeek = nf.format((todaySceneCount - lastWeekCount) / (float) lastWeekCount); - } - datamap.put("sceneDownDay", sceneDownDay);//比昨日下降 - datamap.put("sceneUpWeek", sceneUpWeek);//比上周提升 - datamap.put("todaySceneCount", todaySceneCount);//今日领取数 - return new ResultData(datamap); + return getSaleSceneCount(tenantId); } //触达用户数 if (chart.equals(EnumChart.CDYHS.getCode())) { - //查询UV PV - HashMap params = new HashMap<>(); - params.put("tenantId", tenantId); - params.put("startTime", addDay(-30)); - params.put("endTime", addDay(1)); - List wxUserVisitList = wxUserVisitMapper.touchUsersReportData(params); - startdate = DateUtils.getTimeBefore(30, new Date()); - enddate = DateUtils.getTimeBefore(1, new Date()); - List tjTimeList = DateUtils.getTjTimeList(startdate, enddate, "0"); - List tjList = tjTimeList.stream().map(d -> d.substring(5).replace("-", "/")).collect(Collectors.toList()); - List tempDatalist = new LinkedList<>(); - for (String tj : tjList) { - Optional first = wxUserVisitList.stream().filter(c -> c.getxTime().equals(tj)).findFirst(); - if (!first.isPresent()) { - TouchUsersReportVo touchUsersReportVo = new TouchUsersReportVo(); - touchUsersReportVo.setPv(0); - touchUsersReportVo.setUv(0); - touchUsersReportVo.setCouponCount(0); - touchUsersReportVo.setUserCount(0); - touchUsersReportVo.setVerifyCount(0); - touchUsersReportVo.setVerifyUserCount(0); - touchUsersReportVo.setxTime(tj); - tempDatalist.add(touchUsersReportVo); - continue; - } - tempDatalist.add(first.get()); - } - return new ResultData(tempDatalist); + return getTouchUserCount(tenantId); } //场景营销数据 if (chart.equals(EnumChart.CJYXSJ.getCode())) { - - HashMap params = new HashMap<>(); - params.put("tenantId", tenantId); - params.put("startTime", addDay(-30)); - params.put("endTime", addDay(1)); - //停车发券数 停车发券被核销数 核销发券数 核销发券被核销数 - List list = wxCouponActionLogMapper.sceneDataMap(params); - - //停车发券被核销数 - HashMap params1 = new HashMap<>(); - params1.put("tenantId", tenantId); - params1.put("startTime", addDay(-30)); - params1.put("endTime", addDay(1)); - params1.put("channelType", EnumCouponSendSendType.CAR_STOP.getCode());//停车 - List list1 = wxCouponActionLogMapper.sceneDataMapJoinCouponOrder(params1); - Map parkCountMap = list1.stream().collect(Collectors.toMap(MarkingSceneDataReportVo::getXTime, p -> p.getTempCount())); - - //核销发券被核销数 - HashMap params2 = new HashMap<>(); - params2.put("tenantId", tenantId); - params2.put("startTime", addDay(-30)); - params2.put("endTime", addDay(1)); - params2.put("channelType", EnumCouponSendSendType.COUPON_VERIFY.getCode());//核销 - List list2 = wxCouponActionLogMapper.sceneDataMapJoinCouponOrder(params2); - Map verifyCountMap = list2.stream().collect(Collectors.toMap(MarkingSceneDataReportVo::getXTime, p -> p.getTempCount())); - - // B端刷卡支付被核销数 - HashMap params3 = new HashMap<>(); - params3.put("tenantId", tenantId); - params3.put("startTime", addDay(-30)); - params3.put("endTime", addDay(1)); - params3.put("channelType", EnumCouponSendSendType.B_MICROPAY.getCode());//B端刷卡支付 - List list3 = wxCouponActionLogMapper.sceneDataMapJoinCouponOrder(params3); - Map microPayCountMap = list3.stream().collect(Collectors.toMap(MarkingSceneDataReportVo::getXTime, p -> p.getTempCount())); - - // 购买发券被核销数 - HashMap params4 = new HashMap<>(); - params3.put("tenantId", tenantId); - params3.put("startTime", addDay(-30)); - params3.put("endTime", addDay(1)); - params3.put("channelType", EnumCouponSendSendType.C_ORDER.getCode());//买券 - List list4 = wxCouponActionLogMapper.sceneDataMapJoinCouponOrder(params4); - Map OrderCountMap = list4.stream().collect(Collectors.toMap(MarkingSceneDataReportVo::getXTime, p -> p.getTempCount())); - - for (MarkingSceneDataReportVo vo : list) { - vo.setParkCount(parkCountMap.get(vo.getXTime()) == null ? 0 : parkCountMap.get(vo.getXTime())); - vo.setVerifyCount(verifyCountMap.get(vo.getXTime()) == null ? 0 : verifyCountMap.get(vo.getXTime())); - vo.setMicroPayCount(microPayCountMap.get(vo.getXTime()) == null ? 0 : microPayCountMap.get(vo.getXTime())); - vo.setOrderCount(OrderCountMap.get(vo.getXTime()) == null ? 0 : OrderCountMap.get(vo.getXTime())); - } - - startdate = DateUtils.getTimeBefore(30, new Date()); - enddate = DateUtils.getTimeBefore(1, new Date()); - List tjTimeList = DateUtils.getTjTimeList(startdate, enddate, "0"); - List tjList = tjTimeList.stream().map(d -> d.substring(5).replace("-", "/")).collect(Collectors.toList()); - List tempDatalist = new LinkedList<>(); - - for (String tj : tjList) { - Optional first = list.stream().filter(c -> c.getXTime().equals(tj)).findFirst(); - - MarkingSceneDataReportVo msdVo; - if (!first.isPresent()) { - msdVo = new MarkingSceneDataReportVo(); - msdVo.setXTime(tj); - msdVo.setCarCount(0); - msdVo.setParkCount(0); - msdVo.setVerifyCount(0); - msdVo.setMicroPayCount(0); - msdVo.setOrderCount(0); - msdVo.setTempCount(0); - msdVo.setParkSendCount(0); - msdVo.setVerifySendCount(0); - msdVo.setMicroPaySendCount(0); - msdVo.setOrderSendCount(0); - msdVo.setTotal(0); - } else { - msdVo = first.get(); - msdVo.setTotal(msdVo.getParkSendCount() + - msdVo.getVerifySendCount() + - msdVo.getMicroPaySendCount() + - msdVo.getOrderSendCount()); - } - tempDatalist.add(msdVo); - } - datamap.put("sceneDataMap", tempDatalist); - return new ResultData(datamap); + return getSceneData(tenantId); } //新增用户 if (chart.equals(EnumChart.XZYH.getCode())) { - WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); - dto.setTenantId(tenantId); - long allCount = wxCUserMapper.findCount(dto);//总数 - Calendar c = Calendar.getInstance(); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - Date today = c.getTime(); - c.setTime(today); - c.add(Calendar.DAY_OF_YEAR, -1); - dto.setStartTime(c.getTime()); - c.add(Calendar.DAY_OF_YEAR, 1); - dto.setEndTime(c.getTime()); - long todayCount = wxCUserMapper.findCount(dto); - datamap.put("allCount", allCount);//会员总数 - datamap.put("todayCount", todayCount);//今日新增会员数 - return new ResultData(datamap); + return getNewUserCount(tenantId); } //活跃用户 if (chart.equals(EnumChart.HYYH.getCode())) { - HashMap params = new HashMap<>(); - Calendar c = Calendar.getInstance(); - c.add(Calendar.DAY_OF_YEAR, -1); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - Date endTime = c.getTime(); - c.add(Calendar.DAY_OF_YEAR, -30); - Date startTime = c.getTime(); - params.put("startTime", startTime); - params.put("endTime", endTime); - params.put("tenantId", tenantId); - List list = wxUserVisitMapper.touchUsersReportList(params); - String yesterday = DateUtils.getTimeBefore(1, new Date()); - List collect = list.parallelStream().filter(x -> x.getxTime().equals(yesterday)).collect(Collectors.toList()); - int yesterdayCount = 0; - if (!collect.isEmpty()) { - yesterdayCount = collect.get(0).getUv(); - } - Integer thisMonthCount = list.parallelStream().collect(Collectors.summingInt(u -> u.getUv())); - datamap.put("yesterdayCount", yesterdayCount);//昨日活跃数 - datamap.put("thisMonthCount", thisMonthCount);//近一个月活跃数 - return new ResultData(datamap); + return getActiveMemberCount(tenantId); } //线上交易 if (chart.equals(EnumChart.XSJY.getCode())) { - Calendar c = Calendar.getInstance(); - c.add(Calendar.DAY_OF_YEAR, 1); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - Date endTime = c.getTime();//明天0点 - c.add(Calendar.DAY_OF_YEAR, -30); - Date startTime = c.getTime(); - int thisMonthCount = wxCouponOrderMapper.queryPriceTotal(tenantId, startTime, endTime);//月消费金额 - c.clear(); - c.add(Calendar.DAY_OF_YEAR, -1); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - startTime = c.getTime(); - int todayCount = wxCouponOrderMapper.queryPriceTotal(tenantId, startTime, endTime);//月消费金额 - DecimalFormat df = new DecimalFormat("0.00"); - datamap.put("todayCount", df.format((float) todayCount / 100));//今日消费金额 - String thisMonthCountStr = df.format((float) thisMonthCount / 100); - datamap.put("thisMonthCount", thisMonthCountStr);//近一个月消费金额数 - return new ResultData(datamap); + return getOnlineOrderCount(tenantId); } //近一周新增用户数 if (chart.equals(EnumChart.JYZXZYHS.getCode())) { - WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); - dto.setTenantId(tenantId); - Calendar c = Calendar.getInstance(); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - Date today = c.getTime(); - List weekVos = new ArrayList<>();//周会员数 - for (int i = 7, sortNum = 0; i >= 0; i--) { - c.clear(); - c.setTime(today); - c.add(Calendar.DAY_OF_YEAR, -i); - dto.setStartTime(c.getTime()); - c.add(Calendar.DAY_OF_YEAR, 1); - dto.setEndTime(c.getTime()); - long count = wxCUserMapper.findCount(dto); - UserStructureVo vo = new UserStructureVo(); - vo.setName(new SimpleDateFormat("MM/dd").format(dto.getStartTime())); - vo.setSortNum(sortNum++); - vo.setCount(count); - weekVos.add(vo); - } - datamap.put("weekVos", weekVos);//月用户增加数列表 - return new ResultData(datamap); - + return getNewMemberInWeek(tenantId); } //近一周活跃用户数 if (chart.equals(EnumChart.JYZHYYHS.getCode())) { - HashMap params = new HashMap<>(); - Calendar c = Calendar.getInstance(); - c.add(Calendar.DAY_OF_YEAR, -1); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - Date endTime = c.getTime(); - c.add(Calendar.DAY_OF_YEAR, -7); - Date startTime = c.getTime(); - params.put("startTime", startTime); - params.put("endTime", endTime); - params.put("tenantId", tenantId); - List list = wxUserVisitMapper.touchUsersReportList(params); - Map dateMap = new HashMap<>(); - for (TouchUsersReportVo vo : list) { - dateMap.put(vo.getxTime(), vo); - } - List weekVos = new ArrayList<>();//每周uv - for (int i = 7, sortNum = 0; i >= 0; i--) { - c.clear(); - c.setTime(endTime); - c.add(Calendar.DAY_OF_YEAR, -i); - String dayStr = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()); - UserStructureVo vo = new UserStructureVo(); - vo.setName(new SimpleDateFormat("MM/dd").format(c.getTime())); - vo.setSortNum(sortNum++); - if (dateMap.get(dayStr) != null) { - TouchUsersReportVo rv = dateMap.get(dayStr); - Long l = new Long((long) rv.getUv()); - vo.setCount(l); - } else { - vo.setCount(0); - } - weekVos.add(vo); - } - datamap.put("weekVos", weekVos);//周活跃数列表 - return new ResultData(datamap); - + return getActiveMemberCountInWeek(tenantId); } //近一周线上交易金额(元) if (chart.equals(EnumChart.JYZXSJYJE.getCode())) { - Calendar c = Calendar.getInstance(); - Date today = c.getTime(); - c.add(Calendar.DAY_OF_YEAR, 1); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - Date endTime = c.getTime();//明天0点 - c.add(Calendar.DAY_OF_YEAR, -30);//三十天前 - c.clear(); - c.setTime(endTime); - Date eTime = c.getTime(); - c.add(Calendar.DAY_OF_YEAR, -7); - Date sTime = c.getTime(); - List datas = wxCouponOrderMapper.queryPriceTotalGroup(tenantId, sTime, eTime); - Map dataMap = new HashMap<>(); - for (CUserDateAmountVo v : datas) { - dataMap.put(v.getxTime(), v.getPrice()); - } - List weekVos = new ArrayList<>();//周消费金额 - for (int i = 7, sortNum = 0; i >= 0; i--) { - c.clear(); - c.setTime(today); - c.add(Calendar.DAY_OF_YEAR, -i); - String dateStr = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()); - UserStructureVo vo = new UserStructureVo(); - vo.setName(new SimpleDateFormat("MM/dd").format(c.getTime())); - vo.setSortNum(sortNum++); - if (dataMap.get(dateStr) != null) { - int price = dataMap.get(dateStr); - vo.setPrice(price); - } else { - vo.setPrice(0); - } - weekVos.add(vo); - } - datamap.put("weekVos", weekVos);//一周金额列表 - return new ResultData(datamap); + return getWeekMoneyData(tenantId); } //新增用户趋势 if (chart.equals(EnumChart.XZYHQS.getCode())) { - WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); - dto.setTenantId(tenantId); - Calendar c = Calendar.getInstance(); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - Date today = c.getTime(); - List monthVos = new ArrayList<>();//会员数 - for (int i = 29, sortNum = 0; i >= 0; i--) { - c.clear(); - c.setTime(today); - c.add(Calendar.DAY_OF_YEAR, -i); - dto.setStartTime(c.getTime()); - c.add(Calendar.DAY_OF_YEAR, 1); - dto.setEndTime(c.getTime()); - long count = wxCUserMapper.findCount(dto); - UserStructureVo vo = new UserStructureVo(); - vo.setName(new SimpleDateFormat("MM/dd").format(dto.getStartTime())); - vo.setSortNum(sortNum++); - vo.setCount(count); - monthVos.add(vo); - } - datamap.put("monthVos", monthVos);//月用户增加数列表 - return new ResultData(datamap); + return getNewMemberTradeMonthly(tenantId); } //活跃用户趋势 if (chart.equals(EnumChart.HYYHQS.getCode())) { - HashMap params = new HashMap<>(); - Calendar c = Calendar.getInstance(); - c.add(Calendar.DAY_OF_YEAR, -1); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - Date endTime = c.getTime(); - c.add(Calendar.DAY_OF_YEAR, -30); - Date startTime = c.getTime(); - params.put("startTime", startTime); - params.put("endTime", endTime); - params.put("tenantId", tenantId); - List list = wxUserVisitMapper.touchUsersReportList(params); - Map dateMap = new HashMap<>(); - for (TouchUsersReportVo vo : list) { - dateMap.put(vo.getxTime(), vo); - } - List monthVos = new ArrayList<>();//每月uv - for (int i = 29, sortNum = 0; i >= 0; i--) { - c.clear(); - c.setTime(endTime); - c.add(Calendar.DAY_OF_YEAR, -i); - String dayStr = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()); - UserStructureVo vo = new UserStructureVo(); - vo.setName(new SimpleDateFormat("MM/dd").format(c.getTime())); - vo.setSortNum(sortNum++); - if (dateMap.get(dayStr) != null) { - TouchUsersReportVo rv = dateMap.get(dayStr); - Long l = new Long((long) rv.getUv()); - vo.setCount(l); - } else { - vo.setCount(0); - } - monthVos.add(vo); - } - datamap.put("monthVos", monthVos);//月活跃数列表 - return new ResultData(datamap); + return getActiveMemberTrade(tenantId); } //线上交易趋势 if (chart.equals(EnumChart.XSJYQS.getCode())) { - Calendar c = Calendar.getInstance(); - Date today = c.getTime(); - c.add(Calendar.DAY_OF_YEAR, 1); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - Date eTime = c.getTime();//明天0点 - c.add(Calendar.DAY_OF_YEAR, -30);//三十天前 - Date sTime = c.getTime(); - List datas = wxCouponOrderMapper.queryPriceTotalGroup(tenantId, sTime, eTime); - Map dataMap = new HashMap<>(); - for (CUserDateAmountVo v : datas) { - dataMap.put(v.getxTime(), v.getPrice()); - } - List monthVos = new ArrayList<>(); - for (int i = 29, sortNum = 0; i >= 0; i--) { - c.clear(); - c.setTime(today); - c.add(Calendar.DAY_OF_YEAR, -i); - String dateStr = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()); - UserStructureVo vo = new UserStructureVo(); - vo.setName(new SimpleDateFormat("MM/dd").format(c.getTime())); - vo.setSortNum(sortNum++); - if (dataMap.get(dateStr) != null) { - int price = dataMap.get(dateStr); - vo.setPrice(price); - } else { - vo.setPrice(0); - } - monthVos.add(vo); - } - datamap.put("monthVos", monthVos);//一月金额列表 - return new ResultData(datamap); + return getOnlineTrade(tenantId); } //微信用户总数 if (chart.equals(EnumChart.WXYHZS.getCode())) { - WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); - dto.setTenantId(tenantId); - //微信用户数据 - long wxallCount = wxCUserMapper.findCount(dto);//总量 - Calendar c = Calendar.getInstance(); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - Date today = c.getTime(); - dto.setStartTime(today); - dto.setEndTime(null); - long wxtodayCount = wxCUserMapper.findCount(dto);//今天新增 - datamap.put("wxallCount", wxallCount);//累计会员总数 - datamap.put("wxtodayCount", wxtodayCount);//今日新增会员数 - return new ResultData(datamap); + return getMemeberWechatTotal(tenantId); } //会员总数 if (chart.equals(EnumChart.HYZS.getCode())) { - WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); - dto.setTenantId(tenantId); - long allCount = wxCUserBasicInfoMapper.findCount(dto);//总量 - Calendar c = Calendar.getInstance(); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - Date today = c.getTime(); - dto.setStartTime(today); - dto.setEndTime(null); - long todayCount = wxCUserBasicInfoMapper.findCount(dto);//今天新增 - datamap.put("allCount", allCount);//累计会员总数 - datamap.put("todayCount", todayCount);//今日新增会员数 - return new ResultData(datamap); + return getMemberTotalCount(tenantId); } //微信用户累计趋势 if (chart.equals(EnumChart.WXYHLJQS.getCode())) { - final int daysBefore = 29; - WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); - dto.setTenantId(tenantId); - Calendar c = Calendar.getInstance(); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - Date today = c.getTime(); - List wxnewCountVos = new ArrayList<>();//每日新增会员数 - int j = 1; - for (int i = daysBefore; i >= 0; i--) { - c.clear(); - c.setTime(today); - c.add(Calendar.DAY_OF_YEAR, -i); - dto.setStartTime(c.getTime()); - c.add(Calendar.DAY_OF_YEAR, 1); - dto.setEndTime(c.getTime()); - long count = wxCUserMapper.findCount(dto); - UserStructureVo vo = new UserStructureVo(); - vo.setSortNum(j); - j++; - vo.setName(new SimpleDateFormat("MM/dd").format(dto.getStartTime())); - vo.setCount(count); - wxnewCountVos.add(vo); - } - List wxallCountVos = new ArrayList<>();//累计会员数 - c.clear(); - c.setTime(today); - c.add(Calendar.DAY_OF_YEAR, -daysBefore); - dto.setEndTime(c.getTime()); - dto.setStartTime(null); - long firstDay = wxCUserMapper.findCount(dto);//统计的第一天总数 - int i = 0; - long sumCount = 0; - for (UserStructureVo v : wxnewCountVos) { - UserStructureVo vo = new UserStructureVo(); - sumCount += v.getCount(); - vo.setCount(firstDay + sumCount); - vo.setName(v.getName()); - vo.setSortNum(i + 1); - wxallCountVos.add(vo); - i++; - } - datamap.put("wxallCountVos", wxallCountVos);//累计会员列表( 日期和数量list) - return new ResultData(datamap); + return getMemberWechatJoinTrade(tenantId); } //会员累计趋势 if (chart.equals(EnumChart.HYLJQS.getCode())) { - WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); - dto.setTenantId(tenantId); - final int daysBefore = 29; - Calendar c = Calendar.getInstance(); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - Date today = c.getTime(); - List newCountVos = new ArrayList<>();//每日新增会员数 - int j = 1; - for (int i = daysBefore; i >= 0; i--) { - c.clear(); - c.setTime(today); - c.add(Calendar.DAY_OF_YEAR, -i); - dto.setStartTime(c.getTime()); - c.add(Calendar.DAY_OF_YEAR, 1); - dto.setEndTime(c.getTime()); - long count = wxCUserBasicInfoMapper.findCount(dto); - UserStructureVo vo = new UserStructureVo(); - vo.setSortNum(j); - j++; - vo.setName(new SimpleDateFormat("MM/dd").format(dto.getStartTime())); - vo.setCount(count); - newCountVos.add(vo); - } - List allCountVos = new ArrayList<>();//累计会员数 - c.clear(); - c.setTime(today); - c.add(Calendar.DAY_OF_YEAR, -daysBefore); - dto.setEndTime(c.getTime()); - dto.setStartTime(null); - long firstDay = wxCUserBasicInfoMapper.findCount(dto);//统计的第一天总数 - int i = 0; - long sumCount = 0; - for (UserStructureVo v : newCountVos) { - UserStructureVo vo = new UserStructureVo(); - sumCount += v.getCount(); - vo.setCount(firstDay + sumCount); - vo.setName(v.getName()); - vo.setSortNum(i + 1); - allCountVos.add(vo); - i++; - } - datamap.put("allCountVos", allCountVos);//累计会员列表( 日期和数量list) - return new ResultData(datamap); - + return getMemberJoinTrade(tenantId); } //微信用户新增趋势 if (chart.equals(EnumChart.WXYHXZQS.getCode())) { - final int daysBefore = 29; - WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); - dto.setTenantId(tenantId); - Calendar c = Calendar.getInstance(); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - Date today = c.getTime(); - List wxnewCountVos = new ArrayList<>();//每日新增会员数 - int j = 1; - for (int i = daysBefore; i >= 0; i--) { - c.clear(); - c.setTime(today); - c.add(Calendar.DAY_OF_YEAR, -i); - dto.setStartTime(c.getTime()); - c.add(Calendar.DAY_OF_YEAR, 1); - dto.setEndTime(c.getTime()); - long count = wxCUserMapper.findCount(dto); - UserStructureVo vo = new UserStructureVo(); - vo.setSortNum(j); - j++; - vo.setName(new SimpleDateFormat("MM/dd").format(dto.getStartTime())); - vo.setCount(count); - wxnewCountVos.add(vo); - } - datamap.put("wxnewCountVos", wxnewCountVos);//新增会员列表(日期和数量list) - return new ResultData(datamap); + return getWechatMemberTrade(tenantId); } //会员新增趋势 if (chart.equals(EnumChart.HYXZQS.getCode())) { - WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); - dto.setTenantId(tenantId); - final int daysBefore = 29; - Calendar c = Calendar.getInstance(); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - Date today = c.getTime(); - List newCountVos = new ArrayList<>();//每日新增会员数 - int j = 1; - for (int i = daysBefore; i >= 0; i--) { - c.clear(); - c.setTime(today); - c.add(Calendar.DAY_OF_YEAR, -i); - dto.setStartTime(c.getTime()); - c.add(Calendar.DAY_OF_YEAR, 1); - dto.setEndTime(c.getTime()); - long count = wxCUserBasicInfoMapper.findCount(dto); - UserStructureVo vo = new UserStructureVo(); - vo.setSortNum(j); - j++; - vo.setName(new SimpleDateFormat("MM/dd").format(dto.getStartTime())); - vo.setCount(count); - newCountVos.add(vo); - } - datamap.put("newCountVos", newCountVos);//新增会员列表(日期和数量list) - return new ResultData(datamap); + return getNewMemberTrade(tenantId); } //拓客渠道 if (chart.equals(EnumChart.TKQD.getCode())) { - List channelStructureList = new ArrayList<>(); - WxCUser wxCUser = new WxCUser(); - wxCUser.setTenantId(tenantId); - List channels = wxUserChannelMapper.findDistinctChannel(); - for (WxUserChannel w : channels) { - WxUserChannel c = new WxUserChannel(); - c.setChannelName(w.getChannelName()); - PageInfo page = PageHelper.startPage(1, 1000).doSelectPageInfo(() -> wxUserChannelMapper.findList(c)); - if (page.getSize() > 0) { - List sceneList = new ArrayList<>(); - for (WxUserChannel uc : page.getList()) { - List scene = new ArrayList<>(); - scene.add(uc.getSceneAddress()); - wxCUser.setSceneList(scene); - sceneList.add(uc.getSceneAddress()); - } - wxCUser.setSceneList(sceneList); - WxUserChannel channelStructure = new WxUserChannel(); - channelStructure.setChannelName(w.getChannelName()); - channelStructure.setCount(wxCUserMapper.countByChannel(wxCUser)); - channelStructureList.add(channelStructure); - } - } - datamap.put("channelList", channelStructureList); - return new ResultData(datamap); + return getFromChannelAnalysis(tenantId); } //场景排名 if (chart.equals(EnumChart.CJPM.getCode())) { - List senceStructureList = new ArrayList<>(); - WxCUser wxCUser = new WxCUser(); - wxCUser.setTenantId(tenantId); - List channels = wxUserChannelMapper.findDistinctChannel(); - for (WxUserChannel w : channels) { - WxUserChannel c = new WxUserChannel(); - c.setChannelName(w.getChannelName()); - PageInfo page = PageHelper.startPage(1, 1000).doSelectPageInfo(() -> wxUserChannelMapper.findList(c)); - if (page.getSize() > 0) { - for (WxUserChannel uc : page.getList()) { - List scene = new ArrayList<>(); - scene.add(uc.getSceneAddress()); - wxCUser.setSceneList(scene); - WxUserChannel senceStructure = new WxUserChannel(); - senceStructure.setDescription(uc.getDescription()); - senceStructure.setCount(wxCUserMapper.countByChannel(wxCUser)); - senceStructureList.add(senceStructure); - } - } - } - Collections.sort(senceStructureList, (s1, s2) -> ((int) (s2.getCount() - s1.getCount()))); - datamap.put("senceList", senceStructureList.subList(0, 10)); - return new ResultData(datamap); + return getSceneAnalysis(tenantId); } //会员性别比例 if (chart.equals(EnumChart.HYXBBL.getCode())) { - WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); - dto.setTenantId(tenantId); - dto.setStartTime(DateUtils.stringToDate(startdate + " 00:00:00")); - dto.setEndTime(DateUtils.stringToDate(enddate + " 23:59:59")); - long all = wxCUserBasicInfoMapper.findCount(dto); - List vos = new ArrayList<>(); - Calendar c = Calendar.getInstance(); - for (EnumAgeInfo a : EnumAgeInfo.values()) { - c.clear(); - c.setTime(new Date()); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - long count = getCountByAge(a, c, dto); - vos.add(getVo(count, all, a.getDesc(), a.getSortNum())); - } - return new ResultData(datamap); + return getMemberSexRate(tenantId, startdate, enddate); } //会员绑定车牌率 if (chart.equals(EnumChart.HYBDCPL.getCode())) { - WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); - dto.setTenantId(tenantId); - dto.setStartTime(DateUtils.stringToDate(startdate + " 00:00:00")); - dto.setEndTime(DateUtils.stringToDate(enddate + " 23:59:59")); - long total = wxCUserBasicInfoMapper.findCount(dto); - long userCountWithCar = wxCUserCarMapper.countUser(dto); - Map userWithCar = new HashMap(); - userWithCar.put("title", "已绑定车牌"); - userWithCar.put("count", userCountWithCar); - long userCountWithoutCar = total - userCountWithCar; - Map userWithoutCar = new HashMap(); - userWithoutCar.put("title", "未绑定车牌"); - userWithoutCar.put("count", userCountWithoutCar); - NumberFormat nf = NumberFormat.getPercentInstance(); - nf.setMinimumFractionDigits(2); - if (userCountWithoutCar + userCountWithCar > 0) { - userWithCar.put("percentage", nf.format(userCountWithCar / new Double(userCountWithoutCar + userCountWithCar).doubleValue())); - userWithoutCar.put("percentage", nf.format(userCountWithoutCar / new Double(userCountWithoutCar + userCountWithCar).doubleValue())); - } else { - userWithCar.put("percentage", "--"); - userWithoutCar.put("percentage", "--"); - } - List list = new ArrayList<>(); - list.add(userWithCar); - list.add(userWithoutCar); - return new ResultData(list); + return getMemberBindCar(tenantId, startdate, enddate); } //会员年龄层次 if (chart.equals(EnumChart.HYNLCC.getCode())) { - WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); - dto.setTenantId(tenantId); - dto.setStartTime(DateUtils.stringToDate(startdate + " 00:00:00")); - dto.setEndTime(DateUtils.stringToDate(enddate + " 23:59:59")); - long all = wxCUserBasicInfoMapper.findCount(dto); - List vos = new ArrayList<>(); - Calendar c = Calendar.getInstance(); - for (EnumAgeInfo a : EnumAgeInfo.values()) { - c.clear(); - c.setTime(new Date()); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - long count = getCountByAge(a, c, dto); - vos.add(getVo(count, all, a.getDesc(), a.getSortNum())); - } - return new ResultData(datamap); - + return getMemberAgeAnalysis(tenantId, startdate, enddate); } //会员成长值 if (chart.equals(EnumChart.HYCZZ.getCode())) { - WxLevelConfig wxLevelConfig = new WxLevelConfig(); - wxLevelConfig.setTenantId(tenantId); - wxLevelConfig.setSortColumns(WxLevelConfig.Field.Points_ASC); - List levelList = wxLevelConfigMapper.findList(wxLevelConfig); - - for (int i = 0; i < levelList.size(); i++) { - - WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); - dto.setTenantId(tenantId); - dto.setStartTime(DateUtils.stringToDate(startdate + " 00:00:00")); - dto.setEndTime(DateUtils.stringToDate(enddate + " 23:59:59")); - if (i + 1 < levelList.size()) { - dto.setLevelStartScore(levelList.get(i).getPoints()); - dto.setLevelEndScore(levelList.get(i + 1).getPoints()); - } else { - dto.setLevelStartScore(levelList.get(i).getPoints()); - } - - long all = wxCUserBasicInfoMapper.findCountByScore(dto); - - levelList.get(i).setCount(all); - } - WxLevelConfig other = new WxLevelConfig(); - //没有等级的会员 - other.setLevel("无"); - WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); - other.setCount(wxCUserBasicInfoMapper.findCount(dto) - - levelList.stream().map(WxLevelConfig::getCount).reduce(Long::sum).orElse(0L)); - levelList.add(other); - return new ResultData(levelList); + return getMemberGrowthAnalysis(tenantId, startdate, enddate); } //会员手机品牌 if (chart.equals(EnumChart.HYSJPP.getCode())) { - WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); - dto.setTenantId(tenantId); - Date startTime = DateUtils.stringToDate(startdate + " 00:00:00"); - Date endTime = DateUtils.stringToDate(enddate + " 23:59:59"); - dto.setStartTime(startTime); - dto.setEndTime(endTime); - long total = wxCUserBasicInfoMapper.findCount(dto); - List tagList = new ArrayList<>(); - EnumTag[] tags = {EnumTag.ID_49, - EnumTag.ID_50, - EnumTag.ID_51, - EnumTag.ID_52, - EnumTag.ID_53, - EnumTag.ID_54}; - for (int i = 0; i < tags.length; i++) { - WxTags tag = new WxTags(); - tag.setName(tags[i].getMessage()); - tag.setCount(wxCUserTagsMapper.countUser(JSON.toJSONString(tags[i].getCode()), tenantId, startTime, endTime)); - tagList.add(tag); - total -= tag.getCount(); - } - - WxTags tag = new WxTags(); - tag.setName("暂未获取"); - tag.setCount(total); - tagList.add(tag); - return new ResultData(tagList); + return getMobileBrandAnalysis(tenantId, startdate, enddate); } //会员活跃度 if (chart.equals(EnumChart.HYHYD.getCode())) { - WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); - dto.setTenantId(tenantId); - Date startTime = DateUtils.stringToDate(startdate + " 00:00:00"); - Date endTime = DateUtils.stringToDate(enddate + " 23:59:59"); - dto.setStartTime(startTime); - dto.setEndTime(endTime); - long total = wxCUserBasicInfoMapper.findCount(dto); - List tagList = new ArrayList<>(); - EnumTag[] tags = { - EnumTag.ID_112, - EnumTag.ID_111, - EnumTag.ID_110 - }; - for (int i = 0; i < tags.length; i++) { - WxTags tag = new WxTags(); - tag.setName(tags[i].getMessage()); - tag.setCount(wxCUserTagsMapper.countUser(JSON.toJSONString(tags[i].getCode()), tenantId, startTime, endTime)); - tagList.add(tag); - total -= tag.getCount(); - } - WxTags tag = new WxTags(); - tag.setName("休眠"); - tag.setCount(total); - tagList.add(tag); - return new ResultData(tagList); + return getMemActivity(tenantId, startdate, enddate); } //卡营销数据 if (chart.equals(EnumChart.SALE_CARD.getCode())) { - WxCoupon wxCoupon = new WxCoupon(); - - //默认时间本月第一天,截止到当天 - if (StringUtils.isEmpty(paramsMap.get("startdate"))) { - Calendar c = Calendar.getInstance(); - c.add(Calendar.MONTH, 0); - c.set(Calendar.DAY_OF_MONTH,1); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - wxCoupon.setStartdate(c.getTime()); - }else{ - Date startTime = DateUtils.stringToDate(startdate); - wxCoupon.setStartdate(startTime); - } - if (StringUtils.isEmpty(paramsMap.get("enddate"))) { - wxCoupon.setEnddate(new Date()); - }else{ - Date endTime = DateUtils.stringToDate(enddate, "yyyy-MM-dd HH:mm:ss"); - wxCoupon.setEnddate(endTime); - } - - Map result = new HashedMap(); - List saleMoneyList = wxCouponService.findSaleMoneyByDate(wxCoupon); - List paymentList = wxCouponService.findPaymentByDate(wxCoupon); - Map saleMap = getDateMap(wxCoupon.getStartdate(),wxCoupon.getEnddate()); - Map payMentMap = getDateMap(wxCoupon.getStartdate(),wxCoupon.getEnddate()); - - for (WxCouponStatisVo coupon:saleMoneyList){ - saleMap.put(coupon.getXtime(),coupon.getXcount()); - } - for (WxCouponStatisVo coupon:paymentList){ - payMentMap.put(coupon.getXtime(),coupon.getXcount()); - } - result.put("saleHistory",saleMap); - result.put("paymentHistory",payMentMap); - result.put("saleCardCount",wxCouponService.findSaleCardCount(wxCoupon)); - result.put("tranCount",wxCouponService.findTranCardCount(wxCoupon)); - result.put("subsidyCount",wxCouponService.findSubsidyMoney(wxCoupon)); - return new ResultData(result); + return getSaleCardAnalysis(paramsMap, startdate, enddate); } - //卷营销数据 + //券营销数据 if (chart.equals(EnumChart.SALE_COUPON.getCode())) { - WxCoupon wxCoupon = new WxCoupon(); - Map result = new HashedMap(); - - //默认时间本月第一天,截止到当天 - if (StringUtils.isEmpty(paramsMap.get("startdate"))) { - Calendar c = Calendar.getInstance(); - c.add(Calendar.MONTH, 0); - c.set(Calendar.DAY_OF_MONTH,1); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - wxCoupon.setStartdate(c.getTime()); - }else{ - Date startTime = DateUtils.stringToDate(startdate); - wxCoupon.setStartdate(startTime); - } - if (StringUtils.isEmpty(paramsMap.get("enddate"))) { - wxCoupon.setEnddate(new Date()); - }else{ - Date endTime = DateUtils.stringToDate(enddate, "yyyy-MM-dd HH:mm:ss"); - wxCoupon.setEnddate(endTime); - } - List orderCountList = wxCouponService.findCouponOrderCount(wxCoupon); - List paymentCountList = wxCouponService.findCouponPaymentCount(wxCoupon); - List priceCouponSaleCountList = wxCouponService.priceCouponSaleCount(wxCoupon); - List priceCouponPaymentCountList = wxCouponService.priceCouponPaymentCount(wxCoupon); - - Map orderCountMap = getDateMap(wxCoupon.getStartdate(),wxCoupon.getEnddate()); - Map paymentCountMap = getDateMap(wxCoupon.getStartdate(),wxCoupon.getEnddate()); - Map priceCouponSaleCountMap = getDateMap(wxCoupon.getStartdate(),wxCoupon.getEnddate()); - Map priceCouponPaymentCountMap = getDateMap(wxCoupon.getStartdate(),wxCoupon.getEnddate()); - - for (WxCouponStatisVo coupon:orderCountList){ - orderCountMap.put(coupon.getXtime(),coupon.getXcount()); - } - for (WxCouponStatisVo coupon:paymentCountList){ - paymentCountMap.put(coupon.getXtime(),coupon.getXcount()); - } - for (WxCouponStatisVo coupon:priceCouponSaleCountList){ - priceCouponSaleCountMap.put(coupon.getXtime(),coupon.getXcount()); - } - for (WxCouponStatisVo coupon:priceCouponPaymentCountList){ - priceCouponPaymentCountMap.put(coupon.getXtime(),coupon.getXcount()); - } - result.put("orderCountList",orderCountMap); - result.put("paymentCountList",paymentCountMap); - result.put("priceCouponSaleCountList",priceCouponSaleCountMap); - result.put("priceCouponPaymentCountList",priceCouponPaymentCountMap); - - result.put("sumPriceSaleMoney",wxCouponService.findSumPriceSaleMoney(wxCoupon)); - result.put("sumPricePayMent",wxCouponService.findSumPricePayMent(wxCoupon)); - result.put("sumSubsidyMoney",wxCouponService.findSumSubsidyMoney(wxCoupon)); - return new ResultData(result); + return getSaleCouponAnalysis(paramsMap, startdate, enddate); } //砍价营销数据 if (chart.equals(EnumChart.SALE_PRESS.getCode())) { - WxCoupon wxCoupon = new WxCoupon(); - Map result = new HashedMap(); - - //默认时间本月第一天,截止到当天 - if (StringUtils.isEmpty(paramsMap.get("startdate"))) { - Calendar c = Calendar.getInstance(); - c.add(Calendar.MONTH, 0); - c.set(Calendar.DAY_OF_MONTH,1); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - wxCoupon.setStartdate(c.getTime()); - }else{ - Date startTime = DateUtils.stringToDate(startdate); - wxCoupon.setStartdate(startTime); - } - if (StringUtils.isEmpty(paramsMap.get("enddate"))) { - wxCoupon.setEnddate(new Date()); - }else{ - Date endTime = DateUtils.stringToDate(enddate, "yyyy-MM-dd HH:mm:ss"); - wxCoupon.setEnddate(endTime); - } - List pressSendHistory = wxCouponService.pressSendHistory(wxCoupon); - List pressSuccHistory = wxCouponService.pressSuccHistory(wxCoupon); - List pressPaymentHistory = wxCouponService.pressPaymentHistory(wxCoupon); + return getSalePressAnalysis(paramsMap, tenantId, startdate, enddate); + } - Map pressSendHistoryMap = getDateMap(wxCoupon.getStartdate(),wxCoupon.getEnddate()); - Map pressSuccHistoryMap = getDateMap(wxCoupon.getStartdate(),wxCoupon.getEnddate()); - Map pressPaymentHistoryMap = getDateMap(wxCoupon.getStartdate(),wxCoupon.getEnddate()); + //拼团营销数据 + if (chart.equals(EnumChart.SALE_GROUP.getCode())) { + return getSaleGroupAnalysis(paramsMap, tenantId, startdate); + } - for (WxCouponStatisVo coupon:pressSendHistory){ - pressSendHistoryMap.put(coupon.getXtime(),coupon.getXcount()); + return new ResultData(ErrorCode.REPORT_TYPE_UNKNOWN); + } + + /** + * 解单数据 - 月 + * @param tenantId + * @return + */ + private ResultData getMerchantTradeMonthly(String tenantId) { + WxMerchantTradeDaily wxMerchantTradeDaily = new WxMerchantTradeDaily(); + wxMerchantTradeDaily.setTenantId(tenantId); + + List recordList = wxMerchantTradeDailyMapper.findTotalListOfMonth(wxMerchantTradeDaily); + Map recordMap = recordList.stream().collect(Collectors.toMap(WxMerchantTradeDaily::getReportDate, r -> r)); + + List tradeList = new ArrayList<>(); + Calendar cal = Calendar.getInstance(); + SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd"); + SimpleDateFormat fmtv = new SimpleDateFormat("MM/dd"); + cal.setTime(new Date()); + for (int i = 0; i < 30; i++) { + cal.add(Calendar.DAY_OF_YEAR, -1); + WxMerchantTradeDaily trade = recordMap.get(fmt.format(cal.getTime())); + if (trade != null) { + trade.setReportDate(fmtv.format(cal.getTime())); + tradeList.add(trade); + } else { + trade = new WxMerchantTradeDaily(); + trade.setTradeAmt(0); + trade.setReportDate(fmtv.format(cal.getTime())); + tradeList.add(trade); } - for (WxCouponStatisVo coupon:pressSuccHistory){ - pressSuccHistoryMap.put(coupon.getXtime(),coupon.getXcount()); + } + Collections.reverse(tradeList); + return new ResultData(tradeList); + } + + /** + * 今日已绑车牌量 + * @param tenantId + * @return + */ + private ResultData getBindCarAnalysis(String tenantId) { + HashMap datamap = new HashMap<>(); + String yesterday = DateUtils.getTimeBefore(1, new Date()); + String lastweek = DateUtils.getTimeBefore(7, new Date()); + //绑定车牌 + Map carParams = new HashMap<>(); + carParams.put("tenantId", tenantId); + carParams.put("startdate", DateUtils.getSystemTime("yyyy-MM-dd 00:00:00")); + carParams.put("enddate", DateUtils.getSystemTime("yyyy-MM-dd HH:mm:ss")); + long todaybindcar = wxCUserCarMapper.queryCarCount(carParams); + carParams.put("startdate", yesterday + " 00:00:00"); + carParams.put("enddate", yesterday + " 23:59:59"); + long yesterdaybindcar = wxCUserCarMapper.queryCarCount(carParams); + carParams.put("startdate", lastweek + " 00:00:00"); + carParams.put("enddate", lastweek + " 23:59:59"); + long lastweekbindcar = wxCUserCarMapper.queryCarCount(carParams); + datamap.put("todaybindcar", todaybindcar); + if (yesterdaybindcar > 0) { + double yesterdaybinddhb = (double) (todaybindcar - yesterdaybindcar) / yesterdaybindcar * 100; + double yesterdaybindhb = new BigDecimal(yesterdaybinddhb).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + datamap.put("yesterdaybindhb", yesterdaybindhb + "%"); + } else { + datamap.put("yesterdaybindhb", "--"); + } + if (lastweekbindcar > 0) { + double lastweekbinddhb = (double) (todaybindcar - lastweekbindcar) / lastweekbindcar * 100; + double lastweekbindhb = new BigDecimal(lastweekbinddhb).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + datamap.put("lastweekbindhb", lastweekbindhb + "%"); + } else { + datamap.put("lastweekbindhb", "--"); + } + return new ResultData(datamap); + } + + /** + * 实时车流量 + * @param tenantId + * @return + */ + private ResultData getCarDataCurrent(String tenantId) { + HashMap datamap = new HashMap<>(); + String systemTime = DateUtils.getSystemTime("yyyy-MM-dd"); + String yesterday = DateUtils.getTimeBefore(1, new Date()); + String lastweek = DateUtils.getTimeBefore(7, new Date()); + HashMap params = new HashMap<>(); + params.put("tenantId", tenantId); + params.put("cmdType", EnumCarCmd.CAR_ETCP_CALLBACK_PARK_IN.getCode()); + params.put("startdate", systemTime + " 05:00:00"); + params.put("enddate", DateUtils.getSystemTime("yyyy-MM-dd HH:mm:ss")); + List> todayCarlist = wxCarCmdLogMapper.queryTodayCar(params); + Map todaycollect = todayCarlist.stream().collect(Collectors.toMap(m -> { + return m.get("create_time"); + }, m -> { + return m.get("carcount"); + })); + List hourList = new ArrayList<>(); + Calendar instance = Calendar.getInstance(); + instance.add(Calendar.HOUR_OF_DAY, 1); + int hour = instance.get(Calendar.HOUR_OF_DAY); + int startHour = 6; + int endHour = 24; + for (int i = startHour; i < endHour; i++) { + hourList.add(i < 10 ? "0" + i + ":00" : i + ":00"); + } + List todayCarList = new ArrayList<>(); + for (int i = startHour; i < endHour; i++) { + if(i> yesterdayCarlist = wxCarCmdLogMapper.queryTodayCar(params); + Map yesterdaycollect = yesterdayCarlist.stream().collect(Collectors.toMap(m -> { + return m.get("create_time"); + }, m -> { + return m.get("carcount"); + })); + List yesterdayCarList = new ArrayList<>(); + for (int i = startHour; i < endHour; i++) { + yesterdayCarList.add(yesterdaycollect.get((Object) hourList.get(i-startHour))); + } + datamap.put("yesterdaycardata", yesterdayCarList); + + params.put("startdate", lastweek + " 05:00:00"); + params.put("enddate", lastweek + " 22:59:59"); + List> lastdayCarlist = wxCarCmdLogMapper.queryTodayCar(params); + Map lastweekdaycollect = lastdayCarlist.stream().collect(Collectors.toMap(m -> { + return m.get("create_time"); + }, m -> { + return m.get("carcount"); + })); + List lastweekdayCarList = new ArrayList<>(); + for (int i = startHour; i < endHour; i++) { + lastweekdayCarList.add(lastweekdaycollect.get((Object) hourList.get(i-startHour))); + } + datamap.put("lastdaycardata", lastweekdayCarList); + + return new ResultData(datamap); + } + + /** + * 数据塔台-数据总览-车流数据 | 数据塔台-车流数据-(历史车流量 + 今日车流量 + 上周同期) + * @param tenantId + * @return + */ + private ResultData getCarHistoryAndTodayAndHB(String tenantId, boolean withOthers ) { + String startdate; + HashMap datamap = new HashMap<>(); + HashMap params = new HashMap<>(); + params.put("tenantId", tenantId); + params.put("cmdType", EnumCarCmd.CAR_ETCP_CALLBACK_PARK_IN.getCode()); + startdate = DateUtils.getTimeBefore(30, new Date()); + String systemTime = DateUtils.getSystemTime("yyyy-MM-dd"); + + List tjTimeList = DateUtils.getTjTimeList(startdate, systemTime, "0"); + + params.put("startdate", startdate + " 00:00:00"); + params.put("enddate", systemTime + " 23:59:59"); + + List> historylist = wxCarCmdLogMapper.queryHistory(params); + + Map collect = historylist.stream().collect(Collectors.toMap(m -> { + return m.get("create_date"); + }, m -> { + return m.get("carcount"); + })); + + List timeList = new ArrayList<>(); + List valList = new ArrayList<>(); + for (String date : tjTimeList) { + Object o = collect.get(date); + timeList.add(date.substring(5).replace("-", "/")); + if (o == null) { + valList.add(0L); + } else { + valList.add(o); } - result.put("pressSendHistory",pressSendHistoryMap); - result.put("pressSuccHistory",pressSuccHistoryMap); - result.put("pressPaymentHistory",pressPaymentHistoryMap); + } + Map map = new HashMap(); + map.put("index", timeList); + map.put("val", valList); + datamap.put("history", map); - wxCoupon.setTenantId(tenantId); - result.put("pressSuccRate",wxCouponService.pressSuccRate(wxCoupon)); - result.put("sumJoin",wxCouponService.sumJoin(wxCoupon)); - return new ResultData(result); + if(withOthers) { + //今日车流量 + long todaycar = ((Long) valList.get(valList.size()-1)).longValue(); + datamap.put("todaycar", todaycar); + //环比 + long yesterdaycar = (long) ((Long) valList.get(valList.size()-2)).longValue(); + if (yesterdaycar > 0) { + double hbd = (double) (todaycar - yesterdaycar) / yesterdaycar * 100; + double hb = new BigDecimal(hbd).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + datamap.put("hb", hb + "%"); + } else { + datamap.put("hb", "--"); + } + //上周同期 + long lastweekcar = ((Long) valList.get(valList.size()-8)).longValue(); + if (lastweekcar > 0) { + double lasthbd = (double) (todaycar - lastweekcar) / lastweekcar * 100; + double lasthb = new BigDecimal(lasthbd).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + datamap.put("lasthb", lasthb + "%"); + } else { + datamap.put("lasthb", "--"); + } + // 周入场数量 + long carWeekCount = 0L; + for(int i=0;i<7;i++) { + carWeekCount += ((Long)valList.get(valList.size()-1-i)).longValue(); + } + datamap.put("carWeekCount", carWeekCount); } + return new ResultData(datamap); + } - //拼团营销数据 - if (chart.equals(EnumChart.SALE_GROUP.getCode())) { - Map params = new HashMap<>(); - params.put("tenantId", tenantId); - //默认时间本月第一天,截止到当天 - Map result = new HashMap<>(); - Date startTime = new Date(); - Date endTime = startTime; - if (StringUtils.isEmpty(paramsMap.get("startdate"))) { - Calendar c = Calendar.getInstance(); - c.add(Calendar.MONTH, 0); - c.set(Calendar.DAY_OF_MONTH, 1); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - startTime = c.getTime(); - params.put("startdate", startTime); + /** + * 近一周线上缴费车辆 + * @param tenantId + * @return + */ + private ResultData getCarPayCarCountInWeek(String tenantId) { + HashMap datamap = new HashMap<>(); + HashMap weekParams = new HashMap<>(); + weekParams.put("tenantId", tenantId); + String oneWeekStartdate = DateUtils.getTimeBefore(7, new Date()); + String oneWeekEndDate = DateUtils.getTimeBefore(1, new Date()); + weekParams.put("startdate", oneWeekStartdate + " 00:00:00"); + weekParams.put("enddate", oneWeekEndDate + " 23:59:59"); + weekParams.put("cmdType", EnumCarCmd.CAR_ETCP_CALLBACK_PAY_MANUAL.getCode()); + datamap.put("oneWeekCarPayCount", wxCarCmdLogMapper.queryWeekCarPayCount(weekParams)); + return new ResultData(datamap); + } + + /** + * 近一周线上缴费金额 + * @param tenantId + * @return + */ + private ResultData getCarPayCountInWeek(String tenantId) { + HashMap datamap = new HashMap<>(); + HashMap weekParams = new HashMap<>(); + weekParams.put("tenantId", tenantId); + String oneWeekStartdate = DateUtils.getTimeBefore(7, new Date()); + String oneWeekEndDate = DateUtils.getTimeBefore(1, new Date()); + weekParams.put("startdate", oneWeekStartdate + " 00:00:00"); + weekParams.put("enddate", oneWeekEndDate + " 23:59:59"); + weekParams.put("cmdType", EnumCarCmd.CAR_ETCP_CALLBACK_PAY_MANUAL.getCode()); + List> weekCarPayHistoryList = wxCarCmdLogMapper.queryWeekCarPay(weekParams); + Map weekCollect = weekCarPayHistoryList.stream().collect(Collectors.toMap(m -> { + return (String) m.get("create_time"); + }, m -> { + return m.get("fee"); + })); + List days = DateUtils.getTjTimeList(oneWeekStartdate, oneWeekEndDate, "0"); + List timeList = new ArrayList<>(); + List valList = new ArrayList<>(); + for (String date : days) { + Object o = weekCollect.get(date); + timeList.add(date.substring(5, date.length()).replace("-", "/")); + if (o == null) { + valList.add(0L); + } else { + valList.add(o); + } + } + + Map map = new HashMap(); + map.put("index", timeList); + map.put("val", valList); + datamap.put("oneWeekCarPayFeeCount", map); + return new ResultData(datamap); + } + + /** + * 车流 - 近一周新增停车会员 + * @param tenantId + * @return + */ + private ResultData getCarNewMemberCount(String tenantId) { + HashMap datamap = new HashMap<>(); + String oneWeekStartdate = DateUtils.getTimeBefore(7, new Date()); + String oneWeekEndDate = DateUtils.getTimeBefore(1, new Date()); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + WxCUserBasicInfoDto wxCUserBasicInfoDto = new WxCUserBasicInfoDto(); + wxCUserBasicInfoDto.setTenantId(tenantId); + try { + wxCUserBasicInfoDto.setStartTime(sdf.parse(oneWeekStartdate)); + wxCUserBasicInfoDto.setEndTime(sdf.parse(oneWeekEndDate)); + } catch (Exception e) { + e.printStackTrace(); + } + datamap.put("oneWeekNewCarUserCount", wxCUserCarMapper.countUser(wxCUserBasicInfoDto)); + //停车会员总数 + wxCUserBasicInfoDto = new WxCUserBasicInfoDto(); + wxCUserBasicInfoDto.setTenantId(tenantId); + datamap.put("newCarUserSumCount", wxCUserCarMapper.countUser(wxCUserBasicInfoDto)); + + return new ResultData(datamap); + } + + /** + * 车流 - 近一周新增会员数 + * @param tenantId + * @return + */ + private ResultData getCarNewMemberCountInWeek(String tenantId) { + HashMap datamap = new HashMap<>(); + HashMap weekParams = new HashMap<>(); + weekParams.put("tenantId", tenantId); + String oneWeekStartdate = DateUtils.getTimeBefore(7, new Date()); + String oneWeekEndDate = DateUtils.getTimeBefore(1, new Date()); + weekParams.put("startdate", oneWeekStartdate + " 00:00:00"); + weekParams.put("enddate", oneWeekEndDate + " 23:59:59"); + weekParams.put("cmdType", EnumCarCmd.CAR_ETCP_CALLBACK_PAY_MANUAL.getCode()); + List> carCountHistory = wxCUserCarMapper.queryCarCountHistory(weekParams); + Map weekCarCollect = carCountHistory.stream().collect(Collectors.toMap(m -> { + return (String) m.get("create_time"); + }, m -> { + return m.get("count"); + })); + List days = DateUtils.getTjTimeList(oneWeekStartdate, oneWeekEndDate, "0"); + List timeList = new ArrayList<>(); + List valList = new ArrayList<>(); + for (String date : days) { + Object o = weekCarCollect.get(date); + timeList.add(date.substring(5, date.length()).replace("-", "/")); + if (o == null) { + valList.add(0L); + } else { + valList.add(o); + } + } + + Map map = new HashMap(); + map.put("index", timeList); + map.put("val", valList); + datamap.put("oneWeekNewCarUserHistory", map); + return new ResultData(datamap); + } + + /** + * 今日券交易数据 + * @param tenantId + * @return + */ + private ResultData getTodayTouchUser(String tenantId) { + HashMap datamap = new HashMap<>(); + //查询UV PV + HashMap params = new HashMap<>(); + params.put("tenantId", tenantId); + params.put("startTime", addDay(-1)); + params.put("endTime", addDay(1)); + List wxUserVisitList = wxUserVisitMapper.touchUsersReportData(params); + TouchUsersReportVo touchUsersReportVo = new TouchUsersReportVo(); + if (!wxUserVisitList.isEmpty()) { + touchUsersReportVo = wxUserVisitList.get(0); + } else { + touchUsersReportVo.setPv(0); + touchUsersReportVo.setUv(0); + touchUsersReportVo.setCouponCount(0); + touchUsersReportVo.setUserCount(0); + touchUsersReportVo.setVerifyCount(0); + touchUsersReportVo.setVerifyUserCount(0); + touchUsersReportVo.setxTime(DateUtils.getSystemTime("MM/dd")); + } + datamap.put("yesterday", touchUsersReportVo); + return new ResultData(datamap); + } + + /** + * 今日券交易数据 + * @param tenantId + * @return + */ + private ResultData getTodayCouponCount(String tenantId) { + HashMap datamap = new HashMap<>(); + //今日领取券数 + //查询coupon order表 + int todayCouponCount = wxCouponOrderMapper.findCountByDateLimit(tenantId, addDay(0), addDay(1)); + int yesterdayCount = wxCouponOrderMapper.findCountByDateLimit(tenantId, addDay(-1), addDay(0)); + int lastWeekCount = wxCouponOrderMapper.findCountByDateLimit(tenantId, addDay(-7), addDay(-6)); + NumberFormat nf = NumberFormat.getPercentInstance(); + nf.setMinimumFractionDigits(2);//控制保留小数点后几位,2:表示保留2位小数点 + String couponUpDay = "--"; + if (yesterdayCount != 0) { + couponUpDay = nf.format((todayCouponCount - yesterdayCount) / (float) yesterdayCount); + } + String couponUpWeek = "--"; + if (lastWeekCount != 0) { + couponUpWeek = nf.format((todayCouponCount - lastWeekCount) / (float) lastWeekCount); + } + datamap.put("couponUpDay", couponUpDay);//比昨日提升 + datamap.put("couponUpWeek", couponUpWeek);//比上周提升 + datamap.put("todayCouponCount", todayCouponCount);//今日领取数 + return new ResultData(datamap); + } + + /** + * 今日场景营销 + * @param tenantId + * @return + */ + private ResultData getSaleSceneCount(String tenantId) { + HashMap datamap = new HashMap<>(); + int todaySceneCount = wxCouponActionLogMapper.getCountByDateLimit(tenantId, addDay(0), addDay(1)); + int yesterdayCount = wxCouponActionLogMapper.getCountByDateLimit(tenantId, addDay(-1), addDay(0)); + int lastWeekCount = wxCouponActionLogMapper.getCountByDateLimit(tenantId, addDay(-7), addDay(-6)); + NumberFormat nf = NumberFormat.getPercentInstance(); + nf.setMinimumFractionDigits(2);//控制保留小数点后几位,2:表示保留2位小数点 + String sceneDownDay = "--"; + if (yesterdayCount != 0) { + sceneDownDay = nf.format((yesterdayCount - todaySceneCount) / (float) yesterdayCount); + } + String sceneUpWeek = "--"; + if (lastWeekCount != 0) { + sceneUpWeek = nf.format((todaySceneCount - lastWeekCount) / (float) lastWeekCount); + } + datamap.put("sceneDownDay", sceneDownDay);//比昨日下降 + datamap.put("sceneUpWeek", sceneUpWeek);//比上周提升 + datamap.put("todaySceneCount", todaySceneCount);//今日领取数 + return new ResultData(datamap); + } + + /** + * 触达用户数 + * @param tenantId + * @return + */ + private ResultData getTouchUserCount(String tenantId) { + String startdate; + String enddate;//查询UV PV + HashMap params = new HashMap<>(); + params.put("tenantId", tenantId); + params.put("startTime", addDay(-30)); + params.put("endTime", addDay(1)); + List wxUserVisitList = wxUserVisitMapper.touchUsersReportData(params); + startdate = DateUtils.getTimeBefore(30, new Date()); + enddate = DateUtils.getTimeBefore(1, new Date()); + List tjTimeList = DateUtils.getTjTimeList(startdate, enddate, "0"); + List tjList = tjTimeList.stream().map(d -> d.substring(5).replace("-", "/")).collect(Collectors.toList()); + List tempDatalist = new LinkedList<>(); + for (String tj : tjList) { + Optional first = wxUserVisitList.stream().filter(c -> c.getxTime().equals(tj)).findFirst(); + if (!first.isPresent()) { + TouchUsersReportVo touchUsersReportVo = new TouchUsersReportVo(); + touchUsersReportVo.setPv(0); + touchUsersReportVo.setUv(0); + touchUsersReportVo.setCouponCount(0); + touchUsersReportVo.setUserCount(0); + touchUsersReportVo.setVerifyCount(0); + touchUsersReportVo.setVerifyUserCount(0); + touchUsersReportVo.setxTime(tj); + tempDatalist.add(touchUsersReportVo); + continue; + } + tempDatalist.add(first.get()); + } + return new ResultData(tempDatalist); + } + + /** + * 场景营销数据 + * @param tenantId + * @return + */ + private ResultData getSceneData(String tenantId) { + String startdate; + String enddate; + HashMap datamap = new HashMap<>(); + + HashMap params = new HashMap<>(); + params.put("tenantId", tenantId); + params.put("startTime", addDay(-30)); + params.put("endTime", addDay(1)); + //停车发券数 停车发券被核销数 核销发券数 核销发券被核销数 + List list = wxCouponActionLogMapper.sceneDataMap(params); + + //停车发券被核销数 + HashMap params1 = new HashMap<>(); + params1.put("tenantId", tenantId); + params1.put("startTime", addDay(-30)); + params1.put("endTime", addDay(1)); + params1.put("channelType", EnumCouponSendSendType.CAR_STOP.getCode());//停车 + List list1 = wxCouponActionLogMapper.sceneDataMapJoinCouponOrder(params1); + Map parkCountMap = list1.stream().collect(Collectors.toMap(MarkingSceneDataReportVo::getXTime, p -> p.getTempCount())); + + //核销发券被核销数 + HashMap params2 = new HashMap<>(); + params2.put("tenantId", tenantId); + params2.put("startTime", addDay(-30)); + params2.put("endTime", addDay(1)); + params2.put("channelType", EnumCouponSendSendType.COUPON_VERIFY.getCode());//核销 + List list2 = wxCouponActionLogMapper.sceneDataMapJoinCouponOrder(params2); + Map verifyCountMap = list2.stream().collect(Collectors.toMap(MarkingSceneDataReportVo::getXTime, p -> p.getTempCount())); + + // B端刷卡支付被核销数 + HashMap params3 = new HashMap<>(); + params3.put("tenantId", tenantId); + params3.put("startTime", addDay(-30)); + params3.put("endTime", addDay(1)); + params3.put("channelType", EnumCouponSendSendType.B_MICROPAY.getCode());//B端刷卡支付 + List list3 = wxCouponActionLogMapper.sceneDataMapJoinCouponOrder(params3); + Map microPayCountMap = list3.stream().collect(Collectors.toMap(MarkingSceneDataReportVo::getXTime, p -> p.getTempCount())); + + // 购买发券被核销数 + HashMap params4 = new HashMap<>(); + params3.put("tenantId", tenantId); + params3.put("startTime", addDay(-30)); + params3.put("endTime", addDay(1)); + params3.put("channelType", EnumCouponSendSendType.C_ORDER.getCode());//买券 + List list4 = wxCouponActionLogMapper.sceneDataMapJoinCouponOrder(params4); + Map OrderCountMap = list4.stream().collect(Collectors.toMap(MarkingSceneDataReportVo::getXTime, p -> p.getTempCount())); + + for (MarkingSceneDataReportVo vo : list) { + vo.setParkCount(parkCountMap.get(vo.getXTime()) == null ? 0 : parkCountMap.get(vo.getXTime())); + vo.setVerifyCount(verifyCountMap.get(vo.getXTime()) == null ? 0 : verifyCountMap.get(vo.getXTime())); + vo.setMicroPayCount(microPayCountMap.get(vo.getXTime()) == null ? 0 : microPayCountMap.get(vo.getXTime())); + vo.setOrderCount(OrderCountMap.get(vo.getXTime()) == null ? 0 : OrderCountMap.get(vo.getXTime())); + } + + startdate = DateUtils.getTimeBefore(30, new Date()); + enddate = DateUtils.getTimeBefore(1, new Date()); + List tjTimeList = DateUtils.getTjTimeList(startdate, enddate, "0"); + List tjList = tjTimeList.stream().map(d -> d.substring(5).replace("-", "/")).collect(Collectors.toList()); + List tempDatalist = new LinkedList<>(); + + for (String tj : tjList) { + Optional first = list.stream().filter(c -> c.getXTime().equals(tj)).findFirst(); + + MarkingSceneDataReportVo msdVo; + if (!first.isPresent()) { + msdVo = new MarkingSceneDataReportVo(); + msdVo.setXTime(tj); + msdVo.setCarCount(0); + msdVo.setParkCount(0); + msdVo.setVerifyCount(0); + msdVo.setMicroPayCount(0); + msdVo.setOrderCount(0); + msdVo.setTempCount(0); + msdVo.setParkSendCount(0); + msdVo.setVerifySendCount(0); + msdVo.setMicroPaySendCount(0); + msdVo.setOrderSendCount(0); + msdVo.setTotal(0); + } else { + msdVo = first.get(); + msdVo.setTotal(msdVo.getParkSendCount() + + msdVo.getVerifySendCount() + + msdVo.getMicroPaySendCount() + + msdVo.getOrderSendCount()); + } + tempDatalist.add(msdVo); + } + datamap.put("sceneDataMap", tempDatalist); + return new ResultData(datamap); + } + + /** + * 活跃用户 + * @param tenantId + * @return + */ + private ResultData getNewUserCount(String tenantId) { + HashMap datamap = new HashMap<>(); + WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); + dto.setTenantId(tenantId); + long allCount = wxCUserMapper.findCount(dto);//总数 + Calendar c = Calendar.getInstance(); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + Date today = c.getTime(); + c.setTime(today); + c.add(Calendar.DAY_OF_YEAR, -1); + dto.setStartTime(c.getTime()); + c.add(Calendar.DAY_OF_YEAR, 1); + dto.setEndTime(c.getTime()); + long todayCount = wxCUserMapper.findCount(dto); + datamap.put("allCount", allCount);//会员总数 + datamap.put("todayCount", todayCount);//今日新增会员数 + return new ResultData(datamap); + } + + /** + * 活跃用户 + * @param tenantId + * @return + */ + private ResultData getActiveMemberCount(String tenantId) { + HashMap datamap = new HashMap<>(); + HashMap params = new HashMap<>(); + Calendar c = Calendar.getInstance(); + c.add(Calendar.DAY_OF_YEAR, -1); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + Date endTime = c.getTime(); + c.add(Calendar.DAY_OF_YEAR, -30); + Date startTime = c.getTime(); + params.put("startTime", startTime); + params.put("endTime", endTime); + params.put("tenantId", tenantId); + List list = wxUserVisitMapper.touchUsersReportList(params); + String yesterday = DateUtils.getTimeBefore(1, new Date()); + List collect = list.parallelStream().filter(x -> x.getxTime().equals(yesterday)).collect(Collectors.toList()); + int yesterdayCount = 0; + if (!collect.isEmpty()) { + yesterdayCount = collect.get(0).getUv(); + } + Integer thisMonthCount = list.parallelStream().collect(Collectors.summingInt(u -> u.getUv())); + datamap.put("yesterdayCount", yesterdayCount);//昨日活跃数 + datamap.put("thisMonthCount", thisMonthCount);//近一个月活跃数 + return new ResultData(datamap); + } + + /** + * 线上交易 + * @param tenantId + * @return + */ + private ResultData getOnlineOrderCount(String tenantId) { + HashMap datamap = new HashMap<>(); + Calendar c = Calendar.getInstance(); + c.add(Calendar.DAY_OF_YEAR, 1); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + Date endTime = c.getTime();//明天0点 + c.add(Calendar.DAY_OF_YEAR, -30); + Date startTime = c.getTime(); + int thisMonthCount = wxCouponOrderMapper.queryPriceTotal(tenantId, startTime, endTime);//月消费金额 + c.clear(); + c.add(Calendar.DAY_OF_YEAR, -1); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + startTime = c.getTime(); + int todayCount = wxCouponOrderMapper.queryPriceTotal(tenantId, startTime, endTime);//月消费金额 + DecimalFormat df = new DecimalFormat("0.00"); + datamap.put("todayCount", df.format((float) todayCount / 100));//今日消费金额 + String thisMonthCountStr = df.format((float) thisMonthCount / 100); + datamap.put("thisMonthCount", thisMonthCountStr);//近一个月消费金额数 + return new ResultData(datamap); + } + + private ResultData getNewMemberCount(String tenantId, int days, String returnName) { + HashMap datamap = new HashMap<>(); + WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); + dto.setTenantId(tenantId); + Calendar c = Calendar.getInstance(); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + Date today = c.getTime(); + List weekVos = new ArrayList<>();//周会员数 + for (int i = days, sortNum = 0; i >= 0; i--) { + c.clear(); + c.setTime(today); + c.add(Calendar.DAY_OF_YEAR, -i); + dto.setStartTime(c.getTime()); + c.add(Calendar.DAY_OF_YEAR, 1); + dto.setEndTime(c.getTime()); + long count = wxCUserMapper.findCount(dto); + UserStructureVo vo = new UserStructureVo(); + vo.setName(new SimpleDateFormat("MM/dd").format(dto.getStartTime())); + vo.setSortNum(sortNum++); + vo.setCount(count); + weekVos.add(vo); + } + datamap.put(returnName, weekVos);//月用户增加数列表 + return new ResultData(datamap); + } + + /** + * 近一周新增用户数 + * @param tenantId + * @return + */ + private ResultData getNewMemberInWeek(String tenantId) { + return getNewMemberCount(tenantId, 7, "weekVos"); + } + + /** + * 近一周活跃用户数 + * @param tenantId + * @return + */ + private ResultData getActiveMemberCountInWeek(String tenantId) { + HashMap datamap = new HashMap<>(); + HashMap params = new HashMap<>(); + Calendar c = Calendar.getInstance(); + c.add(Calendar.DAY_OF_YEAR, -1); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + Date endTime = c.getTime(); + c.add(Calendar.DAY_OF_YEAR, -7); + Date startTime = c.getTime(); + params.put("startTime", startTime); + params.put("endTime", endTime); + params.put("tenantId", tenantId); + List list = wxUserVisitMapper.touchUsersReportList(params); + Map dateMap = new HashMap<>(); + for (TouchUsersReportVo vo : list) { + dateMap.put(vo.getxTime(), vo); + } + List weekVos = new ArrayList<>();//每周uv + for (int i = 7, sortNum = 0; i >= 0; i--) { + c.clear(); + c.setTime(endTime); + c.add(Calendar.DAY_OF_YEAR, -i); + String dayStr = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()); + UserStructureVo vo = new UserStructureVo(); + vo.setName(new SimpleDateFormat("MM/dd").format(c.getTime())); + vo.setSortNum(sortNum++); + if (dateMap.get(dayStr) != null) { + TouchUsersReportVo rv = dateMap.get(dayStr); + Long l = new Long((long) rv.getUv()); + vo.setCount(l); + } else { + vo.setCount(0); + } + weekVos.add(vo); + } + datamap.put("weekVos", weekVos);//周活跃数列表 + return new ResultData(datamap); + } + + /** + * 近一周线上交易金额(元) + * @param tenantId + * @return + */ + private ResultData getWeekMoneyData(String tenantId) { + HashMap datamap = new HashMap<>(); + Calendar c = Calendar.getInstance(); + Date today = c.getTime(); + c.add(Calendar.DAY_OF_YEAR, 1); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + Date endTime = c.getTime();//明天0点 + c.add(Calendar.DAY_OF_YEAR, -30);//三十天前 + c.clear(); + c.setTime(endTime); + Date eTime = c.getTime(); + c.add(Calendar.DAY_OF_YEAR, -7); + Date sTime = c.getTime(); + List datas = wxCouponOrderMapper.queryPriceTotalGroup(tenantId, sTime, eTime); + Map dataMap = new HashMap<>(); + for (CUserDateAmountVo v : datas) { + dataMap.put(v.getxTime(), v.getPrice()); + } + List weekVos = new ArrayList<>();//周消费金额 + for (int i = 7, sortNum = 0; i >= 0; i--) { + c.clear(); + c.setTime(today); + c.add(Calendar.DAY_OF_YEAR, -i); + String dateStr = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()); + UserStructureVo vo = new UserStructureVo(); + vo.setName(new SimpleDateFormat("MM/dd").format(c.getTime())); + vo.setSortNum(sortNum++); + if (dataMap.get(dateStr) != null) { + int price = dataMap.get(dateStr); + vo.setPrice(price); + } else { + vo.setPrice(0); + } + weekVos.add(vo); + } + datamap.put("weekVos", weekVos);//一周金额列表 + return new ResultData(datamap); + } + + /** + * 销售数据 + * @param tenantId + * @return + */ + private ResultData getSaleAnalysis(String tenantId) { + HashMap datamap = new HashMap<>(); + Calendar c = Calendar.getInstance(); + Date sTime = c.getTime(); + c.add(Calendar.DAY_OF_YEAR, 1); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + Date eTime = c.getTime();//明天0点 + c.add(Calendar.DAY_OF_YEAR, -30);//三十天前 + List datas = wxCouponOrderMapper.queryPriceTotalGroup(tenantId, sTime, eTime); + List monthVos = new ArrayList<>();//周消费金额 + Map dataMap = new HashMap<>(); + for (CUserDateAmountVo v : datas) { + dataMap.put(v.getxTime(), v.getPrice()); + } + for (int i = 29, sortNum = 0; i >= 0; i--) { + c.clear(); + c.setTime(sTime); + c.add(Calendar.DAY_OF_YEAR, -i); + String dateStr = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()); + UserStructureVo vo = new UserStructureVo(); + vo.setName(new SimpleDateFormat("MM/dd").format(c.getTime())); + vo.setSortNum(sortNum++); + if (datamap.get(dateStr) != null) { + int price = dataMap.get(dateStr); + vo.setPrice(price); + } else { + vo.setPrice(0); + } + monthVos.add(vo); + } + datamap.put("monthVos", monthVos);//一月金额列表 + return new ResultData(datamap); + } + + private ResultData getActiveMemberAnalysis(String tenantId) { + HashMap datamap = new HashMap<>(); + HashMap params = new HashMap<>(); + Calendar c = Calendar.getInstance(); + c.add(Calendar.DAY_OF_YEAR, -1); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + Date endTime = c.getTime(); + c.add(Calendar.DAY_OF_YEAR, -30); + Date startTime = c.getTime(); + params.put("startTime", startTime); + params.put("endTime", endTime); + params.put("tenantId", tenantId); + List list = wxUserVisitMapper.touchUsersReportList(params); + Map dateMap = new HashMap<>(); + for (TouchUsersReportVo vo : list) { + dateMap.put(vo.getxTime(), vo); + } + List monthVos = new ArrayList<>();//每月uv + for (int i = 29, sortNum = 0; i >= 0; i--) { + c.clear(); + c.setTime(endTime); + c.add(Calendar.DAY_OF_YEAR, -i); + String dayStr = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()); + UserStructureVo vo = new UserStructureVo(); + vo.setName(new SimpleDateFormat("MM/dd").format(c.getTime())); + vo.setSortNum(sortNum++); + if (dateMap.get(dayStr) != null) { + TouchUsersReportVo rv = dateMap.get(dayStr); + Long l = new Long((long) rv.getUv()); + vo.setCount(l); + } else { + vo.setCount(0); + } + monthVos.add(vo); + } + datamap.put("monthVos", monthVos);//月活跃数列表 + return new ResultData(datamap); + } + + /** + * 新增用户趋势-月 + * @param tenantId + * @return + */ + private ResultData getNewMemberTradeMonthly(String tenantId) { + return getNewMemberCount(tenantId, 29, "monthVos"); + } + + /** + * 活跃用户趋势 + * @param tenantId + * @return + */ + private ResultData getActiveMemberTrade(String tenantId) { + HashMap datamap = new HashMap<>(); + HashMap params = new HashMap<>(); + Calendar c = Calendar.getInstance(); + c.add(Calendar.DAY_OF_YEAR, -1); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + Date endTime = c.getTime(); + c.add(Calendar.DAY_OF_YEAR, -30); + Date startTime = c.getTime(); + params.put("startTime", startTime); + params.put("endTime", endTime); + params.put("tenantId", tenantId); + List list = wxUserVisitMapper.touchUsersReportList(params); + Map dateMap = new HashMap<>(); + for (TouchUsersReportVo vo : list) { + dateMap.put(vo.getxTime(), vo); + } + List monthVos = new ArrayList<>();//每月uv + for (int i = 29, sortNum = 0; i >= 0; i--) { + c.clear(); + c.setTime(endTime); + c.add(Calendar.DAY_OF_YEAR, -i); + String dayStr = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()); + UserStructureVo vo = new UserStructureVo(); + vo.setName(new SimpleDateFormat("MM/dd").format(c.getTime())); + vo.setSortNum(sortNum++); + if (dateMap.get(dayStr) != null) { + TouchUsersReportVo rv = dateMap.get(dayStr); + Long l = new Long((long) rv.getUv()); + vo.setCount(l); } else { - startTime = DateUtils.stringToDate(startdate + " 00:00:00"); - params.put("startdate", startTime); + vo.setCount(0); } - if (StringUtils.isEmpty(paramsMap.get("enddate"))) { - params.put("enddate", endTime); + monthVos.add(vo); + } + datamap.put("monthVos", monthVos);//月活跃数列表 + return new ResultData(datamap); + } + + /** + * 线上交易趋势 + * @param tenantId + * @return + */ + private ResultData getOnlineTrade(String tenantId) { + HashMap datamap = new HashMap<>(); + Calendar c = Calendar.getInstance(); + Date today = c.getTime(); + c.add(Calendar.DAY_OF_YEAR, 1); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + Date eTime = c.getTime();//明天0点 + c.add(Calendar.DAY_OF_YEAR, -30);//三十天前 + Date sTime = c.getTime(); + List datas = wxCouponOrderMapper.queryPriceTotalGroup(tenantId, sTime, eTime); + Map dataMap = new HashMap<>(); + for (CUserDateAmountVo v : datas) { + dataMap.put(v.getxTime(), v.getPrice()); + } + List monthVos = new ArrayList<>(); + for (int i = 29, sortNum = 0; i >= 0; i--) { + c.clear(); + c.setTime(today); + c.add(Calendar.DAY_OF_YEAR, -i); + String dateStr = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()); + UserStructureVo vo = new UserStructureVo(); + vo.setName(new SimpleDateFormat("MM/dd").format(c.getTime())); + vo.setSortNum(sortNum++); + if (dataMap.get(dateStr) != null) { + int price = dataMap.get(dateStr); + vo.setPrice(price); } else { - endTime = DateUtils.stringToDate(paramsMap.get("enddate") + " 23:59:59", "yyyy-MM-dd HH:mm:ss"); - params.put("enddate", paramsMap.get("enddate") + " 23:59:59"); + vo.setPrice(0); } - List> successlist = wxOrderGroupMapper.queryOrderGroupSuccessCountAndTime(params); - List> verifyList = wxOrderGroupMapper.queryOrderGroupVerifyCountAndTime(params); - - Map successMap = getDateMap(startTime, endTime); - Map verifyMap = getDateMap(startTime, endTime); - - long successCount = wxOrderGroupMapper.queryOrderGroupSuccessCount(params); - long groupCount = wxOrderGroupMapper.queryOrderGroupCount(params); - long peopleCount = wxOrderGroupMapper.queryOrderGroupPeopleCount(params); - double transferRatio = 0; - if (groupCount > 0) { - double transfer = (double) successCount / groupCount * 100; - transferRatio = new BigDecimal(transfer).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + monthVos.add(vo); + } + datamap.put("monthVos", monthVos);//一月金额列表 + return new ResultData(datamap); + } + + /** + * 微信用户总数 + * @param tenantId + * @return + */ + private ResultData getMemeberWechatTotal(String tenantId) { + HashMap datamap = new HashMap<>(); + WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); + dto.setTenantId(tenantId); + //微信用户数据 + long wxallCount = wxCUserMapper.findCount(dto);//总量 + Calendar c = Calendar.getInstance(); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + Date today = c.getTime(); + dto.setStartTime(today); + dto.setEndTime(null); + long wxtodayCount = wxCUserMapper.findCount(dto);//今天新增 + datamap.put("wxallCount", wxallCount);//累计会员总数 + datamap.put("wxtodayCount", wxtodayCount);//今日新增会员数 + return new ResultData(datamap); + } + + /** + * 会员总数 + * @param tenantId + * @return + */ + private ResultData getMemberTotalCount(String tenantId) { + HashMap datamap = new HashMap<>(); + WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); + dto.setTenantId(tenantId); + long allCount = wxCUserBasicInfoMapper.findCount(dto);//总量 + Calendar c = Calendar.getInstance(); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + Date today = c.getTime(); + dto.setStartTime(today); + dto.setEndTime(null); + long todayCount = wxCUserBasicInfoMapper.findCount(dto);//今天新增 + datamap.put("allCount", allCount);//累计会员总数 + datamap.put("todayCount", todayCount);//今日新增会员数 + return new ResultData(datamap); + } + + /** + * 微信用户累计趋势 + * @param tenantId + * @return + */ + private ResultData getMemberWechatJoinTrade(String tenantId) { + HashMap datamap = new HashMap<>(); + final int daysBefore = 29; + WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); + dto.setTenantId(tenantId); + Calendar c = Calendar.getInstance(); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + Date today = c.getTime(); + List wxnewCountVos = new ArrayList<>();//每日新增会员数 + int j = 1; + for (int i = daysBefore; i >= 0; i--) { + c.clear(); + c.setTime(today); + c.add(Calendar.DAY_OF_YEAR, -i); + dto.setStartTime(c.getTime()); + c.add(Calendar.DAY_OF_YEAR, 1); + dto.setEndTime(c.getTime()); + long count = wxCUserMapper.findCount(dto); + UserStructureVo vo = new UserStructureVo(); + vo.setSortNum(j); + j++; + vo.setName(new SimpleDateFormat("MM/dd").format(dto.getStartTime())); + vo.setCount(count); + wxnewCountVos.add(vo); + } + List wxallCountVos = new ArrayList<>();//累计会员数 + c.clear(); + c.setTime(today); + c.add(Calendar.DAY_OF_YEAR, -daysBefore); + dto.setEndTime(c.getTime()); + dto.setStartTime(null); + long firstDay = wxCUserMapper.findCount(dto);//统计的第一天总数 + int i = 0; + long sumCount = 0; + for (UserStructureVo v : wxnewCountVos) { + UserStructureVo vo = new UserStructureVo(); + sumCount += v.getCount(); + vo.setCount(firstDay + sumCount); + vo.setName(v.getName()); + vo.setSortNum(i + 1); + wxallCountVos.add(vo); + i++; + } + datamap.put("wxallCountVos", wxallCountVos);//累计会员列表( 日期和数量list) + return new ResultData(datamap); + } + + /** + * 券交易数据 + * @param tenantId + * @return + */ + private ResultData getCouponSaleAnalysis(String tenantId) { + String startdate; + String enddate; + HashMap datamap = new HashMap<>(); + //couponData + HashMap params = new HashMap<>(); + params.put("tenantId", tenantId); + params.put("startTime", addDay(-30)); + params.put("endTime", addDay(1)); + List couponDatalist = wxCouponOrderMapper.couponDataMap(params); + //查询券领取人数 + startdate = DateUtils.getTimeBefore(30, new Date()); + enddate = DateUtils.getTimeBefore(1, new Date()); + List tjTimeList = DateUtils.getTjTimeList(startdate, enddate, "0"); + List tjList = tjTimeList.stream().map(d -> d.substring(5).replace("-", "/")).collect(Collectors.toList()); + List couponTempDatalist = new LinkedList<>(); + for (String tj : tjList) { + Optional first = couponDatalist.stream().filter(c -> c.getCreateTime().equals(tj)).findFirst(); + if (!first.isPresent()) { + MarkingCouponDataReportVo markingCouponDataReportVo = new MarkingCouponDataReportVo(); + markingCouponDataReportVo.setCreateTime(tj); + markingCouponDataReportVo.setCouponCount(0); + markingCouponDataReportVo.setCouponUserCount(0); + markingCouponDataReportVo.setVerifyCount(0); + markingCouponDataReportVo.setVerifyUserCount(0); + couponTempDatalist.add(markingCouponDataReportVo); + continue; + } + couponTempDatalist.add(first.get()); + } + datamap.put("couponDataMap", couponTempDatalist); + return new ResultData(datamap); + } + + /** + * 会员累计趋势 + * @param tenantId + * @return + */ + private ResultData getMemberJoinTrade(String tenantId) { + HashMap datamap = new HashMap<>(); + WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); + dto.setTenantId(tenantId); + final int daysBefore = 29; + Calendar c = Calendar.getInstance(); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + Date today = c.getTime(); + List newCountVos = new ArrayList<>();//每日新增会员数 + int j = 1; + for (int i = daysBefore; i >= 0; i--) { + c.clear(); + c.setTime(today); + c.add(Calendar.DAY_OF_YEAR, -i); + dto.setStartTime(c.getTime()); + c.add(Calendar.DAY_OF_YEAR, 1); + dto.setEndTime(c.getTime()); + long count = wxCUserBasicInfoMapper.findCount(dto); + UserStructureVo vo = new UserStructureVo(); + vo.setSortNum(j); + j++; + vo.setName(new SimpleDateFormat("MM/dd").format(dto.getStartTime())); + vo.setCount(count); + newCountVos.add(vo); + } + List allCountVos = new ArrayList<>();//累计会员数 + c.clear(); + c.setTime(today); + c.add(Calendar.DAY_OF_YEAR, -daysBefore); + dto.setEndTime(c.getTime()); + dto.setStartTime(null); + long firstDay = wxCUserBasicInfoMapper.findCount(dto);//统计的第一天总数 + int i = 0; + long sumCount = 0; + for (UserStructureVo v : newCountVos) { + UserStructureVo vo = new UserStructureVo(); + sumCount += v.getCount(); + vo.setCount(firstDay + sumCount); + vo.setName(v.getName()); + vo.setSortNum(i + 1); + allCountVos.add(vo); + i++; + } + datamap.put("allCountVos", allCountVos);//累计会员列表( 日期和数量list) + return new ResultData(datamap); + } + + /** + * 拓客渠道 + * @param tenantId + * @return + */ + private ResultData getFromChannelAnalysis(String tenantId) { + HashMap datamap = new HashMap<>(); + List channelStructureList = new ArrayList<>(); + WxCUser wxCUser = new WxCUser(); + wxCUser.setTenantId(tenantId); + List channels = wxUserChannelMapper.findDistinctChannel(); + for (WxUserChannel w : channels) { + WxUserChannel c = new WxUserChannel(); + c.setChannelName(w.getChannelName()); + PageInfo page = PageHelper.startPage(1, 1000).doSelectPageInfo(() -> wxUserChannelMapper.findList(c)); + if (page.getSize() > 0) { + List sceneList = new ArrayList<>(); + for (WxUserChannel uc : page.getList()) { + List scene = new ArrayList<>(); + scene.add(uc.getSceneAddress()); + wxCUser.setSceneList(scene); + sceneList.add(uc.getSceneAddress()); + } + wxCUser.setSceneList(sceneList); + WxUserChannel channelStructure = new WxUserChannel(); + channelStructure.setChannelName(w.getChannelName()); + channelStructure.setCount(wxCUserMapper.countByChannel(wxCUser)); + channelStructureList.add(channelStructure); } + } + datamap.put("channelList", channelStructureList); + return new ResultData(datamap); + } - Map successListMap = successlist.parallelStream().collect(Collectors.toMap(x -> { - return x.get("time").toString(); - }, x -> { - return x.get("total").toString(); - })); + /** + * 微信用户新增趋势 + * @param tenantId + * @return + */ + private ResultData getWechatMemberTrade(String tenantId) { + HashMap datamap = new HashMap<>(); + final int daysBefore = 29; + WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); + dto.setTenantId(tenantId); + Calendar c = Calendar.getInstance(); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + Date today = c.getTime(); + List wxnewCountVos = new ArrayList<>();//每日新增会员数 + int j = 1; + for (int i = daysBefore; i >= 0; i--) { + c.clear(); + c.setTime(today); + c.add(Calendar.DAY_OF_YEAR, -i); + dto.setStartTime(c.getTime()); + c.add(Calendar.DAY_OF_YEAR, 1); + dto.setEndTime(c.getTime()); + long count = wxCUserMapper.findCount(dto); + UserStructureVo vo = new UserStructureVo(); + vo.setSortNum(j); + j++; + vo.setName(new SimpleDateFormat("MM/dd").format(dto.getStartTime())); + vo.setCount(count); + wxnewCountVos.add(vo); + } + datamap.put("wxnewCountVos", wxnewCountVos);//新增会员列表(日期和数量list) + return new ResultData(datamap); + } - Map verifyListMap = verifyList.parallelStream().collect(Collectors.toMap(x -> { - return x.get("time").toString(); - }, x -> { - return x.get("total").toString(); - })); + /** + * 会员新增趋势 + * @param tenantId + * @return + */ + private ResultData getNewMemberTrade(String tenantId) { + HashMap datamap = new HashMap<>(); + WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); + dto.setTenantId(tenantId); + final int daysBefore = 29; + Calendar c = Calendar.getInstance(); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + Date today = c.getTime(); + List newCountVos = new ArrayList<>();//每日新增会员数 + int j = 1; + for (int i = daysBefore; i >= 0; i--) { + c.clear(); + c.setTime(today); + c.add(Calendar.DAY_OF_YEAR, -i); + dto.setStartTime(c.getTime()); + c.add(Calendar.DAY_OF_YEAR, 1); + dto.setEndTime(c.getTime()); + long count = wxCUserBasicInfoMapper.findCount(dto); + UserStructureVo vo = new UserStructureVo(); + vo.setSortNum(j); + j++; + vo.setName(new SimpleDateFormat("MM/dd").format(dto.getStartTime())); + vo.setCount(count); + newCountVos.add(vo); + } + datamap.put("newCountVos", newCountVos);//新增会员列表(日期和数量list) + return new ResultData(datamap); + } - successMap.putAll(successListMap); - verifyMap.putAll(verifyListMap); + /** + * 场景排名 + * @param tenantId + * @return + */ + private ResultData getSceneAnalysis(String tenantId) { + HashMap datamap = new HashMap<>(); + List senceStructureList = new ArrayList<>(); + WxCUser wxCUser = new WxCUser(); + wxCUser.setTenantId(tenantId); + List channels = wxUserChannelMapper.findDistinctChannel(); + for (WxUserChannel w : channels) { + WxUserChannel c = new WxUserChannel(); + c.setChannelName(w.getChannelName()); + PageInfo page = PageHelper.startPage(1, 1000).doSelectPageInfo(() -> wxUserChannelMapper.findList(c)); + if (page.getSize() > 0) { + for (WxUserChannel uc : page.getList()) { + List scene = new ArrayList<>(); + scene.add(uc.getSceneAddress()); + wxCUser.setSceneList(scene); + WxUserChannel senceStructure = new WxUserChannel(); + senceStructure.setDescription(uc.getDescription()); + senceStructure.setCount(wxCUserMapper.countByChannel(wxCUser)); + senceStructureList.add(senceStructure); + } + } + } + Collections.sort(senceStructureList, (s1, s2) -> ((int) (s2.getCount() - s1.getCount()))); + datamap.put("senceList", senceStructureList.subList(0, 10)); + return new ResultData(datamap); + } - result.put("successList", successMap); - result.put("verifyList", verifyMap); + /** + * 会员性别比例 TODO + * @param tenantId + * @param startdate + * @param enddate + * @return + */ + private ResultData getMemberSexRate(String tenantId, String startdate, String enddate) { + HashMap datamap = new HashMap<>(); + WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); + dto.setTenantId(tenantId); + dto.setStartTime(DateUtils.stringToDate(startdate + " 00:00:00")); + dto.setEndTime(DateUtils.stringToDate(enddate + " 23:59:59")); + long all = wxCUserBasicInfoMapper.findCount(dto); + List vos = new ArrayList<>(); + Calendar c = Calendar.getInstance(); + for (EnumAgeInfo a : EnumAgeInfo.values()) { + c.clear(); + c.setTime(new Date()); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + long count = getCountByAge(a, c, dto); + vos.add(getVo(count, all, a.getDesc(), a.getSortNum())); + } + return new ResultData(datamap); + } - result.put("successCount", successCount); - result.put("groupCount", groupCount); - result.put("peopleCount", peopleCount); - result.put("transferRatio", transferRatio); + /** + * 会员绑定车牌率 + * @param tenantId + * @param startdate + * @param enddate + * @return + */ + private ResultData getMemberBindCar(String tenantId, String startdate, String enddate) { + WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); + dto.setTenantId(tenantId); + dto.setStartTime(DateUtils.stringToDate(startdate + " 00:00:00")); + dto.setEndTime(DateUtils.stringToDate(enddate + " 23:59:59")); + long total = wxCUserBasicInfoMapper.findCount(dto); + long userCountWithCar = wxCUserCarMapper.countUser(dto); + Map userWithCar = new HashMap(); + userWithCar.put("title", "已绑定车牌"); + userWithCar.put("count", userCountWithCar); + long userCountWithoutCar = total - userCountWithCar; + Map userWithoutCar = new HashMap(); + userWithoutCar.put("title", "未绑定车牌"); + userWithoutCar.put("count", userCountWithoutCar); + NumberFormat nf = NumberFormat.getPercentInstance(); + nf.setMinimumFractionDigits(2); + if (userCountWithoutCar + userCountWithCar > 0) { + userWithCar.put("percentage", nf.format(userCountWithCar / new Double(userCountWithoutCar + userCountWithCar).doubleValue())); + userWithoutCar.put("percentage", nf.format(userCountWithoutCar / new Double(userCountWithoutCar + userCountWithCar).doubleValue())); + } else { + userWithCar.put("percentage", "--"); + userWithoutCar.put("percentage", "--"); + } + List list = new ArrayList<>(); + list.add(userWithCar); + list.add(userWithoutCar); + return new ResultData(list); + } - return new ResultData(result); + /** + * 会员年龄层次 + * @param tenantId + * @param startdate + * @param enddate + * @return + */ + private ResultData getMemberAgeAnalysis(String tenantId, String startdate, String enddate) { + HashMap datamap = new HashMap<>(); + WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); + dto.setTenantId(tenantId); + dto.setStartTime(DateUtils.stringToDate(startdate + " 00:00:00")); + dto.setEndTime(DateUtils.stringToDate(enddate + " 23:59:59")); + long all = wxCUserBasicInfoMapper.findCount(dto); + List vos = new ArrayList<>(); + Calendar c = Calendar.getInstance(); + for (EnumAgeInfo a : EnumAgeInfo.values()) { + c.clear(); + c.setTime(new Date()); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + long count = getCountByAge(a, c, dto); + vos.add(getVo(count, all, a.getDesc(), a.getSortNum())); } + return new ResultData(datamap); + } + /** + * 会员成长值 + * @param tenantId + * @param startdate + * @param enddate + * @return + */ + private ResultData getMemberGrowthAnalysis(String tenantId, String startdate, String enddate) { + WxLevelConfig wxLevelConfig = new WxLevelConfig(); + wxLevelConfig.setTenantId(tenantId); + wxLevelConfig.setSortColumns(WxLevelConfig.Field.Points_ASC); + List levelList = wxLevelConfigMapper.findList(wxLevelConfig); + + for (int i = 0; i < levelList.size(); i++) { + + WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); + dto.setTenantId(tenantId); + dto.setStartTime(DateUtils.stringToDate(startdate + " 00:00:00")); + dto.setEndTime(DateUtils.stringToDate(enddate + " 23:59:59")); + if (i + 1 < levelList.size()) { + dto.setLevelStartScore(levelList.get(i).getPoints()); + dto.setLevelEndScore(levelList.get(i + 1).getPoints()); + } else { + dto.setLevelStartScore(levelList.get(i).getPoints()); + } + long all = wxCUserBasicInfoMapper.findCountByScore(dto); + + levelList.get(i).setCount(all); + } + WxLevelConfig other = new WxLevelConfig(); + //没有等级的会员 + other.setLevel("无"); + WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); + other.setCount(wxCUserBasicInfoMapper.findCount(dto) + - levelList.stream().map(WxLevelConfig::getCount).reduce(Long::sum).orElse(0L)); + levelList.add(other); + return new ResultData(levelList); + } + + /** + * 会员手机品牌 + * @param tenantId + * @param startdate + * @param enddate + * @return + */ + private ResultData getMobileBrandAnalysis(String tenantId, String startdate, String enddate) { + WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); + dto.setTenantId(tenantId); + Date startTime = DateUtils.stringToDate(startdate + " 00:00:00"); + Date endTime = DateUtils.stringToDate(enddate + " 23:59:59"); + dto.setStartTime(startTime); + dto.setEndTime(endTime); + long total = wxCUserBasicInfoMapper.findCount(dto); + List tagList = new ArrayList<>(); + EnumTag[] tags = {EnumTag.ID_49, + EnumTag.ID_50, + EnumTag.ID_51, + EnumTag.ID_52, + EnumTag.ID_53, + EnumTag.ID_54}; + for (int i = 0; i < tags.length; i++) { + WxTags tag = new WxTags(); + tag.setName(tags[i].getMessage()); + tag.setCount(wxCUserTagsMapper.countUser(JSON.toJSONString(tags[i].getCode()), tenantId, startTime, endTime)); + tagList.add(tag); + total -= tag.getCount(); + } + + WxTags tag = new WxTags(); + tag.setName("暂未获取"); + tag.setCount(total); + tagList.add(tag); + return new ResultData(tagList); + } + + /** + * 会员活跃度 + * @param tenantId + * @param startdate + * @param enddate + * @return + */ + private ResultData getMemActivity(String tenantId, String startdate, String enddate) { + WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); + dto.setTenantId(tenantId); + Date startTime = DateUtils.stringToDate(startdate + " 00:00:00"); + Date endTime = DateUtils.stringToDate(enddate + " 23:59:59"); + dto.setStartTime(startTime); + dto.setEndTime(endTime); + long total = wxCUserBasicInfoMapper.findCount(dto); + List tagList = new ArrayList<>(); + EnumTag[] tags = { + EnumTag.ID_112, + EnumTag.ID_111, + EnumTag.ID_110 + }; + for (int i = 0; i < tags.length; i++) { + WxTags tag = new WxTags(); + tag.setName(tags[i].getMessage()); + tag.setCount(wxCUserTagsMapper.countUser(JSON.toJSONString(tags[i].getCode()), tenantId, startTime, endTime)); + tagList.add(tag); + total -= tag.getCount(); + } + WxTags tag = new WxTags(); + tag.setName("休眠"); + tag.setCount(total); + tagList.add(tag); + return new ResultData(tagList); + } + + /** + * 卡营销数据 + * @param paramsMap + * @param startdate + * @param enddate + * @return + */ + private ResultData getSaleCardAnalysis(Map paramsMap, String startdate, String enddate) { + WxCoupon wxCoupon = new WxCoupon(); + + //默认时间本月第一天,截止到当天 + if (StringUtils.isEmpty(paramsMap.get("startdate"))) { + wxCoupon.setStartdate(getMonthFirstDay()); + }else{ + Date startTime = DateUtils.stringToDate(startdate); + wxCoupon.setStartdate(startTime); + } + if (StringUtils.isEmpty(paramsMap.get("enddate"))) { + wxCoupon.setEnddate(new Date()); + }else{ + Date endTime = DateUtils.stringToDate(enddate, "yyyy-MM-dd HH:mm:ss"); + wxCoupon.setEnddate(endTime); + } + + Map result = new HashedMap(); + List saleMoneyList = wxCouponService.findSaleMoneyByDate(wxCoupon); + List paymentList = wxCouponService.findPaymentByDate(wxCoupon); + Map saleMap = getDateMap(wxCoupon.getStartdate(),wxCoupon.getEnddate()); + Map payMentMap = getDateMap(wxCoupon.getStartdate(),wxCoupon.getEnddate()); + + for (WxCouponStatisVo coupon:saleMoneyList){ + saleMap.put(coupon.getXtime(),coupon.getXcount()); + } + for (WxCouponStatisVo coupon:paymentList){ + payMentMap.put(coupon.getXtime(),coupon.getXcount()); + } + result.put("saleHistory",saleMap); + result.put("paymentHistory",payMentMap); + result.put("saleCardCount",wxCouponService.findSaleCardCount(wxCoupon)); + result.put("tranCount",wxCouponService.findTranCardCount(wxCoupon)); + result.put("subsidyCount",wxCouponService.findSubsidyMoney(wxCoupon)); + return new ResultData(result); + } + + /** + * 券营销数据 + * @param paramsMap + * @param startdate + * @param enddate + * @return + */ + private ResultData getSaleCouponAnalysis(Map paramsMap, String startdate, String enddate) { + WxCoupon wxCoupon = new WxCoupon(); + Map result = new HashedMap(); + + //默认时间本月第一天,截止到当天 + if (StringUtils.isEmpty(paramsMap.get("startdate"))) { + wxCoupon.setStartdate(getMonthFirstDay()); + }else{ + Date startTime = DateUtils.stringToDate(startdate); + wxCoupon.setStartdate(startTime); + } + if (StringUtils.isEmpty(paramsMap.get("enddate"))) { + wxCoupon.setEnddate(new Date()); + }else{ + Date endTime = DateUtils.stringToDate(enddate, "yyyy-MM-dd HH:mm:ss"); + wxCoupon.setEnddate(endTime); + } + List orderCountList = wxCouponService.findCouponOrderCount(wxCoupon); + List paymentCountList = wxCouponService.findCouponPaymentCount(wxCoupon); + List priceCouponSaleCountList = wxCouponService.priceCouponSaleCount(wxCoupon); + List priceCouponPaymentCountList = wxCouponService.priceCouponPaymentCount(wxCoupon); + + Map orderCountMap = getDateMap(wxCoupon.getStartdate(),wxCoupon.getEnddate()); + Map paymentCountMap = getDateMap(wxCoupon.getStartdate(),wxCoupon.getEnddate()); + Map priceCouponSaleCountMap = getDateMap(wxCoupon.getStartdate(),wxCoupon.getEnddate()); + Map priceCouponPaymentCountMap = getDateMap(wxCoupon.getStartdate(),wxCoupon.getEnddate()); + + for (WxCouponStatisVo coupon:orderCountList){ + orderCountMap.put(coupon.getXtime(),coupon.getXcount()); + } + for (WxCouponStatisVo coupon:paymentCountList){ + paymentCountMap.put(coupon.getXtime(),coupon.getXcount()); + } + for (WxCouponStatisVo coupon:priceCouponSaleCountList){ + priceCouponSaleCountMap.put(coupon.getXtime(),coupon.getXcount()); + } + for (WxCouponStatisVo coupon:priceCouponPaymentCountList){ + priceCouponPaymentCountMap.put(coupon.getXtime(),coupon.getXcount()); + } + result.put("orderCountList",orderCountMap); + result.put("paymentCountList",paymentCountMap); + result.put("priceCouponSaleCountList",priceCouponSaleCountMap); + result.put("priceCouponPaymentCountList",priceCouponPaymentCountMap); + + result.put("sumPriceSaleMoney",wxCouponService.findSumPriceSaleMoney(wxCoupon)); + result.put("sumPricePayMent",wxCouponService.findSumPricePayMent(wxCoupon)); + result.put("sumSubsidyMoney",wxCouponService.findSumSubsidyMoney(wxCoupon)); + return new ResultData(result); + } + + /** + * 砍价营销数据 + * @param paramsMap + * @param tenantId + * @param startdate + * @param enddate + * @return + */ + private ResultData getSalePressAnalysis(Map paramsMap, String tenantId, String startdate, String enddate) { + WxCoupon wxCoupon = new WxCoupon(); + Map result = new HashedMap(); + + //默认时间本月第一天,截止到当天 + if (StringUtils.isEmpty(paramsMap.get("startdate"))) { + wxCoupon.setStartdate(getMonthFirstDay()); + }else{ + Date startTime = DateUtils.stringToDate(startdate); + wxCoupon.setStartdate(startTime); + } + if (StringUtils.isEmpty(paramsMap.get("enddate"))) { + wxCoupon.setEnddate(new Date()); + }else{ + Date endTime = DateUtils.stringToDate(enddate, "yyyy-MM-dd HH:mm:ss"); + wxCoupon.setEnddate(endTime); + } + List pressSendHistory = wxCouponService.pressSendHistory(wxCoupon); + List pressSuccHistory = wxCouponService.pressSuccHistory(wxCoupon); + List pressPaymentHistory = wxCouponService.pressPaymentHistory(wxCoupon); + + Map pressSendHistoryMap = getDateMap(wxCoupon.getStartdate(),wxCoupon.getEnddate()); + Map pressSuccHistoryMap = getDateMap(wxCoupon.getStartdate(),wxCoupon.getEnddate()); + Map pressPaymentHistoryMap = getDateMap(wxCoupon.getStartdate(),wxCoupon.getEnddate()); + + for (WxCouponStatisVo coupon:pressSendHistory){ + pressSendHistoryMap.put(coupon.getXtime(),coupon.getXcount()); + } + for (WxCouponStatisVo coupon:pressSuccHistory){ + pressSuccHistoryMap.put(coupon.getXtime(),coupon.getXcount()); + } + for (WxCouponStatisVo coupon:pressPaymentHistory){ + pressPaymentHistoryMap.put(coupon.getXtime(),coupon.getXcount()); + } + result.put("pressSendHistory",pressSendHistoryMap); + result.put("pressSuccHistory",pressSuccHistoryMap); + result.put("pressPaymentHistory",pressPaymentHistoryMap); + + wxCoupon.setTenantId(tenantId); + result.put("pressSuccRate",wxCouponService.pressSuccRate(wxCoupon)); + result.put("sumJoin",wxCouponService.sumJoin(wxCoupon)); + return new ResultData(result); + } + + private Date getMonthFirstDay() { + Calendar c = Calendar.getInstance(); + c.add(Calendar.MONTH, 0); + c.set(Calendar.DAY_OF_MONTH,1); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + return c.getTime(); + } + + /** + * 拼团营销数据 + * @param paramsMap + * @param tenantId + * @param startdate + * @return + */ + private ResultData getSaleGroupAnalysis(Map paramsMap, String tenantId, String startdate) { + Map params = new HashMap<>(); + params.put("tenantId", tenantId); + //默认时间本月第一天,截止到当天 + Map result = new HashMap<>(); + Date startTime = new Date(); + Date endTime = startTime; + if (StringUtils.isEmpty(paramsMap.get("startdate"))) { + startTime = getMonthFirstDay(); + params.put("startdate", startTime); + } else { + startTime = DateUtils.stringToDate(startdate + " 00:00:00"); + params.put("startdate", startTime); + } + if (StringUtils.isEmpty(paramsMap.get("enddate"))) { + params.put("enddate", endTime); + } else { + endTime = DateUtils.stringToDate(paramsMap.get("enddate") + " 23:59:59", "yyyy-MM-dd HH:mm:ss"); + params.put("enddate", paramsMap.get("enddate") + " 23:59:59"); + } + List> successlist = wxOrderGroupMapper.queryOrderGroupSuccessCountAndTime(params); + List> verifyList = wxOrderGroupMapper.queryOrderGroupVerifyCountAndTime(params); + + Map successMap = getDateMap(startTime, endTime); + Map verifyMap = getDateMap(startTime, endTime); + + long successCount = wxOrderGroupMapper.queryOrderGroupSuccessCount(params); + long groupCount = wxOrderGroupMapper.queryOrderGroupCount(params); + long peopleCount = wxOrderGroupMapper.queryOrderGroupPeopleCount(params); + double transferRatio = 0; + if (groupCount > 0) { + double transfer = (double) successCount / groupCount * 100; + transferRatio = new BigDecimal(transfer).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + } + + Map successListMap = successlist.parallelStream().collect(Collectors.toMap(x -> { + return x.get("time").toString(); + }, x -> { + return x.get("total").toString(); + })); + + Map verifyListMap = verifyList.parallelStream().collect(Collectors.toMap(x -> { + return x.get("time").toString(); + }, x -> { + return x.get("total").toString(); + })); + + successMap.putAll(successListMap); + verifyMap.putAll(verifyListMap); + + result.put("successList", successMap); + result.put("verifyList", verifyMap); + + result.put("successCount", successCount); + result.put("groupCount", groupCount); + result.put("peopleCount", peopleCount); + result.put("transferRatio", transferRatio); + + return new ResultData(result); + } + + /** + * 昨日解单率 + * @param tenantId + * @return + */ + private ResultData getYesterdayTradeRate(String tenantId) { + HashMap datamap = new HashMap<>(); + WxMerchant wxMerchant = new WxMerchant(); + wxMerchant.setTenantId(tenantId); + wxMerchant.setStatus(1); + List merchants = wxMerchantMapper.findList(wxMerchant); + WxMerchantTradeDaily wxMerchantTradeDaily = new WxMerchantTradeDaily(); + wxMerchantTradeDaily.setTenantId(tenantId); + String reportdate = DateUtils.getTimeBefore(1, new Date()); + wxMerchantTradeDaily.setReportDate(reportdate); + List tradelist = wxMerchantTradeDailyMapper.findList(wxMerchantTradeDaily); + int merchantsize = merchants.size(); + int tradesize = tradelist.size(); + if (merchantsize > 0 && tradesize > 0) { + double shsbld = ((double) tradesize / merchantsize) * 100; + double shsbl = new BigDecimal(shsbld).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + datamap.put("shsbl", shsbl); + } else { + datamap.put("shsbl", 0); + } + int shsbjg = tradelist.stream().mapToInt(WxMerchantTradeDaily::getTradeAmt).sum(); + datamap.put("shsbjg", shsbjg); + return new ResultData(datamap); + } + + /** + * 出租率 + * @param tenantId + */ + private ResultData getRentRate(String tenantId) { + HashMap datamap = new HashMap<>(); + WxShop wxShop = new WxShop(); + wxShop.setTenantId(tenantId); + wxShop.setStatus(EnumShopStatus.RENT.getCode()); + List yczlist = wxShopMapper.findList(wxShop); + wxShop.setStatus(EnumShopStatus.NOT_RENT.getCode()); + List wczlist = wxShopMapper.findList(wxShop); + //出租与未出租 + int yczsize = yczlist.size(); + int wczsize = wczlist.size(); + int size = yczsize + wczsize; + if (size == 0) { + datamap.put("yczsl", 0); + datamap.put("wczsl", 0); + datamap.put("yczl", 0); + datamap.put("wczl", 0); + } else { + datamap.put("yczsl", yczsize); + datamap.put("wczsl", wczsize); + double yczld = ((double) yczsize / size) * 100; + double dczl = new BigDecimal(yczld).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + double wczld = ((double) wczsize / size) * 100; + double wczl = new BigDecimal(wczld).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + datamap.put("yczl", dczl); + datamap.put("wczl", wczl); + } + return new ResultData(datamap); + } + + /** + * 租金收缴率 + * @param tenantId + * @param startdate + * @param enddate + * @return + */ + private ResultData getRentMoneyRate(String tenantId, String startdate, String enddate) { + HashMap datamap = new HashMap<>(); + //租金 + Map params = new HashMap<>(); + params.put("tenantId", tenantId); + params.put("startdate", startdate + " 00:00:00"); + params.put("enddate", enddate + " 23:59:59"); + Map payinfo = wxBillRentMapper.queryPayInfo(params); + if (payinfo != null) { + BigDecimal receivepay = (BigDecimal) payinfo.get("receivepay"); + BigDecimal pay = (BigDecimal) payinfo.get("pay"); + if (receivepay.doubleValue() > 0) { + BigDecimal divide = pay.divide(receivepay, 2, BigDecimal.ROUND_HALF_UP); + double zjcjl = divide.multiply(new BigDecimal(100)).doubleValue(); + datamap.put("ysje", receivepay); + datamap.put("ssje", pay); + datamap.put("zjsjl", zjcjl); + } else { + datamap.put("ysje", 0); + datamap.put("ssje", 0); + datamap.put("zjsjl", 0); + } + } else { + datamap.put("ysje", 0); + datamap.put("ssje", 0); + datamap.put("zjsjl", 0); + } return new ResultData(datamap); } @@ -1712,29 +2125,6 @@ public class WxChartServiceImpl implements WxChartDataService { return result; } - public TreeMap getTimeTreeMap() { - TreeMap timemap = new TreeMap(); - timemap.put("06:00", 0); - timemap.put("07:00", 0); - timemap.put("08:00", 0); - timemap.put("09:00", 0); - timemap.put("10:00", 0); - timemap.put("11:00", 0); - timemap.put("12:00", 0); - timemap.put("13:00", 0); - timemap.put("14:00", 0); - timemap.put("15:00", 0); - timemap.put("16:00", 0); - timemap.put("17:00", 0); - timemap.put("18:00", 0); - timemap.put("19:00", 0); - timemap.put("20:00", 0); - timemap.put("21:00", 0); - timemap.put("22:00", 0); - timemap.put("23:00", 0); - return timemap; - } - private long getCountByAge(EnumAgeInfo a, Calendar c, WxCUserBasicInfoDto dto) { if (a.getStart() != 0 || a.getEnd() != 0) { c.add(Calendar.YEAR, -a.getEnd()); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java index e2e2aef59..60397caea 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java @@ -3,20 +3,29 @@ package com.iformall.service.impl; import java.util.*; import java.util.stream.Collectors; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.google.common.collect.Lists; -import com.iformall.domain.dto.WxCreditHistoryDto; +import com.iformall.common.ErrorCode; +import com.iformall.common.Result; +import com.iformall.common.ResultData; import com.iformall.domain.po.*; import com.iformall.domain.vo.WxCreditHistoryVo; +import com.iformall.enums.EnumBusiness; +import com.iformall.enums.EnumScoreType; import com.iformall.enums.EnumUserType; import com.iformall.mapper.*; import com.iformall.service.WxCreditHistoryService; +import com.iformall.service.WxScoreRulesService; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.iformall.common.IdWorker; @Service +@Slf4j public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { @Autowired @@ -34,6 +43,9 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { @Autowired MallUserInfoMapper mallUserInfoMapper; + @Autowired + WxScoreRulesService wxScoreRulesService; + @Override public PageInfo listAsPage(WxCreditHistory record, Integer pageIndex, Integer pageSize) { return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCreditHistoryMapper.findList(record)); @@ -113,27 +125,202 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { } @Override - public void saveOrUpdate(WxCreditHistory record) { + public ResultData saveOrUpdate(WxCreditHistory record) { + WxCUser wxCUser = wxCUserMapper.selectByPrimaryKey(record.getCUserId()); + WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoMapper.selectByPrimaryKey(record.getCUserId()); + if (wxCUser == null && wxCUserBasicInfo == null) { + //验证此用户是否存在 + return new ResultData(ErrorCode.USER_IS_EMPTY); + } + //获取当前用户总积分 + int currentCreditAmount = wxCreditHistoryMapper.creditAmount(record.getCUserId()); + + //计算出需要新增或减少的积分 + int creditChangeNum = creditIncrement(record); + + if (creditChangeNum == 0) { + return new ResultData(ErrorCode.CREDIT_ZERO); + } + if (currentCreditAmount + creditChangeNum < 0) { + return new ResultData(ErrorCode.CREDIT_NOT_ENOUGH); + } + record.setCreditNum(creditChangeNum); + record.setCreditAmount(currentCreditAmount + creditChangeNum); if (record.getId() == null) { - //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); final IdWorker idWorker = IdWorker.get(); record.setId(idWorker.nextId()); wxCreditHistoryMapper.insertSelective(record); + //将计算出来新的总积分 更新到两张用户表里 + updateCredit(wxCUser,wxCUserBasicInfo,record.getCreditAmount()); } else { - wxCreditHistoryMapper.updateByPrimaryKeySelective(record); + //wxCreditHistoryMapper.updateByPrimaryKeySelective(record); } + return new ResultData(Result.SUCCESS, "积分操作成功"); + } @Override public void deleteById(Long id) { wxCreditHistoryMapper.deleteByPrimaryKey(id); } - - - - - - - - + + //根据积分类型计算"增加积分" + private int creditIncrement(WxCreditHistory record) { + if (record.getCreditType() == EnumScoreType.LOGIN.getCode()) { + return loginAddCredit(record); + } + if (record.getCreditType() == EnumScoreType.BIND_CAR.getCode()) { + return bindCarAddCredit(record); + } + if (record.getCreditType() == EnumScoreType.WIFI_CONNECTION.getCode()) { + return wifiAddCredit(); + } + if (record.getCreditType() == EnumScoreType.WECHAT_PERSION.getCode()) { + return personAddCredit(record); + } + if (record.getCreditType() == EnumScoreType.WECHAT_PHONE.getCode()) { + return phoneAddCredit(record); + } + if (record.getCreditType() == EnumScoreType.COMPLETE_INFO.getCode()) { + return infoAddCredit(record); + } + if (record.getCreditType() == EnumScoreType.SPEND_CREDIT.getCode()) { + return spendCredit(record); + } + if (record.getCreditType() == EnumScoreType.CHANGE_CREDIT.getCode()) { + //TODO 待实现 + return changeCredit(record); + } + if (record.getCreditType() == EnumScoreType.CONSUMPTION.getCode()) { + return payAddCredit(record); + } + + + return 0; + } + + private int loginAddCredit(WxCreditHistory record) { + //如果当天已经登录过则跳过 + if (wxCreditHistoryMapper.loginCount(record) > 0) { + return 0; + } + // 1. 获取当前租户下积分的增加规则 + WxScoreRules wxScoreRules = wxScoreRulesService.getCreditRules(record.getTenantId()); + // 2. 增长的积分 + return wxScoreRules.getRule(EnumScoreType.LOGIN,WxScoreRules.SCORE); + } + + private int bindCarAddCredit(WxCreditHistory record) { + // 1. 获取score rules + WxScoreRules wxScoreRules = wxScoreRulesService.getCreditRules(record.getTenantId()); + // 2. 增长的积分 + return wxScoreRules.getRule(EnumScoreType.BIND_CAR,WxScoreRules.SCORE); + } + + private int wifiAddCredit() { + int addCreditNumber = 0; + return addCreditNumber; + } + + private int personAddCredit(WxCreditHistory record) { + // 1. 获取score rules + WxScoreRules wxScoreRules = wxScoreRulesService.getCreditRules(record.getTenantId()); + // 2. 增长的积分 + return wxScoreRules.getRule(EnumScoreType.WECHAT_PERSION,WxScoreRules.SCORE); + } + + private int phoneAddCredit(WxCreditHistory record) { + // 1. 获取score rules + WxScoreRules wxScoreRules = wxScoreRulesService.getCreditRules(record.getTenantId()); + // 2. 获取成长值 + return wxScoreRules.getRule(EnumScoreType.WECHAT_PERSION,WxScoreRules.SCORE); + } + + private int checkCompleteInfoScoreCount(WxCUser cUser) { + WxCreditHistory wxCreditHistory = new WxCreditHistory(); + wxCreditHistory.setTenantId(cUser.getTenantId()); + wxCreditHistory.setCUserId(cUser.getId()); + wxCreditHistory.setCreditType(EnumScoreType.COMPLETE_INFO.getCode()); + return wxCreditHistoryMapper.countList(wxCreditHistory); + } + + private int infoAddCredit(WxCreditHistory record) { + WxCUser user = wxCUserMapper.selectByPrimaryKey(record.getCUserId()); + if (user == null || checkCompleteInfoScoreCount(user) > 0) + return 0; + // 1. 获取score rules + WxScoreRules scoreRules = wxScoreRulesService.getCreditRules(user.getTenantId()); + // 2. 获取成长值 + return scoreRules.getRule(EnumScoreType.COMPLETE_INFO,WxScoreRules.SCORE); + } + + private int spendCredit(WxCreditHistory record){ + int spendCredit = record.getCreditNum(); + return -spendCredit; + } + + private int changeCredit(WxCreditHistory record){ + //TODO 积分兑换扣减规则 + return 0; + } + + private int payAddCredit(WxCreditHistory record) { + int addCreditNumber = 0; + // 订单金额为0时不计入 + if (record.getCreditNum() == 0) + return 0; + // 1. 获取score rules + WxScoreRules scoreRules = wxScoreRulesService.getCreditRules(record.getTenantId()); + + // 2. 获取成长值 by id + JSONObject payRule = scoreRules.getRuleObj(EnumScoreType.CONSUMPTION); + // 3. 获取成长值 by 业态 + JSONObject busRule = null; + JSONObject busRuleOther = null; + JSONArray busRules = payRule.getJSONArray("childs"); + if (busRules != null) { + for (int i = 0; i < busRules.size(); i++) { + JSONObject bus = (JSONObject) busRules.get(i); + Integer businessId1 = bus.getInteger("businessId"); + if (record.getBusinessId().equals(businessId1)) { + busRule = bus; + } + if (businessId1.equals(EnumBusiness.BUSINESS_ID6.getCode())) { + busRuleOther = bus; + } + } + if (busRule == null) { + busRule = busRuleOther; + } + } + if (busRule == null) { + busRule = payRule; + } + Double priceCondition = busRule.getDouble(WxScoreRules.STEP) * 100; // 元->分 + int baseScore = busRule.getInteger(WxScoreRules.SCORE); // 消费增长积分 + + // 4. 计算积分 + Double dScoreT = Math.floor(record.getSpend() * 1.0D / priceCondition * baseScore); + addCreditNumber = dScoreT.intValue(); + log.info("CREDIT:" + busRule.toJSONString() + "\nAddCredit: " + addCreditNumber); + + return addCreditNumber; + } + + /** + * 更新两个表中的最新总积分 + * @param creditAmount 用户最新总积分 + */ + private void updateCredit(WxCUser wxCUser, WxCUserBasicInfo wxCUserBasicInfo, int creditAmount) { + if (wxCUser != null) { + wxCUser.setCredit(creditAmount); + wxCUserMapper.updateByPrimaryKeySelective(wxCUser); + } + if (wxCUserBasicInfo != null) { + wxCUserBasicInfo.setCredit(creditAmount); + wxCUserBasicInfoMapper.updateByPrimaryKeySelective(wxCUserBasicInfo); + } + } + + } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantSubsidyServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantSubsidyServiceImpl.java index 094e774f0..6e1713dd8 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantSubsidyServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantSubsidyServiceImpl.java @@ -167,7 +167,7 @@ public class WxMerchantSubsidyServiceImpl implements WxMerchantSubsidyService { e.printStackTrace(); } } - */ + public void downFile(String filePath, String filename, String exportFileName, HttpServletResponse response, HttpServletRequest req) throws IOException { @@ -198,6 +198,6 @@ public class WxMerchantSubsidyServiceImpl implements WxMerchantSubsidyService { e.printStackTrace(); } } - + */ } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java index fbae7c59b..24fc9cb28 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java @@ -205,19 +205,40 @@ public class WxRentContractServiceImpl implements WxRentContractService { Date date = new Date(); record.setCreatetime(date); record.setUpdatetime(date); - try { + + if (record.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { + String rentInfo = record.getRentInfo(); + JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); + int size = rentInfoArray.size(); + if (size == 0) { + return new ResultData(ErrorCode.SHOP_NOT_SELECTED); + } + //查询rent_info 包括 shopId + for (int i = 0; i < size; i++) { + JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); + WxRentContract wxRentContract = new WxRentContract(); + wxRentContract.setTenantId(record.getTenantId()); + wxRentContract.setShopId(rentInfoObject.getLong("shopId")); + int count = wxRentContractMapper.selectRentContractCountByShopId(wxRentContract); + if (count > 0) { + String shopNumber = rentInfoObject.getString("shopNumber"); + return new ResultData(ErrorCode.SHOP_IS_RENT.getCode(), "店铺 " + shopNumber + " 已出租"); + } + } + } else { WxRentContract wxRentContract = new WxRentContract(); wxRentContract.setTenantId(record.getTenantId()); wxRentContract.setShopId(record.getShopId()); long count = wxRentContractMapper.queryRentContractData(wxRentContract).stream(). - filter(rc -> !rc.get("status").equals(EnumRentContractStatus.CONTRACT_TERMINATE.getCode()) - && !rc.get("status").equals(EnumRentContractStatus.WAIT_SIGN.getCode()) - && !rc.get("status").equals(EnumRentContractStatus.INVALID.getCode()) - && !rc.get("status").equals(EnumRentContractStatus.CONTRACT_END.getCode()) - && !rc.get("status").equals(EnumRentContractStatus.INTENTION.getCode())).count(); + filter(rc -> rc.get("status").equals(EnumRentContractStatus.SIGNED_RENT_UNPAID.getCode()) + || rc.get("status").equals(EnumRentContractStatus.RENT_PAID.getCode()) + || rc.get("status").equals(EnumRentContractStatus.CONTRACT_END_SOON.getCode())).count(); if (count > 0) { return new ResultData(ErrorCode.RENT_CONTRACT_WITH_SHOP_IS_FOUND); } + } + + try { record.setApplyStatus(EnumRentContractAppStatus.DEFAULT.getCode()); wxRentContractMapper.insertSelective(record); } catch (Exception e) { @@ -264,51 +285,58 @@ public class WxRentContractServiceImpl implements WxRentContractService { wxBillRent.setIsPreview(EnumIsPreview.YES.getCode()); List resultList = wxBillRentMapper.findList(wxBillRent); - boolean change = false; - if(CollectionUtils.isEmpty(resultList)){ - change = true; - }else if(record.getAdjustPeriod().intValue() != dbRent.getAdjustPeriod().intValue()){ - change = true; + ResultData resultData = null; + if (dbRent.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { + // 更新 + resultData = getResultDataForUpdate(record, userId); + //删除预账单,重新生成 + wxBillRentMapper.deletePreviewBill(record); + resultList = buildRent(new WxMerchant(), null, record, EnumIsPreview.YES.getCode()); }else{ - if(record.getReceivePeriod() != null && record.getLease()!=null && record.getPrice()!= null) { - if (record.getType().equals(EnumRentContractType.RENT_BY_AREA.getCode())) { - if (!record.getReceivePeriod().equals(dbRent.getReceivePeriod()) - || !record.getLease().equals(dbRent.getLease()) - || !record.getType().equals(dbRent.getType()) - || !record.getPrice().equals(dbRent.getPrice()) - || !record.getAdjustRatio().replaceAll("\\s*","").equals(dbRent.getAdjustRatio().replaceAll("\\s*","")) - ) { - change = true; - } - } else if (record.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode())) { - if (!record.getReceivePeriod().equals(dbRent.getReceivePeriod()) - || !record.getLease().equals(dbRent.getLease()) - || !record.getType().equals(dbRent.getType()) - || !record.getRevenue().equals(dbRent.getRevenue()) - || !record.getPayRatio().equals(dbRent.getPayRatio()) - ) { - change = true; - } - } else if (record.getType().equals(EnumRentContractType.RENT_BY_AREA_AND_JOINT.getCode())) { - if (!record.getReceivePeriod().equals(dbRent.getReceivePeriod()) - || !record.getLease().equals(dbRent.getLease()) - || !record.getType().equals(dbRent.getType()) - || !record.getPrice().equals(dbRent.getPrice()) - || !record.getPayRatio().equals(dbRent.getPayRatio()) - ) { - change = true; + boolean change = false; + if (CollectionUtils.isEmpty(resultList)) { + change = true; + } else if (record.getAdjustPeriod().intValue() != dbRent.getAdjustPeriod().intValue()) { + change = true; + } else { + if (record.getReceivePeriod() != null && record.getLease() != null && record.getPrice() != null) { + if (record.getType().equals(EnumRentContractType.RENT_BY_AREA.getCode())) { + if (!record.getReceivePeriod().equals(dbRent.getReceivePeriod()) + || !record.getLease().equals(dbRent.getLease()) + || !record.getType().equals(dbRent.getType()) + || !record.getPrice().equals(dbRent.getPrice()) + || !record.getAdjustRatio().replaceAll("\\s*", "").equals(dbRent.getAdjustRatio().replaceAll("\\s*", "")) + ) { + change = true; + } + } else if (record.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode())) { + if (!record.getReceivePeriod().equals(dbRent.getReceivePeriod()) + || !record.getLease().equals(dbRent.getLease()) + || !record.getType().equals(dbRent.getType()) + || !record.getRevenue().equals(dbRent.getRevenue()) + || !record.getPayRatio().equals(dbRent.getPayRatio()) + ) { + change = true; + } + } else if (record.getType().equals(EnumRentContractType.RENT_BY_AREA_AND_JOINT.getCode())) { + if (!record.getReceivePeriod().equals(dbRent.getReceivePeriod()) + || !record.getLease().equals(dbRent.getLease()) + || !record.getType().equals(dbRent.getType()) + || !record.getPrice().equals(dbRent.getPrice()) + || !record.getPayRatio().equals(dbRent.getPayRatio()) + ) { + change = true; + } } } } - } - - // 更新 - ResultData resultData = getResultDataForUpdate(record, userId); - - //有改变,删除预账单,重新生成 - if(change) { - wxBillRentMapper.deletePreviewBill(record); - resultList = buildRent(new WxMerchant(), null, record, EnumIsPreview.YES.getCode()); + // 更新 + resultData = getResultDataForUpdate(record, userId); + //有改变,删除预账单,重新生成 + if (change) { + wxBillRentMapper.deletePreviewBill(record); + resultList = buildRent(new WxMerchant(), null, record, EnumIsPreview.YES.getCode()); + } } //启动审批流 @@ -373,20 +401,40 @@ public class WxRentContractServiceImpl implements WxRentContractService { record.setDeposit(record.getDeposit() == null ? 0 : record.getDeposit()); record.setUpdatetime(new Date()); - try { - WxRentContract wxRentContractParams = new WxRentContract(); - wxRentContractParams.setTenantId(record.getTenantId()); - wxRentContractParams.setShopId(record.getShopId()); - long count = wxRentContractMapper.queryRentContractData(wxRentContractParams).stream(). - filter(rc -> !rc.get("status").equals(EnumRentContractStatus.CONTRACT_TERMINATE.getCode()) - && !rc.get("status").equals(EnumRentContractStatus.WAIT_SIGN.getCode()) - && !rc.get("status").equals(EnumRentContractStatus.INVALID.getCode()) - && !rc.get("status").equals(EnumRentContractStatus.CONTRACT_END.getCode()) - && !rc.get("status").equals(EnumRentContractStatus.INTENTION.getCode()) - && !rc.get("id").equals(wxRentContract.getId())).count(); + + if (record.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { + String rentInfo = record.getRentInfo(); + JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); + int size = rentInfoArray.size(); + if (size == 0) { + return new ResultData(ErrorCode.SHOP_NOT_SELECTED); + } + //查询rent_info 包括 shopId + for (int i = 0; i < size; i++) { + JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); + WxRentContract wxRentContractQuery = new WxRentContract(); + wxRentContractQuery.setTenantId(record.getTenantId()); + wxRentContractQuery.setShopId(rentInfoObject.getLong("shopId")); + int count = wxRentContractMapper.selectRentContractCountByShopId(wxRentContractQuery); + if (count > 0) { + String shopNumber = rentInfoObject.getString("shopNumber"); + return new ResultData(ErrorCode.SHOP_IS_RENT.getCode(), "店铺 " + shopNumber + " 已出租"); + } + } + } else { + WxRentContract wxRentContractQuery = new WxRentContract(); + wxRentContractQuery.setTenantId(record.getTenantId()); + wxRentContractQuery.setShopId(record.getShopId()); + long count = wxRentContractMapper.queryRentContractData(wxRentContract).stream(). + filter(rc -> rc.get("status").equals(EnumRentContractStatus.SIGNED_RENT_UNPAID.getCode()) + || rc.get("status").equals(EnumRentContractStatus.RENT_PAID.getCode()) + || rc.get("status").equals(EnumRentContractStatus.CONTRACT_END_SOON.getCode())).count(); if (count > 0) { return new ResultData(ErrorCode.RENT_CONTRACT_WITH_SHOP_IS_FOUND); } + } + + try { wxRentContractMapper.updateByPrimaryKeySelective(record); } catch (Exception e) { logger.error("更新租赁合同信息失败,e:" + e.getMessage()); @@ -442,15 +490,17 @@ public class WxRentContractServiceImpl implements WxRentContractService { wxBillDeposit.setUpdatetime(date); wxBillDeposit.setIsDel(EnumDelStatus.NOT_DEL.getCode()); wxBillDeposit.setRentShopType(wxRentContract.getRentShopType()); - String rentInfo = wxRentContract.getRentInfo(); - if (rentInfo != null) { - JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); - Map shopInfo = new HashMap<>(); - for (int i = 0, size = rentInfoArray.size(); i < size; i++) { - JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); - shopInfo.put(rentInfoObject.getString("shopNumber"), rentInfoObject.get("deposit")); + if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { + String rentInfo = wxRentContract.getRentInfo(); + if (rentInfo != null) { + JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); + Map shopInfo = new HashMap<>(); + for (int i = 0, size = rentInfoArray.size(); i < size; i++) { + JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); + shopInfo.put(rentInfoObject.getString("shopNumber"), rentInfoObject.get("deposit")); + } + wxBillDeposit.setShopInfo(JSONObject.toJSONString(shopInfo)); } - wxBillDeposit.setShopInfo(JSONObject.toJSONString(shopInfo)); } try { wxBillDepositMapper.insertSelective(wxBillDeposit); @@ -513,7 +563,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { int[] priceArr = new int[arraySize]; for (int i = 0; i < arraySize; i++) { JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); - priceArr[i] = rentInfoObject.getIntValue("price"); + priceArr[i] = new BigDecimal(rentInfoObject.getIntValue("price")).multiply(new BigDecimal(100)).intValue(); } priceList.add(priceArr); //大于一年 @@ -526,8 +576,9 @@ public class WxRentContractServiceImpl implements WxRentContractService { for (int j = 0; j < arraySize; j++) { rentInfoObject = rentInfoArray.getJSONObject(j); adjustRatio = rentInfoObject.getJSONArray("adjustRatio"); - double price = priceList.get(i)[j] + priceList.get(i)[j] * adjustRatio.getIntValue(i) / 10000.0; - priceArrs[j] = new BigDecimal(price).setScale(0, RoundingMode.HALF_EVEN).intValue(); + BigDecimal multiply = new BigDecimal(priceList.get(i)[j]).multiply(new BigDecimal(adjustRatio.getIntValue(i)).divide(new BigDecimal(100))); + BigDecimal price = new BigDecimal(priceList.get(i)[j]).add(multiply); + priceArrs[j] = price.setScale(0, RoundingMode.HALF_EVEN).intValue(); } priceList.add(priceArrs); } @@ -535,32 +586,50 @@ public class WxRentContractServiceImpl implements WxRentContractService { } public List buildRentMonth(WxMerchant wxMerchant, Long userId, WxRentContract wxRentContract, int receivePeriod, Integer lease, Date rentalStartDate, Integer price,Integer isPreview) { - String rentInfo = wxRentContract.getRentInfo(); - JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); - List priceList = computePrice(rentInfo); - int size = priceList.size(); - int[] priceArrs = new int[size]; - for (int i = 0; i < size; i++) { - int[] priceInt = priceList.get(i); - int sum = 0; - for (int p : priceInt) { - sum += p; + int size = 0; + int[] priceArrs = null; + List> shopInfos = new ArrayList<>(); + if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { + String rentInfo = wxRentContract.getRentInfo(); + JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); + + List priceList = computePrice(rentInfo); + size = priceList.size(); + priceArrs = new int[size]; + for (int i = 0; i < size; i++) { + int[] priceInt = priceList.get(i); + int sum = 0; + for (int p : priceInt) { + sum += p; + } + priceArrs[i] = sum; } - priceArrs[i] = sum; - } - List> shopInfos = new ArrayList<>(); - for (int i = 0; i < size; i++) { - Map shopInfo = new HashMap<>(); - int[] ints = priceList.get(i); - for (int j = 0; j < ints.length; j++) { - JSONObject rentInfoObject = rentInfoArray.getJSONObject(j); - shopInfo.put(rentInfoObject.getString("shopNumber"), ints[j]); + for (int i = 0; i < size; i++) { + Map shopInfo = new HashMap<>(); + int[] ints = priceList.get(i); + for (int j = 0; j < ints.length; j++) { + JSONObject rentInfoObject = rentInfoArray.getJSONObject(j); + shopInfo.put(rentInfoObject.getString("shopNumber"), ints[j]); + } + shopInfos.add(shopInfo); + } + } else { + String adjustRatio = wxRentContract.getAdjustRatio(); + List integers = JSONArray.parseArray(adjustRatio, Integer.class); + integers.add(0, 0); + size = integers.size(); + priceArrs = new int[size]; + priceArrs[0] = price; + double priceD = price; + for (int i = 1; i < size; i++) { + priceD = priceD + priceD * integers.get(i) / 10000.0; + priceArrs[i] = new BigDecimal(priceD).setScale(0, RoundingMode.HALF_EVEN).intValue(); } - shopInfos.add(shopInfo); } + int month = 12; int divide = lease / month; int mod = lease % month; @@ -579,7 +648,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { instance.setTime(rentalStartDate); //开始时间 instance.add(Calendar.MONTH, month * i); - Map resultMap = buildRent(leaseArr[i], receivePeriod, priceArrs[i], instance.getTime(), Calendar.MONTH, wxRentContract, userId, wxMerchant, billcount, isPreview, shopInfos.get(i)); + Map resultMap = buildRent(leaseArr[i], receivePeriod, priceArrs[i], instance.getTime(), Calendar.MONTH, wxRentContract, userId, wxMerchant, billcount, isPreview, shopInfos.isEmpty() ? null : shopInfos.get(i)); List billRentList = (List)resultMap.get("billList"); billcount = (Integer)resultMap.get("billcount"); resultList.addAll(billRentList); @@ -1538,67 +1607,4 @@ public class WxRentContractServiceImpl implements WxRentContractService { wxRentContractMapper.updateApplyStatus(wxRentContract); } - - public static void main(String[] args) { - JSONArray rentInfoArray = JSONArray.parseArray("[{shopId:0,shopNumber:0,price:1000,adjustRatio:[1100,1100]},{shopId:1,shopNumber:1,price:2000,adjustRatio:[1200,1200]},{shopId:2,shopNumber:2,price:3000,adjustRatio:[1300,1300]}]"); - int arraySize = rentInfoArray.size(); - List priceList = new ArrayList<>(); - //第一年 - int[] priceArr = new int[arraySize]; - for (int i = 0; i < arraySize; i++) { - JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); - priceArr[i] = rentInfoObject.getIntValue("price"); - } - priceList.add(priceArr); - //大于一年 - JSONObject rentInfoObject = rentInfoArray.getJSONObject(0); - JSONArray adjustRatio = rentInfoObject.getJSONArray("adjustRatio"); - int adjustRatioSize = adjustRatio.size(); - - for (int i = 0; i < adjustRatioSize; i++) { - int[] priceArrs = new int[arraySize]; - for (int j = 0; j < arraySize; j++) { - rentInfoObject = rentInfoArray.getJSONObject(j); - adjustRatio = rentInfoObject.getJSONArray("adjustRatio");// - double price = priceList.get(i)[j] + priceList.get(i)[j] * adjustRatio.getIntValue(i) / 10000.0; - priceArrs[j] = new BigDecimal(price).setScale(0, RoundingMode.HALF_EVEN).intValue(); - } - priceList.add(priceArrs); - } - int size = priceList.size(); - int[] priceArrs = new int[size]; - for (int i = 0; i < size; i++) { - int[] price = priceList.get(i); - int sum = 0; - for (int p : price) { - sum += p; - } - priceArrs[i] = sum; - } - - - List> shopInfos = new ArrayList<>(); - for (int i = 0; i < size; i++) { - Map shopInfo = new HashMap<>(); - int[] ints = priceList.get(i); - for (int j = 0; j < ints.length; j++) { - rentInfoObject = rentInfoArray.getJSONObject(j); - shopInfo.put(rentInfoObject.getString("shopNumber"), ints[j]); - } - shopInfos.add(shopInfo); - } - - System.out.println(shopInfos); - //System.out.println(Arrays.toString(priceArr)); -// Calendar a = Calendar.getInstance(); -// a.set(Calendar.DATE, 1); -// a.roll(Calendar.DATE, -1); -// int maxDate = a.get(Calendar.DATE); -// System.out.println(maxDate); -// a.clear(); -// a.setTime(new Date()); -// System.out.println(a.get(Calendar.DAY_OF_MONTH)); - - } - } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxScoreRulesServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxScoreRulesServiceImpl.java index 9f1e0524e..1a7629783 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxScoreRulesServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxScoreRulesServiceImpl.java @@ -28,6 +28,8 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { private String keyPrev = "setting:scorerules:"; + private String creditKeyPrev = "setting:creditrules:"; + @Autowired WxScoreRulesMapper wxScoreRulesMapper; @Autowired @@ -57,6 +59,7 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { WxScoreRules scoreRules = new WxScoreRules(); scoreRules.setTenantId(tenantId); + scoreRules.setType(1); List list = wxScoreRulesMapper.findList(scoreRules); if (list.size() > 0) { scoreRules = list.get(0); @@ -76,6 +79,39 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { return scoreRules; } + @Override + public WxScoreRules getCreditRules(String tenantId) { + // get pushLime from cache + String key = creditKeyPrev + tenantId; + + // 缓存存在 + if (scoreRulesRedisTemplate.hasKey(key)) { + WxScoreRules wScoreRules = scoreRulesRedisTemplate.opsForValue().get(key); + logger.info("WxScoreRulesServiceImpl.getScoreRules() : 从缓存中获取了积分值设置 >> " + wScoreRules.toString()); + return wScoreRules; + } + + WxScoreRules scoreRules = new WxScoreRules(); + scoreRules.setTenantId(tenantId); + scoreRules.setType(2); + List list = wxScoreRulesMapper.findList(scoreRules); + if (list.size() > 0) { + scoreRules = list.get(0); + } else { + // 如果积分规则不存在,启用默认值 + final IdWorker idWorker = IdWorker.get(); + scoreRules.setId(idWorker.nextId()); + scoreRules.setRules(WxScoreRules.getDefaultRules()); + + wxScoreRulesMapper.insertSelective(scoreRules); + } + + // 插入缓存 + scoreRulesRedisTemplate.opsForValue().set(key, scoreRules); + logger.info("WxScoreRulesServiceImpl.getScoreRules() : 积分设置插入缓存 >> " + scoreRules.toString()); + + return scoreRules; + } @Override @@ -89,12 +125,23 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { wxScoreRulesMapper.updateByPrimaryKeySelective(record); } - // 缓存存在,删除缓存 - String key = keyPrev + record.getTenantId(); - boolean hasKey = scoreRulesRedisTemplate.hasKey(key); - if (hasKey) { - scoreRulesRedisTemplate.delete(key); - logger.info("WxScoreRulesServiceImpl.saveOrUpdate() : 从缓存中删除成长值设置 >> " + record.toString()); + if (record != null && record.getType() == 1) { + // 缓存存在,删除缓存 + String key = keyPrev + record.getTenantId(); + boolean hasKey = scoreRulesRedisTemplate.hasKey(key); + if (hasKey) { + scoreRulesRedisTemplate.delete(key); + logger.info("WxScoreRulesServiceImpl.saveOrUpdate() : 从缓存中删除成长值设置 >> " + record.toString()); + } + } + if (record != null && record.getType() == 2) { + // 缓存存在,删除缓存 + String key = creditKeyPrev + record.getTenantId(); + boolean hasKey = scoreRulesRedisTemplate.hasKey(key); + if (hasKey) { + scoreRulesRedisTemplate.delete(key); + logger.info("WxScoreRulesServiceImpl.saveOrUpdate() : 从缓存中删除积分设置 >> " + record.toString()); + } } } @@ -123,6 +170,8 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { } } + + private void resetBasicUserScore(Long userId, int scoreNumber) { // 1. basicUser WxCUserBasicInfo user = wxCUserBasicInfoMapper.selectByPrimaryKey(userId); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxShopServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxShopServiceImpl.java index 29c6ac051..fc16d0f2a 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxShopServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxShopServiceImpl.java @@ -9,19 +9,14 @@ import com.iformall.common.ResultData; import com.iformall.domain.po.WxMerchantShop; import com.iformall.domain.po.WxShop; import com.iformall.domain.vo.WxShopVo; -import com.iformall.enums.*; -import com.iformall.exception.MallinkException; +import com.iformall.enums.EnumDelStatus; +import com.iformall.enums.EnumRentShopType; +import com.iformall.enums.EnumShopStatus; +import com.iformall.enums.EnumUserAdmin; import com.iformall.mapper.WxMerchantShopMapper; import com.iformall.mapper.WxShopMapper; import com.iformall.service.ExcelService; import com.iformall.service.WxShopService; -import com.iformall.utils.Constant; -import com.iformall.utils.DownFileUtil; -import org.apache.commons.io.FileUtils; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.xssf.streaming.SXSSFSheet; -import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -29,9 +24,10 @@ import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.File; -import java.io.FileOutputStream; -import java.util.*; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; @Service public class WxShopServiceImpl implements WxShopService { @@ -83,21 +79,39 @@ public class WxShopServiceImpl implements WxShopService { } @Override - public void deleteById(Long id, Integer isAdmin) { + public ResultData deleteById(Long id, Integer isAdmin) { //1、已出租不让删除 WxShop wxShop = wxShopMapper.selectByPrimaryKey(id); + if (wxShop == null) { + return new ResultData(ErrorCode.SHOP_IS_NOT_FOUND); + } if (wxShop.getStatus().equals(EnumShopStatus.RENT.getCode())) { - throw new MallinkException(ErrorCode.SHOP_BAN_DELETED); + return new ResultData(ErrorCode.SHOP_BAN_DELETED); } //2、是否关联过商户 WxMerchantShop wxMerchantShop = new WxMerchantShop(); wxMerchantShop.setShopId(wxShop.getId()); - int count = wxMerchantShopMapper.selectCount(wxMerchantShop); + List wxMerchantShops = wxMerchantShopMapper.select(wxMerchantShop); //有关联过商户必须是管理员才能删除 - if (count > 0 && !isAdmin.equals(EnumUserAdmin.ADMIN.getCode())) { - throw new MallinkException(ErrorCode.SHOP_DELETED_BY_ADMIN); + int count = wxMerchantShops.size(); + if (count > 0) { + if (!isAdmin.equals(EnumUserAdmin.ADMIN.getCode())) { + return new ResultData(ErrorCode.SHOP_DELETED_BY_ADMIN); + } + //更新标记 + wxShop.setIsDel(EnumDelStatus.DEL.getCode()); + wxShopMapper.updateByPrimaryKeySelective(wxShop); + //关联表 + for (int i = 0; i < count; i++) { + WxMerchantShop updateMerchantShop = wxMerchantShops.get(i); + updateMerchantShop.setIsDel(EnumDelStatus.DEL.getCode()); + wxMerchantShopMapper.updateByPrimaryKeySelective(updateMerchantShop); + } + } else { + //无关联商铺直接删除 + wxShopMapper.deleteByPrimaryKey(id); } - wxShopMapper.deleteByPrimaryKey(id); + return new ResultData(Result.SUCCESS, "删除成功"); } @Override diff --git a/mallinkService/src/main/java/com/iformall/utils/ETCPUtil.java b/mallinkService/src/main/java/com/iformall/utils/ETCPUtil.java index ace4ab489..a6a3c52a4 100755 --- a/mallinkService/src/main/java/com/iformall/utils/ETCPUtil.java +++ b/mallinkService/src/main/java/com/iformall/utils/ETCPUtil.java @@ -3,6 +3,8 @@ package com.iformall.utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.iformall.common.ErrorCode; +import com.iformall.exception.MallinkException; import okhttp3.*; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -306,7 +308,7 @@ public class ETCPUtil { * } */ public String userSignin(String baseUrl, String appId, String merchantNo, String merchantKey, String version, - String mobilePhone) { + String mobilePhone) throws MallinkException { JSONObject jsonObject = new JSONObject(); jsonObject.put("appId", appId); jsonObject.put("mobilePhone", mobilePhone); @@ -315,8 +317,12 @@ public class ETCPUtil { String timeStamp = dateTimeFormatter.format(LocalDateTime.now()); String sign = genSign(data, merchantKey, timeStamp); - return doPost(baseUrl + userSigninUrl.replaceAll("\\{version}", version), data, sign, + String respStr = doPost(baseUrl + userSigninUrl.replaceAll("\\{version}", version), data, sign, timeStamp, merchantNo); + if(respStr.startsWith("")) { + throw new MallinkException(ErrorCode.ETCP_CMD_FAIL); + } + return respStr; } /** @@ -333,7 +339,7 @@ public class ETCPUtil { */ public String bindCar(String baseUrl, String merchantNo, String merchantKey, String version, String etcpToken, - String plateNumber, String plateColor) { + String plateNumber, String plateColor) throws MallinkException { JSONObject jsonObject = new JSONObject(); jsonObject.put("token", etcpToken); jsonObject.put("plateNumber", plateNumber); @@ -346,8 +352,12 @@ public class ETCPUtil { String timeStamp = dateTimeFormatter.format(LocalDateTime.now()); String sign = genSign(data, merchantKey, timeStamp); - return doPost(baseUrl + bindCarUrl.replaceAll("\\{version}", version), + String respStr = doPost(baseUrl + bindCarUrl.replaceAll("\\{version}", version), data, sign, timeStamp, merchantNo); + if(respStr.startsWith("")) { + throw new MallinkException(ErrorCode.ETCP_CMD_FAIL); + } + return respStr; } /** @@ -363,7 +373,7 @@ public class ETCPUtil { */ public String unbindCar(String baseUrl, String merchantNo, String merchantKey, String version, String etcpToken, - String plateNumber) { + String plateNumber) throws MallinkException { JSONObject jsonObject = new JSONObject(); jsonObject.put("token", etcpToken); jsonObject.put("plateNumber", plateNumber); @@ -372,8 +382,12 @@ public class ETCPUtil { String timeStamp = dateTimeFormatter.format(LocalDateTime.now()); String sign = genSign(data, merchantKey, timeStamp); - return doPost(baseUrl + unbindCarUrl.replaceAll("\\{version}", version), + String respStr = doPost(baseUrl + unbindCarUrl.replaceAll("\\{version}", version), data, sign, timeStamp, merchantNo); + if(respStr.startsWith("")) { + throw new MallinkException(ErrorCode.ETCP_CMD_FAIL); + } + return respStr; } /** @@ -392,7 +406,7 @@ public class ETCPUtil { public String carAuth(String baseUrl, String merchantNo, String merchantKey, String version, String etcpToken, String carFrameNum, String plateNumber, String carEngineNum - ) { + ) throws MallinkException { JSONObject jsonObject = new JSONObject(); jsonObject.put("token", etcpToken); jsonObject.put("carFrameNum", carFrameNum); @@ -403,8 +417,12 @@ public class ETCPUtil { String timeStamp = dateTimeFormatter.format(LocalDateTime.now()); String sign = genSign(data, merchantKey, timeStamp); - return doPost(baseUrl + carAuthUrl.replaceAll("\\{version}", version), + String respStr = doPost(baseUrl + carAuthUrl.replaceAll("\\{version}", version), data, sign, timeStamp, merchantNo); + if(respStr.startsWith("")) { + throw new MallinkException(ErrorCode.ETCP_CMD_FAIL); + } + return respStr; } /** @@ -423,7 +441,7 @@ public class ETCPUtil { */ public String carRetrieve(String baseUrl, String merchantNo, String merchantKey, String version, String etcpToken, - String carFrameNum, String plateNumber, String carEngineNum, String plateColor ) { + String carFrameNum, String plateNumber, String carEngineNum, String plateColor ) throws MallinkException { JSONObject jsonObject = new JSONObject(); jsonObject.put("token", etcpToken); jsonObject.put("carFrameNum", carFrameNum); @@ -436,8 +454,12 @@ public class ETCPUtil { String timeStamp = dateTimeFormatter.format(LocalDateTime.now()); String sign = genSign(data, merchantKey, timeStamp); - return doPost(baseUrl + carRetrieveUrl.replaceAll("\\{version}", version), + String respStr = doPost(baseUrl + carRetrieveUrl.replaceAll("\\{version}", version), data, sign, timeStamp, merchantNo); + if(respStr.startsWith("")) { + throw new MallinkException(ErrorCode.ETCP_CMD_FAIL); + } + return respStr; } /** @@ -458,7 +480,7 @@ public class ETCPUtil { * } */ public String carNum(String baseUrl, String merchantNo, String merchantKey, String version, - String etcpToken) { + String etcpToken) throws MallinkException { JSONObject jsonObject = new JSONObject(); jsonObject.put("token", etcpToken); @@ -466,8 +488,12 @@ public class ETCPUtil { String timeStamp = dateTimeFormatter.format(LocalDateTime.now()); String sign = genSign(data, merchantKey, timeStamp); - return doGet(baseUrl + carNumUrl.replaceAll("\\{version}", version), + String respStr = doGet(baseUrl + carNumUrl.replaceAll("\\{version}", version), data, sign, timeStamp, merchantNo); + if(respStr.startsWith("")) { + throw new MallinkException(ErrorCode.ETCP_CMD_FAIL); + } + return respStr; } /** @@ -481,7 +507,7 @@ public class ETCPUtil { public String orderUnpay(String baseUrl, String appId, String merchantNo, String merchantKey, String version, String etcpToken, - String plateNumber) { + String plateNumber) throws MallinkException { JSONObject jsonObject = new JSONObject(); jsonObject.put("token", etcpToken); jsonObject.put("plateNumber", plateNumber); @@ -493,8 +519,12 @@ public class ETCPUtil { String timeStamp = dateTimeFormatter.format(LocalDateTime.now()); String sign = genSign(data, merchantKey, timeStamp); - return doGet(baseUrl + orderUnpayUrl.replaceAll("\\{version}", version), + String respStr = doGet(baseUrl + orderUnpayUrl.replaceAll("\\{version}", version), data, sign, timeStamp, merchantNo); + if(respStr.startsWith("")) { + throw new MallinkException(ErrorCode.ETCP_CMD_FAIL); + } + return respStr; } /** @@ -508,7 +538,7 @@ public class ETCPUtil { public String couponList(String baseUrl, String merchantNo, String merchantKey, String version, String etcpToken, - String lastCode, String pageSize) { + String lastCode, String pageSize) throws MallinkException { JSONObject jsonObject = new JSONObject(); jsonObject.put("token", etcpToken); if (!StringUtils.isBlank(lastCode)) @@ -519,8 +549,12 @@ public class ETCPUtil { String timeStamp = dateTimeFormatter.format(LocalDateTime.now()); String sign = genSign(data, merchantKey, timeStamp); - return doGet(baseUrl + couponListUrl.replaceAll("\\{version}", version), + String respStr = doGet(baseUrl + couponListUrl.replaceAll("\\{version}", version), data, sign, timeStamp, merchantNo); + if(respStr.startsWith("")) { + throw new MallinkException(ErrorCode.ETCP_CMD_FAIL); + } + return respStr; } /** @@ -531,7 +565,7 @@ public class ETCPUtil { */ public String orderHistory(String baseUrl, String merchantNo, String merchantKey, String version, - String etcpToken) { + String etcpToken) throws MallinkException { JSONObject jsonObject = new JSONObject(); jsonObject.put("token", etcpToken); @@ -539,8 +573,12 @@ public class ETCPUtil { String timeStamp = dateTimeFormatter.format(LocalDateTime.now()); String sign = genSign(data, merchantKey, timeStamp); - return doGet(baseUrl + orderHistoryUrl.replaceAll("\\{version}", version), + String respStr = doGet(baseUrl + orderHistoryUrl.replaceAll("\\{version}", version), data, sign, timeStamp, merchantNo); + if(respStr.startsWith("")) { + throw new MallinkException(ErrorCode.ETCP_CMD_FAIL); + } + return respStr; } /** @@ -555,7 +593,7 @@ public class ETCPUtil { public String orderPay(String baseUrl, String merchantNo, String merchantKey, String version, String etcpToken, String orderId, - String returnUrl, String couponCode) { + String returnUrl, String couponCode) throws MallinkException { // payType 支付方式(1 微信公众号内支付 2 支付宝 H5 支付 3 微信二维码 4 支付宝二维码 5 微信 H5)(非空) int payType = 1; JSONObject jsonObject = new JSONObject(); @@ -571,8 +609,12 @@ public class ETCPUtil { String timeStamp = dateTimeFormatter.format(LocalDateTime.now()); String sign = genSign(data, merchantKey, timeStamp); - return doPost(baseUrl + orderpayUrl.replaceAll("\\{version}", version), + String respStr = doPost(baseUrl + orderpayUrl.replaceAll("\\{version}", version), data, sign, timeStamp, merchantNo); + if(respStr.startsWith("")) { + throw new MallinkException(ErrorCode.ETCP_CMD_FAIL); + } + return respStr; } /** @@ -591,7 +633,7 @@ public class ETCPUtil { String appId, String merchantNo, String merchantKey, String version, String etcpToken, String orderId, String externalOrderId, - BigDecimal payment, String payTime, String verificationInfo) { + BigDecimal payment, String payTime, String verificationInfo) throws MallinkException { JSONObject jsonObject = new JSONObject(); jsonObject.put("token", etcpToken); jsonObject.put("orderId", orderId); @@ -607,8 +649,12 @@ public class ETCPUtil { String timeStamp = dateTimeFormatter.format(LocalDateTime.now()); String sign = genSign(data, merchantKey, timeStamp); - return doPost(baseUrl + orderPaidUrl.replaceAll("\\{version}", version), + String respStr = doPost(baseUrl + orderPaidUrl.replaceAll("\\{version}", version), data, sign, timeStamp, merchantNo); + if(respStr.startsWith("")) { + throw new MallinkException(ErrorCode.ETCP_CMD_FAIL); + } + return respStr; } /** @@ -619,7 +665,7 @@ public class ETCPUtil { */ public String parkingInfo(String baseUrl, String merchantNo, String merchantKey, String version, - String lat, String lon, String radius) { + String lat, String lon, String radius) throws MallinkException { JSONObject jsonObject = new JSONObject(); jsonObject.put("lat", lat); jsonObject.put("lon", lon); @@ -630,8 +676,12 @@ public class ETCPUtil { String timeStamp = dateTimeFormatter.format(LocalDateTime.now()); String sign = genSign(data, merchantKey, timeStamp); - return doPost(baseUrl + parkingInfoUrl.replaceAll("\\{version}", version), + String respStr = doPost(baseUrl + parkingInfoUrl.replaceAll("\\{version}", version), data, sign, timeStamp, merchantNo); + if(respStr.startsWith("")) { + throw new MallinkException(ErrorCode.ETCP_CMD_FAIL); + } + return respStr; } /** @@ -642,7 +692,7 @@ public class ETCPUtil { */ public String parkingStatus(String baseUrl, String merchantNo, String merchantKey, String version, - String parkingId) { + String parkingId) throws MallinkException { JSONObject jsonObject = new JSONObject(); jsonObject.put("parkingId", parkingId); @@ -650,8 +700,12 @@ public class ETCPUtil { String timeStamp = dateTimeFormatter.format(LocalDateTime.now()); String sign = genSign(data, merchantKey, timeStamp); - return doPost(baseUrl + parkingStatusUrl.replaceAll("\\{version}", version), + String respStr = doPost(baseUrl + parkingStatusUrl.replaceAll("\\{version}", version), data, sign, timeStamp, merchantNo); + if(respStr.startsWith("")) { + throw new MallinkException(ErrorCode.ETCP_CMD_FAIL); + } + return respStr; } /** @@ -662,7 +716,7 @@ public class ETCPUtil { */ public String getDebt(String baseUrl, String appId, String merchantNo, String merchantKey, String version, - String etcpToken, String carNumber) { + String etcpToken, String carNumber) throws MallinkException { JSONObject jsonObject = new JSONObject(); jsonObject.put("token", etcpToken); jsonObject.put("appId", appId); @@ -672,8 +726,12 @@ public class ETCPUtil { String timeStamp = dateTimeFormatter.format(LocalDateTime.now()); String sign = genSign(data, merchantKey, timeStamp); - return doPost(baseUrl + parkingStatusUrl.replaceAll("\\{version}", version), + String respStr = doPost(baseUrl + parkingStatusUrl.replaceAll("\\{version}", version), data, sign, timeStamp, merchantNo); + if(respStr.startsWith("")) { + throw new MallinkException(ErrorCode.ETCP_CMD_FAIL); + } + return respStr; } /** @@ -686,7 +744,7 @@ public class ETCPUtil { */ public String repayDebt(String baseUrl, String merchantNo, String merchantKey, String version, - String etcpToken, String returnUrl) { + String etcpToken, String returnUrl) throws MallinkException { // payType(1:支付宝 2:微信H5) int payType = 2; JSONObject jsonObject = new JSONObject(); @@ -698,8 +756,12 @@ public class ETCPUtil { String timeStamp = dateTimeFormatter.format(LocalDateTime.now()); String sign = genSign(data, merchantKey, timeStamp); - return doPost(baseUrl + parkingStatusUrl.replaceAll("\\{version}", version), + String respStr = doPost(baseUrl + parkingStatusUrl.replaceAll("\\{version}", version), data, sign, timeStamp, merchantNo); + if(respStr.startsWith("")) { + throw new MallinkException(ErrorCode.ETCP_CMD_FAIL); + } + return respStr; } /** @@ -709,7 +771,7 @@ public class ETCPUtil { */ public String getBCouponList(String baseUrl, String merchantNo, String merchantKey, String version, - String parkId, String businessId) { + String parkId, String businessId) throws MallinkException { JSONObject jsonObject = new JSONObject(); jsonObject.put("parkId", parkId); jsonObject.put("businessId", businessId); @@ -718,8 +780,12 @@ public class ETCPUtil { String timeStamp = dateTimeFormatter.format(LocalDateTime.now()); String sign = genSign(data, merchantKey, timeStamp); - return doPost(baseUrl + bCouponListUrl.replaceAll("\\{version}", version), + String respStr = doPost(baseUrl + bCouponListUrl.replaceAll("\\{version}", version), data, sign, timeStamp, merchantNo); + if(respStr.startsWith("")) { + throw new MallinkException(ErrorCode.ETCP_CMD_FAIL); + } + return respStr; } /** @@ -731,7 +797,7 @@ public class ETCPUtil { public String bCouponRecord(String baseUrl, String merchantNo, String merchantKey, String version, String etcpToken, - String parkId, String businessId, String carNumber, String couponFreeId) { + String parkId, String businessId, String carNumber, String couponFreeId) throws MallinkException { JSONObject jsonObject = new JSONObject(); jsonObject.put("token", etcpToken); jsonObject.put("parkId", parkId); @@ -743,8 +809,12 @@ public class ETCPUtil { String timeStamp = dateTimeFormatter.format(LocalDateTime.now()); String sign = genSign(data, merchantKey, timeStamp); - return doPost(baseUrl + bCouponRecordUrl.replaceAll("\\{version}", version), + String respStr = doPost(baseUrl + bCouponRecordUrl.replaceAll("\\{version}", version), data, sign, timeStamp, merchantNo); + if(respStr.startsWith("")) { + throw new MallinkException(ErrorCode.ETCP_CMD_FAIL); + } + return respStr; } /** @@ -755,7 +825,7 @@ public class ETCPUtil { */ public String carSimulation(String baseUrl, String appId, String merchantNo, String merchantKey, String version, - String plateNumber) { + String plateNumber) throws MallinkException { JSONObject jsonObject = new JSONObject(); jsonObject.put("appId", appId); jsonObject.put("plateNumber", plateNumber); @@ -764,8 +834,12 @@ public class ETCPUtil { String timeStamp = dateTimeFormatter.format(LocalDateTime.now()); String sign = genSign(data, merchantKey, timeStamp); - return doPost(baseUrl + bCarSimulationUrl.replaceAll("\\{version}", version), + String respStr = doPost(baseUrl + bCarSimulationUrl.replaceAll("\\{version}", version), data, sign, timeStamp, merchantNo); + if(respStr.startsWith("")) { + throw new MallinkException(ErrorCode.ETCP_CMD_FAIL); + } + return respStr; } private String doPost(String url, String data, String sign, String timeStamp, String merchantNo) { diff --git a/mallinkService/src/main/resources/mapper/WxBillActionMapper.xml b/mallinkService/src/main/resources/mapper/WxBillActionMapper.xml new file mode 100644 index 000000000..e68abb250 --- /dev/null +++ b/mallinkService/src/main/resources/mapper/WxBillActionMapper.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + `id`,`tenant_id`,`bill_id`,`user_id`,`user_name`,`phone`,`action`,`details`,`createtime`,`updatetime` + + + + where 1=1 + + + and `id` = #{id} + + + + and `tenant_id` = #{tenantId} + + + + and `action` = #{action} + + + + and `bill_id` = #{billId} + + + + and id in + + #{idItem} + + + order by ${sortColumns} + + + + + + diff --git a/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml b/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml index f3069840a..f11e201d6 100644 --- a/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml @@ -2,12 +2,47 @@ - + select + bill.id,bill.tenant_id tenantId,bill.merchant_id merchantId,bill.shop_id shopId, + bill.bill_type_value billTypeValue,bill.bill_type billType,bill.need_pay needPay, + bill.receive_pay receivePay,bill.pay,bill.owe,bill.receive_date receiveDate,bill.pay_date payDate, + bill.expired_day expiredDay,bill.status, + bill.starttime,bill.endtime,bill.name,bill.rent_shop_type rentShopType, + m.name merchantName, + s.shop_number shopNumber, s.manager, s.manager_phone managerPhone + from ( select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金' bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type from wx_bill_rent where is_preview = 0 @@ -53,14 +88,14 @@ and bill.bill_type_value = #{billTypeValue} and bill.`status` = #{status} and bill.rent_shop_type = #{rentShopType} - + order by bill.id desc,bill.merchant_id,bill.status,bill.receive_date desc - + - - + + - + - - + + - - + + - - - + + + + + + + + diff --git a/mallinkService/src/main/resources/mapper/WxRentContractMapper.xml b/mallinkService/src/main/resources/mapper/WxRentContractMapper.xml index b03d2808d..7cc7b0323 100644 --- a/mallinkService/src/main/resources/mapper/WxRentContractMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxRentContractMapper.xml @@ -223,5 +223,9 @@ and merchant_id not in(select merchant_id from wx_property_contract where status in(2,3,4)) and rent_shop_type = #{rentShopType} + + diff --git a/mallinkService/src/main/resources/mapper/WxScoreRulesMapper.xml b/mallinkService/src/main/resources/mapper/WxScoreRulesMapper.xml index b6b25712f..375ae8ae7 100644 --- a/mallinkService/src/main/resources/mapper/WxScoreRulesMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxScoreRulesMapper.xml @@ -7,10 +7,12 @@ + + - `id`,`tenant_id`,`rules`,`create_date`,`update_date` + `id`,`tenant_id`,`rules`,`create_date`,`update_date`,`type`,`clear_year` @@ -29,6 +31,12 @@ and `update_date` = #{updateDate} + + and `type` = #{type} + + + and `clear_year` = #{clearYear} + and id in diff --git a/mallinkService/src/main/resources/mapper/WxShopMapper.xml b/mallinkService/src/main/resources/mapper/WxShopMapper.xml index eb7e550b6..aba684f35 100644 --- a/mallinkService/src/main/resources/mapper/WxShopMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxShopMapper.xml @@ -25,16 +25,18 @@ + + `id`,`tenant_id`,`shop_number`,`build_area`,`operation_area`,`building`, `floor`,`status`,`x`,`y`,`addr`,`baidu_poi`,`longitude`,`latitude`,`create_date`, - `update_date`,`img_url`,`manager`,`manager_phone`,`type`,`point_type`,`comments`,email + `update_date`,`img_url`,`manager`,`manager_phone`,`type`,`point_type`,`comments`,email,`is_del` - where 1 = 1 + where is_del=0 and `id` = #{id} @@ -132,6 +134,7 @@ and `email` = #{email} + and id in @@ -160,7 +163,7 @@ left join wx_merchant m on ms.merchant_id=m.id left join wx_mall_building b on s.building=b.id left join wx_mall_floor f on s.floor=f.id - where 1 = 1 + where s.is_del=0 and s.`id` = #{id} @@ -322,7 +325,7 @@ left join wx_mall_floor f on s.floor=f.id left join wx_business bus on m.business_id = bus.id left join wx_brand brand on m.brand = brand.id - where 1 = 1 + where s.is_del=0 and s.`id` = #{id} @@ -432,7 +435,7 @@ - select count(*) from wx_shop where tenant_id=#{tenantId} and shop_number=#{shopNumber} and `type`=#{type} + select count(*) from wx_shop where tenant_id=#{tenantId} and shop_number=#{shopNumber} and `type`=#{type} and + is_del=0 and id != #{id} diff --git a/mallinkService/src/main/resources/mapper/WxTagsMapper.xml b/mallinkService/src/main/resources/mapper/WxTagsMapper.xml index a920fdc2a..ccabccc2b 100644 --- a/mallinkService/src/main/resources/mapper/WxTagsMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxTagsMapper.xml @@ -64,4 +64,7 @@ and `name` = #{name} +