| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | |
| | | import cn.afterturn.easypoi.excel.ExcelExportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.ExportParams; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.annotation.Log; |
| | |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.WebUtils; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.dto.TCrmClinicAuditDTO; |
| | | import com.ruoyi.system.dto.TCrmClinicDTO; |
| | | import com.ruoyi.system.export.TCrmChangePointsBranchExport; |
| | | import com.ruoyi.system.export.TCrmClinicAuditExport; |
| | | import com.ruoyi.system.export.TCrmClinicListExport; |
| | | import com.ruoyi.system.model.*; |
| | | import com.ruoyi.system.query.TCrmChangePointsQuery; |
| | | import com.ruoyi.system.query.TCrmClinicQuery; |
| | | import com.ruoyi.system.service.*; |
| | | import com.ruoyi.system.vo.TCrmClinicVO; |
| | | import com.ruoyi.system.vo.TSysAppUserVO; |
| | | import com.ruoyi.web.controller.tool.MsgUtils; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.time.LocalDateTime; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | private final TCrmSalespersonService crmSalespersonService; |
| | | private final ISysUserService sysUserService; |
| | | private final TCrmDeviceService crmDeviceService; |
| | | private final TokenService tokenService; |
| | | private final MsgUtils msgUtils; |
| | | private final TSysMessageTemplateService sysMessageTemplateService; |
| | | @Autowired |
| | | public TCrmClinicController(TCrmClinicService crmClinicService, TCrmSupplierService crmSupplierService, TCrmBranchService crmBranchService, TCrmWarehouseService crmWarehouseService, TCrmSalespersonService crmSalespersonService, ISysUserService sysUserService, TCrmDeviceService crmDeviceService) { |
| | | public TCrmClinicController(TCrmClinicService crmClinicService, TCrmSupplierService crmSupplierService, TCrmBranchService crmBranchService, TCrmWarehouseService crmWarehouseService, TCrmSalespersonService crmSalespersonService, ISysUserService sysUserService, TCrmDeviceService crmDeviceService, TokenService tokenService, MsgUtils msgUtils, TSysMessageTemplateService sysMessageTemplateService) { |
| | | this.crmClinicService = crmClinicService; |
| | | this.crmSupplierService = crmSupplierService; |
| | | this.crmBranchService = crmBranchService; |
| | |
| | | this.crmSalespersonService = crmSalespersonService; |
| | | this.sysUserService = sysUserService; |
| | | this.crmDeviceService = crmDeviceService; |
| | | this.tokenService = tokenService; |
| | | this.msgUtils = msgUtils; |
| | | this.sysMessageTemplateService = sysMessageTemplateService; |
| | | } |
| | | |
| | | /** |
| | |
| | | @ApiOperation(value = "获取crm诊所管理分页列表") |
| | | @PostMapping(value = "/pageList") |
| | | public R<PageInfo<TCrmClinicVO>> pageList(@RequestBody TCrmClinicQuery query) { |
| | | Integer roleType = tokenService.getLoginUser().getUser().getRoleType(); |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | | if(roleType == 2){ |
| | | query.setUserId(userId); |
| | | query.setRoleType(roleType); |
| | | // 查询账号绑定的分公司 |
| | | TCrmBranch crmBranch = crmBranchService.getOne(Wrappers.lambdaQuery(TCrmBranch.class) |
| | | .eq(TCrmBranch::getUserId,userId) |
| | | .last("LIMIT 1")); |
| | | query.setBranchId(crmBranch.getId()); |
| | | } |
| | | if(roleType == 3){ |
| | | query.setUserId(userId); |
| | | query.setRoleType(roleType); |
| | | // 查询账号绑定的业务员 |
| | | TCrmSalesperson crmSalesperson = crmSalespersonService.getOne(Wrappers.lambdaQuery(TCrmSalesperson.class) |
| | | .eq(TCrmSalesperson::getUserId,userId) |
| | | .last("LIMIT 1")); |
| | | query.setSalespersonId(crmSalesperson.getId()); |
| | | } |
| | | return R.ok(crmClinicService.pageList(query)); |
| | | } |
| | | |
| | |
| | | @ApiOperation(value = "添加crm诊所管理") |
| | | @PostMapping(value = "/add") |
| | | public R<Boolean> add(@Validated @RequestBody TCrmClinicDTO dto) { |
| | | Integer roleType = tokenService.getLoginUser().getUser().getRoleType(); |
| | | if (roleType == 1){ |
| | | dto.setStatus(3); |
| | | }else { |
| | | dto.setStatus(1); |
| | | } |
| | | return crmClinicService.addClinic(dto); |
| | | } |
| | | |
| | |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | @Log(title = "crm诊所管理信息-诊所管理导出", businessType = BusinessType.EXPORT) |
| | | @ApiOperation(value = "诊所管理导出") |
| | | @PostMapping("/exportList") |
| | | public void exportList(@RequestBody TCrmClinicQuery query){ |
| | | List<TCrmClinicListExport> crmClinicListExports = crmClinicService.exportList(query); |
| | | for (TCrmClinicListExport crmClinicListExport : crmClinicListExports) { |
| | | if(Objects.nonNull(crmClinicListExport.getLowProcurementMoney())){ |
| | | crmClinicListExport.setLowProcurementMoneyStr("¥"+crmClinicListExport.getLowProcurementMoney()); |
| | | } |
| | | if(Objects.nonNull(crmClinicListExport.getMonthPurchaseAmount())){ |
| | | crmClinicListExport.setMonthPurchaseAmountStr("¥"+crmClinicListExport.getMonthPurchaseAmount()); |
| | | } |
| | | } |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TCrmClinicListExport.class, crmClinicListExports); |
| | | HttpServletResponse response = WebUtils.response(); |
| | | assert response != null; |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | ServletOutputStream outputStream = null; |
| | | try { |
| | | String fileName = URLEncoder.encode("诊所管理.xls", "utf-8"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + fileName); |
| | | response.setContentType("application/vnd.ms-excel;charset=UTF-8"); |
| | | response.setHeader("Pragma", "no-cache"); |
| | | response.setHeader("Cache-Control", "no-cache"); |
| | | outputStream = response.getOutputStream(); |
| | | workbook.write(outputStream); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | outputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | @Log(title = "crm诊所管理信息-诊所审核导出", businessType = BusinessType.EXPORT) |
| | | @ApiOperation(value = "诊所审核导出") |
| | | @PostMapping("/exportAudit") |
| | | public void exportAudit(@RequestBody TCrmClinicQuery query){ |
| | | List<TCrmClinicAuditExport> crmClinicAuditExports = crmClinicService.exportAudit(query); |
| | | for (TCrmClinicAuditExport crmClinicAuditExport : crmClinicAuditExports) { |
| | | if(Objects.nonNull(crmClinicAuditExport.getLowProcurementMoney())){ |
| | | crmClinicAuditExport.setLowProcurementMoneyStr("¥"+crmClinicAuditExport.getLowProcurementMoney()); |
| | | } |
| | | } |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TCrmClinicAuditExport.class, crmClinicAuditExports); |
| | | HttpServletResponse response = WebUtils.response(); |
| | | assert response != null; |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | ServletOutputStream outputStream = null; |
| | | try { |
| | | String fileName = URLEncoder.encode("诊所审核.xls", "utf-8"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + fileName); |
| | | response.setContentType("application/vnd.ms-excel;charset=UTF-8"); |
| | | response.setHeader("Pragma", "no-cache"); |
| | | response.setHeader("Cache-Control", "no-cache"); |
| | | outputStream = response.getOutputStream(); |
| | | workbook.write(outputStream); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | outputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 业绩短信提醒 |
| | | */ |
| | | @ApiOperation(value = "crm诊所管理信息-业绩短信提醒", notes = "clinicId:诊所id") |
| | | @GetMapping(value = "/medicationReminder") |
| | | public R<String> medicationReminder(@RequestParam(value = "clinicId") String clinicId) { |
| | | TCrmClinic crmClinic = crmClinicService.getById(clinicId); |
| | | if(StringUtils.isNotBlank(crmClinic.getPhone())){ |
| | | int performanceCount = crmClinic.getPerformanceCount() + 1; |
| | | TCrmSalesperson crmSalesperson = crmSalespersonService.getById(crmClinic.getSalespersonId()); |
| | | TSysMessageTemplate messageTemplate = sysMessageTemplateService.getOne(Wrappers.lambdaQuery(TSysMessageTemplate.class) |
| | | .eq(TSysMessageTemplate::getTemplateType, 2)); |
| | | // 发送短信 |
| | | try { |
| | | Map<String,String> params = new HashMap<>(); |
| | | params.put("name",crmSalesperson.getSalespersonName()); |
| | | params.put("num", Integer.toString(performanceCount)); |
| | | msgUtils.sendMsg(crmClinic.getPhone(),params, messageTemplate.getTemplateCode()); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | } |
| | | |