6 Commits d7e7eb843d ... 12a20b3dcb

Auteur SHA1 Message Date
  liuchuanwei 12a20b3dcb feat:调试人情往来新增编辑页面 il y a 7 mois
  liuchuanwei aa6e3399dd refactor:重命名人员删除接口 il y a 7 mois
  liuchuanwei db5aac069a feat:调试人情往来事件列表查询页面 il y a 7 mois
  liuchuanwei b34fc81ff6 feat:修改人情往来事件列表查询SQL il y a 7 mois
  liuchuanwei e79c77dcc3 feat:添加人情往来事件删除接口 il y a 7 mois
  liuchuanwei be7877cd4e refactor:修改接口错误返回方法 il y a 7 mois

+ 22 - 10
src/main/java/com/anyway/favor/controller/FavorController.java

@@ -44,15 +44,13 @@ public class FavorController {
      * @return
      */
     @RequestMapping("/toList")
-    public ModelAndView toList(@RequestParam Map<String, Object> map, ModelAndView mv) {
+    public ModelAndView toList(ModelAndView mv) {
         User currentUser = SessionUtils.currentUser();
-        map.put("createBy", currentUser.getId());
-        if(!map.containsKey("sortName")) {
-            map.put("sortName", "occur_date");
-            map.put("sortOrder", "asc");
-        }
-        List<Favor> favorList = favorService.findByCondition(map);
-        mv.addObject("favorList", favorList);
+        //人员列表
+        Map<String, Object> map = new HashMap<>();
+        map.put("relatedId", SessionUtils.currentUserId());
+        List<Person> personList = personService.findByCondition(map);
+        mv.addObject("personList", personList);
         mv.setViewName("/favor/list");
         return mv;
     }
@@ -89,6 +87,7 @@ public class FavorController {
         map.put("relatedId", SessionUtils.currentUserId());
         List<Person> personList = personService.findByCondition(map);
         mv.addObject("personList", personList);
+        //送礼人员列表
         if (!StringUtils.isEmpty(sourcePersonIds)) {
             map.put("idList", Arrays.asList(sourcePersonIds.split(",")));
             List<Person> sourcePersonList = personService.findByCondition(map);
@@ -111,7 +110,7 @@ public class FavorController {
         User currentUser = SessionUtils.currentUser();
         favor.setCreateBy(currentUser.getId());
         favor.setModifyBy(currentUser.getId());
-        return favorService.add(favor) ? R.ok() : R.fail();
+        return favorService.add(favor) ? R.ok() : R.fail("新增失败");
     }
 
     /**
@@ -143,7 +142,7 @@ public class FavorController {
     public R update(@RequestBody Favor favor) {
         User currentUser = SessionUtils.currentUser();
         favor.setModifyBy(currentUser.getId());
-        return favorService.update(favor) ? R.ok() : R.fail();
+        return favorService.update(favor) ? R.ok() : R.fail("保存失败");
     }
 
     /**
@@ -164,4 +163,17 @@ public class FavorController {
         return mv;
     }
 
+    /**
+     * 删除
+     *
+     * @param id
+     * @return
+     */
+    @RequestMapping("/delete/{id}")
+    @ResponseBody
+    public R delete(@PathVariable Long id) {
+        boolean b = favorService.deleteById(id);
+        return b ? R.ok() : R.fail("删除失败");
+    }
+
 }

+ 5 - 5
src/main/java/com/anyway/favor/controller/PersonController.java

@@ -74,7 +74,7 @@ public class PersonController {
         person.setRelatedId(currentUser.getId());
         person.setCreateBy(currentUser.getId());
         person.setModifyBy(currentUser.getId());
-        return personService.add(person) ? R.ok() : R.fail();
+        return personService.add(person) ? R.ok() : R.fail("新增失败");
     }
 
     /**
@@ -120,7 +120,7 @@ public class PersonController {
     public R update(@RequestBody Person person) {
         User currentUser = SessionUtils.currentUser();
         person.setModifyBy(currentUser.getId());
-        return personService.update(person) ? R.ok() : R.fail();
+        return personService.update(person) ? R.ok() : R.fail("保存失败");
     }
 
     /**
@@ -190,9 +190,9 @@ public class PersonController {
      * @return
      */
     @ResponseBody
-    @RequestMapping("/del/{id}")
-    public R del(@PathVariable Long id) {
+    @RequestMapping("/delete/{id}")
+    public R delete(@PathVariable Long id) {
         int c = personService.delete(id);
-        return  c > 0? R.ok() : R.fail();
+        return  c > 0? R.ok() : R.fail("删除失败");
     }
 }

+ 7 - 0
src/main/java/com/anyway/favor/service/FavorService.java

@@ -54,4 +54,11 @@ public interface FavorService {
      */
     Favor findById(Long id);
 
+    /**
+     * 根据ID移除
+     *
+     * @param id
+     * @return
+     */
+    boolean deleteById(Long id);
 }

+ 9 - 0
src/main/java/com/anyway/favor/service/impl/FavorServiceImpl.java

@@ -77,4 +77,13 @@ public class FavorServiceImpl implements FavorService {
     public Favor findById(Long id) {
         return favorMapper.findById(id);
     }
+
+    @Override
+    public boolean deleteById(Long id) {
+        int i = favorMapper.deleteById(id);
+        if (i>0) {
+            favorItemMapper.deleteByFavorId(id);
+        }
+        return i>0;
+    }
 }

+ 3 - 2
src/main/java/com/anyway/util/R.java

@@ -48,12 +48,13 @@ public class R {
     /**
      * 失败返回
      *
+     * @param msg
      * @return
      */
-    public static R fail() {
+    public static R fail(String msg) {
         R r = new R();
         r.setCode(1);
-        r.setMsg("失败");
+        r.setMsg(msg);
         return r;
     }
 

+ 7 - 1
src/main/resources/mapper/FavorMapper.xml

@@ -24,10 +24,16 @@
         <if test="occurDate != null">
             AND f.occur_date = #{occurDate}
         </if>
+        <if test="@Ognl@isNotEmpty(startOccurDate)">
+            AND f.occur_date >= DATE_FORMAT(#{startOccurDate},'%Y-%m-%d')
+        </if>
+        <if test="@Ognl@isNotEmpty(endOccurDate)">
+            <![CDATA[ AND f.occur_date <= DATE_FORMAT(#{endOccurDate},'%Y-%m-%d') ]]>
+        </if>
         <if test="title != null and title != ''">
             AND f.title LIKE CONCAT('%', #{title}, '%')
         </if>
-        <if test="personId != null">
+        <if test="@Ognl@isNotEmpty(personId)">
             AND f.person_id = #{personId}
         </if>
         <if test="remark != null and remark != ''">

+ 39 - 26
src/main/webapp/WEB-INF/pages/favor/add.jsp

@@ -67,7 +67,7 @@
         </div>
         <div class="layui-form-item"> <label class="layui-form-label">收入金额</label>
             <div class="layui-input-inline">
-                <input type="number" name="incomeAmount" value="${favor.incomeAmount}" min="0" autocomplete="off" class="layui-input">
+                <input id="incomeAmount" type="number" name="incomeAmount" value="${favor.incomeAmount}" min="0" autocomplete="off" class="layui-input">
             </div>
         </div>
         <div class="layui-form-item"> <label class="layui-form-label">支出金额</label>
@@ -149,6 +149,7 @@
         });
         form.on('select(person)', function (data) {
             setValue(data);
+            console.log("选中收礼人", table.cache['favorItemTab']);
         });
 
         function setValue(data) {
@@ -157,7 +158,6 @@
             let tableData = table.cache['favorItemTab']; // grid为table id
             // 更新到表格的缓存数据中,才能在获得选中行等等其他的方法中得到更新之后的值
             tableData[trElem.data('index')][elem.attr('class')] = data.value;
-            console.log("列表数据:", tableData);
         }
 
         //送礼人列表
@@ -192,19 +192,20 @@
                 remark:""
             })
         }
-        console.log(dataa);
-        table.render({
+        console.log("初始化表格数据:", dataa);
+        //region 渲染往来明细表格数据
+        let tables = table.render({
             elem: '#favorItemTab',
             data:dataa,
             toolbar: '#toolbarDemo', //开启头部工具栏,并为其绑定左侧模板
             title: '人情明细',
             cols: [[
-                {field:'sourcePersonId', title:'送礼人', width:200, templet: '#sourcePersonTpl'},
-                {field:'address', title:'地址', width:150},
+                {field:'sourcePersonId', title:'送礼人', width:150, templet: '#sourcePersonTpl'},
+                {field:'address', title:'地址', width:100},
                 {field:'amount', title:'金额', width:100, edit: 'number'},
-                {field:'returnGift', title:'还礼', width:150, edit: 'textarea'},
-                {field:'personId', title:'收礼人', width:200, templet: '#personTpl'},
-                {field:'remark', title:'备注', edit: 'text'},
+                {field:'returnGift', title:'还礼', width:100, edit: 'textarea'},
+                {field:'personId', title:'收礼人', width:150, templet: '#personTpl'},
+                {field:'remark', title:'备注', width:150, edit: 'textarea'},
                 {fixed:'right', align:'center', toolbar: '#barDemo'}
             ]],
             page: false,
@@ -223,29 +224,33 @@
                 form.render();
             }
         });
+        //endregion
+
         //监听行工具事件
         table.on('tool(favorItem)', function(obj){
             if(obj.event === 'del'){
-                obj.del();
-                let index = $(obj.tr).attr("data-index");
-                removeArrEle(table.cache["favorItemTab"], index);
-                console.log("删除一条明细", table.cache["favorItemTab"])
+                //删除对应行(tr)的DOM结构,并更新缓存
+                let tableData = table.cache["favorItemTab"];
+                tableData.splice(obj.tr.data('index'), 1)//根据索引删除当前行
+                tables.reload({
+                    data: tableData
+                });
+                console.log("删除一条明细后:", table.cache["favorItemTab"]);
+                calcAmount();
             }
         });
         // 单元格普通编辑事件
         table.on('edit(favorItem)', function(obj){
-            console.log("编辑了:" + JSON.stringify(obj));
-            let value = obj.value // 得到修改后的值
-            let data = obj.data // 得到所在行所有键值
-            let field = obj.field; // 得到字段
             // 更新数据中对应的字段
             let update = {};
-            update[field] = value;
+            update[obj.field] = obj.value;
             obj.update(update);
-
+            console.log("编辑一条明细后:", table.cache["favorItemTab"]);
+            if (obj.field === 'amount') {
+                calcAmount();
+            }
         });
 
-
         //头工具栏事件
         table.on('toolbar(favorItem)', function (obj) {
             switch (obj.event) {
@@ -260,13 +265,23 @@
                         remark:""
                     }
                     oldData.push(newRow);
-                    console.log("新增一条明细", oldData);
                     table.reload('favorItemTab', {
                         data: oldData
                     });
+                    console.log("新增一条明细后:", table.cache["favorItemTab"]);
                     break;
             }
         });
+        //计算收入总金额
+        function calcAmount() {
+            let arr = table.cache["favorItemTab"];
+            let totalAmount = 0;
+            for(let i=0; i<arr.length; i++) {
+                totalAmount = totalAmount + parseFloat(arr[i].amount);
+            }
+            console.log("计算收礼总金额", totalAmount);
+            $("#incomeAmount").val(totalAmount);
+        }
 
         //监听提交
         form.on('submit(submit)', function(data){
@@ -275,8 +290,6 @@
             if (formJson.id === undefined || formJson.id === '') {
                 url = "${pageContext.request.contextPath}/favor/add";
             }
-            //删除不需要的属性
-            deleteObjKey(formJson, "sourcePersonId");
             formJson.favorItemList = [];
             let arr = table.cache['favorItemTab'];
             for(let i=0; i<arr.length; i++) {
@@ -287,8 +300,8 @@
                     formJson.favorItemList.push(arr[i]);
                 }
             }
-            console.log("提交地址:" + url);
-            console.log(formJson);
+            console.log("提交-地址:", url);
+            console.log("提交-请求报文:", formJson);
             $.ajax({
                 url:url,
                 type:"POST",
@@ -296,7 +309,7 @@
                 contentType:"application/json; charset=utf-8",
                 dataType:"json",
                 success: function(res){
-                    console.log(res);
+                    console.log("提交-返回报文:", res);
                     if (res.code === 1) {
                         layer.msg(res.msg, {icon: 2, time: 2000});
                     } else {

+ 34 - 26
src/main/webapp/WEB-INF/pages/favor/list.jsp

@@ -15,13 +15,13 @@
 <div style="margin: 0 auto; width: 90%;">
     <form class="layui-form" action="">
         <div class="layui-inline">
-            <label class="layui-form-label">事件</label>
+            <label class="layui-form-label">事件标题</label>
             <div class="layui-input-inline">
                 <input type="text" id="title" name="title" autocomplete="off" class="layui-input">
             </div>
         </div>
         <div class="layui-inline">
-            <label class="layui-form-label">人员</label>
+            <label class="layui-form-label">事件对象</label>
             <div class="layui-input-inline">
                 <select id="personId" name="personId" lay-verify="" lay-search>
                     <option value="">请选择</option>
@@ -48,7 +48,7 @@
         </div>
     </form>
 
-    <table id="favorTab" class="layui-hide" lay-filter="person"></table>
+    <table id="favorTab" class="layui-hide" lay-filter="favor"></table>
 </div>
 
 <%-- 表格上方按钮 --%>
@@ -69,19 +69,19 @@
 <script>
     let headUrl = "${pageContext.request.contextPath}";
     layui.use(['laydate', 'table',], function () {
-        var $ = layui.$,//jquery
+        let $ = layui.$,//jquery
             table = layui.table,//表格
             layer = layui.layer,//基础
             laydate = layui.laydate;//日期
-        var myDate = new Date();//获取当前时间设置选择时间的范围
-        var maxtime = myDate.getFullYear() + "-" + (myDate.getMonth() + 1) + "-" + (myDate.getDate());//拼接当前是时间
 
-        //初始化选择时间控件
+        //region 初始化选择时间控件
+        let myDate = new Date();//获取当前时间设置选择时间的范围
+        let maxTime = myDate.getFullYear() + "-" + (myDate.getMonth() + 1) + "-" + (myDate.getDate());//拼接当前是时间
         laydate.render({
             elem: '#occurDate'
             , type: 'date'
             , range: '~'
-            , max: maxtime//设置选择最大时间为当前
+            , max: maxTime//设置选择最大时间为当前
             , calendar: true
             , btns: ['clear', 'confirm', 'now']
             , done: function (value, date) {
@@ -90,6 +90,7 @@
                 console.log("日期范围的值:" + value)
             }
         });
+        //endregion
         //数据表格渲染
         table.render({
             id: 'favorTab',
@@ -119,15 +120,28 @@
             cols: [[
                 { field: 'occurDate', title: '日期', sort: true },
                 { field: 'title', title: '事件'},
-                { field: 'personName', title: '主体人员'},
+                { field: 'personName', title: '对象', event: 'clickPerson',style:'cursor: pointer;' },
                 { field: 'incomeAmount', title: '收入金额'},
                 { field: 'payAmount', title: '支出金额' },
                 { field: 'remark', title: '备注'},
                 { fixed: 'right', align:'center', width: 240, toolbar: '#barDemo'}
             ]]
         });
-        //搜索
+        //点击查询按钮
         $('#searchBtn').on('click', function () {
+            let terms = {
+                title: $("#title").val(),
+                personId: $("#personId").val()
+            };
+            let occurDate = $("#occurDate").val();
+            let arr = occurDate.split(" ~ ");
+            if(arr.length > 0) {
+                terms.startOccurDate = arr[0];
+                if(arr.length>1) {
+                    terms.endOccurDate = arr[1];
+                }
+            }
+
             table.reload('favorTab', {
                 url: '${pageContext.request.contextPath}/favor/listPage',
                 method: 'post',
@@ -141,12 +155,8 @@
                     pageNo: 1 //重新从第 1 页开始
                 },
                 where : {
-                    terms: {
-                        title: $("#title").val(),
-                        personId: $("#personId").val(),
-                        familyPersonId: $("#familyPersonId").val()
-                    },
-                    sortName: "p.create_time",
+                    terms: terms,
+                    sortName: "occur_date",
                     sortOrder: "asc"
                 }
             });
@@ -154,27 +164,25 @@
         });
 
         //头工具栏事件
-        table.on('toolbar(person)', function (obj) {
+        table.on('toolbar(favor)', function (obj) {
             switch (obj.event) {
                 case 'addFavor':
                     window.location.href = "${pageContext.request.contextPath}/favor/toAdd";
                     break;
-            };
+            }
         });
 
         //监听行工具事件
-        table.on('tool(person)', function (obj) {
-            var data = obj.data;
-            if (obj.event === 'clickAddress') {
-                $("#address").val(data.address);
-                $("#searchBtn").click();
-            } else if (obj.event === 'addFavor') {
-                $("#address").val(data.address);
+        table.on('tool(favor)', function (obj) {
+            let data = obj.data;
+            if (obj.event === 'clickPerson') {
+                $("#personId").val(data.personId);
+                layui.form.render();
                 $("#searchBtn").click();
             } else if (obj.event === 'del') {
                 //eg1
                 layer.confirm('确定要删除?<br/><i>会删掉关联的明细等</i>', {icon: 3, title:'提示'}, function(index){
-                    let url = "${pageContext.request.contextPath}/favor/del/" + data.id;
+                    let url = "${pageContext.request.contextPath}/favor/delete/" + data.id;
                     $.ajax({
                         url:url,
                         type:"POST",

+ 1 - 1
src/main/webapp/WEB-INF/pages/person/list.jsp

@@ -210,7 +210,7 @@
             } else if (obj.event === 'del') {
                 //eg1
                 layer.confirm('确定要删除?<br/><i>会删掉相关人员的配偶、父母等</i>', {icon: 3, title:'提示'}, function(index){
-                    let url = "${pageContext.request.contextPath}/person/del/" + data.id;
+                    let url = "${pageContext.request.contextPath}/person/delete/" + data.id;
                     $.ajax({
                         url:url,
                         type:"POST",