|
@@ -0,0 +1,227 @@
|
|
|
+package com.jpsoft.picc.modules.base.controller;
|
|
|
+
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.jpsoft.picc.modules.base.dto.PromoterDto;
|
|
|
+import com.jpsoft.picc.modules.base.entity.Company;
|
|
|
+import com.jpsoft.picc.modules.base.entity.CompanyUser;
|
|
|
+import com.jpsoft.picc.modules.base.service.CompanyService;
|
|
|
+import com.jpsoft.picc.modules.base.service.CompanyUserService;
|
|
|
+import com.jpsoft.picc.modules.business.entity.InsuranceApplication;
|
|
|
+import com.jpsoft.picc.modules.business.service.InsuranceApplicationService;
|
|
|
+import com.jpsoft.picc.modules.common.constant.PolicyStatus;
|
|
|
+import com.jpsoft.picc.modules.common.dto.MsgResult;
|
|
|
+import com.jpsoft.picc.modules.common.dto.Sort;
|
|
|
+import com.jpsoft.picc.modules.common.utils.PojoUtils;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import net.sf.jsqlparser.expression.DateTimeLiteralExpression;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Api(description = "推广者API")
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("/pub/promoter")
|
|
|
+public class PromoterController {
|
|
|
+ @Autowired
|
|
|
+ private CompanyService companyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CompanyUserService companyUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InsuranceApplicationService insuranceApplicationService;
|
|
|
+
|
|
|
+ @ApiOperation(value="保存推广者信息")
|
|
|
+ @RequestMapping(value = "save",method = RequestMethod.POST)
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "promoter",value = "推广者帐号", required = true, paramType = "query"),
|
|
|
+ @ApiImplicitParam(name = "userName",value = "企业账户用户名", required = true, paramType = "query"),
|
|
|
+ @ApiImplicitParam(name = "companyName",value = "企业名", required = true, paramType = "query"),
|
|
|
+ @ApiImplicitParam(name = "openId",value = "企业账户微信ID", required = true, paramType = "query"),
|
|
|
+ })
|
|
|
+ public MsgResult<String> save(String promoter,String userName,String companyName, String openId){
|
|
|
+ MsgResult<String> msgResult = new MsgResult<String>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ CompanyUser companyUser = companyUserService.findByUserName(userName);
|
|
|
+
|
|
|
+ if(companyUser==null) {
|
|
|
+ Company company = new Company();
|
|
|
+ company.setId(UUID.randomUUID().toString());
|
|
|
+ company.setName(companyName);
|
|
|
+ company.setPromoter(promoter);
|
|
|
+ company.setCreateBy(userName);
|
|
|
+ company.setCreateTime(new Date());
|
|
|
+ company.setDelFlag(false);
|
|
|
+
|
|
|
+ int affectCount = companyService.insert(company);
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ companyUser = new CompanyUser();
|
|
|
+ companyUser.setId(UUID.randomUUID().toString());
|
|
|
+ companyUser.setUserName(userName);
|
|
|
+ companyUser.setOpenId(openId);
|
|
|
+ companyUser.setCreateBy(userName);
|
|
|
+ companyUser.setCreateTime(new Date());
|
|
|
+ companyUser.setDelFlag(false);
|
|
|
+ companyUser.setCompanyId(company.getId());
|
|
|
+
|
|
|
+ affectCount = companyUserService.insert(companyUser);
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ msgResult.setSuccess(true);
|
|
|
+ } else {
|
|
|
+ msgResult.setSuccess(false);
|
|
|
+ msgResult.setMsg("添加企业用户信息失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ msgResult.setMsg("添加企业信息失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ msgResult.setSuccess(false);
|
|
|
+ msgResult.setMsg("企业账户" + userName + "已存在!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ log.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setSuccess(false);
|
|
|
+ msgResult.setMsg(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="推广者推广统计数据")
|
|
|
+ @RequestMapping(value = "promoterStatData",method = RequestMethod.POST)
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "promoter",value = "推广者帐号", required = true, paramType = "query")
|
|
|
+ })
|
|
|
+ public MsgResult<PromoterDto> promoterStatData(String promoter){
|
|
|
+ MsgResult<PromoterDto> msgResult = new MsgResult<PromoterDto>();
|
|
|
+ PromoterDto promoterDto = new PromoterDto();
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ Date date = new Date();
|
|
|
+
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
|
|
|
+
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+
|
|
|
+ calendar.setTime(date);
|
|
|
+
|
|
|
+ calendar.add(Calendar.MONTH, 1);//增加一个月
|
|
|
+
|
|
|
+ Date dt1 = calendar.getTime();
|
|
|
+
|
|
|
+ String startTime = sdf.format(date) + "-01";
|
|
|
+ String endTime = sdf.format(dt1) + "-01";
|
|
|
+
|
|
|
+ //累计客户数
|
|
|
+ List<Company> companyList = companyService.findByPromoter(promoter);
|
|
|
+
|
|
|
+ BigDecimal total = new BigDecimal(0);
|
|
|
+ BigDecimal month = new BigDecimal(0);
|
|
|
+
|
|
|
+ for (Company company : companyList) {
|
|
|
+ String status = String.valueOf(PolicyStatus.SendOutPolicy.getValue());
|
|
|
+ //累计投保生效金额
|
|
|
+ List<InsuranceApplication> insuranceApplicationList = insuranceApplicationService.findByCompanyId(company.getId(),status);
|
|
|
+
|
|
|
+ for (InsuranceApplication insuranceApplication : insuranceApplicationList) {
|
|
|
+ BigDecimal insuranceFee = insuranceApplication.getInsuranceFee();
|
|
|
+ total = total.add(insuranceFee);
|
|
|
+ }
|
|
|
+
|
|
|
+ //本月投保生效金额
|
|
|
+ List<InsuranceApplication> insuranceApplicationList2 = insuranceApplicationService.findByCompanyIdAndCreatTime(company.getId(), status,startTime, endTime);
|
|
|
+
|
|
|
+ for (InsuranceApplication insuranceApplication : insuranceApplicationList2) {
|
|
|
+ BigDecimal insuranceFee = insuranceApplication.getInsuranceFee();
|
|
|
+ month = month.add(insuranceFee);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //本月客户数
|
|
|
+ List<Company> monthCompanyList = companyService.findByPromoterAndCreatTime(promoter, startTime, endTime);
|
|
|
+
|
|
|
+ promoterDto.setCompanyNum(companyList.size());
|
|
|
+ promoterDto.setMonthCompanyNum(monthCompanyList.size());
|
|
|
+ promoterDto.setTotalInsuranceFee(total);
|
|
|
+ promoterDto.setMonthInsuranceFee(month);
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ log.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setSuccess(false);
|
|
|
+ msgResult.setMsg(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ msgResult.setSuccess(true);
|
|
|
+ msgResult.setData(promoterDto);
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="推广成功客户明细数据")
|
|
|
+ @RequestMapping(value = "promoterSuccessData",method = RequestMethod.POST)
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "promoter",value = "推广者帐号", required = true, paramType = "query"),
|
|
|
+ @ApiImplicitParam(name = "startTime",value = "开始时间", required = false, paramType = "query"),
|
|
|
+ @ApiImplicitParam(name = "endTime",value = "结束时间", required = false, paramType = "query")
|
|
|
+ })
|
|
|
+ public MsgResult<Map> promoterSuccessData(
|
|
|
+ String promoter,String startTime,String endTime,
|
|
|
+ @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
|
|
|
+ @RequestParam(value="pageSize",defaultValue="20") int pageSize){
|
|
|
+ MsgResult<Map> msgResult = new MsgResult<Map>();
|
|
|
+
|
|
|
+ Map<String,Object> searchParams = new HashMap<>();
|
|
|
+
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
+ sortList.add(new Sort("create_time","desc"));
|
|
|
+
|
|
|
+ searchParams.put("promoter",promoter);
|
|
|
+ searchParams.put("startTime",startTime);
|
|
|
+ searchParams.put("endTime",endTime);
|
|
|
+
|
|
|
+ Page<Company> page = companyService.pageSearch(searchParams,pageIndex,pageSize,sortList);
|
|
|
+
|
|
|
+ msgResult.setSuccess(true);
|
|
|
+
|
|
|
+ Map dataMap = PojoUtils.pageWrapper(page);
|
|
|
+
|
|
|
+ //客户企业名称、客户注册时间、联系电话
|
|
|
+ List<Map> mapList = new ArrayList<>();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ for (Company company: page.getResult()) {
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ map.put("name",company.getName());
|
|
|
+ map.put("createTime", sdf.format(company.getCreateTime()));
|
|
|
+ map.put("tel",company.getTel());
|
|
|
+
|
|
|
+ mapList.add(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ dataMap.put("data",mapList);
|
|
|
+
|
|
|
+ msgResult.setData(dataMap);
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+
|
|
|
+ }
|
|
|
+}
|