销售机会管理增删改+客户开发计划

CRM客户关系关系系统复习

5、销售机会管理增删改,客户开发计划查询

4章节中“客户经理乱码的,加载不出来的”在navicat中输入命令查看MySQL编码命令

 show variables like 'character%';

结果这样就是对的:

 | character_set_client     | utf8                                                    |
 | character_set_connection | utf8                                                   |
 | character_set_database   | utf8                                                   |
 | character_set_filesystem | binary                                                 |
 | character_set_results   | utf8                                                   |
 | character_set_server     | utf8                                                   |
 | character_set_system     | utf8                                        

指派给的选中事件:

 $(function () {
             $("#assignMan").combobox({
                 //选中事件
                 onSelect: function (record) {
                     console.log(record);
                     if (record.truename != '') {
                         $("#assignTime").val(getCurrentDateTime());
                    } else {
                         $("#assignTime").val("");
                    }
                }
            });
        });

保存的前台代码:

 function saveSaleChance() {
     $("#fm").form("submit", {
         url: url,
         onSubmit: function () {//提交表单调用
             return $(this).form("validate");//表单验证
        },
         success: function (result) {//请求成功的回调
             result = eval("("+ result +")");  //{success:true/false}
             if (result.success) {
                 $.messager.alert("系统提示", "保存成功!");
                 resetValue();
                 $("#dlg").dialog("close");
                 $("#dg").datagrid("reload");//重新加载数据 datagrid会再发送一次url加载最新数据
            } else {
                 $.messager.alert("系统提示", "保存失败!");
                 return;
            }
        }
    });
 }

逻辑:

 新增销售机会:
     前台:easyUI-form  easyui-validatebox  easyui-combobox
     点击保存按钮,提交表单ajax请求 saleChance/save
     后台处理请求插入数据库,返回{success:true/false}
     前台success回调方法中:
     $("#dlg").dialog("close");关闭对话框
     $("#dg").datagrid("reload"); 重新加载数据
   修改销售机会:
       $("#dg").form("load",row); row是选中的一条对应的json数据(js对象),通过
       load方法自动回显数据,只要row里的属性名和form表单中的name一致就行了
       需要考虑的是,如果用户点击的是未指派的数据然后指派了一个人,那么我们要把state修改为1
   删除销售机会:
   前台根据js代码发送所有选中的ids:1,2,3,4,5
   后台单表删除即可,因为删除的是未开发的(没有销售计划的)

5.1、添加销售机会代码:(因为前台json数据,所以用TSaleChance来接收,new HashMap,向前台传success,判断true/false)

SaleChanceController

 @RequestMapping("save")
 public Map save(TSaleChance saleChance){
     HashMap map = new HashMap<>();
     try {
         saleChanceService.insertSaleChance(saleChance);
         map.put("success",true);
    }catch (Exception e){
         e.printStackTrace();
         map.put("success",false);
    }
     return map;//自动变成json了,因为用的是@RestController
 }

ISaleChanceService

 //插入销售机会数据
 void insertSaleChance(TSaleChance saleChance);

SaleChanceServiceImpl,里面public上方@service注解下面要加上@Transactional注解(事务)

 @Transactional(readOnly = true)//没事务加事务,有事务用当前事务,这段代码要不要都行
 @Override
 public void insertSaleChance(TSaleChance saleChance) {
     //根据assignman指派给,确定分配状态,分客户经理就是已分配,没分就是未分配
     if (StringUtils.isNotBlank(saleChance.getAssignman())) {
             saleChance.setState(1);
        }else {
             saleChance.setState(0);
        }
         //确定开发状态
         saleChance.setDevresult(0);
         saleChanceMapper.insertSelective(saleChance);//insertSelective选择性插入
 }

到此发现日期接收格式不正确(createtime,assigntime)-----接收需要自己设置日期格式

bean中TSaleChance 里面定义

 @DateTimeFormat(pattern="yyyy-mm-dd HH:mm:ss")
 private Date createtime;
 
 @DateTimeFormat(pattern="yyyy-mm-dd HH:mm:ss")
 private Date assigntime;

至此,添加完成

5.2、修改,更新销售机会代码:(因为前台json数据,所以还用TSaleChance来接收,new HashMap)

SaleChanceController

 @RequestMapping("update")
 public Map update(TSaleChance saleChance){
     HashMap map = new HashMap<>();
     try {
         saleChanceService.updateSaleChance(saleChance);
         map.put("success",true);
    }catch (Exception e){
         e.printStackTrace();
         map.put("success",false);
    }
     return map;//自动变成json了,因为用的是@RestController
 }

ISaleChanceService

 //修改,更新销售机会数据
 void updateSaleChance(TSaleChance saleChance);

SaleChanceServiceImpl

 @Override
     public void updateSaleChance(TSaleChance saleChance) {
         //可以把未分配的修改成已分配,判断是否有指派人
         if (StringUtils.isNotBlank(saleChance.getAssignman()))
             saleChance.setState(1);
         saleChanceMapper.updateByPrimaryKeySelective(saleChance);
    }

修改完成

5.3、删除销售机会代码:(用string字符串来接收ids)

SaleChanceController

 @RequestMapping("delete")
     public Map deleteSaleChanceByIds(String ids){
         HashMap map = new HashMap<>();
         try {
             saleChanceService.deleteSaleChance(ids);
             map.put("success",true);
        }catch (Exception e){
             e.printStackTrace();
             map.put("success",false);
        }
         return map;
    }

