|  |  |  | 
|---|
|  |  |  | package com.zy.crm.manager.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
|---|
|  |  |  | import com.core.annotations.ManagerAuth; | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | import com.core.common.R; | 
|---|
|  |  |  | import com.zy.crm.common.web.BaseController; | 
|---|
|  |  |  | import com.zy.crm.manager.entity.CompanyTarget; | 
|---|
|  |  |  | import com.zy.crm.manager.entity.Order; | 
|---|
|  |  |  | import com.zy.crm.manager.service.CompanyTargetService; | 
|---|
|  |  |  | import com.zy.crm.manager.service.OrderService; | 
|---|
|  |  |  | import com.zy.crm.manager.utils.WordUtils; | 
|---|
|  |  |  | import com.zy.crm.system.entity.Role; | 
|---|
|  |  |  | import com.zy.crm.system.entity.User; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.text.DecimalFormat; | 
|---|
|  |  |  | import java.text.NumberFormat; | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | 
|---|
|  |  |  | public R getCompanyData() { | 
|---|
|  |  |  | HashMap<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | NumberFormat formatter = new DecimalFormat("#,###"); | 
|---|
|  |  |  | Date date = new Date(); | 
|---|
|  |  |  | SimpleDateFormat format = new SimpleDateFormat("yyyy"); | 
|---|
|  |  |  | String year = format.format(date); | 
|---|
|  |  |  | CompanyTarget companyTarget = companyTargetService.selectByYear(year);//获取公司全年目标数据 | 
|---|
|  |  |  | CompanyTarget companyTarget = companyTargetService.selectCompanyByYear(year);//获取公司全年目标数据 | 
|---|
|  |  |  | if (companyTarget == null) { | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | map.put("yearTarget", companyTarget.getTarget$());//全年交易目标 | 
|---|
|  |  |  | double whole = Double.parseDouble(companyTarget.getTarget()); | 
|---|
|  |  |  | map.put("yearTarget", formatter.format(whole));//全年交易目标 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取全年交易成功金额 | 
|---|
|  |  |  | Double successMoney = orderService.selectMoneyByYearAndStatus(year, 1); | 
|---|
|  |  |  | //获取全年未交易成功金额 | 
|---|
|  |  |  | Double progressMoney = orderService.selectMoneyByYearAndStatus(year, 0); | 
|---|
|  |  |  | //        double v = whole - orderService.selectMoneyByYearAndStatus(year, 0); | 
|---|
|  |  |  | double v = whole - orderService.selectMoneyByYearAndStatus(year, 1); | 
|---|
|  |  |  | Double progressMoney =  v > 0? v : 0D; | 
|---|
|  |  |  | //获取全年交易失败金额 | 
|---|
|  |  |  | Double failedMoney = orderService.selectMoneyByYearAndStatus(year, 2); | 
|---|
|  |  |  | //全年交易率 | 
|---|
|  |  |  | double yearTransactionRate = (successMoney / (successMoney + progressMoney + failedMoney)) * 100; | 
|---|
|  |  |  | map.put("successMoney", WordUtils.formatNumberForAccounting(successMoney));//全年交易成功金额 | 
|---|
|  |  |  | map.put("progressMoney", WordUtils.formatNumberForAccounting(progressMoney));//全年未交易成功金额 | 
|---|
|  |  |  | //全年完成率 | 
|---|
|  |  |  | //        double yearTransactionRate = successMoney == 0 ? successMoney : (successMoney / (successMoney + progressMoney + failedMoney)) * 100; | 
|---|
|  |  |  | double yearTransactionRate = successMoney == 0 ? successMoney : (successMoney / Double.parseDouble(companyTarget.getTarget())) * 100; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | map.put("successMoney", formatter.format(successMoney));//全年交易成功金额 | 
|---|
|  |  |  | map.put("progressMoney", formatter.format(progressMoney));//全年未交易成功金额 | 
|---|
|  |  |  | map.put("yearTransactionRate", String.format("%.2f", yearTransactionRate));//全年交易率 | 
|---|
|  |  |  | return R.ok().add(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | public R getPersonData() { | 
|---|
|  |  |  | HashMap<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | NumberFormat formatter = new DecimalFormat("#,###"); | 
|---|
|  |  |  | Date date = new Date(); | 
|---|
|  |  |  | SimpleDateFormat format = new SimpleDateFormat("yyyy"); | 
|---|
|  |  |  | String year = format.format(date); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | User user = getUser(); | 
|---|
|  |  |  | String yearTarget = "0.00";//获取个人全年目标数据 | 
|---|
|  |  |  | if (user.getTarget() != null) { | 
|---|
|  |  |  | yearTarget = WordUtils.formatNumberForAccounting(Double.parseDouble(user.getTarget()));; | 
|---|
|  |  |  | Double yearTarget = 0D;//获取个人全年目标数据 | 
|---|
|  |  |  | CompanyTarget person = companyTargetService.selectPersonByYear(year, getUserId()); | 
|---|
|  |  |  | if (person != null) { | 
|---|
|  |  |  | yearTarget = Double.parseDouble(person.getTarget()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | map.put("yearTarget", yearTarget);//全年交易目标 | 
|---|
|  |  |  | map.put("yearTarget", formatter.format(yearTarget));//全年交易目标 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取全年交易成功金额 | 
|---|
|  |  |  | Double successMoney = orderService.selectMoneyByUserAndYearAndStatus(user.getId(), year, 1); | 
|---|
|  |  |  | Double successMoney = orderService.selectMoneyByUserAndYearAndStatus(getUserId(), year, 1); | 
|---|
|  |  |  | //获取全年未交易成功金额 | 
|---|
|  |  |  | Double progressMoney = orderService.selectMoneyByUserAndYearAndStatus(user.getId(), year, 0); | 
|---|
|  |  |  | double v = yearTarget - orderService.selectMoneyByUserAndYearAndStatus(getUserId(), year, 1); | 
|---|
|  |  |  | Double progressMoney = v > 0? v : 0D; | 
|---|
|  |  |  | Double progressMoney2 = orderService.selectMoneyByUserAndYearAndStatus(getUserId(), year, 0); | 
|---|
|  |  |  | //获取全年交易失败金额 | 
|---|
|  |  |  | Double failedMoney = orderService.selectMoneyByUserAndYearAndStatus(user.getId(), year, 2); | 
|---|
|  |  |  | //全年交易率 | 
|---|
|  |  |  | double yearTransactionRate = (successMoney / (successMoney + progressMoney + failedMoney)) * 100; | 
|---|
|  |  |  | map.put("successMoney", WordUtils.formatNumberForAccounting(successMoney));//全年交易成功金额 | 
|---|
|  |  |  | map.put("progressMoney", WordUtils.formatNumberForAccounting(progressMoney));//全年未交易成功金额 | 
|---|
|  |  |  | Double failedMoney = orderService.selectMoneyByUserAndYearAndStatus(getUserId(), year, 2); | 
|---|
|  |  |  | //全年完成率 | 
|---|
|  |  |  | //        double yearTransactionRate = successMoney == 0 ? successMoney : (successMoney / (successMoney + progressMoney + failedMoney)) * 100; | 
|---|
|  |  |  | double yearTransactionRate = yearTarget==0? 0 : successMoney == 0 ? successMoney : (successMoney / yearTarget) * 100; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | map.put("successMoney", formatter.format(successMoney));//全年交易成功金额 | 
|---|
|  |  |  | map.put("progressMoney", formatter.format(progressMoney));//全年未交易成功金额 | 
|---|
|  |  |  | map.put("progressMoney2", formatter.format(progressMoney2));//跟踪项目金额 | 
|---|
|  |  |  | map.put("yearTransactionRate", String.format("%.2f", yearTransactionRate));//全年交易率 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取全年跟踪数量 | 
|---|
|  |  |  | Integer progressCount = orderService.selectCountByUserYearAndStatus(getUserId(), year, 0); | 
|---|
|  |  |  | //获取全年成交数量 | 
|---|
|  |  |  | Integer successCount = orderService.selectCountByUserYearAndStatus(getUserId(), year, 1); | 
|---|
|  |  |  | map.put("progressCount", progressCount); | 
|---|
|  |  |  | map.put("successCount", successCount); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok().add(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R getStaffRank() { | 
|---|
|  |  |  | ArrayList<HashMap<String, Object>> list = new ArrayList<>(); | 
|---|
|  |  |  | NumberFormat formatter = new DecimalFormat("#,###"); | 
|---|
|  |  |  | for (Order order : orderService.selectTopMoney()) { | 
|---|
|  |  |  | HashMap<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | map.put("username", order.getUserId$()); | 
|---|
|  |  |  | map.put("money", WordUtils.formatNumberForAccounting(order.getMoney())); | 
|---|
|  |  |  | map.put("money", formatter.format(order.getMoney())); | 
|---|
|  |  |  | list.add(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok().add(list); | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok().add(list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping("/dashboard/popup/auth") | 
|---|
|  |  |  | public R popup(String token) { | 
|---|
|  |  |  | String item = "false"; | 
|---|
|  |  |  | if (Cools.isEmpty(token)){ | 
|---|
|  |  |  | return R.ok(item); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | User user = getUser(token); | 
|---|
|  |  |  | if (Cools.isEmpty(user) || Cools.isEmpty(user.getRoleId())){ | 
|---|
|  |  |  | return R.ok(item); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (user.getRoleId()<3){ | 
|---|
|  |  |  | item="true"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(item); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|