ソースを参照

增加培训API

FengChaoYu 3 日 前
コミット
8506c38225

+ 31 - 0
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/bean/message/TrainingVO.java

@@ -0,0 +1,31 @@
+package com.gree.mall.miniapp.bean.message;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+@ApiModel
+public class TrainingVO {
+
+    @ApiModelProperty(value = "id")
+    private String id;
+
+    @ApiModelProperty(value = "商户id")
+    private String companyWechatId;
+
+    @ApiModelProperty(value = "商户名称")
+    private String companyName;
+
+    @ApiModelProperty(value = "名称")
+    private String name;
+
+    @ApiModelProperty(value = "说明")
+    private String remark;
+
+    @ApiModelProperty(value = "文件类型")
+    private String file_type;
+
+    @ApiModelProperty(value = "文件地址")
+    private String url;
+}

+ 4 - 0
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/commonmapper/AppMapper.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.gree.mall.miniapp.bean.StorageBean;
 import com.gree.mall.miniapp.bean.goods.GoodsNewBean;
+import com.gree.mall.miniapp.bean.message.TrainingVO;
 import com.gree.mall.miniapp.bean.order.OrderStatusBean;
 import com.gree.mall.miniapp.bean.order.ShoppingCartList;
 import com.gree.mall.miniapp.plus.entity.CommonFile;
@@ -52,4 +53,7 @@ public interface AppMapper {
      */
     @InterceptorIgnore(tenantLine = "1", blockAttack = "1", illegalSql = "1")
     List<StorageBean> findStorageByLocate(String companyWechatId, String lng, String lat);
+
+    @InterceptorIgnore(tenantLine = "1", blockAttack = "1", illegalSql = "1")
+    List<TrainingVO> queryTrainingList(@Param("companyWechatId") String companyWechatId);
 }

+ 4 - 3
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/controller/common/CommonController.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.gree.mall.miniapp.annotation.ApiNotAuth;
 import com.gree.mall.miniapp.bean.common.OrderPickTimeConfigBean;
+import com.gree.mall.miniapp.bean.message.TrainingVO;
 import com.gree.mall.miniapp.bean.user.CurrentCompanyWechat;
 import com.gree.mall.miniapp.constant.Constant;
 import com.gree.mall.miniapp.exception.RemoteServiceException;
