wucl пре 2 година
родитељ
комит
f13b29cdee

+ 18 - 1
biz-base/src/main/java/com/dayou/controller/CustomerController.java

@@ -21,11 +21,18 @@ import com.dayou.common.PullDownModel;
 import com.dayou.utils.ConvertUtil;
 import com.dayou.utils.HttpKit;
 import com.dayou.exception.ErrorCode;
+
+import java.io.IOException;
 import java.util.Date;
 import java.util.List;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import org.springframework.http.MediaType;
 import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletResponse;
+
+import static com.dayou.common.Constants.MANAGER_OFFICE;
+
 /**
  * 客户表
  *
@@ -42,7 +49,7 @@ public class CustomerController extends BaseController {
     /**
     * 客户表列表
     */
-    @DataPermission
+    @DataPermission(ignoreDepartment = {MANAGER_OFFICE})
     @GetMapping("")
     public RestResponse<Page<CustomerDTO>> page(CustomerDTO customer, Page page){
         Page<CustomerDTO> pages=customerService.selectPage(page,customer);
@@ -131,5 +138,15 @@ public class CustomerController extends BaseController {
         customerService.importExcel(file);
         return RestResponse.data(true);
     }
+
+    /**
+     * 客户表导出
+     */
+    @DataPermission
+    @GetMapping("/export")
+    public void exportData(CustomerDTO customer,HttpServletResponse response ) throws IOException {
+        List<CustomerDTO> list = customerService.getList(customer);
+        exportPlus(response,"客户列表",list,CustomerDTO.class);
+    }
 }
 

+ 3 - 1
biz-base/src/main/java/com/dayou/controller/ItemController.java

@@ -31,6 +31,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import org.springframework.http.MediaType;
 import org.springframework.web.multipart.MultipartFile;
 
+import static com.dayou.common.Constants.MANAGER_OFFICE;
+import static com.dayou.common.Constants.MARKET_DEPARTMENT;
 import static com.dayou.enums.OperationTypeEnum.ADD;
 
 /**
@@ -49,7 +51,7 @@ public class ItemController extends BaseController {
     /**
     * 项目信息表列表(项目所属部门是自己的部门的项目)
     */
