小区添加所属居委的同时把所对应的居委代码也加进去

CommunityController

package com.wise.SpringController.web.songduweb;


import com.wise.SpringController.service.CommunityService;
import com.wise.SpringController.model.T_Community;
import com.wise.SpringController.model.T_Juwei;
import com.wise.SpringController.tool.CustomResponse;
import com.wise.SpringController.tool.StringUtils;
import com.wise.SpringController.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/community")
public class CommunityController extends BaseController {
    @Autowired
    private CommunityService communityService;

    /**
     * 跳转首页
     * @return
     */
    @GetMapping("/index")
    public String community() {
        return "community/index";
    }

    /**
     * 列表显示
     * @param communityBean
     * @return
     */
    @PostMapping("/list")
    @ResponseBody
    public Object list(T_Community communityBean) {
        startPage();
        List<Map<String,Object>> list = communityService.selectCommunityList(communityBean);
        return getCustomResponse(list);
    }


    /**
     * 添加修改
     * @param id
     * @param model
     * @return
     */
    @RequestMapping("/formView")
    public String formView(String id, Model model){
        T_Community communityBean=null;
        if (id != null) {
            communityBean=communityService.selectCommunityById(id);
        } else {
            communityBean=new T_Community();
        }
        model.addAttribute("communityBean",communityBean);
        List<Map<String,Object>> t_juwei= communityService.selectJuwei();
        model.addAttribute("juweiBean",t_juwei);
        return "community/form";
    }

    @ResponseBody
    @RequestMapping("/insertCommunity")
    public Object insertCommunity(T_Community communityBean,String juweiCode){
        if (communityBean!=null){
            Map<String,Object> juwei = communityService.selectByJuweiCode(juweiCode);
            communityBean.setJuwei(juwei.get("JUWEINAMEFULL").toString());

            if (StringUtils.isNotEmpty(communityBean.getId())){
                communityService.updateCommunity(communityBean);
                return new CustomResponse(true,"修改成功");
            }else{
                communityService.insertCommunity(communityBean);
                return new CustomResponse(true,"保存成功");
            }
        }else{
            return new CustomResponse(false,"保存失败");
        }

    }

    @RequestMapping("deleteById")
    @ResponseBody
    public Object deleteById(String id) {
        try {
            communityService.deleteById(id);
            return new CustomResponse(true, "删除成功");
        } catch (Exception e) {
            return new CustomResponse(true, "删除失败");
        }
    }
}

CommunityService(接口)

package com.wise.SpringController.service;


import com.wise.SpringController.model.T_Community;
import com.wise.SpringController.model.T_Juwei;


import java.util.List;
import java.util.Map;

public interface CommunityService {
    /**
     * 插入小区信息
     * @param t_community
     * @return
     */
    int insertCommunity(T_Community t_community);

    /**
     * 修改
     * @param t_community
     * @return
     */
    int updateCommunity(T_Community t_community);

    /**
     * 列表查询
     * @param t_community
     * @return
     */
    List<Map<String,Object>> selectCommunityList(T_Community t_community);

    /**
     * 社区名称、编码查询
     * @return
     */
    List<Map<String,Object>> selectJuwei();

    /**
     * 通过社区编号查询社区名称
     * @return
     */
    Map<String,Object> selectByJuweiCode(String juweiCode);

    /**
     * 通过ID查询
     * @param id 数据ID
     * @return
     */
    T_Community selectCommunityById(String id);

    /**
     * 假删
     * @param id 数据ID
     * @return
     */
    int deleteById(String id);

    /**
     * 小程序显示
     * @param id 用户ID
     * @return
     */
    T_Community wxCommunityDetails(String id);

}

CommunityServicelmpl

package com.wise.SpringController.service.impl;


