消费者模块除controller,开发完成

This commit is contained in:
clunt 2022-03-22 15:30:40 +08:00
parent 36d34a84ce
commit 0fada0ff74
4 changed files with 183 additions and 41 deletions

View File

@ -1,7 +1,41 @@
package com.ghy.customer.mapper;
import com.ghy.customer.domain.Customer;
/**
* @author clunt
* 消费者Mapper
*/
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);
}

View File

@ -1,4 +1,41 @@
package com.ghy.customer.service;
import com.ghy.customer.domain.Customer;
/**
* @author clunt
* 消费者service层
*/
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);
}

View File

@ -1,11 +1,65 @@
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 org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* @author clunt
* 消费者Impl层
*/
@Service
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;
}
}

View File

@ -3,7 +3,13 @@
<mapper namespace="com.ghy.customer.mapper.CustomerMapper">
<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="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
@ -11,60 +17,71 @@
<result property="remark" column="remark" />
</resultMap>
<sql id="selectGoodsImgs">
SELECT goods_imgs_id, goods_id, img_url, create_by, create_time, remark
FROM goods_imgs
<sql id="selectCustomer">
SELECT customer_id, name, account, phone, open_id, status,
customer_logo_url, create_by, create_time, remark
FROM customer
</sql>
<delete id="delete">
DELETE FROM goods_imgs WHERE goods_imgs_id IN
<foreach collection="array" item="goodsImgsId" open="(" separator="," close=")">
#{goodsImgsId}
<delete id="deleteByIds">
DELETE FROM customer WHERE customer_id IN
<foreach collection="array" item="customerIds" open="(" separator="," close=")">
#{customerIds}
</foreach>
</delete>
<delete id="deleteByGoodsId">
DELETE FROM goods_imgs WHERE goods_id = #{goodsId}
<delete id="deleteByCustomerId" parameterType="Long">
DELETE FROM customer WHERE customer_id = #{customerId}
</delete>
<select id="selectByGoodsId" resultType="com.ghy.goods.domain.GoodsImgs">
<include refid="selectGoodsImgs"/>
<select id="selectByCustomerId" resultType="com.ghy.customer.domain.Customer">
<include refid="selectCustomer"/>
<where>
<if test="goodsId != null and goodsId != 0">
AND goods_id = #{goodsId}
<if test="customerId != null and customerId != 0">
AND customer = #{customerId}
</if>
</where>
</select>
<insert id="batchInsert" parameterType="com.ghy.goods.domain.GoodsImgs" useGeneratedKeys="true" keyProperty="goodsImgsId">
<foreach collection="array" item="goodsImgs">
INSERT INTO goods_imgs(
<if test="goodsImgsId != null and goodsImgsId != 0">goods_imgs_id,</if>
<if test="goodsId != null and goodsId != 0">goods_id,</if>
<if test="imgUrl != null and imgUrl != ''">img_url,</if>
<insert id="insertCustomer" parameterType="com.ghy.customer.domain.Customer" useGeneratedKeys="true" keyProperty="customerId">
insert into customer(
<if test="customerId != null and customerId != 0">customer_id,</if>
<if test="name != null and name != ''">name,</if>
<if test="account != null and account != ''">account,</if>
<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>
create_time)
VALUES(
<if test="goodsImgsId != null and goodsImgsId != 0">#{goodsImgsId},</if>
<if test="goodsId != null and goodsId != 0">#{goodsId},</if>
<if test="imgUrl != null and imgUrl != ''">#{imgUrl},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate());
</foreach>
create_time
)values(
<if test="customerId != null and customerId != 0">${customer_id},</if>
<if test="name != null and name != ''">${name},</if>
<if test="account != null and account != ''">${account},</if>
<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>
<update id="batchUpdate" parameterType="com.ghy.goods.domain.GoodsImgs">
<foreach collection="array" item="goodsImgs">
UPDATE goods_imgs
<update id="updateCustomer" parameterType="com.ghy.customer.domain.Customer">
update costomer
<set>
<if test="goodsId != null and goodsId != ''">goods_id = #{goodsId},</if>
<if test="imgUrl != null and imgUrl != ''">img_url = #{imgUrl},</if>
<if test="name != null and name != ''">name = ${name},</if>
<if test="account != null and account != ''">account = ${account},</if>
<if test="phone != null and phone != ''">phone = ${phone},</if>
<if test="customerLogoUrl != null and customerLogoUrl != ''">customer_logo_url = ${customer_logo_url},</if>
<if test="status != null and status != ''">status = #{status},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
WHERE goods_imgs_id = #{goodsImgsId};
</foreach>
where customer_id = #{customerId}
</update>
</mapper>