ISaleChanceService

     //删除销售机会数据
     void deleteSaleChance(String ids);

SaleChanceServiceImpl

 @Override
     public void deleteSaleChance(String ids) {
         //将id拆分成数组
         String[] ids_arr = ids.split(",");
         //逆向工程写
         TSaleChanceExample example = new TSaleChanceExample();
         List<Integer> idsList = new ArrayList<>();
         for (String id : ids_arr) {
             idsList.add(Integer.parseInt(id));
        }
         //where id in(1,2,3,4,5)
         example.createCriteria().andIdIn(idsList);
         saleChanceMapper.deleteByExample(example);
    }

销售机会管理增删改完成

 

6、客户开发计划分页查询

 1.查询
     查询的条件为所有已经分配的销售机会state=1
     修改controller代码:
              if (devResultOrState == 1){
                  saleChance.setState(1);
              }
              if (devResultOrState == 0){
                  saleChance.setDevresult(0);
              }
     点击开发按钮:调用main.jsp中的openTab方法,传入url为cusdevplanitemManage?saleChanceId=xx,新增选项卡
     在新的页面中,通过参数域把id取出来${param.saleChanceId}
     直接在页面中通过$.post发送了findById?saleChanceId=xx请求
                通过datagrid发送url,GET cusDevPlan/52
     后台处理这两个异步请求即可。(销售计划的增删改查采用restFul请求风格)

6.1、显示、检索客户开发计划(由于逻辑与销售机会管理查询相通,所以改一处代码即可完成查询数据)

修改SaleChanceController中的

 @RestController
 @RequestMapping("saleChance")
 public class SaleChanceController {
     @Autowired
     private ISaleChanceService saleChanceService;
     //SaleChance/list/0 检索销售机会管理的查询
     //SaleChance/list/1 检索销售计划管理中的销售机会
     @RequestMapping("list/{devResultOrState}")
     //page 当前页   rows每页显示条数
     //通过TSaleChance接受前台提交的查询条件
     public DatagridResult list(TSaleChance saleChance, @PathVariable int devResultOrState, int page, int rows){
          if(devResultOrState == 1){
              saleChance.setState(1);
          }
          if (devResultOrState == 0){
              saleChance.setDevresult(0);
          }
          return saleChanceService.selectSaleChanceByPage(saleChance,page,rows);
    }
     @RequestMapping("save")
     public Map save(TSaleChance saleChance){
         HashMap map = new HashMap<>();
         try {
             saleChanceService.insertSaleChance(saleChance);
             map.put("success",true);
        }catch (Exception e){
             e.printStackTrace();
             map.put("success",false);
        }
         return map;//自动变成json了,因为用的是@RestController
    }
     @RequestMapping("update")
     public Map update(TSaleChance saleChance){
         HashMap map = new HashMap<>();
         try {
             saleChanceService.updateSaleChance(saleChance);
             map.put("success",true);
        }catch (Exception e){
             e.printStackTrace();
             map.put("success",false);
        }
         return map;//自动变成json了,因为用的是@RestController
    }
     @RequestMapping("delete")
     public Map deleteSaleChanceByIds(String ids){
         HashMap map = new HashMap<>();
         try {
             saleChanceService.deleteSaleChance(ids);
             map.put("success",true);
        }catch (Exception e){
             e.printStackTrace();
             map.put("success",false);
        }
         return map;
    }
 }

6.2、根据id检索销售机会

SaleChanceController

 @RequestMapping("findById")
     //根据id检索,显示销售机会信息
     public TSaleChance findById(int id){
         return saleChanceService.selectSaleChanceById(id);
    }

ISaleChanceService

 //根据id检索销售机会
     TSaleChance selectSaleChanceById(int id);

SaleChanceServiceImpl

 @Override
     public TSaleChance selectSaleChanceById(int id) {
         return saleChanceMapper.selectByPrimaryKey(id);
 }

6.3、根据外键查询devPlan表数据(开发计划项数据显示)

新建DevPlanController

 @RestController
 @RequestMapping("cusDevPlan")
 public class DevPlanController {
     @Autowired
     private IDevPlanService devPlanService;
     //restFul处理
     @GetMapping("{SaleChanceId}")
     public DatagridResult list(@PathVariable int SaleChanceId){
         return devPlanService.selectPlanSaleChanceId(SaleChanceId);
    }
 }

IDevPlanService

 //根据外键查询devPlan表数据
     DatagridResult selectPlanSaleChanceId(int saleChanceId);

DevPlanServiceImpl

 @Service
 public class DevPlanServiceImpl implements IDevPlanService {
     @Autowired
     private TCusDevPlanMapper devPlanMapper;
 
     @Override
     public DatagridResult selectPlanSaleChanceId(int saleChanceId) {
         TCusDevPlanExample example = new TCusDevPlanExample();
         example.createCriteria().andSalechanceidEqualTo(saleChanceId);
         List<TCusDevPlan> devPlanList = devPlanMapper.selectByExample(example);
         DatagridResult datagridResult = new DatagridResult();
         datagridResult.setRows(devPlanList);
         return datagridResult;
    }
 }
 
posted @ 2022-05-25 19:34  为了她  阅读(23)  评论(0编辑  收藏  举报