import com.wise.SpringController.dao.SdTCommunityMapper;
import com.wise.SpringController.model.T_Community;
import com.wise.SpringController.model.T_Juwei;
import com.wise.SpringController.service.CommunityService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CommunityServicelmpl implements CommunityService{
    @Autowired
    private SdTCommunityMapper tCommunityMapper;
    /**
     * 详情查询
     * @param id 数据ID
     * @return
     */
    @Override
    public T_Community selectCommunityById(String id) {
        return tCommunityMapper.selectCommunityById(id);
    }

    /**
     * 列表查询
     * @param community
     * @return
     */
    @Override
    public List<Map<String,Object>> selectCommunityList(T_Community community) {
        return tCommunityMapper.selectCommunityList(community);
    }

    /**
     * 查询社区编码、名称
     * @return
     */
    @Override
    public List<Map<String,Object>> selectJuwei() {
        return tCommunityMapper.selectJuwei();
    }

    /**
     * 通过社区编号查询社区名称
     * @return
     */
    @Override
    public Map<String,Object> selectByJuweiCode(String juweiCode) {
        return tCommunityMapper.selectByJuweiCode(juweiCode);
    }

    @Override
    public int insertCommunity(T_Community community) {
        return tCommunityMapper.insertCommunity(community);
    }

    /**
     * 修改
     * @param community
     * @return
     */
    @Override
    public int updateCommunity(T_Community community) {
        return tCommunityMapper.updateCommunity(community);
    }

    /**
     * 假删
     * @param id 数据ID
     * @return
     */
    @Override
    public int deleteById(String id) {
        return tCommunityMapper.deleteCommunityById(id);
    }

    /**
     * 小程序查询
     * @param id 用户ID
     * @return
     */
    @Override
    public T_Community wxCommunityDetails(String id) {
        return tCommunityMapper.wxCommunityDetails(id);
    }
}

SdTCommunityMapper(接口)

package com.wise.SpringController.dao;

import com.wise.SpringController.model.T_Community;
import com.wise.SpringController.model.T_Juwei;

import java.util.List;
import java.util.Map;

public interface SdTCommunityMapper {

    /**
     * 小区列表
     * @param community
     * @return
     */
    List<Map<String,Object>> selectCommunityList(T_Community community);

    /**
     * 通过id查询小区列表
     * @param id
     * @return
     */
    T_Community selectCommunityById(String id);

    /**
     * 查询社区编码、名称
     * @return
     */
    List<Map<String,Object>> selectJuwei();

    /**
     * 通过社区编号查询社区名称
     * @param juweiCode
     * @return
     */
    Map<String,Object> selectByJuweiCode(String juweiCode);
    
    /**
     * 保存小区列表
     * @param community
     * @return
     */
    int insertCommunity(T_Community community);

    /**
     * 修改小区列表
     * @param community
     * @return
     */
    int updateCommunity(T_Community community);

    /**
     * 删除小区列表
     * @param id
     * @return
     */
    int deleteCommunityById(String id);

    /**
     * 小程序查询
     * @param id
     * @return
     */
    T_Community wxCommunityDetails(String id);
    
    /**
     * 小区名称列表
     * @param t_Community
     * @return
     */
    List<T_Community> selectTCommunityList(T_Community t_Community);

    /**
     * 小区名称列表
     * @param t_Community
     * @return
     */
    List<Map<String,Object>> selectMapTCommunityList(T_Community t_Community);

    /**
     * 通过id查询小区列表
     * @param id
     * @return
     */
    T_Community selectTCommunityById(String id);
}

CommunityMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.wise.SpringController.dao.SdTCommunityMapper">

    <resultMap type="com.wise.SpringController.model.T_Community" id="CommunityResult">
        <result property="id" column="id"/>
        <result property="title" column="title"/>
        <result property="juweiCode" column="juwei_code"/>
        <result property="communityName" column="community_name"/>
        <result property="address" column="address"/>
        <result property="area" column="area"/>
        <result property="households" column="households"/>
        <result property="juwei" column="juwei"/>
        <result property="createDate" column="create_date"/>
        <result property="updateDate" column="update_date"/>
    </resultMap>

    <sql id="selectCommunity">
        SELECT tc.title,tc.id,tc.release_status,tc.juwei_code,tc.community_name,tc.address,tc.area,tc.households,tc.juwei,tc.create_date,tc.update_date
        FROM T_COMMUNITY tc
    </sql>

    <select id="wxCommunityDetails" resultMap="CommunityResult">
        SELECT tc.title,tc.id,tc.release_status,tc.juwei_code,tc.community_name,tc.address,tc.area,tc.households,tc.juwei,tc.create_date,tc.update_date
        FROM T_COMMUNITY tc
        where tc.id=
        (select community_id from sd_wechat_user where id=#{id}) and release_status = '0'
    </select>

    <select id="selectCommunityList" parameterType="com.wise.SpringController.model.T_Community" resultType="map">
        <include refid="selectCommunity"/>
        where tc.release_status = '0'
        <if test="communityName != null and communityName != ''">
            AND tc.community_name like concat(concat('%',#{communityName}),'%')
        </if>
    </select>

    <select id="selectCommunityById" parameterType="String" resultMap="CommunityResult">
        SELECT tc.title,tc.id,tc.release_status,tc.juwei_code,tc.community_name,tc.address,tc.area,tc.households,tc.juwei,tc.create_date,tc.update_date
        FROM T_COMMUNITY tc
        where tc.id = #{id}
    </select>



    <insert id="insertCommunity" parameterType="com.wise.SpringController.model.T_Community" useGeneratedKeys="true" keyProperty="id">
        <selectKey keyProperty="id" order="BEFORE" resultType="String">
            select seq_t_community.nextval as id from DUAL
        </selectKey>
        insert into t_community(
        <if test="id != null">id,</if>
        <if test="juweiCode != null and juweiCode != ''">juwei_code,</if>
        <if test="title != null and title != ''">title,</if>
        <if test="communityName != null and communityName != ''">community_name,</if>
        <if test="address != null and address != ''">address,</if>
        <if test="area != null and area != ''">area,</if>
        <if test="households != null and households != ''">households,</if>
        <if test="juwei != null and juwei != ''">juwei,</if>
        release_status,
        create_date,
        update_date
        )values(
        <if test="id != null ">#{id},</if>
        <if test="juweiCode != null and juweiCode != ''">#{juweiCode},</if>
        <if test="title != null and title != ''">#{title},</if>
        <if test="communityName != null and communityName != ''">#{communityName},</if>
        <if test="address != null and address != ''">#{address},</if>
        <if test="area != null and area != ''">#{area},</if>
        <if test="households != null and households != ''">#{households},</if>
        <if test="juwei != null and juwei != ''">#{juwei},</if>
        0,
        sysdate,
        sysdate
        )
    </insert>


    <update id="updateCommunity" parameterType="com.wise.SpringController.model.T_Community">
        update t_community
        <set>
            <if test="juweiCode != null and juweiCode != ''">juwei_code = #{juweiCode},</if>
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="communityName != null and communityName != ''">community_name = #{communityName},</if>
            <if test="address != null and address != ''">address = #{address},</if>
            <if test="area != null and area != ''">area = #{area},</if>
            <if test="households != null and households != ''">households = #{households},</if>
            <if test="juwei != null and juwei != ''">juwei = #{juwei},</if>
            update_date = sysdate
        </set>
        where id = #{id}
    </update>


    <delete id="deleteCommunityById">
       update t_community set release_status=1 where id = #{id}
    </delete>

    <select id="selectJuwei" resultType="map">
        select j.juweiCode,j.juweiNameFull from T_JUWEI j
    </select>

    <resultMap type="com.wise.SpringController.model.T_Juwei" id="JuweiResult">
        <result property="id" column="id"/>
        <result property="title" column="title"/>
        <result property="juweiCode" column="juweiCode"/>
        <result property="juweiNameFull" column="juweiNameFull"/>

    </resultMap>
    <select id="selectByJuweiCode" resultType="map">
        select j.juweiNameFull from T_JUWEI j where j.juweiCode = #{juweiCode}
    </select>

</mapper>

index.html列表页面

<!DOCTYPE html>
<html lang="zh_cn" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>小区管理</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="format-detection" content="telephone=no">
    <meta name="format-detection" content="email=no">
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/iframe/zui/css/zui.min.css}">
    <link rel="stylesheet" th:href="@{/iframe/css/page1.css}">
    <link rel="stylesheet" th:href="@{/css/zui.uploader.min.css}">
    <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}">
    <link rel="stylesheet" th:href="@{/css/bootstrap-datetimepicker.min.css}">
    <script th:src="@{/iframe/zui/lib/jquery/jquery.js}"></script>
    <script type="text/javascript" th:src="@{/js/jquery-3.3.1.min.js}"></script>
    <script type="text/javascript" th:src="@{/js/jquery.form.js}"></script>
    <script type="text/javascript" th:src="@{/js/jquery.page.js}"></script>
    <script type="text/javascript" th:src="@{/js/zui.min.js}"></script>
    <script type="text/javascript" th:src="@{/js/eventcommon.js}"></script>
    <script type="text/javascript" th:src="@{/js/bootstrap-multiselect.js}"></script>
    <script type="text/javascript" th:src="@{/js/bootstrap-datetimepicker.min.js}"></script>
    <script type="text/javascript" th:src="@{/js/bootstrap-datetimepicker.zh-CN.js}"></script>
    <script type="text/javascript" th:src="@{/js/common.js}"></script>
    <script type="text/javascript" th:src="@{/js/zui.uploader.min.js}"></script>
    <script type="text/javascript" th:src="@{/layer/layer.js}"></script>
    <script type="text/javascript" th:src="@{/js/wise.openlayer.js}"></script>
    <script type="text/javascript" th:src="@{/js/laydate.js}"></script>

</head>
<body>
<div class="wrapper">
    <div class="search row">
        <div class="search-item col-sm-4">
            <label class="search-label">小区名称</label>
            <input type="text" id="communityName" name="communityName" class="form-control">
        </div>
        <div class="search-item col-sm-2">
            <button class="btn btn-danger search-btn" type="button" onclick='loadEventList(1)'>
                <i class="icon icon-search"></i>
                <span class="text">搜索</span>
            </button>
        </div>
    </div>

    <div class="result">
        <div class="result-option">
            <a class="btn btn-danger result-btn"
               th:onclick="'openlayer.openWindows(\'添加\',\''+@{/community/formView(action=add)}+'\')'" data-position="60px"
               aria-hidden="true" data-backdrop="static">
                <i class="icon icon-plus"></i>
                <span class="text">添加小区</span>
            </a>
        </div>
        <input type="hidden" id="dqpage">
        <h2 class="result-table-title">小区列表</h2>
        <div class="result-table">
            <table class="table table-striped table-bordered table-hover">
                <thead>
                <tr>
                    <th>小区名称</th>
                    <th>小区地址</th>
                    <th>面 积</th>
                    <th>户 数</th>
                    <th>所属社区</th>
                    <th>操 作</th>
                </tr>
                </thead>
                <tbody class="tbody" id="tablist">
                </tbody>
            </table>
        </div>
<!--分页-->
        <div class="result-footer">
            <ul class="pager" data-ride="pager"
                data-elements="prev, nav, next,total_text"
                data-max-nav-count="6"
                data-page="1" data-rec-total="100" data-rec-per-page="10">
            </ul>
        </div>
    </div>
</div>
</body>
    <script th:inline="javascript">
    var basePath =/*[[@{/}]]*/;

    $(function () {

        loadEventList(1);

    });

    function reflush() {
        var pagenum = $("#dqpage").val();
        loadEventList(pagenum);
    }

    $('.pager').pager({
        page: 1,
        onPageChange: function (state, oldState) {
            if (typeof (oldState.page) !== "undefined") {
                if (state.page !== oldState.page) {
                    loadEventList(state.page);
                    $("#dqpage").val(state.page);
                }
            }
        }

    });


    function loadEventList(page) {
        $.ajax({
            type: "POST",
            url: basePath + "community/list",
            async: false,
            data: "pageSize=10&pageNum=" + page + "&communityName=" + $("#communityName").val(),
            success: function (obj) {
            console.log(obj);
            console.log(obj.data.rows);
                $("#tablist tr").remove();
                $(obj.data.rows).each(function () {
                    var html = "<tr>";
                    html += "<td>" + trimToEmpty(this.COMMUNITY_NAME) + "</td>";
                    html += "<td>" + trimToEmpty(this.ADDRESS) + "</td>";
                    html += "<td>" + trimToEmpty(this.AREA) + "</td>";
                    html += "<td>" + trimToEmpty(this.HOUSEHOLDS) + "</td>";
                    html += "<td>" + trimToEmpty(this.JUWEI) + "</td>";
                    html += "<td>";
                    html += "<a class='btn btn-info'  οnclick='openlayer.openWindows(&#x27;详情&#x27;,&#x27;/ljzqksg/community/formView?id=" + this.ID + "&action=show&#x27;)'>详情</a>";
                    html += "<a class='btn btn-warning'  οnclick='openlayer.openWindows(&#x27;编辑&#x27;,&#x27;/ljzqksg/community/formView?id=" + this.ID + "&action=edit&#x27;)'>编辑</a>";
                    html += "&nbsp;<a class='btn btn-danger' οnclick='delbyid(\"" + this.ID + "\")'>删除</a>";
                    html += "</td>";
                    html += "</tr>";

                    $("#tablist").append(html);

                });

                refreshPager(obj,page);

            }
        });
    }

    function trimToEmpty(obj) {
        if (obj == null) {
            return "";
        }
        return obj;
    }



    function refreshPager(obj,page) {
        var pager = $('.pager').data('zui.pager');
        pager.set(obj.data.page, obj.data.total, 10);
    }

    function delbyid(id) {
        if (confirm("确定需要删除吗?")) {
            $.ajax({
                type: "POST",
                url: basePath + "community/deleteById" ,
                data: "id=" + id,
                async: false,
                success: function (obj) {
                    if (obj.status) {
                        layer.msg("删除成功");
                        reflush();
                    } else {
                        layer.msg("删除失败");
                    }
                    reflush();
                }
            });
        }
    }

</script>
</html>

添加修改查看页面(form.html)

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh_cn">
<head>
    <meta charset="UTF-8">
    <title>小区管理</title>
    <link rel="stylesheet" type="text/css" th:href="@{/css/bootstrap-datetimepicker.min.css}"/>
</head>
<body>
<form th:action="@{propertypublic/insertPropertyPublic}" method="post" id="saveForm" class="form-horizontal" style="margin-top: 20px">
    <input type="hidden" class="form-control" name="id" th:value="${communityBean.id}"/>
    <div class="form-group">
        <label class="col-sm-2">小区名称</label>
        <div class="col-xs-3">
            <input class="form-control" name="communityName" th:value="${communityBean.communityName}"/>
        </div>

        <label class="col-sm-2">所属社区</label>
        <div class="col-xs-3">
            <select class="form-control" name="juweiCode">

                <option th:each="qt:${juweiBean}" th:value="${qt.JUWEICODE}"
                        th:text="${qt.JUWEINAMEFULL}" th:selected="${communityBean.juweiCode==qt.JUWEICODE}"></option>
            </select>
<!--            <input class="form-control" name="communityId" th:value="${journeyBean.communityId}"/>-->
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2">小区地址</label>
        <div class="col-xs-8">
            <input class="form-control" name="address" th:value="${communityBean.address}"/>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2">面 积</label>
        <div class="col-sm-8">
            <input type="text" class="form-control" name="area" th:value="${communityBean.area}"/>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2">户 数</label>
        <div class="col-sm-8">
            <input type="text" class="form-control" name="households" th:value="${communityBean.households}"/>
        </div>
    </div>

    <div style="text-align: center; padding-top: 10px">
        <a id="saveBtn" class="btn btn-primary" href="javascript:void(0)" onclick="submitFormv(this)">保存</a>
        <a id="closebtn" class="btn" data-dismiss="modal" onclick="openlayer.closeWindows()">关闭</a>
    </div>
</form>
</body>
<script type="text/javascript" th:inline="javascript">

    /*<![CDATA[*/
    var basePath =/*[[@{/}]]*/;
    var saveForm = $("#saveForm");
    var time = $("#time");
    var action = [[${#httpServletRequest.getParameter("action")}]];
    console.log(action);

    $(function () {
        initDefaultSettings(action);
    });


    function initDefaultSettings(action) {
        if (action == "" || action == "show") {//禁用各种标签
            disableTag("saveForm");
        }
        if (action == "edit" || action == "add") {

            $(".form-date").datetimepicker(
                {
                    language: "zh-CN",
                    weekStart: 1,
                    todayBtn: 1,
                    autoclose: 1,
                    todayHighlight: 1,
                    startView: 2,
                    minView: 0,
                    minuteStep: 1,
                    forceParse: 0,
                    format: 'yyyy-mm-dd hh:ii:ss',
                });
        }
    }



    function disableTag(formId) {
        var form = document.getElementById(formId)
        var inputTags = form.getElementsByTagName("input");
        for (i = 0; i < inputTags.length; i++) {
            if (inputTags[i].type == "radio" || inputTags[i].type == "text" || inputTags[i].type == "password" || inputTags[i].type == "file") {
                inputTags[i].readOnly = true;
            }
            if (inputTags[i].type == "checkbox") {
                inputTags[i].disabled = true;
            }
        }
        var selectTags = form.getElementsByTagName("select");
        for (i = 0; i < selectTags.length; i++) {
            selectTags[i].disabled = true;
        }
        var buttonTags = form.getElementsByTagName("button");
        for (i = 0; i < buttonTags.length; i++) {
            buttonTags[i].remove();
        }
        var textareaTags = form.getElementsByTagName("textarea");
        for (i = 0; i < textareaTags.length; i++) {
            textareaTags[i].readOnly = true;
        }
        $("#saveBtn").remove();
    }




    function submitFormv(obj) {
        $.ajax({
            type: "POST",
            url: basePath + "/community/insertCommunity",
            data: $("#saveForm").serialize(),
            success: function (data) {
                if (data.status) {
                    $("#saveBtn").hide();
                    $("#closebtn").show();
                    layer.msg(data.msg);
                }else{
                    layer.msg(data.msg);
                }
            }
        });
    }

    /*]]>*/
</script>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值