-    @DataPermission(department = true,postChild = false)
+    @DataPermission(department = true,postChild = false,ignoreDepartment = {MANAGER_OFFICE})
     @GetMapping("")
     public RestResponse<Page<ItemVO>> page(ItemDTO item, Page page){
         Page<ItemVO> pages=itemService.xSelectPage(page,item);

+ 5 - 1
biz-base/src/main/java/com/dayou/controller/ItemStageController.java

@@ -27,6 +27,8 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.validation.Valid;
 
+import static com.dayou.common.Constants.*;
+
 /**
  * 项目阶段表
  *
@@ -115,7 +117,9 @@ public class ItemStageController extends BaseController {
      * 项目首页流程数据
      * @return
      */
-    @DataPermission(department = true,postChild = false)
+    @DataPermission(department = true,postChild = false,
+            ignoreDepartment = {MANAGER_OFFICE,MARKET_DEPARTMENT},
+            ignorePost = {CUSTOMER_MANAGER,SALESMAN})
     @GetMapping("/list")
     public RestResponse<List<List<ItemStageVO>>> stageList(ItemStageVO itemStageVO){
         List<List<ItemStageVO>> list = itemStageService.stageList(itemStageVO);

+ 0 - 118
common/src/main/java/com/dayou/controller/BaseController.java

@@ -78,99 +78,6 @@ public class BaseController {
     }
 
 
-    protected void handleStudentPhotoZip(String zipName, HttpServletResponse response, List<? extends SimpleDownloadModel> downloadModels) throws IOException {
-        String fileName = URLEncoder.encode(zipName, "UTF-8");
-        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".zip");
-        File zipTmpFile = FileUtil.file(dfsConfig.getPath() + "\\" + RandomUtil.randomString(32) + ".zip");
-        List<File> fileList = new ArrayList<>();
-        for (SimpleDownloadModel simpleDownloadModel : downloadModels) {
-            try {
-                String url = simpleDownloadModel.getUrl();
-                String newFileName = simpleDownloadModel.getNewFileName();
-                if (StrUtil.isNotBlank(url)) {
-                    String parent = FileUtil.file(dfsConfig.getPath()).getParent();
-                    String filePath = "";
-                    if (!url.contains(parent)) {
-                        filePath = parent + url;
-                    } else {
-                        filePath = url;
-                    }
-                    File old = FileUtil.file(filePath);
-                    String extName = FileUtil.extName(old);
-                    String pathname = old.getParent() + "\\" + newFileName + "." + extName;
-                    //pathname = new String(pathname.getBytes("ISO8859-1"),"GBK");
-                    File tmp = new File(pathname);
-                    FileUtil.copyFile(old, tmp);
-                    fileList.add(tmp);
-                }
-            } catch (Exception e) {
-                log.error("导出zip错误 ", e);
-            }
-
-        }
-        File[] files = ArrayUtil.toArray(fileList, File.class);
-
-        ZipUtil.zip(zipTmpFile, true, files);
-
-        ServletOutputStream outputStream = response.getOutputStream();
-        IoUtil.copy(FileUtil.getInputStream(zipTmpFile), outputStream);
-
-        zipTmpFile.delete();
-        files = null;
-        for (File file : fileList) {
-            try {
-                file.delete();
-            } catch (Exception e) {
-            }
-        }
-    }
-
-    protected void handleApplyStudentPhotoZip(String zipName, HttpServletResponse response, List<? extends SimpleDownloadModel> downloadModels) throws IOException {
-        String fileName = URLEncoder.encode(zipName, "UTF-8");
-        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".zip");
-        File zipTmpFile = FileUtil.file(dfsConfig.getPath() + "\\" + RandomUtil.randomString(32) + ".zip");
-        List<File> fileList = new ArrayList<>();
-        for (SimpleDownloadModel simpleDownloadModel : downloadModels) {
-            try {
-                String url = simpleDownloadModel.getUrl();
-                String newFileName = simpleDownloadModel.getNewFileName();
-                if (StrUtil.isNotBlank(url)) {
-                    String parent = FileUtil.file(dfsConfig.getPath()).getParent();
-                    String filePath = "";
-                    if (!url.contains(parent)) {
-                        filePath = parent + url;
-                    } else {
-                        filePath = url;
-                    }
-                    File old = FileUtil.file(filePath);
-                    String extName = FileUtil.extName(old);
-                    File tmp =
-                            new File(old.getParent() + "\\" + newFileName + "." + extName);
-                    FileUtil.copyFile(old, tmp);
-                    fileList.add(tmp);
-                }
-            } catch (Exception e) {
-                log.error("导出zip错误 ", e);
-            }
-
-        }
-        File[] files = ArrayUtil.toArray(fileList, File.class);
-
-        ZipUtil.zip(zipTmpFile, true, files);
-
-        ServletOutputStream outputStream = response.getOutputStream();
-        IoUtil.copy(FileUtil.getInputStream(zipTmpFile), outputStream);
-
-        zipTmpFile.delete();
-        files = null;
-        for (File file : fileList) {
-            try {
-                file.delete();
-            } catch (Exception e) {
-            }
-        }
-    }
-
     protected void exportPlusCombos(HttpServletResponse response, String filename, List datas, Class clz, String[] options) throws IOException {
         ServletOutputStream outputStream = response.getOutputStream();
         ExcelPlusUtil<Object> util = new ExcelPlusUtil<Object>(clz);
@@ -179,29 +86,4 @@ public class BaseController {
         util.exportExcel2HttpResponse(datas, filename, outputStream, options);
     }
 
-    protected void handleStudentFileZip(String zipName, HttpServletResponse response, List<? extends SimpleDownloadModel> downloadModels)throws IOException {
-        String fileName = URLEncoder.encode(zipName, "UTF-8");
-        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".zip");
-        File zipTmpFile = FileUtil.file(dfsConfig.getPath() + "\\" + RandomUtil.randomString(32) + ".zip");
-        List<File> fileList = new ArrayList<>();
-        for (SimpleDownloadModel simpleDownloadModel : downloadModels) {
-            try {
-                String url = simpleDownloadModel.getUrl();
-                if (StrUtil.isNotBlank(url)) {
-                    File old = FileUtil.file("/opt"+url);
-                    fileList.add(old);
-                }
-            } catch (Exception e) {
-                log.error("导出zip错误 ", e);
-            }
-        }
-        File[] files = ArrayUtil.toArray(fileList, File.class);
-
-        ZipUtil.zip(zipTmpFile, true, files);
-
-        ServletOutputStream outputStream = response.getOutputStream();
-        IoUtil.copy(FileUtil.getInputStream(zipTmpFile), outputStream);
-
-        zipTmpFile.delete();
-    }
 }

+ 1 - 0
dao/src/main/java/com/dayou/mapper/CustomerMapper.java

