中扬CRM客户关系管理系统
#
luxiaotao1123
2022-09-18 5b9f71b862978c3ca16708db2f9de329bf65b3bf
src/main/java/com/zy/crm/manager/controller/CstmrController.java
@@ -9,14 +9,27 @@
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.R;
import com.core.exception.CoolException;
import com.zy.crm.common.web.BaseController;
import com.zy.crm.manager.entity.Cstmr;
import com.zy.crm.manager.service.CstmrService;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
@Slf4j
@RestController
public class CstmrController extends BaseController {
@@ -40,9 +53,24 @@
        EntityWrapper<Cstmr> wrapper = new EntityWrapper<>();
        excludeTrash(param);
        convert(param, wrapper);
        hostEq(wrapper);
        allLike(Cstmr.class, param.keySet(), wrapper, condition);
        if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
        return R.ok(cstmrService.selectPage(new Page<>(curr, limit), wrapper));
        if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} else {
            wrapper.orderBy("create_time", false);
        }
        if (!Cools.isEmpty(param.get("dept_id"))) {
            return R.ok(cstmrService.getPage(new Page<>(curr, limit)
                    , getHostId()
                    , String.valueOf(param.get("dept_id"))
                    , condition)
            );
        } else {
            if (Cools.isEmpty(param.get("user_id"))) {
                wrapper.andNew();
                wrapper.eq("user_id", getUserId());
            }
            return R.ok(cstmrService.selectPage(new Page<>(curr, limit), wrapper));
        }
    }
    private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){
@@ -61,8 +89,12 @@
    @RequestMapping(value = "/cstmr/add/auth")
    @ManagerAuth
    public R add(Cstmr cstmr) {
        cstmr.setHostId(getHostId());
        cstmr.setUuid(cstmrService.getNextUuid());  // 客户代号
        Long hostId = getHostId();
        if (cstmrService.selectByUuid(hostId, cstmr.getUuid()) != null) {
            throw new CoolException("客户已存在");
        }
        cstmr.setHostId(hostId);
        cstmr.setUuid(cstmrService.getUuid(hostId));  // 客户代号
        cstmr.setDeptId(getDeptId());               // 所属部门
        cstmr.setUserId(getUserId());               // 所属人员
@@ -133,4 +165,66 @@
        return R.ok();
    }
    /*************************************** 数据相关 ***********************************************/
    /**
     * excel导入
     */
    @PostMapping(value = "/cstmr/excel/import/auth")
    @ManagerAuth(memo = "甲方单位Excel导入")
    @Transactional
    public R cstmrExcelImport(MultipartFile file) throws IOException {
        try (InputStream inStream = file.getInputStream()) {
            String fileMime = file.getContentType();
            int excelVersion = 2007;
            if ("application/vnd.ms-excel".equals(fileMime)) {
                excelVersion = 2003;
            }
            Workbook book = null;
            if (excelVersion == 2003) {
                book = new HSSFWorkbook(inStream);
            }
            else {  // 当 excel 是 2007 时
                book = new XSSFWorkbook(inStream);
            }
            Sheet sheet = book.getSheetAt(0);
            int totalRows = sheet.getPhysicalNumberOfRows() - 1;    // 总
            Long userId = getUserId();
            Long hostId = getHostId();
            Long deptId = getDeptId();
            Date now = new Date();
            for (int i = 2; i < totalRows; i++) {
                Cstmr cstmr = new Cstmr();
                Row row = sheet.getRow(i);
                System.out.println(row.getCell(0).getStringCellValue());
                cstmr.setHostId(hostId);
                cstmr.setDeptId(deptId);
                cstmr.setUserId(userId);
                cstmr.setStatus(1);
                cstmr.setCreateBy(userId);
                cstmr.setCreateTime(now);
                cstmr.setUpdateBy(userId);
                cstmr.setUpdateTime(now);
                if (!cstmrService.insert(cstmr)) {
                    throw new CoolException("保存失败,请重新导入");
                }
            }
        }  catch (Exception e) {
            e.printStackTrace();
        }
        return R.ok();
    }
    /**
     * excel导出
     */
    @PostMapping(value = "/cstmr/excel/export/auth")
    @ManagerAuth
    public void cstmrExcelExport(HttpServletResponse response) throws IOException {
    }
}