@@ -237,8 +238,8 @@ public class CommonController {
     @ApiNotAuth
     @PostMapping("/training/list")
     @ApiOperation(value = "培训列表")
-    public ResponseHelper<List<CommonFile>> trainingList(@ApiParam(required = true, value = "文件夹id") @RequestParam String id) {
-        List<CommonFile> region = commonLogic.trainingList(id);
-        return ResponseHelper.success(region);
+    public ResponseHelper<List<TrainingVO>> trainingList() {
+        List<TrainingVO> list = commonLogic.trainingList();
+        return ResponseHelper.success(list);
     }
 }

+ 9 - 4
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/logic/common/CommonLogic.java

@@ -9,7 +9,9 @@ import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.TypeReference;
 import com.gree.mall.miniapp.bean.common.OrderPickTimeConfigBean;
 import com.gree.mall.miniapp.bean.common.OrderPickTimeCountBean;
+import com.gree.mall.miniapp.bean.message.TrainingVO;
 import com.gree.mall.miniapp.bean.user.CurrentCompanyWechat;
+import com.gree.mall.miniapp.commonmapper.AppMapper;
 import com.gree.mall.miniapp.constant.Constant;
 import com.gree.mall.miniapp.enums.OrderStatusEnum;
 import com.gree.mall.miniapp.exception.RemoteServiceException;
@@ -68,6 +70,8 @@ public class CommonLogic {
     AdminPlatformService adminPlatformService;
     @Resource
     StorageService storageService;
+    @Resource
+    AppMapper appMapper;
     @Value("${spring.profiles.active}")
     private String profiles;
     @Value("${inf.url}")
@@ -454,9 +458,10 @@ public class CommonLogic {
         return adminCompanyWechatService.list();
     }
 
-    public List<CommonFile> trainingList(String id) {
-        return commonFileService.lambdaQuery()
-                .eq(CommonFile::getObjId, id)
-                .list();
+    public List<TrainingVO> trainingList() {
+        final CurrentCompanyWechat companyWechat = getCurrentCompanyWechat();
+
+        List<TrainingVO> list = appMapper.queryTrainingList(companyWechat.getCurrentCompanyWechatId());
+        return list;
     }
 }

+ 17 - 0
mall-miniapp-service/src/main/resources/mapper/AppMapper.xml

@@ -114,4 +114,21 @@
         ORDER BY distance ASC
     </select>
 
+    <select id="queryTrainingList" resultType="com.gree.mall.miniapp.bean.message.TrainingVO">
+        SELECT
+            a.id,
+            a.company_wechat_id,
+            a.company_name,
+            b.name,
+            b.remark,
+            b.file_type,
+            b.url
+        FROM training a
+        LEFT JOIN common_file b ON a.obj_id = b.id
+        WHERE
+            a.company_wechat_id IN ('0', CONCAT(#{companyWechatId}))
+            AND a.del = 0
+        ORDER BY a.create_time DESC
+    </select>
+
 </mapper>

+ 52 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/message/TrainingVO.java

@@ -0,0 +1,52 @@
+package com.gree.mall.manager.bean.message;
+
+import com.gree.mall.manager.annotation.ZfireField;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+@ApiModel
+@ZfireField(tbName = "a")
+public class TrainingVO {
+
+    @ApiModelProperty(value = "id")
+    private String id;
+
+    @ZfireField(hide = true)
+    @ApiModelProperty(value = "商户id")
+    private String companyWechatId;
+
+    @ApiModelProperty(value = "商户名称")
+    private String companyName;
+
+    @ZfireField(hide = true)
+    @ApiModelProperty(value = "文件库id")
+    private String objId;
+
+    @ZfireField(tbName = "b")
+    @ApiModelProperty(value = "名称")
+    private String name;
+
+    @ZfireField(tbName = "b")
+    @ApiModelProperty(value = "说明")
+    private String remark;
+
+//    @ZfireField(tbName = "b")
+//    @ApiModelProperty(value = "文件类型")
+//    private String fileType;
+
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+
+    @ApiModelProperty(value = "创建人")
+    private String createBy;
+
+    @ApiModelProperty(value = "修改时间")
+    private Date updateTime;
+
+    @ApiModelProperty(value = "修改人")
+    private String updateBy;
+}

+ 9 - 0
mall-server-api/src/main/java/com/gree/mall/manager/commonmapper/CommonMapper.java

@@ -17,6 +17,7 @@ import com.gree.mall.manager.bean.listvo.workorder.*;
 import com.gree.mall.manager.bean.member.UserCompanyCreditVO;
 import com.gree.mall.manager.bean.member.UserCompanyDeliveryVO;
 import com.gree.mall.manager.bean.message.MessageVO;
+import com.gree.mall.manager.bean.message.TrainingVO;
 import com.gree.mall.manager.bean.order.LeaseOrderVO;
 import com.gree.mall.manager.bean.order.OrderPickTimeConfigVO;
 import com.gree.mall.manager.bean.order.refund.OrderOfflineRefundVO;
@@ -680,4 +681,12 @@ public interface CommonMapper {
      * @return
      */
     IPage<MessageVO> messagePage(Page page, @Param("ex") ZfireParamBean zfireParamBean);
+
+    /**
+     * 培训列表
+     * @param page
+     * @param zfireParamBean
+     * @return
+     */
+    IPage<TrainingVO> trainingPage(Page page, @Param("ex") ZfireParamBean zfireParamBean);
 }

+ 65 - 0
mall-server-api/src/main/java/com/gree/mall/manager/controller/message/TrainingController.java

@@ -0,0 +1,65 @@
+package com.gree.mall.manager.controller.message;
+
+import cn.hutool.core.lang.TypeReference;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.gree.mall.manager.annotation.ZfireList;
+import com.gree.mall.manager.bean.message.TrainingVO;
+import com.gree.mall.manager.exception.RemoteServiceException;
+import com.gree.mall.manager.helper.ResponseHelper;
+import com.gree.mall.manager.logic.message.TrainingBean;
+import com.gree.mall.manager.logic.message.TrainingLogic;
+import com.gree.mall.manager.zfire.bean.ZfireParamBean;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+
+@Slf4j
+@RestController
+@Api(value = "培训API", tags ={"培训API"} )
+@RequestMapping(value = "/training", produces = "application/json; charset=utf-8")
+public class TrainingController {
+
+    @Resource
+    TrainingLogic trainingLogic;
+
+    @ZfireList
+    @PostMapping("/list")
+    @ApiOperation(value = "列表")
+    public ResponseHelper<IPage<TrainingVO>> list(
+            @RequestBody ZfireParamBean zfireParamBean
+    ) {
+        IPage<TrainingVO> page = trainingLogic.list(zfireParamBean);
+        return ResponseHelper.success(page, new TypeReference<TrainingVO>() {});
+    }
+
+    @PostMapping("/detail")
+    @ApiOperation(value = "详情")
+    public ResponseHelper<TrainingBean> detail(
+            @ApiParam(value = "id",required = true) @RequestParam String id
+    ) throws RemoteServiceException {
+        TrainingBean detail = trainingLogic.detail(id);
+        return ResponseHelper.success(detail);
+    }
+
+    @PostMapping("/save")
+    @ApiOperation(value = "新增修改")
+    public ResponseHelper add(
+            @ApiParam(value = "object",required = true) @RequestBody TrainingBean trainingBean
+    ) throws Exception {
+        trainingLogic.save(trainingBean);
+        return ResponseHelper.success();
+    }
+
+    @PostMapping("/del")
+    @ApiOperation(value = "删除")
+    public ResponseHelper del(
+            @ApiParam(value = "id",required = true) @RequestParam String id
+    ) throws Exception {
+        trainingLogic.del(id);
+        return ResponseHelper.success();
+    }
+}

+ 18 - 0
mall-server-api/src/main/java/com/gree/mall/manager/logic/message/TrainingBean.java

@@ -0,0 +1,18 @@
+package com.gree.mall.manager.logic.message;
+
+import com.gree.mall.manager.plus.entity.CommonFile;
+import com.gree.mall.manager.plus.entity.Training;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+@ApiModel
+public class TrainingBean extends Training {
+
+    @ApiModelProperty(value = "文件对象")
+    private CommonFile commonFile;
+
+}

+ 96 - 0
mall-server-api/src/main/java/com/gree/mall/manager/logic/message/TrainingLogic.java

@@ -0,0 +1,96 @@
+package com.gree.mall.manager.logic.message;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.gree.mall.manager.bean.admin.AdminUserCom;
+import com.gree.mall.manager.bean.message.TrainingVO;
+import com.gree.mall.manager.commonmapper.CommonMapper;
+import com.gree.mall.manager.logic.common.CommonLogic;
+import com.gree.mall.manager.plus.entity.CommonFile;
+import com.gree.mall.manager.plus.entity.Training;
+import com.gree.mall.manager.plus.service.CommonFileService;
+import com.gree.mall.manager.plus.service.TrainingService;
+import com.gree.mall.manager.zfire.bean.ZfireParamBean;
+import com.gree.mall.manager.zfire.util.FieldUtils;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@Slf4j
+@RequiredArgsConstructor
+public class TrainingLogic {
+
+    private final CommonMapper commonMapper;
+    private final CommonLogic commonLogic;
+    private final TrainingService trainingService;
+    private final CommonFileService commonFileService;
+
+    public IPage<TrainingVO> list(ZfireParamBean zfireParamBean) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        FieldUtils.supplyParam(zfireParamBean, TrainingVO.class, adminUser);
+
+        IPage<TrainingVO> page = commonMapper.trainingPage(new Page(zfireParamBean.getPageNum(), zfireParamBean.getPageSize()), zfireParamBean);
+        return page;
+    }
+    
+    public TrainingBean detail(String id) {
+        TrainingBean trainingBean = new TrainingBean();
+        final Training training = trainingService.getById(id);
+        BeanUtils.copyProperties(training, trainingBean);
+        final CommonFile commonFile = commonFileService.getById(training.getObjId());
+        trainingBean.setCommonFile(commonFile);
+
+        return trainingBean;
+    }
+
+    @Transactional
+    public void save(TrainingBean trainingBean) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        if (adminUser.getType() == 2) {
+            trainingBean.setCompanyWechatId("0");
+        } else {
+            trainingBean.setCompanyWechatId(adminUser.getCompanyWechatId());
+            trainingBean.setCompanyName(adminUser.getCompanyName());
+        }
+
+        if (StringUtils.isBlank(trainingBean.getId())) {
+            trainingBean.setId(IdWorker.getIdStr());
+        }
+
+        Training training = new Training();
+        BeanUtils.copyProperties(trainingBean, training);
+
+        CommonFile commonFile = trainingBean.getCommonFile();
+        if (StringUtils.isBlank(commonFile.getId())) {
+            commonFile.setId(IdWorker.getIdStr());
+            commonFileService.lambdaUpdate()
+                    .eq(CommonFile::getObjId, training.getId())
+                    .eq(CommonFile::getObjType,  "TRAINING")
+                    .remove();
+        }
+
+        commonFile.setObjType("TRAINING");
+        commonFile.setObjId(training.getId());
+
+        // 文件库id注入
+        training.setObjId(commonFile.getId());
+
+
+        training.insertOrUpdate();
+        commonFile.insertOrUpdate();
+    }
+
+    @Transactional
+    public void del(String id) {
+        trainingService.removeById(id);
+        commonFileService.lambdaUpdate()
+                .eq(CommonFile::getObjId, id)
+                .eq(CommonFile::getObjType,  "TRAINING")
+                .remove();
+    }
+}

+ 11 - 0
mall-server-api/src/main/resources/mapper/CommonMapper.xml

@@ -1319,5 +1319,16 @@
         ${ex.orderBy}
     </select>
 
+    <select id="trainingPage" resultType="com.gree.mall.manager.bean.message.TrainingVO">
+        SELECT
+        ${ex.selected}
+        FROM training a
+            LEFT JOIN common_file b ON a.obj_id = b.id
+        ${ex.query}
+        <if test="ex.orderBy == null or ex.orderBy ==''">
+            ORDER BY a.create_time DESC
+        </if>
+        ${ex.orderBy}
+    </select>
 
 </mapper>