@@ -20,4 +20,5 @@ public interface CustomerMapper extends CustomBaseMapper<Customer> {
 
     Page<CustomerDTO> getPage(Page page, @Param("customer") CustomerDTO customer);
 
+    List<CustomerDTO> getList( @Param("customer") CustomerDTO customer);
 }

+ 1 - 1
dao/src/main/resources/mapper/BusinessOpportunityMapper.xml

@@ -53,6 +53,6 @@
                 #{userId}
             </foreach>
         </if>
-        order by business_opportunity.id DESC
+        order by business_opportunity.state desc, business_opportunity.estimate_date DESC
     </select>
 </mapper>

+ 21 - 0
dao/src/main/resources/mapper/CustomerMapper.xml

@@ -50,4 +50,25 @@
             </if>
         </where>
     </select>
+
+    <select id="getList" parameterType="com.dayou.dto.CustomerDTO" resultType="com.dayou.dto.CustomerDTO">
+        select c.*,u.name as userName
+        from customer c left join user u on c.user_id = u.id
+        <where>
+            and c.deleted = 0 and u.deleted = 0
+            <if test="customer!=null and customer.name!=null and customer.name!='' ">
+                and c.name like concat ('%',#{customer.name},'%')
+            </if>
+            <if test="customer!=null and customer.level!=null and customer.level!='' ">
+                and c.level = #{customer.level}
+            </if>
+            <if test="customer!=null and customer.userIds!=null and customer.userIds.size!=0">
+                and  c.user_id in
+                <foreach collection="customer.userIds" open="(" close=")" separator="," item="userId">
+                    #{userId}
+                </foreach>
+            </if>
+        </where>
+        order by c.id DESC
+    </select>
 </mapper>

+ 9 - 1
dao/src/main/resources/mapper/MarketStatMapper.xml

@@ -75,7 +75,15 @@
             #{userId}
          </foreach>
       </if>
-        ) AS monthPaymentDone
+        ) AS monthPaymentDone,
+       ( select sum(estimate_amount) from business_opportunity where deleted = 0 and state = '跟进中'
+       <if test="dto!=null and dto.userIds!=null and dto.userIds.size!=0">
+           and user_id in
+           <foreach collection="dto.userIds" open="(" close=")" separator="," item="userId">
+               #{userId}
+           </foreach>
+       </if>
+       ) AS estimateAmount
    </select>
 
     <select id="currentMonthPayment" resultType="java.math.BigDecimal">

+ 3 - 0
dao/src/main/resources/mapper/VisitMapper.xml

@@ -43,6 +43,9 @@
                 or c.section like concat('%',#{keyword},'%')
             )
         </if>
+        <if test="visit!=null and visit.userName!=null and visit.userName!='' " >
+            and u.name like concat ('%',#{visit.userName},'%')
+        </if>
         <if test="visit!=null and visit.userIds!=null and visit.userIds.size!=0">
             and v.user_id in
             <foreach collection="visit.userIds" open="(" close=")" separator="," item="userId">

+ 21 - 2
domain/src/main/java/com/dayou/annotation/DataPermission.java

@@ -1,6 +1,13 @@
 package com.dayou.annotation;
 
+
+import com.google.common.collect.Sets;
+
 import java.lang.annotation.*;
+import java.util.Set;
+
+import static com.dayou.common.Constants.MANAGER_OFFICE;
+import static com.dayou.common.Constants.MARKET_DEPARTMENT;
 
 /**
  * 类说明:
@@ -18,11 +25,23 @@ public @interface DataPermission {
      * 岗位数据权限 是否包含下级岗位
      * @return
      */
-    public boolean postChild() default true;
+    boolean postChild() default true;
 
     /**
      * 部门数据权限
      * @return
      */
-    public boolean department() default false;
+    boolean department() default false;
+
+    /**
+     * 忽略数据权限的部门
+     * @return
+     */
+    String[] ignoreDepartment() default {};
+
+    /**
+     * 忽略数据权限的岗位
+     * @return
+     */
+    String[] ignorePost() default {};
 }

+ 8 - 0
domain/src/main/java/com/dayou/common/Constants.java

@@ -78,4 +78,12 @@ public interface Constants {
     BigDecimal HUNDRED = BigDecimal.TEN.multiply(BigDecimal.TEN);
 
     String YEARMONTH = "year-month";
+
+    String MANAGER_OFFICE = "总经办";
+
+    String MARKET_DEPARTMENT = "市场部";
+
+    String CUSTOMER_MANAGER = "客户经理";
+
+    String SALESMAN = "客户经理-业务员";
 }

+ 6 - 1
domain/src/main/java/com/dayou/dto/CustomerDTO.java

