消费者模块除controller,开发完成
This commit is contained in:
parent
36d34a84ce
commit
0fada0ff74
|
|
@ -1,7 +1,41 @@
|
||||||
package com.ghy.customer.mapper;
|
package com.ghy.customer.mapper;
|
||||||
|
|
||||||
|
import com.ghy.customer.domain.Customer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author clunt
|
||||||
|
* 消费者Mapper
|
||||||
|
*/
|
||||||
public interface CustomerMapper {
|
public interface CustomerMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param customerId 消费者id
|
||||||
|
* @return 消费者信息
|
||||||
|
*/
|
||||||
|
Customer selectByCustomerId(Long customerId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param customerId 消费者ids
|
||||||
|
* @return 删除成功条数
|
||||||
|
*/
|
||||||
|
int deleteByIds(Long [] customerId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param customerId 消费者id
|
||||||
|
* @return 删除成功条数
|
||||||
|
*/
|
||||||
|
int deleteByCustomerId(Long customerId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param customer 消费者对象
|
||||||
|
* @return 入库成功条数
|
||||||
|
*/
|
||||||
|
int insertCustomer(Customer customer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param customer 消费者对象
|
||||||
|
* @return 更新成功条数
|
||||||
|
*/
|
||||||
|
int updateCustomer(Customer customer);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,41 @@
|
||||||
package com.ghy.customer.service;
|
package com.ghy.customer.service;
|
||||||
|
|
||||||
|
import com.ghy.customer.domain.Customer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author clunt
|
||||||
|
* 消费者service层
|
||||||
|
*/
|
||||||
public interface CustomerService {
|
public interface CustomerService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param customerId 消费者id
|
||||||
|
* @return 消费者信息
|
||||||
|
*/
|
||||||
|
Customer selectByCustomerId(Long customerId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ids 消费者ids
|
||||||
|
* @return 删除成功条数
|
||||||
|
*/
|
||||||
|
int deleteByIds(String ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param customerId 消费者id
|
||||||
|
* @return 删除成功条数
|
||||||
|
*/
|
||||||
|
int deleteByCustomerId(Long customerId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param customer 消费者对象
|
||||||
|
* @return 入库成功条数
|
||||||
|
*/
|
||||||
|
int insertCustomer(Customer customer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param customer 消费者对象
|
||||||
|
* @return 更新成功条数
|
||||||
|
*/
|
||||||
|
int updateCustomer(Customer customer);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,65 @@
|
||||||
package com.ghy.customer.service.impl;
|
package com.ghy.customer.service.impl;
|
||||||
|
|
||||||
|
import com.ghy.common.core.text.Convert;
|
||||||
|
import com.ghy.common.exception.ServiceException;
|
||||||
|
import com.ghy.customer.domain.Customer;
|
||||||
|
import com.ghy.customer.mapper.CustomerMapper;
|
||||||
import com.ghy.customer.service.CustomerService;
|
import com.ghy.customer.service.CustomerService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author clunt
|
||||||
|
* 消费者Impl层
|
||||||
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class CustomerServiceImpl implements CustomerService {
|
public class CustomerServiceImpl implements CustomerService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CustomerMapper customerMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Customer selectByCustomerId(Long customerId) {
|
||||||
|
return customerMapper.selectByCustomerId(customerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int deleteByIds(String ids) {
|
||||||
|
Long [] customerIds = Convert.toLongArray(ids);
|
||||||
|
for (Long customerId : customerIds)
|
||||||
|
{
|
||||||
|
Customer customer = selectByCustomerId(customerId);
|
||||||
|
if (countUserCustomer(customer) > 0)
|
||||||
|
{
|
||||||
|
throw new ServiceException(String.format("%1$s正在使用,不能删除", customer.getName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return customerMapper.deleteByIds(customerIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int deleteByCustomerId(Long customerId) {
|
||||||
|
Customer customer = selectByCustomerId(customerId);
|
||||||
|
if (countUserCustomer(customer) > 0)
|
||||||
|
{
|
||||||
|
throw new ServiceException(String.format("%1$s正在使用,不能删除", customer.getName()));
|
||||||
|
}
|
||||||
|
return customerMapper.deleteByCustomerId(customerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int insertCustomer(Customer customer) {
|
||||||
|
return customerMapper.insertCustomer(customer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int updateCustomer(Customer customer) {
|
||||||
|
return customerMapper.updateCustomer(customer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int countUserCustomer(Customer customer) {
|
||||||
|
//TODO 需要校验用户是否在被使用。
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,13 @@
|
||||||
<mapper namespace="com.ghy.customer.mapper.CustomerMapper">
|
<mapper namespace="com.ghy.customer.mapper.CustomerMapper">
|
||||||
|
|
||||||
<resultMap id="GoodsImgsResult" type="com.ghy.customer.domain.Customer">
|
<resultMap id="GoodsImgsResult" type="com.ghy.customer.domain.Customer">
|
||||||
<!-- 消费者属性 -->
|
<result property="customerId" column="customer_id" />
|
||||||
|
<result property="name" column="name" />
|
||||||
|
<result property="account" column="account" />
|
||||||
|
<result property="phone" column="phone" />
|
||||||
|
<result property="openId" column="open_id" />
|
||||||
|
<result property="status" column="status" />
|
||||||
|
<result property="customerLogoUrl" column="customer_logo_url" />
|
||||||
<result property="createBy" column="create_by" />
|
<result property="createBy" column="create_by" />
|
||||||
<result property="createTime" column="create_time" />
|
<result property="createTime" column="create_time" />
|
||||||
<result property="updateBy" column="update_by" />
|
<result property="updateBy" column="update_by" />
|
||||||
|
|
@ -11,60 +17,71 @@
|
||||||
<result property="remark" column="remark" />
|
<result property="remark" column="remark" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectGoodsImgs">
|
<sql id="selectCustomer">
|
||||||
SELECT goods_imgs_id, goods_id, img_url, create_by, create_time, remark
|
SELECT customer_id, name, account, phone, open_id, status,
|
||||||
FROM goods_imgs
|
customer_logo_url, create_by, create_time, remark
|
||||||
|
FROM customer
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<delete id="delete">
|
<delete id="deleteByIds">
|
||||||
DELETE FROM goods_imgs WHERE goods_imgs_id IN
|
DELETE FROM customer WHERE customer_id IN
|
||||||
<foreach collection="array" item="goodsImgsId" open="(" separator="," close=")">
|
<foreach collection="array" item="customerIds" open="(" separator="," close=")">
|
||||||
#{goodsImgsId}
|
#{customerIds}
|
||||||
</foreach>
|
</foreach>
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<delete id="deleteByGoodsId">
|
<delete id="deleteByCustomerId" parameterType="Long">
|
||||||
DELETE FROM goods_imgs WHERE goods_id = #{goodsId}
|
DELETE FROM customer WHERE customer_id = #{customerId}
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<select id="selectByGoodsId" resultType="com.ghy.goods.domain.GoodsImgs">
|
<select id="selectByCustomerId" resultType="com.ghy.customer.domain.Customer">
|
||||||
<include refid="selectGoodsImgs"/>
|
<include refid="selectCustomer"/>
|
||||||
<where>
|
<where>
|
||||||
<if test="goodsId != null and goodsId != 0">
|
<if test="customerId != null and customerId != 0">
|
||||||
AND goods_id = #{goodsId}
|
AND customer = #{customerId}
|
||||||
</if>
|
</if>
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<insert id="batchInsert" parameterType="com.ghy.goods.domain.GoodsImgs" useGeneratedKeys="true" keyProperty="goodsImgsId">
|
<insert id="insertCustomer" parameterType="com.ghy.customer.domain.Customer" useGeneratedKeys="true" keyProperty="customerId">
|
||||||
<foreach collection="array" item="goodsImgs">
|
insert into customer(
|
||||||
INSERT INTO goods_imgs(
|
<if test="customerId != null and customerId != 0">customer_id,</if>
|
||||||
<if test="goodsImgsId != null and goodsImgsId != 0">goods_imgs_id,</if>
|
<if test="name != null and name != ''">name,</if>
|
||||||
<if test="goodsId != null and goodsId != 0">goods_id,</if>
|
<if test="account != null and account != ''">account,</if>
|
||||||
<if test="imgUrl != null and imgUrl != ''">img_url,</if>
|
<if test="phone != null and phone != ''">phone,</if>
|
||||||
<if test="remark != null and remark != ''">remark,</if>
|
<if test="customerLogoUrl != null and customerLogoUrl != ''">customer_logo_url,</if>
|
||||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
<if test="openId != null and openId != ''">open_id,</if>
|
||||||
create_time)
|
<if test="status != null and status != ''">status,</if>
|
||||||
VALUES(
|
<if test="remark != null and remark != ''">remark,</if>
|
||||||
<if test="goodsImgsId != null and goodsImgsId != 0">#{goodsImgsId},</if>
|
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||||
<if test="goodsId != null and goodsId != 0">#{goodsId},</if>
|
create_time
|
||||||
<if test="imgUrl != null and imgUrl != ''">#{imgUrl},</if>
|
)values(
|
||||||
<if test="remark != null and remark != ''">#{remark},</if>
|
<if test="customerId != null and customerId != 0">${customer_id},</if>
|
||||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
<if test="name != null and name != ''">${name},</if>
|
||||||
sysdate());
|
<if test="account != null and account != ''">${account},</if>
|
||||||
</foreach>
|
<if test="phone != null and phone != ''">${phone},</if>
|
||||||
|
<if test="customerLogoUrl != null and customerLogoUrl != ''">${customer_logo_url},</if>
|
||||||
|
<if test="openId != null and openId != ''">${open_id},</if>
|
||||||
|
<if test="status != null and status != ''">${status},</if>
|
||||||
|
<if test="remark != null and remark != ''">${remark},</if>
|
||||||
|
<if test="createBy != null and createBy != ''">${create_by},</if>
|
||||||
|
sysdate()
|
||||||
|
)
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<update id="batchUpdate" parameterType="com.ghy.goods.domain.GoodsImgs">
|
<update id="updateCustomer" parameterType="com.ghy.customer.domain.Customer">
|
||||||
<foreach collection="array" item="goodsImgs">
|
update costomer
|
||||||
UPDATE goods_imgs
|
<set>
|
||||||
<set>
|
<if test="name != null and name != ''">name = ${name},</if>
|
||||||
<if test="goodsId != null and goodsId != ''">goods_id = #{goodsId},</if>
|
<if test="account != null and account != ''">account = ${account},</if>
|
||||||
<if test="imgUrl != null and imgUrl != ''">img_url = #{imgUrl},</if>
|
<if test="phone != null and phone != ''">phone = ${phone},</if>
|
||||||
update_time = sysdate()
|
<if test="customerLogoUrl != null and customerLogoUrl != ''">customer_logo_url = ${customer_logo_url},</if>
|
||||||
</set>
|
<if test="status != null and status != ''">status = #{status},</if>
|
||||||
WHERE goods_imgs_id = #{goodsImgsId};
|
<if test="remark != null">remark = #{remark},</if>
|
||||||
</foreach>
|
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||||
|
update_time = sysdate()
|
||||||
|
</set>
|
||||||
|
where customer_id = #{customerId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
Loading…
Reference in New Issue