@@ -1,5 +1,7 @@
 package com.dayou.dto;
 
+import com.dayou.annotation.Excel;
+import com.dayou.annotation.ExportCell;
 import com.dayou.entity.Customer;
 import lombok.Data;
 
@@ -21,11 +23,13 @@ public class CustomerDTO extends Customer {
     /**
      * 市
      */
+    @Excel( name="市")
     private String firstCity;
 
     /**
      * 区县
      */
+    @Excel(name="区县")
     private String secCity;
 
     /**
@@ -34,7 +38,8 @@ public class CustomerDTO extends Customer {
     private Set<Long> userIds;
 
     /**
-     * 业务员
+     * 客户经理
      */
+    @Excel(name = "客户经理")
     private String userName;
 }

+ 10 - 12
domain/src/main/java/com/dayou/entity/Customer.java

@@ -1,4 +1,5 @@
 package com.dayou.entity;
+import com.dayou.annotation.Excel;
 import com.dayou.common.BaseEntity;
 import com.baomidou.mybatisplus.annotation.TableField;
 import lombok.Data;
@@ -28,56 +29,54 @@ public class Customer extends BaseEntity {
      * 客户名称
      */
     @ImportCell(notNull = true)
-    @ExportCell(columnName = "客户名称")
+    @Excel(name = "客户名称")
     private String name;
 
     /**
      * 省市县
      */
     @ImportCell
-    @ExportCell(columnName = "市")
     private String city;
 
     /**
      * 区/县 (已弃用)
      */
     @ImportCell
-    @ExportCell(columnName = "区/县")
     private String county;
 
     /**
      * 部门
      */
     @ImportCell
-    @ExportCell(columnName = "部门")
+    @Excel(name = "部门")
     private String department;
 
     /**
      * 职位
      */
     @ImportCell
-    @ExportCell(columnName = "职位")
+    @Excel(name = "职位")
     private String position;
 
     /**
      * 科室
      */
     @ImportCell
-    @ExportCell(columnName = "科室")
+    @Excel(name = "科室")
     private String section;
 
     /**
      * 联系电话
      */
     @ImportCell
-    @ExportCell(columnName = "联系电话")
+    @Excel(name = "联系电话")
     private String mobile;
 
     /**
      * 微信号
      */
     @ImportCell
-    @ExportCell(columnName = "微信号")
+    @Excel(name = "微信号")
     private String wechatNo;
 
     /**
@@ -85,28 +84,27 @@ public class Customer extends BaseEntity {
      */
     @TableField("QQ")
     @ImportCell
-    @ExportCell(columnName = "QQ号")
+    @Excel(name = "QQ号")
     private String qq;
 
     /**
      * 客户等级
      */
     @ImportCell()
-    @ExportCell(columnName = "客户等级")
+    @Excel(name = "客户等级")
     private String level;
 
     /**
      * 客户地址
      */
     @ImportCell
-    @ExportCell(columnName = "客户地址")
+    @Excel(name = "客户地址")
     private String address;
 
     /**
      * 所属员工id
      */
     @ImportCell
-    @ExportCell(columnName = "所属员工id")
     private Long userId;
 
 }

+ 5 - 0
domain/src/main/java/com/dayou/entity/Item.java

@@ -125,4 +125,9 @@ public class Item extends BaseEntity {
      * 客户id
      */
     private Long customerId;
+
+    /**
+     * 合同上传日期
+     */
+    private LocalDate uploadDate;
 }

+ 5 - 0
domain/src/main/java/com/dayou/vo/MarketStatVO.java

@@ -38,4 +38,9 @@ public class MarketStatVO {
      *本月已回款
      */
     private BigDecimal monthPaymentDone;
+
+    /**
+     * 预计签约金额
+     */
+    private BigDecimal estimateAmount;
 }

+ 9 - 9
service/src/main/java/com/dayou/aspect/DataPermissionAop.java

@@ -14,6 +14,7 @@ import org.aspectj.lang.annotation.Aspect;
 import org.aspectj.lang.annotation.Pointcut;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
 
 import java.lang.reflect.Field;
 import java.util.*;
@@ -47,18 +48,17 @@ public class DataPermissionAop {
     public Object  beforeHandle(ProceedingJoinPoint joinPoint, DataPermission dataPermission) throws Throwable {
 
         Object arg = joinPoint.getArgs()[0];
+        List<SimpleParentModel> departmentList = LoginContext.getLoginCacheUserBO().getDepartmentList();
+        List<String> departmentNames = departmentList.stream().map(SimpleListModel::getName).collect(Collectors.toList());
+        List<SimplePostModel> postList = LoginContext.getLoginCacheUserBO().getPostList();
+
+        List<String> ignores = Arrays.asList(dataPermission.ignoreDepartment());
+        if (!CollectionUtils.isEmpty(ignores) && !Collections.disjoint(departmentNames,ignores)){
+            return joinPoint.proceed();
+        }
 
         if (dataPermission.department()){
-            List<SimpleParentModel> departmentList = LoginContext.getLoginCacheUserBO().getDepartmentList();
-            List<Long> ids = departmentList.stream().map(SimpleListModel::getId).collect(Collectors.toList());
-            List<Long> parentIds = departmentList.stream().map(SimpleParentModel::getParentId).collect(Collectors.toList());
-            //需特殊处理最高部门,最高部门无数据权限限制
-            if (parentIds.contains(null)){
-                return joinPoint.proceed();
-            }
             //部门内部最高岗位拥有该部门最高数据权限,否则只有登录人参与的项目的数据权限
-            List<SimplePostModel> postList = LoginContext.getLoginCacheUserBO().getPostList();
-
             List<Long> dIds = new ArrayList<>();
             Set<Long> users = new HashSet<>();
             for (SimplePostModel post : postList){

+ 1 - 0
service/src/main/java/com/dayou/service/ICustomerService.java

@@ -33,4 +33,5 @@ public interface ICustomerService extends IService<Customer> {
 
         void importExcel(MultipartFile file);
 
+    List<CustomerDTO> getList(CustomerDTO customer);
 }

+ 30 - 8
service/src/main/java/com/dayou/service/impl/CustomerServiceImpl.java

@@ -14,6 +14,7 @@ import com.dayou.utils.LoginContext;
 import com.fasterxml.jackson.databind.util.BeanUtil;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -31,10 +32,9 @@ import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.ArrayList;
+import java.util.*;
+import java.util.stream.Collectors;
+
 import org.springframework.transaction.annotation.Transactional;
 import com.dayou.enums.BatchTaskTypeEnum;
 
@@ -47,12 +47,14 @@ import com.dayou.enums.BatchTaskTypeEnum;
  * @since 2023-01-10
  */
 @Service
-public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements ICustomerService {
+public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements ICustomerService , InitializingBean {
 
 
     @Autowired
     private IDistrictsService districtsService;
 
+    private Map<Long,String> districtsMap;
+
     @Autowired
     private CustomerMapper customerMapper;
     private static final List<String> customerExcelTitles = new ArrayList();
@@ -83,9 +85,8 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
             BeanUtils.copyProperties(x,dto);
             if (StrUtil.isNotEmpty(x.getCity())){
                 List<Long> citys = JSON.parseArray(x.getCity(), Long.class);
-                List<Districts> list = districtsService.list(new LambdaQueryWrapper<Districts>().select(Districts::getExtName).in(Districts::getId, citys));
-                dto.setFirstCity(list.get(1).getExtName());
-                dto.setSecCity(list.get(2).getExtName());
+                dto.setFirstCity(districtsMap.get(citys.get(1)));
+                dto.setSecCity(districtsMap.get(citys.get(2)));
             }
             xRecords.add(dto);
         });
@@ -151,6 +152,21 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
         }, file, BatchTaskTypeEnum.DEFAULT, ExcelUtil.BatchImportStrategy.ROLL_BACK);
     }
 
+    @Override
+    public List<CustomerDTO> getList(CustomerDTO customer) {
+        List<CustomerDTO> list = customerMapper.getList(customer);
+        list.stream().forEach(x->{
+            CustomerDTO dto = new CustomerDTO();
+            BeanUtils.copyProperties(x,dto);
+            if (StrUtil.isNotEmpty(x.getCity())){
+                List<Long> citys = JSON.parseArray(x.getCity(), Long.class);
+                x.setFirstCity(districtsMap.get(citys.get(1)));
+                x.setSecCity(districtsMap.get(citys.get(2)));
+            }
+        });
+        return list;
+    }
+
 
     private void createExcelTitle(XSSFWorkbook wb) {
         Sheet sheet = wb.createSheet("客户信息导入模板");
@@ -163,4 +179,10 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
             cell.setCellValue(customerExcelTitles.get(i));
         }
     }
+
+    @Override
+    public void afterPropertiesSet() throws Exception {
+        districtsMap = districtsService.list(new LambdaQueryWrapper<Districts>().select(Districts::getId, Districts::getExtName))
+                .stream().collect(Collectors.toMap(Districts::getId, Districts::getExtName));
+    }
 }